Skip to content

Commit f561cb1

Browse files
committed
support swappable cypress test environments
1 parent 6aec1b0 commit f561cb1

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

packages/viewer/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ The developer panel (at `/dev`) has some utilities that may be helpful for contr
2929
Other helpful development commands
3030

3131
```bash
32-
$ npm run test:watch # run tests on change
33-
$ npm run test:cov # run tests with coverage report
34-
$ npm run cy:open # starts cypress
32+
$ npm run test:watch # run tests on change
33+
$ npm run test:cov # run tests with coverage report
34+
$ npm run cy:open # start cypress against the local dev server
35+
$ npm run cy:open:prev # … preview for the current branch (or env.BRANCH, if set)
36+
$ npm run cy:open:prod # … or production
3537
```
3638

3739
## Deployment

packages/viewer/cypress.config.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
import { defineConfig } from 'cypress'
2+
import { execSync } from 'child_process'
3+
4+
function getCurrentBranch() {
5+
try {
6+
return execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
7+
} catch (error) {
8+
throw new Error(`Could not determine current git branch: ${error}`)
9+
}
10+
}
11+
12+
function baseUrl({ CYPRESS_ENV = 'local' } = process.env) {
13+
switch (CYPRESS_ENV) {
14+
case 'local':
15+
return 'http://localhost:5173'
16+
case 'production':
17+
return 'https://topology.pi-base.org'
18+
case 'preview':
19+
const branch = process.env.BRANCH || getCurrentBranch()
20+
const domain = branch.toLowerCase().replaceAll('/', '-').slice(0, 28)
21+
return `https://${domain}.topology.pages.dev`
22+
default:
23+
throw new Error(`Invalid environment: ${CYPRESS_ENV}`)
24+
}
25+
}
226

327
export default defineConfig({
428
projectId: 'bkb3p8',
529
chromeWebSecurity: false,
630
e2e: {
7-
baseUrl: 'http://localhost:5173',
31+
baseUrl: baseUrl(),
832
experimentalRunAllSpecs: true,
933
specPattern: 'cypress/e2e/**/*.{ts,tsx}',
1034
supportFile: false,

packages/viewer/cypress/e2e/loading.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ describe('Loading', () => {
88

99
cy.title().should(
1010
'eq',
11-
'T2: Countably compact ⇒ Weakly Countably Compact | π-Base',
11+
'T2: Countably compact ⇒ Weakly countably compact | π-Base',
1212
)
13-
cy.contains('Countably compact ⇒ Weakly Countably Compact')
13+
cy.contains('Countably compact ⇒ Weakly countably compact')
1414
})
1515
})
1616

packages/viewer/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
"scripts": {
88
"build": "vite build --logLevel warn",
99
"cy:open": "cypress open",
10+
"cy:open:prev": "CYPRESS_ENV=preview cypress open",
11+
"cy:open:prod": "CYPRESS_ENV=production cypress open",
1012
"cy:run": "cypress run",
13+
"cy:run:prev": "CYPRESS_ENV=preview cypress run $@",
14+
"cy:run:prod": "CYPRESS_ENV=production cypress run $@",
1115
"dev": "vite",
1216
"preview": "vite preview",
1317
"test": "vitest run",
@@ -44,7 +48,7 @@
4448
"@types/katex": "^0.16.7",
4549
"@types/page": "^1.11.9",
4650
"@types/unist": "^2.0.10",
47-
"cypress": "^13.6.2",
51+
"cypress": "^14.3.2",
4852
"svelte": "^4.2.8",
4953
"svelte-check": "^3.6.3",
5054
"svelte-preprocess": "^5.1.3",

0 commit comments

Comments
 (0)