Skip to content

Commit 4f7dec6

Browse files
committed
feat(esm): Add ESM test project to CI (#379)
1 parent 223868b commit 4f7dec6

File tree

4 files changed

+213
-0
lines changed

4 files changed

+213
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Set up test project
2+
description: Sets up the test project fixture in CI for smoke tests and CLI checks
3+
4+
runs:
5+
using: node20
6+
main: 'setUpTestProjectEsm.mjs'
7+
8+
inputs:
9+
canary:
10+
description: Upgrade the project to canary?
11+
default: 'false'
12+
13+
outputs:
14+
test-project-path:
15+
description: Path to the test project
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* eslint-env node */
2+
// @ts-check
3+
4+
import path from 'node:path'
5+
6+
import core from '@actions/core'
7+
8+
import fs from 'fs-extra'
9+
10+
import {
11+
createExecWithEnvInCwd,
12+
execInFramework,
13+
REDWOOD_FRAMEWORK_PATH,
14+
} from '../actionsLib.mjs'
15+
16+
const TEST_PROJECT_PATH = path.join(
17+
path.dirname(process.cwd()),
18+
'esm-test-project',
19+
)
20+
21+
core.setOutput('test-project-path', TEST_PROJECT_PATH)
22+
23+
const canary = core.getInput('canary') === 'true'
24+
console.log({
25+
canary,
26+
})
27+
28+
console.log()
29+
30+
/**
31+
* @returns {Promise<void>}
32+
*/
33+
async function main() {
34+
await setUpTestProject({
35+
canary: true,
36+
})
37+
}
38+
39+
/**
40+
* @param {{canary: boolean}} options
41+
* @returns {Promise<void>}
42+
*/
43+
async function setUpTestProject({ canary }) {
44+
const TEST_PROJECT_FIXTURE_PATH = path.join(
45+
REDWOOD_FRAMEWORK_PATH,
46+
'__fixtures__',
47+
'esm-test-project',
48+
)
49+
50+
console.log(`Creating project at ${TEST_PROJECT_PATH}`)
51+
console.log()
52+
await fs.copy(TEST_PROJECT_FIXTURE_PATH, TEST_PROJECT_PATH)
53+
54+
await execInFramework('yarn project:tarsync --verbose', {
55+
env: { RWJS_CWD: TEST_PROJECT_PATH },
56+
})
57+
58+
if (canary) {
59+
console.log(`Upgrading project to canary`)
60+
await execInProject('yarn rw upgrade -t canary', {
61+
input: Buffer.from('Y'),
62+
})
63+
console.log()
64+
}
65+
66+
await sharedTasks()
67+
}
68+
69+
const execInProject = createExecWithEnvInCwd(TEST_PROJECT_PATH)
70+
71+
/**
72+
* @returns {Promise<void>}
73+
*/
74+
async function sharedTasks() {
75+
console.log('Generating dbAuth secret')
76+
const { stdout } = await execInProject('yarn rw g secret --raw', {
77+
silent: true,
78+
})
79+
fs.appendFileSync(
80+
path.join(TEST_PROJECT_PATH, '.env'),
81+
`SESSION_SECRET='${stdout}'`,
82+
)
83+
console.log()
84+
85+
console.log('Running prisma migrate reset')
86+
await execInProject('yarn rw prisma migrate reset --force')
87+
}
88+
89+
main()

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ jobs:
117117
with:
118118
os: ${{ matrix.os }}
119119

120+
smoke-tests-esm:
121+
needs: check
122+
123+
strategy:
124+
matrix:
125+
os: [ubuntu-latest, windows-latest]
126+
127+
name: 🔄 Smoke tests ESM / ${{ matrix.os }} / node 20 latest
128+
uses: ./.github/workflows/smoke-tests-test-esm.yml
129+
with:
130+
os: ${{ matrix.os }}
131+
120132
cli-smoke-tests:
121133
needs: check
122134

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: 🔄 Smoke Tests Test
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
os:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
smoke-tests:
12+
runs-on: ${{ inputs.os }}
13+
14+
env:
15+
REDWOOD_CI: 1
16+
REDWOOD_VERBOSE_TELEMETRY: 1
17+
18+
steps:
19+
- name: Checkout the framework code
20+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
21+
22+
- name: Set up job
23+
uses: ./.github/actions/set-up-job
24+
25+
- name: 🌲 Set up test project
26+
id: set-up-test-project
27+
uses: ./.github/actions/set-up-test-project-esm
28+
env:
29+
REDWOOD_DISABLE_TELEMETRY: 1
30+
YARN_ENABLE_IMMUTABLE_INSTALLS: false
31+
32+
- name: 🎭 Install playwright dependencies
33+
run: npx playwright install --with-deps chromium
34+
35+
- name: 🧑‍💻 Run dev smoke tests
36+
working-directory: ./tasks/smoke-tests/dev
37+
run: npx playwright test
38+
env:
39+
REDWOOD_TEST_PROJECT_PATH: '${{ steps.set-up-test-project.outputs.test-project-path }}'
40+
REDWOOD_DISABLE_TELEMETRY: 1
41+
42+
- name: 🔐 Run auth smoke tests
43+
working-directory: ./tasks/smoke-tests/auth
44+
run: npx playwright test
45+
env:
46+
REDWOOD_TEST_PROJECT_PATH: ${{ steps.set-up-test-project.outputs.test-project-path }}
47+
REDWOOD_DISABLE_TELEMETRY: 1
48+
49+
- name: Run `rw build --no-prerender`
50+
run: |
51+
yarn rw build --no-prerender
52+
working-directory: ${{ steps.set-up-test-project.outputs.test-project-path }}
53+
54+
- name: Run `rw prerender`
55+
run: |
56+
yarn rw prerender --verbose
57+
working-directory: ${{ steps.set-up-test-project.outputs.test-project-path }}
58+
59+
- name: Run `rw test web`
60+
run: |
61+
yarn rw test web --no-watch
62+
working-directory: ${{ steps.set-up-test-project.outputs.test-project-path }}
63+
64+
- name: Run `rw test api`
65+
run: |
66+
yarn rw test api --no-watch
67+
working-directory: ${{ steps.set-up-test-project.outputs.test-project-path }}
68+
69+
- name: Run db import tracking tests
70+
shell: bash
71+
run: |
72+
# Only run this for ESM projects where the vitest config file exists
73+
if test -f ./vitest-sort.config.ts; then
74+
npx vitest --config ./vitest-sort.config.ts run
75+
fi
76+
working-directory: ${{ steps.set-up-test-project.outputs.test-project-path }}/api
77+
78+
- name: 🖥️ Run serve smoke tests
79+
working-directory: tasks/smoke-tests/serve
80+
run: npx playwright test
81+
env:
82+
REDWOOD_TEST_PROJECT_PATH: ${{ steps.set-up-test-project.outputs.test-project-path }}
83+
REDWOOD_DISABLE_TELEMETRY: 1
84+
85+
- name: 📄 Run prerender smoke tests
86+
working-directory: tasks/smoke-tests/prerender
87+
run: npx playwright test
88+
env:
89+
REDWOOD_TEST_PROJECT_PATH: ${{ steps.set-up-test-project.outputs.test-project-path }}
90+
REDWOOD_DISABLE_TELEMETRY: 1
91+
92+
- name: 📕 Run Storybook smoke tests
93+
working-directory: tasks/smoke-tests/storybook
94+
run: npx playwright test
95+
env:
96+
REDWOOD_TEST_PROJECT_PATH: ${{ steps.set-up-test-project.outputs.test-project-path }}
97+
REDWOOD_DISABLE_TELEMETRY: 1

0 commit comments

Comments
 (0)