From 9acd9cd7c28c073e13fbcecd07184a009376026b Mon Sep 17 00:00:00 2001 From: Michal Glaus Date: Fri, 9 Nov 2018 17:40:31 +0100 Subject: [PATCH] Setup tests on CircleCI (#6) * Add script for installing peer dependecies See https://github.com/yarnpkg/yarn/issues/1503 * Add test configuration * Fix eslint errors and warnings * Add workflow to CircleCI config * Use node 10 image * Remove `yarn` from test script --- .circleci/config.yml | 32 ++++++++++++++++++++++++++++++++ .npmignore | 2 ++ getPeerScript.js | 11 +++++++++++ package.json | 3 ++- src/output.js | 2 +- src/server.js | 2 +- src/styles.js | 4 ++-- 7 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 getPeerScript.js diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..e630c30 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,32 @@ +version: 2 +jobs: + test: + docker: + - image: circleci/node:10 + + steps: + - checkout + - restore_cache: + name: Restoring Yarn Cache + keys: + # Find a cache corresponding to this specific package.json checksum. + - v-yarn-{{ checksum "package.json" }} + # Find the most recent cache regardless of package.json checksum. + - v-yarn- + - run: + name: Installing All Dependencies + command: yarn install-peer + - save_cache: + name: Saving Yarn Cache + key: v-yarn-{{ checksum "package.json" }} + paths: + - node_modules + - run: + name: Running Tests + command: yarn test + +workflows: + version: 2 + test: + jobs: + - test diff --git a/.npmignore b/.npmignore index 7900830..7047ea7 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,5 @@ +extractPeerDeps.js +getPeerScript.js src webpack.config.js yarn.lock diff --git a/getPeerScript.js b/getPeerScript.js new file mode 100644 index 0000000..3a5f770 --- /dev/null +++ b/getPeerScript.js @@ -0,0 +1,11 @@ +// returns a yarn command to re-add peer dependencies which as a side effect installs them into node_modules +const deps = require('./package').peerDependencies +const res = [] +for (let dep in deps) { + res.push(`"${dep}@${deps[dep]}"`) +} + +const depStr = res.join(' ') +if (depStr.length) { + process.stdout.write(`yarn add --peer --no-lockfile ${depStr}`) +} diff --git a/package.json b/package.json index 8dc980f..2597434 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,11 @@ "description": "Default Webpack 2 & 3 config we use in vacuumlabs.", "main": "dist/index.js", "scripts": { + "install-peer": "node ./getPeerScript.js | sh", "build": "babel -d dist/ src/ && node ./extractPeerDeps.js", "build-watch": "babel -d dist/ src/ --watch", "prepublish": "npm run build", - "test": "echo \"Error: no test specified\" && exit 1", + "test": "eslint . --max-warnings 0", "eslint": "eslint ." }, "repository": { diff --git a/src/output.js b/src/output.js index f6b2d9b..1680d37 100644 --- a/src/output.js +++ b/src/output.js @@ -1,7 +1,7 @@ export default function(options) { return { path: options.buildDir, - filename: options.useHashedAssetNames ? '[name].[hash].js': '[name].js', + filename: options.useHashedAssetNames ? '[name].[hash].js' : '[name].js', chunkFilename: '[name]-[chunkhash].js', publicPath: options.env === 'development' ? `http://${options.host}:${options.port}/` diff --git a/src/server.js b/src/server.js index 24dd53c..c1b0d93 100644 --- a/src/server.js +++ b/src/server.js @@ -2,7 +2,7 @@ import webpack from 'webpack' import WebpackDevServer from 'webpack-dev-server' -export default (webpackConfig, options, done) => +export default (webpackConfig, options, done) => new WebpackDevServer(webpack(webpackConfig), { publicPath: webpackConfig.output.publicPath, hot: true, diff --git a/src/styles.js b/src/styles.js index 5d5a0ff..59eb688 100644 --- a/src/styles.js +++ b/src/styles.js @@ -48,6 +48,6 @@ export function plugins(options) { return options.useDevServer ? [] : [new ExtractTextPlugin({ - filename: options.useHashedAssetNames ? 'app.[contenthash].css' : 'app.css', - allChunks: true})] + filename: options.useHashedAssetNames ? 'app.[contenthash].css' : 'app.css', + allChunks: true})] }