Skip to content

Commit 88aa26f

Browse files
committed
refactor: remove shelljs from tests
1 parent c7af218 commit 88aa26f

File tree

14 files changed

+56
-103
lines changed

14 files changed

+56
-103
lines changed

package-lock.json

Lines changed: 0 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"proxyquire": "^2.1.0",
6969
"semantic-release": "15.13.18",
7070
"semver": "6.2.0",
71-
"shelljs": "0.7.6",
7271
"sinon": "^6.3.4",
7372
"uuid": "3.3.2"
7473
},

src/commitizen/adapter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function addPathToAdapterConfig (cliPath, repoPath, adapterNpmName) {
4242
}
4343
};
4444

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

118118
/**

src/commitizen/init.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function init (repoPath, adapterNpmName, {
6363
checkRequiredArguments(repoPath, adapterNpmName);
6464

6565
// Load the current adapter config
66-
let adapterConfig = loadAdapterConfig();
66+
let adapterConfig = loadAdapterConfig(repoPath);
6767

6868
// Get the npm string mappings based on the arguments provided
6969
let stringMappings = yarn ? getYarnAddStringMappings(dev, exact, force) : getNpmInstallStringMappings(save, saveDev, saveExact, force);
@@ -112,8 +112,8 @@ function checkRequiredArguments (path, adapterNpmName) {
112112
* CONFIG
113113
* Loads and returns the adapter config at key config.commitizen, if it exists
114114
*/
115-
function loadAdapterConfig () {
116-
let config = configLoader.load();
115+
function loadAdapterConfig (cwd) {
116+
let config = configLoader.load(null, cwd);
117117
if (config) {
118118
return config;
119119
} else {

src/commitizen/staging.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export { isClean };
88
function isClean (repoPath, done) {
99
exec('git diff --no-ext-diff --name-only && git diff --no-ext-diff --cached --name-only', {
1010
maxBuffer: Infinity,
11-
cwd: repoPath || process.cwd()
11+
cwd: repoPath
1212
}, function (error, stdout) {
1313
if (error) {
1414
return done(error);

src/configLoader/loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export default loader;
1414
/**
1515
* Get content of the configuration file
1616
* @param {String} config - partial path to configuration file
17-
* @param {String} [cwd = process.cwd()] - directory path which will be joined with config argument
17+
* @param {String} cwd - directory path which will be joined with config argument
1818
* @return {Object|undefined}
1919
*/
2020
function loader (configs, config, cwd) {
2121
var content;
22-
var directory = cwd || process.cwd();
22+
var directory = cwd;
2323

2424
// If config option is given, attempt to load it
2525
if (config) {

test/config.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ let config = {
3333
*/
3434
maxTimeout: 240000,
3535

36-
/**
37-
* Whether shelljs should suppress output, should be true
38-
* unless debugging.
39-
*/
40-
silent: true,
41-
4236
/**
4337
* Whether or not to keep the artifacts of the tests after
4438
* they've run.

test/tester.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@ import * as clean from './tools/clean';
33
import * as files from './tools/files';
44
import * as util from '../src/common/util';
55
import { config as userConfig } from './config';
6-
import * as sh from 'shelljs'; // local instance
76
import _ from 'lodash';
87

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

1211
function bootstrap () {
1312

14-
// Patch any shelljs specific config settings
15-
sh.config.silent = patchedConfig.silent || true;
16-
17-
// Return the patched config and shelljs instance
13+
// Return the patched config
1814
return {
1915
config: patchedConfig,
20-
sh,
2116
repo,
2217
clean,
2318
util,

test/tests/adapter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import { isFunction } from '../../src/common/util';
1212
import { bootstrap } from '../tester';
1313

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

1717
before(function () {
1818
// Creates the temp path
19-
clean.before(sh, config.paths.tmp);
19+
clean.before(config.paths.tmp);
2020
});
2121

2222
beforeEach(function () {
2323
this.timeout(config.maxTimeout); // this could take a while
24-
repo.createEndUser(sh, config.paths.endUserRepo);
24+
repo.createEndUser(config.paths.endUserRepo);
2525
});
2626

2727
describe('adapter', function () {
@@ -180,12 +180,12 @@ describe('adapter', function () {
180180
afterEach(function () {
181181
this.timeout(config.maxTimeout); // this could take a while
182182
// All this should do is archive the tmp path to the artifacts
183-
clean.afterEach(sh, config.paths.tmp, config.preserve);
183+
clean.afterEach(config.paths.tmp, config.preserve);
184184
});
185185

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

test/tests/commit.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ import { addFile as gitAddFile, init as gitInit, log, whatChanged } from '../../
1313
import { commit as commitizenCommit, init as commitizenInit } from '../../src/commitizen';
1414

1515
// Destructure some things for cleaner tests
16-
let { config, sh, repo, clean, files } = bootstrap();
16+
let { config, repo, clean, files } = bootstrap();
1717
let { writeFilesToPath } = files;
1818

1919
before(function () {
2020
// Creates the temp path
21-
clean.before(sh, config.paths.tmp);
21+
clean.before(config.paths.tmp);
2222
});
2323

2424
beforeEach(function () {
2525
this.timeout(config.maxTimeout); // this could take a while
2626
/* istanbul ignore next */
27-
repo.createEndUser(sh, config.paths.endUserRepo);
27+
repo.createEndUser(config.paths.endUserRepo);
2828
});
2929

3030
describe('commit', function () {
@@ -316,14 +316,14 @@ ${(os.platform === 'win32') ? '' : ' '}
316316
afterEach(function () {
317317
this.timeout(config.maxTimeout); // this could take a while
318318
// All this should do is archive the tmp path to the artifacts
319-
clean.afterEach(sh, config.paths.tmp, config.preserve);
319+
clean.afterEach(config.paths.tmp, config.preserve);
320320
});
321321

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

329329
/**

0 commit comments

Comments
 (0)