Skip to content

Commit d761a3a

Browse files
committed
refactor: wip
1 parent da0cb32 commit d761a3a

21 files changed

+192
-159
lines changed

packages/utils/eslint.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ export default tseslint.config(
1818
'n/no-sync': 'off',
1919
},
2020
},
21+
{
22+
files: ['packages/utils/src/lib/profiler/trace-file-utils.ts'],
23+
rules: {
24+
// os.availableParallelism() is checked for existence before use, with fallback to os.cpus().length
25+
'n/no-unsupported-features/node-builtins': 'off',
26+
},
27+
},
2128
{
2229
files: ['**/*.json'],
2330
rules: {

packages/utils/src/lib/execute-process.int.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ process:complete
129129
throwError: true,
130130
}),
131131
),
132-
).rejects.toThrow('Process failed with exit code 1');
132+
).rejects.toThrowError('Process failed with exit code 1');
133133
expect(logger.debug).toHaveBeenCalledWith(
134134
expect.stringMatching(/process:start.*Error: dummy-error/s),
135135
{ force: true },

packages/utils/src/lib/exit-process.int.test.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('subscribeProcessExit', () => {
2525
});
2626

2727
it('should install event listeners for all expected events', () => {
28-
expect(() => subscribeProcessExit({ onError, onExit })).not.toThrow();
28+
expect(() => subscribeProcessExit({ onError, onExit })).not.toThrowError();
2929

3030
expect(processOnSpy).toHaveBeenCalledWith(
3131
'uncaughtException',
@@ -42,86 +42,91 @@ describe('subscribeProcessExit', () => {
4242
});
4343

4444
it('should call onError with error and kind for uncaughtException', () => {
45-
expect(() => subscribeProcessExit({ onError })).not.toThrow();
45+
expect(() => subscribeProcessExit({ onError })).not.toThrowError();
4646

4747
const testError = new Error('Test uncaught exception');
4848

4949
(process as any).emit('uncaughtException', testError);
5050

51-
expect(onError).toHaveBeenCalledWith(testError, 'uncaughtException');
52-
expect(onError).toHaveBeenCalledOnce();
51+
expect(onError).toHaveBeenCalledExactlyOnceWith(
52+
testError,
53+
'uncaughtException',
54+
);
5355
expect(onExit).not.toHaveBeenCalled();
5456
});
5557

5658
it('should call onError with reason and kind for unhandledRejection', () => {
57-
expect(() => subscribeProcessExit({ onError })).not.toThrow();
59+
expect(() => subscribeProcessExit({ onError })).not.toThrowError();
5860

5961
const testReason = 'Test unhandled rejection';
6062

6163
(process as any).emit('unhandledRejection', testReason);
6264

63-
expect(onError).toHaveBeenCalledWith(testReason, 'unhandledRejection');
64-
expect(onError).toHaveBeenCalledOnce();
65+
expect(onError).toHaveBeenCalledExactlyOnceWith(
66+
testReason,
67+
'unhandledRejection',
68+
);
6569
expect(onExit).not.toHaveBeenCalled();
6670
});
6771

6872
it('should call onExit and exit with code 0 for SIGINT', () => {
69-
expect(() => subscribeProcessExit({ onExit })).not.toThrow();
73+
expect(() => subscribeProcessExit({ onExit })).not.toThrowError();
7074

7175
(process as any).emit('SIGINT');
7276

73-
expect(onExit).toHaveBeenCalledOnce();
74-
expect(onExit).toHaveBeenCalledWith(SIGNAL_EXIT_CODES().SIGINT, {
77+
expect(onExit).toHaveBeenCalledExactlyOnceWith(SIGNAL_EXIT_CODES().SIGINT, {
7578
kind: 'signal',
7679
signal: 'SIGINT',
7780
});
7881
expect(onError).not.toHaveBeenCalled();
7982
});
8083

8184
it('should call onExit and exit with code 0 for SIGTERM', () => {
82-
expect(() => subscribeProcessExit({ onExit })).not.toThrow();
85+
expect(() => subscribeProcessExit({ onExit })).not.toThrowError();
8386

8487
(process as any).emit('SIGTERM');
8588

86-
expect(onExit).toHaveBeenCalledOnce();
87-
expect(onExit).toHaveBeenCalledWith(SIGNAL_EXIT_CODES().SIGTERM, {
88-
kind: 'signal',
89-
signal: 'SIGTERM',
90-
});
89+
expect(onExit).toHaveBeenCalledExactlyOnceWith(
90+
SIGNAL_EXIT_CODES().SIGTERM,
91+
{
92+
kind: 'signal',
93+
signal: 'SIGTERM',
94+
},
95+
);
9196
expect(onError).not.toHaveBeenCalled();
9297
});
9398

9499
it('should call onExit and exit with code 0 for SIGQUIT', () => {
95-
expect(() => subscribeProcessExit({ onExit })).not.toThrow();
100+
expect(() => subscribeProcessExit({ onExit })).not.toThrowError();
96101

97102
(process as any).emit('SIGQUIT');
98103

99-
expect(onExit).toHaveBeenCalledOnce();
100-
expect(onExit).toHaveBeenCalledWith(SIGNAL_EXIT_CODES().SIGQUIT, {
101-
kind: 'signal',
102-
signal: 'SIGQUIT',
103-
});
104+
expect(onExit).toHaveBeenCalledExactlyOnceWith(
105+
SIGNAL_EXIT_CODES().SIGQUIT,
106+
{
107+
kind: 'signal',
108+
signal: 'SIGQUIT',
109+
},
110+
);
104111
expect(onError).not.toHaveBeenCalled();
105112
});
106113

107114
it('should call onExit for successful process termination with exit code 0', () => {
108-
expect(() => subscribeProcessExit({ onExit })).not.toThrow();
115+
expect(() => subscribeProcessExit({ onExit })).not.toThrowError();
109116

110117
(process as any).emit('exit', 0);
111118

112-
expect(onExit).toHaveBeenCalledOnce();
113-
expect(onExit).toHaveBeenCalledWith(0, { kind: 'exit' });
119+
expect(onExit).toHaveBeenCalledExactlyOnceWith(0, { kind: 'exit' });
114120
expect(onError).not.toHaveBeenCalled();
115121
expect(processExitSpy).not.toHaveBeenCalled();
116122
});
117123

118124
it('should call onExit for failed process termination with exit code 1', () => {
119-
expect(() => subscribeProcessExit({ onExit })).not.toThrow();
125+
expect(() => subscribeProcessExit({ onExit })).not.toThrowError();
120126

121127
(process as any).emit('exit', 1);
122128

123-
expect(onExit).toHaveBeenCalledOnce();
124-
expect(onExit).toHaveBeenCalledWith(1, { kind: 'exit' });
129+
expect(onExit).toHaveBeenCalledExactlyOnceWith(1, { kind: 'exit' });
125130
expect(onError).not.toHaveBeenCalled();
126131
expect(processExitSpy).not.toHaveBeenCalled();
127132
});

0 commit comments

Comments
 (0)