<commit_before>import Helmet from 'react-helmet';
import { getMockRenderRequestMap } from '../mocks';
import start from '../../src/server';
import { Forbidden, NotFound, Redirect } from '../../src/router';

Forbidden.rewind = jest.fn(Forbidden.rewind);
NotFound.rewind = jest.fn(NotFound.rewind);
Redirect.rewind = jest.fn(Redirect.rewind);
Helmet.rewind = jest.fn(Helmet.rewind);

const testSideEffectError = (Component, name) =>
	start(getMockRenderRequestMap(), {}).then(server => {
		const request = {
			method: 'get',
			url: `/badImplementation?${name}`,
			credentials: 'whatever',
		};
		return server
			.inject(request)
			.then(response => {
				expect(Component.rewind).toHaveBeenCalled();
			})
			.then(() => server.stop())
			.catch(err => {
				server.stop();
				throw err;
			});
	});

describe('rewind behavior', () => {
	it('rewind() for all side effect components for normal server render', () =>
		start(getMockRenderRequestMap(), {}).then(server => {
			const request = {
				method: 'get',
				url: '/foo',
				credentials: 'whatever',
			};
			return server
				.inject(request)
				.then(() => {
					expect(Forbidden.rewind).toHaveBeenCalled();
					expect(NotFound.rewind).toHaveBeenCalled();
					expect(Redirect.rewind).toHaveBeenCalled();
					expect(Helmet.rewind).toHaveBeenCalled();<commit_msg>just a little more test for your test<commit_after>import Helmet from 'react-helmet';
import { getMockRenderRequestMap } from '../mocks';
import start from '../../src/server';
import { Forbidden, NotFound, Redirect } from '../../src/router';

Forbidden.rewind = jest.fn(Forbidden.rewind);
NotFound.rewind = jest.fn(NotFound.rewind);
Redirect.rewind = jest.fn(Redirect.rewind);
Helmet.rewind = jest.fn(Helmet.rewind);

const testSideEffectError = (Component, name) =>
	start(getMockRenderRequestMap(), {}).then(server => {
		const request = {
			method: 'get',
			url: `/badImplementation?${name}`,
			credentials: 'whatever',
		};
		return server
			.inject(request)
			.then(response => {
				expect(response.statusCode === 500);
				expect(Component.rewind).toHaveBeenCalled();
			})
			.then(() => server.stop())
			.catch(err => {
				server.stop();
				throw err;
			});
	});

describe('rewind behavior', () => {
	it('rewind() for all side effect components for normal server render', () =>
		start(getMockRenderRequestMap(), {}).then(server => {
			const request = {
				method: 'get',
				url: '/foo',
				credentials: 'whatever',
			};
			return server
				.inject(request)
				.then(() => {
					expect(Forbidden.rewind).toHaveBeenCalled();
					expect(NotFound.rewind).toHaveBeenCalled();
					expect(Redirect.rewind).toHaveBeenCalled();
					expect(Helmet.rewind).toHaveBeenCalled();
{'fraction_non_alphanumeric': 0.17517443995593096, 'fraction_numerical': 0.0011017260374586854, 'mean_word_length': 3.916967509025271, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5198787', 'n_tokens_mistral': 1003, 'n_tokens_neox': 876, 'n_words': 170}