Skip to content

Commit e805108

Browse files
committed
feat: add test
Signed-off-by: Raí Siqueira <rai93siqueira@gmail.com>
1 parent acdb130 commit e805108

File tree

4 files changed

+132
-6
lines changed

4 files changed

+132
-6
lines changed

lib/__tests__/index.test.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
1-
import { describe, it } from 'vitest';
1+
import { render } from 'cli-testing-library';
2+
import { resolve } from 'path';
3+
import { describe, it, expect } from 'vitest';
24

3-
describe('lib', () => {
4-
it.todo('should render lib');
5+
import { CLIUserEvents } from '../src/testUtils';
6+
7+
describe('eruption-cli', () => {
8+
const cliPath = resolve(__dirname, '../eruption-cli.mjs');
9+
it('should render the cli prompts (without CLI flags)', async () => {
10+
const { findByText, userEvent } = await render('node', [cliPath]);
11+
const projectName = await findByText(/What is the name of your project/i);
12+
13+
expect(projectName).toBeTruthy();
14+
15+
// Simulate the project name being entered and the enter key being pressed.
16+
userEvent.keyboard(`my-project${CLIUserEvents.Enter}`);
17+
expect(await findByText(/my-project/i)).toBeTruthy();
18+
19+
const kit = await findByText(/Select your Eruption kit/i);
20+
expect(kit).toBeTruthy();
21+
22+
// Simulate the user pressing the down arrow key and then the enter key. (For now, we are selecting the core kit)
23+
userEvent.keyboard(`${CLIUserEvents.ArrowDown}${CLIUserEvents.Enter}`);
24+
expect(await findByText(/core/i)).toBeTruthy();
25+
26+
// Simulate the user pressing the down arrow key and then the enter key. (For now, we are selecting the core kit)
27+
const confirm = await findByText(/Do you want to continue/i);
28+
expect(confirm).toBeTruthy();
29+
30+
userEvent.keyboard(`${CLIUserEvents.ArrowDown}${CLIUserEvents.Enter}`);
31+
32+
expect(await findByText(/starting the project/i)).toBeTruthy();
33+
expect(await findByText(/Done/i)).toBeTruthy();
34+
});
535
});

lib/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-eruption",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "The Eruption CLI 🌋",
55
"license": "MIT",
66
"author": "Raí Siqueira <me@raisiqueira.io>",
@@ -43,12 +43,13 @@
4343
"@clack/prompts": "^0.5.0",
4444
"@tsconfig/node16": "^1.0.3",
4545
"@types/yargs-parser": "^21.0.0",
46-
"@vitest/coverage-c8": "^0.24.5"
46+
"@vitest/coverage-c8": "^0.24.5",
47+
"cli-testing-library": "^2.0.1"
4748
},
4849
"dependencies": {
4950
"kleur": "^4.1.5",
5051
"node-fetch": "^3.3.0",
5152
"tiged": "^2.12.3",
5253
"yargs-parser": "^21.1.1"
5354
}
54-
}
55+
}

lib/src/testUtils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const CLIUserEvents = {
2+
Enter: '[Enter]',
3+
Space: '[Space]',
4+
ESC: '[Escape]',
5+
Backspace: '[Backspace]',
6+
Delete: '[Delete]',
7+
ArrowLeft: '[ArrowLeft]',
8+
ArrowRight: '[ArrowRight]',
9+
ArrowUp: '[ArrowUp]',
10+
ArrowDown: '[ArrowDown]',
11+
Home: '[Home]',
12+
End: '[End]',
13+
};

pnpm-lock.yaml

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)