diff --git a/test/snapshots/index.js.md b/__e2e__/__snapshots__/__e2e__/cli.test.js.md similarity index 96% rename from test/snapshots/index.js.md rename to __e2e__/__snapshots__/__e2e__/cli.test.js.md index 4a782fa..9f61e33 100644 --- a/test/snapshots/index.js.md +++ b/__e2e__/__snapshots__/__e2e__/cli.test.js.md @@ -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). diff --git a/__e2e__/__snapshots__/__e2e__/cli.test.js.snap b/__e2e__/__snapshots__/__e2e__/cli.test.js.snap new file mode 100644 index 0000000..61f7400 Binary files /dev/null and b/__e2e__/__snapshots__/__e2e__/cli.test.js.snap differ diff --git a/__e2e__/__snapshots__/__e2e__/commands/showcommands.test.js.md b/__e2e__/__snapshots__/__e2e__/commands/showcommands.test.js.md new file mode 100644 index 0000000..12725fb --- /dev/null +++ b/__e2e__/__snapshots__/__e2e__/commands/showcommands.test.js.md @@ -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 │ 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!␊ + ␊ + ` diff --git a/__e2e__/__snapshots__/__e2e__/commands/showcommands.test.js.snap b/__e2e__/__snapshots__/__e2e__/commands/showcommands.test.js.snap new file mode 100644 index 0000000..7ce51a5 Binary files /dev/null and b/__e2e__/__snapshots__/__e2e__/commands/showcommands.test.js.snap differ diff --git a/__e2e__/__snapshots__/__e2e__/commands/showkeys.test.js.md b/__e2e__/__snapshots__/__e2e__/commands/showkeys.test.js.md new file mode 100644 index 0000000..e4a82db --- /dev/null +++ b/__e2e__/__snapshots__/__e2e__/commands/showkeys.test.js.md @@ -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!␊ + ` diff --git a/__e2e__/__snapshots__/__e2e__/commands/showkeys.test.js.snap b/__e2e__/__snapshots__/__e2e__/commands/showkeys.test.js.snap new file mode 100644 index 0000000..7f3a178 Binary files /dev/null and b/__e2e__/__snapshots__/__e2e__/commands/showkeys.test.js.snap differ diff --git a/test/index.js b/__e2e__/cli.test.js similarity index 100% rename from test/index.js rename to __e2e__/cli.test.js diff --git a/__e2e__/commands/showcommands.test.js b/__e2e__/commands/showcommands.test.js new file mode 100644 index 0000000..844378c --- /dev/null +++ b/__e2e__/commands/showcommands.test.js @@ -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); +}); diff --git a/__e2e__/commands/showkeys.test.js b/__e2e__/commands/showkeys.test.js new file mode 100644 index 0000000..d58b8d7 --- /dev/null +++ b/__e2e__/commands/showkeys.test.js @@ -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); +}); diff --git a/package.json b/package.json index cea53b8..6436b3e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/snapshots/index.js.snap b/test/snapshots/index.js.snap deleted file mode 100644 index e4a2d9a..0000000 Binary files a/test/snapshots/index.js.snap and /dev/null differ