Skip to content

Commit b741c79

Browse files
authored
chore(node-runtime-worker-thread): use strict TS flag for tests (#2155)
... and remove the non-strict TS config from this repo entirely 🎉
1 parent 1685c71 commit b741c79

File tree

9 files changed

+29
-51
lines changed

9 files changed

+29
-51
lines changed

configs/tsconfig-mongosh/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"description": "Shared Mongosh Typescript configuration",
66
"license": "SSPL",
77
"files": [
8-
"tsconfig.common.json",
9-
"tsconfig.test.json"
8+
"tsconfig.common.json"
109
],
1110
"peerDependencies": {
1211
"typescript": "^5.3.3"

configs/tsconfig-mongosh/tsconfig.test.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/node-runtime-worker-thread/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"node": ">=14.15.1"
1818
},
1919
"scripts": {
20-
"test": "cross-env TS_NODE_PROJECT=./tsconfig.test.json mocha -r \"../../scripts/import-expansions.js\" -r \"./tests/register-worker.js \" --timeout 15000 -r ts-node/register \"./src/**/*.spec.ts\"",
20+
"test": "mocha -r \"../../scripts/import-expansions.js\" -r \"./tests/register-worker.js \" --timeout 15000 -r ts-node/register \"./src/**/*.spec.ts\"",
2121
"pretest-ci": "node ../../scripts/run-if-package-requested.js npm run webpack-build -- --no-stats --no-devtool",
2222
"test-ci": "node ../../scripts/run-if-package-requested.js npm test",
2323
"test-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test",

packages/node-runtime-worker-thread/src/index.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('WorkerRuntime', function () {
4848
nodb: true,
4949
});
5050

51-
let err: Error;
51+
let err!: Error;
5252

5353
try {
5454
await runtime.evaluate('throw new TypeError("Oh no, types!")');
@@ -219,7 +219,7 @@ describe('WorkerRuntime', function () {
219219
const runtime = new WorkerRuntime('mongodb://nodb/', dummyOptions, {
220220
nodb: true,
221221
});
222-
let err: Error;
222+
let err!: Error;
223223
try {
224224
await Promise.all([
225225
runtime.evaluate('while(true){}'),
@@ -246,7 +246,7 @@ describe('WorkerRuntime', function () {
246246

247247
await runtime.waitForRuntimeToBeReady();
248248

249-
let err: Error;
249+
let err!: Error;
250250

251251
try {
252252
await Promise.all([
@@ -329,7 +329,7 @@ describe('WorkerRuntime', function () {
329329

330330
await runtime.waitForRuntimeToBeReady();
331331

332-
let err: Error;
332+
let err!: Error;
333333

334334
try {
335335
await Promise.all([

packages/node-runtime-worker-thread/src/lock.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Lock', function () {
2525
// eslint-disable-next-line @typescript-eslint/no-floating-promises
2626
lock.lock();
2727

28-
let err: Error;
28+
let err!: Error;
2929

3030
try {
3131
// eslint-disable-next-line @typescript-eslint/no-floating-promises

packages/node-runtime-worker-thread/src/rpc.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('rpc', function () {
2727
woof(...args: any[]): string;
2828
neverResolves(...args: any[]): void;
2929
}>;
30-
let exposed: Exposed<unknown> | null;
30+
let exposed: Exposed<unknown>; // adding `| null` breaks TS type inference
3131

3232
afterEach(function () {
3333
if (messageBus) {
@@ -36,12 +36,12 @@ describe('rpc', function () {
3636

3737
if (caller) {
3838
caller[cancel]();
39-
caller = null;
39+
caller = null as any;
4040
}
4141

4242
if (exposed) {
4343
exposed[close]();
44-
exposed = null;
44+
exposed = null as any;
4545
}
4646
});
4747

@@ -74,7 +74,7 @@ describe('rpc', function () {
7474
messageBus
7575
);
7676

77-
let err: Error;
77+
let err!: Error;
7878

7979
try {
8080
// eslint-disable-next-line @typescript-eslint/await-thenable
@@ -136,7 +136,7 @@ describe('rpc', function () {
136136
messageBus = createMockRpcMesageBus();
137137
caller = createCaller(['meow'], messageBus);
138138

139-
messageBus.addEventListener('message', (data) => {
139+
messageBus.addEventListener('message', (data: unknown) => {
140140
expect(data).to.have.property('func', 'meow');
141141
done();
142142
});
@@ -150,7 +150,7 @@ describe('rpc', function () {
150150
it('stops all in-flight evaluations', async function () {
151151
messageBus = createMockRpcMesageBus();
152152
caller = createCaller(['neverResolves'], messageBus);
153-
let err: Error;
153+
let err!: Error;
154154
try {
155155
await Promise.all([
156156
caller.neverResolves(),

packages/node-runtime-worker-thread/src/rpc.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ export type Exposed<T> = { [k in keyof T]: T[k] & { close(): void } } & {
5050
[close]: () => void;
5151
};
5252

53-
export function exposeAll<O>(obj: O, messageBus: RPCMessageBus): Exposed<O> {
53+
export function exposeAll<O extends object>(
54+
obj: O,
55+
messageBus: RPCMessageBus
56+
): Exposed<O> {
5457
Object.entries(obj as Record<string, any>).forEach(([key, val]) => {
5558
const { close } = expose(
5659
key,

packages/node-runtime-worker-thread/src/worker-runtime.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ describe('worker-runtime', function () {
6363

6464
if (caller) {
6565
caller[cancel]();
66-
caller = null;
66+
caller = null as any;
6767
}
6868
});
6969

7070
it('should throw if worker is not initialized yet', async function () {
7171
const { evaluate } = caller;
7272

73-
let err: Error;
73+
let err!: Error;
7474

7575
try {
7676
await evaluate('1 + 1');
@@ -161,18 +161,18 @@ describe('worker-runtime', function () {
161161
describe('shell-api results', function () {
162162
const testServer = startSharedTestServer();
163163
const db = `test-db-${Date.now().toString(16)}`;
164-
let exposed: Exposed<unknown> | null;
164+
let exposed: Exposed<unknown>; // adding `| null` breaks TS type inference
165165

166166
afterEach(function () {
167167
if (exposed) {
168168
exposed[close]();
169-
exposed = null;
169+
exposed = null as any;
170170
}
171171
});
172172

173173
type CommandTestRecord =
174174
| [string | string[], string]
175-
| [string | string[], string, any];
175+
| [string | string[], string | null, any];
176176

177177
const showCommand: CommandTestRecord[] = [
178178
[
@@ -323,11 +323,11 @@ describe('worker-runtime', function () {
323323
.forEach((testCase) => {
324324
const [commands, resultType, printable] = testCase;
325325

326-
let command: string | undefined;
326+
let command: string;
327327
let prepare: undefined | string[];
328328

329329
if (Array.isArray(commands)) {
330-
command = commands.pop();
330+
command = commands.pop()!;
331331
prepare = commands;
332332
} else {
333333
command = commands;
@@ -376,7 +376,7 @@ describe('worker-runtime', function () {
376376

377377
await init('mongodb://nodb/', dummyOptions, { nodb: true });
378378

379-
let err: Error;
379+
let err!: Error;
380380
try {
381381
await evaluate('throw new TypeError("Oh no, types!")');
382382
} catch (e: any) {
@@ -396,7 +396,7 @@ describe('worker-runtime', function () {
396396

397397
await init('mongodb://nodb/', dummyOptions, { nodb: true });
398398

399-
let err: Error;
399+
let err!: Error;
400400
try {
401401
await evaluate(
402402
'throw Object.assign(new TypeError("Oh no, types!"), { errInfo: { message: "wrong type :S" } })'
@@ -430,7 +430,7 @@ describe('worker-runtime', function () {
430430
const { init, evaluate } = caller;
431431
await init('mongodb://nodb/', dummyOptions, { nodb: true });
432432

433-
let err: Error;
433+
let err!: Error;
434434

435435
try {
436436
await Promise.all([
@@ -665,7 +665,7 @@ describe('worker-runtime', function () {
665665

666666
await init('mongodb://nodb/', dummyOptions, { nodb: true });
667667

668-
let err: Error;
668+
let err!: Error;
669669

670670
try {
671671
await Promise.all([
@@ -695,7 +695,7 @@ describe('worker-runtime', function () {
695695

696696
await init('mongodb://nodb/', dummyOptions, { nodb: true });
697697

698-
let err: Error;
698+
let err!: Error;
699699

700700
try {
701701
await Promise.all([

packages/node-runtime-worker-thread/tsconfig.test.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)