-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
106 lines (89 loc) · 2.53 KB
/
test.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Node dependencies
*/
const { resolve } = require('path');
const { existsSync, readdir } = require('fs');
/**
* Test environment
*/
const tape = require('tape');
const createPWA = require('./src');
const { iconSizes, faviconSizes, msTileSizes, launchScreenSizes, appleTouchIconSizes } = require('./src/helpers');
/**
* Init
*/
createPWA();
/**
* Test if a manifest is created
*/
tape('Should create a manifest', t => {
const manifest = resolve(__dirname, './manifest.json');
const manifestExists = existsSync(manifest);
t.ok(manifestExists, 'manifest.json exists');
t.end();
});
/**
* Test if the app name is correct
*/
tape('The name of the app should be "create-pwa"', t => {
t.equal(require(resolve(__dirname, './manifest.json')).name, 'create-pwa', 'The name of the PWA is "create-pwa"');
t.end();
});
/**
* Test if a service worker is created
*/
tape('Should create a service worker', t => {
const sw = resolve(__dirname, './service-worker.js');
const serviceWorkerExists = existsSync(sw);
t.ok(serviceWorkerExists, 'service-worker.js exists');
t.end();
});
/**
* Test if an appcache file is created
*/
tape('Should create an appcache file', t => {
const ac = resolve(__dirname, './create-pwa.appcache');
const appCacheFileExists = existsSync(ac);
t.ok(appCacheFileExists, 'create-pwa.appcache exists');
t.end();
});
/**
* Test if icons are being generated
*/
tape('Should generate icons', t => {
readdir(resolve(__dirname, 'icons'), (err, files) => {
const len = iconSizes.length;
t.equal(len, files.length, `There should be ${len} icon files`);
t.end();
});
});
/**
* Test if launch screens are being created
*/
tape('Should generate launch screens', t => {
readdir(resolve(__dirname, 'launch-screens'), (err, files) => {
const len = Array.from(new Set(launchScreenSizes)).length;
t.equal(len, files.length, `There should be ${len} launch screen files`);
t.end();
});
});
/**
* Test if favicons are being created
*/
tape('Should generate favicons', t => {
readdir(resolve(__dirname, 'favicons'), (err, files) => {
const len = faviconSizes.length + msTileSizes.length + appleTouchIconSizes.length;
files = files.filter(file => !file.endsWith('ico'));
t.equal(len, files.length, `There should be ${len} favicon files.`);
t.end();
});
});
/**
* Test if config.xml is being created
*/
tape('Should generate a config file for Microsoft browsers', t => {
const ac = resolve(__dirname, './config.xml');
const configFileExists = existsSync(ac);
t.ok(configFileExists, 'config.xml exists');
t.end();
});