Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

test: Setup dev server for rendering JS and Sass #2

Merged
merged 10 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16,193 changes: 10,046 additions & 6,147 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "Material Components React",
"license": "Apache-2.0",
"scripts": {
"start": "webpack-dev-server --config test/screenshot/webpack.config.js --content-base test/screenshot",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can do the --content-base option here. I think we need the webpack.config.js file to live in the root. I don't think it transform the files in the packages dir. Try importing a React Component into the screenshot tests, and I don't think you'll get JSX errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope!

"commitmsg": "validate-commit-msg",
"fix": "eslint --fix packages test",
"lint": "eslint packages test",
Expand All @@ -25,9 +26,14 @@
"babel-core": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"chai": "^4.1.2",
"css-loader": "^0.28.10",
"eslint": "^3.19.0",
"eslint-config-google": "^0.9.1",
"extract-loader": "^1.0.2",
"file-loader": "^1.1.11",
"husky": "^0.14.3",
"istanbul": "^0.4.5",
"istanbul-instrumenter-loader": "^3.0.0",
Expand All @@ -37,7 +43,12 @@
"karma-mocha": "^1.3.0",
"karma-webpack": "^2.0.13",
"mocha": "^5.0.2",
"node-sass": "^4.7.2",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"sass-loader": "^6.0.7",
"validate-commit-msg": "^2.14.0",
"webpack": "^3.11.0"
"webpack": "^3.11.0",
"webpack-dev-server": "^2.11.2"
}
}
3 changes: 3 additions & 0 deletions test/screenshot/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html>
<a href="temporary-package">Temporary Package</a>
</html>
9 changes: 9 additions & 0 deletions test/screenshot/temporary-package/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add <!DOCTYPE html> before this line.

Without it, all browsers will go into "quirks mode" instead of "standards mode", and things will render differently.

(The HTML5 spec also says doctype is required.)

<head>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-indent this file (everything inside <html> is missing 1 leading space).

<link rel="stylesheet" href="bundle.css">
<script src="bundle.js" async></script>
</head>
<body>
<div id="app"></div>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did a tab character \t sneak in here? 😛

</body>
</html>
8 changes: 8 additions & 0 deletions test/screenshot/temporary-package/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import TemporaryClass from '../../../packages/temporary-package';

const temporary = new TemporaryClass();
ReactDOM.render((
<div>{temporary.returnOne()}</div>
), document.getElementById('app'));
3 changes: 3 additions & 0 deletions test/screenshot/temporary-package/temporary-package.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: blue;
}
63 changes: 63 additions & 0 deletions test/screenshot/webpack-bundles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module.exports.sassBundle = function(sassInput, cssOutput) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think cutting this down from sassBundle and javaScript bundle into just 1 xyzBundle method will cut down the compile time. When you pass a new config into the array in multicompiler mode, webpack thinks it is a new bundle. Yes we want the css file to be separate, but I think by passing the name prop to the the file-loader will create a separate css file.

The only drawback(up for debate) to having 1 bundle is that you must import sass files into the JS files. But I think this improves build times.

return {
entry: sassInput,
output: {
// This is necessary for webpack to compile
// But we never use style-bundle.js
filename: 'style-bundle.js',
},
module: {
rules: [{
test: /\.scss$/,
use: [{
loader: 'file-loader',
options: {
name: cssOutput,
},
},
{
loader: 'extract-loader'
},
{
loader: 'css-loader'
},
{
loader: 'sass-loader',
options: {
importer: function(url, prev) {
if (url.indexOf('@material') === 0) {
var filePath = url.split('@material')[1];
var nodeModulePath = `./node_modules/@material/${filePath}`;
return {
file: require('path').resolve(nodeModulePath)
};
}
return {
file: url
};
}
}
}
]
}]
}
};
};

module.exports.javaScriptBundle = function(input, output) {
return {
entry: input,
output: {
filename: output
},
module: {
loaders: [{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}]
}
}
};
6 changes: 6 additions & 0 deletions test/screenshot/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const {sassBundle, javaScriptBundle} = require('./webpack-bundles');

module.exports = [
sassBundle('./test/screenshot/temporary-package/temporary-package.scss', 'temporary-package/bundle.css'),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

javaScriptBundle('./test/screenshot/temporary-package/index.js', 'temporary-package/bundle.js')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

];