Skip to content

Commit

Permalink
[#29] Update eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangmirs committed Jul 26, 2022
1 parent d83a963 commit b0c23e2
Show file tree
Hide file tree
Showing 29 changed files with 491 additions and 139 deletions.
127 changes: 118 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"inquirer": "^8.2.4"
},
"devDependencies": {
"@nimblehq/eslint-config-nimble": "^2.3.0",
"@nimblehq/eslint-config-nimble": "^2.4.0",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/inquirer": "^8.2.1",
Expand Down
46 changes: 29 additions & 17 deletions src/commands/generate/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Generator command', () => {
const projectDir = 'aws-basic-test';
const consoleErrorSpy = jest.spyOn(global.console, 'error');

beforeAll(async() => {
beforeAll(async () => {
(prompt as unknown as jest.Mock)
.mockResolvedValueOnce({ provider: 'aws' })
.mockResolvedValueOnce({ infrastructureType: 'basic' });
Expand All @@ -29,15 +29,17 @@ describe('Generator command', () => {
});

it('displays the error message', () => {
expect(consoleErrorSpy).toHaveBeenCalledWith(Error('This type has not been implemented!'));
expect(consoleErrorSpy).toHaveBeenCalledWith(
Error('This type has not been implemented!')
);
});
});

describe('given infrastructure type is advanced', () => {
const projectDir = 'aws-advanced-test';
const stdoutSpy = jest.spyOn(process.stdout, 'write');

beforeAll(async() => {
beforeAll(async () => {
(prompt as unknown as jest.Mock)
.mockResolvedValueOnce({ provider: 'aws' })
.mockResolvedValueOnce({ infrastructureType: 'advanced' });
Expand All @@ -55,7 +57,9 @@ describe('Generator command', () => {
});

it('displays the success message', () => {
expect(stdoutSpy).toHaveBeenCalledWith('The infrastructure has been generated!\n');
expect(stdoutSpy).toHaveBeenCalledWith(
'The infrastructure has been generated!\n'
);
});
});
});
Expand All @@ -64,9 +68,10 @@ describe('Generator command', () => {
const projectDir = 'gcp-test';
const consoleErrorSpy = jest.spyOn(global.console, 'error');

beforeAll(async() => {
(prompt as unknown as jest.Mock)
.mockResolvedValueOnce({ provider: 'gcp' });
beforeAll(async () => {
(prompt as unknown as jest.Mock).mockResolvedValueOnce({
provider: 'gcp',
});

await Generator.run([projectDir]);
});
Expand All @@ -77,17 +82,20 @@ describe('Generator command', () => {
});

it('displays the error message', () => {
expect(consoleErrorSpy).toHaveBeenCalledWith(Error('This provider has not been implemented!'));
expect(consoleErrorSpy).toHaveBeenCalledWith(
Error('This provider has not been implemented!')
);
});
});

describe('given provider is Heroku', () => {
const projectDir = 'heroku-test';
const consoleErrorSpy = jest.spyOn(global.console, 'error');

beforeAll(async() => {
(prompt as unknown as jest.Mock)
.mockResolvedValueOnce({ provider: 'heroku' });
beforeAll(async () => {
(prompt as unknown as jest.Mock).mockResolvedValueOnce({
provider: 'heroku',
});

await Generator.run([projectDir]);
});
Expand All @@ -98,15 +106,17 @@ describe('Generator command', () => {
});

it('displays the error message', () => {
expect(consoleErrorSpy).toHaveBeenCalledWith(Error('This provider has not been implemented!'));
expect(consoleErrorSpy).toHaveBeenCalledWith(
Error('This provider has not been implemented!')
);
});
});

describe('postProcess', () => {
const projectDir = 'postProcess-test';

describe('given current machine had terraform', () => {
beforeAll(async() => {
beforeAll(async () => {
(prompt as unknown as jest.Mock)
.mockResolvedValueOnce({ provider: 'aws' })
.mockResolvedValueOnce({ infrastructureType: 'advanced' });
Expand All @@ -121,15 +131,15 @@ describe('Generator command', () => {
remove('/', projectDir);
});

it('runs formatCode', async() => {
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() => {
beforeAll(async () => {
(prompt as unknown as jest.Mock)
.mockResolvedValueOnce({ provider: 'aws' })
.mockResolvedValueOnce({ infrastructureType: 'advanced' });
Expand All @@ -146,12 +156,14 @@ describe('Generator command', () => {
remove('/', projectDir);
});

it('does NOT run formatCode', async() => {
it('does NOT run formatCode', async () => {
await expect(formatCode).not.toHaveBeenCalled();
});

it('displays the error message', () => {
expect(consoleErrorSpy).toHaveBeenCalledWith(Error('terraform not found'));
expect(consoleErrorSpy).toHaveBeenCalledWith(
Error('terraform not found')
);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/childProcess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { runCommand } from './childProcess';
describe('ChildProcess helper', () => {
describe('runCommand', () => {
describe('given a valid command', () => {
it('runs the command', async() => {
it('runs the command', async () => {
const result = await runCommand('echo', ['hello']);

expect(result).toBe('hello');
});
});

describe('given an INVALID command', () => {
it('throws an error', async() => {
it('throws an error', async () => {
let result: string;
const invalidCommand = 'invalid-command';

Expand Down
6 changes: 2 additions & 4 deletions src/helpers/childProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { spawn } from 'node:child_process';
const runCommand = (
command: string,
args: string[],
cwd = './',
cwd = './'
): Promise<string> => {
return new Promise((resolve, reject) => {
const child = spawn(command, args, { cwd });
Expand All @@ -15,6 +15,4 @@ const runCommand = (
});
};

export {
runCommand,
};
export { runCommand };
Loading

0 comments on commit b0c23e2

Please sign in to comment.