-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exit nonzero when a spec fails to load
* Fixes #167
- Loading branch information
Showing
13 changed files
with
83 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spec/fixtures/cjs-syntax-error/syntax_error.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
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 was deleted.
Oops, something went wrong.
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 @@ | ||
{ | ||
"spec_dir": ".", | ||
"spec_files": [ | ||
"throws_on_load.js" | ||
], | ||
"helpers": [] | ||
} |
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 @@ | ||
throw new Error("nope"); |
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 @@ | ||
{ | ||
"spec_dir": ".", | ||
"spec_files": [ | ||
"syntax_error.js" | ||
], | ||
"helpers": [] | ||
} |
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 @@ | ||
function( |
Empty file.
Empty file.
Empty file.
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,59 @@ | ||
const child_process = require('child_process'); | ||
|
||
describe('Integration', function () { | ||
it('supports ES modules', async function () { | ||
let {exitCode, output} = await runJasmine('spec/fixtures/esm'); | ||
expect(exitCode).toEqual(0); | ||
// Node < 14 outputs a warning when ES modules are used, e.g.: | ||
// (node:5258) ExperimentalWarning: The ESM module loader is experimental. | ||
// The position of this warning in the output varies. Sometimes it | ||
// occurs before the lines we're interested in but sometimes it's in | ||
// the middle of them. | ||
output = output.replace(/^.*ExperimentalWarning.*$\n/m, ''); | ||
expect(output).toContain( | ||
'name_reporter\n' + | ||
'commonjs_helper\n' + | ||
'esm_helper\n' + | ||
'Started\n' + | ||
'Spec: A spec file ending in .js is required as a commonjs module\n' + | ||
'.Spec: A spec file ending in .mjs is imported as an es module\n' | ||
); | ||
}); | ||
|
||
it('handles load-time exceptions from CommonJS specs properly', async function () { | ||
const {exitCode, output} = await runJasmine('spec/fixtures/cjs-load-exception'); | ||
expect(exitCode).toEqual(1); | ||
expect(output).toContain('Error: nope'); | ||
expect(output).toMatch(/at .*throws_on_load.js/); | ||
}); | ||
|
||
it('handles syntax errors in CommonJS specs properly', async function () { | ||
const {exitCode, output} = await runJasmine('spec/fixtures/cjs-syntax-error'); | ||
expect(exitCode).toEqual(1); | ||
expect(output).toContain('SyntaxError'); | ||
expect(output).toContain('syntax_error.js'); | ||
}); | ||
}); | ||
|
||
async function runJasmine(cwd) { | ||
return new Promise(function(resolve) { | ||
const child = child_process.spawn( | ||
'node', | ||
['--experimental-modules', '../../../bin/jasmine.js', '--config=jasmine.json'], | ||
{ | ||
cwd, | ||
shell: false | ||
} | ||
); | ||
let output = ''; | ||
child.stdout.on('data', function (data) { | ||
output += data; | ||
}); | ||
child.stderr.on('data', function (data) { | ||
output += data; | ||
}); | ||
child.on('close', function (exitCode) { | ||
resolve({exitCode, output}); | ||
}); | ||
}); | ||
} |
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