Skip to content
Permalink
Browse files
test: improve lib/internal/source_map/source_map.js coverage
  • Loading branch information
fossamagna authored and danielleadams committed Oct 5, 2022
1 parent 60a05d6 commit dc2af265d7e425c920a52aadb03b0ac9a83bd88a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
@@ -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": "./"
}
}
]
}
@@ -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) {

0 comments on commit dc2af26

Please sign in to comment.