@@ -20,6 +20,10 @@ async function compileAndCompare(fixture, { lessLoaderOptions, lessLoaderContext
20
20
expect ( actualCss ) . toBe ( expectedCss ) ;
21
21
}
22
22
23
+ function lessFixturePath ( fixture ) {
24
+ return path . resolve ( __dirname , 'fixtures' , 'less' , fixture ) ;
25
+ }
26
+
23
27
test ( 'should compile simple less without errors' , async ( ) => {
24
28
await compileAndCompare ( 'basic' ) ;
25
29
} ) ;
@@ -28,10 +32,50 @@ test('should resolve all imports', async () => {
28
32
await compileAndCompare ( 'import' ) ;
29
33
} ) ;
30
34
35
+ test ( 'should add all resolved imports as dependencies' , async ( ) => {
36
+ const dependencies = [ ] ;
37
+
38
+ await compileAndCompare ( 'import' , {
39
+ lessLoaderContext : {
40
+ addDependency ( dep ) {
41
+ if ( dependencies . indexOf ( dep ) === - 1 ) {
42
+ dependencies . push ( dep ) ;
43
+ }
44
+ } ,
45
+ } ,
46
+ } ) ;
47
+
48
+ expect ( dependencies . sort ( ) ) . toEqual ( [
49
+ lessFixturePath ( 'import.less' ) ,
50
+ lessFixturePath ( 'css.css' ) ,
51
+ lessFixturePath ( 'basic.less' ) ,
52
+ ] . sort ( ) ) ;
53
+ } ) ;
54
+
31
55
test ( 'should resolve all imports from node_modules using webpack\'s resolver' , async ( ) => {
32
56
await compileAndCompare ( 'import-webpack' ) ;
33
57
} ) ;
34
58
59
+ test ( 'should add all resolved imports as dependencies, including node_modules' , async ( ) => {
60
+ const dependencies = [ ] ;
61
+
62
+ await compileAndCompare ( 'import-webpack' , {
63
+ lessLoaderContext : {
64
+ addDependency ( dep ) {
65
+ if ( dependencies . indexOf ( dep ) === - 1 ) {
66
+ dependencies . push ( dep ) ;
67
+ }
68
+ } ,
69
+ } ,
70
+ } ) ;
71
+
72
+ expect ( dependencies . sort ( ) ) . toEqual ( [
73
+ lessFixturePath ( 'import-webpack.less' ) ,
74
+ lessFixturePath ( '../node_modules/some/module.less' ) ,
75
+ lessFixturePath ( '../node_modules/some/css.css' ) ,
76
+ ] . sort ( ) ) ;
77
+ } ) ;
78
+
35
79
test ( 'should resolve aliases as configured' , async ( ) => {
36
80
await compileAndCompare ( 'import-webpack-alias' , {
37
81
resolveAlias : {
@@ -40,12 +84,54 @@ test('should resolve aliases as configured', async () => {
40
84
} ) ;
41
85
} ) ;
42
86
87
+ test ( 'should add all resolved imports as dependencies, including aliased ones' , async ( ) => {
88
+ const dependencies = [ ] ;
89
+
90
+ await compileAndCompare ( 'import-webpack-alias' , {
91
+ resolveAlias : {
92
+ 'aliased-some' : 'some' ,
93
+ } ,
94
+ lessLoaderContext : {
95
+ addDependency ( dep ) {
96
+ if ( dependencies . indexOf ( dep ) === - 1 ) {
97
+ dependencies . push ( dep ) ;
98
+ }
99
+ } ,
100
+ } ,
101
+ } ) ;
102
+
103
+ expect ( dependencies . sort ( ) ) . toEqual ( [
104
+ lessFixturePath ( 'import-webpack-alias.less' ) ,
105
+ lessFixturePath ( '../node_modules/some/module.less' ) ,
106
+ ] . sort ( ) ) ;
107
+ } ) ;
108
+
43
109
test ( 'should resolve all imports from the given paths using Less\' resolver' , async ( ) => {
44
110
await compileAndCompare ( 'import-paths' , {
45
111
lessLoaderOptions : { paths : [ __dirname , nodeModulesPath ] } ,
46
112
} ) ;
47
113
} ) ;
48
114
115
+ test ( 'should add all resolved imports as dependencies, including those from the Less resolver' , async ( ) => {
116
+ const dependencies = [ ] ;
117
+
118
+ await compileAndCompare ( 'import-paths' , {
119
+ lessLoaderOptions : { paths : [ __dirname , nodeModulesPath ] } ,
120
+ lessLoaderContext : {
121
+ addDependency ( dep ) {
122
+ if ( dependencies . indexOf ( dep ) === - 1 ) {
123
+ dependencies . push ( dep ) ;
124
+ }
125
+ } ,
126
+ } ,
127
+ } ) ;
128
+
129
+ expect ( dependencies . sort ( ) ) . toEqual ( [
130
+ lessFixturePath ( 'import-paths.less' ) ,
131
+ lessFixturePath ( '../node_modules/some/module.less' ) ,
132
+ ] . sort ( ) ) ;
133
+ } ) ;
134
+
49
135
test ( 'should allow to disable webpack\'s resolver by passing an empty paths array' , async ( ) => {
50
136
const err = await compile ( 'import-webpack' , moduleRules . basic ( { paths : [ ] } ) )
51
137
. catch ( e => e ) ;
@@ -140,3 +226,23 @@ test('should provide a useful error message if there was a syntax error', async
140
226
expect ( err ) . toBeInstanceOf ( Error ) ;
141
227
compareErrorMessage ( err . message ) ;
142
228
} ) ;
229
+
230
+ test ( 'should add a file with an error as dependency so that the watcher is triggered when the error is fixed' , async ( ) => {
231
+ const dependencies = [ ] ;
232
+ const lessLoaderContext = {
233
+ addDependency ( dep ) {
234
+ if ( dependencies . indexOf ( dep ) === - 1 ) {
235
+ dependencies . push ( dep ) ;
236
+ }
237
+ } ,
238
+ } ;
239
+ const rules = moduleRules . basic ( { } , lessLoaderContext ) ;
240
+
241
+ await compile ( 'error-import-file-with-error' , rules )
242
+ . catch ( e => e ) ;
243
+
244
+ expect ( dependencies . sort ( ) ) . toEqual ( [
245
+ lessFixturePath ( 'error-import-file-with-error.less' ) ,
246
+ lessFixturePath ( 'error-syntax.less' ) ,
247
+ ] . sort ( ) ) ;
248
+ } ) ;
0 commit comments