-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for running a suite multiple times
- Loading branch information
Showing
5 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
test/integration/fixtures/multiple-runs/multiple-runs-different-output-suite.fixture.js
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,19 @@ | ||
describe('Multiple runs', () => { | ||
|
||
/** | ||
* Shared state! Bad practice, but nice for this test | ||
*/ | ||
let i = 0; | ||
|
||
it('should skip, fail and pass respectively', function () { | ||
switch (i++) { | ||
case 0: | ||
this.skip(); | ||
case 1: | ||
throw new Error('Expected error'); | ||
default: | ||
// this is fine ☕ | ||
break; | ||
} | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
test/integration/fixtures/multiple-runs/multiple-runs-different-output.fixture.js
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,22 @@ | ||
'use strict'; | ||
const Mocha = require('../../../../lib/mocha'); | ||
|
||
const mocha = new Mocha( { reporter: 'json' } ); | ||
if(process.argv.indexOf('--no-clean-references') >= 0) { | ||
mocha.cleanReferencesAfterRun(false); | ||
} | ||
if(process.argv.indexOf('--directly-dispose') >= 0){ | ||
mocha.dispose(); | ||
} | ||
mocha.addFile(require.resolve('./multiple-runs-different-output-suite.fixture.js')); | ||
console.log('['); | ||
mocha.run(() => { | ||
console.log(','); | ||
mocha.run(() => { | ||
console.log(','); | ||
mocha.run(() => { | ||
console.log(']'); | ||
}); | ||
}); | ||
}); | ||
|
5 changes: 5 additions & 0 deletions
5
...ion/fixtures/multiple-runs/start-second-run-if-previous-is-still-running-suite.fixture.js
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 @@ | ||
describe('slow suite', () => { | ||
it('should be slow', (done) => { | ||
setTimeout(200, done); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
...tegration/fixtures/multiple-runs/start-second-run-if-previous-is-still-running.fixture.js
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,8 @@ | ||
'use strict'; | ||
const Mocha = require('../../../../lib/mocha'); | ||
|
||
const mocha = new Mocha( { reporter: 'json' } ); | ||
mocha.addFile(require.resolve('./start-second-run-if-previous-is-still-running-suite.fixture.js')); | ||
mocha.run(); | ||
mocha.run(); | ||
|
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,74 @@ | ||
'use strict'; | ||
|
||
var invokeNode = require('./helpers').invokeNode; | ||
|
||
describe('multiple runs', function(done) { | ||
it('should should be allowed to run multiple times if cleanReferences is turned off', function(done) { | ||
var path = require.resolve( | ||
'./fixtures/multiple-runs/multiple-runs-different-output.fixture.js' | ||
); | ||
invokeNode([path, '--no-clean-references'], function(err, res) { | ||
expect(err, 'to be null'); | ||
expect(res.code, 'to be', 0); | ||
var results = JSON.parse(res.output); | ||
expect(results, 'to have length', 3); | ||
expect(results[0].pending, 'to have length', 1); | ||
expect(results[0].failures, 'to have length', 0); | ||
expect(results[0].passes, 'to have length', 0); | ||
expect(results[1].pending, 'to have length', 0); | ||
expect(results[1].failures, 'to have length', 1); | ||
expect(results[1].passes, 'to have length', 0); | ||
expect(results[2].pending, 'to have length', 0); | ||
expect(results[2].failures, 'to have length', 0); | ||
expect(results[2].passes, 'to have length', 1); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should should not be allowed if cleanReferences is true', function(done) { | ||
var path = require.resolve( | ||
'./fixtures/multiple-runs/multiple-runs-different-output.fixture.js' | ||
); | ||
invokeNode( | ||
[path], | ||
function(err, res) { | ||
expect(err, 'to be null'); | ||
expect(res.code, 'not to be', 0); | ||
expect(res.output, 'to contain', 'ERR_MOCHA_INSTANCE_ALREADY_DISPOSED'); | ||
done(); | ||
}, | ||
{stdio: ['ignore', 'pipe', 'pipe']} | ||
); | ||
}); | ||
|
||
it('should should not be allowed if the instance is disposed', function(done) { | ||
var path = require.resolve( | ||
'./fixtures/multiple-runs/multiple-runs-different-output.fixture.js' | ||
); | ||
invokeNode( | ||
[path, '--directly-dispose'], | ||
function(err, res) { | ||
expect(err, 'to be null'); | ||
expect(res.code, 'not to be', 0); | ||
expect(res.output, 'to contain', 'ERR_MOCHA_INSTANCE_ALREADY_DISPOSED'); | ||
done(); | ||
}, | ||
{stdio: ['ignore', 'pipe', 'pipe']} | ||
); | ||
}); | ||
|
||
it('should should not allowed to run while a previous run is in progress', function(done) { | ||
var path = require.resolve( | ||
'./fixtures/multiple-runs/start-second-run-if-previous-is-still-running.fixture' | ||
); | ||
invokeNode( | ||
[path], | ||
function(err, res) { | ||
expect(err, 'to be null'); | ||
expect(res.output, 'to contain', 'ERR_MOCHA_INSTANCE_ALREADY_RUNNING'); | ||
done(); | ||
}, | ||
{stdio: ['ignore', 'pipe', 'pipe']} | ||
); | ||
}); | ||
}); |