Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This is the log of notable changes to EAS CLI and related packages.

### 🐛 Bug fixes

- [eas-cli] Remove temporary working directories after `eas build:inspect` copies inspect output, avoiding leftover disk usage after failed builds. ([#3981](https://github.com/expo/eas-cli/pull/3981) by [@szdziedzic](https://github.com/szdziedzic))
- [build-tools] Skip embedded bundle upload for development client builds instead of warning that the bundle is missing. ([#3940](https://github.com/expo/eas-cli/pull/3940) by [@gwdp](https://github.com/gwdp))
- [eas-cli] Retry uploading assets that don't finish processing during `eas update`, instead of failing the update. ([#3918](https://github.com/expo/eas-cli/pull/3918) by [@gwdp](https://github.com/gwdp))

Expand Down
92 changes: 92 additions & 0 deletions packages/eas-cli/src/commands/build/__tests__/inspect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import fs from 'fs-extra';
import path from 'path';

import { getMockOclifConfig } from '../../../__tests__/commands/utils';
import { runBuildAndSubmitAsync } from '../../../build/runBuildAndSubmit';
import BuildInspect from '../inspect';

jest.mock('fs-extra', () => ({
pathExists: jest.fn(),
remove: jest.fn(),
mkdirp: jest.fn(),
copy: jest.fn(),
}));
jest.mock('../../../build/runBuildAndSubmit', () => ({
runBuildAndSubmitAsync: jest.fn(),
}));
jest.mock('../../../log');
jest.mock('../../../ora', () => ({
ora: jest.fn(() => ({
start: jest.fn(() => ({
succeed: jest.fn(),
fail: jest.fn(),
})),
})),
}));
jest.mock('../../../utils/paths', () => ({
...jest.requireActual('../../../utils/paths'),
getTmpDirectory: jest.fn(() => '/tmp/eas-cli'),
}));
jest.mock('uuid', () => ({
v4: jest.fn(() => 'tmp-id'),
}));

describe(BuildInspect, () => {
const mockConfig = getMockOclifConfig();
const tmpWorkingdir = '/tmp/eas-cli/tmp-id';
const tmpBuildDir = path.join(tmpWorkingdir, 'build');
const outputDirectory = path.join(process.cwd(), 'inspect-output');
const mockPathExists = fs.pathExists as jest.Mock;
const mockMkdirp = fs.mkdirp as jest.Mock;
const mockCopy = fs.copy as jest.Mock;
const mockRemove = fs.remove as jest.Mock;

beforeEach(() => {
jest.clearAllMocks();
mockPathExists.mockResolvedValue(false);
mockMkdirp.mockResolvedValue(undefined);
mockCopy.mockResolvedValue(undefined);
mockRemove.mockResolvedValue(undefined);
jest.mocked(runBuildAndSubmitAsync).mockResolvedValue({ buildIds: [] });
});

function createCommand(): BuildInspect {
const command = new BuildInspect(
['--platform', 'ios', '--stage', 'pre-build', '--output', 'inspect-output'],
mockConfig
);
jest.spyOn(command as any, 'getContextAsync').mockResolvedValue({
loggedIn: {
actor: {},
graphqlClient: {},
},
getDynamicPrivateProjectConfigAsync: jest.fn(),
projectDir: '/project',
analytics: {},
vcsClient: {},
} as any);
return command;
}

it('removes the temporary working directory after copying output when the build fails', async () => {
jest.mocked(runBuildAndSubmitAsync).mockRejectedValue(new Error('build failed'));
mockPathExists.mockResolvedValueOnce(false).mockResolvedValueOnce(true);

await createCommand().runAsync();

expect(fs.copy).toHaveBeenCalledWith(tmpBuildDir, outputDirectory);
expect(fs.remove).toHaveBeenCalledWith(tmpBuildDir);
expect(fs.remove).toHaveBeenCalledWith(tmpWorkingdir);
});

it('keeps the temporary working directory when copying output fails', async () => {
jest.mocked(runBuildAndSubmitAsync).mockRejectedValue(new Error('build failed'));
mockPathExists.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
mockCopy.mockRejectedValue(new Error('copy failed'));

await expect(createCommand().runAsync()).rejects.toThrow('copy failed');

expect(fs.remove).not.toHaveBeenCalledWith(tmpBuildDir);
expect(fs.remove).not.toHaveBeenCalledWith(tmpWorkingdir);
});
});
10 changes: 10 additions & 0 deletions packages/eas-cli/src/commands/build/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export default class BuildInspect extends EasCommand {
}
} finally {
await this.copyToOutputDirAsync(path.join(tmpWorkingdir, 'build'), outputDirectory);
await this.cleanUpTmpWorkingdirAsync(tmpWorkingdir);
}
}
}
Expand Down Expand Up @@ -163,4 +164,13 @@ export default class BuildInspect extends EasCommand {
throw err;
}
}

private async cleanUpTmpWorkingdirAsync(tmpWorkingdir: string): Promise<void> {
try {
await fs.remove(tmpWorkingdir);
} catch (err) {
Log.warn(`Failed to remove temporary directory ${tmpWorkingdir}`);
Log.debug(err);
}
}
}
Loading