Skip to content

Commit 992033b

Browse files
saihajardatan
andauthored
Add Cloudflare Modules E2E test (#1440) (#1802)
* Add Cloudflare Modules E2E test * Try * Try new flag * aaa Co-authored-by: Arda TANRIKULU <[email protected]>
1 parent 96cc3bc commit 992033b

File tree

6 files changed

+108
-81
lines changed

6 files changed

+108
-81
lines changed

.github/workflows/deployment-e2e.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
plan: ['cf-worker', 'azure-function', 'aws-lambda', 'vercel-function']
12+
plan:
13+
[
14+
'cf-worker',
15+
'cf-modules',
16+
'azure-function',
17+
'aws-lambda',
18+
'vercel-function',
19+
]
1320
name: e2e / ${{ matrix.plan }}
21+
1422
runs-on: ubuntu-latest
1523
if: github.event.pull_request.head.repo.full_name == github.repository
1624
steps:

e2e/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { LocalWorkspace } from '@pulumi/pulumi/automation'
22
import { awsLambdaDeployment } from './tests/aws-lambda'
33
import { azureFunctionDeployment } from './tests/azure-function'
44
import { cloudFlareDeployment } from './tests/cf-worker'
5+
import { cfModulesDeployment } from './tests/cf-modules'
56
import { dockerDeployment } from './tests/docker'
67
import { DeploymentConfiguration } from './types'
78
import { env, getCommitId } from './utils'
89
import { vercelDeployment } from './tests/vercel'
910

1011
const AVAILABLE_TEST_PLANS = {
1112
'cf-worker': cloudFlareDeployment,
13+
'cf-modules': cfModulesDeployment,
1214
'azure-function': azureFunctionDeployment,
1315
'aws-lambda': awsLambdaDeployment,
1416
'vercel-function': vercelDeployment,

e2e/tests/cf-modules.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createCFDeployment } from './create-cf-deployment'
2+
3+
export const cfModulesDeployment = createCFDeployment(
4+
'cloudflare-modules',
5+
true,
6+
)

e2e/tests/cf-worker.ts

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,3 @@
1-
import { Stack } from '@pulumi/pulumi/automation'
2-
import { DeploymentConfiguration } from '../types'
3-
import * as cf from '@pulumi/cloudflare'
4-
import {
5-
assertGraphiQL,
6-
assertQuery,
7-
env,
8-
execPromise,
9-
fsPromises,
10-
waitForEndpoint,
11-
} from '../utils'
12-
import * as pulumi from '@pulumi/pulumi'
13-
import { version } from '@pulumi/cloudflare/package.json'
1+
import { createCFDeployment } from './create-cf-deployment'
142

15-
export const cloudFlareDeployment: DeploymentConfiguration<{
16-
workerUrl: string
17-
}> = {
18-
prerequisites: async (stack: Stack) => {
19-
console.info('\t\tℹ️ Installing Pulumi CF plugin...')
20-
// Intall Pulumi CF Plugin
21-
await stack.workspace.installPlugin('cloudflare', version, 'resource')
22-
23-
// Build and bundle the worker
24-
console.info('\t\tℹ️ Bundling the CF Worker....')
25-
await execPromise('yarn build', {
26-
cwd: '../examples/service-worker',
27-
})
28-
},
29-
config: async (stack: Stack) => {
30-
// Configure the Pulumi environment with the CloudFlare credentials
31-
// This will allow Pulummi program to just run without caring about secrets/configs.
32-
// See: https://www.pulumi.com/registry/packages/cloudflare/installation-configuration/
33-
await stack.setConfig('cloudflare:apiToken', {
34-
value: env('CLOUDFLARE_API_TOKEN'),
35-
})
36-
await stack.setConfig('cloudflare:accountId', {
37-
value: env('CLOUDFLARE_ACCOUNT_ID'),
38-
})
39-
},
40-
program: async () => {
41-
const stackName = pulumi.getStack()
42-
const workerUrl = `e2e.graphql-yoga.com/${stackName}`
43-
44-
// Deploy CF script as Worker
45-
const workerScript = new cf.WorkerScript('worker', {
46-
content: await fsPromises.readFile(
47-
'../examples/service-worker/dist/index.js',
48-
'utf-8',
49-
),
50-
secretTextBindings: [
51-
{
52-
name: 'GRAPHQL_ROUTE',
53-
text: `/${stackName}`,
54-
},
55-
{
56-
name: 'DEBUG',
57-
text: 'true',
58-
},
59-
],
60-
name: stackName,
61-
})
62-
63-
// Create a nice route for easy testing
64-
new cf.WorkerRoute('worker-route', {
65-
scriptName: workerScript.name,
66-
pattern: workerUrl,
67-
zoneId: env('CLOUDFLARE_ZONE_ID'),
68-
})
69-
70-
return {
71-
workerUrl: `https://${workerUrl}`,
72-
}
73-
},
74-
test: async ({ workerUrl }) => {
75-
console.log(`ℹ️ CloudFlare Worker deployed to URL: ${workerUrl.value}`)
76-
await waitForEndpoint(workerUrl.value, 5, 10000)
77-
await assertGraphiQL(workerUrl.value)
78-
await assertQuery(workerUrl.value)
79-
},
80-
}
3+
export const cloudFlareDeployment = createCFDeployment('service-worker')

e2e/tests/create-cf-deployment.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { Stack } from '@pulumi/pulumi/automation'
2+
import { DeploymentConfiguration } from '../types'
3+
import * as cf from '@pulumi/cloudflare'
4+
import {
5+
assertGraphiQL,
6+
assertQuery,
7+
env,
8+
execPromise,
9+
fsPromises,
10+
waitForEndpoint,
11+
} from '../utils'
12+
import * as pulumi from '@pulumi/pulumi'
13+
import { version } from '@pulumi/cloudflare/package.json'
14+
15+
export function createCFDeployment(
16+
projectName: string,
17+
isModule = false,
18+
): DeploymentConfiguration<{
19+
workerUrl: string
20+
}> {
21+
return {
22+
prerequisites: async (stack: Stack) => {
23+
console.info('\t\tℹ️ Installing Pulumi CF plugin...')
24+
// Intall Pulumi CF Plugin
25+
await stack.workspace.installPlugin('cloudflare', version, 'resource')
26+
27+
// Build and bundle the worker
28+
console.info('\t\tℹ️ Bundling the CF Worker....')
29+
await execPromise('yarn build', {
30+
cwd: '../examples/' + projectName,
31+
})
32+
},
33+
config: async (stack: Stack) => {
34+
// Configure the Pulumi environment with the CloudFlare credentials
35+
// This will allow Pulummi program to just run without caring about secrets/configs.
36+
// See: https://www.pulumi.com/registry/packages/cloudflare/installation-configuration/
37+
await stack.setConfig('cloudflare:apiToken', {
38+
value: env('CLOUDFLARE_API_TOKEN'),
39+
})
40+
await stack.setConfig('cloudflare:accountId', {
41+
value: env('CLOUDFLARE_ACCOUNT_ID'),
42+
})
43+
},
44+
program: async () => {
45+
const stackName = pulumi.getStack()
46+
const workerUrl = `e2e.graphql-yoga.com/${stackName}`
47+
48+
// Deploy CF script as Worker
49+
const workerScript = new cf.WorkerScript('worker', {
50+
content: await fsPromises.readFile(
51+
`../examples/${projectName}/dist/index.js`,
52+
'utf-8',
53+
),
54+
module: isModule,
55+
secretTextBindings: [
56+
{
57+
name: 'GRAPHQL_ROUTE',
58+
text: `/${stackName}`,
59+
},
60+
{
61+
name: 'DEBUG',
62+
text: 'true',
63+
},
64+
],
65+
name: stackName,
66+
})
67+
68+
// Create a nice route for easy testing
69+
new cf.WorkerRoute('worker-route', {
70+
scriptName: workerScript.name,
71+
pattern: workerUrl,
72+
zoneId: env('CLOUDFLARE_ZONE_ID'),
73+
})
74+
75+
return {
76+
workerUrl: `https://${workerUrl}`,
77+
}
78+
},
79+
test: async ({ workerUrl }) => {
80+
console.log(`ℹ️ CloudFlare Worker deployed to URL: ${workerUrl.value}`)
81+
await waitForEndpoint(workerUrl.value, 5, 10000)
82+
await assertGraphiQL(workerUrl.value)
83+
await assertQuery(workerUrl.value)
84+
},
85+
}
86+
}

examples/cloudflare-modules/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// src/index.mjs
22
import { createYoga, createSchema } from 'graphql-yoga'
33

4-
export default createYoga({
4+
const { fetch } = createYoga({
55
graphqlEndpoint: '/graphql',
66
landingPage: false,
77
schema: createSchema({
@@ -18,3 +18,5 @@ export default createYoga({
1818
},
1919
}),
2020
})
21+
22+
export default { fetch }

0 commit comments

Comments
 (0)