2
2
3
3
const webpack = require ( './helpers/compiler' )
4
4
const { loader } = require ( './helpers/compilation' )
5
+ const { copyFile, deleteFile } = require ( './helpers/fs' ) ;
5
6
6
7
describe ( 'Loader' , ( ) => {
7
8
test ( 'Default' , ( ) => {
@@ -20,4 +21,67 @@ describe('Loader', () => {
20
21
expect ( src ) . toMatchSnapshot ( )
21
22
} )
22
23
} )
24
+
25
+ describe ( 'Watching' , ( ) => {
26
+ describe ( 'Dependencies' , ( ) => {
27
+ const files = {
28
+ syntaxError : "watch/watching/syntaxError.css" ,
29
+ noSyntaxError : "watch/watching/noSyntaxError.css" ,
30
+ changingFile : "watch/watching/styleDep.css"
31
+ }
32
+
33
+ beforeEach ( ( ) => copyFile ( files . noSyntaxError , files . changingFile ) )
34
+
35
+ afterEach ( ( ) => deleteFile ( files . changingFile ) )
36
+
37
+ test ( 'Error' , ( ) => {
38
+ const config = {
39
+ loader : {
40
+ options : {
41
+ plugins : [ require ( "postcss-import" ) ] ,
42
+ }
43
+ }
44
+ }
45
+
46
+ const steps = [
47
+ ( stats ) => {
48
+ const { err, src } = loader ( stats )
49
+
50
+ expect ( src ) . toMatchSnapshot ( )
51
+ expect ( err . length ) . toEqual ( 0 )
52
+
53
+ return copyFile ( files . syntaxError , files . changingFile )
54
+ } ,
55
+ ( stats ) => {
56
+ const { err, src } = loader ( stats )
57
+
58
+ expect ( src ) . toMatchSnapshot ( )
59
+ expect ( err . length ) . toEqual ( 1 )
60
+
61
+ return copyFile ( files . noSyntaxError , files . changingFile )
62
+ } ,
63
+ ( stats , close ) => {
64
+ const { err, src } = loader ( stats )
65
+
66
+ expect ( src ) . toMatchSnapshot ( )
67
+ expect ( src ) . toEqual ( "module.exports = \"a { color: black }\\n\"" )
68
+ expect ( err . length ) . toEqual ( 0 )
69
+
70
+ return close ( )
71
+ }
72
+ ] ;
73
+
74
+ var currentStep = 0
75
+
76
+ const options = {
77
+ watch ( err , stats , close ) {
78
+ steps [ currentStep ] ( stats , close )
79
+ currentStep ++
80
+ }
81
+ }
82
+
83
+ return webpack ( 'watch/watching/index.js' , config , options )
84
+ } )
85
+ } )
86
+ } )
23
87
} )
0 commit comments