-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
1 parent
8cdb7ca
commit 28a5bc5
Showing
4 changed files
with
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { spawnPromisified } from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import { strictEqual } from 'node:assert'; | ||
import { execPath } from 'node:process'; | ||
import { describe, it } from 'node:test'; | ||
|
||
describe('off-thread hooks', { concurrency: true }, () => { | ||
it('uses only one hooks thread to support multiple application threads', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ | ||
'--no-warnings', | ||
'--import', | ||
`data:text/javascript,${encodeURIComponent(` | ||
import { register } from 'node:module'; | ||
register(${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-log.mjs'))}); | ||
`)}`, | ||
fixtures.path('es-module-loaders/workers-spawned.mjs'), | ||
]); | ||
|
||
strictEqual(stderr, ''); | ||
strictEqual(stdout.split('\n').filter(line => line.startsWith('initialize')).length, 1); | ||
strictEqual(code, 0); | ||
strictEqual(signal, null); | ||
}); | ||
}); |
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,19 @@ | ||
import { writeFileSync } from 'node:fs'; | ||
|
||
let initializeCount = 0; | ||
let resolveCount = 0; | ||
let loadCount = 0; | ||
|
||
export function initialize() { | ||
writeFileSync(1, `initialize ${++initializeCount}\n`); | ||
} | ||
|
||
export function resolve(specifier, context, next) { | ||
writeFileSync(1, `resolve ${++resolveCount} ${specifier}\n`); | ||
return next(specifier, context); | ||
} | ||
|
||
export function load(url, context, next) { | ||
writeFileSync(1, `load ${++loadCount} ${url}\n`); | ||
return next(url, context); | ||
} |
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,3 @@ | ||
import { foo } from './module-named-exports.mjs'; | ||
|
||
console.log(foo); |
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,8 @@ | ||
import { Worker } from 'worker_threads'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
const workerPath = new URL('./worker-log.mjs', import.meta.url); | ||
|
||
// Spawn two workers | ||
new Worker(workerPath); | ||
new Worker(workerPath); |