Skip to content

Commit

Permalink
Run tests against production bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Mar 8, 2019
1 parent 1566a31 commit 6cc95e9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -24,4 +24,5 @@ addons:
script:
- npm run build
- COVERAGE=true npm run test
- PRODUCTION=true PERFORMANCE=false COVERAGE=false npm run test:karma
- ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info;
51 changes: 48 additions & 3 deletions karma.conf.js
@@ -1,14 +1,40 @@
/*eslint no-var:0, object-shorthand:0 */

var coverage = String(process.env.COVERAGE) === 'true',
prod = String(process.env.PRODUCTION) === 'true',
ci = String(process.env.CI).match(/^(1|true)$/gi),
pullRequest = !String(process.env.TRAVIS_PULL_REQUEST).match(/^(0|false|undefined)$/gi),
masterBranch = String(process.env.TRAVIS_BRANCH).match(/^master$/gi),
sauceLabs = ci && !pullRequest && masterBranch,
performance = !coverage && String(process.env.PERFORMANCE) !== 'false',
webpack = require('webpack'),
WebpackModules = require('webpack-modules'),
TerserPlugin = require('terser-webpack-plugin'),
path = require('path');

let nameCache = null;
let minifyOptions = {};

[
require('./mangle.json'),
require('./compat/mangle.json'),
require('./debug/mangle.json'),
require('./hooks/mangle.json')
].forEach(config => {
if (config.minify) {
minifyOptions = config.minify;
}

if (config.props) {
if (nameCache==null) {
nameCache = { props: config.props };
}
else {
Object.assign(nameCache.props.props, config.props.props);
}
}
});

var sauceLabsLaunchers = {
sl_chrome: {
base: 'SauceLabs',
Expand Down Expand Up @@ -151,18 +177,37 @@ module.exports = function(config) {
// rather than referencing source files inside the module
// directly
alias: {
'preact/hooks': path.join(__dirname, './hooks/src'),
preact: path.join(__dirname, './src')
'preact/compat': prod
? path.join(__dirname, './compat/dist/compat.mjs')
: path.join(__dirname, './compat/src'),
'preact/debug': prod
? path.join(__dirname, './debug/dist/debug.mjs')
: path.join(__dirname, './debug/src'),
'preact/hooks': prod
? path.join(__dirname, './hooks/dist/hooks.mjs')
: path.join(__dirname, './hooks/src'),
preact: prod
? path.join(__dirname, './dist/preact.mjs')
: path.join(__dirname, './src')
}
},
plugins: [
prod && new TerserPlugin({
sourceMap: true,
exclude: /(dist|node_modules)/,
terserOptions: {
nameCache,
mangle: minifyOptions.mangle
}
}),
new WebpackModules(),
new webpack.DefinePlugin({
coverage: coverage,
NODE_ENV: JSON.stringify(process.env.NODE_ENV || ''),
ENABLE_PERFORMANCE: performance,
DISABLE_FLAKEY: !!String(process.env.FLAKEY).match(/^(0|false)$/gi)
})
],
].filter(Boolean),
performance: {
hints: false
}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -126,8 +126,10 @@
"npm-run-all": "^4.0.0",
"sinon": "^6.1.3",
"sinon-chai": "^3.0.0",
"terser-webpack-plugin": "^1.2.3",
"typescript": "^3.0.1",
"webpack": "^4.3.0"
"webpack": "^4.3.0",
"webpack-modules": "^1.0.0"
},
"bundlesize": [
{
Expand Down

0 comments on commit 6cc95e9

Please sign in to comment.