Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('service - cannot track the same types more than once at a time', t => {
const perfService = getService(
createTestFixture,
NodePerformanceEmitterPlugin
);
t.throws(() => perfService.start(), 'already running trackers cannot start');
// Able to start now that we've stopped
t.doesNotThrow(() => perfService.stop(), 'service can be stopped');
t.doesNotThrow(
() => perfService.start(),
'service can run if the trackers are not active'
);
t.doesNotThrow(() => perfService.stop(), 'service can be stopped');
t.doesNotThrow(
() => perfService.stop(),
tape('non-ssr routes', async t => {
const reducer = (state, action) => ({test: action.payload || 1});
const plugin = getService(appCreator(reducer), Redux);
let mockCtx = {
body: null,
memoized: new Map(),
};
t.plan(1);
if (!Redux.middleware) {
t.end();
return;
}
// $FlowFixMe
await Redux.middleware(null, plugin)((mockCtx: any), () => Promise.resolve());
t.notok(plugin.from((mockCtx: any)).store);
t.end();
});
tape('browser middleware', async t => {
const element = React.createElement('div');
const ctx: any = {element, template: {body: []}, memoized: new Map()};
const service = getService(appCreator(), Plugin);
try {
await (Plugin.middleware &&
// $FlowFixMe
Plugin.middleware(null, service)((ctx: any), () => Promise.resolve()));
} catch (e) {
t.ifError(e);
}
t.end();
});
test('mock plugin', t => {
t.equals(typeof mock.provides, 'function');
const handlers = {test() {}};
const appCreator = () => {
const app = new App('content', el => el);
app.register(RPCHandlersToken, handlers);
return app;
};
const RPCRedux = getService(appCreator, mock);
const mockCtx: Context = ({headers: {}, memoized: new Map()}: any);
t.equal(typeof RPCRedux.from(mockCtx).request, 'function');
t.end();
});
tape('browser with no preloadedState and no __REDUX_STATE__ element', t => {
const Redux = GetReduxPlugin();
const reducer = (state, action) => {
return {
...state,
test: action.payload || 1,
};
};
const provider = getService(appCreator(reducer), Redux);
const {store} = provider && provider.from();
t.deepLooseEqual(store.getState(), {test: 1});
store.dispatch({type: 'CHANGE', payload: 2});
t.equals(store.getState().test, 2, 'state receives dispatch');
t.end();
});
tape('browser provider', async t => {
const reduxState = document.createElement('script');
reduxState.setAttribute('type', 'application/json');
reduxState.setAttribute('id', '__PLUGIN_VALUE__');
reduxState.textContent = JSON.stringify({value: 'create-fusion-plugin'});
document.body && document.body.appendChild(reduxState);
const provider = getService(appCreator(), Plugin);
const {value} = provider && provider.from();
t.equal(value, 'create-fusion-plugin');
t.end();
});
t.equal(payload.status, 'success');
t.equal(typeof payload.timing, 'number');
},
from() {
return this;
},
});
const appCreator = () => {
const app = new App('content', el => el);
app.register(UniversalEventsToken, mockEmitter);
app.register(RPCHandlersToken, mockHandlers);
return app;
};
const rpcFactory = getService(appCreator, RPCPlugin);
const rpc = rpcFactory.from(mockCtx);
t.equals(typeof rpc.request, 'function', 'has request method');
try {
const p = rpc.request('test', 'test-args');
t.ok(p instanceof Promise, 'has right return type');
t.equals(await p, 1, 'method works');
} catch (e) {
t.fail(e);
}
t.end();
});
function getStore(appCreator, Redux) {
const provider = getService(appCreator, Redux);
return provider && provider.from().store;
}
function getStore(appCreator, Redux) {
const provider = getService(appCreator, Redux);
return provider && provider.from().store;
}