Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: e2e test cases for showkeys and `showcommands' #63

Merged
merged 12 commits into from
Dec 28, 2019
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Snapshot report for `test/index.js`
# Snapshot report for `__e2e__/cli.test.js`

The actual snapshot is saved in `index.js.snap`.
The actual snapshot is saved in `cli.test.js.snap`.

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

Expand Down
Binary file added __e2e__/__snapshots__/__e2e__/cli.test.js.snap
Binary file not shown.
48 changes: 48 additions & 0 deletions __e2e__/__snapshots__/__e2e__/commands/showcommands.test.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Snapshot report for `__e2e__/commands/showcommands.test.js`

The actual snapshot is saved in `showcommands.test.js.snap`.

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

## config file present for showcommands

> Snapshot 1

` _ _ _ ␊
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
␊
 Learn to code effectively Powered by MadHacks␊
User: validConfigJson Progress: 1/30␊
┌───────────────────────────┬───────────────────────────────────────┐␊
│ teachcode init │ Initialize all the tasks │␊
├───────────────────────────┼───────────────────────────────────────┤␊
│ teachcode fetchtask <key> │ Fetch new task providing the key │␊
├───────────────────────────┼───────────────────────────────────────┤␊
│ teachcode submit │ Submits the current file │␊
├───────────────────────────┼───────────────────────────────────────┤␊
│ teachcode showkeys │ View any tasks by grabbing their keys │␊
├───────────────────────────┼───────────────────────────────────────┤␊
│ teachcode showcommands │ Lists all the commands │␊
└───────────────────────────┴───────────────────────────────────────┘`

## no config file for showcommands

> Snapshot 1

` _ _ _ ␊
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
␊
 Learn to code effectively Powered by MadHacks␊
Config file doesn't exist!␊
`
Binary file not shown.
58 changes: 58 additions & 0 deletions __e2e__/__snapshots__/__e2e__/commands/showkeys.test.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Snapshot report for `__e2e__/commands/showkeys.test.js`

The actual snapshot is saved in `showkeys.test.js.snap`.

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

## multiple keys in config file

> Snapshot 1

` _ _ _ ␊
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
␊
 Learn to code effectively Powered by MadHacks␊
User: configWithMultipleKeys Progress: 3/30␊
Task-1: testkey1␊
Task-2: testkey2`

## no config file

> Snapshot 1

` _ _ _ ␊
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
␊
 Learn to code effectively Powered by MadHacks␊
Config file doesn't exist!␊
`

## no keys in config file

> Snapshot 1

` _ _ _ ␊
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊
␊
 Learn to code effectively Powered by MadHacks␊
User: configWithoutKeys Progress: 1/30␊
Looks like this is your very first task. Fire in teachcode fetchtask to start out!␊
`
Binary file not shown.
File renamed without changes.
29 changes: 29 additions & 0 deletions __e2e__/commands/showcommands.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const path = require('path');
const execa = require('execa');
const test = require('ava');
const fs = require('fs');

const rootCommand = path.join(process.cwd(), 'bin/index.js');
const configFilePath = path.join(process.cwd(), 'config.json');

const validConfigJson = {
userName: 'validConfigJson',
taskCount: 0,
};

test.serial('no config file for showcommands', async t => {
if (fs.existsSync(configFilePath)) fs.unlinkSync(configFilePath);
const { stdout } = await execa(rootCommand, ['showcommands'], {
reject: false,
});
t.snapshot(stdout);
});

test.serial('config file present for showcommands', async t => {
fs.writeFileSync('config.json', JSON.stringify(validConfigJson));
const { stdout } = await execa(rootCommand, ['showcommands']);
t.snapshot(stdout);
fs.unlinkSync(configFilePath);
});
41 changes: 41 additions & 0 deletions __e2e__/commands/showkeys.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const path = require('path');
const execa = require('execa');
const test = require('ava');
const fs = require('fs');

const rootCommand = path.join(process.cwd(), 'bin/index.js');
const configFilePath = path.join(process.cwd(), 'config.json');

const configWithoutKeys = {
userName: 'configWithoutKeys',
taskCount: 0,
keys: [],
};
const configWithMultipleKeys = {
userName: 'configWithMultipleKeys',
taskCount: 2,
keys: ['testkey1', 'testkey2'],
};

// tests are serial as we are creating different temp config files for each tests
test.serial('no config file', async t => {
if (fs.existsSync(configFilePath)) fs.unlinkSync(configFilePath);
const { stdout } = await execa(rootCommand, ['showkeys'], { reject: false });
t.snapshot(stdout);
});

test.serial('no keys in config file', async t => {
fs.writeFileSync('config.json', JSON.stringify(configWithoutKeys));
const { stdout } = await execa(rootCommand, ['showkeys']);
t.snapshot(stdout);
fs.unlinkSync(configFilePath);
});

test.serial('multiple keys in config file', async t => {
fs.writeFileSync('config.json', JSON.stringify(configWithMultipleKeys));
const { stdout } = await execa(rootCommand, ['showkeys']);
t.snapshot(stdout);
fs.unlinkSync(configFilePath);
});
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
"teachcode": "./bin/index.js"
},
"scripts": {
"lint": "eslint src bin test",
"lint:fix": "eslint --fix src bin test",
"lint": "eslint src bin __e2e__",
"lint:fix": "eslint --fix src bin __e2e__",
"pretest": "npm run lint",
"test": "ava test/index.js",
"test": "ava --serial",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs"
},
"ava": {
"snapshotDir": "__e2e__/__snapshots__"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
Expand Down
Binary file removed test/snapshots/index.js.snap
Binary file not shown.