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

Commit

Permalink
test: 💍 add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
theashraf committed Feb 7, 2020
1 parent fe66607 commit daa52fe
Show file tree
Hide file tree
Showing 9 changed files with 1,809 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",
"test:dev": "jest --watch",
"test:coverage":"jest --coverage",
"release": "semantic-release",
"eslint": "eslint lib/*.js"
},
Expand All @@ -40,12 +42,14 @@
"husky": "4.2.1",
"inquirer": "6.5.2",
"inquirer-list-search-prompt": "1.0.2",
"jest": "^25.1.0",
"minimist": "1.2.0",
"mocha": "6.2.2",
"pkg": "4.4.2",
"rimraf": "3.0.1",
"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"
}
169 changes: 169 additions & 0 deletions test/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// 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
--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'
"
`;

exports[`git-cz 1`] = `
"Running in dry mode.
? Select the type of change that you're committing: (Use arrow keys or type to s
earch)
❯ 💍 test: Adding missing tests
🎸 feat: A new feature
🐛 fix: A bug fix
🤖 chore: Build process or auxiliary tool changes
✏️ docs: Documentation only changes
💡 refactor: A code change that neither fixes a bug or adds a feature
💄 style: Markup, white-space, formatting, missing semi-colons...
(Move up and down to reveal more choices)? Select the type of change that you're committing: 
💍 test: Adding missing tests
❯ 🎸 feat: A new feature
🐛 fix: A bug fix
🤖 chore: Build process or auxiliary tool changes
✏️ docs: Documentation only changes
💡 refactor: A code change that neither fixes a bug or adds a feature
💄 style: Markup, white-space, formatting, missing semi-colons...
(Move up and down to reveal more choices)? Select the type of change that you're committing: 🎸 feat: A new featur
e
? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 55 chars left
feat: ? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 54 chars left
feat: a? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 53 chars left
feat: ad? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 52 chars left
feat: add? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 51 chars left
feat: addi? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 50 chars left
feat: addin? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 49 chars left
feat: adding? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 48 chars left
feat: adding ? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 47 chars left
feat: adding a? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 46 chars left
feat: adding an? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 45 chars left
feat: adding an ? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 44 chars left
feat: adding an a? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 43 chars left
feat: adding an aw? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 42 chars left
feat: adding an awe? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 41 chars left
feat: adding an awes? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 40 chars left
feat: adding an aweso? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 39 chars left
feat: adding an awesom? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 38 chars left
feat: adding an awesome? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 37 chars left
feat: adding an awesome ? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 36 chars left
feat: adding an awesome f? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 35 chars left
feat: adding an awesome fe? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 34 chars left
feat: adding an awesome fea? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 33 chars left
feat: adding an awesome feat? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 32 chars left
feat: adding an awesome featu? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 31 chars left
feat: adding an awesome featur? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 30 chars left
feat: adding an awesome feature? Write a short, imperative mood description of the change: 
[-------------------------------------------------------------] 55 chars left
feat: adding an awesome feature
? Provide a longer description of the change:
  ? Provide a longer description of the change:
  t? Provide a longer description of the change:
  th? Provide a longer description of the change:
  the? Provide a longer description of the change:
  the ? Provide a longer description of the change:
  the f? Provide a longer description of the change:
  the fe? Provide a longer description of the change:
  the fea? Provide a longer description of the change:
  the feat? Provide a longer description of the change:
  the featu? Provide a longer description of the change:
  the featur? Provide a longer description of the change:
  the feature? Provide a longer description of the change:
  the feature ? Provide a longer description of the change:
  the feature d? Provide a longer description of the change:
  the feature de? Provide a longer description of the change:
  the feature des? Provide a longer description of the change:
  the feature desc? Provide a longer description of the change:
  the feature descr? Provide a longer description of the change:
  the feature descri? Provide a longer description of the change:
  the feature descrip? Provide a longer description of the change:
  the feature descript? Provide a longer description of the change:
  the feature descripti? Provide a longer description of the change:
  the feature descriptio? Provide a longer description of the change:
  the feature description? Provide a longer description of the change:
  the feature description
? List any breaking changes
 BREAKING CHANGE: ? List any breaking changes
 BREAKING CHANGE: S? List any breaking changes
 BREAKING CHANGE: So? List any breaking changes
 BREAKING CHANGE: Som? List any breaking changes
 BREAKING CHANGE: Some? List any breaking changes
 BREAKING CHANGE: Some ? List any breaking changes
 BREAKING CHANGE: Some B? List any breaking changes
 BREAKING CHANGE: Some Br? List any breaking changes
 BREAKING CHANGE: Some Bre? List any breaking changes
 BREAKING CHANGE: Some Brea? List any breaking changes
 BREAKING CHANGE: Some Break? List any breaking changes
 BREAKING CHANGE: Some Breaki? List any breaking changes
 BREAKING CHANGE: Some Breakin? List any breaking changes
 BREAKING CHANGE: Some Breaking? List any breaking changes
 BREAKING CHANGE: Some Breaking ? List any breaking changes
 BREAKING CHANGE: Some Breaking C? List any breaking changes
 BREAKING CHANGE: Some Breaking Ch? List any breaking changes
 BREAKING CHANGE: Some Breaking Cha? List any breaking changes
 BREAKING CHANGE: Some Breaking Chan? List any breaking changes
 BREAKING CHANGE: Some Breaking Chang? List any breaking changes
 BREAKING CHANGE: Some Breaking Change? List any breaking changes
 BREAKING CHANGE: Some Breaking Changes? List any breaking changes
 BREAKING CHANGE: Some Breaking Changes
? Issues this commit closes, e.g #123: ? Issues this commit closes, e.g #123: #? Issues this commit closes, e.g #123: #1? Issues this commit closes, e.g #123: #1
Will execute command:
git commit --message 'feat: 🎸 adding an awesome feature
the feature description
BREAKING CHANGE: 🧨 Some Breaking Changes
✅ Closes: #1'
"
`;
46 changes: 46 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const pkg = require('../package.json');
const {runCLI, keys} = 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();
});

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

await write([
keys.down,
keys.enter,
'adding an awesome feature',
keys.enter,
'the feature description',
keys.enter,
'Some Breaking Changes',
keys.enter,
'#1'
]);

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 daa52fe

Please sign in to comment.