@@ -9,85 +9,88 @@ var test = require("tape")
9
9
10
10
var utils = require ( "./utils" )
11
11
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
+
12
18
var cssnextBin = "node bin/cssnext" // node bin is used to help for windows
13
19
14
20
test ( "cli/watcher" , function ( t ) {
15
21
var planned = 0
16
22
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 )
28
38
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
38
42
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"
41
45
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" } )
43
47
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...
47
51
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';" )
50
54
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" , "/**/" )
55
62
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" )
58
66
59
- // check the output has been update
60
67
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
62
71
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 )
67
75
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 )
71
79
72
- // not sure why but it's better with the statSync on the watched file in this delayed call
73
80
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" )
80
84
81
- utils . remove ( "cli.output--watch-import" )
82
- watchImportProcess . kill ( )
83
- } , 1000 )
85
+ utils . remove ( "cli.output--watch-import" )
86
+ watchImportProcess . kill ( )
84
87
} , 1000 )
85
88
} , 1000 )
86
89
} , 1000 )
87
90
} , 1000 )
91
+ } , 1000 )
88
92
89
- planned += 3
90
- }
93
+ planned += 3
91
94
92
95
t . plan ( planned )
93
96
} )
0 commit comments