Skip to content

Commit 5055381

Browse files
test: package resolving (#530)
1 parent 9c8bf1c commit 5055381

File tree

10 files changed

+103
-0
lines changed

10 files changed

+103
-0
lines changed

test/__snapshots__/loader.test.js.snap

+31
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,37 @@ exports[`loader should resolve nested imports: errors 1`] = `[]`;
392392

393393
exports[`loader should resolve nested imports: warnings 1`] = `[]`;
394394

395+
exports[`loader should resolve nested package #2: css 1`] = `
396+
".less-package-1-nested {
397+
background: red;
398+
}
399+
.less-package-2 {
400+
background: red;
401+
}
402+
.top {
403+
color: red;
404+
}
405+
"
406+
`;
407+
408+
exports[`loader should resolve nested package #2: errors 1`] = `[]`;
409+
410+
exports[`loader should resolve nested package #2: warnings 1`] = `[]`;
411+
412+
exports[`loader should resolve nested package: css 1`] = `
413+
".less-package-1-nested {
414+
background: red;
415+
}
416+
.less-package-2 {
417+
background: red;
418+
}
419+
"
420+
`;
421+
422+
exports[`loader should resolve nested package: errors 1`] = `[]`;
423+
424+
exports[`loader should resolve nested package: warnings 1`] = `[]`;
425+
395426
exports[`loader should resolve non-less import with alias: css 1`] = `
396427
".some-file {
397428
background: hotpink;

test/fixtures/less-package.less

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "less-package-2";
2+
3+
.top {
4+
color: red;
5+
}

test/fixtures/node_modules/less-package-1/index.less

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/less-package-1/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/less-package-2/index.less

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/less-package-2/node_modules/less-package-1/index.less

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/less-package-2/node_modules/less-package-1/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/less-package-2/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/helpers/getCodeFromLess.js

+18
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@ const pathMap = {
115115
"custom-main-files",
116116
"custom.less"
117117
),
118+
"less-package-1/index.less": path.resolve(
119+
__dirname,
120+
"..",
121+
"fixtures",
122+
"node_modules",
123+
"less-package-2",
124+
"node_modules",
125+
"less-package-1",
126+
"index.less"
127+
),
128+
"less-package-2": path.resolve(
129+
__dirname,
130+
"..",
131+
"fixtures",
132+
"node_modules",
133+
"less-package-2",
134+
"index.less"
135+
),
118136
};
119137

120138
class ResolvePlugin extends less.FileManager {

test/loader.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,32 @@ describe("loader", () => {
843843
expect(getErrors(stats)).toMatchSnapshot("errors");
844844
});
845845

846+
it("should resolve nested package", async () => {
847+
const testId = "./node_modules/less-package-2/index.less";
848+
const compiler = getCompiler(testId);
849+
const stats = await compile(compiler);
850+
const codeFromBundle = getCodeFromBundle(stats, compiler);
851+
const codeFromLess = await getCodeFromLess(testId);
852+
853+
expect(codeFromBundle.css).toBe(codeFromLess.css);
854+
expect(codeFromBundle.css).toMatchSnapshot("css");
855+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
856+
expect(getErrors(stats)).toMatchSnapshot("errors");
857+
});
858+
859+
it("should resolve nested package #2", async () => {
860+
const testId = "./less-package.less";
861+
const compiler = getCompiler(testId);
862+
const stats = await compile(compiler);
863+
const codeFromBundle = getCodeFromBundle(stats, compiler);
864+
const codeFromLess = await getCodeFromLess(testId);
865+
866+
expect(codeFromBundle.css).toBe(codeFromLess.css);
867+
expect(codeFromBundle.css).toMatchSnapshot("css");
868+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
869+
expect(getErrors(stats)).toMatchSnapshot("errors");
870+
});
871+
846872
// TODO bug on windows
847873
it.skip("should work with circular imports", async () => {
848874
const testId = "./circular.less";

0 commit comments

Comments
 (0)