Skip to content

Commit

Permalink
chore: align test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Feb 23, 2024
1 parent 990b163 commit d799301
Show file tree
Hide file tree
Showing 149 changed files with 190 additions and 98 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ packages/rspack/src/config/schema.check.js

packages/rspack/tests/fixtures/**/*
packages/rspack/tests/statsCases/**/*
packages/rspack/tests/configCases/errors/**/*
packages/rspack/tests/cases/**/*
packages/rspack/tests/configCases/**/*
packages/rspack/tests/hotCases/**/*
packages/rspack/tests/diagnostics/**/*
packages/rspack/tests/js/**/*
Expand Down
23 changes: 14 additions & 9 deletions packages/rspack/tests/TestCases.template.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

// require("./helpers/warmup-webpack");
require("./helpers/warmup-webpack");
const path = require("path");
const fs = require("graceful-fs");
const vm = require("vm");
Expand Down Expand Up @@ -117,12 +117,14 @@ const describeCases = config => {
removeAvailableModules: true,
removeEmptyChunks: true,
mergeDuplicateChunks: true,
flagIncludedChunks: true,
// CHANGE: rspack does not support `flagIncludedChunks` yet.
// flagIncludedChunks: true,
sideEffects: true,
providedExports: true,
usedExports: true,
mangleExports: true,
emitOnErrors: true,
// CHANGE: rspack does not support `emitOnErrors` yet.
// emitOnErrors: true,
concatenateModules:
!!testConfig?.optimization?.concatenateModules,
innerGraph: true,
Expand All @@ -134,9 +136,10 @@ const describeCases = config => {
minimizer: [terserForTesting],
...config.optimization
},
performance: {
hints: false
},
// CHANGE: rspack does not support `performance` yet.
// performance: {
// hints: false
// },
node: {
__dirname: "mock",
__filename: "mock"
Expand All @@ -146,7 +149,8 @@ const describeCases = config => {
...config.cache
},
output: {
pathinfo: "verbose",
// CHANGE: rspack does not support `pathinfo` yet.
// pathinfo: "verbose",
path: outputDirectory,
filename: config.module ? "bundle.mjs" : "bundle.js"
},
Expand Down Expand Up @@ -215,7 +219,8 @@ const describeCases = config => {
experiments: {
asyncWebAssembly: true,
topLevelAwait: true,
backCompat: false,
// CHANGE: rspack does not support `backCompat` yet.
// backCompat: false,
// CHANGE: Rspack enables `css` by default.
// Turning off here to fallback to webpack's default css processing logic.

Expand Down Expand Up @@ -321,7 +326,7 @@ const describeCases = config => {
testName + " should compile",
done => {
infraStructureLog.length = 0;
const webpack = require("@rspack/core").rspack;
const webpack = require("..");
const compiler = webpack(options);
const run = () => {
const deprecationTracker = deprecationTracking.start();
Expand Down
7 changes: 7 additions & 0 deletions packages/rspack/tests/TestCasesNormal.basictest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { describeCases } = require("./TestCases.template");

describe("TestCases", () => {
describeCases({
name: "normal"
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ exports[`ConfigTestCases chunk-index available-modules-order-index exported test
"
`;

exports[`ConfigTestCases css rewrite-url exported tests should rewrite the css url() 1`] = `"eb587e4780c414fe3a22.png"`;

exports[`ConfigTestCases css rewrite-url exported tests should rewrite the css url() 2`] = `"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAOCAYAAAAbvf3sAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAEWSURBVHgBjZFRSsNAEIb/3fQAOUK9gfpe6YIovjU3UE+gJ2g8gTcw3sC+itUFrW+BeAN7ATFSKAjbHWcSC+mSlszLDrvfzvzzj0LHmNpZBtBQd4Gf7fuYgHPPueoCe1DK1UsHd7Dzw+P0daQj/SC5h09OzdGktw221vZXUBlVMN0ILPd6O9yzBBXX8CBdv6kWOGa4YLivQJNjM0ia73oTLsBwJjCB5gu4i7CgbsIey5ThEcOfKziTGFOGHypJeZ7jZ/Gbst4x2/fN9h2eGTNvgk92VrDEWLNmfJXLpIYrRy5b4Fs+9v2/pL0oUncI7FuHLI6PK5lJZGoe8qXNvrry27DesoRLpLPmNkTw9yEcxPWJMR+S/AFbfpAZqxwUNQAAAABJRU5ErkJggg=="`;

exports[`ConfigTestCases css rewrite-url-css-variables exported tests should rewrite the css url() in css variables 1`] = `"eb587e4780c414fe3a22.png"`;

exports[`ConfigTestCases css rewrite-url-css-variables exported tests should rewrite the css url() in css variables 2`] = `"eb587e4780c414fe3a22.png"`;

exports[`ConfigTestCases css rewrite-url-with-css-filename exported tests should rewrite the css url() with publicPath and ~@ prefix 1`] = `"/image/logo.eb587e47.png"`;

exports[`ConfigTestCases css rewrite-url-with-css-filename exported tests should rewrite the css url() with publicPath when output.cssFilename is set 1`] = `"/image/logo.eb587e47.png"`;

exports[`ConfigTestCases css urls exported tests css urls should works 1`] = `
"/* @supports (background-image: url("unknown.png")) {
div {
Expand Down Expand Up @@ -301,3 +313,27 @@ exports[`ConfigTestCases plugins chunk-modules exported tests chunk-modules 1`]
},
}
`;
exports[`ConfigTestCases schemes data-imports exported tests data imports 1`] = `
".red{color: red;}
.b{color: green}
.a { color: palegreen; };;;
.bad {
a: url(data:text/bad-base64;base64,abcd?#iefix);
b: url("data:text/bad-base64;base64, abcd?#iefix");
}
/* .b{color: green} */
.class {
a: url(bd595024fc7e226eea64.svg);
b: url(bd595024fc7e226eea64.svg);
c: url(bd595024fc7e226eea64);
d: url(bd595024fc7e226eea64);
}
"
`;
18 changes: 0 additions & 18 deletions packages/rspack/tests/cases/hooks/entryOption/package.json

This file was deleted.

18 changes: 0 additions & 18 deletions packages/rspack/tests/cases/hooks/stillValidModule/package.json

This file was deleted.

18 changes: 0 additions & 18 deletions packages/rspack/tests/cases/hooks/succeedModule/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/rspack/tests/cases/hooks/succeedModule/src/index.js

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ module.exports = {
"polyfill for auto public path in target: 'node'",
async assets => {
compilation.updateAsset(
"main.js",
"bundle0.js",
new ConcatSource(
new RawSource(
`globalThis = { document: { currentScript: { src: "/" } } };\n`
),
assets["main.js"]
assets["bundle0.js"]
)
);
}
);
});
}
}
]
],
experiments: {
css: true
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require("fs");
const path = require("path");

it("should rewrite the css url() in css variables", function () {
const css = fs.readFileSync(path.resolve(__dirname, "main.css"), "utf-8");
const css = fs.readFileSync(path.resolve(__dirname, "bundle0.css"), "utf-8");
const a = /--a: url\((.*)\);/.exec(css)[1];
expect(a.startsWith("./")).toBe(false);
expect(a.includes("./logo.png")).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ module.exports = {
type: "asset"
}
]
},
experiments: {
css: true
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require("fs");
const path = require("path");

it("should rewrite the css url()", function () {
const css = fs.readFileSync(path.resolve(__dirname, "main.css"), "utf-8");
const css = fs.readFileSync(path.resolve(__dirname, "bundle0.css"), "utf-8");
const a = /a: url\((.*)\);/.exec(css)[1];
expect(a).toBe("https://test.rspack.dev/cdn/logo.png");
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ module.exports = {
}
}
]
},
experiments: {
css: true
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ module.exports = {
}
}
]
},
experiments: {
css: true
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ module.exports = {
}
}
]
},
experiments: {
css: true
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require("fs");
const path = require("path");

it("should rewrite the css url()", function () {
const css = fs.readFileSync(path.resolve(__dirname, "main.css"), "utf-8");
const css = fs.readFileSync(path.resolve(__dirname, "bundle0.css"), "utf-8");
const a = /a: url\((.*)\);/.exec(css)[1];
expect(a.startsWith("./")).toBe(false);
expect(a.includes("./logo.png")).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ module.exports = {
type: "asset"
}
]
},
experiments: {
css: true
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const fs = require("fs");
const path = require("path");

it("should build success", () => {
const css = fs.readFileSync(path.resolve(__dirname, "./main.css"), "utf-8");
const css = fs.readFileSync(
path.resolve(__dirname, "./bundle0.css"),
"utf-8"
);
const invalidRaw =
"data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAQAQAABAAARkZUTZA8qYoAACe8AAAAHEdERUY";
expect(css.includes(invalidRaw)).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experiments: {
css: true
}
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
it("should exec fn which defined `index.js` success", () => {
globalThis.getNumberOne = function () {
global.getNumberOne = function () {
return 1;
};
expect(getNumberTwo()).toBe(2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
globalThis.getNumberTwo = function () {
global.getNumberTwo = function () {
return 2;
};
it("should success exec function from before.js", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
// target: "node",
entry: ["./before.js", "./index.js"]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
findBundle() {
return ["main.js", "test.js"];
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ class MyEntryOptionPlugin {
assert(context === config.context, "Context is not equal.");
assert.deepStrictEqual(
entry,
config.entry,
Object.keys(config.entry).reduce((acc, key) => {
acc[key] = { import: [config.entry[key]] };
return acc;
}, {}),
"Entry is not strictly equal."
);
});
Expand All @@ -21,6 +24,9 @@ const config = {
main: "./src/index.js",
test: "./src/index2.js"
},
output: {
filename: "[name].js"
},
plugins: [new MyEntryOptionPlugin()]
};
module.exports = config;
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { answer } from "./answer";
console.log(`hello ${answer}`);
it("should work", () => {});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const MyStillValidModulePlugin = require("./plugins/MyStillValidModulePlugin");
const config = {
context: __dirname,
mode: "development",
watch: true,
entry: {
main: "./src/index.js"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { answer } from "./answer";

try {
require(`./child/${a}.js`);
} catch (e) {}
console.log(`hello ${answer}`);
it("should work", () => {});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const MySucceedModulePlugin = require("./plugins/MySucceedModulePlugin");
const config = {
context: __dirname,
mode: "development",
watch: true,
entry: {
main: "./src/index.js"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
Loading

0 comments on commit d799301

Please sign in to comment.