Skip to content

Commit 038d2cf

Browse files
Separated "fixtures" and "files"
1 parent a6fa150 commit 038d2cf

4 files changed

Lines changed: 78 additions & 30 deletions

File tree

test/specs/files.spec.js

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
"use strict";
22

3-
const { check, files } = require("../utils");
3+
const { check, files, fixtures } = require("../utils");
44
const { chaiExec, expect } = require("../utils/chai");
55

66
describe.skip("bump [files...]", () => {
77

88
it("should replace the version number in non-manifest files", () => {
99
files.create("package.json", { version: "1.2.3" });
10-
files.copy("LICENSE");
11-
files.copy("README.md");
12-
files.copy("script1.js");
13-
files.copy("script2.js");
10+
files.create("LICENSE", fixtures.license);
11+
files.create("README.md", fixtures.readme);
12+
files.create("script1.js", fixtures.script1);
13+
files.create("script2.js", fixtures.script2);
14+
files.create("subdir/deep/script1.js", fixtures.script1);
15+
files.create("subdir/deep/script2.js", fixtures.script2);
1416

15-
let bump = chaiExec("--major --grep LICENSE README.* *.js");
17+
let bump = chaiExec("major LICENSE README.* *.js");
1618

1719
expect(bump).to.have.stderr("");
1820
expect(bump).to.have.exitCode(0);
1921

2022
bump.should.have.stdout(
21-
`${check} Updated package.json to 2.0.0\n` +
23+
`${check} Updated LICENSE to 2.0.0\n` +
2224
`${check} Updated README.md to 2.0.0\n` +
23-
`${check} Updated script1.js to 2.0.0\n` +
24-
`${check} Updated LICENSE to 2.0.0\n`
25+
`${check} Updated script1.js to 2.0.0\n`
2526
);
2627

2728
expect(files.json("package.json").version).to.equal("2.0.0");
@@ -34,12 +35,12 @@ describe.skip("bump [files...]", () => {
3435

3536
it("should not replace other version numbers in non-manifest files", () => {
3637
files.create("package.json", { version: "1.2.3" });
37-
files.copy("LICENSE");
38-
files.copy("README.md");
39-
files.copy("script1.js");
40-
files.copy("script2.js");
38+
files.create("LICENSE", fixtures.license);
39+
files.create("README.md", fixtures.readme);
40+
files.create("script1.js", fixtures.script1);
41+
files.create("script2.js", fixtures.script2);
4142

42-
let bump = chaiExec("--major --grep LICENSE README.* *.js");
43+
let bump = chaiExec("major LICENSE README.* *.js");
4344

4445
expect(bump).to.have.stderr("");
4546
expect(bump).to.have.exitCode(0);
@@ -57,12 +58,56 @@ describe.skip("bump [files...]", () => {
5758

5859
it("should not not modify non-manifest files that don't contain the old version number", () => {
5960
files.create("package.json", { version: "4.5.6" });
60-
files.copy("LICENSE");
61-
files.copy("README.md");
62-
files.copy("script1.js");
63-
files.copy("script2.js");
61+
files.create("LICENSE", fixtures.license);
62+
files.create("README.md", fixtures.readme);
63+
files.create("script1.js", fixtures.script1);
64+
files.create("script2.js", fixtures.script2);
65+
66+
let bump = chaiExec("major LICENSE README.* *.js");
67+
68+
expect(bump).to.have.stderr("");
69+
expect(bump).to.have.exitCode(0);
70+
71+
bump.should.have.stdout(
72+
`${check} Updated package.json to 5.0.0\n`
73+
);
74+
75+
expect(files.json("package.json").version).to.equal("5.0.0");
76+
expect(files.text("LICENSE")).to.match(/MyApp v1.2.3 Copyright/);
77+
expect(files.text("README.md")).to.match(/version 5.6.7 and v8.9.10 should not be changed/);
78+
expect(files.text("README.md")).to.match(/version 1.2.3 and v1.2.3 should both get updated/);
79+
expect(files.text("script1.js")).to.match(/make sure v1.2.3 gets replaced correctly/);
80+
expect(files.text("script1.js")).to.match(/let version = "1.2.3";/);
81+
expect(files.text("script1.js")).to.match(/let version = "1.2.3";/);
82+
expect(files.text("script2.js")).to.match(/version 3.2.1 and v8.9.10 don't match the old version number/);
83+
});
84+
85+
it("should error if an explicitly-specified file doesn't exist", () => {
86+
files.create("package.json", { version: "4.5.6" });
87+
88+
let bump = chaiExec("major LICENSE README.* *.js");
89+
90+
expect(bump).to.have.stderr("");
91+
expect(bump).to.have.exitCode(0);
92+
93+
bump.should.have.stdout(
94+
`${check} Updated package.json to 5.0.0\n`
95+
);
96+
97+
expect(files.json("package.json").version).to.equal("5.0.0");
98+
expect(files.text("LICENSE")).to.match(/MyApp v1.2.3 Copyright/);
99+
expect(files.text("README.md")).to.match(/version 5.6.7 and v8.9.10 should not be changed/);
100+
expect(files.text("README.md")).to.match(/version 1.2.3 and v1.2.3 should both get updated/);
101+
expect(files.text("script1.js")).to.match(/make sure v1.2.3 gets replaced correctly/);
102+
expect(files.text("script1.js")).to.match(/let version = "1.2.3";/);
103+
expect(files.text("script1.js")).to.match(/let version = "1.2.3";/);
104+
expect(files.text("script2.js")).to.match(/version 3.2.1 and v8.9.10 don't match the old version number/);
105+
});
106+
107+
it("should error if a glob pattern doesn't match any files", () => {
108+
files.create("package.json", { version: "4.5.6" });
64109

65-
let bump = chaiExec("--major --grep LICENSE README.* *.js");
110+
let bump = chaiExec("major README.* *.js");
66111

67112
expect(bump).to.have.stderr("");
68113
expect(bump).to.have.exitCode(0);

test/utils/files.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const fs = require("fs");
44
const path = require("path");
55
const mkdirp = require("mkdirp");
66

7-
const filesDir = path.resolve("test", "fixtures", "files");
87
const tempDir = path.resolve("test", ".tmp");
98

109
const files = module.exports = {
@@ -26,16 +25,6 @@ const files = module.exports = {
2625
fs.writeFileSync(filePath, contents);
2726
},
2827

29-
/**
30-
* Copies a file from the "test/fixtures/files" directory to the "test/.tmp" directory.
31-
*
32-
* @param {string} name - The name of the file to copy (e.g. "README.md", "script1.js")
33-
*/
34-
copy (name) {
35-
let contents = fs.readFileSync(path.join(filesDir, name), "utf8");
36-
files.create(name, contents);
37-
},
38-
3928
/**
4029
* Reads a file in the "test/.tmp" directory, and returns its contents as a string.
4130
*

test/utils/fixtures.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
const filesDir = path.resolve("test", "fixtures", "files");
7+
8+
module.exports = {
9+
license: fs.readFileSync(path.join(filesDir, "LICENSE"), "utf8"),
10+
readme: fs.readFileSync(path.join(filesDir, "README.md"), "utf8"),
11+
script1: fs.readFileSync(path.join(filesDir, "script1.js"), "utf8"),
12+
script2: fs.readFileSync(path.join(filesDir, "script2.js"), "utf8"),
13+
};

test/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
module.exports = {
44
check: require("./check"),
55
files: require("./files"),
6+
fixtures: require("./fixtures"),
67
mocks: require("./mocks"),
78
};

0 commit comments

Comments
 (0)