Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(index): emit
warnings
as an instance of {Error}
instead of `{…
…String}`
- Loading branch information
1 parent
a3f21db
commit 6eb82be
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
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,14 @@ | ||
class Warning extends Error { | ||
constructor (warning) { | ||
super() | ||
|
||
const { line, column, text } = warning | ||
|
||
this.name = 'LoaderWarning' | ||
this.message = `\n(${line}:${column}) ${text}\n` | ||
|
||
this.stack = false | ||
} | ||
} | ||
|
||
module.exports = Warning |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { webpack } = require('@webpack-utilities/test') | ||
|
||
const plugin = (options = {}) => (css, result) => { | ||
css.walkDecls((node) => { | ||
node.warn(result, '<Message>') | ||
}) | ||
} | ||
|
||
describe('Warnings', () => { | ||
test('Plugins', () => { | ||
const config = { | ||
loader: { | ||
test: /\.css$/, | ||
options: { | ||
plugins: [ | ||
plugin() | ||
] | ||
} | ||
} | ||
} | ||
|
||
return webpack('css/index.js', config).then((stats) => { | ||
const warning = stats.compilation.warnings[0] | ||
|
||
const message = warning.message | ||
.split('\n') | ||
.slice(1) | ||
.join('\n') | ||
|
||
expect(message).toMatchSnapshot() | ||
}) | ||
}) | ||
}) | ||
|
||
process.on('warning', (warning) => console.warn(warning)) |
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,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Warnings Plugins 1`] = ` | ||
" | ||
(1:5) <Message> | ||
" | ||
`; |