|
5 | 5 |
|
6 | 6 | require('../common'); |
7 | 7 | const assert = require('assert'); |
| 8 | +const EventEmitter = require('events'); |
| 9 | +const e = new EventEmitter(); |
| 10 | +e.on('hello', assert); |
8 | 11 |
|
9 | 12 | if (process.argv[2] !== 'child') { |
10 | 13 | const tmpdir = require('../common/tmpdir'); |
11 | 14 | tmpdir.refresh(); |
12 | 15 | const { spawnSync } = require('child_process'); |
13 | | - const { output, status, error } = |
14 | | - spawnSync(process.execPath, |
15 | | - ['--expose-internals', process.argv[1], 'child'], |
16 | | - { cwd: tmpdir.path, env: process.env }); |
17 | | - assert.ifError(error); |
18 | | - assert.strictEqual(status, 0, `Exit code: ${status}\n${output}`); |
19 | | -} else { |
20 | | - const EventEmitter = require('events'); |
21 | | - const { errorCache } = require('internal/assert'); |
22 | | - const { writeFileSync } = require('fs'); |
23 | | - const e = new EventEmitter(); |
24 | | - |
25 | | - e.on('hello', assert); |
26 | 16 |
|
27 | 17 | let threw = false; |
28 | 18 | try { |
29 | 19 | e.emit('hello', false); |
30 | 20 | } catch (err) { |
31 | 21 | const frames = err.stack.split('\n'); |
32 | | - const [, filename, line, column] = frames[1].match(/\((.+):(\d+):(\d+)\)/); |
33 | | - // Reset the cache to check again |
34 | | - const size = errorCache.size; |
35 | | - errorCache.delete(`${filename}${line - 1}${column - 1}`); |
36 | | - assert.strictEqual(errorCache.size, size - 1); |
37 | | - const data = `${'\n'.repeat(line - 1)}${' '.repeat(column - 1)}` + |
38 | | - 'ok(failed(badly));'; |
| 22 | + const [, filename, , ] = frames[1].match(/\((.+):(\d+):(\d+)\)/); |
| 23 | + // Spawn a child process to avoid the error having been cached in the assert |
| 24 | + // module's `errorCache` Map. |
39 | 25 |
|
40 | | - writeFileSync(filename, data); |
41 | | - assert.throws( |
42 | | - () => e.emit('hello', false), |
43 | | - { |
44 | | - message: 'false == true' |
45 | | - } |
46 | | - ); |
| 26 | + const { output, status, error } = |
| 27 | + spawnSync(process.execPath, |
| 28 | + [process.argv[1], 'child', filename], |
| 29 | + { cwd: tmpdir.path, env: process.env }); |
| 30 | + assert.ifError(error); |
| 31 | + assert.strictEqual(status, 0, `Exit code: ${status}\n${output}`); |
47 | 32 | threw = true; |
48 | | - |
49 | 33 | } |
50 | | - assert(threw); |
| 34 | + assert.ok(threw); |
| 35 | +} else { |
| 36 | + const { writeFileSync } = require('fs'); |
| 37 | + const [, , , filename, line, column] = process.argv; |
| 38 | + const data = `${'\n'.repeat(line - 1)}${' '.repeat(column - 1)}` + |
| 39 | + 'ok(failed(badly));'; |
| 40 | + |
| 41 | + writeFileSync(filename, data); |
| 42 | + assert.throws( |
| 43 | + () => e.emit('hello', false), |
| 44 | + { |
| 45 | + message: 'false == true' |
| 46 | + } |
| 47 | + ); |
51 | 48 | } |
0 commit comments