Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit f8dabb5

Browse files
committed
Correctly skip watcher on CI
1 parent 83988ff commit f8dabb5

File tree

1 file changed

+58
-55
lines changed

1 file changed

+58
-55
lines changed

test/cli.watcher.js

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,85 +9,88 @@ var test = require("tape")
99

1010
var utils = require("./utils")
1111

12+
// I don't success to call the kill() process from node and both Travis CI and Appveyor
13+
// so we avoid this test on this environnements
14+
if (process.env.TRAVIS || process.env.APPVEYOR) {
15+
return
16+
}
17+
1218
var cssnextBin = "node bin/cssnext" // node bin is used to help for windows
1319

1420
test("cli/watcher", function(t) {
1521
var planned = 0
1622

17-
// I don't success to call the kill() process from node and both Travis CI and Appveyor
18-
// so we avoid this test on this environnements
19-
if (!process.env.TRAVIS && !process.env.APPVEYOR) {
20-
var watchProcess = exec(cssnextBin + " --watch test/fixtures/cli.error.css test/fixtures/cli.output--watch.css", function(err) {
21-
t.ok(err && err.signal === "SIGTERM", "should only be killed by an interrupt when `--watch` option passed")
22-
if (err && !err.killed) { throw err }
23-
})
24-
25-
var msgWatch = "should output error messages when `--watch` option passed"
26-
var watchTimeout = setTimeout(function() {
27-
t.fail(msgWatch)
23+
24+
var watchProcess = exec(cssnextBin + " --watch test/fixtures/cli.error.css test/fixtures/cli.output--watch.css", function(err) {
25+
t.ok(err && err.signal === "SIGTERM", "should only be killed by an interrupt when `--watch` option passed")
26+
if (err && !err.killed) { throw err }
27+
})
28+
29+
var msgWatch = "should output error messages when `--watch` option passed"
30+
var watchTimeout = setTimeout(function() {
31+
t.fail(msgWatch)
32+
watchProcess.kill()
33+
}, 5000)
34+
watchProcess.stderr.on("data", function(data) {
35+
if (utils.contains(data, "encounters an error")) {
36+
t.pass(msgWatch)
37+
clearTimeout(watchTimeout)
2838
watchProcess.kill()
29-
}, 5000)
30-
watchProcess.stderr.on("data", function(data) {
31-
if (utils.contains(data, "encounters an error")) {
32-
t.pass(msgWatch)
33-
clearTimeout(watchTimeout)
34-
watchProcess.kill()
35-
}
36-
})
37-
planned+=2
39+
}
40+
})
41+
planned+=2
3842

39-
// watch/import tests
40-
var watchOut = "test/fixtures/cli.output--watch-import.css"
43+
// watch/import tests
44+
var watchOut = "test/fixtures/cli.output--watch-import.css"
4145

42-
var watchImportProcess = spawn("node", ["bin/cssnext", "--watch", "test/fixtures/cli.watch-import.css", watchOut], {stdio: "inherit"})
46+
var watchImportProcess = spawn("node", ["bin/cssnext", "--watch", "test/fixtures/cli.watch-import.css", watchOut], {stdio: "inherit"})
4347

44-
// watch an empty file doesn't seems to work great, so I am using
45-
// /**/ to get a content
46-
// yeah...
48+
// watch an empty file doesn't seems to work great, so I am using
49+
// /**/ to get a content
50+
// yeah...
4751

48-
// trigger a change in cli.import.css to add a new watched file cli.import2.css
49-
fs.writeFileSync("test/fixtures/cli.watch-import.css", "/**/ @import 'cli.watch-import-import.css';")
52+
// trigger a change in cli.import.css to add a new watched file cli.import2.css
53+
fs.writeFileSync("test/fixtures/cli.watch-import.css", "/**/ @import 'cli.watch-import-import.css';")
5054

51-
// we are using setTimeout for the watcher to do his job
52-
setTimeout(function() {
53-
// check the output has been updated (watcher works)
54-
t.equal(fs.readFileSync(watchOut, {encoding:"utf8"}), "/**/ watch{}", "should update the file")
55+
// we are using setTimeout for the watcher to do his job
56+
setTimeout(function() {
57+
// check the output has been updated (watcher works)
58+
t.equal(fs.readFileSync(watchOut, {encoding:"utf8"}), "/**/ watch{}", "should update the file")
59+
60+
// remove this newly imported file
61+
fs.writeFileSync("test/fixtures/cli.watch-import.css", "/**/")
5562

56-
// remove this newly imported file
57-
fs.writeFileSync("test/fixtures/cli.watch-import.css", "/**/")
63+
// check the output has been update
64+
setTimeout(function() {
65+
t.equal(fs.readFileSync(watchOut, {encoding:"utf8"}), "/**/", "should update the file, again")
5866

59-
// check the output has been update
6067
setTimeout(function() {
61-
t.equal(fs.readFileSync(watchOut, {encoding:"utf8"}), "/**/", "should update the file, again")
68+
// previously imported file should not be watched anymore
69+
// to check that we read output mtime, modify the file that should not be watched
70+
// and check back that the output file has the same mtime
6271

63-
setTimeout(function() {
64-
// previously imported file should not be watched anymore
65-
// to check that we read output mtime, modify the file that should not be watched
66-
// and check back that the output file has the same mtime
72+
// trigger a change in previously imported file
73+
var now = (new Date()).getTime()
74+
fs.utimesSync("test/fixtures/cli.watch-import-import.css", now, now)
6775

68-
// trigger a change in previously imported file
69-
var now = (new Date()).getTime()
70-
fs.utimesSync("test/fixtures/cli.watch-import-import.css", now, now)
76+
// not sure why but it's better with the statSync on the watched file in this delayed call
77+
setTimeout(function() {
78+
var outStat = fs.statSync(watchOut)
7179

72-
// not sure why but it's better with the statSync on the watched file in this delayed call
7380
setTimeout(function() {
74-
var outStat = fs.statSync(watchOut)
75-
76-
setTimeout(function() {
77-
// this time, it should not trigger anything
78-
var outStatAfter = fs.statSync(watchOut)
79-
t.equal(outStat.mtime.getTime(), outStatAfter.mtime.getTime(), "should not modify a file if a previously imported file is modified")
81+
// this time, it should not trigger anything
82+
var outStatAfter = fs.statSync(watchOut)
83+
t.equal(outStat.mtime.getTime(), outStatAfter.mtime.getTime(), "should not modify a file if a previously imported file is modified")
8084

81-
utils.remove("cli.output--watch-import")
82-
watchImportProcess.kill()
83-
}, 1000)
85+
utils.remove("cli.output--watch-import")
86+
watchImportProcess.kill()
8487
}, 1000)
8588
}, 1000)
8689
}, 1000)
8790
}, 1000)
91+
}, 1000)
8892

89-
planned+=3
90-
}
93+
planned+=3
9194

9295
t.plan(planned)
9396
})

0 commit comments

Comments
 (0)