From 6fed3b24181ad9b07a78dc670ca30a775a763f11 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Tue, 16 Apr 2024 18:46:36 -0700 Subject: [PATCH 1/8] Add draft source map spec tests This commit adds a submodule for the draft source map spec test repo and adds a new test file that runs each of the test cases. Some test cases that have known failures are skipped, with a comment explaining why. --- .gitmodules | 3 ++ test/source-map-tests | 1 + test/test-spec-tests.js | 102 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 .gitmodules create mode 160000 test/source-map-tests create mode 100644 test/test-spec-tests.js diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..34cbd89f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "test/source-map-tests"] + path = test/source-map-tests + url = https://github.com/takikawa/source-map-tests.git diff --git a/test/source-map-tests b/test/source-map-tests new file mode 160000 index 00000000..b2852261 --- /dev/null +++ b/test/source-map-tests @@ -0,0 +1 @@ +Subproject commit b2852261baf54df31ac33e2ccc5c8fe246c9a4bb diff --git a/test/test-spec-tests.js b/test/test-spec-tests.js new file mode 100644 index 00000000..bc169bbf --- /dev/null +++ b/test/test-spec-tests.js @@ -0,0 +1,102 @@ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2024 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + +const fs = require('node:fs/promises'); +const SourceMapConsumer = + require("../lib/source-map-consumer").SourceMapConsumer; + +const sourceMapSpecTests = require("./source-map-tests/source-map-spec-tests.json"); + +async function readJSON(path) { + const file = await fs.open(require.resolve(path)); + const json = JSON.parse(await file.readFile()); + file.close(); + return json; +} + +// Known failures due to intentional implementation choices or due to bugs. +const skippedTests = [ + // Versions are explicitly checked a bit loosely. + "versionNumericString", + // Stricter sources array checking isn't implemented. + "sourcesNotStringOrNull", + "sourcesAndSourcesContentBothNull", + // Stricter names array checking isn't implemented. + "namesMissing", + "namesNotString", + // This check isn't as strict in this library. + "invalidMappingNotAString1", + // A mapping segment with no fields is technically invalid in the spec. + "invalidMappingSegmentWithZeroFields", + // These tests fail due to imprecision in the spec about the 32-bit limit. + "invalidMappingSegmentWithColumnExceeding32Bits", + "invalidMappingSegmentWithOriginalLineExceeding32Bits", + "invalidMappingSegmentWithOriginalColumnExceeding32Bits", + // A large VLQ that should parse, but currently does not. + "validMappingLargeVLQ", + // The library currently doesn't check the types of offset lines/columns. + "indexMapOffsetLineWrongType", + "indexMapOffsetColumnWrongType", + // The spec is not totally clear about this case. + "indexMapInvalidBaseMappings", + // The spec's definition of overlap can be refined + "indexMapInvalidOverlap", + // Not clear if this test makes sense, but spec isn't clear on behavior + "validMappingNullSources" +] + +async function testMappingAction(assert, rawSourceMap, action) { + return SourceMapConsumer.with(rawSourceMap, null, (consumer) => { + let mappedPosition = consumer.generatedPositionFor({ + source: action.originalSource, + line: action.originalLine + 1, + column: action.originalColumn + }); + + assert.equal(mappedPosition.line, action.generatedLine + 1, `generated line didn't match, expected ${action.generatedLine + 1} got ${mappedPosition.line}`); + assert.equal(mappedPosition.column, action.generatedColumn, `generated column didn't match, expected ${action.generatedColumn} got ${mappedPosition.column}`); + + mappedPosition = consumer.originalPositionFor({ + line: action.generatedLine + 1, + column: action.generatedColumn, + }); + + assert.equal(mappedPosition.line, action.originalLine + 1, `original line didn't match, expected ${action.originalLine + 1} got ${mappedPosition.line}`); + assert.equal(mappedPosition.column, action.originalColumn, `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}`); + assert.equal(mappedPosition.source, action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`); + if (action.mappedName) + assert.equal(mappedPosition.name, action.mappedName, `mapped name didn't match, expected ${action.mappedName} got ${mappedPosition.name}`); + }); +} + +for (let testCase of sourceMapSpecTests.tests) { + if (skippedTests.includes(testCase.name)) + continue; + exports[`test from source map spec tests, name: ${testCase.name}`] = + async function (assert) { + const json = await readJSON(`./source-map-tests/resources/${testCase.sourceMapFile}`); + let sourceMapFailed = false; + try { + const map = await new SourceMapConsumer(json); + map.eachMapping(() => {}); + map.destroy(); + } catch (exn) { + if (testCase.sourceMapIsValid) + assert.fail("Expected valid source map but failed to load successfully: " + exn.message); + return; + } + if (!testCase.sourceMapIsValid) + assert.fail("Expected invalid source map but loaded successfully"); + if (testCase.testActions) { + for (let testAction of testCase.testActions) { + if (testAction.actionType == "checkMapping") { + await testMappingAction(assert, json, testAction); + } + } + } + }; +}; From d5cb02ce816470795be4adcd851508562705453c Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Thu, 9 May 2024 11:26:58 -0700 Subject: [PATCH 2/8] Add transitive mapping support in spec test harness --- test/source-map-tests | 2 +- test/test-spec-tests.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/test/source-map-tests b/test/source-map-tests index b2852261..ec5a471d 160000 --- a/test/source-map-tests +++ b/test/source-map-tests @@ -1 +1 @@ -Subproject commit b2852261baf54df31ac33e2ccc5c8fe246c9a4bb +Subproject commit ec5a471db6e3a736242e1e3d9a4aebea1472edf5 diff --git a/test/test-spec-tests.js b/test/test-spec-tests.js index bc169bbf..656da32c 100644 --- a/test/test-spec-tests.js +++ b/test/test-spec-tests.js @@ -73,6 +73,31 @@ async function testMappingAction(assert, rawSourceMap, action) { }); } +async function testTransitiveMappingAction(assert, rawSourceMap, action) { + return SourceMapConsumer.with(rawSourceMap, null, async (consumer) => { + assert.ok(Array.isArray(action.intermediateMaps), "transitive mapping case requires intermediate maps"); + + let mappedPosition = consumer.originalPositionFor({ + line: action.generatedLine + 1, + column: action.generatedColumn, + }); + + for (let intermediateMapPath of action.intermediateMaps) { + const intermediateMap = await readJSON(`./source-map-tests/resources/${intermediateMapPath}`); + await SourceMapConsumer.with(intermediateMap, null, (consumer) => { + mappedPosition = consumer.originalPositionFor({ + line: mappedPosition.line, + column: mappedPosition.column, + }); + }); + } + + assert.equal(mappedPosition.line, action.originalLine + 1, `original line didn't match, expected ${action.originalLine + 1} got ${mappedPosition.line}`); + assert.equal(mappedPosition.column, action.originalColumn, `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}`); + assert.equal(mappedPosition.source, action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`); + }); +} + for (let testCase of sourceMapSpecTests.tests) { if (skippedTests.includes(testCase.name)) continue; @@ -95,6 +120,8 @@ for (let testCase of sourceMapSpecTests.tests) { for (let testAction of testCase.testActions) { if (testAction.actionType == "checkMapping") { await testMappingAction(assert, json, testAction); + } else if (testAction.actionType == "checkMappingTransitive") { + await testTransitiveMappingAction(assert, json, testAction); } } } From 6396a24aa3dcb37edf57783af50bc8b0eb576a88 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Tue, 21 May 2024 14:59:41 -0700 Subject: [PATCH 3/8] Refine handling of null in the test harness * Don't do reverse lookup test if source is null * Allow "null" in cases where null is expected --- test/test-spec-tests.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/test/test-spec-tests.js b/test/test-spec-tests.js index 656da32c..a966c552 100644 --- a/test/test-spec-tests.js +++ b/test/test-spec-tests.js @@ -45,21 +45,19 @@ const skippedTests = [ "indexMapInvalidBaseMappings", // The spec's definition of overlap can be refined "indexMapInvalidOverlap", - // Not clear if this test makes sense, but spec isn't clear on behavior - "validMappingNullSources" ] +// The source-map library converts null sources to the "null" URL in its +// sources list, so for equality checking we accept this as null. +function nullish(nullOrString) { + if (nullOrString === "null") { + return null; + } + return nullOrString; +} + async function testMappingAction(assert, rawSourceMap, action) { return SourceMapConsumer.with(rawSourceMap, null, (consumer) => { - let mappedPosition = consumer.generatedPositionFor({ - source: action.originalSource, - line: action.originalLine + 1, - column: action.originalColumn - }); - - assert.equal(mappedPosition.line, action.generatedLine + 1, `generated line didn't match, expected ${action.generatedLine + 1} got ${mappedPosition.line}`); - assert.equal(mappedPosition.column, action.generatedColumn, `generated column didn't match, expected ${action.generatedColumn} got ${mappedPosition.column}`); - mappedPosition = consumer.originalPositionFor({ line: action.generatedLine + 1, column: action.generatedColumn, @@ -67,9 +65,23 @@ async function testMappingAction(assert, rawSourceMap, action) { assert.equal(mappedPosition.line, action.originalLine + 1, `original line didn't match, expected ${action.originalLine + 1} got ${mappedPosition.line}`); assert.equal(mappedPosition.column, action.originalColumn, `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}`); - assert.equal(mappedPosition.source, action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`); + assert.equal(nullish(mappedPosition.source), action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`); if (action.mappedName) assert.equal(mappedPosition.name, action.mappedName, `mapped name didn't match, expected ${action.mappedName} got ${mappedPosition.name}`); + + // When the source is null, a reverse lookup may not make sense + // because there isn't a unique way to look it up. + if (action.originalSource !== null) { + let mappedPosition = consumer.generatedPositionFor({ + source: action.originalSource, + line: action.originalLine + 1, + column: action.originalColumn + }); + + assert.equal(mappedPosition.line, action.generatedLine + 1, `generated line didn't match, expected ${action.generatedLine + 1} got ${mappedPosition.line}`); + assert.equal(mappedPosition.column, action.generatedColumn, `generated column didn't match, expected ${action.generatedColumn} got ${mappedPosition.column}`); + } + }); } From 2dea47e672f30ecda8dcb20cdd02e0345cbb91c1 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Thu, 6 Jun 2024 09:28:48 +0200 Subject: [PATCH 4/8] Update source map tests repo to official one --- .gitmodules | 2 +- test/source-map-tests | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 34cbd89f..163c0757 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "test/source-map-tests"] path = test/source-map-tests - url = https://github.com/takikawa/source-map-tests.git + url = https://github.com/tc39/source-map-tests.git diff --git a/test/source-map-tests b/test/source-map-tests index ec5a471d..14c89744 160000 --- a/test/source-map-tests +++ b/test/source-map-tests @@ -1 +1 @@ -Subproject commit ec5a471db6e3a736242e1e3d9a4aebea1472edf5 +Subproject commit 14c897444208365fc586a9c00c623bfb1955d731 From 3a33cd7037df9f768dec44f525d328820e725074 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Thu, 6 Jun 2024 09:56:18 +0200 Subject: [PATCH 5/8] Update skipped tests for ignoreList tests These aren't supported yet because the library doesn't support ignoreList yet and doesn't do any checking for it. --- test/test-spec-tests.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test-spec-tests.js b/test/test-spec-tests.js index a966c552..dd1296ba 100644 --- a/test/test-spec-tests.js +++ b/test/test-spec-tests.js @@ -45,6 +45,11 @@ const skippedTests = [ "indexMapInvalidBaseMappings", // The spec's definition of overlap can be refined "indexMapInvalidOverlap", + // The library doesn't support the new ignoreList feature yet. + "ignoreListWrongType1", + "ignoreListWrongType2", + "ignoreListWrongType3", + "ignoreListOutOfBounds", ] // The source-map library converts null sources to the "null" URL in its From 8afce96252a35ed665d436f13372b6c92539c0b9 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Thu, 6 Jun 2024 10:02:50 +0200 Subject: [PATCH 6/8] Address PR feedback --- package.json | 2 +- test/test-spec-tests.js | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 00077059..3301cbdd 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "license": "BSD-3-Clause", "scripts": { "lint": "eslint --fix *.js lib/ test/", - "test": "node test/run-tests.js", + "test": "git submodule update --init --recursive; node test/run-tests.js", "coverage": "c8 --reporter=text --reporter=html npm test", "prettier": "prettier --write .", "clean": "rm -rf coverage", diff --git a/test/test-spec-tests.js b/test/test-spec-tests.js index dd1296ba..12fc2cea 100644 --- a/test/test-spec-tests.js +++ b/test/test-spec-tests.js @@ -61,14 +61,18 @@ function nullish(nullOrString) { return nullOrString; } +function mapLine(line) { + return line + 1; +} + async function testMappingAction(assert, rawSourceMap, action) { return SourceMapConsumer.with(rawSourceMap, null, (consumer) => { mappedPosition = consumer.originalPositionFor({ - line: action.generatedLine + 1, + line: mapLine(action.generatedLine), column: action.generatedColumn, }); - assert.equal(mappedPosition.line, action.originalLine + 1, `original line didn't match, expected ${action.originalLine + 1} got ${mappedPosition.line}`); + assert.equal(mappedPosition.line, mapLine(action.originalLine), `original line didn't match, expected ${mapLine(action.originalLine)} got ${mappedPosition.line}`); assert.equal(mappedPosition.column, action.originalColumn, `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}`); assert.equal(nullish(mappedPosition.source), action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`); if (action.mappedName) @@ -79,11 +83,11 @@ async function testMappingAction(assert, rawSourceMap, action) { if (action.originalSource !== null) { let mappedPosition = consumer.generatedPositionFor({ source: action.originalSource, - line: action.originalLine + 1, + line: mapLine(action.originalLine), column: action.originalColumn }); - assert.equal(mappedPosition.line, action.generatedLine + 1, `generated line didn't match, expected ${action.generatedLine + 1} got ${mappedPosition.line}`); + assert.equal(mappedPosition.line, mapLine(action.generatedLine), `generated line didn't match, expected ${mapLine(action.generatedLine)} got ${mappedPosition.line}`); assert.equal(mappedPosition.column, action.generatedColumn, `generated column didn't match, expected ${action.generatedColumn} got ${mappedPosition.column}`); } @@ -95,11 +99,11 @@ async function testTransitiveMappingAction(assert, rawSourceMap, action) { assert.ok(Array.isArray(action.intermediateMaps), "transitive mapping case requires intermediate maps"); let mappedPosition = consumer.originalPositionFor({ - line: action.generatedLine + 1, + line: mapLine(action.generatedLine), column: action.generatedColumn, }); - for (let intermediateMapPath of action.intermediateMaps) { + for (const intermediateMapPath of action.intermediateMaps) { const intermediateMap = await readJSON(`./source-map-tests/resources/${intermediateMapPath}`); await SourceMapConsumer.with(intermediateMap, null, (consumer) => { mappedPosition = consumer.originalPositionFor({ @@ -109,19 +113,18 @@ async function testTransitiveMappingAction(assert, rawSourceMap, action) { }); } - assert.equal(mappedPosition.line, action.originalLine + 1, `original line didn't match, expected ${action.originalLine + 1} got ${mappedPosition.line}`); + assert.equal(mappedPosition.line, mapLine(action.originalLine), `original line didn't match, expected ${mapLine(action.originalLine)} got ${mappedPosition.line}`); assert.equal(mappedPosition.column, action.originalColumn, `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}`); assert.equal(mappedPosition.source, action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`); }); } -for (let testCase of sourceMapSpecTests.tests) { +for (const testCase of sourceMapSpecTests.tests) { if (skippedTests.includes(testCase.name)) continue; exports[`test from source map spec tests, name: ${testCase.name}`] = async function (assert) { const json = await readJSON(`./source-map-tests/resources/${testCase.sourceMapFile}`); - let sourceMapFailed = false; try { const map = await new SourceMapConsumer(json); map.eachMapping(() => {}); @@ -134,7 +137,7 @@ for (let testCase of sourceMapSpecTests.tests) { if (!testCase.sourceMapIsValid) assert.fail("Expected invalid source map but loaded successfully"); if (testCase.testActions) { - for (let testAction of testCase.testActions) { + for (const testAction of testCase.testActions) { if (testAction.actionType == "checkMapping") { await testMappingAction(assert, json, testAction); } else if (testAction.actionType == "checkMappingTransitive") { From 64050e6a6345b171a35f81833367ba486ca13338 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Thu, 6 Jun 2024 10:09:55 +0200 Subject: [PATCH 7/8] Updates to satisfy linter Also makes the linter ignore the submodule --- package.json | 2 +- test/test-spec-tests.js | 123 +++++++++++++++++++++++++++++----------- 2 files changed, 92 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 3301cbdd..ae0e6552 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ }, "license": "BSD-3-Clause", "scripts": { - "lint": "eslint --fix *.js lib/ test/", + "lint": "eslint --fix *.js lib/ test/ --ignore-pattern 'test/source-map-tests/**'", "test": "git submodule update --init --recursive; node test/run-tests.js", "coverage": "c8 --reporter=text --reporter=html npm test", "prettier": "prettier --write .", diff --git a/test/test-spec-tests.js b/test/test-spec-tests.js index 12fc2cea..fbe29117 100644 --- a/test/test-spec-tests.js +++ b/test/test-spec-tests.js @@ -5,7 +5,7 @@ * http://opensource.org/licenses/BSD-3-Clause */ -const fs = require('node:fs/promises'); +const fs = require("node:fs/promises"); const SourceMapConsumer = require("../lib/source-map-consumer").SourceMapConsumer; @@ -50,7 +50,7 @@ const skippedTests = [ "ignoreListWrongType2", "ignoreListWrongType3", "ignoreListOutOfBounds", -] +]; // The source-map library converts null sources to the "null" URL in its // sources list, so for equality checking we accept this as null. @@ -66,37 +66,68 @@ function mapLine(line) { } async function testMappingAction(assert, rawSourceMap, action) { - return SourceMapConsumer.with(rawSourceMap, null, (consumer) => { - mappedPosition = consumer.originalPositionFor({ + return SourceMapConsumer.with(rawSourceMap, null, consumer => { + let mappedPosition = consumer.originalPositionFor({ line: mapLine(action.generatedLine), column: action.generatedColumn, }); - assert.equal(mappedPosition.line, mapLine(action.originalLine), `original line didn't match, expected ${mapLine(action.originalLine)} got ${mappedPosition.line}`); - assert.equal(mappedPosition.column, action.originalColumn, `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}`); - assert.equal(nullish(mappedPosition.source), action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`); - if (action.mappedName) - assert.equal(mappedPosition.name, action.mappedName, `mapped name didn't match, expected ${action.mappedName} got ${mappedPosition.name}`); + assert.equal( + mappedPosition.line, + mapLine(action.originalLine), + `original line didn't match, expected ${mapLine( + action.originalLine + )} got ${mappedPosition.line}` + ); + assert.equal( + mappedPosition.column, + action.originalColumn, + `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}` + ); + assert.equal( + nullish(mappedPosition.source), + action.originalSource, + `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}` + ); + if (action.mappedName) { + assert.equal( + mappedPosition.name, + action.mappedName, + `mapped name didn't match, expected ${action.mappedName} got ${mappedPosition.name}` + ); + } // When the source is null, a reverse lookup may not make sense // because there isn't a unique way to look it up. if (action.originalSource !== null) { - let mappedPosition = consumer.generatedPositionFor({ + mappedPosition = consumer.generatedPositionFor({ source: action.originalSource, line: mapLine(action.originalLine), - column: action.originalColumn + column: action.originalColumn, }); - assert.equal(mappedPosition.line, mapLine(action.generatedLine), `generated line didn't match, expected ${mapLine(action.generatedLine)} got ${mappedPosition.line}`); - assert.equal(mappedPosition.column, action.generatedColumn, `generated column didn't match, expected ${action.generatedColumn} got ${mappedPosition.column}`); + assert.equal( + mappedPosition.line, + mapLine(action.generatedLine), + `generated line didn't match, expected ${mapLine( + action.generatedLine + )} got ${mappedPosition.line}` + ); + assert.equal( + mappedPosition.column, + action.generatedColumn, + `generated column didn't match, expected ${action.generatedColumn} got ${mappedPosition.column}` + ); } - }); } async function testTransitiveMappingAction(assert, rawSourceMap, action) { - return SourceMapConsumer.with(rawSourceMap, null, async (consumer) => { - assert.ok(Array.isArray(action.intermediateMaps), "transitive mapping case requires intermediate maps"); + return SourceMapConsumer.with(rawSourceMap, null, async consumer => { + assert.ok( + Array.isArray(action.intermediateMaps), + "transitive mapping case requires intermediate maps" + ); let mappedPosition = consumer.originalPositionFor({ line: mapLine(action.generatedLine), @@ -104,38 +135,66 @@ async function testTransitiveMappingAction(assert, rawSourceMap, action) { }); for (const intermediateMapPath of action.intermediateMaps) { - const intermediateMap = await readJSON(`./source-map-tests/resources/${intermediateMapPath}`); - await SourceMapConsumer.with(intermediateMap, null, (consumer) => { - mappedPosition = consumer.originalPositionFor({ - line: mappedPosition.line, - column: mappedPosition.column, - }); - }); + const intermediateMap = await readJSON( + `./source-map-tests/resources/${intermediateMapPath}` + ); + await SourceMapConsumer.with( + intermediateMap, + null, + consumerIntermediate => { + mappedPosition = consumerIntermediate.originalPositionFor({ + line: mappedPosition.line, + column: mappedPosition.column, + }); + } + ); } - assert.equal(mappedPosition.line, mapLine(action.originalLine), `original line didn't match, expected ${mapLine(action.originalLine)} got ${mappedPosition.line}`); - assert.equal(mappedPosition.column, action.originalColumn, `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}`); - assert.equal(mappedPosition.source, action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`); + assert.equal( + mappedPosition.line, + mapLine(action.originalLine), + `original line didn't match, expected ${mapLine( + action.originalLine + )} got ${mappedPosition.line}` + ); + assert.equal( + mappedPosition.column, + action.originalColumn, + `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}` + ); + assert.equal( + mappedPosition.source, + action.originalSource, + `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}` + ); }); } for (const testCase of sourceMapSpecTests.tests) { - if (skippedTests.includes(testCase.name)) + if (skippedTests.includes(testCase.name)) { continue; + } exports[`test from source map spec tests, name: ${testCase.name}`] = async function (assert) { - const json = await readJSON(`./source-map-tests/resources/${testCase.sourceMapFile}`); + const json = await readJSON( + `./source-map-tests/resources/${testCase.sourceMapFile}` + ); try { const map = await new SourceMapConsumer(json); map.eachMapping(() => {}); map.destroy(); } catch (exn) { - if (testCase.sourceMapIsValid) - assert.fail("Expected valid source map but failed to load successfully: " + exn.message); + if (testCase.sourceMapIsValid) { + assert.fail( + "Expected valid source map but failed to load successfully: " + + exn.message + ); + } return; } - if (!testCase.sourceMapIsValid) + if (!testCase.sourceMapIsValid) { assert.fail("Expected invalid source map but loaded successfully"); + } if (testCase.testActions) { for (const testAction of testCase.testActions) { if (testAction.actionType == "checkMapping") { @@ -146,4 +205,4 @@ for (const testCase of sourceMapSpecTests.tests) { } } }; -}; +} From d243a04ce31850f3f726332b790448b824df1a8c Mon Sep 17 00:00:00 2001 From: Hubert Boma Manilla Date: Sun, 9 Jun 2024 15:34:55 +0100 Subject: [PATCH 8/8] Update test/test-spec-tests.js Fix the require of the fs promises module --- test/test-spec-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-spec-tests.js b/test/test-spec-tests.js index fbe29117..8f113160 100644 --- a/test/test-spec-tests.js +++ b/test/test-spec-tests.js @@ -5,7 +5,7 @@ * http://opensource.org/licenses/BSD-3-Clause */ -const fs = require("node:fs/promises"); +const fs = require("fs").promises; const SourceMapConsumer = require("../lib/source-map-consumer").SourceMapConsumer;