Skip to content

Commit cbaf51d

Browse files
test: lessOptions relativeUrls (#384)
1 parent d87294f commit cbaf51d

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

test/__snapshots__/loader.test.js.snap

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,46 @@ exports[`loader should watch imports correctly: errors 1`] = `Array []`;
511511
512512
exports[`loader should watch imports correctly: warnings 1`] = `Array []`;
513513
514+
exports[`loader should work lessOptions.relativeUrls is false: css 1`] = `
515+
".top-import {
516+
background: red;
517+
}
518+
.img4 {
519+
background: url(img.jpg);
520+
}
521+
.img5 {
522+
background: url(some/img.jpg);
523+
}
524+
.img6 {
525+
background: url(../img.jpg);
526+
}
527+
"
528+
`;
529+
530+
exports[`loader should work lessOptions.relativeUrls is false: errors 1`] = `Array []`;
531+
532+
exports[`loader should work lessOptions.relativeUrls is false: warnings 1`] = `Array []`;
533+
534+
exports[`loader should work lessOptions.relativeUrls is true: css 1`] = `
535+
".top-import {
536+
background: red;
537+
}
538+
.img4 {
539+
background: url(folder/img.jpg);
540+
}
541+
.img5 {
542+
background: url(folder/some/img.jpg);
543+
}
544+
.img6 {
545+
background: url(./img.jpg);
546+
}
547+
"
548+
`;
549+
550+
exports[`loader should work lessOptions.relativeUrls is true: errors 1`] = `Array []`;
551+
552+
exports[`loader should work lessOptions.relativeUrls is true: warnings 1`] = `Array []`;
553+
514554
exports[`loader should work loaderContext in less plugins: css 1`] = `
515555
".webpackLoaderContext {
516556
isDefined: true;

test/fixtures/import-relative.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.top-import {
2+
background: red;
3+
}
4+
5+
@import "folder/url-path.less";

test/loader.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,48 @@ describe('loader', () => {
163163
expect(getErrors(stats)).toMatchSnapshot('errors');
164164
});
165165

166+
it('should work lessOptions.relativeUrls is true', async () => {
167+
const testId = './import-relative.less';
168+
const compiler = getCompiler(testId, {
169+
lessOptions: {
170+
relativeUrls: true,
171+
},
172+
});
173+
const stats = await compile(compiler);
174+
const codeFromBundle = getCodeFromBundle(stats, compiler);
175+
const codeFromLess = await getCodeFromLess(testId, {
176+
lessOptions: {
177+
relativeUrls: true,
178+
},
179+
});
180+
181+
expect(codeFromBundle.css).toBe(codeFromLess.css);
182+
expect(codeFromBundle.css).toMatchSnapshot('css');
183+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
184+
expect(getErrors(stats)).toMatchSnapshot('errors');
185+
});
186+
187+
it('should work lessOptions.relativeUrls is false', async () => {
188+
const testId = './import-relative.less';
189+
const compiler = getCompiler(testId, {
190+
lessOptions: {
191+
relativeUrls: false,
192+
},
193+
});
194+
const stats = await compile(compiler);
195+
const codeFromBundle = getCodeFromBundle(stats, compiler);
196+
const codeFromLess = await getCodeFromLess(testId, {
197+
lessOptions: {
198+
relativeUrls: false,
199+
},
200+
});
201+
202+
expect(codeFromBundle.css).toBe(codeFromLess.css);
203+
expect(codeFromBundle.css).toMatchSnapshot('css');
204+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
205+
expect(getErrors(stats)).toMatchSnapshot('errors');
206+
});
207+
166208
it("should resolve all imports from node_modules using webpack's resolver", async () => {
167209
const testId = './import-webpack.less';
168210
const compiler = getCompiler(testId);

0 commit comments

Comments
 (0)