-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E2E Smoke test #4497
Merged
Merged
E2E Smoke test #4497
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
130ed17
Setup playwright smoke tests
dac09 f19dd75
Try adding smoke test
dac09 f966b7e
No need to build fw first
dac09 a1c8378
Try playwright install
dac09 45d1bc3
Update playwright install cmd
dac09 80869b9
Remove copy from setup_test_project
dac09 244ff66
Add serve tests
dac09 a109349
Add visual check, Renable cli checks
dac09 2f4c633
Add linux snapshot
dac09 e1d75c0
Add windows snapshot | try caching playwright binaries
dac09 521290d
Move visual checks to rw serve, reduce threshold
dac09 788c6eb
Remove visual check for now
dac09 04d0e97
Merge branch 'main' into chore/smoke-test
dac09 b8692eb
Add top level script to run smoke test
dac09 55a322f
Cleanup
dac09 5eed832
Prepend subprocess outputs for tests | Build for serve if not built a…
dac09 84f1c69
Specify import type
dac09 4f4bff0
Refine test-project script
dac09 95a13e6
Merge branch 'main' of github.com:redwoodjs/redwood into chore/smoke-…
dac09 d16ff10
Sort package.json
dac09 86002ef
Merge branch 'main' into chore/smoke-test
dac09 7a2b610
Disable telemetry on setting up test project
dac09 64aef7f
Address more comments from DP
dac09 9497ba9
Merge branch 'main' into chore/smoke-test
dac09 1158df4
Fix lockfile
dac09 48189d7
Match up fs-extra versions
dac09 34f512f
Disable telemetry for building test project a different way
dac09 38f0746
Remove yarn install in test-project generator
dac09 c865f9e
Update linux snapshot using codespaces
dac09 a41f702
Remove snapshot comparison
dac09 e98f4bf
Remove unused snapshots
dac09 88fef62
Merge branch 'main' into chore/smoke-test
thedavidprice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
name: CLI Checks and Telemetry Benchmarks | ||
name: Smoke test, CLI Checks and Telemetry Benchmarks | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
cli-checks-and-telemetry-benchmarks: | ||
smoke-test: | ||
if: github.repository == 'redwoodjs/redwood' | ||
strategy: | ||
matrix: | ||
|
@@ -18,6 +18,7 @@ jobs: | |
env: | ||
REDWOOD_CI: 1 | ||
REDWOOD_VERBOSE_TELEMETRY: 1 | ||
PLAYWRIGHT_BROWSERS_PATH: 0 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
@@ -40,24 +41,32 @@ jobs: | |
restore-keys: | | ||
yarn- | ||
|
||
- name: Install dependencies and Build Framework | ||
- name: Install framework dependencies | ||
run: | | ||
yarn install --immutable | ||
yarn build:clean || echo "Project already clean" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also done as part of the test project generator |
||
yarn build:js | ||
|
||
- name: Setup test project | ||
id: setup_test_project | ||
uses: ./.github/actions/setup_test_project | ||
|
||
- name: Run `rw info` | ||
- name: Install Playwright deps | ||
run: npx playwright install --with-deps chromium | ||
|
||
- name: Run `rw build` | ||
run: | | ||
yarn rw info | ||
yarn rw build | ||
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }} | ||
|
||
- name: Run `rw build` without prerender | ||
# We run prisma reset, seed, rw dev, rw build and rw serve | ||
- name: Run smoke tests | ||
dac09 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
working-directory: ./tasks/smoke-test | ||
run: npx playwright test | ||
env: | ||
PROJECT_PATH: ${{ steps.setup_test_project.outputs.test_project_path }} | ||
dac09 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: Run `rw info` | ||
run: | | ||
yarn rw build --no-prerender | ||
thedavidprice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
yarn rw info | ||
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }} | ||
|
||
- name: Run `rw prerender` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* eslint-disable no-empty-pattern */ | ||
import { test as base } from '@playwright/test' | ||
import execa from 'execa' | ||
|
||
import { waitForServer } from '../util' | ||
|
||
// Declare worker fixtures. | ||
type DevServerFixtures = { | ||
webServerPort: number | ||
apiServerPort: number | ||
server: any | ||
} | ||
|
||
// Note that we did not provide an test-scoped fixtures, so we pass {}. | ||
const test = base.extend<any, DevServerFixtures>({ | ||
webServerPort: [ | ||
async ({}, use, workerInfo) => { | ||
// "port" fixture uses a unique value of the worker process index. | ||
await use(9000 + workerInfo.workerIndex) | ||
}, | ||
{ scope: 'worker' }, | ||
], | ||
apiServerPort: [ | ||
async ({}, use, workerInfo) => { | ||
// "port" fixture uses a unique value of the worker process index. | ||
await use(9001 + workerInfo.workerIndex) | ||
}, | ||
{ scope: 'worker' }, | ||
], | ||
|
||
// "server" fixture starts automatically for every worker - we pass "auto" for that. | ||
server: [ | ||
async ({ webServerPort, apiServerPort }, use) => { | ||
console.log('Starting dev server.....') | ||
|
||
const projectPath = process.env.PROJECT_PATH | ||
|
||
if (!projectPath) { | ||
throw new Error( | ||
'PROJECT_PATH env var not defined. Please build a test project, and re-run with PROJECT_PATH defined' | ||
) | ||
} | ||
|
||
console.log(`Launching dev server at ${projectPath}`) | ||
|
||
// Don't wait for this to finish, because it doens't | ||
const devServerHandler = execa.command( | ||
`yarn rw dev --fwd="--no-open" --no-generate`, | ||
{ | ||
cwd: projectPath, | ||
shell: true, | ||
env: { | ||
WEB_DEV_PORT: webServerPort, | ||
API_DEV_PORT: apiServerPort, | ||
}, | ||
} | ||
) | ||
|
||
// Pipe out logs so we can debug, when required | ||
devServerHandler.stdout.on('data', (data) => { | ||
console.log( | ||
'[devServer-fixture] ', | ||
Buffer.from(data, 'utf-8').toString() | ||
) | ||
}) | ||
|
||
console.log('Waiting for dev servers.....') | ||
await waitForServer(webServerPort, 1000) | ||
await waitForServer(apiServerPort, 1000) | ||
|
||
console.log('Starting tests!') | ||
await use() | ||
}, | ||
{ scope: 'worker', auto: true }, | ||
], | ||
}) | ||
|
||
export default test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* eslint-disable no-empty-pattern */ | ||
import { test as base } from '@playwright/test' | ||
import execa from 'execa' | ||
import { pathExistsSync } from 'fs-extra' | ||
import path from 'node:path' | ||
|
||
import { waitForServer } from '../util' | ||
|
||
// Declare worker fixtures. | ||
type DevServerFixtures = { | ||
port: number | ||
server: any | ||
} | ||
|
||
// Note that we did not provide an test-scoped fixtures, so we pass {}. | ||
const test = base.extend<any, DevServerFixtures>({ | ||
port: [ | ||
async ({}, use, workerInfo) => { | ||
// "port" fixture uses a unique value of the worker process index. | ||
await use(8899 + workerInfo.workerIndex) | ||
}, | ||
{ scope: 'worker' }, | ||
], | ||
|
||
// "server" fixture starts automatically for every worker - we pass "auto" for that. | ||
server: [ | ||
async ({ port }, use) => { | ||
console.log('Starting rw server.....') | ||
|
||
const projectPath = process.env.PROJECT_PATH | ||
|
||
if (!projectPath) { | ||
throw new Error( | ||
'PROJECT_PATH env var not defined. Please build a test project, and re-run with PROJECT_PATH defined' | ||
) | ||
} | ||
|
||
console.log(`Running rw serve at ${projectPath}`) | ||
|
||
if (projectNeedsBuilding(projectPath)) { | ||
// skip rw build if its already done | ||
execa.sync(`yarn rw build`, { | ||
cwd: projectPath, | ||
shell: true, | ||
}) | ||
} | ||
|
||
// Don't wait for this to finish, because it doens't | ||
const rwServeHandler = execa.command(`yarn rw serve -p ${port}`, { | ||
cwd: projectPath, | ||
shell: true, | ||
}) | ||
jtoar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Pipe out logs so we can debug, when required | ||
rwServeHandler.stdout.on('data', (data) => { | ||
console.log( | ||
'[rw-serve-fixture] ', | ||
Buffer.from(data, 'utf-8').toString() | ||
) | ||
}) | ||
|
||
console.log('Waiting for server.....') | ||
await waitForServer(port, 1000) | ||
|
||
console.log('Starting tests!') | ||
await use() | ||
}, | ||
{ scope: 'worker', auto: true }, | ||
], | ||
}) | ||
|
||
const projectNeedsBuilding = ( | ||
projectPath: string = process.env.PROJECT_PATH | ||
) => { | ||
const webDist = path.join(projectPath, 'web/dist') | ||
const apiDist = path.join(projectPath, 'api/dist') | ||
return !(pathExistsSync(webDist) && pathExistsSync(apiDist)) | ||
} | ||
|
||
export default test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { PlaywrightTestConfig } from '@playwright/test' | ||
|
||
// See https://playwright.dev/docs/test-configuration#global-configuration | ||
const config: PlaywrightTestConfig = { | ||
timeout: 60_000, | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expect } from '@playwright/test' | ||
|
||
export const smokeTest = async ({ page, webServerPort }) => { | ||
// Go to http://localhost:8910/ | ||
await page.goto(`http://localhost:${webServerPort}/`) | ||
|
||
// Check that the blog posts are being loaded | ||
await page.textContent('text=Welcome to the blog!') | ||
await page.textContent('text=What is the meaning of life?') | ||
await page.textContent('text=A little more about me') | ||
|
||
// Click text=About | ||
await page.click('text=About') | ||
|
||
expect(page.url()).toBe(`http://localhost:${webServerPort}/about`) | ||
|
||
await page.textContent( | ||
'text=This site was created to demonstrate my mastery of Redwood: Look on my works, ye' | ||
) | ||
// Click text=Contact | ||
await page.click('text=Contact') | ||
expect(page.url()).toBe(`http://localhost:${webServerPort}/contact`) | ||
|
||
// Click text=Admin | ||
await page.click('text=Admin') | ||
expect(page.url()).toBe(`http://localhost:${webServerPort}/posts`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import devServerTest from '../playwright-fixtures/devServer.fixture' | ||
|
||
import { smokeTest } from './common' | ||
|
||
devServerTest('Smoke test with dev server', smokeTest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import rwServeTest from '../playwright-fixtures/rwServe.fixture' | ||
|
||
import { smokeTest } from './common' | ||
|
||
rwServeTest('Smoke test with rw serve', ({ port, page }) => | ||
smokeTest({ webServerPort: port, page }) | ||
) | ||
|
||
// @TODO it might be useful to have this visual check | ||
// But gitpod screenshot doesnt seem to match up with github runners | ||
// Possibly due to fonts | ||
// rwServeTest('Visual check', async ({ page, port }) => { | ||
// await page.goto(`http://localhost:${port}/`) | ||
|
||
// // Wait till cell has finished rendering | ||
// await page.textContent('text=Welcome to the blog!') | ||
|
||
// expect(await page.screenshot()).toMatchSnapshot('landing.png', { | ||
// threshold: 0.2, // reduce sensitivity of visual comparison | ||
// }) | ||
// }) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import isPortReachable from 'is-port-reachable' | ||
|
||
export function waitForServer(port, interval) { | ||
return new Promise((resolve) => { | ||
setInterval(async () => { | ||
const isServerUp = await isPortReachable(port, { host: 'localhost' }) | ||
isServerUp && resolve(true) | ||
}, interval) | ||
}) | ||
jtoar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now taken care of by
yarn build:test-project