forked from mochajs/mocha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(esm): allow
import
from mocha in parallel (mochajs#4574)
- Loading branch information
Showing
7 changed files
with
189 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const {runMochaAsync} = require('./helpers'); | ||
|
||
describe('common js require', () => { | ||
it('should be able to run a test where all mocha exports are used', async () => { | ||
const result = await runMochaAsync('common-js-require.fixture.js', [ | ||
'--delay' | ||
]); | ||
expect(result.output, 'to contain', 'running before'); | ||
expect(result.output, 'to contain', 'running suiteSetup'); | ||
expect(result.output, 'to contain', 'running setup'); | ||
expect(result.output, 'to contain', 'running beforeEach'); | ||
expect(result.output, 'to contain', 'running it'); | ||
expect(result.output, 'to contain', 'running afterEach'); | ||
expect(result.output, 'to contain', 'running teardown'); | ||
expect(result.output, 'to contain', 'running suiteTeardown'); | ||
expect(result.output, 'to contain', 'running after'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const { afterEach, | ||
after, | ||
beforeEach, | ||
before, | ||
describe, | ||
xdescribe, | ||
it, | ||
xit, | ||
setup, | ||
suiteSetup, | ||
suiteTeardown, | ||
suite, | ||
teardown, | ||
test, | ||
run } = require('../../..'); | ||
|
||
|
||
suite('root suite', () => { | ||
setup(() => { | ||
console.log('running setup'); | ||
}) | ||
before(() => { | ||
console.log('running before'); | ||
}); | ||
beforeEach(() => { | ||
console.log('running beforeEach'); | ||
}); | ||
afterEach(() => { | ||
console.log('running afterEach'); | ||
}); | ||
after(() => { | ||
console.log('running after'); | ||
}); | ||
teardown(() => { | ||
console.log('running teardown'); | ||
}); | ||
suiteSetup(() => { | ||
console.log('running suiteSetup'); | ||
}); | ||
suiteTeardown(() => { | ||
console.log('running suiteTeardown'); | ||
}); | ||
|
||
describe.only('describe only', () => { | ||
it('it', () => { | ||
console.log('running it'); | ||
}); | ||
xit('it', () => { | ||
console.log('running xit'); | ||
}); | ||
it.only('it.only', () => { | ||
console.log('running it.only'); | ||
}); | ||
it.skip('it.skip', () => { | ||
console.log('running it.skip'); | ||
}); | ||
test('test', () => { | ||
console.log('running test'); | ||
}); | ||
}); | ||
|
||
describe('describe', () => {}); | ||
|
||
xdescribe('xdescribe', () => {}); | ||
|
||
describe.skip('describe.skip', () => {}); | ||
|
||
suite.only('suite only', () => {}); | ||
|
||
suite.skip('suite.skip', () => {}); | ||
|
||
}); | ||
|
||
// using `run` here makes it so this suite needs to be run with `--delay` mode. | ||
// adding it here to test that `run` is correctly exported from mocha. | ||
setTimeout(run, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {describe,it} from "../../../../index.js"; | ||
|
||
describe('test1', () => { | ||
it('should pass', () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {describe,it} from "../../../../index.js"; | ||
|
||
describe('test2', () => { | ||
it('should pass', () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {describe,it} from "../../../../index.js"; | ||
|
||
describe('test3', () => { | ||
it('should fail', () => { | ||
throw new Error('expecting this error to fail'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const {runMochaJSONAsync} = require('./helpers'); | ||
const semver = require('semver'); | ||
|
||
describe('parallel run', () => { | ||
/** | ||
* @see https://github.com/mochajs/mocha/issues/4559 | ||
*/ | ||
it('should allow `import {it} from "mocha"` module syntax', async () => { | ||
if (semver.major(process.version) <= 10) { | ||
console.log( | ||
`[SKIPPED] for node ${process.version} (es module syntax isn't supported on node <= 10)` | ||
); | ||
} else { | ||
const result = await runMochaJSONAsync('parallel/test3.mjs', [ | ||
'--parallel', | ||
'--jobs', | ||
'2', | ||
require.resolve('./fixtures/parallel/test1.mjs'), | ||
require.resolve('./fixtures/parallel/test2.mjs') | ||
]); | ||
assert.strictEqual(result.stats.failures, 1); | ||
assert.strictEqual(result.stats.passes, 2); | ||
} | ||
}); | ||
}); |