Skip to content

Commit

Permalink
Merge branch 'main' into e2e-improve-tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
philrz committed Jan 22, 2024
2 parents 3f3acbb + 15903ea commit 269244b
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 42 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/advance-zed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,14 @@ jobs:
# We need a token with permission to push.
token: ${{ secrets.ZQ_UPDATE_PAT }}
- uses: ./.github/actions/setup-zui
- run: sudo apt-get -y install whois
- run: yarn workspace zui add zed@brimdata/zed#${{ env.zed_ref }}
- run: yarn lint
- run: yarn test
- run: yarn build
- name: End to end tests
id: playwright
uses: GabrielBB/xvfb-action@v1
with:
options: -screen 0 1280x1024x24
run: yarn e2e:ci
- uses: actions/upload-artifact@v2
if: failure() && steps.playwright.outcome == 'failure'
with:
name: artifacts-${{ matrix.os }}
path: |
run/playwright-itest
!run/**/SS
run: /usr/bin/xvfb-run --auto-servernum -s "-screen 0 1280x1024x24" yarn e2e:ci

- run: git -c user.name='Brim Automation' -c [email protected] commit -a -m 'upgrade Zed to ${{ env.zed_ref }}'

Expand Down
63 changes: 55 additions & 8 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,77 @@ name: Run e2e tests

on:
workflow_dispatch:
inputs:
run-target:
description: Command line for running e2e tests
default: 'yarn e2e:ci'
required: true
platforms:
description: OS platforms to test on (list of strings in JSON format)"
default: '["ubuntu-20.04"]'
required: true
video:
description: Whether to record videos of Playwright test runs
type: choice
default: 'true'
options:
- 'true'
- 'false'
required: true
debug:
description: Playwright debug logging
type: choice
options:
- 'pw:api'
- ''
always-upload:
description: Always upload artifacts even if tests don't fail?
type: boolean
required: false

