Skip to content

Commit

Permalink
chore: Add configuration for Playwright tests (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni authored Sep 14, 2024
1 parent 9e029eb commit 10227d0
Show file tree
Hide file tree
Showing 17 changed files with 413 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# shellcheck shell=bash
if ! has nix_direnv_version || ! nix_direnv_version 3.0.5; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.5/direnvrc" "sha256-RuwIS+QKFj/T9M2TFXScjBsLR6V3A17YVoEW/Q6AZ1w="
fi
use flake
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,43 @@ jobs:
- name: Test
run: pnpm run test

test-e2e:
name: E2E test
runs-on: ubuntu-latest
timeout-minutes: 25
needs: build
env:
NODE_VERSION: 22
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ env.NODE_VERSION }}-turbo-
- name: Setup PNPM
uses: pnpm/action-setup@v2

- name: Setup node@${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Install Playwright browsers
run: pnpm dlx playwright@latest install --with-deps

- name: Test
run: pnpm test:e2e

duplicated-packages:
name: Check for duplicated dependencies
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ node_modules/
/turbo/cache-key.json
.pnpm-store
.parcel-cache
.direnv

# dotenv environment variable files
.env
Expand All @@ -56,3 +57,10 @@ dist/
build/
.inox-tools/
*.js.map

# Test results
test-results/
test-results/
playwright-report/
blob-report/
playwright/.cache/
15 changes: 13 additions & 2 deletions docs/turbo.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
{
"$schema": "https://turbo.build/schema.json",
"extends": ["//"],
"extends": [
"//"
],
"tasks": {
"build": {
"inputs": ["*", "src/**", "public/**", "../packages/*/package.json"]
"inputs": [
"*",
"src/**",
"public/**",
"../packages/*/package.json"
],
"outputs": [
".vercel",
".astro"
]
}
}
}
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
description = "A collection of oxygen-free tools for astronauts.";
inputs = {
nixpkgs.url = "github:Fryuni/nixpkgs/master";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = {
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
throwSystem = throw "Unsupported system: ${system}";
pkgs = nixpkgs.legacyPackages.${system};

browsersInfo = builtins.fromJSON (builtins.readFile "${pkgs.playwright-driver}/browsers.json");
in {
devShells.default = pkgs.mkShell {
packages = [
pkgs.nodejs_20
pkgs.corepack_20
pkgs.playwright
];

PLAYWRIGHT_NODEJS_PATH = "${pkgs.nodejs_20}/bin/node";
PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true;
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = 1;
PLAYWRIGHT_BROWSERS_PATH = "${pkgs.playwright-driver.browsers}";

PLAYWRIGHT_CHROME_BIN = let
chromeInfo = pkgs.lib.lists.findFirst (b: b.name == "chromium") (throw "value not found") browsersInfo.browsers;
chromePath =
{
x86_64-linux = "chrome-linux/chrome";
aarch64-linux = "chrome-linux/chrome";
x86_64-darwin = "chrome-mac/Chromium.app/Contents/MacOS/Chromium";
arm64-darwin = "chrome-mac/Chromium.app/Contents/MacOS/Chromium";
}
.${system}
or throwSystem;
in "${pkgs.playwright-driver.browsers}/chromium-${chromeInfo.revision}/${chromePath}";

PLAYWRIGHT_FIREFOX_BIN = let
firefoxInfo = pkgs.lib.lists.findFirst (b: b.name == "firefox") (throw "value not found") browsersInfo.browsers;
firefoxPath =
{
x86_64-linux = "firefox-linux/firefox";
aarch64-linux = "firefox-linux/firefox";
x86_64-darwin = "firefox/Nightly.app/Contents/MacOS/firefox";
arm64-darwin = "firefox/Nightly.app/Contents/MacOS/firefox";
}
.${system}
or throwSystem;
in "${pkgs.playwright-driver.browsers}/firefox-${firefoxInfo.revision}/${firefoxPath}";
};

formatter = pkgs.alejandra;
}
);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"postinstall": "node ./turbo/cache-key.mjs",
"release": "pnpm run build && changeset publish",
"test": "turbo run --concurrency=1 --filter '@inox-tools/*' test",
"test:e2e": "turbo run --concurrency=1 --filter '@inox-tools/*' test:e2e",
"version": "changeset version && pnpm install && pnpm format"
},
"lint-staged": {
Expand Down
29 changes: 29 additions & 0 deletions packages/request-state/e2e/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { setTimeout } from 'node:timers/promises';
import { loadFixture, type PreviewServer } from '@inox-tools/astro-tests/astroFixture';
import { test, expect } from '@playwright/test';

const fixture = await loadFixture({
root: './fixture/basic',
});

let server: PreviewServer;

test.beforeAll(async () => {
await fixture.build({});
server = await fixture.preview({});
});

test.afterAll(async () => {
await server?.stop();
await server?.closed();
});

test('share state ', async ({ page }) => {
const pageUrl = fixture.resolveUrl('/?name=John+Doe');

await page.goto(pageUrl);

await setTimeout(15000);

await expect(page.locator('span#name')).toHaveText('John Doe');
});
9 changes: 9 additions & 0 deletions packages/request-state/e2e/fixture/basic/astro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
import requestState from '@inox-tools/request-state';

export default defineConfig({
output: 'server',
adapter: node({ mode: 'standalone' }),
integrations: [requestState()],
});
10 changes: 10 additions & 0 deletions packages/request-state/e2e/fixture/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@request-state/basic",
"private": true,
"type": "module",
"dependencies": {
"@astrojs/node": "catalog:",
"@inox-tools/request-state": "workspace:",
"astro": "catalog:"
}
}
20 changes: 20 additions & 0 deletions packages/request-state/e2e/fixture/basic/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
import { setState } from '@it-astro:state';
const name = Astro.url.searchParams.get('name');
setState('name', name ?? 'World');
---

<html>
<head>
<title>Basic example</title>
</head>
<body>
<h1>Hello, <span id="name"></span>!</h1>
</body>
<script>
import { getState } from '@it-astro:state';

document.getElementById('name')!.textContent = getState('name') as string;
</script>
</html>
9 changes: 9 additions & 0 deletions packages/request-state/e2e/fixture/basic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../../../../../tsconfig.base.json",
"compilerOptions": {
"lib": [
"dom"
]
}
}
4 changes: 4 additions & 0 deletions packages/request-state/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"dev": "tsup --watch",
"prepublish": "pnpm run build",
"test": "echo 'No tests for now :('",
"test:e2e": "playwright test",
"test:e2e:report": "playwright show-report",
"test:dev": "vitest --coverage.enabled=true",
"test:run": "vitest run --coverage"
},
Expand All @@ -36,6 +38,8 @@
"devalue": "catalog:"
},
"devDependencies": {
"@inox-tools/astro-tests": "workspace:",
"@playwright/test": "catalog:",
"@types/content-type": "catalog:",
"@types/node": "catalog:",
"@vitest/coverage-v8": "catalog:",
Expand Down
Loading

0 comments on commit 10227d0

Please sign in to comment.