Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tux-tn committed Dec 24, 2021
1 parent 938ee3f commit 496ec66
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 42 deletions.
62 changes: 41 additions & 21 deletions lib/craco-less.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ test("the webpack config is modified correctly without any options", () => {
expect(lessRule.use[1].loader).toContain(`${path.sep}css-loader`);
expect(lessRule.use[1].options).toEqual({
importLoaders: 3,
modules: {
mode: "icss",
},
sourceMap: webpackConfig.devtool !== false,
});

expect(lessRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessRule.use[2].options.ident).toEqual("postcss");
expect(lessRule.use[2].options.plugins).not.toBeUndefined();
expect(lessRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(lessRule.use[2].options.postcssOptions.plugins).not.toBeUndefined();

expect(lessRule.use[3].loader).toContain(`${path.sep}resolve-url-loader`);
expect(lessRule.use[3].options).toEqual({
Expand All @@ -81,15 +84,18 @@ test("the webpack config is modified correctly without any options", () => {
expect(lessModuleRule.use[1].loader).toContain(`${path.sep}css-loader`);
expect(lessModuleRule.use[1].options).toEqual({
importLoaders: 3,
sourceMap: webpackConfig.devtool !== false,
modules: {
getLocalIdent: getCSSModuleLocalIdent,
mode: "local",
},
sourceMap: webpackConfig.devtool !== false,
});

expect(lessModuleRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessModuleRule.use[2].options.ident).toEqual("postcss");
expect(lessModuleRule.use[2].options.plugins).not.toBeUndefined();
expect(lessModuleRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(
lessModuleRule.use[2].options.postcssOptions.plugins
).not.toBeUndefined();

expect(lessModuleRule.use[3].loader).toContain(
`${path.sep}resolve-url-loader`
Expand Down Expand Up @@ -144,12 +150,15 @@ test("the webpack config is modified correctly without any options on Windows",
expect(lessRule.use[1].loader).toContain("\\css-loader");
expect(lessRule.use[1].options).toEqual({
importLoaders: 3,
modules: {
mode: "icss",
},
sourceMap: webpackConfig.devtool !== false,
});

expect(lessRule.use[2].loader).toContain("\\postcss-loader");
expect(lessRule.use[2].options.ident).toEqual("postcss");
expect(lessRule.use[2].options.plugins).not.toBeUndefined();
expect(lessRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(lessRule.use[2].options.postcssOptions.plugins).not.toBeUndefined();

expect(lessRule.use[3].loader).toContain(`\\resolve-url-loader`);
expect(lessRule.use[3].options).toEqual({
Expand All @@ -174,12 +183,15 @@ test("the webpack config is modified correctly without any options on Windows",
sourceMap: webpackConfig.devtool !== false,
modules: {
getLocalIdent: getCSSModuleLocalIdent,
mode: "local",
},
});

expect(lessModuleRule.use[2].loader).toContain("\\postcss-loader");
expect(lessModuleRule.use[2].options.ident).toEqual("postcss");
expect(lessModuleRule.use[2].options.plugins).not.toBeUndefined();
expect(lessModuleRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(
lessModuleRule.use[2].options.postcssOptions.plugins
).not.toBeUndefined();

expect(lessModuleRule.use[3].loader).toContain(`\\resolve-url-loader`);
expect(lessModuleRule.use[3].options).toEqual({
Expand Down Expand Up @@ -217,8 +229,8 @@ test("the webpack config is modified correctly with less-loader options", () =>
expect(lessRule).not.toBeUndefined();

expect(lessRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessRule.use[2].options.ident).toEqual("postcss");
expect(lessRule.use[2].options.plugins).not.toBeUndefined();
expect(lessRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(lessRule.use[2].options.postcssOptions.plugins).not.toBeUndefined();

expect(lessRule.use[3].loader).toContain(`${path.sep}resolve-url-loader`);
expect(lessRule.use[3].options).toEqual({
Expand All @@ -241,8 +253,10 @@ test("the webpack config is modified correctly with less-loader options", () =>
expect(lessModuleRule).not.toBeUndefined();

expect(lessModuleRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessModuleRule.use[2].options.ident).toEqual("postcss");
expect(lessModuleRule.use[2].options.plugins).not.toBeUndefined();
expect(lessModuleRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(
lessModuleRule.use[2].options.postcssOptions.plugins
).not.toBeUndefined();

expect(lessModuleRule.use[3].loader).toContain(
`${path.sep}resolve-url-loader`
Expand Down Expand Up @@ -312,8 +326,8 @@ test("the webpack config is modified correctly with all loader options", () => {
});

expect(lessRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessRule.use[2].options.ident).toEqual("test-ident");
expect(lessRule.use[2].options.plugins).not.toBeUndefined();
expect(lessRule.use[2].options.postcssOptions.ident).toEqual("test-ident");
expect(lessRule.use[2].options.postcssOptions.plugins).not.toBeUndefined();

expect(lessRule.use[3].loader).toContain(`${path.sep}resolve-url-loader`);
expect(lessRule.use[3].options).toEqual({
Expand Down Expand Up @@ -348,8 +362,12 @@ test("the webpack config is modified correctly with all loader options", () => {
});

expect(lessModuleRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessModuleRule.use[2].options.ident).toEqual("test-ident");
expect(lessModuleRule.use[2].options.plugins).not.toBeUndefined();
expect(lessModuleRule.use[2].options.postcssOptions.ident).toEqual(
"test-ident"
);
expect(
lessModuleRule.use[2].options.postcssOptions.plugins
).not.toBeUndefined();

expect(lessModuleRule.use[3].loader).toContain(
`${path.sep}resolve-url-loader`
Expand Down Expand Up @@ -399,8 +417,8 @@ test("the webpack config is modified correctly with the modifyLessRule option",
expect(lessRule.use[0].options.testOption).toEqual("test-value-development");

expect(lessRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessRule.use[2].options.ident).toEqual("postcss");
expect(lessRule.use[2].options.plugins).not.toBeUndefined();
expect(lessRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(lessRule.use[2].options.postcssOptions.plugins).not.toBeUndefined();

expect(lessRule.use[3].loader).toContain(`${path.sep}resolve-url-loader`);
expect(lessRule.use[3].options).toEqual({
Expand Down Expand Up @@ -452,8 +470,10 @@ test("the webpack config is modified correctly with the modifyLessModuleRule opt
);

expect(lessModuleRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessModuleRule.use[2].options.ident).toEqual("postcss");
expect(lessModuleRule.use[2].options.plugins).not.toBeUndefined();
expect(lessModuleRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(
lessModuleRule.use[2].options.postcssOptions.plugins
).not.toBeUndefined();

expect(lessModuleRule.use[3].loader).toContain(
`${path.sep}resolve-url-loader`
Expand Down
61 changes: 40 additions & 21 deletions lib/craco-less.prod.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ test("the webpack config is modified correctly without any options", () => {
expect(lessRule.use[1].loader).toContain(`${path.sep}css-loader`);
expect(lessRule.use[1].options).toEqual({
importLoaders: 3,
modules: {
mode: "icss",
},
sourceMap: true,
});

expect(lessRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessRule.use[2].options.ident).toEqual("postcss");
expect(lessRule.use[2].options.plugins).not.toBeUndefined();
expect(lessRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(lessRule.use[2].options.postcssOptions.plugins).not.toBeUndefined();

expect(lessRule.use[3].loader).toContain(`${path.sep}resolve-url-loader`);
expect(lessRule.use[3].options).toEqual({
Expand Down Expand Up @@ -90,12 +93,15 @@ test("the webpack config is modified correctly without any options", () => {
sourceMap: true,
modules: {
getLocalIdent: getCSSModuleLocalIdent,
mode: "local",
},
});

expect(lessModuleRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessModuleRule.use[2].options.ident).toEqual("postcss");
expect(lessModuleRule.use[2].options.plugins).not.toBeUndefined();
expect(lessModuleRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(
lessModuleRule.use[2].options.postcssOptions.plugins
).not.toBeUndefined();

expect(lessModuleRule.use[3].loader).toContain(
`${path.sep}resolve-url-loader`
Expand Down Expand Up @@ -152,12 +158,15 @@ test("the webpack config is modified correctly without any options on Windows",
expect(lessRule.use[1].loader).toContain("\\css-loader");
expect(lessRule.use[1].options).toEqual({
importLoaders: 3,
modules: {
mode: "icss",
},
sourceMap: true,
});

expect(lessRule.use[2].loader).toContain("\\postcss-loader");
expect(lessRule.use[2].options.ident).toEqual("postcss");
expect(lessRule.use[2].options.plugins).not.toBeUndefined();
expect(lessRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(lessRule.use[2].options.postcssOptions.plugins).not.toBeUndefined();

expect(lessRule.use[3].loader).toContain(`\\resolve-url-loader`);
expect(lessRule.use[3].options).toEqual({
Expand All @@ -182,12 +191,15 @@ test("the webpack config is modified correctly without any options on Windows",
sourceMap: true,
modules: {
getLocalIdent: getCSSModuleLocalIdent,
mode: "local",
},
});

expect(lessModuleRule.use[2].loader).toContain("\\postcss-loader");
expect(lessModuleRule.use[2].options.ident).toEqual("postcss");
expect(lessModuleRule.use[2].options.plugins).not.toBeUndefined();
expect(lessModuleRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(
lessModuleRule.use[2].options.postcssOptions.plugins
).not.toBeUndefined();

expect(lessModuleRule.use[3].loader).toContain(`\\resolve-url-loader`);
expect(lessModuleRule.use[3].options).toEqual({
Expand Down Expand Up @@ -225,8 +237,8 @@ test("the webpack config is modified correctly with less-loader options", () =>
expect(lessRule).not.toBeUndefined();

expect(lessRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessRule.use[2].options.ident).toEqual("postcss");
expect(lessRule.use[2].options.plugins).not.toBeUndefined();
expect(lessRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(lessRule.use[2].options.postcssOptions.plugins).not.toBeUndefined();

expect(lessRule.use[3].loader).toContain(`${path.sep}resolve-url-loader`);
expect(lessRule.use[3].options).toEqual({
Expand All @@ -249,8 +261,10 @@ test("the webpack config is modified correctly with less-loader options", () =>
expect(lessModuleRule).not.toBeUndefined();

expect(lessModuleRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessModuleRule.use[2].options.ident).toEqual("postcss");
expect(lessModuleRule.use[2].options.plugins).not.toBeUndefined();
expect(lessModuleRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(
lessModuleRule.use[2].options.postcssOptions.plugins
).not.toBeUndefined();

expect(lessModuleRule.use[3].loader).toContain(
`${path.sep}resolve-url-loader`
Expand Down Expand Up @@ -320,10 +334,9 @@ test("the webpack config is modified correctly with all loader options", () => {
localIdentName: "[local]_[hash:base64:5]",
sourceMap: true,
});

expect(lessRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessRule.use[2].options.ident).toEqual("test-ident");
expect(lessRule.use[2].options.plugins).not.toBeUndefined();
expect(lessRule.use[2].options.postcssOptions.ident).toEqual("test-ident");
expect(lessRule.use[2].options.postcssOptions.plugins).not.toBeUndefined();

expect(lessRule.use[3].loader).toContain(`${path.sep}resolve-url-loader`);
expect(lessRule.use[3].options).toEqual({
Expand Down Expand Up @@ -360,8 +373,12 @@ test("the webpack config is modified correctly with all loader options", () => {
});

expect(lessModuleRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessModuleRule.use[2].options.ident).toEqual("test-ident");
expect(lessModuleRule.use[2].options.plugins).not.toBeUndefined();
expect(lessModuleRule.use[2].options.postcssOptions.ident).toEqual(
"test-ident"
);
expect(
lessModuleRule.use[2].options.postcssOptions.plugins
).not.toBeUndefined();

expect(lessModuleRule.use[3].loader).toContain(
`${path.sep}resolve-url-loader`
Expand Down Expand Up @@ -413,8 +430,8 @@ test("the webpack config is modified correctly with the modifyLessRule option",
expect(lessRule.use[0].options.testOption).toEqual("test-value-production");

expect(lessRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessRule.use[2].options.ident).toEqual("postcss");
expect(lessRule.use[2].options.plugins).not.toBeUndefined();
expect(lessRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(lessRule.use[2].options.postcssOptions.plugins).not.toBeUndefined();

expect(lessRule.use[3].loader).toContain(`${path.sep}resolve-url-loader`);
expect(lessRule.use[3].options).toEqual({
Expand Down Expand Up @@ -470,8 +487,10 @@ test("the webpack config is modified correctly with the modifyLessModuleRule opt
);

expect(lessModuleRule.use[2].loader).toContain(`${path.sep}postcss-loader`);
expect(lessModuleRule.use[2].options.ident).toEqual("postcss");
expect(lessModuleRule.use[2].options.plugins).not.toBeUndefined();
expect(lessModuleRule.use[2].options.postcssOptions.ident).toEqual("postcss");
expect(
lessModuleRule.use[2].options.postcssOptions.plugins
).not.toBeUndefined();

expect(lessModuleRule.use[3].loader).toContain(
`${path.sep}resolve-url-loader`
Expand Down

0 comments on commit 496ec66

Please sign in to comment.