-
-
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.
Do *not* consider an empty include option means 'includes all'. Fixes #…
…20.
- Loading branch information
Showing
2 changed files
with
39 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,57 @@ | ||
import test from 'ava' | ||
import { initPlugin, callHook } from './_common' | ||
import type { ExternalsOptions } from '../src/index' | ||
|
||
test("Filters out relative specifiers", async t => { | ||
const noDeps: ExternalsOptions = { | ||
builtins: false, | ||
deps: false, | ||
devDeps: false, | ||
optDeps: false, | ||
peerDeps: false | ||
} | ||
|
||
test.only("Does NOT filter out relative specifiers by default", async t => { | ||
const relativeSpecifiers = [ './sibling.js', '../parent.js' ] | ||
|
||
const { plugin } = await initPlugin(noDeps) | ||
for (const identifier of relativeSpecifiers) { | ||
t.is(await callHook(plugin, 'resolveId', identifier), null) | ||
} | ||
}) | ||
|
||
test("Filters out relative specifiers when asked to", async t => { | ||
const relativeSpecifiers = [ './sibling.js', '../parent.js' ] | ||
|
||
const { plugin } = await initPlugin({ | ||
...noDeps, | ||
include: relativeSpecifiers | ||
}) | ||
for (const builtin of relativeSpecifiers) { | ||
t.false(await callHook(plugin, 'resolveId', builtin)) | ||
for (const identifier of relativeSpecifiers) { | ||
t.false(await callHook(plugin, 'resolveId', identifier)) | ||
} | ||
}) | ||
|
||
test("Does NOT filter out absolute specifiers by default", async t => { | ||
const absoluteSpecifiers = [ '/root.js' ] | ||
if (process.platform === 'win32') | ||
absoluteSpecifiers.push('C:\\root.js', '\\root.js') | ||
|
||
const { plugin } = await initPlugin(noDeps) | ||
for (const identifier of absoluteSpecifiers) { | ||
t.is(await callHook(plugin, 'resolveId', identifier), null, `Failed id: ${identifier}`) | ||
} | ||
}) | ||
|
||
test("Does NOT filter out absolute specifiers", async t => { | ||
test("Filters out absolute specifiers when asked to", async t => { | ||
const absoluteSpecifiers = [ '/root.js' ] | ||
if (process.platform === 'win32') | ||
absoluteSpecifiers.push('C:\\root.js', '\\root.js') | ||
|
||
const { plugin } = await initPlugin({ | ||
...noDeps, | ||
include: absoluteSpecifiers | ||
}) | ||
for (const builtin of absoluteSpecifiers) { | ||
t.is(await callHook(plugin, 'resolveId', builtin), null) | ||
for (const identifier of absoluteSpecifiers) { | ||
t.is(await callHook(plugin, 'resolveId', identifier), null, `Failed id: ${identifier}`) | ||
} | ||
}) |