Skip to content

Commit

Permalink
Polish webpack message output (#5174)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Timer committed Sep 30, 2018
1 parent 5abff64 commit 7b1a32b
Show file tree
Hide file tree
Showing 27 changed files with 558 additions and 178 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -28,5 +28,8 @@ env:
- TEST_SUITE=behavior
matrix:
include:
- os: osx
node_js: 8
env: TEST_SUITE=behavior
- node_js: 4
env: TEST_SUITE=old-node
@@ -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>
Expand All @@ -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...
Failed to compile.

./src/AppCss.css
Syntax Error: (3:2) Unexpected }
Failed to compile.
 1 | .App {
 2 |  color: red;
> 3 | }}
 |  ^
 4 | 
./src/AppCss.css
Syntax error: Unexpected } (3:2)
1 | .App {
2 | color: red;
> 3 | }}
| ^
4 |
",
Expand Down Expand Up @@ -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...
Failed to compile.

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/.
",
Expand All @@ -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.
",
Expand Down
85 changes: 77 additions & 8 deletions fixtures/output/webpack-message-formatting/index.test.js
@@ -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');
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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();
});
});
4 changes: 1 addition & 3 deletions fixtures/output/webpack-message-formatting/package.json
@@ -1,9 +1,7 @@
{
"dependencies": {
"node-sass": "4.x",
"react": "latest",
"react-dom": "latest",
"react-scripts": "latest"
"react-dom": "latest"
},
"browserslist": [
">0.2%"
Expand Down
@@ -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;
10 changes: 10 additions & 0 deletions fixtures/output/webpack-message-formatting/src/AppIncorrectCase.js
@@ -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;
10 changes: 10 additions & 0 deletions fixtures/output/webpack-message-formatting/src/AppNoDefault.js
@@ -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 changes: 10 additions & 0 deletions fixtures/output/webpack-message-formatting/src/AppSass.js
@@ -0,0 +1,10 @@
import React, { Component } from 'react';
import './AppSass.scss';

class App extends Component {
render() {
return <div className="App" />;
}
}

export default App;
3 changes: 3 additions & 0 deletions fixtures/output/webpack-message-formatting/src/AppSass.scss
@@ -0,0 +1,3 @@
.App {
color: red;
}
10 changes: 10 additions & 0 deletions fixtures/output/webpack-message-formatting/src/AppUnknownFile.js
@@ -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;
1 change: 1 addition & 0 deletions fixtures/output/webpack-message-formatting/src/Export5.js
@@ -0,0 +1 @@
export default 5;
@@ -0,0 +1 @@
export const six = 6;
3 changes: 1 addition & 2 deletions fixtures/smoke/boostrap-sass/package.json
Expand Up @@ -3,7 +3,6 @@
"bootstrap": "4.x",
"node-sass": "4.x",
"react": "latest",
"react-dom": "latest",
"react-scripts": "latest"
"react-dom": "latest"
}
}
3 changes: 1 addition & 2 deletions fixtures/smoke/builds-with-multiple-runtimes/package.json
Expand Up @@ -3,7 +3,6 @@
"dva": "2.4.0",
"ky": "0.3.0",
"react": "latest",
"react-dom": "latest",
"react-scripts": "latest"
"react-dom": "latest"
}
}
3 changes: 1 addition & 2 deletions fixtures/smoke/graphql-with-mjs/package.json
Expand Up @@ -4,7 +4,6 @@
"graphql": "14.0.2",
"react-apollo": "2.2.1",
"react": "latest",
"react-dom": "latest",
"react-scripts": "latest"
"react-dom": "latest"
}
}
4 changes: 1 addition & 3 deletions fixtures/smoke/relative-paths/package.json
@@ -1,6 +1,4 @@
{
"dependencies": {
"react-scripts": "latest"
},
"dependencies": {},
"homepage": "."
}

0 comments on commit 7b1a32b

Please sign in to comment.