2
2
3
3
const { directory } = require ( 'tempy' ) ;
4
4
const { resolve } = require ( 'path' ) ;
5
- const { promisify } = require ( 'util' ) ;
6
5
const set = require ( 'lodash.set' ) ;
7
- const stripEOF = require ( 'strip-final-newline' ) ;
8
6
const fs = require ( 'fs/promises' ) ;
9
7
const debug = require ( 'debug' ) ( 'test' ) ;
10
- const execFile = promisify ( require ( 'child_process' ) . execFile ) ;
8
+ const execa = require ( 'execa' ) ;
11
9
12
- describe ( 'test installing the package' , ( ) => {
13
- const kFilename = 'deploy.tgz' ;
10
+ describe ( '(yarn) test installing the package' , ( ) => {
11
+ const kFilename = 'deploy-yarn .tgz' ;
14
12
const cwd = process . cwd ( ) ;
15
13
const tarball = resolve ( cwd , kFilename ) ;
16
14
const clean = async ( ) => {
@@ -23,11 +21,10 @@ describe('test installing the package', () => {
23
21
24
22
beforeAll ( async ( ) => {
25
23
await clean ( ) ;
26
- await execFile ( 'yarn' , [ 'config' , 'set' , 'preferred-cache-folder' , '/tmp/yarn-cache' ] ) ;
27
- await execFile ( 'yarn' , [ 'config' , 'set' , 'cache-folder' , '/tmp/yarn-cache-internal' ] ) ;
28
- await execFile ( 'yarn' , [ 'config' , 'set' , 'prefer-offline' , 'true' ] ) ;
29
- const { stdout } = await execFile ( 'yarn' , [ 'pack' , '--filename' , kFilename ] ) ;
30
- console . info ( stdout ) ;
24
+ await execa ( 'yarn' , [ 'config' , 'set' , 'preferred-cache-folder' , '/tmp/yarn-cache' ] ) ;
25
+ await execa ( 'yarn' , [ 'config' , 'set' , 'cache-folder' , '/tmp/yarn-cache-internal' ] ) ;
26
+ await execa ( 'yarn' , [ 'config' , 'set' , 'prefer-offline' , 'true' ] ) ;
27
+ await execa ( 'yarn' , [ 'pack' , '--filename' , kFilename ] ) ;
31
28
} ) ;
32
29
33
30
describe ( 'local install' , ( ) => {
@@ -36,21 +33,160 @@ describe('test installing the package', () => {
36
33
beforeAll ( async ( ) => {
37
34
debug ( 'changing to %s' , tmpDir ) ;
38
35
process . chdir ( tmpDir ) ;
39
- await execFile ( 'yarn' , [ 'init' , '-yp' ] ) ;
40
- await execFile ( 'git' , [ 'init' ] ) ;
36
+ await execa ( 'yarn' , [ 'init' , '-yp' ] ) ;
37
+ await execa ( 'git' , [ 'init' ] ) ;
41
38
} ) ;
42
39
43
40
test ( 'is able to install package locally' , async ( ) => {
44
- await execFile ( 'yarn' , [ 'add' , tarball , '--no-lockfile' ] ) ;
41
+ await execa ( 'yarn' , [ 'add' , tarball , '--no-lockfile' ] ) ;
42
+ await execa ( 'yarn' , [ 'mdep' , 'install' ] ) ;
45
43
} , 240000 ) ;
46
44
47
45
test ( 'returns node version' , async ( ) => {
48
- const { stdout } = await execFile ( 'node_modules/.bin/mdep' , [ 'get-config' , 'node' , '--node' , '99.0.0' ] ) ;
49
- expect ( stripEOF ( stdout ) ) . toBe ( '99.0.0' ) ;
46
+ const { stdout } = await execa ( 'node_modules/.bin/mdep' , [ 'get-config' , 'node' , '--node' , '99.0.0' ] ) ;
47
+ expect ( stdout ) . toBe ( '99.0.0' ) ;
50
48
} ) ;
51
49
52
50
test ( 'package.json enhanced' , async ( ) => {
53
- const pkg = require ( `${ tmpDir } /package.json` ) ; // eslint-disable-line import/no-dynamic-require
51
+ const pkg = JSON . parse ( await fs . readFile ( `${ tmpDir } /package.json` ) ) ;
52
+ expect ( pkg . scripts [ 'semantic-release' ] ) . toBeDefined ( ) ;
53
+ expect ( pkg . husky ) . toBeUndefined ( ) ;
54
+ } ) ;
55
+
56
+ test ( '.husky create' , async ( ) => {
57
+ expect ( ( await fs . stat ( '.husky' ) ) . isDirectory ( ) ) . toBe ( true ) ;
58
+ expect ( ( await fs . stat ( '.husky/_/husky.sh' ) ) . isFile ( ) ) . toBe ( true ) ;
59
+ expect ( ( await fs . stat ( '.husky/commit-msg' ) ) . isFile ( ) ) . toBe ( true ) ;
60
+ expect ( ( await fs . stat ( '.husky/prepare-commit-msg' ) ) . isFile ( ) ) . toBe ( true ) ;
61
+ } ) ;
62
+
63
+ test ( 'releaserc & commitlint copied over' , async ( ) => {
64
+ expect ( ( await fs . stat ( '.releaserc.json' ) ) . isFile ( ) ) . toBe ( true ) ;
65
+ expect ( ( await fs . stat ( '.commitlintrc.js' ) ) . isFile ( ) ) . toBe ( true ) ;
66
+ } ) ;
67
+
68
+ test ( 'on reinstall doesnt overwrite existing .releaserc.js(on)' , async ( ) => {
69
+ expect . assertions ( 1 ) ;
70
+
71
+ await fs . writeFile ( '.releaserc.json' , 'overwrite' ) ;
72
+ const { stderr } = await execa ( 'yarn' , [ 'add' , tarball , '--no-lockfile' ] ) ;
73
+ debug ( stderr ) ;
74
+ await expect ( fs . readFile ( '.releaserc.json' , 'utf8' ) ) . resolves . toBe ( 'overwrite' ) ;
75
+ } , 240000 ) ;
76
+
77
+ test ( 'on reinstall doesnt overwrite existing .commitlintrc.js' , async ( ) => {
78
+ expect . assertions ( 1 ) ;
79
+
80
+ await fs . writeFile ( '.commitlintrc.js' , 'overwrite' ) ;
81
+ await execa ( 'yarn' , [ 'add' , tarball , '--no-lockfile' ] ) ;
82
+ await expect ( fs . readFile ( '.commitlintrc.js' , 'utf8' ) ) . resolves . toBe ( 'overwrite' ) ;
83
+ } , 240000 ) ;
84
+ } ) ;
85
+
86
+ describe ( 'local install (husky migration)' , ( ) => {
87
+ const tmpDir = directory ( ) ;
88
+
89
+ beforeAll ( async ( ) => {
90
+ debug ( 'changing to %s' , tmpDir ) ;
91
+ process . chdir ( tmpDir ) ;
92
+ await execa ( 'yarn' , [ 'init' , '-yp' ] ) ;
93
+ await execa ( 'git' , [ 'init' ] ) ;
94
+
95
+ const pkgName = `${ tmpDir } /package.json` ;
96
+ const pkg = JSON . parse ( await fs . readFile ( pkgName ) ) ;
97
+ set ( pkg , 'husky.hooks.commit-msg' , 'commitlint -e $HUSKY_GIT_PARAMS' ) ;
98
+ await fs . writeFile ( pkgName , JSON . stringify ( pkg , null , 2 ) ) ;
99
+ } ) ;
100
+
101
+ test ( 'is able to install package locally' , async ( ) => {
102
+ await execa ( 'yarn' , [ 'add' , tarball , '--no-lockfile' ] ) ;
103
+ await execa ( 'yarn' , [ 'mdep' , 'install' ] ) ;
104
+ } , 240000 ) ;
105
+
106
+ test ( 'package.json enhanced, no husky' , async ( ) => {
107
+ const pkg = JSON . parse ( await fs . readFile ( `${ tmpDir } /package.json` ) ) ;
108
+ expect ( pkg . husky ) . toBeUndefined ( ) ;
109
+ } ) ;
110
+
111
+ test ( '.husky files present' , async ( ) => {
112
+ expect ( ( await fs . stat ( '.husky' ) ) . isDirectory ( ) ) . toBe ( true ) ;
113
+ expect ( ( await fs . stat ( '.husky/_/husky.sh' ) ) . isFile ( ) ) . toBe ( true ) ;
114
+ expect ( ( await fs . stat ( '.husky/commit-msg' ) ) . isFile ( ) ) . toBe ( true ) ;
115
+ expect ( ( await fs . stat ( '.husky/prepare-commit-msg' ) ) . isFile ( ) ) . toBe ( true ) ;
116
+
117
+ const files = await fs . readdir ( '.husky' ) ;
118
+ expect ( files . length ) . toBe ( 3 ) ;
119
+ } ) ;
120
+
121
+ test ( '.husky files content sane' , async ( ) => {
122
+ const contents = await fs . readFile ( '.husky/commit-msg' , { encoding : 'utf8' } ) ;
123
+ expect ( contents ) . toContain ( 'npx --no-install commitlint -e $1' ) ;
124
+ } ) ;
125
+ } ) ;
126
+
127
+ describe ( 'installs globally' , ( ) => {
128
+ test ( 'is able to install package globally' , async ( ) => {
129
+ await execa ( 'yarn' , [ 'global' , 'add' , tarball , '--no-lockfile' ] ) ;
130
+ } , 240000 ) ;
131
+
132
+ test ( 'returns current node version in module' , async ( ) => {
133
+ process . chdir ( cwd ) ;
134
+ const { stdout } = await execa ( 'mdep' , [ 'get-config' , '--path' , 'node' ] ) ;
135
+ expect ( stdout ) . toBe ( '16' ) ;
136
+ } ) ;
137
+ } ) ;
138
+
139
+ afterAll ( clean ) ;
140
+ } ) ;
141
+
142
+ describe ( '(pnpm) test installing the package' , ( ) => {
143
+ const kFilename = 'makeomatic-deploy-0.0.0-development.tgz' ;
144
+ const cwd = process . cwd ( ) ;
145
+ const tarball = resolve ( cwd , kFilename ) ;
146
+ const clean = async ( ) => {
147
+ try {
148
+ await fs . rm ( tarball ) ;
149
+ } catch ( e ) {
150
+ process . stderr . write ( `nothing to cleanup ~ ${ tarball } \n` ) ;
151
+ }
152
+ } ;
153
+
154
+ beforeAll ( async ( ) => {
155
+ await clean ( ) ;
156
+ await execa ( 'pnpm' , [ 'pack' ] ) ;
157
+ } ) ;
158
+
159
+ describe ( 'local install' , ( ) => {
160
+ const tmpDir = directory ( ) ;
161
+
162
+ beforeAll ( async ( ) => {
163
+ debug ( 'changing to %s' , tmpDir ) ;
164
+ process . chdir ( tmpDir ) ;
165
+ await execa ( 'pnpm' , [ 'init' , '-yp' ] ) ;
166
+ await execa ( 'git' , [ 'init' ] ) ;
167
+ } ) ;
168
+
169
+ test ( 'is able to install package locally' , async ( ) => {
170
+ const proc = execa ( 'pnpm' , [ 'add' , tarball ] , {
171
+ buffer : false ,
172
+ cwd : tmpDir ,
173
+ all : true ,
174
+ env : {
175
+ DEBUG : 'makeomatic:deploy' ,
176
+ } ,
177
+ } ) ;
178
+ proc . all . pipe ( process . stdout ) ;
179
+ await proc ;
180
+ await execa ( 'pnpm' , [ 'mdep' , 'install' ] ) ;
181
+ } , 240000 ) ;
182
+
183
+ test ( 'returns node version' , async ( ) => {
184
+ const { stdout } = await execa ( 'node_modules/.bin/mdep' , [ 'get-config' , 'node' , '--node' , '99.0.0' ] ) ;
185
+ expect ( stdout ) . toBe ( '99.0.0' ) ;
186
+ } ) ;
187
+
188
+ test ( 'package.json enhanced' , async ( ) => {
189
+ const pkg = JSON . parse ( await fs . readFile ( `${ tmpDir } /package.json` ) ) ;
54
190
expect ( pkg . scripts [ 'semantic-release' ] ) . toBeDefined ( ) ;
55
191
expect ( pkg . husky ) . toBeUndefined ( ) ;
56
192
} ) ;
@@ -71,7 +207,7 @@ describe('test installing the package', () => {
71
207
expect . assertions ( 1 ) ;
72
208
73
209
await fs . writeFile ( '.releaserc.json' , 'overwrite' ) ;
74
- const { stderr } = await execFile ( 'yarn ', [ 'add' , tarball , '--no-lockfile' ] ) ;
210
+ const { stderr } = await execa ( 'pnpm ', [ 'add' , tarball ] ) ;
75
211
debug ( stderr ) ;
76
212
await expect ( fs . readFile ( '.releaserc.json' , 'utf8' ) ) . resolves . toBe ( 'overwrite' ) ;
77
213
} , 240000 ) ;
@@ -80,7 +216,7 @@ describe('test installing the package', () => {
80
216
expect . assertions ( 1 ) ;
81
217
82
218
await fs . writeFile ( '.commitlintrc.js' , 'overwrite' ) ;
83
- await execFile ( 'yarn ', [ 'add' , tarball , '--no-lockfile' ] ) ;
219
+ await execa ( 'pnpm ', [ 'add' , tarball ] ) ;
84
220
await expect ( fs . readFile ( '.commitlintrc.js' , 'utf8' ) ) . resolves . toBe ( 'overwrite' ) ;
85
221
} , 240000 ) ;
86
222
} ) ;
@@ -91,8 +227,8 @@ describe('test installing the package', () => {
91
227
beforeAll ( async ( ) => {
92
228
debug ( 'changing to %s' , tmpDir ) ;
93
229
process . chdir ( tmpDir ) ;
94
- await execFile ( 'yarn ', [ 'init' , '-yp' ] ) ;
95
- await execFile ( 'git' , [ 'init' ] ) ;
230
+ await execa ( 'pnpm ', [ 'init' , '-yp' ] ) ;
231
+ await execa ( 'git' , [ 'init' ] ) ;
96
232
97
233
const pkgName = `${ tmpDir } /package.json` ;
98
234
const pkg = JSON . parse ( await fs . readFile ( pkgName ) ) ;
@@ -101,7 +237,17 @@ describe('test installing the package', () => {
101
237
} ) ;
102
238
103
239
test ( 'is able to install package locally' , async ( ) => {
104
- await execFile ( 'yarn' , [ 'add' , tarball , '--no-lockfile' ] ) ;
240
+ const proc = execa ( 'pnpm' , [ 'add' , tarball ] , {
241
+ buffer : false ,
242
+ cwd : tmpDir ,
243
+ all : true ,
244
+ env : {
245
+ DEBUG : 'makeomatic:deploy' ,
246
+ } ,
247
+ } ) ;
248
+ proc . all . pipe ( process . stdout ) ;
249
+ await proc ;
250
+ await execa ( 'pnpm' , [ 'mdep' , 'install' ] ) ;
105
251
} , 240000 ) ;
106
252
107
253
test ( 'package.json enhanced, no husky' , async ( ) => {
@@ -127,13 +273,13 @@ describe('test installing the package', () => {
127
273
128
274
describe ( 'installs globally' , ( ) => {
129
275
test ( 'is able to install package globally' , async ( ) => {
130
- await execFile ( 'yarn ', [ 'global ' , 'add' , tarball , '--no-lockfile' ] ) ;
276
+ await execa ( 'pnpm ', [ '-g ' , 'add' , tarball ] ) ;
131
277
} , 240000 ) ;
132
278
133
279
test ( 'returns current node version in module' , async ( ) => {
134
280
process . chdir ( cwd ) ;
135
- const { stdout } = await execFile ( 'mdep' , [ 'get-config' , '--path' , 'node' ] ) ;
136
- expect ( stripEOF ( stdout ) ) . toBe ( '16' ) ;
281
+ const { stdout } = await execa ( 'mdep' , [ 'get-config' , '--path' , 'node' ] ) ;
282
+ expect ( stdout ) . toBe ( '16' ) ;
137
283
} ) ;
138
284
} ) ;
139
285
0 commit comments