jobs:
run-e2e-tests:
name: Run e2e tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
os: ${{ fromJSON(inputs.platforms) }}
steps:
- name: Output inputs
run: echo "${{ toJSON(inputs) }}"
shell: sh
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-zui
- name: Install dependencies (Linux)
if: startsWith(matrix.os, 'ubuntu-')
run: sudo apt-get -y install whois
- name: Install dependencies (Windows)
if: startsWith(matrix.os, 'windows-')
run: choco install -y --no-progress whois
- run: yarn lint
- run: yarn test
- run: yarn build
- name: End to end tests
id: playwright
uses: GabrielBB/xvfb-action@v1
with:
options: -screen 0 1280x1024x24
run: yarn e2e:ci
run: |
if [ "$RUNNER_OS" = "Linux" ]; then
/usr/bin/xvfb-run --auto-servernum -s "-screen 0 1280x1024x24" ${{ inputs.run-target }}
else
${{ inputs.run-target }}
fi
env:
VIDEO: ${{ inputs.video }}
DEBUG: ${{ inputs.debug }}
shell: sh
- name: Put system logs alongside other artifacts
run: |
mkdir -p packages/zui-player/run/var_log
cp /var/log/sys*log* /var/log/kern.log* packages/zui-player/run/var_log || true
shell: sh
- uses: actions/upload-artifact@v2
if: failure() && steps.playwright.outcome == 'failure'
if: (failure() && steps.playwright.outcome == 'failure') || inputs.always-upload
with:
name: artifacts-${{ matrix.os }}
path: |
run/playwright-itest
!run/**/SS
packages/zui-player/run/**
packages/zui-player/test-results
5 changes: 0 additions & 5 deletions apps/zui/electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
"asarUnpack": ["zdeps", "LICENSE.txt", "acknowledgments.txt", "**/*.node"],
"directories": {"output": "../../dist/apps/zui"},
"protocols": [{"name": "zui", "schemes": ["zui"]}],
"mac": {
"binaries": [
"zdeps/zeek/lib/zeek/plugins/Corelight_CommunityID/lib/Corelight-CommunityID.darwin-x86_64.so"
]
},
"linux": {"target": ["deb", "rpm"]},
"rpm": {"depends": ["openssl"]},
"deb": {"depends": ["openssl"]},
Expand Down
4 changes: 2 additions & 2 deletions apps/zui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"acorn": "^7.4.1",
"ajv": "^6.9.1",
"animejs": "^3.2.0",
"brimcap": "brimdata/brimcap#v1.5.5",
"brimcap": "brimdata/brimcap#v1.6.0-beta1",
"chalk": "^4.1.0",
"chevrotain": "^10.5.0",
"chrono-node": "^2.5.0",
Expand Down Expand Up @@ -154,7 +154,7 @@
"use-resize-observer": "^8.0.0",
"web-file-polyfill": "^1.0.4",
"web-streams-polyfill": "^3.2.0",
"zed": "brimdata/zed#a5ec530443348b50f842cc59fdc6d0cd2ce0f5e6",
"zed": "brimdata/zed#c9cf7f1535cb4c907c9ec70cc6b17d62a38cb9d2",
"zui-test-data": "workspace:*"
},
"peerDependencies": {
Expand Down
18 changes: 14 additions & 4 deletions packages/zui-player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The Zui end-to-end test suite uses [Playwright](https://playwright.dev/) as the

When you are writing or debugging tests, you will usually be changing code in zui, then running the tests. To make this workflow streamlined, you will need to start the Zui dev renderer server and watch the main process code for changes.

You can do this with the commaned:
You can do this with the command:

```
nx watch-code zui
Expand All @@ -20,15 +20,15 @@ In another terminal instance, you may run your tests like so:
nx test zui-player
```

To run just one of the tests, specify the name of the file in the `tests` directory, e.g., The -g stands for 'grep' and can take a regex pattern argument.
To run just one of the tests, specify the name of the file in the `tests` directory, e.g., The `-g` stands for 'grep' and can take a regex pattern argument.

```
nx test zui-player -g pool-loads.spec.ts
```

## Running Tests in CI

When the tests run in CI, there will not be a dev server running, serving the HTML. Instead, the workflow will build the app and place static html files on the disk. Zui Player will then test agains those files.
When the tests run in CI, there will not be a dev server running, serving the HTML. Instead, the workflow will build the app and place static html files on the disk. Zui Player will then test against those files.

To simulate this locally, run the following commands:

Expand All @@ -37,6 +37,16 @@ nx build zui
NODE_ENV=production nx test zui-player
```

## Artifacts

The [user data folder](https://zui.brimdata.io/docs/support/Filesystem-Paths#user-data) at the end of each test run can be found below the `run/playwright-itest` directory.

If you also want Playwright to record each test run, set the environment variable `VIDEO=true` and the videos can be found in the `run/videos` directory.

```
VIDEO=true NODE_ENV=production nx test zui-player
```

## Writing a test

To write an e2e test, create a file called `[my-test].spec.ts` in the `tests` directory.
Expand Down Expand Up @@ -70,7 +80,7 @@ These are the four methods you need to know to get most work done.
```ts
await app.click();
await app.attached();
await app.detacted();
await app.detached();
await app.hidden();
await app.visible();
await app.locate();
Expand Down
2 changes: 1 addition & 1 deletion packages/zui-player/ci.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ const baseConfig = require('./playwright.config');
module.exports = {
...baseConfig,
/* This is the list of flaky tests to ignore when running on CI */
testIgnore: /(pool-loads|pool-groups|title-bar-buttons).spec/,
testIgnore: /(pool-loads|pool-groups|title-bar-buttons|packets).spec/,
};
10 changes: 9 additions & 1 deletion packages/zui-player/helpers/test-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export default class TestApp {
args: [`--user-data-dir=${userDataDir}`, entry],
bypassCSP: true,
timeout: 10000,
};
} as any;

if (process.env.VIDEO == 'true') {
launchOpts.recordVideo = { dir: path.join('run', 'videos') };
}

// @ts-ignore
if (bin) launchOpts.executablePath = bin;
Expand Down Expand Up @@ -220,6 +224,10 @@ export default class TestApp {
this.zui.process().stdout.on('data', (d) => console.log(d.toString()));
this.zui.process().stderr.on('data', (d) => console.log(d.toString()));
}

async takeScreenshot(filename: string) {
return await this.page.screenshot({ path: path.join('run', 'screenshots', filename), fullPage: true });
}
}

