@@ -20,6 +20,10 @@ async function compileAndCompare(fixture, { lessLoaderOptions, lessLoaderContext
2020 expect ( actualCss ) . toBe ( expectedCss ) ;
2121}
2222
23+ function lessFixturePath ( fixture ) {
24+ return path . resolve ( __dirname , 'fixtures' , 'less' , fixture ) ;
25+ }
26+
2327test ( 'should compile simple less without errors' , async ( ) => {
2428 await compileAndCompare ( 'basic' ) ;
2529} ) ;
@@ -28,10 +32,50 @@ test('should resolve all imports', async () => {
2832 await compileAndCompare ( 'import' ) ;
2933} ) ;
3034
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+
3155test ( 'should resolve all imports from node_modules using webpack\'s resolver' , async ( ) => {
3256 await compileAndCompare ( 'import-webpack' ) ;
3357} ) ;
3458
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+
3579test ( 'should resolve aliases as configured' , async ( ) => {
3680 await compileAndCompare ( 'import-webpack-alias' , {
3781 resolveAlias : {
@@ -40,12 +84,54 @@ test('should resolve aliases as configured', async () => {
4084 } ) ;
4185} ) ;
4286
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+
43109test ( 'should resolve all imports from the given paths using Less\' resolver' , async ( ) => {
44110 await compileAndCompare ( 'import-paths' , {
45111 lessLoaderOptions : { paths : [ __dirname , nodeModulesPath ] } ,
46112 } ) ;
47113} ) ;
48114
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+
49135test ( 'should allow to disable webpack\'s resolver by passing an empty paths array' , async ( ) => {
50136 const err = await compile ( 'import-webpack' , moduleRules . basic ( { paths : [ ] } ) )
51137 . catch ( e => e ) ;
@@ -140,3 +226,23 @@ test('should provide a useful error message if there was a syntax error', async
140226 expect ( err ) . toBeInstanceOf ( Error ) ;
141227 compareErrorMessage ( err . message ) ;
142228} ) ;
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