Skip to content

Commit

Permalink
test: package resolving (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Dec 27, 2023
1 parent 9c8bf1c commit 5055381
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,37 @@ exports[`loader should resolve nested imports: errors 1`] = `[]`;

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

exports[`loader should resolve nested package #2: css 1`] = `
".less-package-1-nested {
background: red;
}
.less-package-2 {
background: red;
}
.top {
color: red;
}
"
`;

exports[`loader should resolve nested package #2: errors 1`] = `[]`;

exports[`loader should resolve nested package #2: warnings 1`] = `[]`;

exports[`loader should resolve nested package: css 1`] = `
".less-package-1-nested {
background: red;
}
.less-package-2 {
background: red;
}
"
`;

exports[`loader should resolve nested package: errors 1`] = `[]`;

exports[`loader should resolve nested package: warnings 1`] = `[]`;

exports[`loader should resolve non-less import with alias: css 1`] = `
".some-file {
background: hotpink;
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/less-package.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "less-package-2";

.top {
color: red;
}
3 changes: 3 additions & 0 deletions test/fixtures/node_modules/less-package-1/index.less

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/fixtures/node_modules/less-package-1/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/fixtures/node_modules/less-package-2/index.less

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/fixtures/node_modules/less-package-2/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions test/helpers/getCodeFromLess.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ const pathMap = {
"custom-main-files",
"custom.less"
),
"less-package-1/index.less": path.resolve(
__dirname,
"..",
"fixtures",
"node_modules",
"less-package-2",
"node_modules",
"less-package-1",
"index.less"
),
"less-package-2": path.resolve(
__dirname,
"..",
"fixtures",
"node_modules",
"less-package-2",
"index.less"
),
};

class ResolvePlugin extends less.FileManager {
Expand Down
26 changes: 26 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,32 @@ describe("loader", () => {
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should resolve nested package", async () => {
const testId = "./node_modules/less-package-2/index.less";
const compiler = getCompiler(testId);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromLess = await getCodeFromLess(testId);

expect(codeFromBundle.css).toBe(codeFromLess.css);
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should resolve nested package #2", async () => {
const testId = "./less-package.less";
const compiler = getCompiler(testId);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromLess = await getCodeFromLess(testId);

expect(codeFromBundle.css).toBe(codeFromLess.css);
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

// TODO bug on windows
it.skip("should work with circular imports", async () => {
const testId = "./circular.less";
Expand Down

0 comments on commit 5055381

Please sign in to comment.