|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Regression test for https://github.com/nodejs/node/issues/63169 |
| 4 | +// When --enable-source-maps is enabled but the script has no source map, |
| 5 | +// assert(false) should throw AssertionError, not TypeError ERR_INVALID_ARG_TYPE. |
| 6 | + |
| 7 | +require('../common'); |
| 8 | +const assert = require('node:assert'); |
| 9 | +const { spawnSync } = require('node:child_process'); |
| 10 | +const { test } = require('node:test'); |
| 11 | +const fixtures = require('../common/fixtures'); |
| 12 | + |
| 13 | +function runWithSourceMaps(fixture) { |
| 14 | + return spawnSync(process.execPath, [ |
| 15 | + '--enable-source-maps', |
| 16 | + fixtures.path('source-map', fixture), |
| 17 | + ]); |
| 18 | +} |
| 19 | + |
| 20 | +test('assert(false) in .mjs with --enable-source-maps throws AssertionError', () => { |
| 21 | + const result = runWithSourceMaps('assert-no-source-map.mjs'); |
| 22 | + |
| 23 | + assert.strictEqual(result.status, 0, `process exited with ${result.status}: ${result.stderr}`); |
| 24 | + const lines = result.stdout.toString().trim().split('\n'); |
| 25 | + assert.strictEqual(lines[0], 'AssertionError'); |
| 26 | + assert.strictEqual(lines[1], 'ERR_ASSERTION'); |
| 27 | + assert.match(lines[2], /assert\(false\)/); |
| 28 | +}); |
| 29 | + |
| 30 | +test('assert.ok(false) in .cjs with --enable-source-maps throws AssertionError', () => { |
| 31 | + const result = runWithSourceMaps('assert-no-source-map.cjs'); |
| 32 | + |
| 33 | + assert.strictEqual(result.status, 0, `process exited with ${result.status}: ${result.stderr}`); |
| 34 | + const lines = result.stdout.toString().trim().split('\n'); |
| 35 | + assert.strictEqual(lines[0], 'AssertionError'); |
| 36 | + assert.strictEqual(lines[1], 'ERR_ASSERTION'); |
| 37 | + assert.match(lines[2], /assert\.ok\(false\)/); |
| 38 | +}); |
0 commit comments