/
withSentryConfig.test.ts
62 lines (48 loc) · 2.24 KB
/
withSentryConfig.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
import { defaultsObject, exportedNextConfig, runtimePhase, userNextConfig } from './fixtures';
import { materializeFinalNextConfig } from './testUtils';
describe('withSentryConfig', () => {
it('includes expected properties', () => {
const finalConfig = materializeFinalNextConfig(exportedNextConfig);
expect(finalConfig).toEqual(
expect.objectContaining({
webpack: expect.any(Function), // `webpack` is tested specifically elsewhere
}),
);
});
it('preserves unrelated next config options', () => {
const finalConfig = materializeFinalNextConfig(exportedNextConfig);
expect(finalConfig.publicRuntimeConfig).toEqual(userNextConfig.publicRuntimeConfig);
});
it("works when user's overall config is an object", () => {
const finalConfig = materializeFinalNextConfig(exportedNextConfig);
expect(finalConfig).toEqual(
expect.objectContaining({
...userNextConfig,
webpack: expect.any(Function), // `webpack` is tested specifically elsewhere
}),
);
});
it("works when user's overall config is a function", () => {
const exportedNextConfigFunction = () => userNextConfig;
const finalConfig = materializeFinalNextConfig(exportedNextConfigFunction);
expect(finalConfig).toEqual(
expect.objectContaining({
...exportedNextConfigFunction(),
webpack: expect.any(Function), // `webpack` is tested specifically elsewhere
}),
);
});
it('correctly passes `phase` and `defaultConfig` through to functional `userNextConfig`', () => {
const exportedNextConfigFunction = jest.fn().mockReturnValue(userNextConfig);
materializeFinalNextConfig(exportedNextConfigFunction);
expect(exportedNextConfigFunction).toHaveBeenCalledWith(runtimePhase, defaultsObject);
});
it('removes `sentry` property', () => {
// It's unclear why we need this cast -
const finalConfig = materializeFinalNextConfig({ ...exportedNextConfig, sentry: {} });
// const finalConfig = materializeFinalNextConfig({ ...exportedNextConfig, sentry: {} } as ExportedNextConfig);
// We have to check using `in` because TS knows it shouldn't be there and throws a type error if we try to access it
// directly
expect('sentry' in finalConfig).toBe(false);
});
});