Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request streamich#145 from theashraf/test/integration-test
Browse files Browse the repository at this point in the history
test: 💍 add integration test
  • Loading branch information
streamich committed May 16, 2020
2 parents c42b15b + 95a7830 commit 04c50a0
Show file tree
Hide file tree
Showing 9 changed files with 1,645 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ yarn-error.log
dist/
package-lock.json
/binaries/
coverage/
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"arrowParens": "always",
"bracketSpacing": false
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"build:cz": "browserify --node -o dist/cz.js --standalone prompter lib/cz.js",
"build:readme": "mmarkdown",
"build:binaries": "mkdirp binaries && pkg lib/cli.js --out-path binaries",
"test": "mocha",
"test": "jest --maxWorkers 2",
"test:dev": "jest --watch",
"test:coverage":"jest --coverage",
"release": "semantic-release",
"eslint": "eslint lib/*.js"
},
Expand All @@ -40,12 +42,14 @@
"husky": "4.2.5",
"inquirer": "6.5.2",
"inquirer-list-search-prompt": "1.0.2",
"jest": "^25.1.0",
"minimist": "1.2.5",
"mocha": "6.2.3",
"pkg": "4.4.8",
"rimraf": "3.0.2",
"semantic-release": "16.0.4",
"signale": "1.4.0",
"spawncommand": "^2.2.0",
"word-wrap": "1.2.3"
},
"husky": {
Expand Down
4 changes: 2 additions & 2 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "mailonline/mocha"
}
"extends": "mailonline/jest"
}
32 changes: 32 additions & 0 deletions test/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`git-cz --help 1`] = `
"
Semantic emojified git commit, git-cz
Usage: git-cz [options]
options:
-h, --help show usage information
-v, --version print version info and exit
--disable-emoji don't add emoji to commit title
--non-interactive run git-cz in non-interactive mode
non-interactive mode options:
--type type of the commit, defaults to \\"chore\\"
--subject message of the commit, defaults to \\"automated commit\\"
--scope semantic commit scope
--body extended description of the commit
--breaking description of breaking changes, if any
--issues GitHub issues this commit closed, e.g \\"#123\\"
--lerna Lerna mono-repo packages this commit affects
"
`;

exports[`git-cz --non-interactive 1`] = `
"Running in dry mode.
Will execute command:
git commit --message 'chore: 🤖 automated commit'
"
`;
26 changes: 26 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const pkg = require('../package.json');
const {runCLI} = require('./testUtils');

test('git-cz --help', async () => {
const {getResult} = runCLI(['--help']);

const result = await getResult();

expect(result).toMatchSnapshot();
});

test('git-cz --version', async () => {
const {getResult} = runCLI(['--version']);

const result = await getResult();

expect(result.trim()).toBe(pkg.version);
});

test('git-cz --non-interactive', async () => {
const {getResult} = runCLI(['--non-interactive', '--dry-run']);

const result = await getResult();

expect(result).toMatchSnapshot();
});
2 changes: 1 addition & 1 deletion test/cz.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cz = require('../dist/cz');
const cz = require('../lib/cz');

describe('commitizen', () => {
it('exports prompter function', () => {
Expand Down
39 changes: 39 additions & 0 deletions test/testUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const path = require('path');
const spawn = require('spawncommand');

exports.keys = {
down: '\u001B\u005B\u0042',
enter: '\r',
up: '\u001B\u005B\u0041'
};

exports.runCLI = (args = []) => {
const CLI_PATH = path.join(__dirname, '/../lib/cli');

const {promise, stdin} = spawn('node', [
CLI_PATH,
...args
]);

const getResult = async () => {
const {stdout} = await promise;

return stdout;
};

const delay = () => new Promise((resolve) => setTimeout(resolve, 500));

const write = async (inputs = []) => {
for (const input of inputs) {
stdin.write(input);
await delay();
}

stdin.end();
};

return {
getResult,
write
};
};
Loading

0 comments on commit 04c50a0

Please sign in to comment.