|
1 | 1 | import test from 'ava' |
2 | 2 | import { initPlugin, callHook } from './_common' |
| 3 | +import type { ExternalsOptions } from '../src/index' |
3 | 4 |
|
4 | | -test("Filters out relative specifiers", async t => { |
| 5 | +const noDeps: ExternalsOptions = { |
| 6 | + builtins: false, |
| 7 | + deps: false, |
| 8 | + devDeps: false, |
| 9 | + optDeps: false, |
| 10 | + peerDeps: false |
| 11 | +} |
| 12 | + |
| 13 | +test.only("Does NOT filter out relative specifiers by default", async t => { |
| 14 | + const relativeSpecifiers = [ './sibling.js', '../parent.js' ] |
| 15 | + |
| 16 | + const { plugin } = await initPlugin(noDeps) |
| 17 | + for (const identifier of relativeSpecifiers) { |
| 18 | + t.is(await callHook(plugin, 'resolveId', identifier), null) |
| 19 | + } |
| 20 | +}) |
| 21 | + |
| 22 | +test("Filters out relative specifiers when asked to", async t => { |
5 | 23 | const relativeSpecifiers = [ './sibling.js', '../parent.js' ] |
6 | 24 |
|
7 | 25 | const { plugin } = await initPlugin({ |
| 26 | + ...noDeps, |
8 | 27 | include: relativeSpecifiers |
9 | 28 | }) |
10 | | - for (const builtin of relativeSpecifiers) { |
11 | | - t.false(await callHook(plugin, 'resolveId', builtin)) |
| 29 | + for (const identifier of relativeSpecifiers) { |
| 30 | + t.false(await callHook(plugin, 'resolveId', identifier)) |
| 31 | + } |
| 32 | +}) |
| 33 | + |
| 34 | +test("Does NOT filter out absolute specifiers by default", async t => { |
| 35 | + const absoluteSpecifiers = [ '/root.js' ] |
| 36 | + if (process.platform === 'win32') |
| 37 | + absoluteSpecifiers.push('C:\\root.js', '\\root.js') |
| 38 | + |
| 39 | + const { plugin } = await initPlugin(noDeps) |
| 40 | + for (const identifier of absoluteSpecifiers) { |
| 41 | + t.is(await callHook(plugin, 'resolveId', identifier), null, `Failed id: ${identifier}`) |
12 | 42 | } |
13 | 43 | }) |
14 | 44 |
|
15 | | -test("Does NOT filter out absolute specifiers", async t => { |
| 45 | +test("Filters out absolute specifiers when asked to", async t => { |
16 | 46 | const absoluteSpecifiers = [ '/root.js' ] |
17 | 47 | if (process.platform === 'win32') |
18 | 48 | absoluteSpecifiers.push('C:\\root.js', '\\root.js') |
19 | 49 |
|
20 | 50 | const { plugin } = await initPlugin({ |
| 51 | + ...noDeps, |
21 | 52 | include: absoluteSpecifiers |
22 | 53 | }) |
23 | | - for (const builtin of absoluteSpecifiers) { |
24 | | - t.is(await callHook(plugin, 'resolveId', builtin), null) |
| 54 | + for (const identifier of absoluteSpecifiers) { |
| 55 | + t.is(await callHook(plugin, 'resolveId', identifier), null, `Failed id: ${identifier}`) |
25 | 56 | } |
26 | 57 | }) |
0 commit comments