Skip to content

Commit

Permalink
Add stripes config mocking ability to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Wilsman committed Sep 19, 2018
1 parent 557a9fb commit b3404f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
17 changes: 14 additions & 3 deletions test/bigtest/helpers/setup-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import App from '../../../src/App';
import 'typeface-source-sans-pro';
import '@folio/stripes-components/lib/global.css';

import { withModules, clearModules } from './stripes-config';
import {
withModules,
clearModules,
withConfig,
clearConfig
} from './stripes-config';

export default function setupApplication({
disableAuth = true,
modules = [],
stripesConfig,
scenarios
} = {}) {
beforeEach(async function () {
Expand All @@ -28,12 +34,17 @@ export default function setupApplication({
this.server = startMirage(scenarios);
this.server.logging = false;
withModules(modules);
withConfig({
logCategories: '',
...stripesConfig
});
},

teardown: () => {
this.server.shutdown();
localforage.clear();
clearConfig();
clearModules();
localforage.clear();
this.server.shutdown();
}
});

Expand Down
14 changes: 13 additions & 1 deletion test/bigtest/helpers/stripes-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as stripes from 'stripes-config';

const { assign, keys } = Object;

export function withModule({
name,
module,
Expand Down Expand Up @@ -40,7 +42,7 @@ export function withModules(modules) {

export function clearModules() {
// delete existing modules and metadata
Object.keys(stripes.modules).forEach(type => {
keys(stripes.modules).forEach(type => {
stripes.modules[type].forEach(module => {
delete stripes.metadata[module.name];
});
Expand All @@ -51,3 +53,13 @@ export function clearModules() {
// app is required
stripes.modules.app = [];
}

const originalConfig = assign({}, stripes.config);

export function withConfig(config) {
assign(stripes.config, config);
}

export function clearConfig() {
assign(stripes.config, originalConfig);
}

0 comments on commit b3404f7

Please sign in to comment.