Skip to content

Commit ae7a49d

Browse files
chore: e2e test cases for showkeys and `showcommands' (#63)
* feat: e2e tests * fix: fixed prettier issues * chore: minor tweaks * feat: e2e tests for showkeys * refactor: update tests directory structure * test: e2e tests for showcommands * fix: changed variable names Co-Authored-By: James George <[email protected]> * refactor: fix lint errors * refactor: minor change * fix: used fs.unlinkSync to remove files * refactor: changed snapshots directory Co-authored-by: James George <[email protected]>
1 parent 45451d3 commit ae7a49d

File tree

11 files changed

+184
-5
lines changed

11 files changed

+184
-5
lines changed

test/snapshots/index.js.md renamed to __e2e__/__snapshots__/__e2e__/cli.test.js.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Snapshot report for `test/index.js`
1+
# Snapshot report for `__e2e__/cli.test.js`
22

3-
The actual snapshot is saved in `index.js.snap`.
3+
The actual snapshot is saved in `cli.test.js.snap`.
44

55
Generated by [AVA](https://ava.li).
66

573 Bytes
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Snapshot report for `__e2e__/commands/showcommands.test.js`
2+
3+
The actual snapshot is saved in `showcommands.test.js.snap`.
4+
5+
Generated by [AVA](https://ava.li).
6+
7+
## config file present for showcommands
8+
9+
> Snapshot 1
10+
11+
` _ _ _ ␊
12+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
13+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
14+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
15+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
16+
␊
17+
 Learn to code effectively Powered by MadHacks␊
18+
19+
20+
User: validConfigJson Progress: 1/30␊
21+
22+
┌───────────────────────────┬───────────────────────────────────────┐␊
23+
│ teachcode init │ Initialize all the tasks │␊
24+
├───────────────────────────┼───────────────────────────────────────┤␊
25+
│ teachcode fetchtask <key> │ Fetch new task providing the key │␊
26+
├───────────────────────────┼───────────────────────────────────────┤␊
27+
│ teachcode submit │ Submits the current file │␊
28+
├───────────────────────────┼───────────────────────────────────────┤␊
29+
│ teachcode showkeys │ View any tasks by grabbing their keys │␊
30+
├───────────────────────────┼───────────────────────────────────────┤␊
31+
│ teachcode showcommands │ Lists all the commands │␊
32+
└───────────────────────────┴───────────────────────────────────────┘`
33+
34+
## no config file for showcommands
35+
36+
> Snapshot 1
37+
38+
` _ _ _ ␊
39+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
40+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
41+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
42+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
43+
␊
44+
 Learn to code effectively Powered by MadHacks␊
45+
46+
Config file doesn't exist!␊
47+
48+
`
618 Bytes
Binary file not shown.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Snapshot report for `__e2e__/commands/showkeys.test.js`
2+
3+
The actual snapshot is saved in `showkeys.test.js.snap`.
4+
5+
Generated by [AVA](https://ava.li).
6+
7+
## multiple keys in config file
8+
9+
> Snapshot 1
10+
11+
` _ _ _ ␊
12+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
13+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
14+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
15+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
16+
␊
17+
 Learn to code effectively Powered by MadHacks␊
18+
19+
20+
User: configWithMultipleKeys Progress: 3/30␊
21+
22+
Task-1: testkey1␊
23+
24+
Task-2: testkey2`
25+
26+
## no config file
27+
28+
> Snapshot 1
29+
30+
` _ _ _ ␊
31+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
32+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
33+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
34+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
35+
␊
36+
 Learn to code effectively Powered by MadHacks␊
37+
38+
Config file doesn't exist!␊
39+
40+
`
41+
42+
## no keys in config file
43+
44+
> Snapshot 1
45+
46+
` _ _ _ ␊
47+
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
48+
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
49+
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
50+
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
51+
␊
52+
 Learn to code effectively Powered by MadHacks␊
53+
54+
55+
User: configWithoutKeys Progress: 1/30␊
56+
57+
Looks like this is your very first task. Fire in teachcode fetchtask to start out!␊
58+
`
527 Bytes
Binary file not shown.
File renamed without changes.

__e2e__/commands/showcommands.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const execa = require('execa');
5+
const test = require('ava');
6+
const fs = require('fs');
7+
8+
const rootCommand = path.join(process.cwd(), 'bin/index.js');
9+
const configFilePath = path.join(process.cwd(), 'config.json');
10+
11+
const validConfigJson = {
12+
userName: 'validConfigJson',
13+
taskCount: 0,
14+
};
15+
16+
test.serial('no config file for showcommands', async t => {
17+
if (fs.existsSync(configFilePath)) fs.unlinkSync(configFilePath);
18+
const { stdout } = await execa(rootCommand, ['showcommands'], {
19+
reject: false,
20+
});
21+
t.snapshot(stdout);
22+
});
23+
24+
test.serial('config file present for showcommands', async t => {
25+
fs.writeFileSync('config.json', JSON.stringify(validConfigJson));
26+
const { stdout } = await execa(rootCommand, ['showcommands']);
27+
t.snapshot(stdout);
28+
fs.unlinkSync(configFilePath);
29+
});

__e2e__/commands/showkeys.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const execa = require('execa');
5+
const test = require('ava');
6+
const fs = require('fs');
7+
8+
const rootCommand = path.join(process.cwd(), 'bin/index.js');
9+
const configFilePath = path.join(process.cwd(), 'config.json');
10+
11+
const configWithoutKeys = {
12+
userName: 'configWithoutKeys',
13+
taskCount: 0,
14+
keys: [],
15+
};
16+
const configWithMultipleKeys = {
17+
userName: 'configWithMultipleKeys',
18+
taskCount: 2,
19+
keys: ['testkey1', 'testkey2'],
20+
};
21+
22+
// tests are serial as we are creating different temp config files for each tests
23+
test.serial('no config file', async t => {
24+
if (fs.existsSync(configFilePath)) fs.unlinkSync(configFilePath);
25+
const { stdout } = await execa(rootCommand, ['showkeys'], { reject: false });
26+
t.snapshot(stdout);
27+
});
28+
29+
test.serial('no keys in config file', async t => {
30+
fs.writeFileSync('config.json', JSON.stringify(configWithoutKeys));
31+
const { stdout } = await execa(rootCommand, ['showkeys']);
32+
t.snapshot(stdout);
33+
fs.unlinkSync(configFilePath);
34+
});
35+
36+
test.serial('multiple keys in config file', async t => {
37+
fs.writeFileSync('config.json', JSON.stringify(configWithMultipleKeys));
38+
const { stdout } = await execa(rootCommand, ['showkeys']);
39+
t.snapshot(stdout);
40+
fs.unlinkSync(configFilePath);
41+
});

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
"teachcode": "./bin/index.js"
1212
},
1313
"scripts": {
14-
"lint": "eslint src bin test",
15-
"lint:fix": "eslint --fix src bin test",
14+
"lint": "eslint src bin __e2e__",
15+
"lint:fix": "eslint --fix src bin __e2e__",
1616
"pretest": "npm run lint",
17-
"test": "ava test/index.js",
17+
"test": "ava --serial",
1818
"docs:dev": "vuepress dev docs",
1919
"docs:build": "vuepress build docs"
2020
},
21+
"ava": {
22+
"snapshotDir": "__e2e__/__snapshots__"
23+
},
2124
"husky": {
2225
"hooks": {
2326
"pre-commit": "lint-staged",

0 commit comments

Comments
 (0)