diff --git a/.stripesclirc.js b/.stripesclirc.js new file mode 100644 index 000000000..7b2e3fb61 --- /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: ['./test/bigtest/network/boot'].concat(config.entry) + }); + } else { + return config; + } + }; + } +} + +module.exports = { + hasAllPerms: true, + + aliases: { + '@folio/stripes-core': '.' + }, + + // Custom command extension + plugins: { + serve: miragePlugin + } +}; diff --git a/package.json b/package.json index 9e740e616..355a595e5 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "stripescore": "./stripes.js" }, "scripts": { + "start": "stripes serve", "clean": "rimraf static", "test": "stripes test karma", "lint": "eslint . && stylelint \"src/**/*.css\"", diff --git a/test/bigtest/network/config.js b/test/bigtest/network/config.js index 3054d2b01..14aea1547 100644 --- a/test/bigtest/network/config.js +++ b/test/bigtest/network/config.js @@ -18,11 +18,14 @@ export default function configure() { configs: [] }); + this.get('/users', {}); + this.post('/bl-users/login', () => { return new Response(201, { 'X-Okapi-Token': `myOkapiToken:${Date.now()}` }, { user: { + id: 'test', username: 'testuser', personal: { lastName: 'User', @@ -46,9 +49,6 @@ export default function configure() { totalRecords: 0 }); - // translation bundle passthrough - this.pretender.get(`${__webpack_public_path__}translations/:rand.json`, this.pretender.passthrough); // eslint-disable-line - // hot-reload passthrough this.pretender.get('/:rand.hot-update.json', this.pretender.passthrough); } diff --git a/test/bigtest/network/scenarios/default.js b/test/bigtest/network/scenarios/default.js new file mode 100644 index 000000000..c4ad5839c --- /dev/null +++ b/test/bigtest/network/scenarios/default.js @@ -0,0 +1,5 @@ +import withTranslations from '../../helpers/translations'; + +export default function defaultScenarion(server) { + withTranslations(server); +} diff --git a/test/bigtest/network/start.js b/test/bigtest/network/start.js index 5f322bffb..22f92e416 100644 --- a/test/bigtest/network/start.js +++ b/test/bigtest/network/start.js @@ -27,7 +27,7 @@ const modules = req.keys().reduce((acc, modulePath) => { }, {}); export default function startMirage(...scenarioNames) { - const { scenarios, ...options } = modules; + const { scenarios = {}, ...options } = modules; const server = new Mirage(assign(options, { baseConfig, environment })); // mirage only loads a `default` scenario for us out of the box, so