Skip to content

Commit 4d2299a

Browse files
vivek958aduh95
andauthored
Update test/parallel/test-esm-loader-null-source.js
Co-authored-by: Antoine du Hamel <[email protected]>
1 parent 8835663 commit 4d2299a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

test/parallel/test-esm-loader-null-source.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ const fixtures = require('../common/fixtures');
1212
// Test case: Loader returning null source for CommonJS module
1313
// This should throw ERR_INVALID_RETURN_PROPERTY_VALUE, not ERR_INTERNAL_ASSERTION
1414
{
15+
function load(url, context, next) {
16+
if (url.includes("test-null-source")) {
17+
return { format: "commonjs", source: null, shortCircuit: true };
18+
}
19+
return next(url);
20+
}
1521
const result = spawnSync(
1622
process.execPath,
1723
[
@@ -22,14 +28,7 @@ const fixtures = require('../common/fixtures');
2228
import { register } from 'node:module';
2329
2430
// Register a custom loader that returns null source
25-
const code = 'export function load(url, context, next) {' +
26-
' if (url.includes("test-null-source")) {' +
27-
' return { format: "commonjs", source: null, shortCircuit: true };' +
28-
' }' +
29-
' return next(url);' +
30-
'}';
31-
32-
register('data:text/javascript,' + encodeURIComponent(code));
31+
register('data:text/javascript,export ' + encodeURIComponent(${load}));
3332
3433
await assert.rejects(import('file:///test-null-source.js'), { code: 'ERR_INVALID_RETURN_PROPERTY_VALUE' });
3534
`,

0 commit comments

Comments
 (0)