diff --git a/rollup-browser-tests.config.js b/rollup-browser-tests.config.js index a8c4ebdeb..d2ff9e78b 100644 --- a/rollup-browser-tests.config.js +++ b/rollup-browser-tests.config.js @@ -1,70 +1,47 @@ import fetch from 'node-fetch'; -import commonjs from 'rollup-plugin-commonjs'; import nodeResolve from 'rollup-plugin-node-resolve'; -import multiEntry from 'rollup-plugin-multi-entry'; import builtins from 'rollup-plugin-node-builtins'; import globals from 'rollup-plugin-node-globals'; import babel from 'rollup-plugin-babel'; -import json from 'rollup-plugin-json'; import remap from 'rollup-plugin-remap'; -import graphqlCompiler from 'rollup-plugin-graphql-js-client-compiler'; -import eslintTestGenerator from './scripts/rollup-plugin-eslint-test-generator'; +import baseConfig from './rollup-tests-common.config'; const {livereloadPort} = require('./package.json'); const reloadUri = `http://localhost:${livereloadPort}/changed?files=tests.js,index.html`; -export default { - entry: ['test/setup.js', 'test/**/*-test.js'], - plugins: [ - graphqlCompiler({ - schema: './schema.json' - }), - multiEntry({ - exports: false - }), - remap({ - originalPath: './test/isomorphic-fetch-mock.js', - targetPath: './test/fetch-mock-browser.js' - }), - globals(), - builtins(), - json({ - exclude: './schema.json' - }), - eslintTestGenerator({ - paths: [ - 'src', - 'test' +baseConfig.plugins.push( + remap({ + originalPath: './test/isomorphic-fetch-mock.js', + targetPath: './test/fetch-mock-browser.js' + }), + globals(), + builtins(), + nodeResolve({ + jsnext: true, + main: true, + preferBuiltins: false + }), + babel({ + babelrc: false, + presets: [ + [ + `${process.cwd()}/node_modules/babel-preset-shopify/web`, { + modules: false + } ] - }), - nodeResolve({ - jsnext: true, - main: true, - preferBuiltins: false - }), - commonjs({ - include: 'node_modules/**' - }), - babel({ - babelrc: false, - presets: [ - [ - `${process.cwd()}/node_modules/babel-preset-shopify/web`, { - modules: false - } - ] - ] - }), - { - onwrite() { - fetch(reloadUri); - } + ] + }), + { + onwrite() { + fetch(reloadUri); } - ], - targets: [{ - format: 'iife', - dest: '.tmp/test/tests.js' - }], - sourceMap: true -}; + } +); + +baseConfig.targets = [{ + format: 'iife', + dest: '.tmp/test/tests.js' +}]; + +export default baseConfig; diff --git a/rollup-node-tests.config.js b/rollup-node-tests.config.js index 9a2c60fbe..eb31a4520 100644 --- a/rollup-node-tests.config.js +++ b/rollup-node-tests.config.js @@ -1,67 +1,45 @@ -import commonjs from 'rollup-plugin-commonjs'; import nodeResolve from 'rollup-plugin-node-resolve'; -import multiEntry from 'rollup-plugin-multi-entry'; import babel from 'rollup-plugin-babel'; -import json from 'rollup-plugin-json'; import remap from 'rollup-plugin-remap'; -import graphqlCompiler from 'rollup-plugin-graphql-js-client-compiler'; -import eslintTestGenerator from './scripts/rollup-plugin-eslint-test-generator'; +import baseConfig from './rollup-tests-common.config'; -export default { - entry: ['test/setup.js', 'test/**/*-test.js'], - plugins: [ - graphqlCompiler({ - schema: './schema.json' - }), - multiEntry({ - exports: false - }), - remap({ - originalPath: './test/isomorphic-fetch-mock.js', - targetPath: './test/fetch-mock-node.js' - }), - json({ - exclude: './schema.json' - }), - eslintTestGenerator({ - paths: [ - 'src', - 'test' +baseConfig.plugins.push( + remap({ + originalPath: './test/isomorphic-fetch-mock.js', + targetPath: './test/fetch-mock-node.js' + }), + nodeResolve({ + jsnext: true, + main: true, + preferBuiltins: true + }), + babel({ + babelrc: false, + presets: [ + [ + `${process.cwd()}/node_modules/babel-preset-shopify/node`, { + modules: false + } ] - }), - nodeResolve({ - jsnext: true, - main: true, - preferBuiltins: true - }), - commonjs({ - include: 'node_modules/**' - }), - babel({ - babelrc: false, - presets: [ - [ - `${process.cwd()}/node_modules/babel-preset-shopify/node`, { - modules: false - } - ] - ] - }) - ], - targets: [{ - format: 'cjs', - dest: '.tmp/test/node-tests.js' - }], - external: [ - 'assert', - 'url', - 'http', - 'https', - 'zlib', - 'stream', - 'buffer', - 'util', - 'string_decoder' - ], - sourceMap: true -}; + ] + }) +); + +baseConfig.targets = [{ + format: 'cjs', + dest: '.tmp/test/node-tests.js' +}]; + +baseConfig.external = [ + 'assert', + 'url', + 'http', + 'https', + 'zlib', + 'stream', + 'buffer', + 'util', + 'string_decoder' +]; + +export default baseConfig; diff --git a/rollup-tests-common.config.js b/rollup-tests-common.config.js new file mode 100644 index 000000000..f8b6252b2 --- /dev/null +++ b/rollup-tests-common.config.js @@ -0,0 +1,30 @@ +import commonjs from 'rollup-plugin-commonjs'; +import graphqlCompiler from 'rollup-plugin-graphql-js-client-compiler'; +import json from 'rollup-plugin-json'; +import multiEntry from 'rollup-plugin-multi-entry'; +import eslintTestGenerator from './scripts/rollup-plugin-eslint-test-generator'; + +export default { + entry: ['test/setup.js', 'test/**/*-test.js'], + plugins: [ + graphqlCompiler({ + schema: './schema.json' + }), + multiEntry({ + exports: false + }), + json({ + exclude: './schema.json' + }), + eslintTestGenerator({ + paths: [ + 'src', + 'test' + ] + }), + commonjs({ + include: 'node_modules/**' + }) + ], + sourceMap: true +};