-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,57 @@ | ||
import test from 'ava' | ||
import { initPlugin, callHook, noDepsAtAllOptions } from './_common.js' | ||
import { initPlugin, callHook } from './_common.js' | ||
|
||
test("Does NOT filter out relative specifiers by default", async t => { | ||
const relativeSpecifiers = [ './sibling.js', '../parent.js' ] | ||
const { plugin } = await initPlugin(noDepsAtAllOptions) | ||
for (const specifier of relativeSpecifiers) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed id: ${specifier}`) | ||
const testSpecifiers = { | ||
virtual: [ '\\0virtual' ], | ||
absolute: [ '/root.js' ], | ||
absoluteWin32: [ '/root.js', '\\root.js', 'C:\\root.js' ], | ||
bare: [ 'bare' ], | ||
relative: [ './sibling.js', '../parent.js' ], | ||
subpath: [ 'lodash', 'lodash/flatten.js' ], | ||
} | ||
|
||
test("Always ignores virtual modules", async t => { | ||
const { plugin } = await initPlugin() | ||
for (const specifier of testSpecifiers.virtual) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) | ||
} | ||
}) | ||
|
||
test("Does NOT filter out relative specifiers, even when asked to", async t => { | ||
const relativeSpecifiers = [ './sibling.js', '../parent.js' ] | ||
const { plugin } = await initPlugin({ | ||
...noDepsAtAllOptions, | ||
include: relativeSpecifiers | ||
}) | ||
for (const specifier of relativeSpecifiers) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed id: ${specifier}`) | ||
test("Always ignores absolute specifiers", async t => { | ||
const { plugin } = await initPlugin() | ||
for (const specifier of testSpecifiers[process.platform === 'win32' ? 'absoluteWin32' : 'absolute']) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) | ||
} | ||
}) | ||
|
||
test("Does NOT filter out absolute specifiers by default", async t => { | ||
const absoluteSpecifiers = [ '/root.js' ] | ||
if (process.platform === 'win32') | ||
absoluteSpecifiers.push('\\root.js', 'C:\\root.js') | ||
const { plugin } = await initPlugin(noDepsAtAllOptions) | ||
for (const specifier of absoluteSpecifiers) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed id: ${specifier}`) | ||
test("Always ignores relative specifiers", async t => { | ||
const { plugin } = await initPlugin() | ||
for (const specifier of testSpecifiers.relative) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) | ||
} | ||
}) | ||
|
||
test("Does NOT filter out absolute specifiers, even when asked to", async t => { | ||
const absoluteSpecifiers = [ '/root.js' ] | ||
if (process.platform === 'win32') | ||
absoluteSpecifiers.push('\\root.js', 'C:\\root.js') | ||
const { plugin } = await initPlugin({ | ||
...noDepsAtAllOptions, | ||
include: absoluteSpecifiers | ||
}) | ||
for (const specifier of absoluteSpecifiers) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed id: ${specifier}`) | ||
test("Does NOT mark bare specifiers external by default", async t => { | ||
const { plugin } = await initPlugin() | ||
for (const specifier of testSpecifiers.bare) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) | ||
} | ||
}) | ||
|
||
test("Does NOT filter out bare specifiers by default", async t => { | ||
const bareSpecifiers = [ 'dependency' ] | ||
const { plugin } = await initPlugin(noDepsAtAllOptions) | ||
for (const specifier of bareSpecifiers) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed id: ${specifier}`) | ||
test("Marks bare specifiers external when asked to", async t => { | ||
const { plugin } = await initPlugin({ | ||
include: testSpecifiers.bare | ||
}) | ||
for (const specifier of testSpecifiers.bare) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), false, `Failed on: ${specifier}`) | ||
} | ||
}) | ||
|
||
test("Filters out bare specifiers when asked to", async t => { | ||
const bareSpecifiers = [ 'bare' ] | ||
test("Marks subpath imports external (with regexes)", async t => { | ||
const { plugin } = await initPlugin({ | ||
...noDepsAtAllOptions, | ||
include: bareSpecifiers | ||
include: [ /^lodash/ ] | ||
}) | ||
for (const specifier of bareSpecifiers) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), false, `Failed id: ${specifier}`) | ||
for (const specifier of testSpecifiers.subpath) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), false, `Failed on: ${specifier}`) | ||
} | ||
}) |