1
1
/* eslint-env mocha */
2
2
'use strict'
3
3
4
- const { check } = require ( '../src/dependency-check' )
5
4
const { expect } = require ( '../utils/chai' )
6
5
const path = require ( 'path' )
7
- const merge = require ( 'merge-options' )
8
- const { userConfig } = require ( '../src/config/user' )
9
-
10
- // returns an object that looks like the yargs input
11
- const yargsv = ( overrides = { } ) => {
12
- const argv = {
13
- _ : [ 'dependency-check' ] ,
14
- input : userConfig . dependencyCheck . input ,
15
- productionOnly : false ,
16
- productionInput : userConfig . dependencyCheck . productionInput ,
17
- ignore : [ ] ,
18
- fileConfig : userConfig
19
- }
20
-
21
- return merge ( argv , overrides )
22
- }
6
+ const bin = require . resolve ( '../' )
7
+ const execa = require ( 'execa' )
23
8
24
9
describe ( 'dependency check' , ( ) => {
25
10
it ( 'should fail for missing deps' , async ( ) => {
26
11
await expect (
27
- check ( yargsv ( ) , {
12
+ execa ( bin , [ 'dependency-check' ] , {
28
13
cwd : path . join ( __dirname , 'fixtures/dependency-check/fail' )
29
14
} )
30
15
) . to . eventually . be . rejectedWith ( 'execa' )
31
16
} )
32
17
18
+ it ( 'should fail for missing deps in an esm project' , async ( ) => {
19
+ await expect (
20
+ execa ( bin , [ 'dependency-check' ] , {
21
+ cwd : path . join ( __dirname , 'fixtures/dependency-check/esm-fail' )
22
+ } )
23
+ ) . to . eventually . be . rejected ( )
24
+ . with . property ( 'message' )
25
+ . that . include ( 'execa' )
26
+ . and . include ( 'pico' )
27
+ } )
28
+
33
29
it ( 'should pass when there are no missing deps' , async ( ) => {
34
30
await expect (
35
- check ( yargsv ( ) , {
31
+ execa ( bin , [ 'dependency-check' ] , {
36
32
cwd : path . join ( __dirname , 'fixtures/dependency-check/pass' )
37
33
} )
38
34
) . to . eventually . be . fulfilled ( )
39
35
} )
40
36
37
+ it ( 'should pass when there are no missing deps in an esm project' , async ( ) => {
38
+ await expect (
39
+ execa ( bin , [ 'dependency-check' ] , {
40
+ cwd : path . join ( __dirname , 'fixtures/dependency-check/esm-pass' )
41
+ } )
42
+ ) . to . eventually . be . fulfilled ( )
43
+ } )
44
+
41
45
it ( 'should forward options' , async ( ) => {
42
46
await expect (
43
- check ( yargsv ( { '--' : [ '--unused' ] } ) , {
47
+ execa ( bin , [ 'dependency-check' , '--' , '--unused' ] , {
44
48
cwd : path . join ( __dirname , 'fixtures/dependency-check/pass' )
45
49
} )
46
50
) . to . eventually . be . rejectedWith (
@@ -50,7 +54,7 @@ describe('dependency check', () => {
50
54
51
55
it ( 'should fail for missing production deps' , async ( ) => {
52
56
await expect (
53
- check ( yargsv ( { productionOnly : true } ) , {
57
+ execa ( bin , [ 'dependency-check' , '-p' ] , {
54
58
cwd : path . join ( __dirname , 'fixtures/dependency-check/fail-prod' )
55
59
} )
56
60
) . to . eventually . be . rejectedWith ( 'execa' )
@@ -60,16 +64,12 @@ describe('dependency check', () => {
60
64
const file = 'derp/foo.js'
61
65
62
66
await expect (
63
- check (
64
- yargsv ( {
65
- input : [ file ]
66
- } ) ,
67
- {
68
- cwd : path . join (
69
- __dirname ,
70
- 'fixtures/dependency-check/pass-certain-files'
71
- )
72
- }
67
+ execa ( bin , [ 'dependency-check' , file ] , {
68
+ cwd : path . join (
69
+ __dirname ,
70
+ 'fixtures/dependency-check/pass-certain-files'
71
+ )
72
+ }
73
73
)
74
74
) . to . eventually . be . fulfilled ( )
75
75
} )
@@ -78,46 +78,33 @@ describe('dependency check', () => {
78
78
const file = 'derp/foo.js'
79
79
80
80
await expect (
81
- check (
82
- yargsv ( {
83
- productionOnly : true ,
84
- input : [ file ]
85
- } ) ,
86
- {
87
- cwd : path . join (
88
- __dirname ,
89
- 'fixtures/dependency-check/pass-certain-files'
90
- )
91
- }
81
+ execa ( bin , [ 'dependency-check' , file , '-p' ] , {
82
+ cwd : path . join (
83
+ __dirname ,
84
+ 'fixtures/dependency-check/pass-certain-files'
85
+ )
86
+ }
92
87
)
93
88
) . to . eventually . be . fulfilled ( )
94
89
} )
95
90
96
91
it ( 'should pass for ignored modules' , async ( ) => {
97
92
await expect (
98
- check (
99
- yargsv ( {
100
- ignore : [ 'execa' ]
101
- } ) ,
102
- {
103
- cwd : path . join ( __dirname , 'fixtures/dependency-check/fail' )
104
- }
93
+ execa ( bin , [ 'dependency-check' , '-i' , 'execa' ] , {
94
+ cwd : path . join ( __dirname , 'fixtures/dependency-check/fail' )
95
+ }
105
96
)
106
97
) . to . eventually . be . fulfilled ( )
107
98
} )
108
99
109
100
it ( 'should pass for modules used in .aegir.js' , async ( ) => {
110
101
await expect (
111
- check (
112
- yargsv ( {
113
- '--' : [ '--unused' ]
114
- } ) ,
115
- {
116
- cwd : path . join (
117
- __dirname ,
118
- 'fixtures/dependency-check/with-aegir-config'
119
- )
120
- }
102
+ execa ( bin , [ 'dependency-check' , '--' , '--unused' ] , {
103
+ cwd : path . join (
104
+ __dirname ,
105
+ 'fixtures/dependency-check/with-aegir-config'
106
+ )
107
+ }
121
108
)
122
109
) . to . eventually . be . fulfilled ( )
123
110
} )
0 commit comments