@@ -6,6 +6,12 @@ const uniqueTempDir = require('unique-temp-dir');
6
6
const { test} = require ( 'tap' ) ;
7
7
const { execCli} = require ( '../helper/cli' ) ;
8
8
9
+ const overrideCIChecks = {
10
+ CI : '' ,
11
+ TRAVIS : '' ,
12
+ CONTINUOUS_INTEGRATION : ''
13
+ } ;
14
+
9
15
for ( const obj of [
10
16
{ type : 'colocated' , rel : '' , dir : '' } ,
11
17
{ type : '__tests__' , rel : '__tests__-dir' , dir : '__tests__/__snapshots__' } ,
@@ -24,7 +30,7 @@ for (const obj of [
24
30
25
31
const dirname = path . join ( 'fixture/snapshots' , obj . rel ) ;
26
32
// Test should pass, and a snapshot gets written
27
- execCli ( [ '--update-snapshots' ] , { dirname} , error => {
33
+ execCli ( [ '--update-snapshots' , '--verbose' ] , { dirname, env : overrideCIChecks } , error => {
28
34
t . ifError ( error ) ;
29
35
t . true ( fs . existsSync ( snapPath ) ) ;
30
36
@@ -50,7 +56,7 @@ test('one', t => {
50
56
})` ;
51
57
fs . writeFileSync ( path . join ( cwd , 'test.js' ) , initial ) ;
52
58
53
- const run = ( ) => execa ( process . execPath , [ cliPath , '--verbose' , '--no-color' ] , { cwd, env : { CI : '1' } , reject : false } ) ;
59
+ const run = ( ) => execa ( process . execPath , [ cliPath , '--verbose' , '--no-color' ] , { cwd, env : overrideCIChecks , reject : false } ) ;
54
60
return run ( ) . then ( result => {
55
61
t . match ( result . stdout , / 1 t e s t p a s s e d / ) ;
56
62
@@ -161,7 +167,7 @@ test('snapshots infer their location and name from sourcemaps', t => {
161
167
t . true ( fs . existsSync ( relFilePath ) ) ;
162
168
} ;
163
169
164
- execCli ( [ ] , { dirname : relativeFixtureDir } , ( error , stdout ) => {
170
+ execCli ( [ '--verbose' ] , { dirname : relativeFixtureDir , env : overrideCIChecks } , ( error , stdout ) => {
165
171
t . ifError ( error ) ;
166
172
snapFixtureFilePaths . forEach ( x => verifySnapFixtureFiles ( x ) ) ;
167
173
t . match ( stdout , / 6 t e s t s p a s s e d / ) ;
@@ -202,7 +208,7 @@ test('snapshots resolved location from "snapshotDir" in AVA config', t => {
202
208
t . true ( fs . existsSync ( relFilePath ) ) ;
203
209
} ;
204
210
205
- execCli ( [ ] , { dirname : relativeFixtureDir } , ( error , stdout ) => {
211
+ execCli ( [ '--verbose' ] , { dirname : relativeFixtureDir , env : overrideCIChecks } , ( error , stdout ) => {
206
212
t . ifError ( error ) ;
207
213
snapFixtureFilePaths . forEach ( x => verifySnapFixtureFiles ( x ) ) ;
208
214
t . match ( stdout , / 6 t e s t s p a s s e d / ) ;
@@ -231,7 +237,7 @@ test('snapshots are indentical on different platforms', t => {
231
237
[ reportPath , snapPath ] . forEach ( fp => removeFile ( fp ) ) ;
232
238
233
239
// Test should pass, and a snapshot gets written
234
- execCli ( [ '--update-snapshots' ] , { dirname : fixtureDir } , error => {
240
+ execCli ( [ '--update-snapshots' , '--verbose' ] , { dirname : fixtureDir , env : overrideCIChecks } , error => {
235
241
t . ifError ( error ) ;
236
242
t . true ( fs . existsSync ( reportPath ) ) ;
237
243
t . true ( fs . existsSync ( snapPath ) ) ;
@@ -246,3 +252,30 @@ test('snapshots are indentical on different platforms', t => {
246
252
t . end ( ) ;
247
253
} ) ;
248
254
} ) ;
255
+
256
+ test ( 'in CI, new snapshots are not recorded' , t => {
257
+ const fixtureDir = path . join ( __dirname , '..' , 'fixture' , 'snapshots' , 'test-content' ) ;
258
+ const reportPath = path . join ( fixtureDir , 'tests' , 'snapshots' , 'test.js.md' ) ;
259
+ const snapPath = path . join ( fixtureDir , 'tests' , 'snapshots' , 'test.js.snap' ) ;
260
+
261
+ const removeFile = filePath => {
262
+ try {
263
+ fs . unlinkSync ( filePath ) ;
264
+ } catch ( error ) {
265
+ if ( error . code !== 'ENOENT' ) {
266
+ throw error ;
267
+ }
268
+ }
269
+ } ;
270
+
271
+ // Clear current snapshots
272
+ [ reportPath , snapPath ] . forEach ( fp => removeFile ( fp ) ) ;
273
+
274
+ // Test should fail, no snapshot gets written
275
+ execCli ( [ ] , { dirname : fixtureDir } , ( _ , stdout ) => {
276
+ t . match ( stdout , 'No snapshot available — new snapshots are not created in CI environments' ) ;
277
+ t . false ( fs . existsSync ( reportPath ) ) ;
278
+ t . false ( fs . existsSync ( snapPath ) ) ;
279
+ t . end ( ) ;
280
+ } ) ;
281
+ } ) ;
0 commit comments