Skip to content

Commit

Permalink
Add transitive mapping support in spec test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
takikawa committed May 9, 2024
1 parent 2460574 commit 4c10b94
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions test/test-spec-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit 4c10b94

Please sign in to comment.