Skip to content

Commit

Permalink
Add ability to start app with mirage
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Wilsman committed Sep 19, 2018
1 parent c555329 commit ddbe957
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
46 changes: 46 additions & 0 deletions .stripesclirc.js
Original file line number Diff line number Diff line change
@@ -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
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"stripescore": "./stripes.js"
},
"scripts": {
"start": "stripes serve",
"clean": "rimraf static",
"test": "stripes test karma",
"lint": "eslint . && stylelint \"src/**/*.css\"",
Expand Down
6 changes: 3 additions & 3 deletions test/bigtest/network/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
}
5 changes: 5 additions & 0 deletions test/bigtest/network/scenarios/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import withTranslations from '../../helpers/translations';

export default function defaultScenarion(server) {
withTranslations(server);
}
2 changes: 1 addition & 1 deletion test/bigtest/network/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ddbe957

Please sign in to comment.