-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathssr-manifest.test.ts
More file actions
113 lines (96 loc) · 3.69 KB
/
ssr-manifest.test.ts
File metadata and controls
113 lines (96 loc) · 3.69 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
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
107
108
109
110
111
112
113
import { describe, it, expect } from 'vitest'
/**
* Tests for SSR manifest generation.
*
* These tests verify that the Vite plugin correctly generates the Angular SSR
* manifests required by AngularNodeAppEngine. Without these manifests, SSR fails with:
* "Angular app engine manifest is not set."
*
* See: https://github.com/voidzero-dev/oxc-angular-compiler/issues/60
*/
// Import the SSR manifest plugin directly
import {
ssrManifestPlugin,
generateAppManifestCode,
generateAppEngineManifestCode,
} from '../vite-plugin/angular-ssr-manifest-plugin.js'
describe('SSR Manifest Generation (Issue #60)', () => {
describe('generateAppManifestCode', () => {
it('should generate valid app manifest code with bootstrap import', () => {
const code = generateAppManifestCode({
ssrEntryImport: './src/main.server',
baseHref: '/',
indexHtmlContent: '<html><body><app-root></app-root></body></html>',
})
expect(code).toContain('ɵsetAngularAppManifest')
expect(code).toContain('./src/main.server')
expect(code).toContain('bootstrap')
expect(code).toContain('inlineCriticalCss')
expect(code).toContain('index.server.html')
expect(code).toContain('<html><body><app-root></app-root></body></html>')
})
it('should escape template literal characters in HTML', () => {
const code = generateAppManifestCode({
ssrEntryImport: './src/main.server',
baseHref: '/',
indexHtmlContent: '<html><body>${unsafe}`backtick`\\backslash</body></html>',
})
// Template literal chars should be escaped
expect(code).toContain('\\${unsafe}')
expect(code).toContain('\\`backtick\\`')
expect(code).toContain('\\\\backslash')
// The dollar sign should be escaped to prevent template literal injection
expect(code).not.toMatch(/[^\\]\$\{unsafe\}/)
})
it('should use custom baseHref', () => {
const code = generateAppManifestCode({
ssrEntryImport: './src/main.server',
baseHref: '/my-app/',
indexHtmlContent: '<html></html>',
})
expect(code).toContain("baseHref: '/my-app/'")
})
})
describe('generateAppEngineManifestCode', () => {
it('should generate valid app engine manifest code', () => {
const code = generateAppEngineManifestCode({
basePath: '/',
})
expect(code).toContain('ɵsetAngularAppEngineManifest')
expect(code).toContain("basePath: '/'")
expect(code).toContain('supportedLocales')
expect(code).toContain('entryPoints')
expect(code).toContain('allowedHosts')
})
it('should strip trailing slash from basePath (except root)', () => {
const code = generateAppEngineManifestCode({
basePath: '/my-app/',
})
expect(code).toContain("basePath: '/my-app'")
})
it('should keep root basePath as-is', () => {
const code = generateAppEngineManifestCode({
basePath: '/',
})
expect(code).toContain("basePath: '/'")
})
it('should include ɵgetOrCreateAngularServerApp in entry points', () => {
const code = generateAppEngineManifestCode({
basePath: '/',
})
expect(code).toContain('ɵgetOrCreateAngularServerApp')
expect(code).toContain('ɵdestroyAngularServerApp')
expect(code).toContain('ɵextractRoutesAndCreateRouteTree')
})
})
describe('ssrManifestPlugin', () => {
it('should create a plugin with correct name', () => {
const plugin = ssrManifestPlugin({})
expect(plugin.name).toBe('@oxc-angular/vite-ssr-manifest')
})
it('should only apply to build mode', () => {
const plugin = ssrManifestPlugin({})
expect(plugin.apply).toBe('build')
})
})
})