-
Notifications
You must be signed in to change notification settings - Fork 8
/
dev-config.test.ts
85 lines (80 loc) · 2.22 KB
/
dev-config.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
import test from "ava";
import createDevConfig from "./dev-config";
const favPath = "test.js";
const manifestDetails = {
description: "index.html",
hasManifest: false,
name: "test",
shortName: "test",
startURL: "/",
themeColor: "#ffffff",
};
const outputDir = "./dist";
const swExpected = `new GenerateSW({
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [{
urlPattern: /\\/\$/,
handler: 'networkFirst',
options: {
cacheName: 'sw-app-index'
}
}]
})`;
const htmlExpected = "new HtmlWebpackPlugin({filename:'index.html',template:'./templates/_index.html'})";
const fpExpected = `new WebappWebpackPlugin({
logo: './test.js',
favicons: {
appName: 'test',
appDescription: 'index.html',
start_url: '/',
theme_color: '#ffffff'
}
})`;
test("create dev config to return when serviceworker is true", (t) => {
const config = {
serviceWorker: true,
};
const { plugins } = createDevConfig(config);
t.is(plugins.length, 2);
t.is(plugins[0], swExpected);
t.is(plugins[1], htmlExpected);
});
test("create dev config to return when only favPath is defined", (t) => {
const config = {
favPath,
manifestDetails,
serviceWorker: false,
};
const { plugins } = createDevConfig(config);
t.is(plugins.length, 1);
t.is(plugins[0], fpExpected);
});
test("create dev config to return empty when both are sent", (t) => {
const config = {
favPath,
manifestDetails,
serviceWorker: true,
};
const { plugins } = createDevConfig(config);
t.is(plugins.length, 3);
t.is(plugins[0], swExpected);
t.is(plugins[1], htmlExpected);
t.is(plugins[2], fpExpected);
});
// Removed Existing manifest testing.
// tslint:disable-next-line:max-line-length
test("create dev config when serviceWorker, favPath, manifestDetails, outputDir are sent and new manifest file is created", (t) => {
const config = {
favPath,
manifestDetails,
outputDir,
serviceWorker: true,
};
const { plugins } = createDevConfig(config);
t.is(plugins.length, 3);
t.is(plugins[0], swExpected);
t.is(plugins[1], htmlExpected);
t.is(plugins[2], fpExpected);
});
test("create dev config to return empty when config is empty", (t) => t.is(createDevConfig({}).plugins.length, 0));