Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/nodejs/src/repro/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export class Foo {
readonly #bar: string;

constructor(bar: string) {
this.#bar = bar;
}

async baz(): Promise<string> {
await new Promise((resolve) => setTimeout(resolve, 100));
return `Hello ${this.#bar}`;
}
}
20 changes: 20 additions & 0 deletions packages/nodejs/src/repro/makeFoo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect, describe, it, vi } from 'vitest';

import { makeFoo } from './makeFoo.ts';

const mocks = vi.hoisted(() => {
const Foo = vi.fn();
Foo.prototype.baz = vi.fn().mockResolvedValue('Hello fizz');

Check failure on line 7 in packages/nodejs/src/repro/makeFoo.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Use `vi.spyOn` instead
return { Foo };
});
Comment on lines +5 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sucks that --fix is broken for this, but for future reference, this is semantically equivalent and keeps the linter happy:

Suggested change
const mocks = vi.hoisted(() => {
const Foo = vi.fn();
Foo.prototype.baz = vi.fn().mockResolvedValue('Hello fizz');
return { Foo };
});
const mocks = vi.hoisted(() => {
class Foo {
baz = vi.fn().mockResolvedValue('Hello fizz');
}
return { Foo };
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Don't ask me why the linter is happy with this and not the other formulation.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How peculiar.


vi.mock('./foo.ts', () => ({
Foo: mocks.Foo,
}));

describe('makeFoo', () => {
it('should make a Foo', async () => {
const foo = makeFoo('baz');
expect(foo).toBeInstanceOf(mocks.Foo);
});
});
12 changes: 12 additions & 0 deletions packages/nodejs/src/repro/makeFoo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Foo } from './foo.ts';

/**
* Make a Foo
*
* @param bar - The bar to use for the Foo
*
* @returns A Foo
*/
export function makeFoo(bar: string): Foo {
return new Foo(bar);
}
8 changes: 4 additions & 4 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@
lines: 100,
},
'packages/nodejs/**': {
statements: 72.91,
functions: 83.33,
statements: 67.92,
functions: 68.75,
branches: 63.63,
lines: 72.91,
lines: 69.23,
},
'packages/rpc-methods/**': {
statements: 100,
Expand Down Expand Up @@ -139,4 +139,4 @@
},
},
},
});
});

Check failure on line 142 in vitest.config.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Insert `⏎`
Loading