@@ -35,29 +35,72 @@ describe('cloudflare-pages-integration generator', () => {
35
35
it ( 'should add required targets' , async ( ) => {
36
36
await cloudflarePagesIntegrationGenerator ( appTree , options ) ;
37
37
const config = readProjectConfiguration ( appTree , projectName ) ;
38
- expect (
39
- config . targets ! [ 'build.ssr' ] . configurations ! [ 'cloudflare-pages' ]
40
- ) . toEqual ( {
38
+ expect ( config . targets ! [ 'build.ssr' ] . configurations ! [ 'production' ] ) . toEqual ( {
41
39
configFile : `apps/${ projectName } /adaptors/cloudflare-pages/vite.config.ts` ,
42
40
} ) ;
43
41
expect ( config . targets ! [ 'deploy' ] ) . toEqual ( {
44
42
executor : '@k11r/nx-cloudflare-wrangler:deploy-page' ,
45
43
options : {
46
44
dist : `dist/apps/${ projectName } /client` ,
47
45
} ,
48
- dependsOn : [ 'build-cloudflare-pages ' ] ,
46
+ dependsOn : [ 'build-cloudflare' ] ,
49
47
} ) ;
50
- expect ( config . targets ! [ 'preview-cloudflare-pages ' ] ) . toEqual ( {
48
+ expect ( config . targets ! [ 'preview-cloudflare' ] ) . toEqual ( {
51
49
executor : '@k11r/nx-cloudflare-wrangler:serve-page' ,
52
50
options : {
53
51
dist : `dist/apps/${ projectName } /client` ,
54
52
} ,
55
- dependsOn : [ 'build-cloudflare-pages ' ] ,
53
+ dependsOn : [ 'build-cloudflare' ] ,
56
54
} ) ;
57
- expect ( config . targets ! [ 'build-cloudflare-pages ' ] ) . toEqual ( {
55
+ expect ( config . targets ! [ 'build-cloudflare' ] ) . toEqual ( {
58
56
executor : 'nx:run-commands' ,
59
57
options : {
60
- command : `npx nx run ${ projectName } :build:cloudflare-pages` ,
58
+ command : `npx nx run ${ projectName } :build:production` ,
59
+ } ,
60
+ } ) ;
61
+ } ) ;
62
+
63
+ it ( 'should use other target name if deploy target is already defined' , async ( ) => {
64
+ const configBefore = readProjectConfiguration ( appTree , projectName ) ;
65
+ configBefore . targets ! [ 'deploy' ] = { executor : 'nx:noop' } ;
66
+ updateProjectConfiguration ( appTree , projectName , configBefore ) ;
67
+
68
+ await cloudflarePagesIntegrationGenerator ( appTree , options ) ;
69
+
70
+ const config = readProjectConfiguration ( appTree , projectName ) ;
71
+ expect ( config . targets ! [ 'build.ssr' ] . configurations ! [ 'production' ] ) . toEqual ( {
72
+ configFile : `apps/${ projectName } /adaptors/cloudflare-pages/vite.config.ts` ,
73
+ } ) ;
74
+ expect ( config . targets ! [ 'deploy' ] ) . toEqual ( { executor : 'nx:noop' } ) ;
75
+ expect ( config . targets ! [ 'deploy.cloudflare' ] . executor ) . toEqual (
76
+ '@k11r/nx-cloudflare-wrangler:deploy-page'
77
+ ) ;
78
+ } ) ;
79
+
80
+ it ( 'should use the name of the integration if configuration name "production" is already defined' , async ( ) => {
81
+ const configBefore = readProjectConfiguration ( appTree , projectName ) ;
82
+ configBefore . targets ! [ 'build.ssr' ] . configurations ! [ 'production' ] = { } ;
83
+ updateProjectConfiguration ( appTree , projectName , configBefore ) ;
84
+
85
+ await cloudflarePagesIntegrationGenerator ( appTree , options ) ;
86
+
87
+ const config = readProjectConfiguration ( appTree , projectName ) ;
88
+ expect (
89
+ config . targets ! [ 'build' ] . configurations ! [ 'production' ]
90
+ ) . toBeUndefined ( ) ;
91
+ expect ( config . targets ! [ 'build.ssr' ] . configurations ! [ 'production' ] ) . toEqual (
92
+ { }
93
+ ) ;
94
+ expect ( config . targets ! [ 'build.ssr' ] . configurations ! [ 'cloudflare' ] ) . toEqual ( {
95
+ configFile : `apps/${ projectName } /adaptors/cloudflare-pages/vite.config.ts` ,
96
+ } ) ;
97
+ expect ( config . targets ! [ 'deploy' ] . executor ) . toEqual (
98
+ '@k11r/nx-cloudflare-wrangler:deploy-page'
99
+ ) ;
100
+ expect ( config . targets ! [ 'build-cloudflare' ] ) . toEqual ( {
101
+ executor : 'nx:run-commands' ,
102
+ options : {
103
+ command : `npx nx run ${ projectName } :build:cloudflare` ,
61
104
} ,
62
105
} ) ;
63
106
} ) ;
@@ -70,17 +113,6 @@ describe('cloudflare-pages-integration generator', () => {
70
113
} ) ;
71
114
72
115
describe ( 'should throw if project configuration does not meet the expectations' , ( ) => {
73
- it ( 'deploy target is already defined' , async ( ) => {
74
- const config = readProjectConfiguration ( appTree , projectName ) ;
75
- config . targets ! [ 'deploy' ] = { executor : 'nx:noop' } ;
76
- updateProjectConfiguration ( appTree , projectName , config ) ;
77
-
78
- expect (
79
- cloudflarePagesIntegrationGenerator ( appTree , options )
80
- ) . rejects . toThrow (
81
- `"deploy" target has already been configured for ${ options . project } `
82
- ) ;
83
- } ) ;
84
116
it ( 'project is not an application' , async ( ) => {
85
117
const config = readProjectConfiguration ( appTree , projectName ) ;
86
118
config . projectType = 'library' ;
@@ -95,14 +127,12 @@ describe('cloudflare-pages-integration generator', () => {
95
127
96
128
it ( 'project does not have Qwik\'s "build-ssr" target' , async ( ) => {
97
129
const config = readProjectConfiguration ( appTree , projectName ) ;
98
- config . targets ! . build . executor = 'changed ' ;
130
+ config . targets ! . build . executor = 'nx:run-commands ' ;
99
131
updateProjectConfiguration ( appTree , projectName , config ) ;
100
132
101
133
await expect (
102
134
cloudflarePagesIntegrationGenerator ( appTree , options )
103
- ) . rejects . toThrow (
104
- 'Cannot setup cloudflare integration for the given project.'
105
- ) ;
135
+ ) . rejects . toThrow ( 'Project contains invalid configuration.' ) ;
106
136
} ) ;
107
137
} ) ;
108
138
} ) ;
0 commit comments