|
1 | 1 | import test from 'ava' |
2 | | -import { initPlugin, callHook, noDepsAtAllOptions } from './_common.js' |
| 2 | +import { initPlugin, callHook } from './_common.js' |
3 | 3 |
|
4 | | -test("Does NOT filter out relative specifiers by default", async t => { |
5 | | - const relativeSpecifiers = [ './sibling.js', '../parent.js' ] |
6 | | - const { plugin } = await initPlugin(noDepsAtAllOptions) |
7 | | - for (const specifier of relativeSpecifiers) { |
8 | | - t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed id: ${specifier}`) |
| 4 | +const testSpecifiers = { |
| 5 | + virtual: [ '\\0virtual' ], |
| 6 | + absolute: [ '/root.js' ], |
| 7 | + absoluteWin32: [ '/root.js', '\\root.js', 'C:\\root.js' ], |
| 8 | + bare: [ 'bare' ], |
| 9 | + relative: [ './sibling.js', '../parent.js' ], |
| 10 | + subpath: [ 'lodash', 'lodash/flatten.js' ], |
| 11 | +} |
| 12 | + |
| 13 | +test("Always ignores virtual modules", async t => { |
| 14 | + const { plugin } = await initPlugin() |
| 15 | + for (const specifier of testSpecifiers.virtual) { |
| 16 | + t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) |
9 | 17 | } |
10 | 18 | }) |
11 | 19 |
|
12 | | -test("Does NOT filter out relative specifiers, even when asked to", async t => { |
13 | | - const relativeSpecifiers = [ './sibling.js', '../parent.js' ] |
14 | | - const { plugin } = await initPlugin({ |
15 | | - ...noDepsAtAllOptions, |
16 | | - include: relativeSpecifiers |
17 | | - }) |
18 | | - for (const specifier of relativeSpecifiers) { |
19 | | - t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed id: ${specifier}`) |
| 20 | +test("Always ignores absolute specifiers", async t => { |
| 21 | + const { plugin } = await initPlugin() |
| 22 | + for (const specifier of testSpecifiers[process.platform === 'win32' ? 'absoluteWin32' : 'absolute']) { |
| 23 | + t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) |
20 | 24 | } |
21 | 25 | }) |
22 | 26 |
|
23 | | -test("Does NOT filter out absolute specifiers by default", async t => { |
24 | | - const absoluteSpecifiers = [ '/root.js' ] |
25 | | - if (process.platform === 'win32') |
26 | | - absoluteSpecifiers.push('\\root.js', 'C:\\root.js') |
27 | | - const { plugin } = await initPlugin(noDepsAtAllOptions) |
28 | | - for (const specifier of absoluteSpecifiers) { |
29 | | - t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed id: ${specifier}`) |
| 27 | +test("Always ignores relative specifiers", async t => { |
| 28 | + const { plugin } = await initPlugin() |
| 29 | + for (const specifier of testSpecifiers.relative) { |
| 30 | + t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) |
30 | 31 | } |
31 | 32 | }) |
32 | 33 |
|
33 | | -test("Does NOT filter out absolute specifiers, even when asked to", async t => { |
34 | | - const absoluteSpecifiers = [ '/root.js' ] |
35 | | - if (process.platform === 'win32') |
36 | | - absoluteSpecifiers.push('\\root.js', 'C:\\root.js') |
37 | | - const { plugin } = await initPlugin({ |
38 | | - ...noDepsAtAllOptions, |
39 | | - include: absoluteSpecifiers |
40 | | - }) |
41 | | - for (const specifier of absoluteSpecifiers) { |
42 | | - t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed id: ${specifier}`) |
| 34 | +test("Does NOT mark bare specifiers external by default", async t => { |
| 35 | + const { plugin } = await initPlugin() |
| 36 | + for (const specifier of testSpecifiers.bare) { |
| 37 | + t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) |
43 | 38 | } |
44 | 39 | }) |
45 | 40 |
|
46 | | -test("Does NOT filter out bare specifiers by default", async t => { |
47 | | - const bareSpecifiers = [ 'dependency' ] |
48 | | - const { plugin } = await initPlugin(noDepsAtAllOptions) |
49 | | - for (const specifier of bareSpecifiers) { |
50 | | - t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed id: ${specifier}`) |
| 41 | +test("Marks bare specifiers external when asked to", async t => { |
| 42 | + const { plugin } = await initPlugin({ |
| 43 | + include: testSpecifiers.bare |
| 44 | + }) |
| 45 | + for (const specifier of testSpecifiers.bare) { |
| 46 | + t.is(await callHook(plugin, 'resolveId', specifier), false, `Failed on: ${specifier}`) |
51 | 47 | } |
52 | 48 | }) |
53 | 49 |
|
54 | | -test("Filters out bare specifiers when asked to", async t => { |
55 | | - const bareSpecifiers = [ 'bare' ] |
| 50 | +test("Marks subpath imports external (with regexes)", async t => { |
56 | 51 | const { plugin } = await initPlugin({ |
57 | | - ...noDepsAtAllOptions, |
58 | | - include: bareSpecifiers |
| 52 | + include: [ /^lodash/ ] |
59 | 53 | }) |
60 | | - for (const specifier of bareSpecifiers) { |
61 | | - t.is(await callHook(plugin, 'resolveId', specifier), false, `Failed id: ${specifier}`) |
| 54 | + for (const specifier of testSpecifiers.subpath) { |
| 55 | + t.is(await callHook(plugin, 'resolveId', specifier), false, `Failed on: ${specifier}`) |
62 | 56 | } |
63 | 57 | }) |
0 commit comments