-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
5 changed files
with
157 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export function a(): 'a' | ||
|
||
export function b(): 'b' | ||
|
||
export default a | ||
|
||
export function identity<V>(v: V): V | ||
export function identityAsync<V>(v: V): Promise<V> | ||
|
||
export function foobar<V>(o: { foobar: V }): V | ||
export function foobarAsync<V>(o: { foobar: V }): Promise<V> | ||
|
||
export function args<A>(...args: A[]): A | ||
export function argsAsync<A extends any[]>(...args: A): Promise<A> | ||
|
||
export function firstArg(a: 1, b?: 2): 1 | ||
export function firstArgAsync(a: 2, b?: 3): Promise<2> | ||
|
||
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,61 @@ | ||
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.identity(123)).toBe(123) | ||
expect((await runner.identityAsync(123)) satisfies 123).toBe(123) | ||
|
||
expect(await runner.foobar({ foobar: 1 })).toBe(1) | ||
expect((await runner.foobarAsync({ foobar: 1 })) satisfies 1).toBe(1) | ||
|
||
expect((await runner.firstArg(1)) satisfies 1).toBe(1) | ||
expect((await runner.firstArgAsync(2)) satisfies 2).toBe(2) | ||
|
||
// @ts-expect-error should throw | ||
expect(() => runner.firstArg(1, 2)).toThrow('doesn’t support args array') | ||
// @ts-expect-error should throw | ||
expect(() => runner.firstArgAsync(2, 3)).toThrow('doesn’t support args array') | ||
// @ts-expect-error should throw | ||
expect(() => runner.args(1, 2, 3)).toThrow('doesn’t support args array') | ||
// @ts-expect-error should throw | ||
expect(() => runner.argsAsync(1, 2, 3)).toThrow('doesn’t support args array') | ||
}) | ||
|
||
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.identity(123)).toBe(123) | ||
expect((await runner.identityAsync(123)) satisfies 123).toBe(123) | ||
|
||
expect(await runner.foobar({ foobar: 1 })).toBe(1) | ||
expect((await runner.foobarAsync({ foobar: 1 })) satisfies 1).toBe(1) | ||
|
||
expect((await runner.firstArg(1)) satisfies 1).toBe(1) | ||
expect((await runner.firstArgAsync(2)) satisfies 2).toBe(2) | ||
|
||
// @ts-expect-error should throw | ||
expect(() => runner.firstArg(1, 2)).toThrow('doesn’t support args array') | ||
// @ts-expect-error should throw | ||
expect(() => runner.firstArgAsync(2, 3)).toThrow('doesn’t support args array') | ||
// @ts-expect-error should throw | ||
expect(() => runner.args(1, 2, 3)).toThrow('doesn’t support args array') | ||
// @ts-expect-error should throw | ||
expect(() => runner.argsAsync(1, 2, 3)).toThrow('doesn’t support args array') | ||
}) |