Skip to content
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 playwright test #54

Merged
merged 42 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f36fbca
nix version tests
divinenaman Aug 24, 2023
33204f7
flake checks
divinenaman Aug 24, 2023
f62e9df
Merge remote-tracking branch 'upstream/main' into test-thirtyfour
divinenaman Aug 24, 2023
437f543
merge
divinenaman Aug 24, 2023
97b35f8
Merge remote-tracking branch 'o/main' into test-thirtyfour
srid Aug 25, 2023
47f3874
handle tls error in tests
srid Aug 25, 2023
17ae376
test ignore
divinenaman Aug 25, 2023
15b2ff6
Merge remote-tracking branch 'upstream/main' into test-thirtyfour
divinenaman Aug 25, 2023
d8d716e
fmt
divinenaman Aug 25, 2023
af871a1
e2e nix module
divinenaman Aug 30, 2023
b11393b
working e2e nix module
divinenaman Aug 30, 2023
27600e0
fix flake formatting
Aug 31, 2023
d92eb90
wip: playwright flake module
divinenaman Aug 31, 2023
a3a1b8e
Merge branch 'test-thirtyfour' of github.com:divinenaman/nix-browser …
divinenaman Aug 31, 2023
9bd4b34
wip: playwright flake fix
divinenaman Aug 31, 2023
2741fa7
add playwright test
divinenaman Sep 1, 2023
234e6bd
Merge remote-tracking branch 'upstream/main' into test-thirtyfour
divinenaman Sep 2, 2023
4b3a30d
fixes
divinenaman Sep 3, 2023
9cfc8d5
add playwright test
Sep 4, 2023
d751512
fmt
Sep 4, 2023
ffce24b
review changes
Sep 5, 2023
2786d17
Merge remote-tracking branch 'upstream/main' into e2e-playwright
Sep 6, 2023
074a4bc
remove imports
Sep 7, 2023
d54c2f8
readme
Sep 7, 2023
ecebd62
vscode: add playwright extension
srid Sep 8, 2023
c8e6407
revert lock changes
Sep 8, 2023
44f5a30
Add github actions CI to run e2e tests
srid Sep 11, 2023
7986fcc
add playwright browser path
Sep 11, 2023
0a679ab
make vscode integration work
srid Sep 11, 2023
4dc81b9
avoid unnecessary rebuilds
srid Sep 11, 2023
efd89ef
.ts
srid Sep 11, 2023
905acf4
reindent
srid Sep 11, 2023
76bc79c
devDependencies is fine
srid Sep 11, 2023
a936003
simplify node_module management
srid Sep 11, 2023
6c6d13e
fix
srid Sep 11, 2023
6d42924
rename
srid Sep 11, 2023
fd754c7
not needed
srid Sep 11, 2023
eefb7aa
redundant
srid Sep 11, 2023
3c5650a
readme
srid Sep 11, 2023
4d5fc70
lock file is not needed
srid Sep 11, 2023
a452d36
No need for package.json either
srid Sep 11, 2023
f2aae2c
Merge remote-tracking branch 'origin/main' into e2e-playwright
srid Sep 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
use flake
nix_direnv_watch_file */*.nix
17 changes: 17 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "CI"
on:
# Run only when pushing to master branch, and making PRs
push:
branches:
- master
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: E2E tests
run: nix run .#e2e-playwright-test
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"rust-lang.rust-analyzer",
"mkhl.direnv",
"jnoortheen.nix-ide",
"bradlc.vscode-tailwindcss"
"bradlc.vscode-tailwindcss",
"ms-playwright.playwright"
]
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ nix run
## Contributing

- When you are done with your changes, run `just fmt` to **autoformat** the source tree; the CI checks for this.
- Add tests if relevant. Run `just test` to run the **tests**.
- Add tests if relevant, and run them:
- Run `just test` to run the **unit tests**.
- Run `just e2e` (requires `just watch` to be running) or `just e2e-release` to run the **end-to-end tests**
- Add documentation wherever useful. To preview the **docs**, run `just doc`.

## Frontend tech
Expand Down
4 changes: 4 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
/test-results/
/playwright-report/
/playwright/.cache/
6 changes: 6 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Playwright end-to-end tests

We use [Playwright](https://playwright.dev/dotnet/) to test our application.

- All e2e test are nixified, simply run `nix run .#e2e-playwright-test` from project root
- A `package.json` exists for better IDE support (autocompletion, hover docs etc)
52 changes: 52 additions & 0 deletions e2e/flake-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ lib, ... }:
{
perSystem = { config, self', pkgs, system, ... }: {
# e2e test service using playwright
process-compose.e2e-playwright-test =
let
TEST_PORT = "5000";
in
{
tui = false;
settings.processes = {
start-app = {
command = "${lib.getExe self'.packages.default} --site-addr=127.0.0.1:${TEST_PORT} --no-open";
readiness_probe = {
exec.command = "${lib.getExe pkgs.curl} --fail 127.0.0.1:${TEST_PORT}";
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
};
};
test = {
environment = {
inherit TEST_PORT;
};
command = pkgs.writeShellApplication {
name = "e2e-playwright";
runtimeInputs = with pkgs; [ nodejs playwright-test ];
text = ''
cd e2e
playwright test --project chromium
'';
};
depends_on."start-app".condition = "process_healthy";
availability.exit_on_end = true;
};
};
};

devShells.e2e-playwright = pkgs.mkShell {
buildInputs = with pkgs; [
nodejs
playwright-test
];
shellHook = ''
export NODE_PATH=${pkgs.playwright-test}/lib/node_modules
# VSCode disrespects NODE_PATH https://github.com/microsoft/TypeScript/issues/8760
# So we must manually create ./node_modules
just node_modules NODE_PATH=$NODE_PATH
'';
};
};
}
68 changes: 68 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { defineConfig, devices } from '@playwright/test';

/**
* 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',
/* 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: 'line',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: `http://127.0.0.1:${process.env.TEST_PORT}`,

/* 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'] },
}

/* 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' },
// },
],

/* 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,
// },
});

7 changes: 7 additions & 0 deletions e2e/tests/nix-version.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test, expect } from "@playwright/test";

test('check nix version', async ({ page }) => {
await page.goto('/info');
const nixVersion = await page.locator(":text('Nix Version') + div").textContent();
await expect(nixVersion).toBeTruthy();
});
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
inputs.process-compose-flake.flakeModule
inputs.cargo-doc-live.flakeModule
(inputs.leptos-fullstack + /nix/flake-module.nix)
./e2e/flake-module.nix
];
perSystem = { config, self', pkgs, lib, system, ... }: {
_module.args.pkgs = import inputs.nixpkgs {
Expand Down Expand Up @@ -97,6 +98,7 @@
inputsFrom = [
config.treefmt.build.devShell
self'.devShells.nix-browser
self'.devShells.e2e-playwright
];
packages = with pkgs; [
just
Expand Down
13 changes: 13 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,23 @@ test:
cargo test
cargo leptos test

# Run end-to-end tests against release server
e2e-release:
nix run .#e2e-playwright-test

# Run end-to-end tests against `just watch` server
e2e:
cd e2e && TEST_PORT=3000 playwright test --project chromium

# Run docs server (live reloading)
doc:
cargo-doc-live

# Run CI locally
ci:
nixci

# Setup node_modules using Nix (invoked automatically by nix-shell)
node_modules NODE_PATH:
rm -f ./e2e/node_modules
ln -sf ${NODE_PATH} ./e2e/node_modules