-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
77 lines (72 loc) · 1.95 KB
/
index.test.js
File metadata and controls
77 lines (72 loc) · 1.95 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
const plugin = require("./index");
beforeEach(() => {
jest.resetModules();
});
describe("plugin", () => {
it("adds runtime configuration to the Next config", () => {
jest.doMock(
"config",
() => ({
serverRuntimeConfig: { foo: "bar" },
publicRuntimeConfig: { value: 5 }
}),
{ virtual: true }
);
const nextConfig = plugin({});
expect(nextConfig.serverRuntimeConfig).toEqual({ foo: "bar" });
expect(nextConfig.publicRuntimeConfig).toEqual({ value: 5 });
});
it("extends runtime configuration if some already exists", () => {
jest.doMock(
"config",
() => ({
publicRuntimeConfig: { value: 5 },
serverRuntimeConfig: { foo: "bar" }
}),
{ virtual: true }
);
const nextConfig = plugin({
serverRuntimeConfig: { secret: "entropy9" },
publicRuntimeConfig: { public: "house" }
});
expect(nextConfig.serverRuntimeConfig).toEqual({
secret: "entropy9",
foo: "bar"
});
expect(nextConfig.publicRuntimeConfig).toEqual({
public: "house",
value: 5
});
});
it("allows customizing which keys contain the runtime config", () => {
jest.doMock(
"config",
() => ({
server: { foo: "bar" },
public: { value: 5 }
}),
{ virtual: true }
);
const nextConfig = plugin({
nodeConfigServerKey: "server",
nodeConfigPublicKey: "public"
});
expect(nextConfig.serverRuntimeConfig).toEqual({ foo: "bar" });
expect(nextConfig.publicRuntimeConfig).toEqual({
value: 5,
nodeConfigServerKey: "server",
nodeConfigPublicKey: "public"
});
});
it("adds an alias for config to the webpack config", () => {
jest.doMock("config", () => ({}), { virtual: true });
const nextConfig = plugin({});
expect(nextConfig.webpack({})).toEqual({
resolve: {
alias: {
config$: require.resolve("./config")
}
}
});
});
});