@@ -143,6 +143,65 @@ test('filename can be a file:// URL to an ESM module', async () => {
143143 expect ( result ) . toBe ( 42 )
144144} )
145145
146+ test ( 'filename can be a URL instance' , async ( ) => {
147+ const worker = new Tinypool ( {
148+ filename : pathToFileURL ( resolve ( __dirname , 'fixtures/eval.js' ) ) ,
149+ } )
150+ const result = await worker . run ( '42' )
151+ expect ( result ) . toBe ( 42 )
152+ } )
153+
154+ test ( 'filename can be a URL instance to an ESM module' , async ( ) => {
155+ const worker = new Tinypool ( {
156+ filename : pathToFileURL ( resolve ( __dirname , 'fixtures/esm-export.mjs' ) ) ,
157+ } )
158+ const result = await worker . run ( '42' )
159+ expect ( result ) . toBe ( 42 )
160+ } )
161+
162+ test ( 'run() accepts a URL instance as filename' , async ( ) => {
163+ const worker = new Tinypool ( )
164+ const result = await worker . run ( '42' , {
165+ filename : pathToFileURL ( resolve ( __dirname , 'fixtures/eval.js' ) ) ,
166+ } )
167+ expect ( result ) . toBe ( 42 )
168+ } )
169+
170+ test ( 'a URL instance overrides the pool filename per task' , async ( ) => {
171+ const worker = new Tinypool ( {
172+ filename : resolve ( __dirname , 'fixtures/eval.js' ) ,
173+ } )
174+ const result = await worker . run ( '42' , {
175+ filename : pathToFileURL ( resolve ( __dirname , 'fixtures/esm-export.mjs' ) ) ,
176+ } )
177+ expect ( result ) . toBe ( 42 )
178+ } )
179+
180+ test ( 'filename can be a URL instance with runtime child_process' , async ( ) => {
181+ const worker = new Tinypool ( {
182+ filename : pathToFileURL ( resolve ( __dirname , 'fixtures/eval.js' ) ) ,
183+ runtime : 'child_process' ,
184+ } )
185+ const result = await worker . run ( '42' )
186+ expect ( result ) . toBe ( 42 )
187+ } )
188+
189+ test ( 'a non-file: URL instance is passed through to the worker' , async ( ) => {
190+ const worker = new Tinypool ( {
191+ filename : new URL ( 'data:text/javascript,export default () => 42' ) ,
192+ } )
193+ const result = await worker . run ( null )
194+ expect ( result ) . toBe ( 42 )
195+ } )
196+
197+ test ( 'run() rejects a filename that is neither string nor URL' , async ( ) => {
198+ const worker = new Tinypool ( )
199+ await expect (
200+ // @ts -expect-error -- deliberately wrong type
201+ worker . run ( '42' , { filename : 42 } )
202+ ) . rejects . toThrow ( 'filename must be provided to run() or in options object' )
203+ } )
204+
146205test ( 'named tasks work' , async ( ) => {
147206 const worker = new Tinypool ( {
148207 filename : resolve ( __dirname , 'fixtures/multiple.js' ) ,
0 commit comments