-
-
Notifications
You must be signed in to change notification settings - Fork 732
test: align more test cases with webpack #11834
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fc1ee00
test: align more test cases with webpack
LingyuCoder a6e9e69
test: align more test cases with webpack
LingyuCoder 7f403c3
test: align more test cases with webpack
LingyuCoder eb077e9
test: align more test cases with webpack
LingyuCoder 7422dc1
test: align more test cases with webpack
LingyuCoder 20d25d4
test: align more test cases with webpack
LingyuCoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| const { createDevNormalCase, describeByWalk } = require("@rspack/test-tools"); | ||
| const path = require("path"); | ||
|
|
||
| describeByWalk(__filename, (name, src, dist) => { | ||
| createDevNormalCase(name, src, dist); | ||
| }, { | ||
| source: path.resolve(__dirname, "./normalCases"), | ||
| dist: path.resolve(__dirname, `./js/normal-dev`), | ||
| exclude: [ | ||
| /parsing\/harmony-deep-exports/, | ||
| /parsing\/asi/ | ||
| ] | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| const { createProdNormalCase, describeByWalk } = require("@rspack/test-tools"); | ||
| const path = require("path"); | ||
|
|
||
| describeByWalk(__filename, (name, src, dist) => { | ||
| createProdNormalCase(name, src, dist); | ||
| }, { | ||
| source: path.resolve(__dirname, "./normalCases"), | ||
| dist: path.resolve(__dirname, `./js/normal-prod`), | ||
| // FIXME: these cases throw errors in production | ||
| exclude: [ | ||
| /warnings\/require-as-expression/, | ||
| /side-effects\/empty-modules/, | ||
| /parsing\/resolve-weak-context/, | ||
| /parsing\/issue-7519/, | ||
| /parsing\/api/, | ||
| /mjs\/cjs-import-default/, | ||
| /inner-graph\/simple/ | ||
| ] | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| const rspack = require("@rspack/core"); | ||
| const fs = require("fs"); | ||
|
|
||
| let lastStats = null; | ||
| /** @type {import('@rspack/test-tools').TCompilerCaseConfig[]} */ | ||
| module.exports = [{ | ||
| description: "should cache assets", | ||
| options(context) { | ||
| return { | ||
| mode: "development", | ||
| entry: { | ||
| entry1: context.getDist("entry1.js"), | ||
| entry2: context.getDist("entry2.js") | ||
| }, | ||
| output: { | ||
| path: context.getDist("dist") | ||
| }, | ||
| plugins: [new rspack.BannerPlugin("banner is a string")] | ||
| }; | ||
| }, | ||
| async compiler(context, compiler) { | ||
| compiler.outputFileSystem = fs; | ||
| fs.writeFileSync(context.getDist("entry1.js"), "1", "utf-8"); | ||
| fs.writeFileSync(context.getDist("entry2.js"), "1", "utf-8"); | ||
| }, | ||
| async build(context, compiler) { | ||
| return new Promise((resolve, reject) => { | ||
| compiler.run((err, stats) => { | ||
| if (err) return reject(err); | ||
| try { | ||
| const footerFileResults = fs.readFileSync(context.getDist("dist/entry1.js"), "utf8").split("\n"); | ||
| expect(footerFileResults[0]).toBe("/*! banner is a string */"); | ||
| fs.writeFileSync(context.getDist("entry2.js"), "2", "utf-8"); | ||
| compiler.run((err, stats) => { | ||
| if (err) return reject(err); | ||
| lastStats = stats; | ||
| resolve(); | ||
| }, { | ||
| modifiedFiles: new Set([context.getDist("entry2.js")]) | ||
| }); | ||
| } catch (err) { | ||
| reject(err); | ||
| } | ||
|
|
||
| }); | ||
| }); | ||
| }, | ||
| async check() { | ||
| const { assets } = lastStats.toJson(); | ||
| expect(assets.find(as => as.name === "entry1.js").emitted).toBe(false); | ||
| expect(assets.find(as => as.name === "entry2.js").emitted).toBe(true); | ||
| } | ||
| }, { | ||
| description: "can place banner as footer", | ||
| options(context) { | ||
| return { | ||
| mode: "development", | ||
| entry: { | ||
| footerFile: context.getDist("footerFile.js") | ||
| }, | ||
| output: { | ||
| path: context.getDist("dist") | ||
| }, | ||
| plugins: [ | ||
| new rspack.BannerPlugin({ | ||
| banner: "banner is a string", | ||
| footer: true | ||
| }) | ||
| ] | ||
| }; | ||
| }, | ||
| async compiler(context, compiler) { | ||
| compiler.outputFileSystem = fs; | ||
| fs.writeFileSync(context.getDist("footerFile.js"), "footer", "utf-8"); | ||
| }, | ||
| async check({ context }) { | ||
| const footerFileResults = fs.readFileSync(context.getDist("dist/footerFile.js"), "utf8").split("\n"); | ||
| expect(footerFileResults.pop()).toBe("/*! banner is a string */"); | ||
| } | ||
| }]; | ||
131 changes: 131 additions & 0 deletions
131
tests/rspack-test/compilerCases/changes-and-removals.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| const fs = require("fs"); | ||
|
|
||
| const getChanges = (compiler) => { | ||
| const modifiedFiles = compiler.modifiedFiles; | ||
| const removedFiles = compiler.removedFiles; | ||
| return { | ||
| removed: removedFiles && [...removedFiles], | ||
| modified: modifiedFiles && [...modifiedFiles] | ||
| }; | ||
| }; | ||
|
|
||
| let changes = null; | ||
| /** @type {import('@rspack/test-tools').TCompilerCaseConfig[]} */ | ||
| module.exports = [{ | ||
| description: "should not track modified/removed files during initial watchRun", | ||
| options(context) { | ||
| changes = null; | ||
| return { | ||
| entry: context.getDist("temp-file.js"), | ||
| output: { | ||
| path: context.getDist("dist"), | ||
| filename: "bundle.js" | ||
| }, | ||
| }; | ||
| }, | ||
| async compiler(context, compiler) { | ||
| compiler.hooks.watchRun.tap("ChangesAndRemovalsTest", (compiler) => { | ||
| changes = getChanges(compiler); | ||
| }); | ||
| }, | ||
| async build(context, compiler) { | ||
| return new Promise((resolve, reject) => { | ||
| const watcher = compiler.watch({ aggregateTimeout: 200 }, (err) => { | ||
| if (err) reject(err); | ||
| watcher.close(resolve); | ||
| }); | ||
| }); | ||
| }, | ||
| async check() { | ||
| expect(changes).toEqual({ | ||
| removed: [], | ||
| modified: [] | ||
| }); | ||
| } | ||
| }, { | ||
| description: "should track modified files when they've been modified", | ||
| options(context) { | ||
| changes = null; | ||
| return { | ||
| entry: context.getDist("temp-file.js"), | ||
| output: { | ||
| path: context.getDist("dist"), | ||
| filename: "bundle.js" | ||
| }, | ||
| }; | ||
| }, | ||
| async build(context, compiler) { | ||
| let firstWatchRun = true; | ||
| let firstDone = true; | ||
| return new Promise((resolve, reject) => { | ||
| let watcher = null; | ||
| compiler.hooks.watchRun.tap("ChangesAndRemovalsTest", (compiler) => { | ||
| if (firstWatchRun) { | ||
| firstWatchRun = false; | ||
| return; | ||
| } | ||
| changes = getChanges(compiler); | ||
| watcher.close(resolve); | ||
| }); | ||
| compiler.hooks.done.tap("ChangesAndRemovalsTest", () => { | ||
| if (!firstDone) return; | ||
| firstDone = false; | ||
| setTimeout(() => { | ||
| fs.appendFileSync(context.getDist("temp-file.js"), "\nlet x = 'file modified';"); | ||
| }, 300); | ||
| }); | ||
| watcher = compiler.watch({ aggregateTimeout: 200 }, (err) => { | ||
| if (err) reject(err); | ||
| }); | ||
| }); | ||
| }, | ||
| async check({ context }) { | ||
| expect(changes).toEqual({ | ||
| removed: [], | ||
| modified: [context.getDist("temp-file.js")] | ||
| }); | ||
| } | ||
| }, { | ||
| description: "should track removed file when removing file", | ||
| options(context) { | ||
| changes = null; | ||
| return { | ||
| entry: context.getDist("temp-file.js"), | ||
| output: { | ||
| path: context.getDist("dist"), | ||
| filename: "bundle.js" | ||
| }, | ||
| }; | ||
| }, | ||
| async build(context, compiler) { | ||
| let firstWatchRun = true; | ||
| let firstDone = true; | ||
| return new Promise((resolve, reject) => { | ||
| let watcher = null; | ||
| compiler.hooks.watchRun.tap("ChangesAndRemovalsTest", (compiler) => { | ||
| if (firstWatchRun) { | ||
| firstWatchRun = false; | ||
| return; | ||
| } | ||
| changes = getChanges(compiler); | ||
| watcher.close(resolve); | ||
| }); | ||
| compiler.hooks.done.tap("ChangesAndRemovalsTest", () => { | ||
| if (!firstDone) return; | ||
| firstDone = false; | ||
| setTimeout(() => { | ||
| fs.unlinkSync(context.getDist("temp-file.js")); | ||
| }, 300); | ||
| }); | ||
| watcher = compiler.watch({ aggregateTimeout: 200 }, (err) => { | ||
| if (err) reject(err); | ||
| }); | ||
| }); | ||
| }, | ||
| async check({ context }) { | ||
| expect(changes).toEqual({ | ||
| removed: [context.getDist("temp-file.js")], | ||
| modified: [] | ||
| }); | ||
| } | ||
| }]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.