0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00

refactor(cli): exit normally when no alteration found

This commit is contained in:
Gao Sun 2022-10-12 23:26:38 +08:00
parent 5eb822fee5
commit babd16f68f
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
2 changed files with 11 additions and 13 deletions

View file

@ -13,10 +13,6 @@ const pool = createMockPool({
},
});
const mockExit = jest.fn((code?: number) => {
throw new Error(String(code));
});
describe('getUndeployedAlterations()', () => {
const files = Object.freeze([
{ filename: '1.0.0-1663923770-a.js', path: '/alterations/1.0.0-1663923770-a.js' },
@ -63,14 +59,16 @@ describe('chooseAlterationsByVersion()', () => {
].map((filename) => ({ filename, path: '/alterations/' + filename }))
);
it('exits with code 1 when no alteration file available', async () => {
jest.spyOn(process, 'exit').mockImplementation(mockExit);
await expect(chooseAlterationsByVersion([], 'v1.0.0')).rejects.toThrow('1');
mockExit.mockRestore();
it('chooses nothing when input version is invalid', async () => {
await expect(chooseAlterationsByVersion(files, 'next1')).rejects.toThrow(
'Invalid Version: next1'
);
await expect(chooseAlterationsByVersion([], 'ok')).rejects.toThrow('Invalid Version: ok');
});
it('chooses correct alteration files', async () => {
await Promise.all([
expect(chooseAlterationsByVersion([], 'v1.0.0')).resolves.toEqual([]),
expect(chooseAlterationsByVersion(files, 'v1.0.0')).resolves.toEqual(files.slice(0, 7)),
expect(chooseAlterationsByVersion(files, 'v1.0.0-beta.10')).resolves.toEqual(
files.slice(0, 3)

View file

@ -27,7 +27,7 @@ export const chooseAlterationsByVersion = async (
);
if (endIndex === -1) {
log.error('No alteration script to deploy');
return [];
}
log.info(`Deploy target ${chalk.green(nextTag)}`);
@ -43,10 +43,6 @@ export const chooseAlterationsByVersion = async (
.slice()
.sort((i, j) => compare(j, i));
if (!versions[0]) {
log.error('No alteration script to deploy');
}
const { version: targetVersion } =
initialVersion === latestTag
? { version: versions[0] }
@ -65,6 +61,10 @@ export const chooseAlterationsByVersion = async (
}
);
if (!targetVersion) {
return [];
}
log.info(`Deploy target ${chalk.green(targetVersion.version)}`);
return alterations.filter(({ filename }) => {