-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathwithSentryConfig.test.ts
More file actions
78 lines (60 loc) · 2.67 KB
/
withSentryConfig.test.ts
File metadata and controls
78 lines (60 loc) · 2.67 KB
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
import { describe, expect, it, vi } from 'vitest';
import { defaultRuntimePhase, defaultsObject, exportedNextConfig, 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 = vi.fn().mockReturnValue(userNextConfig);
materializeFinalNextConfig(exportedNextConfigFunction);
expect(exportedNextConfigFunction).toHaveBeenCalledWith(defaultRuntimePhase, defaultsObject);
});
it('handles experimental build mode correctly', () => {
const originalArgv = process.argv;
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
try {
process.argv = [...originalArgv, '--experimental-build-mode'];
materializeFinalNextConfig(exportedNextConfig);
expect(consoleWarnSpy).toHaveBeenCalledWith(
'[@sentry/nextjs] The Sentry Next.js SDK does not currently fully support next build --experimental-build-mode',
);
// Generate phase
process.argv = [...process.argv, 'generate'];
const generateConfig = materializeFinalNextConfig(exportedNextConfig);
expect(generateConfig).toEqual(exportedNextConfig);
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
} finally {
process.argv = originalArgv;
consoleWarnSpy.mockRestore();
}
});
});