Skip to content

Commit d7ed622

Browse files
Split the mocks into separate files for initial setup and testing
1 parent 902bc4b commit d7ed622

5 files changed

Lines changed: 37 additions & 34 deletions

File tree

.mocharc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# https://github.com/mochajs/mocha/blob/master/example/config/.mocharc.yml
44

55
spec:
6+
- test/fixtures/setup-mocks.js
67
- test/fixtures/mocha-hooks.js
78
- test/specs/**/*.spec.js
89

test/fixtures/mocks/git

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env node
2-
'use strict';
2+
"use strict";
33

44
/**
55
*
@@ -8,5 +8,5 @@
88
*
99
*/
1010

11-
const mocks = require('./index');
12-
mocks.record('git', process.argv.slice(2));
11+
const mocks = require("../../utils/mocks");
12+
mocks.record("git", process.argv.slice(2));

test/fixtures/mocks/npm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env node
2-
'use strict';
2+
"use strict";
33

44
/**
55
*
@@ -8,5 +8,5 @@
88
*
99
*/
1010

11-
const mocks = require('./index');
12-
mocks.record('npm', process.argv.slice(2));
11+
const mocks = require("../../utils/mocks");
12+
mocks.record("npm", process.argv.slice(2));

test/fixtures/setup-mocks.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
const mocksDir = path.resolve("test", "fixtures", "mocks");
7+
8+
// Ensure that the mock binaries are executable
9+
fs.chmodSync(path.join(mocksDir, "git"), "0777");
10+
fs.chmodSync(path.join(mocksDir, "npm"), "0777");
11+
12+
// Inject our mocks directory path into the PATH variable,
13+
// so that version-bump-prompt runs our mock `git` and `npm` binaries
14+
// instead of the real ones.
15+
let otherPaths = getEnvPath();
16+
process.env.PATH = mocksDir + path.delimiter + otherPaths; // eslint-disable-line no-path-concat
17+
18+
19+
/**
20+
* Returns the PATH environment variable, case-insensitively
21+
*/
22+
function getEnvPath () {
23+
let keys = Object.keys(process.env);
24+
25+
for (let key of keys) {
26+
if (key.toUpperCase() === "PATH") {
27+
return process.env[key];
28+
}
29+
}
30+
}

test/utils/mocks.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
"use strict";
22

3-
const fs = require("fs");
4-
const path = require("path");
53
const files = require("./files");
64

7-
const mocksDir = path.resolve("test", "fixtures", "mocks");
8-
9-
// Ensure that the mock binaries are executable
10-
fs.chmodSync(path.join(mocksDir, "git"), "0777");
11-
fs.chmodSync(path.join(mocksDir, "npm"), "0777");
12-
13-
// Inject our mocks directory path into the PATH variable,
14-
// so that version-bump-prompt runs our mock `git` and `npm` binaries
15-
// instead of the real ones.
16-
let otherPaths = getEnvPath();
17-
process.env.PATH = mocksDir + path.delimiter + otherPaths; // eslint-disable-line no-path-concat
18-
195
const mocks = module.exports = {
206
/**
217
* Returns information about each time `git` was executed.
@@ -70,20 +56,6 @@ const mocks = module.exports = {
7056
},
7157
};
7258

73-
74-
/**
75-
* Returns the PATH environment variable, case-insensitively
76-
*/
77-
function getEnvPath () {
78-
let keys = Object.keys(process.env);
79-
80-
for (let key of keys) {
81-
if (key.toUpperCase() === "PATH") {
82-
return process.env[key];
83-
}
84-
}
85-
}
86-
8759
/**
8860
* Adds quotes around an argument if it contains whitespace characters
8961
*

0 commit comments

Comments
 (0)