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
/**

test/tests/init.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import { init as commitizenInit } from '../../src/commitizen';
1010
import { bootstrap } from '../tester';
1111

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

1515
before(function () {
1616
// Creates the temp path
17-
clean.before(sh, config.paths.tmp);
17+
clean.before(config.paths.tmp);
1818
});
1919

2020
beforeEach(function () {
2121
this.timeout(config.maxTimeout); // this could take a while
22-
repo.createEndUser(sh, config.paths.endUserRepo);
22+
repo.createEndUser(config.paths.endUserRepo);
2323
});
2424

2525
describe('init', function () {
@@ -65,11 +65,9 @@ describe('init', function () {
6565
// SETUP
6666

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

7170
// TEST
72-
sh.cd(config.paths.endUserRepo);
7371
// Adding a second adapter
7472
expect(function () {
7573
commitizenInit(config.paths.endUserRepo, 'cz-jira-smart-commit', { saveDev: true });
@@ -90,7 +88,6 @@ describe('init', function () {
9088
// SETUP
9189

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

9693
// TEST
@@ -113,7 +110,6 @@ describe('init', function () {
113110
// SETUP
114111

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

@@ -139,7 +135,6 @@ describe('init', function () {
139135
// SETUP
140136

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

@@ -162,7 +157,6 @@ describe('init', function () {
162157
// SETUP
163158

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

@@ -220,11 +214,9 @@ describe('init', function () {
220214
// SETUP
221215

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

226219
// TEST
227-
sh.cd(config.paths.endUserRepo);
228220
// Adding a second adapter
229221
expect(function () {
230222
commitizenInit(config.paths.endUserRepo, 'cz-jira-smart-commit', { yarn: true, dev: true });
@@ -245,7 +237,6 @@ describe('init', function () {
245237
// SETUP
246238

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

251242
// TEST
@@ -268,7 +259,6 @@ describe('init', function () {
268259
// SETUP
269260

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

@@ -294,7 +284,6 @@ describe('init', function () {
294284
// SETUP
295285

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

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

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

test/tests/staging.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import { init as gitInit, addPath as gitAdd } from '../../src/git';
88
import { staging } from '../../src/commitizen';
99

1010
// Destructure some things for cleaner tests
11-
let { config, sh, repo, clean, files } = bootstrap();
11+
let { config, repo, clean, files } = bootstrap();
1212
let { writeFilesToPath } = files;
1313

1414
before(function () {
1515
// Creates the temp path
16-
clean.before(sh, config.paths.tmp);
16+
clean.before(config.paths.tmp);
1717
});
1818

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

2424
describe('staging', function () {
@@ -83,12 +83,12 @@ describe('staging', function () {
8383
afterEach(function () {
8484
this.timeout(config.maxTimeout); // this could take a while
8585
// All this should do is archive the tmp path to the artifacts
86-
clean.afterEach(sh, config.paths.tmp, config.preserve);
86+
clean.afterEach(config.paths.tmp, config.preserve);
8787
});
8888

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

0 commit comments

Comments
 (0)