|
| 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