@@ -9,6 +9,8 @@ const Tmp = require('tmp');
9
9
10
10
const NodeSupport = require ( '..' ) ;
11
11
12
+ const Utils = require ( '../lib/utils' ) ;
13
+
12
14
13
15
const { describe, it, beforeEach, afterEach } = exports . lab = require ( '@hapi/lab' ) . script ( ) ;
14
16
const { expect } = require ( '@hapi/code' ) ;
@@ -24,10 +26,6 @@ internals.prepareFixture = async ({ travisYml, packageJson, git = true } = {}) =
24
26
25
27
internals . tmpObjects . push ( tmpObj ) ;
26
28
27
- if ( git ) {
28
- await SimpleGit ( tmpObj . name ) . init ( ) ;
29
- }
30
-
31
29
if ( travisYml ) {
32
30
Fs . copyFileSync ( Path . join ( __dirname , 'fixtures' , travisYml ) , Path . join ( tmpObj . name , '.travis.yml' ) ) ;
33
31
}
@@ -37,15 +35,41 @@ internals.prepareFixture = async ({ travisYml, packageJson, git = true } = {}) =
37
35
version : '0.0.0-development'
38
36
} ) ) ;
39
37
38
+ if ( git ) {
39
+ const simpleGit = SimpleGit ( tmpObj . name ) ;
40
+ await simpleGit . init ( ) ;
41
+ await simpleGit . add ( './*' ) ;
42
+ await simpleGit . commit ( 'initial commit' , [ '--no-gpg-sign' ] ) ;
43
+ }
44
+
40
45
return tmpObj . name ;
41
46
} ;
42
47
43
48
49
+ internals . assertCommit = ( result ) => {
50
+
51
+ expect ( result . commit ) . to . match ( / ^ [ 0 - 9 a - f ] { 40 } $ / ) ;
52
+ delete result . commit ;
53
+ } ;
54
+
44
55
describe ( 'node-support' , ( ) => {
45
56
57
+ let listRemoteStub ;
58
+
46
59
beforeEach ( ( ) => {
47
60
48
61
Sinon . useFakeTimers ( new Date ( '2020-02-02T20:00:02Z' ) ) ;
62
+
63
+ listRemoteStub = Sinon . stub ( ) . throws ( ) ;
64
+
65
+ Sinon . stub ( Utils , 'simpleGit' ) . callsFake ( ( ...args ) => {
66
+
67
+ const simpleGit = SimpleGit ( ...args ) ;
68
+
69
+ Sinon . stub ( simpleGit , 'listRemote' ) . callsFake ( listRemoteStub ) ;
70
+
71
+ return simpleGit ;
72
+ } ) ;
49
73
} ) ;
50
74
51
75
afterEach ( ( ) => {
@@ -70,6 +94,8 @@ describe('node-support', () => {
70
94
71
95
const result = await NodeSupport . detect ( { path } ) ;
72
96
97
+ internals . assertCommit ( result ) ;
98
+
73
99
expect ( result ) . to . equal ( {
74
100
name : 'node-support' ,
75
101
version : '0.0.0-development' ,
@@ -87,6 +113,8 @@ describe('node-support', () => {
87
113
88
114
const result = await NodeSupport . detect ( { path } ) ;
89
115
116
+ internals . assertCommit ( result ) ;
117
+
90
118
expect ( result ) . to . equal ( {
91
119
name : 'test-module' ,
92
120
version : '0.0.0-development' ,
@@ -102,6 +130,8 @@ describe('node-support', () => {
102
130
103
131
const result = await NodeSupport . detect ( { path } ) ;
104
132
133
+ internals . assertCommit ( result ) ;
134
+
105
135
expect ( result ) . to . equal ( {
106
136
name : 'test-module' ,
107
137
version : '0.0.0-development' ,
@@ -120,6 +150,8 @@ describe('node-support', () => {
120
150
121
151
const result = await NodeSupport . detect ( { path } ) ;
122
152
153
+ internals . assertCommit ( result ) ;
154
+
123
155
expect ( result ) . to . equal ( {
124
156
name : 'test-module' ,
125
157
version : '0.0.0-development' ,
@@ -138,6 +170,8 @@ describe('node-support', () => {
138
170
139
171
const result = await NodeSupport . detect ( { path } ) ;
140
172
173
+ internals . assertCommit ( result ) ;
174
+
141
175
expect ( result ) . to . equal ( {
142
176
name : 'test-module' ,
143
177
version : '0.0.0-development' ,
@@ -156,6 +190,8 @@ describe('node-support', () => {
156
190
157
191
const result = await NodeSupport . detect ( { path } ) ;
158
192
193
+ internals . assertCommit ( result ) ;
194
+
159
195
expect ( result ) . to . equal ( {
160
196
name : 'test-module' ,
161
197
version : '0.0.0-development' ,
@@ -174,6 +210,8 @@ describe('node-support', () => {
174
210
175
211
const result = await NodeSupport . detect ( { path } ) ;
176
212
213
+ internals . assertCommit ( result ) ;
214
+
177
215
expect ( result ) . to . equal ( {
178
216
name : 'test-module' ,
179
217
version : '0.0.0-development' ,
@@ -192,6 +230,8 @@ describe('node-support', () => {
192
230
193
231
const result = await NodeSupport . detect ( { path } ) ;
194
232
233
+ internals . assertCommit ( result ) ;
234
+
195
235
expect ( result ) . to . equal ( {
196
236
name : 'test-module' ,
197
237
version : '0.0.0-development' ,
@@ -210,6 +250,8 @@ describe('node-support', () => {
210
250
211
251
const result = await NodeSupport . detect ( { path } ) ;
212
252
253
+ internals . assertCommit ( result ) ;
254
+
213
255
expect ( result ) . to . equal ( {
214
256
name : 'test-module' ,
215
257
version : '0.0.0-development' ,
@@ -228,6 +270,8 @@ describe('node-support', () => {
228
270
229
271
const result = await NodeSupport . detect ( { path } ) ;
230
272
273
+ internals . assertCommit ( result ) ;
274
+
231
275
expect ( result ) . to . equal ( {
232
276
name : 'test-module' ,
233
277
version : '0.0.0-development' ,
@@ -246,6 +290,8 @@ describe('node-support', () => {
246
290
247
291
const result = await NodeSupport . detect ( { path } ) ;
248
292
293
+ internals . assertCommit ( result ) ;
294
+
249
295
expect ( result ) . to . equal ( {
250
296
name : 'test-module' ,
251
297
version : '0.0.0-development' ,
@@ -264,6 +310,8 @@ describe('node-support', () => {
264
310
265
311
const result = await NodeSupport . detect ( { path } ) ;
266
312
313
+ internals . assertCommit ( result ) ;
314
+
267
315
expect ( result ) . to . equal ( {
268
316
name : 'test-module' ,
269
317
version : '0.0.0-development' ,
@@ -282,6 +330,8 @@ describe('node-support', () => {
282
330
283
331
const result = await NodeSupport . detect ( { path } ) ;
284
332
333
+ internals . assertCommit ( result ) ;
334
+
285
335
expect ( result ) . to . equal ( {
286
336
name : 'test-module' ,
287
337
version : '0.0.0-development' ,
@@ -301,7 +351,6 @@ describe('node-support', () => {
301
351
} ) ;
302
352
} ) ;
303
353
304
-
305
354
describe ( 'repository' , ( ) => {
306
355
307
356
beforeEach ( ( ) => {
@@ -319,6 +368,9 @@ describe('node-support', () => {
319
368
320
369
it ( 'returns node versions from `.travis.yml` in the repository' , async ( ) => {
321
370
371
+ listRemoteStub
372
+ . returns ( '9cef39d21ad229dea4b10295f55b0d9a83800b23\tHEAD\n' ) ;
373
+
322
374
Nock ( 'https://raw.githubusercontent.com' )
323
375
. get ( '/pkgjs/node-support/HEAD/package.json' )
324
376
. reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , 'package.json' ) ) )
@@ -327,9 +379,13 @@ describe('node-support', () => {
327
379
328
380
const result = await NodeSupport . detect ( { repository : 'git+https://github.com/pkgjs/node-support.git' } ) ;
329
381
382
+ expect ( listRemoteStub . callCount ) . to . equal ( 1 ) ;
383
+ expect ( listRemoteStub . args [ 0 ] ) . to . equal ( [ [ 'http://github.com/pkgjs/node-support.git' , 'HEAD' ] ] ) ;
384
+
330
385
expect ( result ) . to . equal ( {
331
386
name : 'node-support' ,
332
387
version : '0.0.0-development' ,
388
+ commit : '9cef39d21ad229dea4b10295f55b0d9a83800b23' ,
333
389
timestamp : 1580673602000 ,
334
390
travis : {
335
391
raw : [ '10' , '12' , '13' ]
0 commit comments