Skip to content

Commit a0fcb9d

Browse files
committed
test: improve lib/internal/source_map/source_map.js coverage
1 parent f50a80c commit a0fcb9d

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": 3,
3+
"sources": [
4+
"disk.js"
5+
],
6+
"sections": [
7+
{ "offset": {"line": 0, "column": 0 }, "map":
8+
{
9+
"version": 3,
10+
"sources": [
11+
"section.js"
12+
],
13+
"names": [
14+
"Foo",
15+
"[object Object]",
16+
"x",
17+
"this",
18+
"console",
19+
"info",
20+
"methodC",
21+
"a",
22+
"b",
23+
"methodA"
24+
],
25+
"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",
26+
"sourceRoot": "./"
27+
}
28+
}
29+
]
30+
}

test/parallel/test-source-map-api.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ const { readFileSync } = require('fs');
9999
assert.notStrictEqual(payload.sources, sourceMap.payload.sources);
100100
}
101101

102+
// SourceMap can be instantiated with Index Source Map V3 object as payload.
103+
{
104+
const payload = JSON.parse(readFileSync(
105+
require.resolve('../fixtures/source-map/disk-index.map'), 'utf8'
106+
));
107+
const sourceMap = new SourceMap(payload);
108+
const {
109+
originalLine,
110+
originalColumn,
111+
originalSource
112+
} = sourceMap.findEntry(0, 29);
113+
assert.strictEqual(originalLine, 2);
114+
assert.strictEqual(originalColumn, 4);
115+
assert(originalSource.endsWith('section.js'));
116+
// The stored payload should be a clone:
117+
assert.strictEqual(payload.mappings, sourceMap.payload.mappings);
118+
assert.notStrictEqual(payload, sourceMap.payload);
119+
assert.strictEqual(payload.sources[0], sourceMap.payload.sources[0]);
120+
assert.notStrictEqual(payload.sources, sourceMap.payload.sources);
121+
}
122+
102123
// Test various known decodings to ensure decodeVLQ works correctly.
103124
{
104125
function makeMinimalMap(column) {

0 commit comments

Comments
 (0)