Skip to content

Commit 54dc975

Browse files
committed
Add test cases so message output can be tweaked with confidence
1 parent 98a875a commit 54dc975

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`formats various webpack errors correctly eslint errors 1`] = `
4+
Object {
5+
"errors": Array [
6+
"./template/src/App.js
7+
Line 8: 'c' is not defined no-undef
8+
9+
Search for the keywords to learn more about each error.",
10+
],
11+
"warnings": Array [],
12+
}
13+
`;
14+
15+
exports[`formats various webpack errors correctly eslint warning 1`] = `
16+
Object {
17+
"errors": Array [],
18+
"warnings": Array [
19+
"./template/src/App.js
20+
Line 7: 'unUsed' is defined but never used no-unused-vars",
21+
],
22+
}
23+
`;
24+
25+
exports[`formats various webpack errors correctly export not found 1`] = `
26+
Object {
27+
"errors": Array [
28+
"./template/src/index.js 1:182-185
29+
'./App' does not contain an export named 'App'.",
30+
],
31+
"warnings": Array [],
32+
}
33+
`;
34+
35+
exports[`formats various webpack errors correctly invalid css syntax 1`] = `
36+
Object {
37+
"errors": Array [
38+
"./template/src/App.css
39+
Syntax error: (19:1) Unexpected }
40+
41+
17 | font-size: calc(10px + 2vmin);
42+
18 | color: white;
43+
> 19 | }
44+
| ^
45+
20 |
46+
21 | .App-link {",
47+
],
48+
"warnings": Array [],
49+
}
50+
`;
51+
52+
exports[`formats various webpack errors correctly invalid js syntax (babel) 1`] = `
53+
Object {
54+
"errors": Array [
55+
"./template/src/App.js
56+
Syntax error: Expected corresponding JSX closing tag for <div> (10:27)
57+
58+
8 | render() {
59+
9 | return (
60+
> 10 | <div className=\\"App\\"></p>
61+
| ^
62+
11 | <header className=\\"App-header\\">
63+
12 | <img src={logo} className=\\"App-logo\\" alt=\\"logo\\" />
64+
13 | <p>",
65+
],
66+
"warnings": Array [],
67+
}
68+
`;
69+
70+
exports[`formats various webpack errors correctly module not found 1`] = `
71+
Object {
72+
"errors": Array [
73+
"./template/src/App.js
74+
Module not found: Can't resolve 'blabla' in '/Users/joe/Documents/Development/OSS/create-react-app/packages/react-scripts/template/src'",
75+
],
76+
"warnings": Array [
77+
"./template/src/App.js
78+
Line 5: 'bla' is defined but never used no-unused-vars",
79+
],
80+
}
81+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
const formatWebpackMessages = require('../formatWebpackMessages');
11+
12+
// TODO: test these messages by actually running a build so we can validate
13+
// webpack upgrades didn't break any of our massaging
14+
describe('formats various webpack errors correctly', () => {
15+
it('invalid js syntax (babel)', () => {
16+
const json = {
17+
errors: [
18+
'./template/src/App.js\nModule Error (from /Users/joe/Documents/Development/OSS/create-react-app/node_modules/thread-loader/dist/cjs.js):\n\n Line 10: Parsing error: Expected corresponding JSX closing tag for <div>\n\n 8 | render() {\n 9 | return (\n> 10 | <div className="App"></p>\n | ^\n 11 | <header className="App-header">\n 12 | <img src={logo} className="App-logo" alt="logo" />\n 13 | <p>\n\n\n @ ./template/src/index.js 1:77-100 1:182-185\n @ multi ./config/polyfills.js ./template/src/index.js',
19+
'./template/src/App.js\nModule build failed (from /Users/joe/Documents/Development/OSS/create-react-app/node_modules/thread-loader/dist/cjs.js):\nThread Loader (Worker 0)\n/Users/joe/Documents/Development/OSS/create-react-app/packages/react-scripts/template/src/App.js: Expected corresponding JSX closing tag for <div> (10:27)\n\n 8 | render() {\n 9 | return (\n> 10 | <div className="App"></p>\n | ^\n 11 | <header className="App-header">\n 12 | <img src={logo} className="App-logo" alt="logo" />\n 13 | <p>\n\n at _class.raise (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/@babel/core/node_modules/babylon/lib/index.js:779:15)\n at _class.jsxParseElementAt (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/@babel/core/node_modules/babylon/lib/index.js:8111:18)\n at _class.jsxParseElement (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/@babel/core/node_modules/babylon/lib/index.js:8137:19)\n at _class.parseExprAtom (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/@babel/core/node_modules/babylon/lib/index.js:8144:21)\n at _class.parseExprSubscripts (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/@babel/core/node_modules/babylon/lib/index.js:2758:21)\n at _class.parseMaybeUnary (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/@babel/core/node_modules/babylon/lib/index.js:2737:21)\n at _class.parseExprOps (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/@babel/core/node_modules/babylon/lib/index.js:2646:21)\n at _class.parseMaybeConditional (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/@babel/core/node_modules/babylon/lib/index.js:2618:21)\n at _class.parseMaybeAssign (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/@babel/core/node_modules/babylon/lib/index.js:2565:21)\n at _class.parseMaybeAssign (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/@babel/core/node_modules/babylon/lib/index.js:7270:57)\n @ ./template/src/index.js 1:77-100 1:182-185\n @ multi ./config/polyfills.js ./template/src/index.js',
20+
],
21+
warnings: [],
22+
};
23+
24+
expect(formatWebpackMessages(json)).toMatchSnapshot();
25+
});
26+
27+
it('invalid css syntax', () => {
28+
const json = {
29+
errors: [
30+
'./template/src/App.css\nModule build failed (from /Users/joe/Documents/Development/OSS/create-react-app/node_modules/mini-css-extract-plugin/dist/loader.js):\nModuleBuildError: Module build failed (from /Users/joe/Documents/Development/OSS/create-react-app/node_modules/postcss-loader/lib/index.js):\nSyntax Error \n\n(19:1) Unexpected }\n\n 17 | font-size: calc(10px + 2vmin);\n 18 | color: white;\n> 19 | }\n | ^\n 20 | \n 21 | .App-link {\n\n at runLoaders (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/webpack/lib/NormalModule.js:286:20)\n at /Users/joe/Documents/Development/OSS/create-react-app/node_modules/loader-runner/lib/LoaderRunner.js:364:11\n at /Users/joe/Documents/Development/OSS/create-react-app/node_modules/loader-runner/lib/LoaderRunner.js:230:18\n at context.callback (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/loader-runner/lib/LoaderRunner.js:111:13)\n at Promise.resolve.then.then.catch (/Users/joe/Documents/Development/OSS/create-react-app/node_modules/postcss-loader/lib/index.js:194:44)\n at <anonymous>\n @ ./template/src/App.js 1:1905-1923\n @ ./template/src/index.js\n @ multi ./config/polyfills.js ./template/src/index.js',
31+
],
32+
warnings: [],
33+
};
34+
35+
expect(formatWebpackMessages(json)).toMatchSnapshot();
36+
});
37+
38+
it('module not found', () => {
39+
const json = {
40+
errors: [
41+
"./template/src/App.js\nModule not found: Error: Can't resolve 'blabla' in '/Users/joe/Documents/Development/OSS/create-react-app/packages/react-scripts/template/src'\n @ ./template/src/App.js 5:0-25\n @ ./template/src/index.js\n @ multi ./config/polyfills.js ../react-dev-utils/webpackHotDevClient.js ./template/src/index.js",
42+
],
43+
warnings: [
44+
"./template/src/App.js\nModule Warning (from /Users/joe/Documents/Development/OSS/create-react-app/node_modules/thread-loader/dist/cjs.js):\n\n \u001b[1mLine 5:\u001b[22m 'bla' is defined but never used \u001b[33m\u001b[4mno-unused-vars\u001b[24m\u001b[39m\n\n\n @ ./template/src/index.js 5:0-24 7:36-39\n @ multi ./config/polyfills.js ../react-dev-utils/webpackHotDevClient.js ./template/src/index.js",
45+
],
46+
};
47+
48+
expect(formatWebpackMessages(json)).toMatchSnapshot();
49+
});
50+
51+
it('eslint errors', () => {
52+
const json = {
53+
errors: [
54+
"./template/src/App.js\nModule Error (from /Users/joe/Documents/Development/OSS/create-react-app/node_modules/thread-loader/dist/cjs.js):\n\n \u001b[1mLine 8:\u001b[22m 'c' is not defined \u001b[31m\u001b[4mno-undef\u001b[24m\u001b[39m\n\nSearch for the \u001b[4m\u001b[31mkeywords\u001b[39m\u001b[24m to learn more about each error.\n @ ./template/src/index.js 1:77-100 1:182-185\n @ multi ./config/polyfills.js ./template/src/index.js",
55+
],
56+
warnings: [],
57+
};
58+
59+
expect(formatWebpackMessages(json)).toMatchSnapshot();
60+
});
61+
62+
it('eslint warning', () => {
63+
const json = {
64+
errors: [],
65+
warnings: [
66+
"./template/src/App.js\nModule Warning (from /Users/joe/Documents/Development/OSS/create-react-app/node_modules/thread-loader/dist/cjs.js):\n\n \u001b[1mLine 7:\u001b[22m 'unUsed' is defined but never used \u001b[33m\u001b[4mno-unused-vars\u001b[24m\u001b[39m\n\n\n @ ./template/src/index.js 1:77-100 1:182-185\n @ multi ./config/polyfills.js ./template/src/index.js",
67+
],
68+
};
69+
70+
expect(formatWebpackMessages(json)).toMatchSnapshot();
71+
});
72+
73+
it('export not found', () => {
74+
const json = {
75+
errors: [
76+
"./template/src/index.js 1:182-185\n\"export 'App' was not found in './App'\n @ multi ./config/polyfills.js ./template/src/index.js",
77+
],
78+
warnings: [],
79+
};
80+
81+
expect(formatWebpackMessages(json)).toMatchSnapshot();
82+
});
83+
});

0 commit comments

Comments
 (0)