-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#153] Add hooks utils to contain postProcess
- Loading branch information
Showing
9 changed files
with
101 additions
and
74 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
nodejs 18.12.1 | ||
terraform 1.3.9 |
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
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
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
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
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
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
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,55 @@ | ||
import { remove } from '@/helpers/file'; | ||
import { formatCode, detectTerraform } from '@/helpers/terraform'; | ||
|
||
import { postProcess } from './hooks'; | ||
|
||
jest.mock('@/helpers/terraform'); | ||
|
||
describe('postProcess', () => { | ||
const projectDir = 'postProcess-test'; | ||
const generalOptions = { projectName: projectDir, provider: 'aws' }; | ||
|
||
describe('given current machine had terraform', () => { | ||
beforeAll(async () => { | ||
(detectTerraform as jest.Mock).mockImplementation(() => true); | ||
|
||
await postProcess(generalOptions); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
remove('/', projectDir); | ||
}); | ||
|
||
it('runs formatCode', async () => { | ||
await expect(formatCode).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('given current machine did not have terraform', () => { | ||
const consoleErrorSpy = jest.spyOn(global.console, 'error'); | ||
|
||
beforeAll(async () => { | ||
(detectTerraform as jest.Mock).mockImplementation(() => { | ||
throw new Error('terraform not found'); | ||
}); | ||
|
||
await postProcess(generalOptions); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
remove('/', projectDir); | ||
}); | ||
|
||
it('does NOT run formatCode', async () => { | ||
await expect(formatCode).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('displays the error message', () => { | ||
expect(consoleErrorSpy).toHaveBeenCalledWith( | ||
Error('terraform not found') | ||
); | ||
}); | ||
}); | ||
}); |
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,16 @@ | ||
import { GeneralOptions } from '@/commands/generate'; | ||
import { getProjectPath } from '@/helpers/file'; | ||
import { detectTerraform, formatCode } from '@/helpers/terraform'; | ||
|
||
const postProcess = async (generalOptions: GeneralOptions) => { | ||
try { | ||
if (await detectTerraform()) { | ||
await formatCode(getProjectPath(generalOptions.projectName)); | ||
console.log('formatCode'); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
export { postProcess }; |