Skip to content

Commit

Permalink
test: improve lib/internal/source_map/source_map.js coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fossamagna authored and danielleadams committed Oct 5, 2022
1 parent 60a05d6 commit dc2af26
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/fixtures/source-map/disk-index.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": 3,
"sources": [
"disk.js"
],
"sections": [
{ "offset": {"line": 0, "column": 0 }, "map":
{
"version": 3,
"sources": [
"section.js"
],
"names": [
"Foo",
"[object Object]",
"x",
"this",
"console",
"info",
"methodC",
"a",
"b",
"methodA"
],
"mappings": "MAAMA,IACJC,YAAaC,EAAE,IACbC,KAAKD,EAAIA,EAAIA,EAAI,GACjB,GAAIC,KAAKD,EAAG,CACVE,QAAQC,KAAK,eACR,CACLD,QAAQC,KAAK,aAEfF,KAAKG,UAEPL,UACEG,QAAQC,KAAK,WAEfJ,UACEG,QAAQC,KAAK,aAEfJ,UACEG,QAAQC,KAAK,WAEfJ,UACEG,QAAQC,KAAK,cAIjB,MAAME,EAAI,IAAIP,IAAI,GAClB,MAAMQ,EAAI,IAAIR,IAAI,IAClBO,EAAEE",
"sourceRoot": "./"
}
}
]
}
21 changes: 21 additions & 0 deletions test/parallel/test-source-map-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ const { readFileSync } = require('fs');
assert.strictEqual(Object.keys(result).length, 0);
}

// SourceMap can be instantiated with Index Source Map V3 object as payload.
{
const payload = JSON.parse(readFileSync(
require.resolve('../fixtures/source-map/disk-index.map'), 'utf8'
));
const sourceMap = new SourceMap(payload);
const {
originalLine,
originalColumn,
originalSource
} = sourceMap.findEntry(0, 29);
assert.strictEqual(originalLine, 2);
assert.strictEqual(originalColumn, 4);
assert(originalSource.endsWith('section.js'));
// The stored payload should be a clone:
assert.strictEqual(payload.mappings, sourceMap.payload.mappings);
assert.notStrictEqual(payload, sourceMap.payload);
assert.strictEqual(payload.sources[0], sourceMap.payload.sources[0]);
assert.notStrictEqual(payload.sources, sourceMap.payload.sources);
}

// Test various known decodings to ensure decodeVLQ works correctly.
{
function makeMinimalMap(column) {
Expand Down

0 comments on commit dc2af26

Please sign in to comment.