-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathapp.test.ts
92 lines (84 loc) · 2.51 KB
/
app.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import express from 'express';
import { createTestConfig } from '../test/config/test-config';
import compression from 'compression';
jest.mock('compression', () =>
jest.fn().mockImplementation(() => (req, res, next) => {
next();
}),
);
jest.mock(
'./routes',
() =>
class Index {
router() {
return express.Router();
}
},
);
import getApp from './app';
test('should not throw when valid config', async () => {
const config = createTestConfig();
// @ts-expect-error - We're passing in empty stores and services
const app = await getApp(config, {}, {});
expect(typeof app.listen).toBe('function');
});
test('should call preHook', async () => {
let called = 0;
const config = createTestConfig({
preHook: () => {
called++;
},
});
// @ts-expect-error - We're passing in empty stores and services
await getApp(config, {}, {});
expect(called).toBe(1);
});
test('should call preRouterHook', async () => {
let called = 0;
const config = createTestConfig({
preRouterHook: () => {
called++;
},
});
// @ts-expect-error - We're passing in empty stores and services
await getApp(config, {}, {});
expect(called).toBe(1);
});
describe('compression middleware', () => {
beforeAll(() => {
(compression as jest.Mock).mockClear();
});
afterEach(() => {
(compression as jest.Mock).mockClear();
});
test.each([
{
disableCompression: true,
expectCompressionEnabled: false,
},
{
disableCompression: false,
expectCompressionEnabled: true,
},
{
disableCompression: null,
expectCompressionEnabled: true,
},
{
disableCompression: undefined,
expectCompressionEnabled: true,
},
])(
`should expect the compression middleware to be $expectCompressionEnabled when configInput.server.disableCompression is $disableCompression`,
async ({ disableCompression, expectCompressionEnabled }) => {
const config = createTestConfig({
server: {
disableCompression: disableCompression as any,
},
});
// @ts-expect-error - We're passing in empty stores and services
await getApp(config, {}, {});
expect(compression).toBeCalledTimes(+expectCompressionEnabled);
},
);
});