Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('renders correct component', () => {
const history = createMemoryHistory('/');
const store = createStore(veteran);
let tree;
before(() => {
// It's perfectly fine in this test to reuse the rendered component. Do that
// cause it cuts the test time from 1s down to ~0.1s.
tree = SkinDeep.shallowRender((
{routes}
), {
store // Mock the Redux store context so components render.
}
);
server.get('*', (req, res) => {
const store = configureStore({
sourceRequest: {
protocol: req.headers['x-forwarded-proto'] || req.protocol,
host: req.headers.host
}
})
const routes = createRoutes(store)
const history = createMemoryHistory(req.originalUrl)
const { dispatch } = store
match({ routes, history}, (err, redirectLocation, renderProps) => {
if (err) {
console.error(err)
return res.status(500).send('Internal server error')
}
if (!renderProps) {
return res.status(404).send('Not found')
}
const { components } = renderProps
// Define locals to be provided to all lifecycle hooks:
const locals = {
checkAuth(auth).then(nr.createTracer('checkingAuth', (authResult) => {
const sessionData = Object.assign({}, authResult.userData)
authResult.userData.password = null
verifiedAuth = authResult
const defaultState = getDefaultState(feature)
let startingState = Object.assign({}, defaultState, { auth: verifiedAuth })
startingState = mapStateToParams(feature, startingState, params)
try {
const history = createMemoryHistory()
const store = getStore(feature, startingState, history, null)
loadData(feature, params, startingState, sessionData, store, Locale).then(nr.createTracer('loadData', (action) => {
const finish = nr.createTracer('finish', () => {
const RootComponent = getRootComponent(feature)
if (RootComponent === null) {
nr.endTransaction()
res.status(500).send({ error: 4, message: `No root component defined for this feature: ${feature}` })
}
getRenderProps(feature, params.url).then(nr.createTracer('getRenderProps', (renderProps) => {
let html = null
try {
html = renderToString()
} catch (ex) {
// throw new Error(`Error: 3 - Could Not Render ${feature} view`, ex)
auth: authStateReducer,
routing: routerReducer,
demoButtons,
demoUi
});
// create the redux store
const store = createStore(
reducer,
compose(
applyMiddleware(thunk)
)
);
let history = (isServer)
? createMemoryHistory(currentLocation)
: browserHistory;
history = syncHistoryWithStore(history, store);
// define app routes
var routes = (
match({routes, location: req.originalUrl}, (error: any, nextLocation: Location, nextState: any) => {
if (error) {
// Send message if an error occurs
res.status(500).send(error.message);
} else if (nextLocation) {
// Redirect on redirection
res.redirect(302, nextLocation.pathname + nextLocation.search);
} else if (nextState) {
// Create history
const history = createMemoryHistory();
// Setup state
const initialState = {};
const store = createStore(
require('../modules/root').reducer,
initialState,
getStoreMiddleware(history),
);
syncHistoryWithStore(history, store);
if (DISABLE_SERVER_SIDE_RENDERING) {
// Just provider Html without SSR
res.status(200).send(renderToString(
,
));
export default (locals, callback) => {
const history = createMemoryHistory()
const location = history.createLocation(locals.path)
match({
routes: Routes,
location: location
}, function(error, redirectLocation, renderProps) {
var html = ReactDOMServer.renderToStaticMarkup(
<template>
</template>
);
callback(null, html)
})
}
export default function setupForRender(createStore, url) {
const basename = ROC_PATH === '/' ? '' : ROC_PATH;
const completeUrl = basename + url;
const memoryHistory = createMemoryHistory({
entries: [completeUrl],
basename
});
const store = createStore ? createStore(memoryHistory) : null;
const history = store ? syncHistoryWithStore(memoryHistory, store) : memoryHistory;
return {
store,
history,
url
};
}
app.use((req, res) => {
const history = createMemoryHistory(req.path);
const store = createStore();
const matchParams = {
history,
routes,
location: req.originalUrl
};
match(matchParams, (error, redirectLocation, renderProps) => {
if (error) {
res.status(500).send(error.message);
} else if (redirectLocation) {
res.redirect(302, redirectLocation.pathname + redirectLocation.search);
} else if (renderProps) {
const reactString = renderToString(
router.use('/*', function(req, res){
const history = createMemoryHistory(req.originalUrl || '/');
const initialState = {};
let staticHTML = ReactDOMServer.renderToString(
React.createFactory(App)({
config: clientConfig,
history,
initialState
})
);
res.render('index', {
staticHTML,
initialState: JSON.stringify(initialState)
});
});
return new Promise((resolve, reject) => {
const memoryHistory = createMemoryHistory(url);
const store = configureStore(memoryHistory);
const history = syncHistoryWithStore(memoryHistory, store);
match({ history, routes, location: url }, (error, redirectLocation, renderProps) => {
if (error) {
reject(error);
} else if (redirectLocation) {
reject({
status: 301,
url: redirectLocation.pathname + redirectLocation.search,
});
} else if (renderProps) {
performContainerStaticMethod(renderProps, store)
.then(() => {
const content = renderToString(