diff options
author | MURAKAMI Masahiko <fossamagna2@gmail.com> | 2022-10-03 10:47:32 +0300 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2022-10-05 13:54:20 +0300 |
commit | dc2af265d7e425c920a52aadb03b0ac9a83bd88a (patch) | |
tree | 62f9ccb555777141b46f7f6aedad4783e9dc3bf4 /test | |
parent | 60a05d6dea5624042c9a50a956894a5e51d96703 (diff) |
test: improve lib/internal/source_map/source_map.js coverage
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/source-map/disk-index.map | 30 | ||||
-rw-r--r-- | test/parallel/test-source-map-api.js | 21 |
2 files changed, 51 insertions, 0 deletions
diff --git a/test/fixtures/source-map/disk-index.map b/test/fixtures/source-map/disk-index.map new file mode 100644 index 00000000000..f004518626b --- /dev/null +++ b/test/fixtures/source-map/disk-index.map @@ -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": "./" + } + } + ] +} diff --git a/test/parallel/test-source-map-api.js b/test/parallel/test-source-map-api.js index 03c892419be..39d523b3e15 100644 --- a/test/parallel/test-source-map-api.js +++ b/test/parallel/test-source-map-api.js @@ -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) { |