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.
`);
}
diff --git a/src/cli/strategies/git-cz.js b/src/cli/strategies/git-cz.js
index 2eda9dde..059c5f33 100644
--- a/src/cli/strategies/git-cz.js
+++ b/src/cli/strategies/git-cz.js
@@ -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;
@@ -42,6 +41,7 @@ function gitCz (rawGitArgs, environment, adapterConfig) {
let resolvedAdapterConfigPath = resolveAdapterPath(adapterConfig.path);
let resolvedAdapterRootPath = findRoot(resolvedAdapterConfigPath);
let prompter = getPrompter(adapterConfig.path);
+ let shouldStageAllFiles = rawGitArgs.includes('-a') || rawGitArgs.includes('--all');
isClean(process.cwd(), function (error, stagingIsClean) {
if (error) {
@@ -56,7 +56,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,
@@ -68,6 +68,6 @@ function gitCz (rawGitArgs, environment, adapterConfig) {
throw error;
}
});
- });
+ }, shouldStageAllFiles);
}
diff --git a/src/cli/strategies/git.js b/src/cli/strategies/git.js
index fff0f167..e55f0b66 100644
--- a/src/cli/strategies/git.js
+++ b/src/cli/strategies/git.js
@@ -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);
diff --git a/src/commitizen.js b/src/commitizen.js
index 254ce4ba..018bd681 100644
--- a/src/commitizen.js
+++ b/src/commitizen.js
@@ -1,3 +1,4 @@
+/* istanbul ignore file */
import * as adapter from './commitizen/adapter';
import * as cache from './commitizen/cache';
import commit from './commitizen/commit';
diff --git a/src/commitizen/adapter.js b/src/commitizen/adapter.js
index 68789467..b3150c40 100644
--- a/src/commitizen/adapter.js
+++ b/src/commitizen/adapter.js
@@ -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';
@@ -11,12 +11,11 @@ export {
addPathToAdapterConfig,
getNearestNodeModulesDirectory,
getNearestProjectRootDirectory,
- getNpmInstallStringMappings,
+ getInstallStringMappings,
getPrompter,
- generateNpmInstallAdapterCommand,
+ generateInstallAdapterCommand,
resolveAdapterPath,
- getYarnAddStringMappings,
- generateYarnAddAdapterCommand,
+ getGitRootPath,
};
/**
@@ -32,7 +31,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 +41,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 || ' ';
@@ -54,40 +53,32 @@ function addPathToAdapterConfig (sh, cliPath, repoPath, adapterNpmName) {
fs.writeFileSync(packageJsonPath, JSON.stringify(newPackageJsonContent, null, indent) + '\n');
}
-/**
- * Generates an npm install command given a map of strings and a package name
+/*
+ * Get additional options for install command
*/
-function generateNpmInstallAdapterCommand (stringMappings, adapterNpmName) {
-
- // Start with an initial npm install command
- let installAdapterCommand = `npm install ${adapterNpmName}`;
+function getInstallOptions(stringMappings) {
+ return Array.from(stringMappings.values()).filter(Boolean).join(" ")
+}
- // Append the neccesary arguments to it based on user preferences
- for (let value of stringMappings.values()) {
- if (value) {
- installAdapterCommand = installAdapterCommand + ' ' + value;
- }
- }
+/*
+ * Get specific install command for passed package manager
+ */
+function getInstallCommand(packageManager) {
+ const fallbackCommand = 'install';
+ const commandByPackageManager = {
+ npm: 'install',
+ yarn: 'add',
+ pnpm: 'add',
+ };
- return installAdapterCommand;
+ return commandByPackageManager[packageManager] || fallbackCommand;
}
/**
- * Generates an yarn add command given a map of strings and a package name
+ * Generates an npm install command given a map of strings and a package name
*/
-function generateYarnAddAdapterCommand (stringMappings, adapterNpmName) {
-
- // Start with an initial yarn add command
- let installAdapterCommand = `yarn add ${adapterNpmName}`;
-
- // Append the necessary arguments to it based on user preferences
- for (let value of stringMappings.values()) {
- if (value) {
- installAdapterCommand = installAdapterCommand + ' ' + value;
- }
- }
-
- return installAdapterCommand;
+function generateInstallAdapterCommand(stringMappings, adapterNpmName, packageManager = "npm") {
+ return `${packageManager} ${getInstallCommand(packageManager)} ${adapterNpmName} ${getInstallOptions(stringMappings)}`;
}
/**
@@ -111,29 +102,33 @@ 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), '/../');
}
/**
- * Gets a map of arguments where the value is the corresponding npm strings
+ * Gets a map of arguments where the value is the corresponding (to passed package manager) string
*/
-function getNpmInstallStringMappings (save, saveDev, saveExact, force) {
- return new Map()
- .set('save', (save && !saveDev) ? '--save' : undefined)
+function getInstallStringMappings({ save, dev, saveDev, exact, saveExact, force }, packageManager) {
+ const npm = new Map()
+ .set('save', save && !saveDev ? '--save' : undefined)
.set('saveDev', saveDev ? '--save-dev' : undefined)
.set('saveExact', saveExact ? '--save-exact' : undefined)
.set('force', force ? '--force' : undefined);
-}
-/**
- * Gets a map of arguments where the value is the corresponding yarn strings
- */
-function getYarnAddStringMappings (dev, exact, force) {
- return new Map()
+ const yarn = new Map()
.set('dev', dev ? '--dev' : undefined)
.set('exact', exact ? '--exact' : undefined)
.set('force', force ? '--force' : undefined);
+
+ const pnpm = new Map()
+ .set('save', save && !saveDev ? '--save-prod' : undefined)
+ .set('dev', saveDev ? '--save-dev' : undefined)
+ .set('exact', saveExact ? '--save-exact' : undefined);
+
+ const map = { npm, yarn, pnpm };
+
+ return map[packageManager] || npm;
}
/**
@@ -180,5 +175,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();
}
diff --git a/src/commitizen/commit.js b/src/commitizen/commit.js
index 6dac0552..f57cc769 100644
--- a/src/commitizen/commit.js
+++ b/src/commitizen/commit.js
@@ -10,9 +10,9 @@ 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);
});
}
@@ -20,7 +20,7 @@ function dispatchGitCommit (sh, repoPath, template, options, overrideOptions, do
/**
* 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);
});
}
}
diff --git a/src/commitizen/init.js b/src/commitizen/init.js
index c7f8ecd2..f4769c9b 100644
--- a/src/commitizen/init.js
+++ b/src/commitizen/init.js
@@ -1,14 +1,12 @@
+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 {
addPathToAdapterConfig,
- generateNpmInstallAdapterCommand,
- getNpmInstallStringMappings,
- generateYarnAddAdapterCommand,
- getYarnAddStringMappings,
+ generateInstallAdapterCommand,
+ getInstallStringMappings,
} = adapter;
export default init;
@@ -43,12 +41,14 @@ const defaultInitOptions = {
yarn: false,
dev: true,
exact: false, // should add trailing comma, thus next developer doesn't got blamed for this line
+
+ pnpm: false, // reuses `save`, `saveDev`, `saveExact`
};
/**
* 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,
@@ -56,22 +56,25 @@ function init (sh, repoPath, adapterNpmName, {
yarn = false,
dev = false,
exact = false,
+ pnpm = false,
+ includeCommitizen = false
} = 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);
+
+ const packageManager = yarn ? 'yarn' : pnpm ? 'pnpm' : 'npm';
// Get the npm string mappings based on the arguments provided
- let stringMappings = yarn ? getYarnAddStringMappings(dev, exact, force) : getNpmInstallStringMappings(save, saveDev, saveExact, force);
+ const stringMappings = getInstallStringMappings({ save, dev, saveDev, saveExact, force }, packageManager);
// Generate a string that represents the npm install command
- let installAdapterCommand = yarn ? generateYarnAddAdapterCommand(stringMappings, adapterNpmName) : generateNpmInstallAdapterCommand(stringMappings, adapterNpmName);
+ const installAdapterCommand = generateInstallAdapterCommand(stringMappings, adapterNpmName, packageManager);
+
+ const installCommitizenCommand = generateInstallAdapterCommand(stringMappings, 'commitizen', packageManager);
// Check for previously installed adapters
if (adapterConfig && adapterConfig.path && adapterConfig.path.length > 0 && !force) {
@@ -85,8 +88,11 @@ function init (sh, repoPath, adapterNpmName, {
}
try {
- executeShellCommand(sh, repoPath, installAdapterCommand);
- addPathToAdapterConfig(sh, CLI_PATH, repoPath, adapterNpmName);
+ childProcess.execSync(installAdapterCommand, { cwd: repoPath });
+ if(includeCommitizen) {
+ childProcess.execSync(installCommitizenCommand, { cwd: repoPath });
+ }
+ addPathToAdapterConfig(CLI_PATH, repoPath, adapterNpmName);
} catch (e) {
console.error(e);
}
@@ -96,10 +102,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.");
}
@@ -112,8 +115,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 {
diff --git a/src/commitizen/staging.js b/src/commitizen/staging.js
index 70fc15b5..c8a81c29 100644
--- a/src/commitizen/staging.js
+++ b/src/commitizen/staging.js
@@ -5,10 +5,10 @@ export { isClean };
/**
* Asynchrounously determines if the staging area is clean
*/
-function isClean (repoPath, done) {
- exec('git diff --no-ext-diff --name-only && git diff --no-ext-diff --cached --name-only', {
+function isClean (repoPath, done, stageAllFiles) {
+ exec(`git diff --cached --no-ext-diff --name-only ${!!stageAllFiles ? '&& git diff --no-ext-diff --name-only' : ''}`, {
maxBuffer: Infinity,
- cwd: repoPath || process.cwd()
+ cwd: repoPath
}, function (error, stdout) {
if (error) {
return done(error);
diff --git a/src/common/util.js b/src/common/util.js
index db652bb0..a9e59e3f 100644
--- a/src/common/util.js
+++ b/src/common/util.js
@@ -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
*/
@@ -64,21 +38,8 @@ function isFunction (functionToCheck) {
return false;
} else {
var getType = {};
- return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
- }
-}
-
-/**
- * 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]';
+ var functionType = getType.toString.call(functionToCheck);
+ return functionToCheck && (functionType === '[object Function]' || functionType === '[object AsyncFunction]');
}
}
diff --git a/src/configLoader.js b/src/configLoader.js
index e11d5fe3..6582d12f 100644
--- a/src/configLoader.js
+++ b/src/configLoader.js
@@ -1,3 +1,4 @@
+/* istanbul ignore file */
import findup from './configLoader/findup';
import getContent from './configLoader/getContent';
import getNormalizedConfig from './configLoader/getNormalizedConfig';
diff --git a/src/git.js b/src/git.js
index 3cd49b50..5cd350e9 100644
--- a/src/git.js
+++ b/src/git.js
@@ -1,3 +1,4 @@
+/* istanbul ignore file */
import { addPath, addFile } from './git/add';
import { commit } from './git/commit';
import { init } from './git/init';
diff --git a/src/git/add.js b/src/git/add.js
index 09ce9c37..4aad8750 100644
--- a/src/git/add.js
+++ b/src/git/add.js
@@ -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 });
}
diff --git a/src/git/commit.js b/src/git/commit.js
index 71d6eeb4..14051b96 100644
--- a/src/git/commit.js
+++ b/src/git/commit.js
@@ -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 {
diff --git a/src/git/init.js b/src/git/init.js
index 43b4c1fe..754eb22a 100644
--- a/src/git/init.js
+++ b/src/git/init.js
@@ -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 });
}
diff --git a/test/config.js b/test/config.js
index d46c69f2..efb6da47 100644
--- a/test/config.js
+++ b/test/config.js
@@ -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.
diff --git a/test/mochareporters.json b/test/mochareporters.json
new file mode 100644
index 00000000..c30f45e3
--- /dev/null
+++ b/test/mochareporters.json
@@ -0,0 +1,8 @@
+{
+ "reporterEnabled": "spec, mocha-junit-reporter",
+ "mochaJunitReporterReporterOptions": {
+ "mochaFile": "../../junit-testresults.xml",
+ "includePending": true,
+ "outputs": true
+ }
+}
\ No newline at end of file
diff --git a/test/tester.js b/test/tester.js
index e8f50a3f..8e99f768 100644
--- a/test/tester.js
+++ b/test/tester.js
@@ -3,7 +3,6 @@ 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
@@ -11,13 +10,9 @@ 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,
diff --git a/test/tests/adapter.js b/test/tests/adapter.js
index c716a532..2147f69c 100644
--- a/test/tests/adapter.js
+++ b/test/tests/adapter.js
@@ -1,6 +1,3 @@
-/* eslint-env mocha */
-/* eslint-disable no-unused-expressions */
-
import { expect } from 'chai';
import path from 'path';
@@ -15,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 () {
@@ -57,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);
@@ -98,7 +95,7 @@ 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);
@@ -106,7 +103,7 @@ describe('adapter', function () {
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
@@ -134,7 +131,7 @@ describe('adapter', function () {
};
// Install an adapter
- commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog');
+ commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', {includeCommitizen: true});
// TEST
expect(function () { adapter.getPrompter('IAMANIMPOSSIBLEPATH'); }).to.throw(Error);
@@ -170,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);
@@ -183,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);
});
diff --git a/test/tests/cli.js b/test/tests/cli.js
index 5fa8267b..244a39d5 100644
--- a/test/tests/cli.js
+++ b/test/tests/cli.js
@@ -1,5 +1,3 @@
-/* eslint-env mocha */
-
import { expect } from 'chai';
import proxyquire from 'proxyquire';
import sinon from 'sinon';
diff --git a/test/tests/commit.js b/test/tests/commit.js
index e69a94b7..8048d657 100644
--- a/test/tests/commit.js
+++ b/test/tests/commit.js
@@ -1,5 +1,3 @@
-/* eslint-env mocha */
-
import { expect } from 'chai';
import os from 'os';
import fs from 'fs';
@@ -15,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 () {
@@ -61,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();
@@ -105,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();
@@ -154,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();
@@ -203,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);
@@ -257,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);
});
@@ -299,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();
@@ -313,28 +311,95 @@ ${(os.platform === 'win32') ? '' : ' '}
done();
});
});
+
+ it('should throw error if staging area is empty', function (done) {
+
+ this.timeout(config.maxTimeout); // this could take a while
+
+ // SETUP
+
+ let dummyCommitMessage = `one does not simply ignore the tests`;
+
+ // Describe a repo and some files to add and commit
+ let repoConfig = {
+ path: config.paths.endUserRepo,
+ files: {
+ dummyfile: {
+ contents: `duck-duck-gray-duck`,
+ filename: `mydummiestfile.txt`,
+ },
+ gitignore: {
+ contents: `node_modules/`,
+ filename: `.gitignore`,
+ }
+ }
+ };
+
+ // Describe an adapter
+ let adapterConfig = {
+ path: path.join(repoConfig.path, '/node_modules/cz-jira-smart-commit'),
+ npmName: 'cz-jira-smart-commit'
+ };
+
+ // Quick setup the repos, adapter, and grab a simple prompter
+ let prompter = quickPrompterSetup(repoConfig, adapterConfig, dummyCommitMessage);
+ // TEST
+
+ // Make an initial commit
+ commitizenCommit(inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function (error) {
+ // Should pass, as the files are added to the staging area
+ expect(error).to.be.null;
+
+ log(repoConfig.path, function (logOutput) {
+ expect(logOutput).to.have.string(dummyCommitMessage);
+ });
+ whatChanged(repoConfig.path, function (whatChangedOutput) {
+ expect(whatChangedOutput).to.have.string('A\t' + repoConfig.files.dummyfile.filename);
+
+ // Make changes and don't add them to the staging area
+ writeFilesToPath({
+ dummymodified: {
+ contents: repoConfig.files.dummyfile.contents + '-modified',
+ filename: repoConfig.files.dummyfile.filename,
+ add: false,
+ }
+ }, repoConfig.path);
+ // Define a dummy prompter
+ let prompter = function (cz, commit) {
+ commit(`${dummyCommitMessage} #2`, {});
+ };
+
+ commitizenCommit(inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function (error) {
+ // Should fail, as staging are is empty
+ expect(error).to.be.instanceOf(Error);
+ done();
+ });
+ });
+ });
+
+ });
});
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,
@@ -344,14 +409,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);
}
}
diff --git a/test/tests/configLoader.js b/test/tests/configLoader.js
index df8892b2..b4a320c8 100644
--- a/test/tests/configLoader.js
+++ b/test/tests/configLoader.js
@@ -1,5 +1,3 @@
-/* eslint-env mocha */
-
import path from 'path';
import { expect } from 'chai';
import { getContent, getNormalizedConfig } from '../../src/configLoader';
diff --git a/test/tests/init.js b/test/tests/init.js
index 1e7269f9..454016bb 100644
--- a/test/tests/init.js
+++ b/test/tests/init.js
@@ -1,5 +1,3 @@
-/* eslint-env mocha */
-
import { expect } from 'chai';
import semver from 'semver';
@@ -12,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 () {
@@ -33,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
@@ -50,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
@@ -67,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
@@ -92,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);
@@ -115,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
@@ -141,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
@@ -157,135 +150,163 @@ describe('init', function () {
});
- it('installs an adapter with --yarn', function () {
+ it('installs an commitizen with includeCommitizen', function () {
this.timeout(config.maxTimeout); // this could take a while
// SETUP
- // Install an adapter
- commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true });
-
- // TEST
-
- // Check resulting json
+ // Add a first adapter
+ commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { includeCommitizen: true });
let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
- expect(packageJson).to.have.nested.property('dependencies.cz-conventional-changelog');
-
- });
-
- it('installs an adapter with --yarn --dev', function () {
-
- this.timeout(config.maxTimeout); // this could take a while
-
- // SETUP
-
- // Install an adapter
- commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });
// TEST
+ expect(packageJson.devDependencies).to.have.property('cz-conventional-changelog');
+ expect(packageJson.devDependencies).to.have.property('commitizen');
+ let range = packageJson.devDependencies['cz-conventional-changelog'];
- // Check resulting json
- let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
- expect(packageJson).to.have.nested.property('devDependencies.cz-conventional-changelog');
-
- });
+ // It should satisfy the requirements of a range
+ expect(semver.validRange(range)).to.not.equal(null);
- it('errors (with --yarn) on previously installed adapter', function () {
+ // But you CAN increment a single version
+ expect(semver.inc(range, 'major')).not.to.equal(null);
- this.timeout(config.maxTimeout); // this could take a while
+ });
- // SETUP
+ const supportedPackageManagers = ['yarn', 'pnpm'];
- // Add a first adapter
- sh.cd(config.paths.endUserRepo);
- commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });
+ supportedPackageManagers.forEach((packageManger) => {
+ describe(`alternative package managers: ${packageManger}`, () => {
+ it(`installs an adapter with ${packageManger}`, function () {
+ this.timeout(config.maxTimeout); // this could take a while
- // 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 });
- }).to.throw(/already configured/);
+ // SETUP
- // Check resulting json
- let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
- expect(packageJson).not.to.have.nested.property('devDependencies', 'cz-jira-smart-commit');
- expect(packageJson).to.have.nested.property('config.commitizen.path', './node_modules/cz-conventional-changelog');
- // TODO: Eventually may need to offer both path and package keys. package = npm package name
- // Path for local development
- });
+ // Install an adapter
+ commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { [packageManger]: true });
- it('succeeds (with --yarn) if force is true', function () {
+ // TEST
- this.timeout(config.maxTimeout); // this could take a while
+ // Check resulting json
+ let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
+ if (packageManger === 'yarn') {
+ expect(packageJson).to.have.nested.property('dependencies.cz-conventional-changelog');
+ } else {
+ expect(packageJson).to.have.nested.property('devDependencies.cz-conventional-changelog');
+ }
+ });
- // SETUP
+ it(`installs an adapter with ${packageManger} --dev`, function () {
+ this.timeout(config.maxTimeout); // this could take a while
- // Add a first adapter
- sh.cd(config.paths.endUserRepo);
- commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });
+ // SETUP
- // TEST
+ // Install an adapter
+ commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { [packageManger]: true, dev: true });
- // Adding a second adapter
- expect(function () {
- commitizenInit(sh, config.paths.endUserRepo, 'cz-jira-smart-commit', { yarn: true, dev: true, force: true });
- }).to.not.throw();
+ // TEST
- let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
- expect(packageJson.devDependencies).to.have.property('cz-jira-smart-commit');
- expect(packageJson).to.have.nested.property('config.commitizen.path', './node_modules/cz-jira-smart-commit');
+ // Check resulting json
+ let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
+ expect(packageJson).to.have.nested.property('devDependencies.cz-conventional-changelog');
+ });
- });
+ it(`errors (with ${packageManger}) on previously installed adapter`, function () {
+ this.timeout(config.maxTimeout); // this could take a while
- it('installs (with --yarn) an adapter without --save-exact', function () {
+ // SETUP
- this.timeout(config.maxTimeout); // this could take a while
+ // Add a first adapter
+ commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { [packageManger]: true, dev: true });
- // SETUP
+ // TEST
+ // Adding a second adapter
+ expect(function () {
+ commitizenInit(config.paths.endUserRepo, 'cz-jira-smart-commit', { [packageManger]: true, dev: true });
+ }).to.throw(/already configured/);
- // Add a first adapter
- sh.cd(config.paths.endUserRepo);
- commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true });
- let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
+ // Check resulting json
+ let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
+ expect(packageJson).not.to.have.nested.property('devDependencies', 'cz-jira-smart-commit');
+ expect(packageJson).to.have.nested.property(
+ 'config.commitizen.path',
+ './node_modules/cz-conventional-changelog'
+ );
+ // TODO: Eventually may need to offer both path and package keys. package = npm package name
+ // Path for local development
+ });
- // TEST
- expect(packageJson.devDependencies).to.have.property('cz-conventional-changelog');
- let range = packageJson.devDependencies['cz-conventional-changelog'];
+ it(`succeeds (with ${packageManger}) if force is true`, function () {
+ this.timeout(config.maxTimeout); // this could take a while
- // It should satisfy the requirements of a range
- expect(semver.validRange(range)).to.not.equal(null);
+ // SETUP
- // // But you CAN NOT increment a range
- // expect(semver.inc(range, 'major')).to.equal(null);
- // TODO: We need to figure out how to check if the repo has save exact set
- // in the config before we can re-enable this. The --save-exact setting
- // in our package.json breaks this test
+ // Add a first adapter
+ commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { [packageManger]: true, dev: true });
- });
+ // TEST
- it('installs an adapter with --yarn --exact', function () {
+ // Adding a second adapter
+ expect(function () {
+ commitizenInit(config.paths.endUserRepo, 'cz-jira-smart-commit', {
+ [packageManger]: true,
+ dev: true,
+ force: true,
+ });
+ }).to.not.throw();
- this.timeout(config.maxTimeout); // this could take a while
+ let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
+ expect(packageJson.devDependencies).to.have.property('cz-jira-smart-commit');
+ expect(packageJson).to.have.nested.property('config.commitizen.path', './node_modules/cz-jira-smart-commit');
+ });
- // SETUP
+ it(`installs (with ${packageManger}) an adapter without --save-exact`, function () {
+ this.timeout(config.maxTimeout); // this could take a while
- // Add a first adapter
- sh.cd(config.paths.endUserRepo);
- commitizenInit(sh, config.paths.endUserRepo, 'cz-conventional-changelog', { yarn: true, dev: true, exact: true });
- let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
+ // SETUP
- // TEST
- expect(packageJson.devDependencies).to.have.property('cz-conventional-changelog');
- let range = packageJson.devDependencies['cz-conventional-changelog'];
+ // Add a first adapter
+ commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', { [packageManger]: true, dev: true });
+ let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
- // It should satisfy the requirements of a range
- expect(semver.validRange(range)).to.not.equal(null);
+ // TEST
+ expect(packageJson.devDependencies).to.have.property('cz-conventional-changelog');
+ let range = packageJson.devDependencies['cz-conventional-changelog'];
- // But you CAN increment a single version
- expect(semver.inc(range, 'major')).not.to.equal(null);
+ // It should satisfy the requirements of a range
+ expect(semver.validRange(range)).to.not.equal(null);
+
+ // // But you CAN NOT increment a range
+ // expect(semver.inc(range, 'major')).to.equal(null);
+ // TODO: We need to figure out how to check if the repo has save exact set
+ // in the config before we can re-enable this. The --save-exact setting
+ // in our package.json breaks this test
+ });
+
+ it(`installs an adapter with ${packageManger} --exact`, function () {
+ this.timeout(config.maxTimeout); // this could take a while
+
+ // SETUP
+
+ // Add a first adapter
+ commitizenInit(config.paths.endUserRepo, 'cz-conventional-changelog', {
+ [packageManger]: true,
+ dev: true,
+ exact: true,
+ });
+ let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo);
+ // TEST
+ expect(packageJson.devDependencies).to.have.property('cz-conventional-changelog');
+ let range = packageJson.devDependencies['cz-conventional-changelog'];
+
+ // It should satisfy the requirements of a range
+ expect(semver.validRange(range)).to.not.equal(null);
+
+ // But you CAN increment a single version
+ expect(semver.inc(range, 'major')).not.to.equal(null);
+ });
+ });
});
});
@@ -293,12 +314,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);
});
diff --git a/test/tests/parsers.js b/test/tests/parsers.js
index 31da04d5..2fc2be31 100644
--- a/test/tests/parsers.js
+++ b/test/tests/parsers.js
@@ -1,5 +1,3 @@
-/* eslint-env mocha */
-
import { expect } from 'chai';
import { gitCz as gitCzParser, commitizen as commitizenParser } from '../../src/cli/parsers';
diff --git a/test/tests/staging.js b/test/tests/staging.js
index 6bdef21b..2ff77256 100644
--- a/test/tests/staging.js
+++ b/test/tests/staging.js
@@ -1,6 +1,3 @@
-/* eslint-env mocha */
-/* eslint-disable no-unused-expressions */
-
import { expect } from 'chai';
// Bootstrap our tester
@@ -11,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 () {
@@ -47,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);
@@ -58,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;
@@ -81,17 +78,54 @@ describe('staging', function () {
});
});
+ it('should determine if --all flag adds files to staging area', function (done) {
+
+ this.timeout(config.maxTimeout); // this could take a while
+
+ // SETUP
+
+ // Describe a repo and some files to add and commit
+ let repoConfig = {
+ path: config.paths.endUserRepo,
+ files: {
+ dummyfile: {
+ contents: `duck-duck-gray-duck`,
+ filename: `mydummiestfile.txt`,
+ },
+ gitignore: {
+ contents: `node_modules/`,
+ filename: `.gitignore`
+ }
+ }
+ };
+
+ gitInit(repoConfig.path);
+
+ staging.isClean(repoConfig.path, function (stagingIsCleanError, stagingIsClean) {
+ expect(stagingIsCleanError).to.be.null;
+ expect(stagingIsClean).to.be.true;
+
+ writeFilesToPath(repoConfig.files, repoConfig.path);
+
+ staging.isClean(repoConfig.path, function (afterWriteStagingIsCleanError, afterWriteStagingIsClean) {
+ expect(afterWriteStagingIsCleanError).to.be.null;
+ expect(afterWriteStagingIsClean).to.be.true;
+
+ done();
+ });
+ }, true);
+ });
});
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);
});
diff --git a/test/tests/util.js b/test/tests/util.js
index 5af675c3..f2368e94 100644
--- a/test/tests/util.js
+++ b/test/tests/util.js
@@ -1,39 +1,12 @@
-/* eslint-env mocha */
-/* eslint-disable no-unused-expressions */
-
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;
- // eslint-disable-next-line no-sparse-arrays
- expect(isArray([1, , 3])).to.be.true;
- // eslint-disable-next-line no-array-constructor
- 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
expect(isFunction(function () {})).to.be.true;
- // eslint-disable-next-line no-new-func
expect(isFunction(new Function())).to.be.true;
// Falsies
@@ -49,29 +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;
- // eslint-disable-next-line no-new-wrappers
- 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;
-
- });
});
diff --git a/test/tools/clean.js b/test/tools/clean.js
index f8bef3db..47476161 100644
--- a/test/tools/clean.js
+++ b/test/tools/clean.js
@@ -1,6 +1,6 @@
import * as path from 'path';
import fs from 'fs-extra';
-import uuid from 'node-uuid';
+import { v4 as uuidv4} from 'uuid';
export {
before,
@@ -9,25 +9,25 @@ export {
};
// Unique id for each 'run' of the entire test suite
-let testSuiteRunId = uuid.v4();
+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,10 +36,10 @@ function after (sh, tmpPath, preserve) {
*
* Generally should be run in afterEach()
*/
-function archive (sh, tmpPath, testSuiteRunId) {
- let destinationPath = path.resolve(tmpPath + '/../artifacts/' + testSuiteRunId + '/' + uuid.v4());
- sh.mkdir('-p', destinationPath);
- sh.cp('-Rf', tmpPath + '/*', destinationPath);
+function archive (tmpPath, testSuiteRunId) {
+ let destinationPath = path.resolve(tmpPath + '/../artifacts/' + testSuiteRunId + '/' + uuidv4());
+ fs.mkdirSync(destinationPath, { recursive: true });
+ fs.copySync(tmpPath, destinationPath);
}
/**
@@ -47,7 +47,7 @@ function archive (sh, tmpPath, testSuiteRunId) {
*
* 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);
}
diff --git a/test/tools/repo.js b/test/tools/repo.js
index 88ab2e8f..2357f3a7 100644
--- a/test/tools/repo.js
+++ b/test/tools/repo.js
@@ -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);
}
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy