|
| 1 | +import test from 'ava' |
| 2 | +import { initPlugin, callHook, noDepsAtAllOptions } from './_common' |
| 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}`) |
| 9 | + } |
| 10 | +}) |
| 11 | + |
| 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 | + } |
| 21 | +}) |
| 22 | + |
| 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}`) |
| 30 | + } |
| 31 | +}) |
| 32 | + |
| 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}`) |
| 43 | + } |
| 44 | +}) |
| 45 | + |
| 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}`) |
| 51 | + } |
| 52 | +}) |
| 53 | + |
| 54 | +test("Filters out bare specifiers when asked to", async t => { |
| 55 | + const bareSpecifiers = [ 'bare' ] |
| 56 | + const { plugin } = await initPlugin({ |
| 57 | + ...noDepsAtAllOptions, |
| 58 | + include: bareSpecifiers |
| 59 | + }) |
| 60 | + for (const specifier of bareSpecifiers) { |
| 61 | + t.is(await callHook(plugin, 'resolveId', specifier), false, `Failed id: ${specifier}`) |
| 62 | + } |
| 63 | +}) |
0 commit comments