diff --git a/test/cli/fixtures/expected/tap-outputs.js b/test/cli/fixtures/expected/tap-outputs.js index 598e289d7..eb09d570f 100644 --- a/test/cli/fixtures/expected/tap-outputs.js +++ b/test/cli/fixtures/expected/tap-outputs.js @@ -164,6 +164,43 @@ not ok 1 global failure # skip 0 # todo 0 # fail 1 +`, + + "qunit sourcemap/source.js": +`TAP version 13 +ok 1 Example > good +not ok 2 Example > bad + --- + message: "failed" + severity: failed + actual: false + expected: true + stack: at .* \\(.*source.js:7:14\\) + ... +1..2 +# pass 1 +# skip 0 +# todo 0 +# fail 1 +`, + + "NODE_OPTIONS='--enable-source-maps' qunit sourcemap/source.min.js": +`TAP version 13 +ok 1 Example > good +not ok 2 Example > bad + --- + message: "failed" + severity: failed + actual: false + expected: true + stack: at .* \\(.*source.min.js:1:.*\\) + -> .*source.js:7:10 + ... +1..2 +# pass 1 +# skip 0 +# todo 0 +# fail 1 `, "qunit timeout": diff --git a/test/cli/fixtures/sourcemap/source.js b/test/cli/fixtures/sourcemap/source.js new file mode 100644 index 000000000..a1b960ed1 --- /dev/null +++ b/test/cli/fixtures/sourcemap/source.js @@ -0,0 +1,9 @@ +QUnit.module( "Example", function() { + QUnit.test( "good", function( assert ) { + assert.true( true ); + } ); + + QUnit.test( "bad", function( assert ) { + assert.true( false ); + } ); +} ); diff --git a/test/cli/fixtures/sourcemap/source.min.js b/test/cli/fixtures/sourcemap/source.min.js new file mode 100644 index 000000000..28e6bca6a --- /dev/null +++ b/test/cli/fixtures/sourcemap/source.min.js @@ -0,0 +1,2 @@ +QUnit.module("Example",function(){QUnit.test("good",function(assert){assert.true(!0)}),QUnit.test("bad",function(assert){assert.true(!1)})}); +//# sourceMappingURL=source.min.js.map \ No newline at end of file diff --git a/test/cli/fixtures/sourcemap/source.min.js.map b/test/cli/fixtures/sourcemap/source.min.js.map new file mode 100644 index 000000000..13a4444df --- /dev/null +++ b/test/cli/fixtures/sourcemap/source.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["sourcemap/source.js"],"names":["QUnit","module","test","assert","true"],"mappings":"AAAAA,MAAMC,OAAQ,UAAW,WACxBD,MAAME,KAAM,OAAQ,SAAUC,QAC7BA,OAAOC,MAAM,KAGdJ,MAAME,KAAM,MAAO,SAAUC,QAC5BA,OAAOC,MAAM"} \ No newline at end of file diff --git a/test/cli/helpers/execute.js b/test/cli/helpers/execute.js index adc52352b..a82345ebf 100644 --- a/test/cli/helpers/execute.js +++ b/test/cli/helpers/execute.js @@ -10,7 +10,7 @@ module.exports = function execute( command, execaOptions ) { const cwd = process.cwd(); process.chdir( path.join( __dirname, "..", "fixtures" ) ); - command = command.replace( /^qunit\b/, "../../../bin/qunit.js" ); + command = command.replace( /(^| )qunit\b/, "$1../../../bin/qunit.js" ); const execution = exec( command, execaOptions ); process.chdir( cwd ); diff --git a/test/cli/main.js b/test/cli/main.js index 55b7922b8..6a01ccd22 100644 --- a/test/cli/main.js +++ b/test/cli/main.js @@ -135,6 +135,37 @@ QUnit.module( "CLI Main", function() { } } ); + // https://nodejs.org/dist/v12.12.0/docs/api/cli.html#cli_enable_source_maps + if ( semver.gte( process.versions.node, "14.0.0" ) ) { + + QUnit.test( "normal trace with native source map", async function( assert ) { + const command = "qunit sourcemap/source.js"; + try { + await execute( command ); + } catch ( e ) { + assert.equal( e.code, 1 ); + assert.equal( e.stderr, "" ); + const re = new RegExp( expectedOutput[ command ] ); + assert.equal( re.test( e.stdout ), true ); + } + } ); + + QUnit.test( "mapped trace with native source map", async function( assert ) { + const command = "NODE_OPTIONS='--enable-source-maps' qunit sourcemap/source.min.js"; + try { + await execute( command ); + } catch ( e ) { + assert.equal( e.code, 1 ); + assert.equal( e.stderr, "" ); + const re = new RegExp( expectedOutput[ command ] ); + assert.equal( re.test( e.stdout ), true ); + if ( !re.test( e.stdout ) ) { + assert.equal( e.stdout, expectedOutput[ command ] ); + } + } + } ); + } + QUnit.test( "timeouts correctly recover", async function( assert ) { const command = "qunit timeout"; try {