Skip to content

Commit 302d501

Browse files
Jake ChampionJakeChampion
authored andcommitted
chore: allow multiple PRs to run the end-to-end tests at the same time
This commit updates the test script to include the branch name in each of the end-to-end test applications -- this allows multiple branches to run the end-to-end tests at the same time. I've also updated the script to not tear-down the service if the tests have failed, this will enable us to debug the deployed application. When the tests pass, the tear-down will happen.
1 parent 032277b commit 302d501

File tree

3 files changed

+114
-16
lines changed

3 files changed

+114
-16
lines changed

integration-tests/js-compute/package-lock.json

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/js-compute/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"prettier": "^2.8.7"
88
},
99
"dependencies": {
10+
"@actions/core": "^1.10.0",
11+
"@iarna/toml": "^2.2.5",
1012
"undici": "^5.21.0",
1113
"zx": "^7.2.0"
1214
},

integration-tests/js-compute/test.js

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { retry, expBackoff } from 'zx/experimental'
88
import { compareDownstreamResponse } from "./compare-downstream-response.js";
99
import { argv, exit } from "node:process";
1010
import { existsSync } from "node:fs";
11-
import { copyFile, readdir, readFile } from "node:fs/promises";
11+
import { copyFile, readdir, readFile, writeFile } from "node:fs/promises";
12+
import core from '@actions/core';
13+
import TOML from '@iarna/toml'
1214

1315
const startTime = Date.now();
1416
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -73,38 +75,53 @@ if (process.env.FASTLY_API_TOKEN === undefined) {
7375
}
7476
const FASTLY_API_TOKEN = process.env.FASTLY_API_TOKEN;
7577
zx.verbose = true;
78+
const branchName = (await $`git branch --show-current`).stdout.trim().replace(/[^a-zA-Z0-9_-]/g, '_')
7679

7780
for (const fixture of testFixtures) {
81+
const serviceName = `${fixture}--${branchName}`
82+
let domain;
7883
await within(async () => {
7984
const fixturePath = join(__dirname, 'fixtures', fixture)
8085
try {
8186
const startTime = Date.now();
8287
await cd(fixturePath);
8388
await copyFile(join(fixturePath, 'fastly.toml.in'), join(fixturePath, 'fastly.toml'))
89+
const config = TOML.parse(await readFile(join(fixturePath, 'fastly.toml'), 'utf-8'))
90+
config.name = serviceName;
91+
await writeFile(join(fixturePath, 'fastly.toml'), TOML.stringify(config), 'utf-8')
92+
core.startGroup('Delete service if already exists')
8493
try {
85-
await zx`fastly service delete --quiet --force --service-name ${fixture} --token $FASTLY_API_TOKEN`
94+
await zx`fastly service delete --quiet --service-name "${serviceName}" --force --token $FASTLY_API_TOKEN`
8695
} catch {}
87-
// build and deploy application to compute@edge
96+
core.endGroup()
97+
core.startGroup('Build and deploy service')
8898
await zx`npm i`
8999
await zx`fastly compute publish -i --quiet --token $FASTLY_API_TOKEN`
90-
100+
core.endGroup()
101+
91102
// get the public domain of the deployed application
92-
const domain = JSON.parse(await $`fastly domain list --quiet --version latest --json`)[0].Name
93-
103+
domain = JSON.parse(await $`fastly domain list --quiet --version latest --json`)[0].Name
104+
core.notice(`Service is running on https://${domain}`)
105+
94106
const setupPath = join(fixturePath, 'setup.js')
95107
if (existsSync(setupPath)) {
108+
core.startGroup('Extra set-up steps for the service')
96109
await $`${setupPath}`
110+
core.endGroup()
97111
}
98-
112+
113+
core.startGroup('Check service is up and running')
99114
await retry(10, expBackoff('60s', '30s'), async () => {
100115
const response = await request(`https://${domain}`)
101116
if (response.statusCode !== 200) {
102117
throw new Error(`Application "${fixture}" :: Not yet available on domain: ${domain}`)
103118
}
104119
})
105-
120+
core.endGroup()
121+
106122
const { default: tests } = await import(join(fixturePath, 'tests.json'), { assert: { type: 'json' } });
107-
123+
124+
core.startGroup('Running tests')
108125
let counter = 0;
109126
await Promise.all(Object.entries(tests).map(async ([title, test]) => {
110127
if (test.environments.includes("c@e")) {
@@ -122,19 +139,26 @@ for (const fixture of testFixtures) {
122139
})
123140
}
124141
}))
142+
core.endGroup()
125143
console.log(`Application "${fixture}" :: All ${counter} tests passed! Took ${(Date.now() - startTime) / 1000} seconds to complete`)
126-
} catch (error) {
127-
console.error(`Application "${fixture}" :: ${error.message}`)
128-
process.exitCode = 1;
129-
} finally {
130144
const teardownPath = join(fixturePath, 'teardown.js')
131145
if (existsSync(teardownPath)) {
146+
core.startGroup('Tear down the extra set-up for the service')
132147
await $`${teardownPath}`
148+
core.endGroup()
133149
}
134-
135-
150+
151+
core.startGroup('Delete service')
136152
// Delete the service now the tests have finished
137-
await zx`fastly service delete --quiet --force --service-name ${fixture} --token $FASTLY_API_TOKEN`
153+
await zx`fastly service delete --quiet --service-name "${serviceName}" --force --token $FASTLY_API_TOKEN`
154+
core.endGroup()
155+
} catch (error) {
156+
console.error(`Application "${fixture}" :: ${error.message}`)
157+
core.notice(`Tests failed, the service is named "${serviceName}"`)
158+
if (domain) {
159+
core.notice(`You can debug the service on https://${domain}`)
160+
}
161+
process.exitCode = 1;
138162
}
139163

140164
})

0 commit comments

Comments
 (0)