|
1 | 1 | import test from 'ava' |
2 | | -import { initPlugin, callHook } from './_common.ts' |
| 2 | +import { initPlugin, callHook, fixture } from './_common.ts' |
3 | 3 |
|
4 | | -const testSpecifiers = { |
| 4 | +const specifiers = { |
5 | 5 | virtual: [ '\\0virtual' ], |
6 | | - absolute: [ '/root.js' ], |
| 6 | + absolutePosix: [ '/root.js' ], |
7 | 7 | absoluteWin32: [ '/root.js', '\\root.js', 'C:\\root.js' ], |
8 | | - bare: [ 'bare' ], |
| 8 | + bare: [ 'foo', 'bar' ], |
9 | 9 | relative: [ './sibling.js', '../parent.js' ], |
10 | | - subpath: [ 'lodash', 'lodash/flatten.js' ], |
| 10 | + subpath: [ 'lodash', 'lodash/flatten' ], |
11 | 11 | } |
12 | 12 |
|
13 | | -test("Always ignores virtual modules", async t => { |
| 13 | +test("Always ignores bundle entry point", async t => { |
14 | 14 | const { plugin } = await initPlugin() |
15 | | - for (const specifier of testSpecifiers.virtual) { |
16 | | - t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) |
17 | | - } |
| 15 | + t.is(await callHook(plugin, 'resolveId', './path/to/entry.js', undefined), null) |
| 16 | +}) |
| 17 | + |
| 18 | +test("Always ignores virtual modules from other plugins", async t => { |
| 19 | + const { plugin } = await initPlugin() |
| 20 | + t.is(await callHook(plugin, 'resolveId', '\\0virtual', undefined), null, `Failed without importer`) |
| 21 | + t.is(await callHook(plugin, 'resolveId', '\\0virtual', 'file.js'), null, `Failed with importer`) |
18 | 22 | }) |
19 | 23 |
|
20 | 24 | test("Always ignores absolute specifiers", async t => { |
21 | 25 | const { plugin } = await initPlugin() |
22 | | - for (const specifier of testSpecifiers[process.platform === 'win32' ? 'absoluteWin32' : 'absolute']) { |
23 | | - t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) |
| 26 | + for (const specifier of specifiers[process.platform === 'win32' ? 'absoluteWin32' : 'absolutePosix']) { |
| 27 | + t.is(await callHook(plugin, 'resolveId', specifier, undefined), null, `Failed on: ${specifier} without importer`) |
| 28 | + t.is(await callHook(plugin, 'resolveId', specifier, 'file.js'), null, `Failed on: ${specifier} with importer`) |
24 | 29 | } |
25 | 30 | }) |
26 | 31 |
|
27 | 32 | test("Always ignores relative specifiers", async t => { |
28 | | - const { plugin } = await initPlugin() |
29 | | - for (const specifier of testSpecifiers.relative) { |
30 | | - t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) |
| 33 | + const { plugin } = await initPlugin({ include: specifiers.relative }) |
| 34 | + for (const specifier of specifiers.relative) { |
| 35 | + t.is(await callHook(plugin, 'resolveId', specifier, undefined), null, `Failed on: ${specifier} without importer`) |
| 36 | + t.is(await callHook(plugin, 'resolveId', specifier, 'file.js'), null, `Failed on: ${specifier} with importer`) |
31 | 37 | } |
32 | 38 | }) |
33 | 39 |
|
34 | | -test("Does NOT mark bare specifiers external by default", async t => { |
| 40 | +test("Marks dependencies external by default", async t => { |
| 41 | + process.chdir(fixture()) |
35 | 42 | const { plugin } = await initPlugin() |
36 | | - for (const specifier of testSpecifiers.bare) { |
37 | | - t.is(await callHook(plugin, 'resolveId', specifier), null, `Failed on: ${specifier}`) |
38 | | - } |
| 43 | + t.false(await callHook(plugin, 'resolveId', 'test-dep', 'index.js')) |
39 | 44 | }) |
40 | 45 |
|
41 | | -test("Marks bare specifiers external when asked to", async t => { |
42 | | - const { plugin } = await initPlugin({ |
43 | | - include: testSpecifiers.bare |
44 | | - }) |
45 | | - for (const specifier of testSpecifiers.bare) { |
46 | | - t.is(await callHook(plugin, 'resolveId', specifier), false, `Failed on: ${specifier}`) |
47 | | - } |
| 46 | +test("Does NOT mark dependencies external when deps=false", async t => { |
| 47 | + process.chdir(fixture()) |
| 48 | + const { plugin } = await initPlugin({ deps: false }) |
| 49 | + t.is(await callHook(plugin, 'resolveId', 'test-dep', 'index.js'), null) |
| 50 | +}) |
| 51 | + |
| 52 | +test("Does NOT mark excluded dependencies external", async t => { |
| 53 | + process.chdir(fixture()) |
| 54 | + const { plugin } = await initPlugin({ exclude: 'test-dep' }) |
| 55 | + t.is(await callHook(plugin, 'resolveId', 'test-dep', 'index.js'), null) |
| 56 | +}) |
| 57 | + |
| 58 | +test("Marks peerDependencies external by default", async t => { |
| 59 | + process.chdir(fixture()) |
| 60 | + const { plugin } = await initPlugin() |
| 61 | + t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) |
| 62 | +}) |
| 63 | + |
| 64 | +test("Does NOT mark peerDependencies external when peerDeps=false", async t => { |
| 65 | + process.chdir(fixture()) |
| 66 | + const { plugin } = await initPlugin({ peerDeps: false }) |
| 67 | + t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) |
| 68 | +}) |
| 69 | + |
| 70 | +test("Does NOT mark excluded peerDependencies external", async t => { |
| 71 | + process.chdir(fixture()) |
| 72 | + const { plugin } = await initPlugin({ exclude: 'test-peer-dep' }) |
| 73 | + t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) |
| 74 | +}) |
| 75 | + |
| 76 | +test("Marks optionalDependencies external by default", async t => { |
| 77 | + process.chdir(fixture()) |
| 78 | + const { plugin } = await initPlugin() |
| 79 | + t.false(await callHook(plugin, 'resolveId', 'test-opt-dep', 'index.js')) |
| 80 | +}) |
| 81 | + |
| 82 | +test("Does NOT mark optionalDependencies external when optDeps=false", async t => { |
| 83 | + process.chdir(fixture()) |
| 84 | + const { plugin } = await initPlugin({ optDeps: false }) |
| 85 | + t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) |
| 86 | +}) |
| 87 | + |
| 88 | +test("Does NOT mark excluded optionalDependencies external", async t => { |
| 89 | + process.chdir(fixture()) |
| 90 | + const { plugin } = await initPlugin({ exclude: 'test-opt-dep' }) |
| 91 | + t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) |
| 92 | +}) |
| 93 | + |
| 94 | +test("Does NOT mark devDependencies external by default", async t => { |
| 95 | + process.chdir(fixture()) |
| 96 | + const { plugin } = await initPlugin() |
| 97 | + t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), null) |
| 98 | +}) |
| 99 | + |
| 100 | +test("Marks devDependencies external when devDeps=true", async t => { |
| 101 | + process.chdir(fixture()) |
| 102 | + const { plugin } = await initPlugin({ devDeps: true }) |
| 103 | + t.false(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js')) |
| 104 | +}) |
| 105 | + |
| 106 | +test("Marks included devDependencies external", async t => { |
| 107 | + process.chdir(fixture()) |
| 108 | + const { plugin } = await initPlugin({ include: 'test-dev-dep' }) |
| 109 | + t.false(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js')) |
| 110 | +}) |
| 111 | + |
| 112 | +test("Marks dependencies/peerDependencies/optionalDependencies subpath imports external", async t => { |
| 113 | + process.chdir(fixture()) |
| 114 | + const { plugin } = await initPlugin() |
| 115 | + t.is(await callHook(plugin, 'resolveId', 'test-dep/sub', 'index.js'), false) |
| 116 | + t.is(await callHook(plugin, 'resolveId', 'test-peer-dep/sub', 'index.js'), false) |
| 117 | + t.is(await callHook(plugin, 'resolveId', 'test-opt-dep/sub', 'index.js'), false) |
48 | 118 | }) |
49 | 119 |
|
50 | 120 | test("Marks subpath imports external (with regexes)", async t => { |
51 | | - const { plugin } = await initPlugin({ |
52 | | - include: [ /^lodash/ ] |
53 | | - }) |
54 | | - for (const specifier of testSpecifiers.subpath) { |
55 | | - t.is(await callHook(plugin, 'resolveId', specifier), false, `Failed on: ${specifier}`) |
56 | | - } |
| 121 | + process.chdir(fixture()) |
| 122 | + const { plugin } = await initPlugin({ include: /^test-dev-dep/ }) |
| 123 | + t.is(await callHook(plugin, 'resolveId', 'test-dev-dep', 'index.js'), false) |
| 124 | + t.is(await callHook(plugin, 'resolveId', 'test-dev-dep/sub', 'index.js'), false) |
57 | 125 | }) |
0 commit comments