@@ -2,9 +2,13 @@ import { FileReplacement } from '@ng-rspack/compiler';
2
2
import {
3
3
getHasServer ,
4
4
HasServerOptions ,
5
+ normalizeOptions ,
6
+ normalizeOptionsServerOptions ,
5
7
resolveFileReplacements ,
6
8
} from './normalize-options' ;
7
- import { describe } from 'vitest' ;
9
+ import { describe , expect } from 'vitest' ;
10
+ import { vol } from 'memfs' ;
11
+ import { MEMFS_VOLUME } from '@ng-rspack/testing-utils' ;
8
12
9
13
describe ( 'resolveFileReplacements' , ( ) => {
10
14
it ( 'should resolve file replacements' , ( ) => {
@@ -19,6 +23,10 @@ describe('resolveFileReplacements', () => {
19
23
} ) ;
20
24
21
25
describe ( 'getHasServer' , ( ) => {
26
+ afterEach ( ( ) => {
27
+ vol . reset ( ) ;
28
+ } ) ;
29
+
22
30
it ( 'should return false if server is not provided' , ( ) => {
23
31
expect ( getHasServer ( { root : '' } ) ) . toBe ( false ) ;
24
32
} ) ;
@@ -30,16 +38,116 @@ describe('getHasServer', () => {
30
38
it ( 'should return false if server file does not exist' , ( ) => {
31
39
expect (
32
40
getHasServer ( {
33
- server : 'server ' ,
34
- ssrEntry : 'ssrEntry ' ,
41
+ server : 'main.ts ' ,
42
+ ssrEntry : 'server.main.ts ' ,
35
43
root : '/not-existing-folder' ,
36
44
} )
37
45
) . toBe ( false ) ;
38
46
} ) ;
39
47
40
- it . todo ( 'should return true if server and ssrEntry files exist' , ( ) => {
48
+ it ( 'should return true if server and ssrEntry files exist' , ( ) => {
49
+ vol . fromJSON (
50
+ {
51
+ 'main.ts' : '' ,
52
+ 'server.main.ts' : '' ,
53
+ } ,
54
+ MEMFS_VOLUME
55
+ ) ;
56
+
41
57
expect (
42
- getHasServer ( { server : 'server' , ssrEntry : 'ssrEntry' , root : __dirname } )
58
+ getHasServer ( {
59
+ server : 'main.ts' ,
60
+ ssrEntry : 'server.main.ts' ,
61
+ root : MEMFS_VOLUME ,
62
+ } )
43
63
) . toBe ( true ) ;
44
64
} ) ;
45
65
} ) ;
66
+
67
+ describe ( 'normalizeOptionsServerOptions' , ( ) => {
68
+ it ( 'should return hasServer false options if getHasServer is false' , ( ) => {
69
+ expect (
70
+ normalizeOptionsServerOptions ( {
71
+ root : MEMFS_VOLUME ,
72
+ } )
73
+ ) . toStrictEqual ( { hasServer : false } ) ;
74
+ } ) ;
75
+
76
+ it ( 'should return hasServer true as well as the server and ssrEntry options if getHasServer is true' , ( ) => {
77
+ vol . fromJSON (
78
+ {
79
+ 'main.ts' : '' ,
80
+ 'server.main.ts' : '' ,
81
+ } ,
82
+ MEMFS_VOLUME
83
+ ) ;
84
+
85
+ expect (
86
+ normalizeOptionsServerOptions ( {
87
+ server : 'main.ts' ,
88
+ ssrEntry : 'server.main.ts' ,
89
+ root : MEMFS_VOLUME ,
90
+ } )
91
+ ) . toStrictEqual ( {
92
+ hasServer : true ,
93
+ server : 'main.ts' ,
94
+ ssrEntry : 'server.main.ts' ,
95
+ } ) ;
96
+ } ) ;
97
+ } ) ;
98
+
99
+ describe ( 'normalizeOptions' , ( ) => {
100
+ it ( 'should normalize options default options' , ( ) => {
101
+ expect ( normalizeOptions ( ) ) . toStrictEqual ( {
102
+ root : process . cwd ( ) ,
103
+ aot : true ,
104
+ hasServer : false ,
105
+ inlineStyleLanguage : 'css' ,
106
+ skipTypeChecking : false ,
107
+ polyfills : [ ] ,
108
+ index : './src/index.html' ,
109
+ browser : './src/main.ts' ,
110
+ assets : [ './public' ] ,
111
+ styles : [ './src/styles.css' ] ,
112
+ scripts : [ ] ,
113
+ fileReplacements : [ ] ,
114
+ tsConfig : expect . stringMatching ( / t s c o n f i g .a p p .j s o n $ / ) ,
115
+ useTsProjectReferences : false ,
116
+ } ) ;
117
+ } ) ;
118
+
119
+ it ( 'should normalize options server options' , ( ) => {
120
+ vol . fromJSON (
121
+ {
122
+ 'main.ts' : '' ,
123
+ 'server.main.ts' : '' ,
124
+ } ,
125
+ MEMFS_VOLUME
126
+ ) ;
127
+
128
+ expect (
129
+ normalizeOptions ( {
130
+ root : MEMFS_VOLUME ,
131
+ server : 'main.ts' ,
132
+ ssrEntry : 'server.main.ts' ,
133
+ } )
134
+ ) . toStrictEqual ( {
135
+ root : MEMFS_VOLUME ,
136
+ server : 'main.ts' ,
137
+ ssrEntry : 'server.main.ts' ,
138
+ hasServer : true ,
139
+ aot : true ,
140
+ inlineStyleLanguage : 'css' ,
141
+ skipTypeChecking : false ,
142
+ polyfills : [ ] ,
143
+ index : './src/index.html' ,
144
+ browser : './src/main.ts' ,
145
+ assets : [ './public' ] ,
146
+ styles : [ './src/styles.css' ] ,
147
+ scripts : [ ] ,
148
+ fileReplacements : [ ] ,
149
+ tsConfig : expect . stringMatching ( / t s c o n f i g .a p p .j s o n $ / ) ,
150
+ useTsProjectReferences : false ,
151
+ } ) ;
152
+ } ) ;
153
+ } ) ;
0 commit comments