Skip to content

Commit

Permalink
updated aio app install tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron committed May 11, 2023
1 parent 2ae6939 commit eeec410
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/commands/app/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ class InstallCommand extends BaseCommand {
await this.unzipFile(args.path, outputPath)
await this.validateConfig(outputPath, USER_CONFIG_FILE)
await this.validateConfig(outputPath, DEPLOY_CONFIG_FILE)
await this.runTests(flags.verbose)
await this.npmInstall(flags.verbose)
await this.runTests()
this.spinner.succeed('Install done.')
} catch (e) {
this.spinner.fail(e.message)
this.error(e.message)
this.error(flags.verbose ? e : e.message)
}
}

Expand Down Expand Up @@ -128,7 +129,6 @@ class InstallCommand extends BaseCommand {
}

async runTests (isVerbose) {
await this.npmInstall(isVerbose)
this.spinner.start('Running app tests...')
return this.config.runCommand('app:test').then((result) => {
if (result === 0) { // success
Expand Down
50 changes: 45 additions & 5 deletions test/commands/app/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,46 @@ describe('run', () => {
command.unzipFile = jest.fn()
command.validateConfig = jest.fn()
command.runTests = jest.fn()
command.npmInstall = jest.fn()
command.error = jest.fn()
await command.run()

expect(command.validateZipDirectoryStructure).toHaveBeenCalledTimes(1)
expect(command.unzipFile).toHaveBeenCalledTimes(1)
expect(command.validateConfig).toHaveBeenCalledTimes(2)
expect(command.runTests).toHaveBeenCalledTimes(1)
expect(command.npmInstall).toHaveBeenCalledTimes(1)
expect(command.error).toHaveBeenCalledTimes(0)
})

test('subcommand throws error', async () => {
test('subcommand throws error (--verbose)', async () => {
const command = new TheCommand()
command.argv = ['my-app.zip', '--verbose']

const errorObject = new Error('this is a subcommand error message')

// since we already unit test the methods above, we mock it here
// we only reject one call, to simulate a subcommand failure
command.validateZipDirectoryStructure = jest.fn()
command.unzipFile = jest.fn()
command.validateConfig = jest.fn()
command.npmInstall = jest.fn()
command.error = jest.fn()
command.runTests = jest.fn(() => { throw errorObject })

await command.run()

expect(command.validateZipDirectoryStructure).toHaveBeenCalledTimes(1)
expect(command.unzipFile).toHaveBeenCalledTimes(1)
expect(command.validateConfig).toHaveBeenCalledTimes(2)
expect(command.runTests).toHaveBeenCalledTimes(1)
expect(command.npmInstall).toHaveBeenCalledTimes(1)
expect(command.error).toHaveBeenCalledTimes(1)

expect(command.error).toHaveBeenCalledWith(errorObject)
})

test('subcommand throws error (not verbose)', async () => {
const command = new TheCommand()
command.argv = ['my-app.zip']

Expand All @@ -306,16 +337,20 @@ describe('run', () => {
command.validateZipDirectoryStructure = jest.fn()
command.unzipFile = jest.fn()
command.validateConfig = jest.fn()
command.runTests = jest.fn(() => {
throw new Error(errorMessage)
})
command.npmInstall = jest.fn()
command.error = jest.fn()
command.runTests = jest.fn(() => { throw new Error(errorMessage) })

await expect(command.run()).rejects.toThrow(errorMessage)
await command.run()

expect(command.validateZipDirectoryStructure).toHaveBeenCalledTimes(1)
expect(command.unzipFile).toHaveBeenCalledTimes(1)
expect(command.validateConfig).toHaveBeenCalledTimes(2)
expect(command.runTests).toHaveBeenCalledTimes(1)
expect(command.npmInstall).toHaveBeenCalledTimes(1)
expect(command.error).toHaveBeenCalledTimes(1)

expect(command.error).toHaveBeenCalledWith(errorMessage)
})

test('flag --output', async () => {
Expand All @@ -327,12 +362,17 @@ describe('run', () => {
command.unzipFile = jest.fn()
command.validateConfig = jest.fn()
command.runTests = jest.fn()
command.npmInstall = jest.fn()
command.error = jest.fn()

await command.run()

expect(command.validateZipDirectoryStructure).toHaveBeenCalledTimes(1)
expect(command.unzipFile).toHaveBeenCalledTimes(1)
expect(command.validateConfig).toHaveBeenCalledTimes(2)
expect(command.runTests).toHaveBeenCalledTimes(1)
expect(command.npmInstall).toHaveBeenCalledTimes(1)
expect(command.error).toHaveBeenCalledTimes(0)
expect(fakeCwd).toEqual(path.resolve('my-dest-folder'))
})
})

0 comments on commit eeec410

Please sign in to comment.