const getAppInfo = () => {
Expand Down
11 changes: 9 additions & 2 deletions packages/zui-player/tests/export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const formats = [
{ label: 'JSON', expectedSize: 13659 },
{ label: 'NDJSON', expectedSize: 13657 },
{ label: 'TSV', expectedSize: 10797 },
{ label: 'VNG', expectedSize: 8052 },
{ label: 'VNG', expectedSize: 7873 },
{ label: 'Zeek', expectedSize: 10138 },
{ label: 'ZJSON', expectedSize: 18007 },
{ label: 'ZNG', expectedSize: 3745 },
Expand All @@ -23,6 +23,11 @@ test.describe('Export tests', () => {
const app = new TestApp('Export tests');

test.beforeAll(async () => {

// Increase timeout due to observed long load times on test data in CI.
// See https://github.com/brimdata/zui/pull/2967
test.setTimeout(60000);

await app.init();
await app.createPool([getPath('sample.zeektsv')]);
await app.click('button', 'Query Pool');
Expand All @@ -40,12 +45,14 @@ test.describe('Export tests', () => {
dialog.showSaveDialog = () =>
Promise.resolve({ canceled: false, filePath });
}, file);
app.click('button', 'Export Results');
await app.click('button', 'Export Results');
await app.attached('dialog');
const dialog = app.mainWin.getByRole('dialog');
await dialog
.getByRole('radio', { name: `${label}`, exact: true })
.click();
await dialog.getByRole('button').filter({ hasText: 'Export' }).click();
await app.detached('dialog');
await app.mainWin
.getByText(new RegExp('Export Completed: .*results\\.' + label))
.waitFor();
Expand Down
16 changes: 16 additions & 0 deletions packages/zui-player/tests/packets.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { play } from 'zui-player';
import { getPath } from 'zui-test-data';
import { isCI } from '../helpers/env';

// Timeouts are increased due to observed long pcap load times in CI.
// See https://github.com/brimdata/zui/pull/2978
play('packets.spec', (app, test) => {
test('dropping a pcap does not pop up preview and load', async () => {
if (isCI()) {
test.setTimeout(120000);
app.page.setDefaultTimeout(120000);
}
await app.dropFile(getPath('sample.pcap'));
await app.attached(/Successfully loaded into sample.pcap/);
});
Expand All @@ -15,4 +22,13 @@ play('packets.spec', (app, test) => {
await app.click('button', 'Packets');
await app.attached(/Packets extracted. Opening.../);
});

test('loading a bad pcap displays an error message', async () => {
if (isCI()) {
test.setTimeout(120000);
app.page.setDefaultTimeout(120000);
}
await app.dropFile(getPath('bad.pcapng'));
await app.attached(/Unable to generate full summary logs from PCAP/);
});
});
Binary file added packages/zui-test-data/data/bad.pcapng
Binary file not shown.
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6841,12 +6841,12 @@ __metadata:
languageName: node
linkType: hard

"brimcap@brimdata/brimcap#v1.5.5":
"brimcap@brimdata/brimcap#v1.6.0-beta1":
version: 1.1.2
resolution: "brimcap@https://github.com/brimdata/brimcap.git#commit=c6873a9cac9c5735f0af438033f4a36c26292ad1"
resolution: "brimcap@https://github.com/brimdata/brimcap.git#commit=48c5cd406c9b45a2ce30426b02df6ecdceed53c6"
bin:
brimcap: build/dist/brimcap
checksum: 32eed65d0f64dd61ee16c8bfb0dd70f88f8fd77b2f69356b62ac2c9de25db179d1e03fe6f31ac95887cd7b6526166f79c4948b21d4bd761b4aaf404106a7e0af
checksum: 30c7f2721128e707eaafaf97601644528e0d9bc88ecd895379ee61b0e8ce18cde71b9981eab472a791960a37620392b2a8aa25e4143cfbb2ff8db168c63201d0
languageName: node
linkType: hard

Expand Down Expand Up @@ -19093,10 +19093,10 @@ __metadata:
languageName: node
linkType: hard

"zed@brimdata/zed#a5ec530443348b50f842cc59fdc6d0cd2ce0f5e6":
"zed@brimdata/zed#c9cf7f1535cb4c907c9ec70cc6b17d62a38cb9d2":
version: 0.33.0-dev
resolution: "zed@https://github.com/brimdata/zed.git#commit=a5ec530443348b50f842cc59fdc6d0cd2ce0f5e6"
checksum: c0f3d475678d81b01ede0c1657874ebb079579d4807b7ef1a4810d36eff49d1d046209bd4be5c4d81b33140f53e94da2f86e73d249f68ce68211f673cbf4ffe0
resolution: "zed@https://github.com/brimdata/zed.git#commit=c9cf7f1535cb4c907c9ec70cc6b17d62a38cb9d2"
checksum: fda3840577cb7e624bb958571990d7f8ad64d9f0e14d457d39d977fa08e3f497b90546ebf48fc8b6ad4284e1deed7f18fc93ebe166df132ed2c6af8cfab0376c
languageName: node
linkType: hard

Expand Down Expand Up @@ -19207,7 +19207,7 @@ __metadata:
acorn: ^7.4.1
ajv: ^6.9.1
animejs: ^3.2.0
brimcap: "brimdata/brimcap#v1.5.5"
brimcap: "brimdata/brimcap#v1.6.0-beta1"
chalk: ^4.1.0
chevrotain: ^10.5.0
chrono-node: ^2.5.0
Expand Down Expand Up @@ -19290,7 +19290,7 @@ __metadata:
use-resize-observer: ^8.0.0
web-file-polyfill: ^1.0.4
web-streams-polyfill: ^3.2.0
zed: "brimdata/zed#a5ec530443348b50f842cc59fdc6d0cd2ce0f5e6"
zed: "brimdata/zed#c9cf7f1535cb4c907c9ec70cc6b17d62a38cb9d2"
zui-test-data: "workspace:*"
peerDependencies:
react: ^18.0.0
Expand Down

0 comments on commit 269244b

Please sign in to comment.