mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-30 02:15:52 +08:00
Polish webpack message output (#5174)
* Only install react-scripts in CI mode
* Link locally
* Re-enable all output tests
* 💄 Polish webpack output
* Test sass support message
* Add more tests, but disabled
* Format missing default export error
* Format aliased import
* Why was node-sass required? Odd
* Format webpack rejection error
* Re-enable unknown package test
* Format file not found error and catch module scope plugin error
* Re-disable case sensitive paths
* Intercept and format case sensitive path errors
* Test out of scope message formatting
* Run behavior on macOS
* Run behavior on Node 8 and 10, only Node 8 for macOS
* Add some debugging
* Update matcher
* Only check stderr
* Remove old snapshot
* More debug
* Remove debug
* Add new debug
* Disable test on linux
* Add comment for future
This commit is contained in:
@@ -1,12 +1,26 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`webpack message formatting formats aliased unknown export 1`] = `
|
||||
Object {
|
||||
"stderr": "Creating an optimized production build...
|
||||
Failed to compile.
|
||||
|
||||
./src/App.js
|
||||
Attempted import error: 'bar' is not exported from './AppUnknownExport' (imported as 'bar2').
|
||||
|
||||
|
||||
",
|
||||
"stdout": "",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`webpack message formatting formats babel syntax error 1`] = `
|
||||
Object {
|
||||
"stderr": "Creating an optimized production build...
|
||||
Failed to compile.
|
||||
|
||||
./src/App.js
|
||||
Syntax error: Unterminated JSX contents (8:12)
|
||||
Syntax error: Unterminated JSX contents (8:13)
|
||||
|
||||
6 | <div>
|
||||
7 | <span>
|
||||
@@ -25,16 +39,16 @@ Syntax error: Unterminated JSX contents (8:12)
|
||||
exports[`webpack message formatting formats css syntax error 1`] = `
|
||||
Object {
|
||||
"stderr": "Creating an optimized production build...
|
||||
[31mFailed to compile.
|
||||
[39m
|
||||
[7m./src/AppCss.css[27m
|
||||
Syntax Error: (3:2) Unexpected }
|
||||
Failed to compile.
|
||||
|
||||
[90m 1 | [39m[33m.App[39m [33m{[39m
|
||||
[90m 2 | [39m color[33m:[39m red[33m;[39m
|
||||
[31m[1m>[22m[39m[90m 3 | [39m[33m}[39m[33m}[39m
|
||||
[90m | [39m [31m[1m^[22m[39m
|
||||
[90m 4 | [39m
|
||||
./src/AppCss.css
|
||||
Syntax error: Unexpected } (3:2)
|
||||
|
||||
1 | .App {
|
||||
2 | color: red;
|
||||
> 3 | }}
|
||||
| ^
|
||||
4 |
|
||||
|
||||
|
||||
",
|
||||
@@ -74,12 +88,58 @@ To ignore, add // eslint-disable-next-line to the line before.
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`webpack message formatting formats file not found error 1`] = `
|
||||
Object {
|
||||
"stderr": "Creating an optimized production build...
|
||||
Failed to compile.
|
||||
|
||||
./src/App.js
|
||||
Cannot find file './ThisFileSouldNotExist' in './src'.
|
||||
|
||||
|
||||
",
|
||||
"stdout": "",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`webpack message formatting formats missing package 1`] = `
|
||||
Object {
|
||||
"stderr": "Creating an optimized production build...
|
||||
[31mFailed to compile.
|
||||
[39m
|
||||
Module not found: Error: Can't resolve 'unknown-package' in '/private/var/folders/c3/vytj6_h56b77f_g72smntm3m0000gn/T/bf26e1d3700ad14275f6eefb5e4417c1/src'
|
||||
Failed to compile.
|
||||
|
||||
./src/App.js
|
||||
Cannot find module: 'unknown-package'. Make sure this package is installed.
|
||||
|
||||
You can install this package by running: yarn add unknown-package.
|
||||
|
||||
|
||||
",
|
||||
"stdout": "",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`webpack message formatting formats no default export 1`] = `
|
||||
Object {
|
||||
"stderr": "Creating an optimized production build...
|
||||
Failed to compile.
|
||||
|
||||
./src/App.js
|
||||
Attempted import error: './ExportNoDefault' does not contain a default export (imported as 'myImport').
|
||||
|
||||
|
||||
",
|
||||
"stdout": "",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`webpack message formatting formats out of scope error 1`] = `
|
||||
Object {
|
||||
"stderr": "Creating an optimized production build...
|
||||
Failed to compile.
|
||||
|
||||
./src/App.js
|
||||
You attempted to import ../OutOfScopeImport which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
|
||||
You can either move it inside src/, or add a symlink to it from project's node_modules/.
|
||||
|
||||
|
||||
",
|
||||
@@ -93,7 +153,22 @@ Object {
|
||||
Failed to compile.
|
||||
|
||||
./src/App.js
|
||||
1:1677-1680 './AppUnknownExport' does not contain an export named 'bar'.
|
||||
Attempted import error: 'bar' is not exported from './AppUnknownExport'.
|
||||
|
||||
|
||||
",
|
||||
"stdout": "",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`webpack message formatting helps when users tries to use sass 1`] = `
|
||||
Object {
|
||||
"stderr": "Creating an optimized production build...
|
||||
Failed to compile.
|
||||
|
||||
./src/AppSass.scss
|
||||
To import Sass files, you first need to install node-sass.
|
||||
Run \`npm install node-sass\` or \`yarn add node-sass\` inside your workspace.
|
||||
|
||||
|
||||
",
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
const { bootstrap, getOutputProduction } = require('../../utils');
|
||||
const {
|
||||
bootstrap,
|
||||
getOutputDevelopment,
|
||||
getOutputProduction,
|
||||
} = require('../../utils');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const Semaphore = require('async-sema');
|
||||
@@ -19,7 +23,7 @@ describe('webpack message formatting', () => {
|
||||
semaphore.release();
|
||||
});
|
||||
|
||||
xit('formats babel syntax error', async () => {
|
||||
it('formats babel syntax error', async () => {
|
||||
fs.copySync(
|
||||
path.join(__dirname, 'src', 'AppBabel.js'),
|
||||
path.join(testDirectory, 'src', 'App.js')
|
||||
@@ -29,8 +33,7 @@ describe('webpack message formatting', () => {
|
||||
expect(response).toMatchSnapshot();
|
||||
});
|
||||
|
||||
xit('formats css syntax error', async () => {
|
||||
// TODO: fix me!
|
||||
it('formats css syntax error', async () => {
|
||||
fs.copySync(
|
||||
path.join(__dirname, 'src', 'AppCss.js'),
|
||||
path.join(testDirectory, 'src', 'App.js')
|
||||
@@ -40,8 +43,7 @@ describe('webpack message formatting', () => {
|
||||
expect(response).toMatchSnapshot();
|
||||
});
|
||||
|
||||
xit('formats unknown export', async () => {
|
||||
// TODO: fix me!
|
||||
it('formats unknown export', async () => {
|
||||
fs.copySync(
|
||||
path.join(__dirname, 'src', 'AppUnknownExport.js'),
|
||||
path.join(testDirectory, 'src', 'App.js')
|
||||
@@ -51,8 +53,27 @@ describe('webpack message formatting', () => {
|
||||
expect(response).toMatchSnapshot();
|
||||
});
|
||||
|
||||
xit('formats missing package', async () => {
|
||||
// TODO: fix me!
|
||||
it('formats aliased unknown export', async () => {
|
||||
fs.copySync(
|
||||
path.join(__dirname, 'src', 'AppAliasUnknownExport.js'),
|
||||
path.join(testDirectory, 'src', 'App.js')
|
||||
);
|
||||
|
||||
const response = await getOutputProduction({ directory: testDirectory });
|
||||
expect(response).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('formats no default export', async () => {
|
||||
fs.copySync(
|
||||
path.join(__dirname, 'src', 'AppNoDefault.js'),
|
||||
path.join(testDirectory, 'src', 'App.js')
|
||||
);
|
||||
|
||||
const response = await getOutputProduction({ directory: testDirectory });
|
||||
expect(response).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('formats missing package', async () => {
|
||||
fs.copySync(
|
||||
path.join(__dirname, 'src', 'AppMissingPackage.js'),
|
||||
path.join(testDirectory, 'src', 'App.js')
|
||||
@@ -85,4 +106,52 @@ describe('webpack message formatting', () => {
|
||||
const response = await getOutputProduction({ directory: testDirectory });
|
||||
expect(response).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('helps when users tries to use sass', async () => {
|
||||
fs.copySync(
|
||||
path.join(__dirname, 'src', 'AppSass.js'),
|
||||
path.join(testDirectory, 'src', 'App.js')
|
||||
);
|
||||
|
||||
const response = await getOutputProduction({ directory: testDirectory });
|
||||
expect(response).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('formats file not found error', async () => {
|
||||
fs.copySync(
|
||||
path.join(__dirname, 'src', 'AppUnknownFile.js'),
|
||||
path.join(testDirectory, 'src', 'App.js')
|
||||
);
|
||||
|
||||
const response = await getOutputProduction({ directory: testDirectory });
|
||||
expect(response).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('formats case sensitive path error', async () => {
|
||||
fs.copySync(
|
||||
path.join(__dirname, 'src', 'AppIncorrectCase.js'),
|
||||
path.join(testDirectory, 'src', 'App.js')
|
||||
);
|
||||
|
||||
const response = await getOutputDevelopment({ directory: testDirectory });
|
||||
if (process.platform === 'darwin') {
|
||||
expect(response.stderr).toMatch(
|
||||
`Cannot find file: 'export5.js' does not match the corresponding name on disk: './src/Export5.js'.`
|
||||
);
|
||||
} else {
|
||||
expect(response.stderr).not.toEqual(''); // TODO: figure out how we can test this on Linux/Windows
|
||||
// I believe getting this working requires we tap into enhanced-resolve
|
||||
// pipeline, which is debt we don't want to take on right now.
|
||||
}
|
||||
});
|
||||
|
||||
it('formats out of scope error', async () => {
|
||||
fs.copySync(
|
||||
path.join(__dirname, 'src', 'AppOutOfScopeImport.js'),
|
||||
path.join(testDirectory, 'src', 'App.js')
|
||||
);
|
||||
|
||||
const response = await getOutputProduction({ directory: testDirectory });
|
||||
expect(response).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"node-sass": "4.x",
|
||||
"react": "latest",
|
||||
"react-dom": "latest",
|
||||
"react-scripts": "latest"
|
||||
"react-dom": "latest"
|
||||
},
|
||||
"browserslist": [
|
||||
">0.2%"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import React, { Component } from 'react';
|
||||
import { bar as bar2 } from './AppUnknownExport';
|
||||
|
||||
class App extends Component {
|
||||
componentDidMount() {
|
||||
bar2();
|
||||
}
|
||||
render() {
|
||||
return <div />;
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import five from './export5';
|
||||
|
||||
class App extends Component {
|
||||
render() {
|
||||
return <div className="App">{five}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import myImport from './ExportNoDefault';
|
||||
|
||||
class App extends Component {
|
||||
render() {
|
||||
return <div className="App">{myImport}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import myImport from '../OutOfScopeImport';
|
||||
|
||||
class App extends Component {
|
||||
render() {
|
||||
return <div className="App">{myImport}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
10
fixtures/output/webpack-message-formatting/src/AppSass.js
Normal file
10
fixtures/output/webpack-message-formatting/src/AppSass.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import './AppSass.scss';
|
||||
|
||||
class App extends Component {
|
||||
render() {
|
||||
return <div className="App" />;
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1,3 @@
|
||||
.App {
|
||||
color: red;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import DefaultExport from './ThisFileSouldNotExist';
|
||||
|
||||
class App extends Component {
|
||||
render() {
|
||||
return <div className="App" />;
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1 @@
|
||||
export default 5;
|
||||
@@ -0,0 +1 @@
|
||||
export const six = 6;
|
||||
Reference in New Issue
Block a user