Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
takikawa committed Jun 6, 2024
1 parent 3a33cd7 commit 8afce96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 13 additions & 10 deletions test/test-spec-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({

Check failure on line 70 in test/test-spec-tests.js

View workflow job for this annotation

GitHub Actions / lint

'mappedPosition' is not defined
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}`);

Check failure on line 75 in test/test-spec-tests.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 167. Maximum allowed is 120

Check failure on line 75 in test/test-spec-tests.js

View workflow job for this annotation

GitHub Actions / lint

'mappedPosition' is not defined

Check failure on line 75 in test/test-spec-tests.js

View workflow job for this annotation

GitHub Actions / lint

'mappedPosition' is not defined
assert.equal(mappedPosition.column, action.originalColumn, `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}`);

Check failure on line 76 in test/test-spec-tests.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 159. Maximum allowed is 120

Check failure on line 76 in test/test-spec-tests.js

View workflow job for this annotation

GitHub Actions / lint

'mappedPosition' is not defined

Check failure on line 76 in test/test-spec-tests.js

View workflow job for this annotation

GitHub Actions / lint

'mappedPosition' is not defined
assert.equal(nullish(mappedPosition.source), action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`);

Check failure on line 77 in test/test-spec-tests.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 168. Maximum allowed is 120

Check failure on line 77 in test/test-spec-tests.js

View workflow job for this annotation

GitHub Actions / lint

'mappedPosition' is not defined

Check failure on line 77 in test/test-spec-tests.js

View workflow job for this annotation

GitHub Actions / lint

'mappedPosition' is not defined
if (action.mappedName)
Expand All @@ -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}`);
}

Expand All @@ -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({
Expand All @@ -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(() => {});
Expand All @@ -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") {
Expand Down

0 comments on commit 8afce96

Please sign in to comment.