Skip to content

Commit

Permalink
refactor: improve error (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Sep 25, 2020
1 parent 74231b1 commit c09dad0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export default async function createEvaluator(loaderContext, code, options) {
} catch (error) {
loaderContext.emitError(
new Error(
`Stylus resolver error:\n${error.message}${
`Stylus resolver error: ${error.message}${
webpackResolveError
? `\n\nWebpack resolver error details:\n${webpackResolveError.details}\n\n` +
`Webpack resolver error missing:\n${webpackResolveError.missing}\n\n`
Expand Down Expand Up @@ -298,7 +298,7 @@ export default async function createEvaluator(loaderContext, code, options) {
} catch (error) {
loaderContext.emitError(
new Error(
`Stylus resolver error:\n${error.message}${
`Stylus resolver error: ${error.message}${
webpackResolveError
? `\n\nWebpack resolver error details:\n${webpackResolveError.details}\n\n` +
`Webpack resolver error missing:\n${webpackResolveError.missing}\n\n`
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ exports[`loader should compile an @import URL through the CSS loader: warnings 1
exports[`loader should emit error when import loop: errors 1`] = `
Array [
"ModuleError: Module Error (from \`replaced original path\`):
Stylus resolver error:",
Stylus resolver error: import loop has been found",
]
`;

Expand All @@ -316,7 +316,7 @@ exports[`loader should emit error when import loop: warnings 1`] = `Array []`;
exports[`loader should emit error when import self: errors 1`] = `
Array [
"ModuleError: Module Error (from \`replaced original path\`):
Stylus resolver error:",
Stylus resolver error: import loop has been found",
]
`;

Expand All @@ -325,7 +325,7 @@ exports[`loader should emit error when import self: warnings 1`] = `Array []`;
exports[`loader should emit error when unresolved import: errors 1`] = `
Array [
"ModuleError: Module Error (from \`replaced original path\`):
Stylus resolver error:",
Stylus resolver error: failed to locate @import file unresolve.styl",
]
`;

Expand Down
12 changes: 11 additions & 1 deletion test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,17 @@ describe('loader', () => {
const stats = await compile(compiler);

expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
expect(
getErrors(stats).map((item) =>
// Due bug in `node-glob`
process.platform === 'win32'
? item.replace(
'failed to locate @import file self.styl',
'import loop has been found'
)
: item
)
).toMatchSnapshot('errors');
});

it('should emit error when import loop', async () => {
Expand Down

0 comments on commit c09dad0

Please sign in to comment.