|
| 1 | +import { spawnPromisified } from '../common/index.mjs'; |
| 2 | +import * as fixtures from '../common/fixtures.mjs'; |
| 3 | +import assert from 'node:assert'; |
| 4 | +import { execPath } from 'node:process'; |
| 5 | +import { describe, it } from 'node:test'; |
| 6 | + |
| 7 | +describe('--entry-url', { concurrency: true }, () => { |
| 8 | + it('should reject loading absolute path that contains %', async () => { |
| 9 | + const { code, signal, stderr, stdout } = await spawnPromisified( |
| 10 | + execPath, |
| 11 | + [ |
| 12 | + '--entry-url', |
| 13 | + fixtures.path('es-modules/test-esm-double-encoding-native%20.mjs'), |
| 14 | + ] |
| 15 | + ); |
| 16 | + |
| 17 | + assert.match(stderr, /ERR_MODULE_NOT_FOUND/); |
| 18 | + assert.strictEqual(stdout, ''); |
| 19 | + assert.strictEqual(code, 1); |
| 20 | + assert.strictEqual(signal, null); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should support loading absolute Unix path properly encoded', async () => { |
| 24 | + const { code, signal, stderr, stdout } = await spawnPromisified( |
| 25 | + execPath, |
| 26 | + [ |
| 27 | + '--entry-url', |
| 28 | + fixtures.fileURL('es-modules/test-esm-double-encoding-native%20.mjs').pathname, |
| 29 | + ] |
| 30 | + ); |
| 31 | + |
| 32 | + assert.match(stderr, /--entry-url is an experimental feature/); |
| 33 | + assert.strictEqual(stdout, ''); |
| 34 | + assert.strictEqual(code, 0); |
| 35 | + assert.strictEqual(signal, null); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should support loading absolute URLs', async () => { |
| 39 | + const { code, signal, stderr, stdout } = await spawnPromisified( |
| 40 | + execPath, |
| 41 | + [ |
| 42 | + '--entry-url', |
| 43 | + fixtures.fileURL('printA.js'), |
| 44 | + ] |
| 45 | + ); |
| 46 | + |
| 47 | + assert.match(stderr, /--entry-url is an experimental feature/); |
| 48 | + assert.match(stdout, /^A\r?\n$/); |
| 49 | + assert.strictEqual(code, 0); |
| 50 | + assert.strictEqual(signal, null); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should support loading relative URLs', async () => { |
| 54 | + const { code, signal, stderr, stdout } = await spawnPromisified( |
| 55 | + execPath, |
| 56 | + [ |
| 57 | + '--entry-url', |
| 58 | + './printA.js?key=value', |
| 59 | + ], |
| 60 | + { |
| 61 | + cwd: fixtures.fileURL('./'), |
| 62 | + } |
| 63 | + ); |
| 64 | + |
| 65 | + assert.match(stderr, /--entry-url is an experimental feature/); |
| 66 | + assert.match(stdout, /^A\r?\n$/); |
| 67 | + assert.strictEqual(code, 0); |
| 68 | + assert.strictEqual(signal, null); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should support loading `data:` URLs', async () => { |
| 72 | + const { code, signal, stderr, stdout } = await spawnPromisified( |
| 73 | + execPath, |
| 74 | + [ |
| 75 | + '--entry-url', |
| 76 | + 'data:text/javascript,console.log(0)', |
| 77 | + ], |
| 78 | + ); |
| 79 | + |
| 80 | + assert.match(stderr, /--entry-url is an experimental feature/); |
| 81 | + assert.match(stdout, /^0\r?\n$/); |
| 82 | + assert.strictEqual(code, 0); |
| 83 | + assert.strictEqual(signal, null); |
| 84 | + }); |
| 85 | +}); |
0 commit comments