-
-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add setters for errors and warnings in Compilation
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
packages/rspack-test-tools/tests/errorCases/error-test-set.js
This file contains 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,38 @@ | ||
/** @type {import('../..').TErrorCaseConfig} */ | ||
module.exports = { | ||
description: "Testing set errors", | ||
options() { | ||
return { | ||
entry: "./resolve-fail-esm", | ||
plugins: [ | ||
compiler => { | ||
compiler.hooks.afterCompile.tap("set errors", compilation => { | ||
compilation.errors = [ | ||
new Error("error 1"), | ||
new Error("error 2") | ||
]; | ||
}); | ||
} | ||
] | ||
}; | ||
}, | ||
async check(diagnostics) { | ||
expect(diagnostics).toMatchInlineSnapshot(` | ||
Object { | ||
"errors": Array [ | ||
Object { | ||
"message": " × Error: error 1\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", | ||
"moduleTrace": Array [], | ||
"stack": "Error: error 1\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/error-test-set.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>", | ||
}, | ||
Object { | ||
"message": " × Error: error 2\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", | ||
"moduleTrace": Array [], | ||
"stack": "Error: error 2\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/error-test-set.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>", | ||
}, | ||
], | ||
"warnings": Array [], | ||
} | ||
`); | ||
} | ||
}; |
38 changes: 38 additions & 0 deletions
38
packages/rspack-test-tools/tests/errorCases/warning-test-set.js
This file contains 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,38 @@ | ||
/** @type {import('../..').TErrorCaseConfig} */ | ||
module.exports = { | ||
description: "Testing set warnings", | ||
options() { | ||
return { | ||
entry: "./require.main.require", | ||
plugins: [ | ||
compiler => { | ||
compiler.hooks.afterCompile.tap("set warnings", compilation => { | ||
compilation.warnings = [ | ||
new Error("warning 1"), | ||
new Error("warning 2") | ||
]; | ||
}); | ||
} | ||
] | ||
}; | ||
}, | ||
async check(diagnostics) { | ||
expect(diagnostics).toMatchInlineSnapshot(` | ||
Object { | ||
"errors": Array [], | ||
"warnings": Array [ | ||
Object { | ||
"message": " ⚠ Error: warning 1\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", | ||
"moduleTrace": Array [], | ||
"stack": "Error: warning 1\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/warning-test-set.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>", | ||
}, | ||
Object { | ||
"message": " ⚠ Error: warning 2\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", | ||
"moduleTrace": Array [], | ||
"stack": "Error: warning 2\\n at Object.fn (<cwd>packages/rspack-test-tools/tests/errorCases/warning-test-set.js:<line>:<col>)\\n at next (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsyncStageRange (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at AsyncSeriesHook.callAsync (<cwd>node_modules/.pnpm/@rspack+lite-tapable@1.0.1/node_modules/@rspack/lite-tapable/dist/index.js:<line>:<col>)\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>\\n at <cwd>packages/rspack/dist/index.js:<line>:<col>", | ||
}, | ||
], | ||
} | ||
`); | ||
} | ||
}; |
This file contains 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 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