From de7fc4ddbe643bb66512a182569e4b8069b6d715 Mon Sep 17 00:00:00 2001 From: Wil Wilsman Date: Mon, 1 Oct 2018 16:56:40 -0500 Subject: [PATCH] Setup BigTest infrastructure --- .stripesclirc.js | 46 ++++++++++++++++++++++++++++++ package.json | 13 +++++++-- tests/index.js | 9 ++++++ tests/network/boot.js | 9 ++++++ tests/network/config.js | 3 ++ tests/network/factories/.gitkeep | 0 tests/network/fixtures/.gitkeep | 0 tests/network/index.js | 28 ++++++++++++++++++ tests/network/models/.gitkeep | 0 tests/network/scenarios/.gitkeep | 0 tests/network/serializers/.gitkeep | 0 11 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 .stripesclirc.js create mode 100644 tests/index.js create mode 100644 tests/network/boot.js create mode 100644 tests/network/config.js create mode 100644 tests/network/factories/.gitkeep create mode 100644 tests/network/fixtures/.gitkeep create mode 100644 tests/network/index.js create mode 100644 tests/network/models/.gitkeep create mode 100644 tests/network/scenarios/.gitkeep create mode 100644 tests/network/serializers/.gitkeep diff --git a/.stripesclirc.js b/.stripesclirc.js new file mode 100644 index 000000000..121f15ef0 --- /dev/null +++ b/.stripesclirc.js @@ -0,0 +1,46 @@ +const webpack = require('webpack'); + +const miragePlugin = { + // Standard yargs options object + options: { + 'mirage [scenario]': { + describe: 'Enable Mirage Server and specify a scenario', + type: 'string', + group: 'Mirage Server' + }, + }, + + // Stripes CLI hook into "webpackOverrides" + beforeBuild: (options) => { + const mirageOption = options.mirage === true ? 'default' : options.mirage; + + return (config) => { + config.plugins.push(new webpack.EnvironmentPlugin({ + MIRAGE_SCENARIO: mirageOption || 'default' + })); + + if (!!mirageOption) { + console.info('Using Mirage Server'); // eslint-disable-line no-console + + return Object.assign({}, config, { + entry: ['./tests/network/boot'].concat(config.entry) + }); + } else { + return config; + } + }; + } +} + +module.exports = { + hasAllPerms: true, + + aliases: { + '@folio/stripes-smart-components': '.' + }, + + // Custom command extension + plugins: { + serve: miragePlugin + } +}; diff --git a/package.json b/package.json index e7fe8ae7a..4db20164c 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "node": ">=6.0.0" }, "stripes": { - "type": "components", "okapiInterfaces": { "notes": "1.0", "tags": "1.0" @@ -76,16 +75,26 @@ "lint": "eslint . && stylelint \"lib/**/*.css\"", "eslint": "eslint .", "stylelint": "stylelint \"lib/**/*.css\"", - "test": "echo 'placeholder. no tests implemented'" + "test": "stripes test karma" }, "devDependencies": { + "@bigtest/convergence": "^1.0.0", + "@bigtest/interactor": "^0.7.2", + "@bigtest/mirage": "^0.0.1", + "@bigtest/mocha": "^0.5.1", + "@bigtest/react": "^0.1.2", "@folio/eslint-config-stripes": "^3.2.1", + "@folio/stripes-cli": "^1.5.0", + "@folio/stripes-core": "^2.14.0", "babel-eslint": "^9.0.0", + "chai": "^4.2.0", "eslint": "^5.5.0", + "mocha": "^5.2.0", "react": "^16.5.0", "react-dom": "^16.5.0", "react-redux": "^5.0.7", "redux": "^4.0.0", + "sinon": "^6.3.4", "stylelint": "^9.5.0", "stylelint-config-standard": "^18.2.0" }, diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 000000000..66492550e --- /dev/null +++ b/tests/index.js @@ -0,0 +1,9 @@ +require('babel-polyfill'); + +// require all test files matching 'lib/**/tests/*-test' +const requireTest = require.context('../lib/', true, /(.*?)\/tests\/(.*?)-test/); +requireTest.keys().forEach(requireTest); + +// require all source files in lib for code coverage +const componentsContext = require.context('../lib/', true, /^(?!.*(stories|examples)).*\.js$/); +componentsContext.keys().forEach(componentsContext); diff --git a/tests/network/boot.js b/tests/network/boot.js new file mode 100644 index 000000000..2de3a4f98 --- /dev/null +++ b/tests/network/boot.js @@ -0,0 +1,9 @@ +import startMirage from '@folio/stripes-core/test/bigtest/network/start'; +import mirageOptions from '.'; + +/** +* Start mirage to handle requests in development and production. Note +* that this file will _not_ be include in the build at all if mirage +* is disabled. Also, it will not included in test builds. +*/ +window.mirage = startMirage(process.env.MIRAGE_SCENARIO, mirageOptions); diff --git a/tests/network/config.js b/tests/network/config.js new file mode 100644 index 000000000..59f805f79 --- /dev/null +++ b/tests/network/config.js @@ -0,0 +1,3 @@ +// typical mirage config export +export default function configure() { +} diff --git a/tests/network/factories/.gitkeep b/tests/network/factories/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/network/fixtures/.gitkeep b/tests/network/fixtures/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/network/index.js b/tests/network/index.js new file mode 100644 index 000000000..715563f34 --- /dev/null +++ b/tests/network/index.js @@ -0,0 +1,28 @@ +import { camelize } from '@bigtest/mirage'; + +// auto-import all mirage submodules +const req = require.context('./', true, /\.js$/); +const modules = req.keys().reduce((acc, modulePath) => { + const moduleParts = modulePath.split('/'); + const moduleType = moduleParts[1]; + const moduleName = moduleParts[2]; + + if (moduleName) { + const moduleKey = camelize(moduleName.replace('.js', '')); + + return Object.assign(acc, { + [moduleType]: { + ...(acc[moduleType] || {}), + [moduleKey]: req(modulePath).default + } + }); + } else if (modulePath === './config.js') { + return Object.assign(acc, { + baseConfig: req(modulePath).default + }); + } else { + return acc; + } +}, {}); + +export default modules; diff --git a/tests/network/models/.gitkeep b/tests/network/models/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/network/scenarios/.gitkeep b/tests/network/scenarios/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/network/serializers/.gitkeep b/tests/network/serializers/.gitkeep new file mode 100644 index 000000000..e69de29bb