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

Run E2E tests on CI #18

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: E2E tests

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21.7"
- uses: oven-sh/setup-bun@v2
- run: go mod tidy
- run: cd reporters/golang && go mod tidy && cd ../..
- run: cd reporters/javascript && bun install && bun run build && cd ../..
- run: cd frontend && bun install && cd ../..
- run: cd e2e-tests && bun install && bunx playwright install --with-deps chromium && cd ../..
- run: cd e2e-tests && bun run test && cd ../..
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: e2e-tests/playwright-report/
retention-days: 3
28 changes: 0 additions & 28 deletions .github/workflows/go.yml

This file was deleted.

31 changes: 0 additions & 31 deletions .github/workflows/node.js.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ In `e2e-tests` directory:

```bash
bun install # install dependencies
bunx playwright install
bunx playwright install --with-deps chromium
bun run test # run tests
```

Expand Down
14 changes: 7 additions & 7 deletions e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig, devices } from '@playwright/test';
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
Expand All @@ -10,31 +10,31 @@ import { defineConfig, devices } from '@playwright/test';
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
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,
retries: process.env.CI ? 0 : 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',
reporter: "html",
/* 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:3000',

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

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

// {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test("send 100 events from JS server", async ({ page }) => {

const COUNT = 100;

await exec(`node count.js ${TEST_NAME} ${COUNT}`, {
await exec(`bun count.js ${TEST_NAME} ${COUNT}`, {
env: { ...process.env, TT_TOKEN: TOKEN, TT_SERVER_URL: `ws://localhost:${serverPort}` },
cwd: path.join(__dirname, "reporter"),
});
Expand Down
10 changes: 8 additions & 2 deletions e2e-tests/tests/javascript-server/javascript-server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import { runServer } from "../utils";
import { runServer, sleep } from "../utils";
import child_process from "child_process";
import util from "util";
import path from "path";
Expand All @@ -20,11 +20,17 @@ test("send hello from JS server", async ({ page }) => {
await page.getByPlaceholder("Enter session ID").fill(TOKEN);
await page.getByRole("button", { name: "Go" }).click();

await exec(`node hello.js ${TEST_NAME}`, {
const result = await exec(`bun hello.js ${TEST_NAME}`, {
env: { ...process.env, TT_TOKEN: TOKEN, TT_SERVER_URL: `ws://localhost:${serverPort}` },
cwd: path.join(__dirname, "reporter"),
});

if (process.env["DEBUG"]) {
console.log("Reporter output: ");
console.log(result.stdout);
console.error(result.stderr);
}

await expect(page.getByText(`hello ${TEST_NAME}`)).toBeVisible();
});

Expand Down
12 changes: 10 additions & 2 deletions e2e-tests/tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import { Readable } from "stream";
import { PassThrough, Readable } from "stream";
import freeports from "find-free-ports";
import { ChildProcess, exec } from "child_process";

Expand Down Expand Up @@ -36,9 +36,17 @@ export async function runServer(startPort: number): Promise<[ChildProcess, numbe
env: { ...process.env, PORT: serverPort.toString(), LOCAL: "true", DISABLE_METRICS: "true" },
cwd: rootDir,
});

const out = new PassThrough();
serverProcess.stdout?.pipe(out);
serverProcess.stdout?.pipe(process.stdout);
serverProcess.stderr?.pipe(process.stderr);

await waitForString("Listening", serverProcess.stdout!);
await waitForString("Listening", out);

if (process.env["DEBUG"]) {
console.log(`Server started on port ${serverPort}`);
}

return [serverProcess, serverPort];
}
Expand Down
14 changes: 14 additions & 0 deletions reporters/javascript/src/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
let cachedNodeCrypto: Crypto | undefined;

const loadCrypto = async () => {
if (globalThis?.crypto) return globalThis.crypto;
try {
return (cachedNodeCrypto ||= (await import("node:crypto")).webcrypto as Crypto);
} catch (error) {
throw new Error("Failed to load crypto");
}
};

/**
* Encrypts plaintext using AES-GCM with supplied password, for decryption with aes_gcm_decrypt()
*
Expand All @@ -6,6 +17,7 @@
* @returns {Promise<string>} encrypted cipher text
*/
export async function encrypt(plaintext: string, password: string): Promise<string> {
const crypto = await loadCrypto();
// encode password as UTF-8
const pwUtf8 = new TextEncoder().encode(password);
// hash the password
Expand Down Expand Up @@ -68,6 +80,8 @@ export async function decrypt(ciphertext: string, password: string): Promise<str
}

export async function sha256(message: string): Promise<string> {
const crypto = await loadCrypto();

// encode as UTF-8
const msgBuffer = new TextEncoder().encode(message);

Expand Down
Loading