@@ -5,12 +5,100 @@ import { getBundleResources as getBundleResourcesActual } from "../../windows/pr
55import { fs , setMockFiles } from "../fs.mock.mts" ;
66
77describe ( "getBundleResources()" , ( ) => {
8- const getBundleResources : typeof getBundleResourcesActual = ( p ) =>
9- getBundleResourcesActual ( p , fs ) ;
8+ const getBundleResources : typeof getBundleResourcesActual = ( p , opts ) =>
9+ getBundleResourcesActual ( p , opts , fs ) ;
10+
11+ const legacyOpts = { useFabric : false } ;
12+ const newArchOpts = { useFabric : true } ;
1013
1114 afterEach ( ( ) => setMockFiles ( ) ) ;
1215
13- it ( "returns app name and bundle resources" , ( ) => {
16+ for ( const opts of [ legacyOpts , newArchOpts ] ) {
17+ const arch = opts . useFabric ? "new" : "old" ;
18+
19+ it ( `returns package manifest (${ arch } arch)` , ( ) => {
20+ setMockFiles ( {
21+ "app.json" : JSON . stringify ( {
22+ windows : {
23+ appxManifest : "windows/Example/Package.appxmanifest" ,
24+ } ,
25+ } ) ,
26+ } ) ;
27+
28+ deepEqual ( getBundleResources ( "app.json" , opts ) , {
29+ appName : "ReactTestApp" ,
30+ singleApp : undefined ,
31+ appxManifest : "windows\\Example\\Package.appxmanifest" ,
32+ assetItems : "" ,
33+ assetItemFilters : "" ,
34+ assetFilters : "" ,
35+ contentItems : "" ,
36+ packageCertificate : "" ,
37+ } ) ;
38+ } ) ;
39+
40+ it ( `handles missing manifest (${ arch } arch)` , ( t ) => {
41+ const warnMock = t . mock . method ( console , "warn" , ( ) => null ) ;
42+
43+ deepEqual ( getBundleResources ( "" , opts ) , {
44+ appName : "ReactTestApp" ,
45+ appxManifest : "windows/Package.appxmanifest" ,
46+ assetItems : "" ,
47+ assetItemFilters : "" ,
48+ assetFilters : "" ,
49+ contentItems : "" ,
50+ packageCertificate : "" ,
51+ } ) ;
52+
53+ equal (
54+ warnMock . mock . calls [ 0 ] . arguments [ 1 ] ,
55+ "Could not find 'app.json' file."
56+ ) ;
57+ } ) ;
58+
59+ it ( `handles invalid manifest (${ arch } arch)` , ( t ) => {
60+ const warnMock = t . mock . method ( console , "warn" , ( ) => null ) ;
61+ setMockFiles ( { "app.json" : "-" } ) ;
62+
63+ deepEqual ( getBundleResources ( "app.json" , opts ) , {
64+ appName : "ReactTestApp" ,
65+ appxManifest : "windows/Package.appxmanifest" ,
66+ assetItems : "" ,
67+ assetItemFilters : "" ,
68+ assetFilters : "" ,
69+ contentItems : "" ,
70+ packageCertificate : "" ,
71+ } ) ;
72+
73+ match (
74+ warnMock . mock . calls [ 0 ] . arguments [ 1 ] ,
75+ / ^ C o u l d n o t p a r s e ' a p p .j s o n ' : \n /
76+ ) ;
77+ } ) ;
78+
79+ it ( `returns package certificate (${ arch } arch)` , ( ) => {
80+ setMockFiles ( {
81+ "app.json" : JSON . stringify ( {
82+ windows : {
83+ certificateKeyFile : "windows/ReactTestApp_TemporaryKey.pfx" ,
84+ certificateThumbprint : "thumbprint" ,
85+ certificatePassword : "password" ,
86+ } ,
87+ } ) ,
88+ } ) ;
89+
90+ const { packageCertificate } = getBundleResources ( "app.json" , opts ) ;
91+ equal (
92+ packageCertificate ,
93+ `<AppxPackageSigningEnabled>true</AppxPackageSigningEnabled>
94+ <PackageCertificateKeyFile>$(ProjectRootDir)\\windows\\ReactTestApp_TemporaryKey.pfx</PackageCertificateKeyFile>
95+ <PackageCertificateThumbprint>thumbprint</PackageCertificateThumbprint>
96+ <PackageCertificatePassword>password</PackageCertificatePassword>`
97+ ) ;
98+ } ) ;
99+ }
100+
101+ it ( "returns app name and bundle resources (old arch)" , ( ) => {
14102 const assets = path . join ( "dist" , "assets" ) ;
15103 const bundle = path . join ( "dist" , "main.bundle" ) ;
16104 setMockFiles ( {
@@ -28,17 +116,18 @@ describe("getBundleResources()", () => {
28116 assetItems,
29117 assetItemFilters,
30118 assetFilters,
31- } = getBundleResources ( "app.json" ) ;
119+ contentItems,
120+ } = getBundleResources ( "app.json" , legacyOpts ) ;
32121
33122 equal ( appName , "Example" ) ;
34123 equal ( appxManifest , "windows\\Package.appxmanifest" ) ;
35124 equal (
36125 assetItems ,
37126 `<CopyFileToFolders Include="$(ProjectRootDir)\\dist\\assets\\app.json">
38- <DestinationFolders>$(BundleDir) \\assets</DestinationFolders>
127+ <DestinationFolders>$(OutDir)\\Bundle \\assets</DestinationFolders>
39128 </CopyFileToFolders>
40129 <CopyFileToFolders Include="$(ProjectRootDir)\\dist\\main.bundle">
41- <DestinationFolders>$(BundleDir) </DestinationFolders>
130+ <DestinationFolders>$(OutDir)\\Bundle </DestinationFolders>
42131 </CopyFileToFolders>`
43132 ) ;
44133 equal (
@@ -54,83 +143,45 @@ describe("getBundleResources()", () => {
54143 assetFilters ,
55144 / ^ < F i l t e r I n c l u d e = " A s s e t s \\ a s s e t s " > \s + < U n i q u e I d e n t i f i e r > { [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } } < \/ U n i q u e I d e n t i f i e r > \s + < \/ F i l t e r > $ /
56145 ) ;
146+ equal ( contentItems , "" ) ;
57147 } ) ;
58148
59- it ( "returns package manifest" , ( ) => {
149+ it ( "returns app name and bundle resources (new arch)" , ( ) => {
150+ const assets = path . join ( "dist" , "assets" ) ;
151+ const bundle = path . join ( "dist" , "main.bundle" ) ;
60152 setMockFiles ( {
61153 "app.json" : JSON . stringify ( {
62- windows : {
63- appxManifest : "windows/Example/Package.appxmanifest" ,
64- } ,
154+ name : "Example" ,
155+ resources : [ assets , bundle ] ,
65156 } ) ,
157+ [ path . join ( assets , "app.json" ) ] : "{}" ,
158+ [ bundle ] : "'use strict';" ,
66159 } ) ;
67160
68- deepEqual ( getBundleResources ( "app.json" ) , {
69- appName : "ReactTestApp" ,
70- singleApp : undefined ,
71- appxManifest : "windows\\Example\\Package.appxmanifest" ,
72- assetItems : "" ,
73- assetItemFilters : "" ,
74- assetFilters : "" ,
75- packageCertificate : "" ,
76- } ) ;
77- } ) ;
78-
79- it ( "handles missing manifest" , ( t ) => {
80- const warnMock = t . mock . method ( console , "warn" , ( ) => null ) ;
81-
82- deepEqual ( getBundleResources ( "" ) , {
83- appName : "ReactTestApp" ,
84- appxManifest : "windows/Package.appxmanifest" ,
85- assetItems : "" ,
86- assetItemFilters : "" ,
87- assetFilters : "" ,
88- packageCertificate : "" ,
89- } ) ;
90-
91- equal (
92- warnMock . mock . calls [ 0 ] . arguments [ 1 ] ,
93- "Could not find 'app.json' file."
94- ) ;
95- } ) ;
96-
97- it ( "handles invalid manifest" , ( t ) => {
98- const warnMock = t . mock . method ( console , "warn" , ( ) => null ) ;
99- setMockFiles ( { "app.json" : "-" } ) ;
100-
101- deepEqual ( getBundleResources ( "app.json" ) , {
102- appName : "ReactTestApp" ,
103- appxManifest : "windows/Package.appxmanifest" ,
104- assetItems : "" ,
105- assetItemFilters : "" ,
106- assetFilters : "" ,
107- packageCertificate : "" ,
108- } ) ;
109-
110- match (
111- warnMock . mock . calls [ 0 ] . arguments [ 1 ] ,
112- / ^ C o u l d n o t p a r s e ' a p p .j s o n ' : \n /
113- ) ;
114- } ) ;
115-
116- it ( "returns package certificate" , ( ) => {
117- setMockFiles ( {
118- "app.json" : JSON . stringify ( {
119- windows : {
120- certificateKeyFile : "windows/ReactTestApp_TemporaryKey.pfx" ,
121- certificateThumbprint : "thumbprint" ,
122- certificatePassword : "password" ,
123- } ,
124- } ) ,
125- } ) ;
161+ const {
162+ appName,
163+ appxManifest,
164+ assetItems,
165+ assetItemFilters,
166+ assetFilters,
167+ contentItems,
168+ } = getBundleResources ( "app.json" , newArchOpts ) ;
126169
127- const { packageCertificate } = getBundleResources ( "app.json" ) ;
170+ equal ( appName , "Example" ) ;
171+ equal ( appxManifest , "windows\\Package.appxmanifest" ) ;
172+ equal ( assetItems , "" ) ;
173+ equal ( assetItemFilters , "" ) ;
174+ equal ( assetFilters , "" ) ;
128175 equal (
129- packageCertificate ,
130- `<AppxPackageSigningEnabled>true</AppxPackageSigningEnabled>
131- <PackageCertificateKeyFile>$(ProjectRootDir)\\windows\\ReactTestApp_TemporaryKey.pfx</PackageCertificateKeyFile>
132- <PackageCertificateThumbprint>thumbprint</PackageCertificateThumbprint>
133- <PackageCertificatePassword>password</PackageCertificatePassword>`
176+ contentItems ,
177+ `<Content Include="$(ProjectRootDir)\\dist\\assets\\app.json">
178+ <Link>Bundle\\assets\\app.json</Link>
179+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
180+ </Content>
181+ <Content Include="$(ProjectRootDir)\\dist\\main.bundle">
182+ <Link>Bundle\\main.bundle</Link>
183+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
184+ </Content>`
134185 ) ;
135186 } ) ;
136187} ) ;
0 commit comments