-
Notifications
You must be signed in to change notification settings - Fork 441
Expand file tree
/
Copy pathpwa-manifest.spec.ts
More file actions
79 lines (70 loc) · 2.43 KB
/
Copy pathpwa-manifest.spec.ts
File metadata and controls
79 lines (70 loc) · 2.43 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
79
import { readFileSync } from 'node:fs';
import { joinPaths } from '@php-wasm/util';
const appRoot = joinPaths(process.cwd(), 'packages/playground/personal-wp');
describe('PWA manifest configuration', () => {
it('includes install metadata, screenshots, and maskable icons', () => {
const manifest = readJson('public/manifest.json');
expect(manifest).toMatchObject({
id: '/',
display: 'standalone',
display_override: ['standalone'],
scope: '/',
start_url: '/',
categories: ['productivity', 'utilities'],
});
expect(manifest.screenshots).toEqual([
expect.objectContaining({
src: 'ogimage-mywp.png',
sizes: '1200x600',
form_factor: 'wide',
}),
]);
expect(manifest).not.toHaveProperty('shortcuts');
expect(manifest.icons).toEqual(
expect.arrayContaining([
expect.objectContaining({
src: 'maskable-icon-512.png',
sizes: '512x512',
purpose: 'maskable',
}),
])
);
});
it('adds iOS install metadata and links the production dynamic manifest', () => {
const html = readText('index.html');
expect(html).toMatch(
/<link\b(?=[^>]*\brel="apple-touch-icon")(?=[^>]*\bhref="\/apple-touch-icon\.png")[^>]*>/
);
expect(html).toMatch(
/<meta\b(?=[^>]*\bname="apple-mobile-web-app-capable")(?=[^>]*\bcontent="yes")[^>]*>/
);
expect(html).toMatch(
/<meta\b(?=[^>]*\bname="apple-mobile-web-app-title")(?=[^>]*\bcontent="My WordPress")[^>]*>/
);
expect(html).toContain('/dynamic-manifest.json.php');
expect(html).toContain(
"window.location.pathname.startsWith('/website-server/')"
);
expect(html).not.toContain('if (!manifestUrl)');
});
it('keeps dynamic manifest identity stable across cache-busting URLs', () => {
const php = readText('public/dynamic-manifest.json.php');
expect(php).toContain('function getManifestId($start_url)');
expect(php).toContain("unset($query['random']);");
expect(php).toContain('"id" => getManifestId($start_url)');
expect(php).toContain('"scope" => $base_url . "/"');
expect(php).toContain("$_SERVER['HTTP_HOST']");
expect(php).not.toContain('getTrustedBaseUrl');
expect(php).toContain(" : '/'");
expect(php).not.toContain('"shortcuts" =>');
expect(php).toContain(
"$app_name = $_GET['app_name'] ?? 'My WordPress';"
);
});
});
function readJson(relativePath: string) {
return JSON.parse(readText(relativePath));
}
function readText(relativePath: string) {
return readFileSync(joinPaths(appRoot, relativePath), 'utf8');
}