Skip to content

Commit 480799a

Browse files
committed
Adjust test
1 parent 2893587 commit 480799a

File tree

2 files changed

+91
-20
lines changed

2 files changed

+91
-20
lines changed

packages/eas-cli/src/vcs/clients/__tests__/git.test.ts

+84-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import fs from 'fs/promises';
33
import os from 'os';
44
import path from 'path';
55

6+
import Log from '../../../log';
67
import GitClient from '../git';
8+
// import getenv from 'getenv';
79

810
describe('git', () => {
911
describe('GitClient that does not require a commit', () => {
@@ -242,27 +244,91 @@ describe('git', () => {
242244
).resolves.not.toThrow();
243245
});
244246

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();
251275
});
252276

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+
});
255284

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+
});
261319

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+
});
267333
});
268334
});

packages/eas-cli/src/vcs/clients/git.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import spawnAsync from '@expo/spawn-async';
33
import { Errors } from '@oclif/core';
44
import chalk from 'chalk';
55
import fs from 'fs-extra';
6-
import { boolish } from 'getenv';
6+
import getenv from 'getenv';
77
import path from 'path';
88

99
import Log, { learnMore } from '../../log';
@@ -19,6 +19,8 @@ import {
1919
import { EASIGNORE_FILENAME, Ignore, makeShallowCopyAsync } from '../local';
2020
import { Client } from '../vcs';
2121

22+
let hasWarnedAboutEasignoreInRequireCommit = false;
23+
2224
export default class GitClient extends Client {
2325
private readonly maybeCwdOverride?: string;
2426
public requireCommit: boolean;
@@ -166,11 +168,14 @@ export default class GitClient extends Client {
166168
const rootPath = await this.getRootPathAsync();
167169
const sourceEasignorePath = path.join(rootPath, EASIGNORE_FILENAME);
168170
const doesEasignoreExist = await fs.exists(sourceEasignorePath);
169-
const shouldSuppressWarning = boolish('EAS_SUPPRESS_REQUIRE_COMMIT_EASIGNORE_WARNING', false);
171+
const shouldSuppressWarning =
172+
hasWarnedAboutEasignoreInRequireCommit ||
173+
getenv.boolish('EAS_SUPPRESS_REQUIRE_COMMIT_EASIGNORE_WARNING', false);
170174
if (this.requireCommit && doesEasignoreExist && !shouldSuppressWarning) {
171175
Log.warn(
172176
`You have "requireCommit: true" in "eas.json" and also ".easignore". If ".easignore" does remove files, note that the repository checked out in EAS will not longer be Git-clean.`
173177
);
178+
hasWarnedAboutEasignoreInRequireCommit = true;
174179
}
175180

176181
let gitRepoUri;

0 commit comments

Comments
 (0)