Skip to content

Commit

Permalink
Playwright E2E smoke test (#64)
Browse files Browse the repository at this point in the history
we're running the playwright tests against the production docker image
in earthly.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
fdietze and mergify[bot] authored May 28, 2024
1 parent ded897c commit d7d73e4
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
uses: actions/checkout@v4

- name: Test
run: earthly +ci-test
run: earthly --allow-privileged --no-output +ci-test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ node_modules/
.env
.DS_Store
GlobalBrain.jl/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
29 changes: 28 additions & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,39 @@ docker-image:
ENV INTERNAL_PORT="8080"
ENV PORT="8081"

RUN nix-collect-garbage
RUN du -sh /* \
&& find /app -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 du -sh | sort -hr | head -20 \
&& find /nix/store -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 du -sh | sort -hr | head -20 \
&& find /app/node_modules -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 du -sh | sort -hr | head -20

# starting the application is defined in litefs.yml
# test locally without litefs:
# docker run -e SESSION_SECRET -e INTERNAL_COMMAND_TOKEN -e HONEYPOT_SECRET sha256:xyzxyz /bin/sh startup.sh
CMD ["/bin/sh", "-c", "/usr/local/bin/litefs mount"]
SAVE IMAGE jabble:latest

docker-image-e2e-test:
# set up an image with dind (docker in docker) and nix
FROM earthly/dind:alpine-3.19-docker-25.0.5-r0
RUN apk add curl \
&& curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install linux \
--extra-conf "sandbox = false" \
--init none \
--no-confirm
ENV PATH="${PATH}:/nix/var/nix/profiles/default/bin"
WORKDIR /app
COPY flake.nix flake.lock .
RUN nix develop ".#e2e" --command echo warmed up
COPY --dir e2e playwright.config.ts ./
COPY docker-compose.yml ./
WITH DOCKER --load jabble:latest=+docker-image
RUN docker image ls \
&& (docker-compose up &) \
&& echo waiting for http server to come online... \
&& timeout 60s sh -c 'until curl --silent --fail http://localhost:8081 > /dev/null; do sleep 1; done' \
&& CI=true nix develop --impure ".#e2e" --command playwright test
END

app-deploy:
# run locally:
Expand Down Expand Up @@ -145,7 +172,7 @@ app-lint:
ci-test:
BUILD +app-typecheck
BUILD +app-lint
BUILD +docker-image
BUILD +docker-image-e2e-test

ci-deploy:
# To run manually:
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
jabble:
image: jabble:latest
container_name: jabble
ports:
- "8081:8081"
environment:
- SESSION_SECRET=super-duper-s3cret
- HONEYPOT_SECRET=super-duper-s3cret
- INTERNAL_COMMAND_TOKEN=some-made-up-token
command: /bin/sh startup.sh
init: true # make ctrl+c work
restart: no
7 changes: 7 additions & 0 deletions e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test, expect } from '@playwright/test'

test('has title', async ({ page }) => {
await page.goto('http://localhost:8081')

await expect(page).toHaveTitle(/Jabble/)
})
18 changes: 18 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@
python3 # for node-gyp
gcc # for node-gyp

playwright-driver.browsers # e2e tests
playwright-test # e2e tests

earthly
docker
docker-compose
flyctl

# darwin.apple_sdk.frameworks.Security
];
shellHook = ''
export PLAYWRIGHT_BROWSERS_PATH="${pkgs.playwright-driver.browsers}"
export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
'';
};
build = pkgs.mkShellNoCC {
buildInputs = with pkgs; [
Expand All @@ -44,6 +52,16 @@
gcc # for node-gyp
];
};
e2e = pkgs.mkShellNoCC {
buildInputs = with pkgs; [
playwright-driver.browsers # e2e tests
playwright-test # e2e tests
];
shellHook = ''
export PLAYWRIGHT_BROWSERS_PATH="${pkgs.playwright-driver.browsers}"
export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
'';
};
production = pkgs.mkShellNoCC {
buildInputs = with pkgs; [
nodejs_20
Expand Down
78 changes: 57 additions & 21 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,77 @@
import { defineConfig, devices } from '@playwright/test'
import 'dotenv/config'

const PORT = process.env.PORT || '3000'
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests/e2e',
timeout: 15 * 1000,
expect: {
timeout: 5 * 1000,
},
testDir: './e2e',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: `http://localhost:${PORT}/`,
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
},
use: { ...devices['Desktop Chrome'] },
},

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },
//
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

webServer: {
command: process.env.CI ? 'npm run start:mocks' : 'npm run dev',
port: Number(PORT),
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
stderr: 'pipe',
env: {
PORT,
},
},
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
})

0 comments on commit d7d73e4

Please sign in to comment.