@@ -10,8 +10,8 @@ describe('Loader hooks', { concurrency: true }, () => { |
10 | 10 | const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ |
11 | 11 | '--no-warnings', |
12 | 12 | '--experimental-loader', |
13 | | - fixtures.fileURL('/es-module-loaders/hooks-input.mjs'), |
14 | | - fixtures.path('/es-modules/json-modules.mjs'), |
| 13 | + fixtures.fileURL('es-module-loaders/hooks-input.mjs'), |
| 14 | + fixtures.path('es-modules/json-modules.mjs'), |
15 | 15 | ]); |
16 | 16 |
|
17 | 17 | assert.strictEqual(stderr, ''); |
@@ -23,6 +23,8 @@ describe('Loader hooks', { concurrency: true }, () => { |
23 | 23 | assert.match(lines[1], /{"source":{"type":"Buffer","data":\[.*\]},"format":"module","shortCircuit":true}/); |
24 | 24 | assert.match(lines[2], /{"url":"file:\/\/\/.*\/experimental\.json","format":"test","shortCircuit":true}/); |
25 | 25 | assert.match(lines[3], /{"source":{"type":"Buffer","data":\[.*\]},"format":"json","shortCircuit":true}/); |
| 26 | + assert.strictEqual(lines[4], ''); |
| 27 | + assert.strictEqual(lines.length, 5); |
26 | 28 | }); |
27 | 29 |
|
28 | 30 | it('are called with all expected arguments using register function', async () => { |
@@ -32,8 +34,8 @@ describe('Loader hooks', { concurrency: true }, () => { |
32 | 34 | '--input-type=module', |
33 | 35 | '--eval', |
34 | 36 | "import { register } from 'node:module';" + |
35 | | - `register(${JSON.stringify(fixtures.fileURL('/es-module-loaders/hooks-input.mjs'))});` + |
36 | | - `await import(${JSON.stringify(fixtures.fileURL('/es-modules/json-modules.mjs'))});`, |
| 37 | + `register(${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-input.mjs'))});` + |
| 38 | + `await import(${JSON.stringify(fixtures.fileURL('es-modules/json-modules.mjs'))});`, |
37 | 39 | ]); |
38 | 40 |
|
39 | 41 | assert.strictEqual(stderr, ''); |
@@ -45,6 +47,8 @@ describe('Loader hooks', { concurrency: true }, () => { |
45 | 47 | assert.match(lines[1], /{"source":{"type":"Buffer","data":\[.*\]},"format":"module","shortCircuit":true}/); |
46 | 48 | assert.match(lines[2], /{"url":"file:\/\/\/.*\/experimental\.json","format":"test","shortCircuit":true}/); |
47 | 49 | assert.match(lines[3], /{"source":{"type":"Buffer","data":\[.*\]},"format":"json","shortCircuit":true}/); |
| 50 | + assert.strictEqual(lines[4], ''); |
| 51 | + assert.strictEqual(lines.length, 5); |
48 | 52 | }); |
49 | 53 |
|
50 | 54 | describe('should handle never-settling hooks in ESM files', { concurrency: true }, () => { |
@@ -340,7 +344,6 @@ describe('Loader hooks', { concurrency: true }, () => { |
340 | 344 |
|
341 | 345 | it('should handle symbol', async () => { |
342 | 346 | const { code, signal, stdout } = await spawnPromisified(execPath, [ |
343 | | - '--no-warnings', |
344 | 347 | '--experimental-loader', |
345 | 348 | 'data:text/javascript,throw Symbol("symbol descriptor")', |
346 | 349 | fixtures.path('empty.js'), |
@@ -524,19 +527,14 @@ describe('Loader hooks', { concurrency: true }, () => { |
524 | 527 | const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ |
525 | 528 | '--no-warnings', |
526 | 529 | '--experimental-loader', |
527 | | - fixtures.fileURL('/es-module-loaders/hooks-initialize.mjs'), |
| 530 | + fixtures.fileURL('es-module-loaders/hooks-initialize.mjs'), |
528 | 531 | '--input-type=module', |
529 | 532 | '--eval', |
530 | 533 | 'import os from "node:os";', |
531 | 534 | ]); |
532 | 535 |
|
533 | | - const lines = stdout.trim().split('\n'); |
534 | | - |
535 | | - assert.strictEqual(lines.length, 1); |
536 | | - assert.strictEqual(lines[0], 'hooks initialize 1'); |
537 | | - |
538 | 536 | assert.strictEqual(stderr, ''); |
539 | | - |
| 537 | + assert.deepStrictEqual(stdout.split('\n'), ['hooks initialize 1', '']); |
540 | 538 | assert.strictEqual(code, 0); |
541 | 539 | assert.strictEqual(signal, null); |
542 | 540 | }); |
@@ -567,7 +565,10 @@ describe('Loader hooks', { concurrency: true }, () => { |
567 | 565 | ]); |
568 | 566 |
|
569 | 567 | assert.strictEqual(stderr, ''); |
570 | | - assert.deepStrictEqual(stdout.split('\n'), ['register ok', 'message initialize', 'message resolve node:os', '']); |
| 568 | + assert.deepStrictEqual(stdout.split('\n'), [ 'register ok', |
| 569 | + 'message initialize', |
| 570 | + 'message resolve node:os', |
| 571 | + '' ]); |
571 | 572 |
|
572 | 573 | assert.strictEqual(code, 0); |
573 | 574 | assert.strictEqual(signal, null); |
@@ -605,18 +606,14 @@ describe('Loader hooks', { concurrency: true }, () => { |
605 | 606 | const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ |
606 | 607 | '--no-warnings', |
607 | 608 | '--require', |
608 | | - fixtures.path('/es-module-loaders/register-loader.cjs'), |
| 609 | + fixtures.path('es-module-loaders/register-loader.cjs'), |
609 | 610 | '--input-type=module', |
610 | 611 | '--eval', |
611 | 612 | 'import "node:os";', |
612 | 613 | ]); |
613 | 614 |
|
614 | | - const lines = stdout.split('\n'); |
615 | | - |
616 | | - assert.strictEqual(lines[0], 'resolve passthru'); |
617 | | - |
618 | 615 | assert.strictEqual(stderr, ''); |
619 | | - |
| 616 | + assert.deepStrictEqual(stdout.split('\n'), ['resolve passthru', 'resolve passthru', '']); |
620 | 617 | assert.strictEqual(code, 0); |
621 | 618 | assert.strictEqual(signal, null); |
622 | 619 | }); |
@@ -625,20 +622,16 @@ describe('Loader hooks', { concurrency: true }, () => { |
625 | 622 | const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ |
626 | 623 | '--no-warnings', |
627 | 624 | '--import', |
628 | | - fixtures.fileURL('/es-module-loaders/register-loader.mjs'), |
| 625 | + fixtures.fileURL('es-module-loaders/register-loader.mjs'), |
629 | 626 | '--input-type=module', |
630 | 627 | '--eval', |
631 | 628 | ` |
632 | 629 | import 'node:os'; |
633 | 630 | `, |
634 | 631 | ]); |
635 | 632 |
|
636 | | - const lines = stdout.split('\n'); |
637 | | - |
638 | | - assert.strictEqual(lines[0], 'resolve passthru'); |
639 | | - |
640 | 633 | assert.strictEqual(stderr, ''); |
641 | | - |
| 634 | + assert.deepStrictEqual(stdout.split('\n'), ['resolve passthru', '']); |
642 | 635 | assert.strictEqual(code, 0); |
643 | 636 | assert.strictEqual(signal, null); |
644 | 637 | }); |
@@ -651,25 +644,22 @@ describe('Loader hooks', { concurrency: true }, () => { |
651 | 644 | ` |
652 | 645 | import {register} from 'node:module'; |
653 | 646 | console.log('result', register( |
654 | | - ${JSON.stringify(fixtures.fileURL('/es-module-loaders/hooks-initialize.mjs'))} |
| 647 | + ${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-initialize.mjs'))} |
655 | 648 | )); |
656 | 649 | console.log('result', register( |
657 | | - ${JSON.stringify(fixtures.fileURL('/es-module-loaders/hooks-initialize.mjs'))} |
| 650 | + ${JSON.stringify(fixtures.fileURL('es-module-loaders/hooks-initialize.mjs'))} |
658 | 651 | )); |
659 | 652 |
|
660 | 653 | await import('node:os'); |
661 | 654 | `, |
662 | 655 | ]); |
663 | 656 |
|
664 | | - const lines = stdout.split('\n'); |
665 | | - |
666 | | - assert.strictEqual(lines[0], 'result 1'); |
667 | | - assert.strictEqual(lines[1], 'result 2'); |
668 | | - assert.strictEqual(lines[2], 'hooks initialize 1'); |
669 | | - assert.strictEqual(lines[3], 'hooks initialize 2'); |
670 | | - |
671 | 657 | assert.strictEqual(stderr, ''); |
672 | | - |
| 658 | + assert.deepStrictEqual(stdout.split('\n'), [ 'result 1', |
| 659 | + 'result 2', |
| 660 | + 'hooks initialize 1', |
| 661 | + 'hooks initialize 2', |
| 662 | + '' ]); |
673 | 663 | assert.strictEqual(code, 0); |
674 | 664 | assert.strictEqual(signal, null); |
675 | 665 | }); |
|