Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(webpack-test): add back two test case #9152

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/actions/pnpm-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ runs:
if: ${{ inputs.node-version != '16' }}
shell: bash
run: |
corepack enable

npm i -g --force corepack && which -a corepack && corepack enable
# https://pnpm.io/continuous-integration#github-actions
# Uses `packageManagement` field from package.json
- name: Install pnpm
Expand Down
116 changes: 68 additions & 48 deletions tests/webpack-test/Compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ const { normalizeFilteredTestName, FilteredStatus } = require("./lib/util/filter

describe("Compiler", () => {
jest.setTimeout(20000);
function compile(entry, options, callback) {
function compile(entry, options, callback, done = () => {}) {
const noOutputPath = !options.output || !options.output.path;
const webpack = require("@rspack/core");
options = webpack.config.getNormalizedWebpackOptions(options);
if (!options.mode) options.mode = "production";
options.entry = entry;
options.context = path.join(__dirname, "fixtures");
if (noOutputPath) options.output.path = "/";
// CHANGE: The pathinfo is currently not supported in rspack
// options.output.pathinfo = true;
options.output.pathinfo = true;
options.optimization = {
minimize: false
};
Expand Down Expand Up @@ -81,7 +80,11 @@ describe("Compiler", () => {
stats.logs = logs;
c.close(err => {
if (err) return callback(err);
callback(stats, files, compilation);
try {
callback(stats, files, compilation);
} catch (e) {
done(e);
}
});
});
}
Expand Down Expand Up @@ -117,6 +120,7 @@ describe("Compiler", () => {
});

// CHANGE: skip due to Rspack defaults to numerical module ids, unlike webpack's string-based ids
// TODO: ModuleInfoHeaderPlugin
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should compile a single file"), done => {
compile("./c", {}, (stats, files) => {
expect(Object.keys(files)).toEqual(["/main.js"]);
Expand All @@ -132,56 +136,74 @@ describe("Compiler", () => {
expect(bundle).not.toMatch("jsonp");
expect(bundle).not.toMatch("fixtures");
done();
});
},
done
);
});

// CHANGE: skip with custom test name for tracking alignment status
// TODO: ModuleInfoHeaderPlugin
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should compile a complex file"), done => {
compile("./main1", {}, (stats, files) => {
expect(Object.keys(files)).toEqual(["/main.js"]);
const bundle = files["/main.js"];
expect(bundle).toMatch("function __webpack_require__(");
expect(bundle).toMatch("__webpack_require__(/*! ./a */");
expect(bundle).toMatch("./main1.js");
expect(bundle).toMatch("./a.js");
expect(bundle).toMatch("./b.js");
expect(bundle).toMatch("./node_modules/m1/a.js");
expect(bundle).toMatch("This is a");
expect(bundle).toMatch("This is b");
expect(bundle).toMatch("This is m1/a");
expect(bundle).not.toMatch("4: function(");
expect(bundle).not.toMatch("window");
expect(bundle).not.toMatch("jsonp");
expect(bundle).not.toMatch("fixtures");
done();
});
compile(
"./main1",
{},
(stats, files) => {
expect(Object.keys(files)).toEqual(["/main.js"]);
const bundle = files["/main.js"];
expect(bundle).toMatch("function __webpack_require__(");
expect(bundle).toMatch("__webpack_require__(/*! ./a */");
expect(bundle).toMatch("./main1.js");
expect(bundle).toMatch("./a.js");
expect(bundle).toMatch("./b.js");
expect(bundle).toMatch("./node_modules/m1/a.js");
expect(bundle).toMatch("This is a");
expect(bundle).toMatch("This is b");
expect(bundle).toMatch("This is m1/a");
expect(bundle).not.toMatch("4: function(");
expect(bundle).not.toMatch("window");
expect(bundle).not.toMatch("jsonp");
expect(bundle).not.toMatch("fixtures");
done();
},
done
);
});

