mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 01:35:51 +00:00

test-assert.js contains a test that writes to the source tree, requires an internal module, and depends on modules not needed by the plethora of other test cases in the file. Move it to its own file so that there are not side effects in test-assert.js and so that it can be refactored to not write to the source tree. PR-URL: https://github.com/nodejs/node/pull/20861 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
// Flags: --expose-internals
|
|
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
const EventEmitter = require('events');
|
|
const { errorCache } = require('internal/assert');
|
|
const { writeFileSync, unlinkSync } = require('fs');
|
|
|
|
// Do not read filesystem for error messages in builtin modules.
|
|
{
|
|
const e = new EventEmitter();
|
|
|
|
e.on('hello', assert);
|
|
|
|
let threw = false;
|
|
try {
|
|
e.emit('hello', false);
|
|
} catch (err) {
|
|
const frames = err.stack.split('\n');
|
|
const [, filename, line, column] = frames[1].match(/\((.+):(\d+):(\d+)\)/);
|
|
// Reset the cache to check again
|
|
const size = errorCache.size;
|
|
errorCache.delete(`${filename}${line - 1}${column - 1}`);
|
|
assert.strictEqual(errorCache.size, size - 1);
|
|
const data = `${'\n'.repeat(line - 1)}${' '.repeat(column - 1)}` +
|
|
'ok(failed(badly));';
|
|
try {
|
|
writeFileSync(filename, data);
|
|
assert.throws(
|
|
() => e.emit('hello', false),
|
|
{
|
|
message: 'false == true'
|
|
}
|
|
);
|
|
threw = true;
|
|
} finally {
|
|
unlinkSync(filename);
|
|
}
|
|
}
|
|
assert(threw);
|
|
}
|