-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eas-cli] add tests for
eas build:version:*
commands (#1829)
* [eas-cli] add utils for testing eas commands and write tests for build:version:* * review feedback
- Loading branch information
Showing
8 changed files
with
646 additions
and
2 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
packages/eas-cli/src/__tests__/commands/__snapshots__/build-version-get-test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`BuildVersionGetView reading version when appVersionSource is set to local 1`] = `"This project is not configured for using remote version source. Add [1m{"cli": { "appVersionSource": "remote" }}[22m in eas.json or re-run this command without "--non-interactive" flag."`; |
161 changes: 161 additions & 0 deletions
161
packages/eas-cli/src/__tests__/commands/build-version-get-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import { AppVersionSource, EasJson } from '@expo/eas-json'; | ||
import chalk from 'chalk'; | ||
|
||
import BuildVersionGetView from '../../commands/build/version/get'; | ||
import { AppVersionQuery } from '../../graphql/queries/AppVersionQuery'; | ||
import Log from '../../log'; | ||
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json'; | ||
import { getMockEasJson, mockCommandContext, mockProjectId, mockTestCommand } from './utils'; | ||
|
||
jest.mock('../../project/applicationIdentifier'); | ||
jest.mock('fs'); | ||
jest.mock('../../log'); | ||
jest.mock('../../utils/json'); | ||
jest.mock('../../graphql/queries/AppVersionQuery'); | ||
|
||
function withRemoteVersionSource(easJson: EasJson): EasJson { | ||
return { | ||
...easJson, | ||
cli: { | ||
...easJson.cli, | ||
appVersionSource: AppVersionSource.REMOTE, | ||
}, | ||
}; | ||
} | ||
|
||
describe(BuildVersionGetView, () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
test('reading version for platform android', async () => { | ||
const ctx = mockCommandContext(BuildVersionGetView, { | ||
easJson: withRemoteVersionSource(getMockEasJson()), | ||
}); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => ({ | ||
buildVersion: '100', | ||
storeVersion: '1.0.0', | ||
})); | ||
|
||
const cmd = mockTestCommand(BuildVersionGetView, ['--platform=android'], ctx); | ||
await cmd.run(); | ||
expect(AppVersionQuery.latestVersionAsync).toHaveBeenCalledWith( | ||
ctx.loggedIn.graphqlClient, | ||
mockProjectId, | ||
'ANDROID', | ||
'eas.test.com' | ||
); | ||
expect(Log.log).toHaveBeenCalledWith(`Android versionCode - ${chalk.bold('100')}`); | ||
expect(enableJsonOutput).not.toHaveBeenCalled(); | ||
expect(printJsonOnlyOutput).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('reading version for platform android when no remote version is set', async () => { | ||
const ctx = mockCommandContext(BuildVersionGetView, { | ||
easJson: withRemoteVersionSource(getMockEasJson()), | ||
}); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null); | ||
|
||
const cmd = mockTestCommand(BuildVersionGetView, ['--platform=android'], ctx); | ||
await cmd.run(); | ||
expect(AppVersionQuery.latestVersionAsync).toHaveBeenCalledWith( | ||
ctx.loggedIn.graphqlClient, | ||
mockProjectId, | ||
'ANDROID', | ||
'eas.test.com' | ||
); | ||
expect(Log.log).toHaveBeenCalledWith(`No remote versions are configured for this project.`); | ||
expect(enableJsonOutput).not.toHaveBeenCalled(); | ||
expect(printJsonOnlyOutput).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('reading version with --json flag for platform android', async () => { | ||
const ctx = mockCommandContext(BuildVersionGetView, { | ||
easJson: withRemoteVersionSource(getMockEasJson()), | ||
}); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => ({ | ||
buildVersion: '100', | ||
storeVersion: '1.0.0', | ||
})); | ||
|
||
const cmd = mockTestCommand( | ||
BuildVersionGetView, | ||
['--non-interactive', '--json', '--platform=android'], | ||
ctx | ||
); | ||
await cmd.run(); | ||
expect(AppVersionQuery.latestVersionAsync).toHaveBeenCalledWith( | ||
ctx.loggedIn.graphqlClient, | ||
mockProjectId, | ||
'ANDROID', | ||
'eas.test.com' | ||
); | ||
expect(enableJsonOutput).toHaveBeenCalled(); | ||
expect(printJsonOnlyOutput).toHaveBeenCalledWith({ | ||
versionCode: '100', | ||
}); | ||
}); | ||
|
||
test('reading version with --json flag for platform ios', async () => { | ||
const ctx = mockCommandContext(BuildVersionGetView, { | ||
easJson: withRemoteVersionSource(getMockEasJson()), | ||
}); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => ({ | ||
buildVersion: '100', | ||
storeVersion: '1.0.0', | ||
})); | ||
|
||
const cmd = mockTestCommand( | ||
BuildVersionGetView, | ||
['--non-interactive', '--json', '--platform=ios'], | ||
ctx | ||
); | ||
await cmd.run(); | ||
expect(AppVersionQuery.latestVersionAsync).toHaveBeenCalledWith( | ||
ctx.loggedIn.graphqlClient, | ||
mockProjectId, | ||
'IOS', | ||
'eas.test.com' | ||
); | ||
expect(enableJsonOutput).toHaveBeenCalled(); | ||
expect(printJsonOnlyOutput).toHaveBeenCalledWith({ | ||
buildNumber: '100', | ||
}); | ||
}); | ||
|
||
test('reading version with --json flag when no remote version is set', async () => { | ||
const ctx = mockCommandContext(BuildVersionGetView, { | ||
easJson: withRemoteVersionSource(getMockEasJson()), | ||
}); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null); | ||
|
||
const cmd = mockTestCommand( | ||
BuildVersionGetView, | ||
['--non-interactive', '--json', '--platform=android'], | ||
ctx | ||
); | ||
await cmd.run(); | ||
expect(AppVersionQuery.latestVersionAsync).toHaveBeenCalledWith( | ||
ctx.loggedIn.graphqlClient, | ||
mockProjectId, | ||
'ANDROID', | ||
'eas.test.com' | ||
); | ||
expect(enableJsonOutput).toHaveBeenCalled(); | ||
expect(printJsonOnlyOutput).toHaveBeenCalledWith({}); | ||
}); | ||
|
||
test('reading version when appVersionSource is set to local ', async () => { | ||
const ctx = mockCommandContext(BuildVersionGetView, {}); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => ({ | ||
buildVersion: '100', | ||
storeVersion: '1.0.0', | ||
})); | ||
|
||
const cmd = mockTestCommand( | ||
BuildVersionGetView, | ||
['--non-interactive', '--json', '--platform=android'], | ||
ctx | ||
); | ||
await expect(cmd.run()).rejects.toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); |
140 changes: 140 additions & 0 deletions
140
packages/eas-cli/src/__tests__/commands/build-version-set-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { AppVersionSource, EasJson } from '@expo/eas-json'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
|
||
import BuildVersionSetView from '../../commands/build/version/set'; | ||
import { AppVersionMutation } from '../../graphql/mutations/AppVersionMutation'; | ||
import { AppQuery } from '../../graphql/queries/AppQuery'; | ||
import { AppVersionQuery } from '../../graphql/queries/AppVersionQuery'; | ||
import Log from '../../log'; | ||
import * as prompts from '../../prompts'; | ||
import { | ||
getMockAppFragment, | ||
getMockEasJson, | ||
mockCommandContext, | ||
mockProjectId, | ||
mockTestCommand, | ||
} from './utils'; | ||
|
||
jest.mock('../../project/applicationIdentifier'); | ||
jest.mock('../../graphql/queries/AppVersionQuery'); | ||
jest.mock('../../graphql/queries/AppQuery'); | ||
jest.mock('../../graphql/mutations/AppVersionMutation'); | ||
jest.mock('fs'); | ||
jest.mock('../../log'); | ||
jest.mock('../../prompts'); | ||
jest.mock('../../utils/json'); | ||
|
||
function withRemoteVersionSource(easJson: EasJson): EasJson { | ||
return { | ||
...easJson, | ||
cli: { | ||
...easJson.cli, | ||
appVersionSource: AppVersionSource.REMOTE, | ||
}, | ||
}; | ||
} | ||
|
||
describe(BuildVersionSetView, () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('setting version for platform android', async () => { | ||
const ctx = mockCommandContext(BuildVersionSetView, { | ||
easJson: withRemoteVersionSource(getMockEasJson()), | ||
}); | ||
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment()); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null); | ||
jest.mocked(prompts.promptAsync).mockImplementation(async () => ({ | ||
version: '1000', | ||
})); | ||
|
||
const cmd = mockTestCommand(BuildVersionSetView, ['--platform=android'], ctx); | ||
await cmd.run(); | ||
expect(AppVersionQuery.latestVersionAsync).toHaveBeenCalledWith( | ||
ctx.loggedIn.graphqlClient, | ||
mockProjectId, | ||
'ANDROID', | ||
'eas.test.com' | ||
); | ||
expect(AppVersionMutation.createAppVersionAsync).toHaveBeenCalledWith( | ||
ctx.loggedIn.graphqlClient, | ||
expect.objectContaining({ | ||
buildVersion: '1000', | ||
storeVersion: '1.0.0', | ||
}) | ||
); | ||
}); | ||
|
||
test('printing current remote version before prompting for a new one', async () => { | ||
const ctx = mockCommandContext(BuildVersionSetView, { | ||
easJson: withRemoteVersionSource(getMockEasJson()), | ||
}); | ||
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment()); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => ({ | ||
buildVersion: '100', | ||
storeVersion: '1.0.0', | ||
})); | ||
jest.mocked(prompts.promptAsync).mockImplementation(async () => ({ | ||
version: '1000', | ||
})); | ||
|
||
const cmd = mockTestCommand(BuildVersionSetView, ['--platform=android'], ctx); | ||
await cmd.run(); | ||
expect(Log.log).toHaveBeenCalledWith(expect.stringMatching('configured with versionCode 100')); | ||
expect(AppVersionQuery.latestVersionAsync).toHaveBeenCalledWith( | ||
ctx.loggedIn.graphqlClient, | ||
mockProjectId, | ||
'ANDROID', | ||
'eas.test.com' | ||
); | ||
}); | ||
|
||
test('printing info that there is no remote version configured', async () => { | ||
const ctx = mockCommandContext(BuildVersionSetView, { | ||
easJson: withRemoteVersionSource(getMockEasJson()), | ||
}); | ||
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment()); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null); | ||
jest.mocked(prompts.promptAsync).mockImplementation(async () => ({ | ||
version: '1000', | ||
})); | ||
|
||
const cmd = mockTestCommand(BuildVersionSetView, ['--platform=android'], ctx); | ||
await cmd.run(); | ||
expect(Log.log).toHaveBeenCalledWith( | ||
expect.stringMatching('does not have any versionCode configured') | ||
); | ||
expect(AppVersionQuery.latestVersionAsync).toHaveBeenCalledWith( | ||
ctx.loggedIn.graphqlClient, | ||
mockProjectId, | ||
'ANDROID', | ||
'eas.test.com' | ||
); | ||
}); | ||
|
||
test('setting version aborts when appVersionSource is set to local and users refuse auto configuration', async () => { | ||
const ctx = mockCommandContext(BuildVersionSetView, {}); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null); | ||
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment()); | ||
jest.mocked(prompts.confirmAsync).mockImplementation(async () => false); | ||
|
||
const cmd = mockTestCommand(BuildVersionSetView, ['--platform=android'], ctx); | ||
await expect(cmd.run()).rejects.toThrowError('Aborting...'); | ||
expect(AppVersionMutation.createAppVersionAsync).not.toHaveBeenCalledWith(); | ||
}); | ||
|
||
test('setting version when appVersionSource is set to local and user allows auto configuration', async () => { | ||
const ctx = mockCommandContext(BuildVersionSetView, {}); | ||
jest.mocked(AppVersionQuery.latestVersionAsync).mockImplementation(async () => null); | ||
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment()); | ||
jest.mocked(prompts.confirmAsync).mockImplementation(async () => true); | ||
|
||
const cmd = mockTestCommand(BuildVersionSetView, ['--platform=android'], ctx); | ||
await cmd.run(); | ||
|
||
const easJsonAfterCmd = await fs.readJson(path.join(ctx.projectDir, 'eas.json')); | ||
expect(easJsonAfterCmd.cli.appVersionSource).toBe('remote'); | ||
}); | ||
}); |
Oops, something went wrong.