-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-esm-loader-default-resolver.mjs
More file actions
66 lines (60 loc) · 2.43 KB
/
test-esm-loader-default-resolver.mjs
File metadata and controls
66 lines (60 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { spawnPromisified } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
describe('default resolver', () => {
// In these tests `byop` is an acronym for "bring your own protocol", and is the
// protocol our byop-dummy-loader.mjs can load
it('should accept foreign schemas without exception (e.g. byop://something/or-other)', async () => {
const { code, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
'--experimental-loader',
fixtures.fileURL('/es-module-loaders/byop-dummy-loader.mjs'),
'--input-type=module',
'--eval',
"import 'byop://1/index.mjs'",
]);
assert.strictEqual(code, 0);
assert.strictEqual(stdout.trim(), 'index.mjs!');
assert.strictEqual(stderr, '');
});
it('should resolve foreign schemas by doing regular url absolutization', async () => {
const { code, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
'--experimental-loader',
fixtures.fileURL('/es-module-loaders/byop-dummy-loader.mjs'),
'--input-type=module',
'--eval',
"import 'byop://1/index2.mjs'",
]);
assert.strictEqual(code, 0);
assert.strictEqual(stdout.trim(), '42');
assert.strictEqual(stderr, '');
});
// In this test, `byoe` is an acronym for "bring your own extension"
it('should accept foreign extensions without exception (e.g. ..//something.byoe)', async () => {
const { code, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
'--experimental-loader',
fixtures.fileURL('/es-module-loaders/byop-dummy-loader.mjs'),
'--input-type=module',
'--eval',
"import 'byop://1/index.byoe'",
]);
assert.strictEqual(code, 0);
assert.strictEqual(stdout.trim(), 'index.byoe!');
assert.strictEqual(stderr, '');
});
it('should identify the parent module of an invalid URL host in import specifier', async () => {
if (process.platform === 'win32') return;
const { code, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
fixtures.path('es-modules', 'invalid-posix-host.mjs'),
]);
assert.match(stderr, /ERR_INVALID_FILE_URL_HOST/);
assert.match(stderr, /file:\/\/hmm\.js/);
assert.match(stderr, /invalid-posix-host\.mjs/);
assert.strictEqual(code, 1);
});
});