Skip to content

Commit 1f6fdb5

Browse files
authored
fix: Overlapping value replacement (#365)
* WIP: sort values to match by length So that values with the same prefixes don't stomp over each other. This feels a bit hacky but works for now. Fixes #363 * test: Fix up travis failures - Directly write files instead of copying - Use travis in VM mode instead of container
1 parent a2f5f58 commit 1f6fdb5

File tree

11 files changed

+84
-58
lines changed

11 files changed

+84
-58
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
sudo: false
1+
# Force a VM instead of Docker, some tests that depend on the FS fail otherwise
2+
sudo: required
23

34
language: node_js
45
node_js:
56
- node
6-
- '7'
7-
- '6'
7+
- '8'
88

99
# https://docs.travis-ci.com/user/customizing-the-build/#Fast-Finishing
1010
matrix:

package-lock.json

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

packages/browserify/test/__snapshots__/issue-58.test.js.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,5 @@ exports[`/browserify.js /issues /58 should update when CSS dependencies change 3
4141
}
4242
.mc46e4a65d_issue2 {
4343
color: aqua;
44-
}
45-
"
44+
}"
4645
`;
Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
"use strict";
22

3-
var from = require("from2-string"),
3+
var fs = require("fs"),
4+
5+
from = require("from2-string"),
46
shell = require("shelljs"),
57
browserify = require("browserify"),
68
watchify = require("watchify"),
9+
dedent = require("dedent"),
710

811
read = require("test-utils/read.js")(__dirname),
912

1013
bundle = require("./lib/bundle.js"),
1114
plugin = require("../browserify.js");
1215

16+
function write(txt) {
17+
fs.writeFileSync(
18+
"./packages/browserify/test/specimens/issues/58/other.css",
19+
dedent(txt),
20+
"utf8"
21+
);
22+
}
23+
1324
describe("/browserify.js", () => {
1425
describe("/issues", () => {
1526
describe("/58", () => {
@@ -21,41 +32,55 @@ describe("/browserify.js", () => {
2132
it("should update when CSS dependencies change", (done) => {
2233
var build = browserify();
2334

24-
shell.cp("-f",
25-
"./packages/browserify/test/specimens/issues/58/1.css",
26-
"./packages/browserify/test/specimens/issues/58/other.css"
27-
);
35+
write(`
36+
.other1 { color: red; }
37+
.other2 { color: navy; }
38+
.other3 { color: blue; }
39+
`);
2840

29-
build.add(from("require('./packages/browserify/test/specimens/issues/58/issue.css');"));
41+
build.add(
42+
from("require('./packages/browserify/test/specimens/issues/58/issue.css');")
43+
);
3044

3145
build.plugin(watchify);
3246
build.plugin(plugin, {
3347
css : "./packages/browserify/test/output/issues/58.css"
3448
});
3549

3650
build.on("update", () => {
37-
bundle(build)
38-
.then((out) => {
39-
expect(out).toMatchSnapshot();
40-
41-
expect(read("./issues/58.css")).toMatchSnapshot();
42-
43-
build.close();
44-
45-
done();
46-
});
47-
});
51+
console.log("File change noticed");
52+
53+
bundle(build).then((out) => {
54+
console.log("second build complete");
4855

49-
bundle(build)
50-
.then((out) => {
5156
expect(out).toMatchSnapshot();
57+
58+
expect(read("./issues/58.css")).toMatchSnapshot();
59+
60+
console.log("snapshot tests complete");
61+
62+
build.close();
5263

53-
shell.cp("-f",
54-
"./packages/browserify/test/specimens/issues/58/2.css",
55-
"./packages/browserify/test/specimens/issues/58/other.css"
56-
);
64+
console.log("test finished");
65+
66+
done();
5767
});
58-
}, 10000);
68+
});
69+
70+
bundle(build).then((out) => {
71+
console.log("initial build complete");
72+
73+
expect(out).toMatchSnapshot();
74+
75+
write(`
76+
.other1 { color: green; }
77+
.other2 { color: yellow; }
78+
.other3 { composes: other2; background: white; }
79+
`);
80+
81+
console.log("File overwritten");
82+
});
83+
});
5984
});
6085
});
6186
});

packages/browserify/test/specimens/issues/58/1.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/browserify/test/specimens/issues/58/2.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/cli/test/cli.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ function success(out) {
1313
}
1414

1515
describe("/cli.js", function() {
16-
// Since these tests keep failing on Travis...
17-
jest.setTimeout(10000);
18-
1916
afterAll(() => require("shelljs").rm("-rf", "./packages/cli/test/output"));
2017

2118
it("should show help with no args", () =>

packages/core/plugins/values-replace.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ module.exports = (css, result) => {
6969

7070
matchRegex = new RegExp(
7171
Object.keys(values)
72+
.sort((a, b) => b.length - a.length)
7273
.map((v) => `\\b${escape(v)}\\b`)
7374
.join("|"),
7475
"g"

packages/core/test/__snapshots__/values.test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ exports[`/processor.js values should support value namespaces 1`] = `
7373
.blue {
7474
color: blue;
7575
}
76+
77+
.other {
78+
color: #000;
79+
}
7680
"
7781
`;
7882

packages/core/test/specimens/value-namespace.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
.blue {
88
color: colors.b;
99
}
10+
11+
.other {
12+
color: colors.base-other;
13+
}

0 commit comments

Comments
 (0)