-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdeploy.config.test.mjs
More file actions
72 lines (63 loc) · 2.57 KB
/
Copy pathdeploy.config.test.mjs
File metadata and controls
72 lines (63 loc) · 2.57 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
import { afterEach, describe, expect, it, vi } from 'vitest';
// deploy.config.mjs reads NEXT_PUBLIC_DEPLOY_TARGET at module-evaluation time, so
// each case stubs the env and re-imports with a fresh module registry.
async function loadWithTarget(target) {
vi.resetModules();
vi.stubEnv('NEXT_PUBLIC_DEPLOY_TARGET', target);
return import('./deploy.config.mjs');
}
afterEach(() => {
vi.unstubAllEnvs();
});
describe('deploy.config', () => {
it('defaults to external when the target is unset', async () => {
const c = await loadWithTarget(undefined);
expect(c.TARGET).toBe('external');
});
it('treats any non-internal value as external', async () => {
const c = await loadWithTarget('nonsense');
expect(c.TARGET).toBe('external');
});
describe('external target', () => {
it('excludes internal-only surfaces', async () => {
const c = await loadWithTarget('external');
expect(c.surfaceEnabled('internal-explorer')).toBe(false);
expect(c.surfaceEnabled('benchmark')).toBe(false);
});
it('reports the disabled route + api prefixes and subtree globs', async () => {
const c = await loadWithTarget('external');
expect(c.disabledRoutePrefixes()).toEqual(['/internal-explorer', '/tips', '/benchmark']);
// Benchmark contributes no api prefix: it calls the report API directly
// from the browser rather than through a route handler in this app.
expect(c.disabledApiPrefixes()).toEqual(['/api/internal-explorer', '/api/tips']);
expect(c.disabledRouteGlobs()).toEqual([
'/internal-explorer',
'/internal-explorer/**',
'/tips',
'/tips/**',
'/benchmark',
'/benchmark/**',
]);
});
});
describe('internal target', () => {
it('includes internal-only surfaces', async () => {
const c = await loadWithTarget('internal');
expect(c.TARGET).toBe('internal');
expect(c.surfaceEnabled('internal-explorer')).toBe(true);
expect(c.surfaceEnabled('benchmark')).toBe(true);
});
it('disables nothing', async () => {
const c = await loadWithTarget('internal');
expect(c.disabledRoutePrefixes()).toEqual([]);
expect(c.disabledApiPrefixes()).toEqual([]);
expect(c.disabledRouteGlobs()).toEqual([]);
});
});
it('treats surfaces absent from the matrix as enabled everywhere', async () => {
const external = await loadWithTarget('external');
expect(external.surfaceEnabled('snapshots')).toBe(true);
const internal = await loadWithTarget('internal');
expect(internal.surfaceEnabled('snapshots')).toBe(true);
});
});