-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
45451d3
commit ae7a49d
Showing
11 changed files
with
184 additions
and
5 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
test/snapshots/index.js.md → __e2e__/__snapshots__/__e2e__/cli.test.js.md
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
Binary file not shown.
48 changes: 48 additions & 0 deletions
48
__e2e__/__snapshots__/__e2e__/commands/showcommands.test.js.md
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,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 | ||
`[2J[0;0f[1m[31m _ _ _ ␊ | ||
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ | ||
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ | ||
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ | ||
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ | ||
[22m[39m␊ | ||
[1m[33m Learn to code effectively Powered by MadHacks[22m[39m␊ | ||
␊ | ||
␊ | ||
User: validConfigJson Progress: 1/30␊ | ||
␊ | ||
[90m┌───────────────────────────[39m[90m┬───────────────────────────────────────┐[39m␊ | ||
[90m│[39m teachcode init [90m│[39m Initialize all the tasks [90m│[39m␊ | ||
[90m├───────────────────────────[39m[90m┼───────────────────────────────────────┤[39m␊ | ||
[90m│[39m teachcode fetchtask <key> [90m│[39m Fetch new task providing the key [90m│[39m␊ | ||
[90m├───────────────────────────[39m[90m┼───────────────────────────────────────┤[39m␊ | ||
[90m│[39m teachcode submit [90m│[39m Submits the current file [90m│[39m␊ | ||
[90m├───────────────────────────[39m[90m┼───────────────────────────────────────┤[39m␊ | ||
[90m│[39m teachcode showkeys [90m│[39m View any tasks by grabbing their keys [90m│[39m␊ | ||
[90m├───────────────────────────[39m[90m┼───────────────────────────────────────┤[39m␊ | ||
[90m│[39m teachcode showcommands [90m│[39m Lists all the commands [90m│[39m␊ | ||
[90m└───────────────────────────[39m[90m┴───────────────────────────────────────┘[39m` | ||
|
||
## no config file for showcommands | ||
|
||
> Snapshot 1 | ||
`[2J[0;0f[1m[31m _ _ _ ␊ | ||
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ | ||
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ | ||
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ | ||
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ | ||
[22m[39m␊ | ||
[1m[33m Learn to code effectively Powered by MadHacks[22m[39m␊ | ||
␊ | ||
Config file doesn't exist!␊ | ||
␊ | ||
` |
Binary file not shown.
58 changes: 58 additions & 0 deletions
58
__e2e__/__snapshots__/__e2e__/commands/showkeys.test.js.md
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,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 | ||
`[2J[0;0f[1m[31m _ _ _ ␊ | ||
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ | ||
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ | ||
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ | ||
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ | ||
[22m[39m␊ | ||
[1m[33m Learn to code effectively Powered by MadHacks[22m[39m␊ | ||
␊ | ||
␊ | ||
User: configWithMultipleKeys Progress: 3/30␊ | ||
␊ | ||
Task-1: testkey1␊ | ||
␊ | ||
Task-2: testkey2` | ||
|
||
## no config file | ||
|
||
> Snapshot 1 | ||
`[2J[0;0f[1m[31m _ _ _ ␊ | ||
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ | ||
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ | ||
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ | ||
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ | ||
[22m[39m␊ | ||
[1m[33m Learn to code effectively Powered by MadHacks[22m[39m␊ | ||
␊ | ||
Config file doesn't exist!␊ | ||
␊ | ||
` | ||
|
||
## no keys in config file | ||
|
||
> Snapshot 1 | ||
`[2J[0;0f[1m[31m _ _ _ ␊ | ||
| |_ ___ __ _ ___| |__ ___ ___ __| | ___ ␊ | ||
| __/ _ \\/ _` |/ __| '_ \\ / __/ _ \\ / _` |/ _ \\␊ | ||
| || __/ (_| | (__| | | | (_| (_) | (_| | __/␊ | ||
\\__\\___|\\__,_|\\___|_| |_|\\___\\___/ \\__,_|\\___|␊ | ||
[22m[39m␊ | ||
[1m[33m Learn to code effectively Powered by MadHacks[22m[39m␊ | ||
␊ | ||
␊ | ||
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.
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,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); | ||
}); |
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,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); | ||
}); |
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
Binary file not shown.