Skip to content

Commit dc2af26

Browse files
fossamagnadanielleadams
authored andcommitted
test: improve lib/internal/source_map/source_map.js coverage
PR-URL: #42771 Refs: https://coverage.nodejs.org/coverage-0699150267c08fb2/lib/internal/source_map/source_map.js.html#L154 Refs: https://coverage.nodejs.org/coverage-0699150267c08fb2/lib/internal/source_map/source_map.js.html#L165 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
1 parent 60a05d6 commit dc2af26

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
+30
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

+21
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,27 @@ const { readFileSync } = require('fs');
126126
assert.strictEqual(Object.keys(result).length, 0);
127127
}
128128

129+
// SourceMap can be instantiated with Index Source Map V3 object as payload.
130+
{
131+
const payload = JSON.parse(readFileSync(
132+
require.resolve('../fixtures/source-map/disk-index.map'), 'utf8'
133+
));
134+
const sourceMap = new SourceMap(payload);
135+
const {
136+
originalLine,
137+
originalColumn,
138+
originalSource
139+
} = sourceMap.findEntry(0, 29);
140+
assert.strictEqual(originalLine, 2);
141+
assert.strictEqual(originalColumn, 4);
142+
assert(originalSource.endsWith('section.js'));
143+
// The stored payload should be a clone:
144+
assert.strictEqual(payload.mappings, sourceMap.payload.mappings);
145+
assert.notStrictEqual(payload, sourceMap.payload);
146+
assert.strictEqual(payload.sources[0], sourceMap.payload.sources[0]);
147+
assert.notStrictEqual(payload.sources, sourceMap.payload.sources);
148+
}
149+
129150
// Test various known decodings to ensure decodeVLQ works correctly.
130151
{
131152
function makeMinimalMap(column) {

0 commit comments

Comments
 (0)