Skip to content

fix: git-cz commit repoPath #676

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

Merged
merged 26 commits into from
Aug 25, 2020
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b4b492b
fix: git-cz commit repoPath
shixy96 Oct 6, 2019
f322e2c
chore(deps): bump minimist from 1.2.0 to 1.2.3 (#721)
dependabot[bot] Apr 6, 2020
bd5a0ba
chore(deps): update dependency nyc to v15 (#704)
renovate[bot] Apr 6, 2020
7642f05
fix: add babel spread plugin
jimthedev Apr 7, 2020
9ae386c
fix: move to babel.config.js
jimthedev Apr 7, 2020
607d514
fix: update azure devops images
jimthedev Apr 7, 2020
09ade00
docs: add commitiquette (#727)
martinmcwhorter Apr 16, 2020
ce1042e
fix(deps): bump vulnerable packages
LinusU Apr 30, 2020
6ef8afa
feature: remove dependency on ShellJS (#729)
LinusU May 4, 2020
0f8644d
feat: remove dependency on ShellJS (#729)
LinusU May 4, 2020
a95fe72
fix(deps): update dependency cz-conventional-changelog to v3.2.0 (#657)
renovate[bot] May 5, 2020
a6adb3b
fix: restore commitizen.congifLoader.load to public API (#733)
LinusU May 5, 2020
be08907
fix: make cwd argument optional again (#735)
LinusU May 5, 2020
2954303
docs: add .czrc support to README (#739)
fsmaia Jul 6, 2020
367d709
fix(deps): upgrade lodash to 4.17.20 and update package lock file
Aug 20, 2020
a333b08
docs: add cz-format-extension (#758)
tyankatsu0105 Aug 21, 2020
2fbd7ea
docs: Update `commitlint` adapter link (#751)
chris-dura Aug 21, 2020
7a61389
docs: add adapter for jira (#748)
juliuscc Aug 21, 2020
c3a4542
chore(deps): update dependency nyc to v15.1.0 (#745)
renovate[bot] Aug 21, 2020
994f3b0
fix(cli): determine correct location of `COMMIT_EDITMSG` (#737)
wkunert Aug 21, 2020
33a77cc
chore(deps): update dependency babel-plugin-istanbul to v5.2.0 (#658)
renovate[bot] Aug 21, 2020
bf275d0
chore(deps): update dependency semver to v6.3.0 (#659)
renovate[bot] Aug 21, 2020
f7257f8
fix(deps): update dependency inquirer to v6.5.2 (#664)
renovate[bot] Aug 21, 2020
c3c533f
feat: use cz as binary name (#767)
felipecrs Aug 24, 2020
e223866
fix: git-cz commit repoPath
shixy96 Oct 6, 2019
23f9692
resolve conflicts
shixy96 Aug 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -22,20 +22,20 @@ npm install -g commitizen

### If your repo is [Commitizen-friendly]:

Simply use `git cz` instead of `git commit` when committing.
Simply use `git cz` or just `cz` instead of `git commit` when committing. You can also use `git-cz`, which is an alias for `cz`.

_Alternatively_, if you are using **NPM 5.2+** you can [use `npx`](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) instead of installing globally:

```
npx git-cz
npx cz
```

or as an npm script:

```json
...
"scripts": {
"commit": "npx git-cz"
"commit": "cz"
}
```

@@ -45,7 +45,7 @@ When you're working in a Commitizen friendly repository, you'll be prompted to f

### If your repo is NOT Commitizen friendly:

If you're **not** working in a Commitizen friendly repository, then `git cz` will work just the same as `git commit` but `npx git-cz` will use the [streamich/git-cz](https://github.com/streamich/git-cz) adapter. To fix this, you need to first [make your repo Commitizen-friendly](#making-your-repo-commitizen-friendly)
If you're **not** working in a Commitizen friendly repository, then `git cz` will work just the same as `git commit` but `npx cz` will use the [streamich/git-cz](https://github.com/streamich/git-cz) adapter. To fix this, you need to first [make your repo Commitizen-friendly](#making-your-repo-commitizen-friendly)

## Making your repo Commitizen-friendly

@@ -86,6 +86,14 @@ The above command does three things for you.
}
```

Alternatively, commitizen configs may be added to a .czrc file:

```json
{
"path": "cz-conventional-changelog"
}
```

This just tells Commitizen which adapter we actually want our contributors to use when they try to commit to this repo.

`commitizen.path` is resolved via [require.resolve](https://nodejs.org/api/globals.html#globals_require_resolve) and supports
@@ -110,7 +118,7 @@ On **NPM 5.2+** you can [use `npx`](https://medium.com/@maybekatz/introducing-np
npx commitizen init cz-conventional-changelog --save-dev --save-exact
```

For **previous versions of NPM (< 5.2)** you can execute `./node_modules/.bin/commitizen` or `./node_modules/.bin/git-cz` in order to actually use the commands.
For **previous versions of NPM (< 5.2)** you can execute `./node_modules/.bin/commitizen` or `./node_modules/.bin/cz` in order to actually use the commands.

You can then initialize the conventional changelog adapter using: `./node_modules/.bin/commitizen init cz-conventional-changelog --save-dev --save-exact`

@@ -119,13 +127,15 @@ And you can then add some nice npm run scripts in your package.json pointing to
```json
...
"scripts": {
"commit": "git-cz"
"commit": "cz"
}
```

This will be more convenient for your users because then if they want to do a commit, all they need to do is run `npm run commit` and they will get the prompts needed to start a commit!

> **NOTE:** if you are using `precommit` hooks thanks to something like `husky`, you will need to name your script some thing other than "commit" (e.g. "cm": "git-cz"). The reason is because npm-scripts has a "feature" where it automatically runs scripts with the name *prexxx* where *xxx* is the name of another script. In essence, npm and husky will run "precommit" scripts twice if you name the script "commit," and the work around is to prevent the npm-triggered *precommit* script.
> **NOTE:** if you are using `precommit` hooks thanks to something like [`husky`](https://www.npmjs.com/package/husky), you will need to name your script some thing other than `"commit"`
> (e.g. `"cm": "cz"`). The reason is because npm-scripts has a "feature" where it automatically runs scripts with the name _prexxx_ where _xxx_ is the name of another script. In essence,
> npm and husky will run `"precommit"` scripts twice if you name the script `"commit"`, and the work around is to prevent the npm-triggered _precommit_ script.

#### Optional: Running Commitizen on `git commit`

@@ -142,10 +152,11 @@ Update `.git/hooks/prepare-commit-msg` with the following code:

```
#!/bin/bash
exec < /dev/tty && node_modules/.bin/git-cz --hook || true
exec < /dev/tty && node_modules/.bin/cz --hook || true
```

##### Husky

For `husky` users, add the following configuration to the project's `package.json`:

```
@@ -252,16 +263,19 @@ npm install company-commit --save-dev
We know that every project and build process has different requirements so we've tried to keep Commitizen open for extension. You can do this by choosing from any of the pre-build adapters or even by building your own. Here are some of the great adapters available to you:

- [cz-conventional-changelog](https://www.npmjs.com/package/cz-conventional-changelog)
- [cz-conventional-changelog-for-jira](https://www.npmjs.com/package/@digitalroute/cz-conventional-changelog-for-jira)
- [cz-jira-smart-commit](https://www.npmjs.com/package/cz-jira-smart-commit)
- [@endemolshinegroup/cz-jira-smart-commit](https://github.com/EndemolShineGroup/cz-jira-smart-commit)
- [@endemolshinegroup/cz-github](https://github.com/EndemolShineGroup/cz-github)
- [rb-conventional-changelog](https://www.npmjs.com/package/rb-conventional-changelog)
- [cz-mapbox-changelog](https://www.npmjs.com/package/cz-mapbox-changelog)
- [cz-customizable](https://github.com/leonardoanalista/cz-customizable)
- [commitlint](https://github.com/marionebl/commitlint)
- [commitlint](https://github.com/conventional-changelog/commitlint#tools)
- [vscode-commitizen](https://github.com/KnisterPeter/vscode-commitizen)
- [cz-emoji](https://github.com/ngryman/cz-emoji)
- [cz-adapter-eslint](https://www.npmjs.com/package/cz-adapter-eslint)
- [commitiquette](https://github.com/martinmcwhorter/commitiquette)
- [cz-format-extension](https://github.com/tyankatsu0105/cz-format-extension)

To create an adapter, just fork one of these great adapters and modify it to suit your needs. We pass you an instance of [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/) but you can capture input using whatever means necessary. Just call the `commit` callback with a string and we'll be happy. Publish it to npm, and you'll be all set!

@@ -271,11 +285,10 @@ As of version 2.7.1, you may attempt to retry the last commit using the `git cz

Please note that the retry cache may be cleared when upgrading commitizen versions, upgrading adapters, or if you delete the `commitizen.json` file in your home or temp directory. Additionally, the commit cache uses the filesystem path of the repo, so if you move a repo or change its path, you will not be able to retry a commit. This is an edge case, but might be confusing if you have scenarios where you are moving folders that contain repos.

It is important to note that if you are running `git-cz` from a npm script (let's say it is called `commit`) you will need to do one of the following:
It is important to note that if you are running `cz` from a npm script (let's say it is called `commit`) you will need to do one of the following:

- Pass `-- --retry` as an argument for your script. i.e: `npm run commit -- --retry`
- Use [npm-run](https://www.npmjs.com/package/npm-run) to find and call git-cz executable directly. i.e: `npm-run git-cz --retry`
- Use [npm-quick-run](https://www.npmjs.com/package/npm-quick-run) i.e: `nr commit --retry` or just `nr c --retry` (which will run all scripts that starts with the letter 'c')
- Use [npx](https://www.npmjs.com/package/npx) to find and call `cz` executable directly. i.e: `npx cz --retry`

Note that the last two options **do not** require you to pass `--` before the args but the first **does**.

@@ -340,4 +353,4 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
<a href="https://opencollective.com/commitizen/sponsor/8/website" target="_blank"><img src="https://opencollective.com/commitizen/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/commitizen/sponsor/9/website" target="_blank"><img src="https://opencollective.com/commitizen/sponsor/9/avatar.svg"></a>

[Commitizen-friendly]: #making-your-repo-commitizen-friendly
[commitizen-friendly]: #making-your-repo-commitizen-friendly
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ jobs:
parameters:
name: macOS
pool:
vmImage: 'macOS-10.13'
vmImage: 'macOS-latest'

- template: jobs/build.yml # Template reference
parameters:
@@ -20,5 +20,5 @@ jobs:
parameters:
name: Windows
pool:
vmImage: 'vs2017-win2016'
vmImage: 'windows-latest'
sign: true # Extra step on Windows only
13 changes: 13 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{
targets: {
node: "10",
},
},
],
],
plugins: ["@babel/plugin-proposal-object-rest-spread", "istanbul"],
};
29,636 changes: 15,575 additions & 14,061 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 9 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
"url": "https://github.com/commitizen/cz-cli/issues"
},
"bin": {
"cz": "./bin/git-cz",
"git-cz": "./bin/git-cz",
"commitizen": "./bin/commitizen"
},
@@ -49,11 +50,12 @@
"devDependencies": {
"@babel/cli": "^7.1.0",
"@babel/core": "^7.1.0",
"@babel/plugin-proposal-object-rest-spread": "7.9.0",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"@istanbuljs/nyc-config-babel": "2.1.1",
"axios": "0.19.0",
"babel-plugin-istanbul": "5.1.4",
"babel-plugin-istanbul": "5.2.0",
"chai": "^4.1.2",
"codecov.io": "0.1.6",
"cz-conventional-changelog-default-export": "0.0.0-semantically-released.1",
@@ -63,45 +65,29 @@
"mocha-junit-reporter": "^1.18.0",
"mocha-multi-reporters": "^1.1.7",
"nodemon": "1.19.1",
"nyc": "14.1.1",
"nyc": "15.1.0",
"proxyquire": "^2.1.0",
"semantic-release": "15.13.18",
"semver": "6.2.0",
"semver": "6.3.0",
"sinon": "^6.3.4",
"uuid": "3.3.2"
},
"dependencies": {
"cachedir": "2.2.0",
"cz-conventional-changelog": "3.0.1",
"cz-conventional-changelog": "3.2.0",
"dedent": "0.7.0",
"detect-indent": "6.0.0",
"find-node-modules": "2.0.0",
"find-root": "1.1.0",
"fs-extra": "8.1.0",
"glob": "7.1.4",
"inquirer": "6.5.0",
"inquirer": "6.5.2",
"is-utf8": "^0.2.1",
"lodash": "4.17.15",
"minimist": "1.2.0",
"shelljs": "0.7.6",
"lodash": "^4.17.20",
"minimist": "1.2.5",
"strip-bom": "4.0.0",
"strip-json-comments": "3.0.1"
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "10"
}
}
]
],
"plugins": [
"istanbul"
]
},
"nyc": {
"extends": "@istanbuljs/nyc-config-babel",
"exclude": [
14 changes: 7 additions & 7 deletions src/cli/commitizen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { init } from '../commitizen';
import { commitizen as commitizenParser } from './parsers';
import * as sh from 'shelljs';

let { parse } = commitizenParser;

@@ -27,7 +26,7 @@ function bootstrap (environment = {}, argv = process.argv) {
if (adapterNpmName) {
console.log(`Attempting to initialize using the npm package ${adapterNpmName}`);
try {
init(sh, process.cwd(), adapterNpmName, parsedArgs);
init(process.cwd(), adapterNpmName, parsedArgs);
} catch (e) {
console.error(`Error: ${e}`);
}
@@ -39,14 +38,15 @@ function bootstrap (environment = {}, argv = process.argv) {
Commitizen has two command line tools:
1) commitizen -- used for installing adapters into your project
2) git-cz -- used for making commits according to convention
1) cz -- used for making commits according to convention
note: you can run 'git cz' if installed with -g
2) git-cz -- alias for 'cz'
3) commitizen -- used for installing adapters into your project
Generally if you're using someone else's repo and they've already set up an
adapter, you're going to just be running:
git-cz
cz
However, if you create a new repo and you want to make it easier for future
contributors to follow your commit message conventions using commitizen then
@@ -72,13 +72,13 @@ function bootstrap (environment = {}, argv = process.argv) {
--save-exact Install an exact version instead of a range
--force Force install the adapter, even if a previous one exists.
2) git-cz <any regular git commit arguments>
2) cz <any regular git commit arguments>
description: Runs the commitizen prompter, asking you questions so that you
follow the commit conventions of the repository of the current
directory.
note: git-cz may even be run as 'git cz' if installed with -g.
note: cz may even be run as 'git cz' if installed with -g.
`);
}
5 changes: 2 additions & 3 deletions src/cli/strategies/git-cz.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sh from 'shelljs';
import inquirer from 'inquirer';
import findRoot from 'find-root';
import { getParsedPackageJsonFromPath } from '../../common/util';
@@ -9,7 +8,7 @@ import * as gitStrategy from './git';
// destructure for shorter apis
let { parse } = gitCzParser;

let { getPrompter, resolveAdapterPath } = adapter;
let { getPrompter, resolveAdapterPath, getGitRootPath } = adapter;
let { isClean } = staging;

export default gitCz;
@@ -56,7 +55,7 @@ function gitCz (rawGitArgs, environment, adapterConfig) {
let adapterPackageJson = getParsedPackageJsonFromPath(resolvedAdapterRootPath);
let cliPackageJson = getParsedPackageJsonFromPath(environment.cliPath);
console.log(`cz-cli@${cliPackageJson.version}, ${adapterPackageJson.name}@${adapterPackageJson.version}\n`);
commit(sh, inquirer, process.cwd(), prompter, {
commit(inquirer, getGitRootPath(), prompter, {
args: parsedGitCzArgs,
disableAppendPaths: true,
emitData: true,
2 changes: 1 addition & 1 deletion src/cli/strategies/git.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ export default git;
// or if debug is enabled then we do a strict check for a config file.
function git (rawGitArgs, environment) {
if (environment.debug === true) {
console.error('COMMITIZEN DEBUG: No git-cz friendly config was detected. I looked for .czrc, .cz.json, or czConfig in package.json.');
console.error('COMMITIZEN DEBUG: No cz friendly config was detected. I looked for .czrc, .cz.json, or czConfig in package.json.');
} else {
var vanillaGitArgs = ["commit"].concat(rawGitArgs);

13 changes: 7 additions & 6 deletions src/commitizen/adapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import childProcess from 'child_process';
import path from 'path';
import fs from 'fs';
import findNodeModules from 'find-node-modules';
import _ from 'lodash';
import detectIndent from 'detect-indent';
import sh from 'shelljs';

import { isFunction } from '../common/util';

@@ -17,6 +17,7 @@ export {
resolveAdapterPath,
getYarnAddStringMappings,
generateYarnAddAdapterCommand,
getGitRootPath,
};

/**
@@ -32,7 +33,7 @@ export {
* Modifies the package.json, sets config.commitizen.path to the path of the adapter
* Must be passed an absolute path to the cli's root
*/
function addPathToAdapterConfig (sh, cliPath, repoPath, adapterNpmName) {
function addPathToAdapterConfig (cliPath, repoPath, adapterNpmName) {

let commitizenAdapterConfig = {
config: {
@@ -42,7 +43,7 @@ function addPathToAdapterConfig (sh, cliPath, repoPath, adapterNpmName) {
}
};

let packageJsonPath = path.join(getNearestProjectRootDirectory(), 'package.json');
let packageJsonPath = path.join(getNearestProjectRootDirectory(repoPath), 'package.json');
let packageJsonString = fs.readFileSync(packageJsonPath, 'utf-8');
// tries to detect the indentation and falls back to a default if it can't
let indent = detectIndent(packageJsonString).indent || ' ';
@@ -111,8 +112,8 @@ function getNearestNodeModulesDirectory (options) {
/**
* Gets the nearest project root directory
*/
function getNearestProjectRootDirectory (options) {
return path.join(process.cwd(), getNearestNodeModulesDirectory(options), '/../');
function getNearestProjectRootDirectory (repoPath, options) {
return path.join(repoPath, getNearestNodeModulesDirectory(options), '/../');
}

/**
@@ -180,5 +181,5 @@ function resolveAdapterPath (inboundAdapterPath) {
}

function getGitRootPath () {
return sh.exec('git rev-parse --show-toplevel', { silent: true }).stdout.trim();
return childProcess.spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).stdout.trim();
}
10 changes: 5 additions & 5 deletions src/commitizen/commit.js
Original file line number Diff line number Diff line change
@@ -10,17 +10,17 @@ export default commit;
/**
* Takes all of the final inputs needed in order to make dispatch a git commit
*/
function dispatchGitCommit (sh, repoPath, template, options, overrideOptions, done) {
function dispatchGitCommit (repoPath, template, options, overrideOptions, done) {
// Commit the user input -- side effect that we'll test
gitCommit(sh, repoPath, template, { ...options, ...overrideOptions }, function (error) {
gitCommit(repoPath, template, { ...options, ...overrideOptions }, function (error) {
done(error, template);
});
}

/**
* Asynchronously commits files using commitizen
*/
function commit (sh, inquirer, repoPath, prompter, options, done) {
function commit (inquirer, repoPath, prompter, options, done) {
var cacheDirectory = cacheDir('commitizen');
var cachePath = path.join(cacheDirectory, 'commitizen.json');

@@ -40,7 +40,7 @@ function commit (sh, inquirer, repoPath, prompter, options, done) {
overrideOptions: retryOverrideOptions,
template: retryTemplate
} = cache.getCacheValueSync(cachePath, repoPath);
dispatchGitCommit(sh, repoPath, retryTemplate, retryOptions, retryOverrideOptions, done);
dispatchGitCommit(repoPath, retryTemplate, retryOptions, retryOverrideOptions, done);

} else {
// Get user input -- side effect that is hard to test
@@ -59,7 +59,7 @@ function commit (sh, inquirer, repoPath, prompter, options, done) {

// We don't want to add retries to the cache, only actual commands
cache.setCacheValueSync(cachePath, repoPath, { template, options, overrideOptions });
dispatchGitCommit(sh, repoPath, template, options, overrideOptions, done);
dispatchGitCommit(repoPath, template, options, overrideOptions, done);
});
}
}
26 changes: 10 additions & 16 deletions src/commitizen/init.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import childProcess from 'child_process';
import path from 'path';
import * as configLoader from './configLoader';
import { executeShellCommand } from '../common/util';
import * as adapter from './adapter';

let {
@@ -48,7 +48,7 @@ const defaultInitOptions = {
/**
* Runs npm install for the adapter then modifies the config.commitizen as needed
*/
function init (sh, repoPath, adapterNpmName, {
function init (repoPath, adapterNpmName, {
save = false,
saveDev = true,
saveExact = false,
@@ -60,13 +60,10 @@ function init (sh, repoPath, adapterNpmName, {
} = defaultInitOptions) {

// Don't let things move forward if required args are missing
checkRequiredArguments(sh, repoPath, adapterNpmName);

// Move to the correct directory so we can run commands
sh.cd(repoPath);
checkRequiredArguments(repoPath, adapterNpmName);

// Load the current adapter config
let adapterConfig = loadAdapterConfig();
let adapterConfig = loadAdapterConfig(repoPath);

// Get the npm string mappings based on the arguments provided
let stringMappings = yarn ? getYarnAddStringMappings(dev, exact, force) : getNpmInstallStringMappings(save, saveDev, saveExact, force);
@@ -88,11 +85,11 @@ function init (sh, repoPath, adapterNpmName, {
}

try {
executeShellCommand(sh, repoPath, installAdapterCommand);
childProcess.execSync(installAdapterCommand, { cwd: repoPath });
if(includeCommitizen) {
executeShellCommand(sh, repoPath, installCommitizenCommand);
childProcess.execSync(installCommitizenCommand, { cwd: repoPath });
}
addPathToAdapterConfig(sh, CLI_PATH, repoPath, adapterNpmName);
addPathToAdapterConfig(CLI_PATH, repoPath, adapterNpmName);
} catch (e) {
console.error(e);
}
@@ -102,10 +99,7 @@ function init (sh, repoPath, adapterNpmName, {
* Checks to make sure that the required arguments are passed
* Throws an exception if any are not.
*/
function checkRequiredArguments (sh, path, adapterNpmName) {
if (!sh) {
throw new Error("You must pass an instance of shelljs when running init.");
}
function checkRequiredArguments (path, adapterNpmName) {
if (!path) {
throw new Error("Path is required when running init.");
}
@@ -118,8 +112,8 @@ function checkRequiredArguments (sh, path, adapterNpmName) {
* CONFIG
* Loads and returns the adapter config at key config.commitizen, if it exists
*/
function loadAdapterConfig () {
let config = configLoader.load();
function loadAdapterConfig (cwd) {
let config = configLoader.load(null, cwd);
if (config) {
return config;
} else {
2 changes: 1 addition & 1 deletion src/commitizen/staging.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ export { isClean };
function isClean (repoPath, done) {
exec('git diff --no-ext-diff --name-only && git diff --no-ext-diff --cached --name-only', {
maxBuffer: Infinity,
cwd: repoPath || process.cwd()
cwd: repoPath
}, function (error, stdout) {
if (error) {
return done(error);
40 changes: 0 additions & 40 deletions src/common/util.js
Original file line number Diff line number Diff line change
@@ -2,24 +2,12 @@ import fs from 'fs';
import path from 'path';

export {
executeShellCommand,
getParsedJsonFromFile,
getParsedPackageJsonFromPath,
isArray,
isFunction,
isString,
isInTest
}

/**
* Executes the command passed to it at the path requested
* using the instance of shelljs passed in
*/
function executeShellCommand (sh, path, installCommand) {
sh.cd(path);
sh.exec(installCommand);
}

/**
* Gets the parsed contents of a json file
*/
@@ -39,20 +27,6 @@ function getParsedPackageJsonFromPath (path) {
return getParsedJsonFromFile(path, 'package.json');
}

/**
* Test if the passed argument is an array
*/
function isArray (arr) {
if (typeof arr === "undefined")
{
return false;
} else if (arr === null) {
return false;
} else {
return arr.constructor === Array;
}
}

/**
* Test if the passed argument is a function
*/
@@ -68,20 +42,6 @@ function isFunction (functionToCheck) {
}
}

/**
* Test if the passed argument is a string
*/
function isString (str) {
if (typeof str === "undefined")
{
return false;
} else if (str === null) {
return false;
} else {
return Object.prototype.toString.call(str) === '[object String]';
}
}

function isInTest () {
return typeof global.it === 'function';
}
12 changes: 6 additions & 6 deletions src/git/add.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import childProcess from 'child_process';

export {
addPath,
addFile
@@ -6,15 +8,13 @@ export {
/**
* Synchronously adds a path to git staging
*/
function addPath (sh, repoPath) {
sh.cd(repoPath);
sh.exec('git add .');
function addPath (repoPath) {
childProcess.spawnSync('git', ['add', '.'], { cwd: repoPath });
}

/**
* Synchronously adds a file to git staging
*/
function addFile (sh, repoPath, filename) {
sh.cd(repoPath);
sh.exec('git add ' + filename)
function addFile (repoPath, filename) {
childProcess.spawnSync('git', ['add', filename], { cwd: repoPath });
}
12 changes: 8 additions & 4 deletions src/git/commit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from 'child_process';
import { execSync, spawn } from 'child_process';

import path from 'path';

@@ -11,7 +11,7 @@ export { commit };
/**
* Asynchronously git commit at a given path with a message
*/
function commit (sh, repoPath, message, options, done) {
function commit (repoPath, message, options, done) {
let called = false;

// commit the file by spawning a git process, unless the --hook
@@ -39,7 +39,7 @@ function commit (sh, repoPath, message, options, done) {
if (code === 128) {
console.warn(`
Git exited with code 128. Did you forget to run:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
`)
@@ -50,7 +50,11 @@ function commit (sh, repoPath, message, options, done) {
}
});
} else {
const commitFilePath = path.join(repoPath, '/.git/COMMIT_EDITMSG');
const gitDirPath = execSync(
'git rev-parse --absolute-git-dir',
{ cwd: repoPath, encoding: 'utf8' },
).trim();
const commitFilePath = path.join(gitDirPath, 'COMMIT_EDITMSG');
try {
const fd = openSync(commitFilePath, 'w');
try {
7 changes: 4 additions & 3 deletions src/git/init.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import childProcess from 'child_process';

export { init };

/**
* Synchronously creates a new git repo at a path
*/
function init (sh, repoPath) {
sh.cd(repoPath);
sh.exec('git init');
function init (repoPath) {
childProcess.spawnSync('git', ['init'], { cwd: repoPath });
}
6 changes: 0 additions & 6 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -33,12 +33,6 @@ let config = {
*/
maxTimeout: 240000,

/**
* Whether shelljs should suppress output, should be true
* unless debugging.
*/
silent: true,

/**
* Whether or not to keep the artifacts of the tests after
* they've run.
7 changes: 1 addition & 6 deletions test/tester.js
Original file line number Diff line number Diff line change
@@ -3,21 +3,16 @@ import * as clean from './tools/clean';
import * as files from './tools/files';
import * as util from '../src/common/util';
import { config as userConfig } from './config';
import * as sh from 'shelljs'; // local instance
import _ from 'lodash';

// Clone the user's config so we don't get caught w/our pants down
let patchedConfig = _.cloneDeep(userConfig);

function bootstrap () {

// Patch any shelljs specific config settings
sh.config.silent = patchedConfig.silent || true;

// Return the patched config and shelljs instance
// Return the patched config
return {
config: patchedConfig,
sh,
repo,
clean,
util,
20 changes: 10 additions & 10 deletions test/tests/adapter.js
Original file line number Diff line number Diff line change
@@ -12,16 +12,16 @@ import { isFunction } from '../../src/common/util';
import { bootstrap } from '../tester';

// Destructure some things based on the bootstrap process
let { config, sh, repo, clean } = bootstrap();
let { config, repo, clean } = bootstrap();

before(function () {
// Creates the temp path
clean.before(sh, config.paths.tmp);
clean.before(config.paths.tmp);
});

beforeEach(function () {
this.timeout(config.maxTimeout); // this could take a while
repo.createEndUser(sh, config.paths.endUserRepo);
repo.createEndUser(config.paths.endUserRepo);
});

describe('adapter', function () {
@@ -54,7 +54,7 @@ describe('adapter', function () {
};

// Install an adapter
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog');
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog');

// TEST
expect(function () { adapter.resolveAdapterPath('IAMANIMPOSSIBLEPATH'); }).to.throw(Error);
@@ -95,15 +95,15 @@ describe('adapter', function () {
};

// Install an adapter
commitizenInit(sh, config.paths.endUserRepo, '@commitizen/cz-conventional-changelog');
commitizenInit(config.paths.endUserRepo, '@commitizen/cz-conventional-changelog');

// TEST
expect(function () { adapter.resolveAdapterPath('IAMANIMPOSSIBLEPATH'); }).to.throw(Error);
expect(function () { adapter.resolveAdapterPath(adapterConfig.path); }).not.to.throw(Error);
expect(function () { adapter.resolveAdapterPath(path.join(adapterConfig.path, 'index.js')); }).not.to.throw(Error);
});

it('gets adapter prompter functions', function () {
it.skip('gets adapter prompter functions', function () {

this.timeout(config.maxTimeout); // this could take a while

@@ -131,7 +131,7 @@ describe('adapter', function () {
};

// Install an adapter
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', {includeCommitizen: true});
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', {includeCommitizen: true});

// TEST
expect(function () { adapter.getPrompter('IAMANIMPOSSIBLEPATH'); }).to.throw(Error);
@@ -167,7 +167,7 @@ describe('adapter', function () {
};

// Install an adapter
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog-default-export');
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog-default-export');

// TEST
expect(function () { adapter.getPrompter('IAMANIMPOSSIBLEPATH'); }).to.throw(Error);
@@ -180,12 +180,12 @@ describe('adapter', function () {
afterEach(function () {
this.timeout(config.maxTimeout); // this could take a while
// All this should do is archive the tmp path to the artifacts
clean.afterEach(sh, config.paths.tmp, config.preserve);
clean.afterEach(config.paths.tmp, config.preserve);
});

after(function () {
this.timeout(config.maxTimeout); // this could take a while
// Once everything is done, the artifacts should be cleaned up based on
// the preserve setting in the config
clean.after(sh, config.paths.tmp, config.preserve);
clean.after(config.paths.tmp, config.preserve);
});
42 changes: 21 additions & 21 deletions test/tests/commit.js
Original file line number Diff line number Diff line change
@@ -13,18 +13,18 @@ import { addFile as gitAddFile, init as gitInit, log, whatChanged } from '../../
import { commit as commitizenCommit, init as commitizenInit } from '../../src/commitizen';

// Destructure some things for cleaner tests
let { config, sh, repo, clean, files } = bootstrap();
let { config, repo, clean, files } = bootstrap();
let { writeFilesToPath } = files;

before(function () {
// Creates the temp path
clean.before(sh, config.paths.tmp);
clean.before(config.paths.tmp);
});

beforeEach(function () {
this.timeout(config.maxTimeout); // this could take a while
/* istanbul ignore next */
repo.createEndUser(sh, config.paths.endUserRepo);
repo.createEndUser(config.paths.endUserRepo);
});

describe('commit', function () {
@@ -59,12 +59,12 @@ describe('commit', function () {
};

// Quick setup the repos, adapter, and grab a simple prompter
let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage);
let prompter = quickPrompterSetup(repoConfig, adapterConfig, dummyCommitMessage);
// TEST

// Pass in inquirer but it never gets used since we've mocked out a different
// version of prompter.
commitizenCommit(sh, inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function () {
commitizenCommit(inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function () {
log(repoConfig.path, function (logOutput) {
expect(logOutput).to.have.string(dummyCommitMessage);
done();
@@ -103,12 +103,12 @@ describe('commit', function () {
};

// Quick setup the repos, adapter, and grab a simple prompter
let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage);
let prompter = quickPrompterSetup(repoConfig, adapterConfig, dummyCommitMessage);
// TEST

// Pass in inquirer but it never gets used since we've mocked out a different
// version of prompter.
commitizenCommit(sh, inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function () {
commitizenCommit(inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function () {
log(repoConfig.path, function (logOutput) {
expect(logOutput).to.have.string(dummyCommitMessage);
done();
@@ -152,12 +152,12 @@ ${(os.platform === 'win32') ? '' : ' '}
};

// Quick setup the repos, adapter, and grab a simple prompter
let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage);
let prompter = quickPrompterSetup(repoConfig, adapterConfig, dummyCommitMessage);
// TEST

// Pass in inquirer but it never gets used since we've mocked out a different
// version of prompter.
commitizenCommit(sh, inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true }, function () {
commitizenCommit(inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true }, function () {
log(repoConfig.path, function (logOutput) {
expect(logOutput).to.have.string(dummyCommitMessage);
done();
@@ -201,12 +201,12 @@ ${(os.platform === 'win32') ? '' : ' '}
};

// Quick setup the repos, adapter, and grab a simple prompter
let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage, options);
let prompter = quickPrompterSetup(repoConfig, adapterConfig, dummyCommitMessage, options);
// TEST

// Pass in inquirer but it never gets used since we've mocked out a different
// version of prompter.
commitizenCommit(sh, inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function () {
commitizenCommit(inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function () {
log(repoConfig.path, function (logOutput) {
expect(logOutput).to.have.string(author);
expect(logOutput).to.have.string(dummyCommitMessage);
@@ -255,12 +255,12 @@ ${(os.platform === 'win32') ? '' : ' '}
};

// Quick setup the repos, adapter, and grab a simple prompter
let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage, options);
let prompter = quickPrompterSetup(repoConfig, adapterConfig, dummyCommitMessage, options);
// TEST

// Pass in inquirer but it never gets used since we've mocked out a different
// version of prompter.
commitizenCommit(sh, inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function () {
commitizenCommit(inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function () {
log(repoConfig.path, function (logOutput) {
expect(logOutput).to.have.string(dummyCommitMessage);
});
@@ -297,11 +297,11 @@ ${(os.platform === 'win32') ? '' : ' '}
}

// Quick setup the repos, adapter, and grab a simple prompter
let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage);
let prompter = quickPrompterSetup(repoConfig, adapterConfig, dummyCommitMessage);
// TEST

// This is a successful commit directly to .git/COMMIT_EDITMSG
commitizenCommit(sh, inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true, hookMode: true }, function (err) {
commitizenCommit(inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true, hookMode: true }, function (err) {
const commitFilePath = path.join(repoConfig.path, '.git/COMMIT_EDITMSG')
const commitFile = fs.openSync(commitFilePath, 'r+')
let commitContents = fs.readFileSync(commitFile, { flags: 'r+' }).toString();
@@ -316,23 +316,23 @@ ${(os.platform === 'win32') ? '' : ' '}
afterEach(function () {
this.timeout(config.maxTimeout); // this could take a while
// All this should do is archive the tmp path to the artifacts
clean.afterEach(sh, config.paths.tmp, config.preserve);
clean.afterEach(config.paths.tmp, config.preserve);
});

after(function () {
this.timeout(config.maxTimeout); // this could take a while
// Once everything is done, the artifacts should be cleaned up based on
// the preserve setting in the config
clean.after(sh, config.paths.tmp, config.preserve);
clean.after(config.paths.tmp, config.preserve);
});

/**
* This is just a helper for testing. NOTE that prompter
* prompter is overriden for testing purposes.
*/
function quickPrompterSetup (sh, repoConfig, adapterConfig, commitMessage, options = {}) {
function quickPrompterSetup (repoConfig, adapterConfig, commitMessage, options = {}) {

commitizenInit(sh, repoConfig.path, adapterConfig.npmName);
commitizenInit(repoConfig.path, adapterConfig.npmName);

// NOTE:
// In our real code we'd use this here but since we're testing,
@@ -342,14 +342,14 @@ function quickPrompterSetup (sh, repoConfig, adapterConfig, commitMessage, optio
commit(commitMessage, options);
}

gitInit(sh, repoConfig.path);
gitInit(repoConfig.path);

writeFilesToPath(repoConfig.files, repoConfig.path);

for (let key in repoConfig.files) {
let file = repoConfig.files[key];
if (file.add !== false) {
gitAddFile(sh, repoConfig.path, file.filename);
gitAddFile(repoConfig.path, file.filename);
}
}

55 changes: 22 additions & 33 deletions test/tests/init.js
Original file line number Diff line number Diff line change
@@ -10,16 +10,16 @@ import { init as commitizenInit } from '../../src/commitizen';
import { bootstrap } from '../tester';

// Destructure some things based on the bootstrap process
let { config, sh, repo, clean, util } = bootstrap();
let { config, repo, clean, util } = bootstrap();

before(function () {
// Creates the temp path
clean.before(sh, config.paths.tmp);
clean.before(config.paths.tmp);
});

beforeEach(function () {
this.timeout(config.maxTimeout); // this could take a while
repo.createEndUser(sh, config.paths.endUserRepo);
repo.createEndUser(config.paths.endUserRepo);
});

describe('init', function () {
@@ -31,7 +31,7 @@ describe('init', function () {
// SETUP

// Install an adapter
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog');
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog');

// TEST

@@ -48,7 +48,7 @@ describe('init', function () {
// SETUP

// Install an adapter
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { save: true, saveDev: false });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { save: true, saveDev: false });

// TEST

@@ -65,14 +65,12 @@ describe('init', function () {
// SETUP

// Add a first adapter
sh.cd(config.paths.endUserRepo);
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { saveDev: true });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { saveDev: true });

// TEST
sh.cd(config.paths.endUserRepo);
// Adding a second adapter
expect(function () {
commitizenInit(sh, config.paths.endUserRepo, 'cz-jira-smart-commit', { saveDev: true });
commitizenInit(config.paths.endUserRepo, 'cz-jira-smart-commit', { saveDev: true });
}).to.throw(/already configured/);

// Check resulting json
@@ -90,14 +88,13 @@ describe('init', function () {
// SETUP

// Add a first adapter
sh.cd(config.paths.endUserRepo);
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { saveDev: true });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { saveDev: true });

// TEST

// Adding a second adapter
expect(function () {
commitizenInit(sh, config.paths.endUserRepo, 'cz-jira-smart-commit', { saveDev: true, force: true });
commitizenInit(config.paths.endUserRepo, 'cz-jira-smart-commit', { saveDev: true, force: true });
}).to.not.throw();

let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
@@ -113,8 +110,7 @@ describe('init', function () {
// SETUP

// Add a first adapter
sh.cd(config.paths.endUserRepo);
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog');
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog');
let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);

// TEST
@@ -139,8 +135,7 @@ describe('init', function () {
// SETUP

// Add a first adapter
sh.cd(config.paths.endUserRepo);
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { saveExact: true });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { saveExact: true });
let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);

// TEST
@@ -162,8 +157,7 @@ describe('init', function () {
// SETUP

// Add a first adapter
sh.cd(config.paths.endUserRepo);
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { includeCommitizen: true });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { includeCommitizen: true });
let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);

// TEST
@@ -186,7 +180,7 @@ describe('init', function () {
// SETUP

// Install an adapter
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true });

// TEST

@@ -203,7 +197,7 @@ describe('init', function () {
// SETUP

// Install an adapter
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });

// TEST

@@ -220,14 +214,12 @@ describe('init', function () {
// SETUP

// Add a first adapter
sh.cd(config.paths.endUserRepo);
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });

// TEST
sh.cd(config.paths.endUserRepo);
// Adding a second adapter
expect(function () {
commitizenInit(sh, config.paths.endUserRepo, 'cz-jira-smart-commit', { yarn: true, dev: true });
commitizenInit(config.paths.endUserRepo, 'cz-jira-smart-commit', { yarn: true, dev: true });
}).to.throw(/already configured/);

// Check resulting json
@@ -245,14 +237,13 @@ describe('init', function () {
// SETUP

// Add a first adapter
sh.cd(config.paths.endUserRepo);
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });

// TEST

// Adding a second adapter
expect(function () {
commitizenInit(sh, config.paths.endUserRepo, 'cz-jira-smart-commit', { yarn: true, dev: true, force: true });
commitizenInit(config.paths.endUserRepo, 'cz-jira-smart-commit', { yarn: true, dev: true, force: true });
}).to.not.throw();

let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
@@ -268,8 +259,7 @@ describe('init', function () {
// SETUP

// Add a first adapter
sh.cd(config.paths.endUserRepo);
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });
let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);

// TEST
@@ -294,8 +284,7 @@ describe('init', function () {
// SETUP

// Add a first adapter
sh.cd(config.paths.endUserRepo);
commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true, exact: true });
commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true, exact: true });
let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);

// TEST
@@ -315,12 +304,12 @@ describe('init', function () {
afterEach(function () {
this.timeout(config.maxTimeout); // this could take a while
// All this should do is archive the tmp path to the artifacts
clean.afterEach(sh, config.paths.tmp, config.preserve);
clean.afterEach(config.paths.tmp, config.preserve);
});

after(function () {
this.timeout(config.maxTimeout); // this could take a while
// Once everything is done, the artifacts should be cleaned up based on
// the preserve setting in the config
clean.after(sh, config.paths.tmp, config.preserve);
clean.after(config.paths.tmp, config.preserve);
});
14 changes: 7 additions & 7 deletions test/tests/staging.js
Original file line number Diff line number Diff line change
@@ -8,17 +8,17 @@ import { init as gitInit, addPath as gitAdd } from '../../src/git';
import { staging } from '../../src/commitizen';

// Destructure some things for cleaner tests
let { config, sh, repo, clean, files } = bootstrap();
let { config, repo, clean, files } = bootstrap();
let { writeFilesToPath } = files;

before(function () {
// Creates the temp path
clean.before(sh, config.paths.tmp);
clean.before(config.paths.tmp);
});

beforeEach(function () {
this.timeout(config.maxTimeout); // this could take a while
repo.createEndUser(sh, config.paths.endUserRepo);
repo.createEndUser(config.paths.endUserRepo);
});

describe('staging', function () {
@@ -44,7 +44,7 @@ describe('staging', function () {
}
};

gitInit(sh, repoConfig.path);
gitInit(repoConfig.path);

staging.isClean('./@this-actually-does-not-exist', function (stagingError) {
expect(stagingError).to.be.an.instanceof(Error);
@@ -55,7 +55,7 @@ describe('staging', function () {

writeFilesToPath(repoConfig.files, repoConfig.path);

gitAdd(sh, repoConfig.path);
gitAdd(repoConfig.path);

staging.isClean(repoConfig.path, function (afterWriteStagingIsCleanError, afterWriteStagingIsClean) {
expect(afterWriteStagingIsCleanError).to.be.null;
@@ -83,12 +83,12 @@ describe('staging', function () {
afterEach(function () {
this.timeout(config.maxTimeout); // this could take a while
// All this should do is archive the tmp path to the artifacts
clean.afterEach(sh, config.paths.tmp, config.preserve);
clean.afterEach(config.paths.tmp, config.preserve);
});

after(function () {
this.timeout(config.maxTimeout); // this could take a while
// Once everything is done, the artifacts should be cleaned up based on
// the preserve setting in the config
clean.after(sh, config.paths.tmp, config.preserve);
clean.after(config.paths.tmp, config.preserve);
});
47 changes: 1 addition & 46 deletions test/tests/util.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
import { expect } from 'chai';
import { isArray, isFunction, isString } from '../../src/common/util';
import { isFunction } from '../../src/common/util';

describe('common util', function () {

it('isArray determines if array is passed', function () {

// Truthies
expect(isArray([])).to.be.true;
expect(isArray([1, 2, 3])).to.be.true;
expect(isArray([1, , 3])).to.be.true;
expect(isArray(new Array())).to.be.true;

// Falsies
expect(isArray(undefined)).to.be.false;
expect(isArray(null)).to.be.false;
expect(isArray(49)).to.be.false;
expect(isArray(function () {})).to.be.false;
expect(isArray({})).to.be.false;
expect(isArray("asdf")).to.be.false;
expect(isArray(true)).to.be.false;
expect(isArray(false)).to.be.false;
expect(isArray(Symbol('test'))).to.be.false;

});

it('isFunction determines if a function is passed', function () {

// Truthies
@@ -43,28 +22,4 @@ describe('common util', function () {

});

it('isString determines if string is passed', function () {

// Truthies
expect(isString('a single quoted string')).to.be.true;
expect(isString("a double quoted string")).to.be.true;
expect(isString(`
a multi
line
string`
)).to.be.true;
expect(isString(new String())).to.be.true;

// Falsies
expect(isString(function () {})).to.be.false;
expect(isString(undefined)).to.be.false;
expect(isString(null)).to.be.false;
expect(isString(49)).to.be.false;
expect(isString([])).to.be.false;
expect(isString({})).to.be.false;
expect(isString(true)).to.be.false;
expect(isString(false)).to.be.false;
expect(isString(Symbol('test'))).to.be.false;

});
});
36 changes: 18 additions & 18 deletions test/tools/clean.js
Original file line number Diff line number Diff line change
@@ -12,22 +12,22 @@ export {
let testSuiteRunId = uuidv4();

// At the beginning of a run purge .tmp
function before (sh, tmpPath) {
cleanPath(sh, tmpPath);
// clean(sh, tmpPath, 'all');
function before (tmpPath) {
cleanPath(tmpPath);
// clean(tmpPath, 'all');
}

function afterEach (sh, tmpPath, preserve) {
function afterEach (tmpPath, preserve) {
if (preserve !== false) {
archive(sh, tmpPath, testSuiteRunId);
archive(tmpPath, testSuiteRunId);
}
cleanPath(sh, tmpPath);
cleanPath(tmpPath);
}

// After should listen to the user via the config
// Before should always purge .tmp irregardless of config
function after (sh, tmpPath, preserve) {
clean(sh, tmpPath, preserve);
function after (tmpPath, preserve) {
clean(tmpPath, preserve);
}

/**
@@ -36,18 +36,18 @@ function after (sh, tmpPath, preserve) {
*
* Generally should be run in afterEach()
*/
function archive (sh, tmpPath, testSuiteRunId) {
function archive (tmpPath, testSuiteRunId) {
let destinationPath = path.resolve(tmpPath + '/../artifacts/' + testSuiteRunId + '/' + uuidv4());
sh.mkdir('-p', destinationPath);
sh.cp('-Rf', tmpPath + '/*', destinationPath);
fs.mkdirSync(destinationPath, { recursive: true });
fs.copySync(tmpPath, destinationPath);
}

/**
* Cleans up the artifacts folder
*
* Generally called in after()
*/
function clean (sh, tmpPath, preserve) {
function clean (tmpPath, preserve) {

/**
* If preserve is a normal integer over 0 thats how many results to keep.
@@ -85,11 +85,11 @@ function clean (sh, tmpPath, preserve) {
});

// Keep only the number of files defined in the config setting 'preserve'.
keep(sh, artifactsBasePath, artifactFolders, preserve);
keep(artifactsBasePath, artifactFolders, preserve);
}

// Always purge tmp, it needs to be empty for next run
cleanPath(sh, tmpPath);
cleanPath(tmpPath);
}

function isNormalNonZeroInteger (str) {
@@ -108,14 +108,14 @@ function isNormalNonZeroInteger (str) {
*
* n is the (1 indexed) count of files to keep.
*/
function keep (sh, basePath, paths, n) {
function keep (basePath, paths, n) {

for (let i = paths.length; i > n; i--) {
fs.removeSync(path.resolve(basePath, paths[i - 1]));
}
}

function cleanPath (sh, tmpPath) {
sh.rm('-rf', tmpPath + '/*');
sh.mkdir(tmpPath);
function cleanPath (tmpPath) {
fs.removeSync(tmpPath);
fs.mkdirSync(tmpPath);
}
14 changes: 8 additions & 6 deletions test/tools/repo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import childProcess from 'child_process';
import fs from 'fs';

export {
createEmpty,
createEndUser
@@ -6,15 +9,14 @@ export {
/**
* Create an empty repo
*/
function createEmpty (sh, path) {
sh.mkdir(path);
sh.cd(path);
sh.exec('npm init --force --yes');
function createEmpty (path) {
fs.mkdirSync(path, { recursive: true });
childProcess.spawnSync('npm', ['init', '--force', '--yes'], { cwd: path, shell: true });
}

/**
* Create a new repo to hold an end user app
*/
function createEndUser (sh, path) {
createEmpty(sh, path);
function createEndUser (path) {
createEmpty(path);
}