-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function a(): 'a' | ||
|
||
export function b(): 'b' | ||
|
||
export default a | ||
|
||
export function foobar<V>(o: { foobar: V }): V | ||
export function asyncFoobar<V>(o: { foobar: V }): Promise<V> | ||
|
||
export function args<A>(...args: A[]): A | ||
export function asyncArgs<A extends any[]>(...args: A): Promise<A> | ||
|
||
export const digit: 4 | ||
|
||
export function returnsAny(): any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { dirname, resolve } from 'node:path' | ||
import Tinypool from 'tinypool' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
|
||
test('runner worker_threads test', async () => { | ||
const { runner } = new Tinypool({ | ||
filename: resolve(__dirname, 'fixtures/multiple.js'), | ||
runtime: 'worker_threads', | ||
}).withRunner<typeof import('./fixtures/multiple.js')>() | ||
|
||
expect((await runner.a()) satisfies 'a').toBe('a') | ||
expect((await runner.b()) satisfies 'b').toBe('b') | ||
expect(await runner.foobar({ foobar: 1 })).toBe(1) | ||
expect((await runner.asyncFoobar({ foobar: 1 })) satisfies 1).toBe(1) | ||
expect(await runner.args(1, 2, 3, { foobar: 1 })).toEqual([ | ||
1, | ||
2, | ||
3, | ||
{ foobar: 1 }, | ||
]) | ||
expect( | ||
(await runner.asyncArgs(1, 2, 3, { foobar: 1 })) satisfies [ | ||
1, | ||
2, | ||
3, | ||
{ foobar: 1 }, | ||
] | ||
).toEqual([1, 2, 3, { foobar: 1 }]) | ||
}) | ||
|
||
test('runner child_process test', async () => { | ||
const { runner } = new Tinypool({ | ||
filename: resolve(__dirname, 'fixtures/multiple.js'), | ||
runtime: 'child_process', | ||
}).withRunner<typeof import('./fixtures/multiple.js')>() | ||
|
||
expect((await runner.a()) satisfies 'a').toBe('a') | ||
expect((await runner.b()) satisfies 'b').toBe('b') | ||
expect(await runner.foobar({ foobar: 1 })).toBe(1) | ||
expect((await runner.asyncFoobar({ foobar: 1 })) satisfies 1).toBe(1) | ||
expect(await runner.args('baz')).toStrictEqual(['baz']) | ||
expect( | ||
(await runner.asyncArgs('baz' as const)) satisfies ['baz'] | ||
).toStrictEqual(['baz']) | ||
|
||
expect(() => runner.args(1, 2, 3)).toThrow( | ||
'doesn’t support args array in child_process runtime' | ||
) | ||
expect(() => runner.asyncArgs(1, 2, 3)).toThrow( | ||
'doesn’t support args array in child_process runtime' | ||
) | ||
}) |