@@ -10,6 +10,9 @@ const specifiers = {
1010 subpath : [ 'lodash' , 'lodash/flatten' ] ,
1111}
1212
13+ // Ensures tests use local package.json
14+ process . chdir ( fixture ( ) )
15+
1316test ( "Always ignores bundle entry point" , async t => {
1417 const { plugin } = await initPlugin ( )
1518 t . is ( await callHook ( plugin , 'resolveId' , './path/to/entry.js' , undefined ) , null )
@@ -37,89 +40,87 @@ test("Always ignores relative specifiers", async t => {
3740 }
3841} )
3942
43+ test ( "Always ignores bare specifiers that are not dependencies" , async t => {
44+ const { plugin } = await initPlugin ( { deps : true , peerDeps : true , optDeps : true , devDeps : true } )
45+ t . is ( await callHook ( plugin , 'resolveId' , 'not-a-dep' , 'index.js' ) , null )
46+ } )
47+
4048test ( "Marks dependencies external by default" , async t => {
41- process . chdir ( fixture ( ) )
4249 const { plugin } = await initPlugin ( )
4350 t . false ( await callHook ( plugin , 'resolveId' , 'test-dep' , 'index.js' ) )
4451} )
4552
4653test ( "Does NOT mark dependencies external when deps=false" , async t => {
47- process . chdir ( fixture ( ) )
4854 const { plugin } = await initPlugin ( { deps : false } )
4955 t . is ( await callHook ( plugin , 'resolveId' , 'test-dep' , 'index.js' ) , null )
5056} )
5157
5258test ( "Does NOT mark excluded dependencies external" , async t => {
53- process . chdir ( fixture ( ) )
5459 const { plugin } = await initPlugin ( { exclude : 'test-dep' } )
5560 t . is ( await callHook ( plugin , 'resolveId' , 'test-dep' , 'index.js' ) , null )
5661} )
5762
5863test ( "Marks peerDependencies external by default" , async t => {
59- process . chdir ( fixture ( ) )
6064 const { plugin } = await initPlugin ( )
6165 t . is ( await callHook ( plugin , 'resolveId' , 'test-dev-dep' , 'index.js' ) , null )
6266} )
6367
6468test ( "Does NOT mark peerDependencies external when peerDeps=false" , async t => {
65- process . chdir ( fixture ( ) )
6669 const { plugin } = await initPlugin ( { peerDeps : false } )
6770 t . is ( await callHook ( plugin , 'resolveId' , 'test-dev-dep' , 'index.js' ) , null )
6871} )
6972
7073test ( "Does NOT mark excluded peerDependencies external" , async t => {
71- process . chdir ( fixture ( ) )
7274 const { plugin } = await initPlugin ( { exclude : 'test-peer-dep' } )
7375 t . is ( await callHook ( plugin , 'resolveId' , 'test-dev-dep' , 'index.js' ) , null )
7476} )
7577
7678test ( "Marks optionalDependencies external by default" , async t => {
77- process . chdir ( fixture ( ) )
7879 const { plugin } = await initPlugin ( )
7980 t . false ( await callHook ( plugin , 'resolveId' , 'test-opt-dep' , 'index.js' ) )
8081} )
8182
8283test ( "Does NOT mark optionalDependencies external when optDeps=false" , async t => {
83- process . chdir ( fixture ( ) )
8484 const { plugin } = await initPlugin ( { optDeps : false } )
8585 t . is ( await callHook ( plugin , 'resolveId' , 'test-dev-dep' , 'index.js' ) , null )
8686} )
8787
8888test ( "Does NOT mark excluded optionalDependencies external" , async t => {
89- process . chdir ( fixture ( ) )
9089 const { plugin } = await initPlugin ( { exclude : 'test-opt-dep' } )
9190 t . is ( await callHook ( plugin , 'resolveId' , 'test-dev-dep' , 'index.js' ) , null )
9291} )
9392
9493test ( "Does NOT mark devDependencies external by default" , async t => {
95- process . chdir ( fixture ( ) )
9694 const { plugin } = await initPlugin ( )
9795 t . is ( await callHook ( plugin , 'resolveId' , 'test-dev-dep' , 'index.js' ) , null )
9896} )
9997
10098test ( "Marks devDependencies external when devDeps=true" , async t => {
101- process . chdir ( fixture ( ) )
10299 const { plugin } = await initPlugin ( { devDeps : true } )
103100 t . false ( await callHook ( plugin , 'resolveId' , 'test-dev-dep' , 'index.js' ) )
104101} )
105102
106103test ( "Marks included devDependencies external" , async t => {
107- process . chdir ( fixture ( ) )
108104 const { plugin } = await initPlugin ( { include : 'test-dev-dep' } )
109105 t . false ( await callHook ( plugin , 'resolveId' , 'test-dev-dep' , 'index.js' ) )
110106} )
111107
112108test ( "Marks dependencies/peerDependencies/optionalDependencies subpath imports external" , async t => {
113- process . chdir ( fixture ( ) )
114109 const { plugin } = await initPlugin ( )
115110 t . is ( await callHook ( plugin , 'resolveId' , 'test-dep/sub' , 'index.js' ) , false )
116111 t . is ( await callHook ( plugin , 'resolveId' , 'test-peer-dep/sub' , 'index.js' ) , false )
117112 t . is ( await callHook ( plugin , 'resolveId' , 'test-opt-dep/sub' , 'index.js' ) , false )
118113} )
119114
120115test ( "Marks subpath imports external (with regexes)" , async t => {
121- process . chdir ( fixture ( ) )
122116 const { plugin } = await initPlugin ( { include : / ^ t e s t - d e v - d e p / } )
123117 t . is ( await callHook ( plugin , 'resolveId' , 'test-dev-dep' , 'index.js' ) , false )
124118 t . is ( await callHook ( plugin , 'resolveId' , 'test-dev-dep/sub' , 'index.js' ) , false )
125119} )
120+
121+ test ( "External dependencies have precedence over devDependencies" , async t => {
122+ const { plugin } = await initPlugin ( {
123+ packagePath : '04_dual/package.json'
124+ } )
125+ t . false ( await callHook ( plugin , 'resolveId' , 'dual-dep' , 'index.js' ) )
126+ } )
0 commit comments