// CHANGE: skip with custom test name for tracking alignment status
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should compile a file with transitive dependencies"), done => {
compile("./abc", {}, (stats, files) => {
expect(Object.keys(files)).toEqual(["/main.js"]);
const bundle = files["/main.js"];
expect(bundle).toMatch("function __webpack_require__(");
expect(bundle).toMatch("__webpack_require__(/*! ./a */");
expect(bundle).toMatch("__webpack_require__(/*! ./b */");
expect(bundle).toMatch("__webpack_require__(/*! ./c */");
expect(bundle).toMatch("./abc.js");
expect(bundle).toMatch("./a.js");
expect(bundle).toMatch("./b.js");
expect(bundle).toMatch("./c.js");
expect(bundle).toMatch("This is a");
expect(bundle).toMatch("This is b");
expect(bundle).toMatch("This is c");
expect(bundle).not.toMatch("4: function(");
expect(bundle).not.toMatch("window");
expect(bundle).not.toMatch("jsonp");
expect(bundle).not.toMatch("fixtures");
done();
});
// TODO: ModuleInfoHeaderPlugin.js
it.skip(normalizeFilteredTestName(
FilteredStatus.TODO,
"should compile a file with transitive dependencies"
), done => {
compile(
"./abc",
{},
(stats, files) => {
expect(Object.keys(files)).toEqual(["/main.js"]);
const bundle = files["/main.js"];
expect(bundle).toMatch("function __webpack_require__(");
expect(bundle).toMatch("__webpack_require__(/*! ./a */");
expect(bundle).toMatch("__webpack_require__(/*! ./b */");
expect(bundle).toMatch("__webpack_require__(/*! ./c */");
expect(bundle).toMatch("./abc.js");
expect(bundle).toMatch("./a.js");
expect(bundle).toMatch("./b.js");
expect(bundle).toMatch("./c.js");
expect(bundle).toMatch("This is a");
expect(bundle).toMatch("This is b");
expect(bundle).toMatch("This is c");
expect(bundle).not.toMatch("4: function(");
expect(bundle).not.toMatch("window");
expect(bundle).not.toMatch("jsonp");
expect(bundle).not.toMatch("fixtures");
done();
},
done
);
});

// CHANGE: skip with custom test name for tracking alignment status
// TODO: ModuleInfoHeaderPlugin CodeSplitting
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should compile a file with multiple chunks"), done => {
compile("./chunks", {}, (stats, files) => {
expect(stats.chunks).toHaveLength(2);
Expand Down Expand Up @@ -699,7 +721,7 @@ describe("Compiler", () => {
});
// CHANGE: skip with custom test name for tracking alignment status
// CHANGE: skip due to panic occurred at runtime
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should call afterDone hook after other callbacks (watch)"), done => {
it("should call afterDone hook after other callbacks (watch)", done => {
const webpack = require("@rspack/core");
compiler = webpack({
context: __dirname,
Expand Down Expand Up @@ -788,9 +810,7 @@ describe("Compiler", () => {
});
});
});
// CHANGE: skip with custom test name for tracking alignment status
// CHANGE: skip due to panic occurred at runtime
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should use cache on second run call"), done => {
it("should use cache on second run call", done => {
const webpack = require("@rspack/core");
compiler = webpack({
context: __dirname,
Expand Down
1 change: 1 addition & 0 deletions tests/webpack-test/fixtures/node_modules/complexm/step1.js

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

1 change: 1 addition & 0 deletions tests/webpack-test/fixtures/node_modules/complexm/step2.js

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

3 changes: 3 additions & 0 deletions tests/webpack-test/fixtures/node_modules/m1/a.js

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

3 changes: 3 additions & 0 deletions tests/webpack-test/fixtures/node_modules/m1/b.js

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

3 changes: 3 additions & 0 deletions tests/webpack-test/fixtures/node_modules/m2-loader/b.js

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

1 change: 1 addition & 0 deletions tests/webpack-test/fixtures/node_modules/m2/b.js

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

Loading