@@ -3,7 +3,9 @@ import fs from 'fs/promises';
3
3
import os from 'os' ;
4
4
import path from 'path' ;
5
5
6
+ import Log from '../../../log' ;
6
7
import GitClient from '../git' ;
8
+ // import getenv from 'getenv';
7
9
8
10
describe ( 'git' , ( ) => {
9
11
describe ( 'GitClient that does not require a commit' , ( ) => {
@@ -242,27 +244,91 @@ describe('git', () => {
242
244
) . resolves . not . toThrow ( ) ;
243
245
} ) ;
244
246
245
- it ( 'adheres to .easignore if requireCommit is true' , async ( ) => {
246
- const repoRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'eas-cli-git-test-' ) ) ;
247
- await spawnAsync ( 'git' , [ 'init' ] , { cwd : repoRoot } ) ;
248
- const vcs = new GitClient ( {
249
- requireCommit : true ,
250
- maybeCwdOverride : repoRoot ,
247
+ describe ( 'when requireCommit is true' , ( ) => {
248
+ it ( 'adheres to .easignore' , async ( ) => {
249
+ const repoRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'eas-cli-git-test-' ) ) ;
250
+ await spawnAsync ( 'git' , [ 'init' ] , { cwd : repoRoot } ) ;
251
+ const vcs = new GitClient ( {
252
+ requireCommit : true ,
253
+ maybeCwdOverride : repoRoot ,
254
+ } ) ;
255
+
256
+ const warn = jest . spyOn ( Log , 'warn' ) ;
257
+
258
+ await fs . writeFile ( `${ repoRoot } /.easignore` , '*easignored*\n' ) ;
259
+ await fs . writeFile ( `${ repoRoot } /.gitignore` , '*gitignored*\n' ) ;
260
+
261
+ await fs . writeFile ( `${ repoRoot } /easignored-file.txt` , 'file' ) ;
262
+ await fs . writeFile ( `${ repoRoot } /nonignored-file.txt` , 'file' ) ;
263
+ await fs . writeFile ( `${ repoRoot } /gitignored-file.txt` , 'file' ) ;
264
+ await spawnAsync ( 'git' , [ 'add' , '.' ] , { cwd : repoRoot } ) ;
265
+ await spawnAsync ( 'git' , [ 'commit' , '-m' , 'tmp commit' ] , { cwd : repoRoot } ) ;
266
+
267
+ const copyRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'eas-cli-git-test-' ) ) ;
268
+ await expect ( vcs . makeShallowCopyAsync ( copyRoot ) ) . resolves . not . toThrow ( ) ;
269
+
270
+ expect ( warn ) . toHaveBeenCalledWith ( expect . stringContaining ( '.easignore' ) ) ;
271
+
272
+ await expect ( fs . stat ( path . join ( copyRoot , 'easignored-file.txt' ) ) ) . rejects . toThrow ( 'ENOENT' ) ;
273
+ await expect ( fs . stat ( path . join ( copyRoot , 'gitignored-file.txt' ) ) ) . rejects . toThrow ( 'ENOENT' ) ;
274
+ await expect ( fs . stat ( path . join ( copyRoot , 'nonignored-file.txt' ) ) ) . resolves . not . toThrow ( ) ;
251
275
} ) ;
252
276
253
- await fs . writeFile ( `${ repoRoot } /.easignore` , '*easignored*\n' ) ;
254
- await fs . writeFile ( `${ repoRoot } /.gitignore` , '*gitignored*\n' ) ;
277
+ it ( 'prints a warning only once if .easignore exists' , async ( ) => {
278
+ const repoRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'eas-cli-git-test-' ) ) ;
279
+ await spawnAsync ( 'git' , [ 'init' ] , { cwd : repoRoot } ) ;
280
+ const vcs = new GitClient ( {
281
+ requireCommit : true ,
282
+ maybeCwdOverride : repoRoot ,
283
+ } ) ;
255
284
256
- await fs . writeFile ( `${ repoRoot } /easignored-file.txt` , 'file' ) ;
257
- await fs . writeFile ( `${ repoRoot } /nonignored-file.txt` , 'file' ) ;
258
- await fs . writeFile ( `${ repoRoot } /gitignored-file.txt` , 'file' ) ;
259
- await spawnAsync ( 'git' , [ 'add' , '.' ] , { cwd : repoRoot } ) ;
260
- await spawnAsync ( 'git' , [ 'commit' , '-m' , 'tmp commit' ] , { cwd : repoRoot } ) ;
285
+ const warn = jest . spyOn ( Log , 'warn' ) ;
286
+
287
+ await fs . writeFile ( `${ repoRoot } /.easignore` , '*easignored*\n' ) ;
288
+ await spawnAsync ( 'git' , [ 'add' , '.' ] , { cwd : repoRoot } ) ;
289
+ await spawnAsync ( 'git' , [ 'commit' , '-m' , 'tmp commit' ] , { cwd : repoRoot } ) ;
290
+
291
+ const copyRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'eas-cli-git-test-' ) ) ;
292
+ await expect ( vcs . makeShallowCopyAsync ( copyRoot ) ) . resolves . not . toThrow ( ) ;
293
+
294
+ expect ( warn ) . toHaveBeenCalledTimes ( 1 ) ;
295
+ expect ( warn ) . toHaveBeenCalledWith ( expect . stringContaining ( '.easignore' ) ) ;
296
+
297
+ const anotherCopyRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'eas-cli-git-test-' ) ) ;
298
+ await expect ( vcs . makeShallowCopyAsync ( anotherCopyRoot ) ) . resolves . not . toThrow ( ) ;
299
+
300
+ expect ( warn ) . toHaveBeenCalledTimes ( 1 ) ;
301
+ } ) ;
302
+
303
+ describe ( 'when EAS_SUPPRESS_REQUIRE_COMMIT_EASIGNORE_WARNING is set' , ( ) => {
304
+ beforeAll ( ( ) => {
305
+ process . env . EAS_SUPPRESS_REQUIRE_COMMIT_EASIGNORE_WARNING = '1' ;
306
+ } ) ;
307
+
308
+ afterAll ( ( ) => {
309
+ delete process . env . EAS_SUPPRESS_REQUIRE_COMMIT_EASIGNORE_WARNING ;
310
+ } ) ;
311
+
312
+ it ( 'does not print a warning' , async ( ) => {
313
+ const repoRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'eas-cli-git-test-' ) ) ;
314
+ await spawnAsync ( 'git' , [ 'init' ] , { cwd : repoRoot } ) ;
315
+ const vcs = new GitClient ( {
316
+ requireCommit : true ,
317
+ maybeCwdOverride : repoRoot ,
318
+ } ) ;
261
319
262
- const copyRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'eas-cli-git-test-' ) ) ;
263
- await expect ( vcs . makeShallowCopyAsync ( copyRoot ) ) . resolves . not . toThrow ( ) ;
264
- await expect ( fs . stat ( path . join ( copyRoot , 'easignored-file.txt' ) ) ) . rejects . toThrow ( 'ENOENT' ) ;
265
- await expect ( fs . stat ( path . join ( copyRoot , 'gitignored-file.txt' ) ) ) . rejects . toThrow ( 'ENOENT' ) ;
266
- await expect ( fs . stat ( path . join ( copyRoot , 'nonignored-file.txt' ) ) ) . resolves . not . toThrow ( ) ;
320
+ const warn = jest . spyOn ( Log , 'warn' ) ;
321
+ warn . mockClear ( ) ;
322
+
323
+ await fs . writeFile ( `${ repoRoot } /.easignore` , '*easignored*\n' ) ;
324
+ await spawnAsync ( 'git' , [ 'add' , '.' ] , { cwd : repoRoot } ) ;
325
+ await spawnAsync ( 'git' , [ 'commit' , '-m' , 'tmp commit' ] , { cwd : repoRoot } ) ;
326
+
327
+ const copyRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'eas-cli-git-test-' ) ) ;
328
+ await expect ( vcs . makeShallowCopyAsync ( copyRoot ) ) . resolves . not . toThrow ( ) ;
329
+
330
+ expect ( warn ) . toHaveBeenCalledTimes ( 0 ) ;
331
+ } ) ;
332
+ } ) ;
267
333
} ) ;
268
334
} ) ;
0 commit comments