/
test.ts
57 lines (45 loc) · 2.03 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as childProcess from 'child_process';
import * as path from 'path';
describe('OnUncaughtException integration', () => {
test('should close process on uncaught error with no additional listeners registered', done => {
expect.assertions(3);
const testScriptPath = path.resolve(__dirname, 'no-additional-listener-test-script.js');
childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stdout) => {
expect(err).not.toBeNull();
expect(err?.code).toBe(1);
expect(stdout).not.toBe("I'm alive!");
done();
});
});
test('should close process on uncaught error when additional listeners are registered', done => {
expect.assertions(3);
const testScriptPath = path.resolve(__dirname, 'additional-listener-test-script.js');
childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stdout) => {
expect(err).not.toBeNull();
expect(err?.code).toBe(1);
expect(stdout).not.toBe("I'm alive!");
done();
});
});
describe('with `exitEvenWhenOtherOnUncaughtExceptionHandlersAreRegistered` set to false', () => {
test('should close process on uncaught error with no additional listeners registered', done => {
expect.assertions(3);
const testScriptPath = path.resolve(__dirname, 'mimic-native-behaviour-no-additional-listener-test-script.js');
childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stdout) => {
expect(err).not.toBeNull();
expect(err?.code).toBe(1);
expect(stdout).not.toBe("I'm alive!");
done();
});
});
test('should not close process on uncaught error when additional listeners are registered', done => {
expect.assertions(2);
const testScriptPath = path.resolve(__dirname, 'mimic-native-behaviour-additional-listener-test-script.js');
childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stdout) => {
expect(err).toBeNull();
expect(stdout).toBe("I'm alive!");
done();
});
});
});
});