From 705e85e736bda41222d3ed728b06915655067f36 Mon Sep 17 00:00:00 2001 From: italo jose Date: Wed, 1 Jun 2022 11:52:35 -0300 Subject: [PATCH] test: improve code coverage for SourceMap class Cover malformed mappings scenario. PR-URL: https://github.com/nodejs/node/pull/43285 Reviewed-By: Ben Coe Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/parallel/test-source-map-api.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/parallel/test-source-map-api.js b/test/parallel/test-source-map-api.js index b8ff59e365e2e9..f66a9af94784c7 100644 --- a/test/parallel/test-source-map-api.js +++ b/test/parallel/test-source-map-api.js @@ -99,6 +99,20 @@ const { readFileSync } = require('fs'); assert.notStrictEqual(payload.sources, sourceMap.payload.sources); } +// findEntry() must return empty object instead error when +// receive a malformed mappings. +{ + const payload = JSON.parse(readFileSync( + require.resolve('../fixtures/source-map/disk.map'), 'utf8' + )); + payload.mappings = ';;;;;;;;;'; + + const sourceMap = new SourceMap(payload); + const result = sourceMap.findEntry(0, 5); + assert.strictEqual(typeof result, 'object'); + assert.strictEqual(Object.keys(result).length, 0); +} + // Test various known decodings to ensure decodeVLQ works correctly. { function makeMinimalMap(column) {