-
-
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
6 changed files
with
159 additions
and
104 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 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 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,57 +1,125 @@ | ||
import test from 'ava' | ||
import { initPlugin, callHook } from './_common.ts' | ||
import { initPlugin, callHook, fixture } from './_common.ts' | ||
|
||
const testSpecifiers = { | ||
const specifiers = { | ||
virtual: [ '\\0virtual' ], | ||
absolute: [ '/root.js' ], | ||
absolutePosix: [ '/root.js' ], | ||
absoluteWin32: [ '/root.js', '\\root.js', 'C:\\root.js' ], | ||
bare: [ 'bare' ], | ||
bare: [ 'foo', 'bar' ], | ||
relative: [ './sibling.js', '../parent.js' ], | ||
subpath: [ 'lodash', 'lodash/flatten.js' ], | ||
subpath: [ 'lodash', 'lodash/flatten' ], | ||
} | ||
|
||
test("Always ignores virtual modules", async t => { | ||
test("Always ignores bundle entry point", async t => { | ||
const { plugin } = await initPlugin() | ||
for (const specifier of testSpecifiers.virtual) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) | ||
} | ||
t.is(await callHook(plugin, 'resolveId', './path/to/entry.js', undefined), null) | ||
}) | ||
|
||
test("Always ignores virtual modules from other plugins", async t => { | ||
const { plugin } = await initPlugin() | ||
t.is(await callHook(plugin, 'resolveId', '\\0virtual', undefined), null, `Failed without importer`) | ||
t.is(await callHook(plugin, 'resolveId', '\\0virtual', 'file.js'), null, `Failed with importer`) | ||
}) | ||
|
||
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}`) | ||
for (const specifier of specifiers[process.platform === 'win32' ? 'absoluteWin32' : 'absolutePosix']) { | ||
t.is(await callHook(plugin, 'resolveId', specifier, undefined), null, `Failed on: ${specifier} without importer`) | ||
t.is(await callHook(plugin, 'resolveId', specifier, 'file.js'), null, `Failed on: ${specifier} with importer`) | ||
} | ||
}) | ||
|
||
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}`) | ||
const { plugin } = await initPlugin({ include: specifiers.relative }) | ||
for (const specifier of specifiers.relative) { | ||
t.is(await callHook(plugin, 'resolveId', specifier, undefined), null, `Failed on: ${specifier} without importer`) | ||
t.is(await callHook(plugin, 'resolveId', specifier, 'file.js'), null, `Failed on: ${specifier} with importer`) | ||
} | ||
}) | ||
|
||
test("Does NOT mark bare specifiers external by default", async t => { | ||
test("Marks dependencies external by default", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin() | ||
for (const specifier of testSpecifiers.bare) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) | ||
} | ||
t.false(await callHook(plugin, 'resolveId', 'test-dep', 'index.js')) | ||
}) | ||
|
||
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("Does NOT mark dependencies external when deps=false", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin({ deps: false }) | ||
t.is(await callHook(plugin, 'resolveId', 'test-dep', 'index.js'), null) | ||
}) | ||
|
||
test("Does NOT mark excluded dependencies external", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin({ exclude: 'test-dep' }) | ||
t.is(await callHook(plugin, 'resolveId', 'test-dep', 'index.js'), null) | ||
}) | ||
|
||
test("Marks peerDependencies external by default", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin() | ||
t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) | ||
}) | ||
|
||
test("Does NOT mark peerDependencies external when peerDeps=false", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin({ peerDeps: false }) | ||
t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) | ||
}) | ||
|
||
test("Does NOT mark excluded peerDependencies external", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin({ exclude: 'test-peer-dep' }) | ||
t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) | ||
}) | ||
|
||
test("Marks optionalDependencies external by default", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin() | ||
t.false(await callHook(plugin, 'resolveId', 'test-opt-dep', 'index.js')) | ||
}) | ||
|
||
test("Does NOT mark optionalDependencies external when optDeps=false", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin({ optDeps: false }) | ||
t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) | ||
}) | ||
|
||
test("Does NOT mark excluded optionalDependencies external", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin({ exclude: 'test-opt-dep' }) | ||
t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) | ||
}) | ||
|
||
test("Does NOT mark devDependencies external by default", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin() | ||
t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) | ||
}) | ||
|
||
test("Marks devDependencies external when devDeps=true", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin({ devDeps: true }) | ||
t.false(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js')) | ||
}) | ||
|
||
test("Marks included devDependencies external", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin({ include: 'test-dev-dep' }) | ||
t.false(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js')) | ||
}) | ||
|
||
test("Marks dependencies/peerDependencies/optionalDependencies subpath imports external", async t => { | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin() | ||
t.is(await callHook(plugin, 'resolveId', 'test-dep/sub', 'index.js'), false) | ||
t.is(await callHook(plugin, 'resolveId', 'test-peer-dep/sub', 'index.js'), false) | ||
t.is(await callHook(plugin, 'resolveId', 'test-opt-dep/sub', 'index.js'), false) | ||
}) | ||
|
||
test("Marks subpath imports external (with regexes)", async t => { | ||
const { plugin } = await initPlugin({ | ||
include: [ /^lodash/ ] | ||
}) | ||
for (const specifier of testSpecifiers.subpath) { | ||
t.is(await callHook(plugin, 'resolveId', specifier), false, `Failed on: ${specifier}`) | ||
} | ||
process.chdir(fixture()) | ||
const { plugin } = await initPlugin({ include: /^test-dev-dep/ }) | ||
t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), false) | ||
t.is(await callHook(plugin, 'resolveId', 'test-dev-dep/sub', 'index.js'), false) | ||
}) |
Oops, something went wrong.