|
1 | 1 | import { createRequire } from 'node:module' |
2 | 2 | import path from 'node:path' |
| 3 | +import { pathToFileURL } from 'node:url' |
3 | 4 |
|
4 | 5 | import { jest } from '@jest/globals' |
5 | 6 |
|
@@ -244,3 +245,30 @@ test('globalShims options', async () => { |
244 | 245 | expect(syncFn(2)).toBe(2) |
245 | 246 | expect(syncFn(5, 0)).toBe(5) |
246 | 247 | }) |
| 248 | + |
| 249 | +test('support file url', async () => { |
| 250 | + const { createSyncFn } = await import('synckit') |
| 251 | + |
| 252 | + const syncFn = createSyncFn<AsyncWorkerFn>(pathToFileURL(workerCjsPath), {}) |
| 253 | + |
| 254 | + expect(syncFn(1)).toBe(1) |
| 255 | + expect(syncFn(2)).toBe(2) |
| 256 | + expect(syncFn(5, 0)).toBe(5) |
| 257 | + |
| 258 | + expect(() => createSyncFn(new URL('https://example.com'))).toThrow( |
| 259 | + 'The URL must be of scheme file', |
| 260 | + ) |
| 261 | +}) |
| 262 | + |
| 263 | +test('support file url protocol', async () => { |
| 264 | + const { createSyncFn } = await import('synckit') |
| 265 | + |
| 266 | + const syncFn = createSyncFn<AsyncWorkerFn>( |
| 267 | + pathToFileURL(workerCjsPath).href, |
| 268 | + {}, |
| 269 | + ) |
| 270 | + |
| 271 | + expect(syncFn(1)).toBe(1) |
| 272 | + expect(syncFn(2)).toBe(2) |
| 273 | + expect(syncFn(5, 0)).toBe(5) |
| 274 | +}) |
0 commit comments