Skip to content

Commit 974b460

Browse files
committed
Add simple e2e test
1 parent 5c58da6 commit 974b460

19 files changed

+329
-71
lines changed

.github/workflows/publish.yml

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
11
name: NPM Publish
22

3-
on:
4-
release:
5-
types: [published]
6-
secrets:
7-
NPM_TOKEN:
8-
required: true
3+
# on:
4+
# release:
5+
# types: [published]
6+
# secrets:
7+
# NPM_TOKEN:
8+
# required: true
99

10-
jobs:
11-
publish:
12-
if: github.repository_owner == 'viamrobotics'
13-
runs-on: ubuntu-latest
14-
container:
15-
image: ghcr.io/viamrobotics/canon:amd64
10+
# jobs:
11+
# publish:
12+
# if: github.repository_owner == 'viamrobotics'
13+
# runs-on: ubuntu-latest
14+
# container:
15+
# image: ghcr.io/viamrobotics/canon:amd64
1616

17-
steps:
18-
- name: Check if organization member
19-
id: is_organization_member
20-
if: github.event_name == 'workflow_dispatch'
21-
uses: jamessingleton/[email protected]
22-
with:
23-
organization: viamrobotics
24-
username: ${{ github.actor }}
25-
token: ${{ secrets.GITHUB_TOKEN }}
17+
# steps:
18+
# - name: Check if organization member
19+
# id: is_organization_member
20+
# if: github.event_name == 'workflow_dispatch'
21+
# uses: jamessingleton/[email protected]
22+
# with:
23+
# organization: viamrobotics
24+
# username: ${{ github.actor }}
25+
# token: ${{ secrets.GITHUB_TOKEN }}
2626

27-
- name: Cancelling - not an organization member
28-
uses: andymckay/[email protected]
29-
if: |
30-
github.event_name == 'workflow_dispatch' && steps.is_organization_member.outputs.result == 'false'
27+
# - name: Cancelling - not an organization member
28+
# uses: andymckay/[email protected]
29+
# if: |
30+
# github.event_name == 'workflow_dispatch' && steps.is_organization_member.outputs.result == 'false'
3131

32-
- name: Download Release
33-
uses: dsaltares/fetch-gh-release-asset@master
34-
with:
35-
file: "viamrobotics\\-sdk\\-.*\\.tgz"
36-
regex: true
37-
target: './'
38-
version: tags/${{ github.event.release.tag_name }}
32+
# - name: Download Release
33+
# uses: dsaltares/fetch-gh-release-asset@master
34+
# with:
35+
# file: "viamrobotics\\-sdk\\-.*\\.tgz"
36+
# regex: true
37+
# target: './'
38+
# version: tags/${{ github.event.release.tag_name }}
3939

40-
- name: Check Files
41-
id: release_file
42-
run: echo "path=$(ls -1 | head -1)" >> $GITHUB_OUTPUT
40+
# - name: Check Files
41+
# id: release_file
42+
# run: echo "path=$(ls -1 | head -1)" >> $GITHUB_OUTPUT
4343

44-
- name: Which Tag
45-
id: which_tag
46-
shell: bash
47-
run: |
48-
if ${{ contains(github.event.release.tag_name, 'rc') }} ; then
49-
echo "tag=rc" >> $GITHUB_OUTPUT
50-
else
51-
echo "tag=latest" >> $GITHUB_OUTPUT
52-
fi
44+
# - name: Which Tag
45+
# id: which_tag
46+
# shell: bash
47+
# run: |
48+
# if ${{ contains(github.event.release.tag_name, 'rc') }} ; then
49+
# echo "tag=rc" >> $GITHUB_OUTPUT
50+
# else
51+
# echo "tag=latest" >> $GITHUB_OUTPUT
52+
# fi
5353

54-
- name: Publish
55-
id: publish
56-
uses: JS-DevTools/npm-publish@v2
57-
with:
58-
token: ${{ secrets.NPM_TOKEN }}
59-
tag: ${{ steps.which_tag.outputs.tag }}
60-
package: ${{ steps.release_file.outputs.path }}
54+
# - name: Publish
55+
# id: publish
56+
# uses: JS-DevTools/npm-publish@v2
57+
# with:
58+
# token: ${{ secrets.NPM_TOKEN }}
59+
# tag: ${{ steps.which_tag.outputs.tag }}
60+
# package: ${{ steps.release_file.outputs.path }}
6161

62-
- name: Notify Slack
63-
uses: slackapi/[email protected]
64-
if: ${{ steps.publish.outputs.tag == 'latest' }}
65-
with:
66-
payload: |
67-
{
68-
"text": "${{ github.event.release.tag_name }} was released.\n${{ github.event.release.html_url }}"
69-
}
70-
env:
71-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
62+
# - name: Notify Slack
63+
# uses: slackapi/[email protected]
64+
# if: ${{ steps.publish.outputs.tag == 'latest' }}
65+
# with:
66+
# payload: |
67+
# {
68+
# "text": "${{ github.event.release.tag_name }} was released.\n${{ github.event.release.html_url }}"
69+
# }
70+
# env:
71+
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77
build_lint_test:
8-
if: github.repository_owner == 'viamrobotics'
8+
# if: github.repository_owner == 'viamrobotics'
99
runs-on: ubuntu-latest
1010
container:
1111
image: ghcr.io/viamrobotics/canon:amd64
@@ -16,4 +16,4 @@ jobs:
1616
- name: Build, lint, and test
1717
run: |
1818
sudo chown -R testbot .
19-
sudo -u testbot bash -lc 'make build lint test'
19+
sudo -u testbot bash -lc 'make build lint test test-e2e'

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ dist
106106
# Generated protobufs
107107
src/gen/
108108

109-
# project bin
110-
bin/
111-
112109
# typedoc documentation
113110
docs/dist
114111

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,20 @@ clean-docs:
8989
.PHONY: build-docs
9090
build-docs: clean-docs build-buf
9191
npm run doc
92+
93+
# e2e tests
94+
95+
.PHONY: install-playwright
96+
install-playwright:
97+
cd e2e && npm install
98+
cd e2e && npx playwright install --with-deps chrome
99+
100+
e2e/bin/viam-server:
101+
bash e2e/setup.sh
102+
103+
.PHONY: run-e2e-server
104+
run-e2e-server: e2e/bin/viam-server
105+
e2e/bin/viam-server --config=./e2e/server_config.json
106+
107+
test-e2e: e2e/bin/viam-server build install-playwright
108+
cd e2e && npm run e2e:playwright

e2e/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
artifacts
2+
bin/viam-server

e2e/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1.0"
8+
/>
9+
<title>E2E Harness</title>
10+
</head>
11+
<body>
12+
<script
13+
type="module"
14+
src="/src/main.ts"
15+
></script>
16+
</body>
17+
</html>

e2e/server_config.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"network": {
3+
"fqdn": "e2e-ts-sdk",
4+
"bind_address": ":9090"
5+
},
6+
"components": [
7+
{
8+
"name": "base1",
9+
"type": "base",
10+
"model": "fake"
11+
},
12+
{
13+
"name": "servo1",
14+
"type": "servo",
15+
"model": "fake"
16+
}
17+
]
18+
}

e2e/setup.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
6+
BIN_DIR=$SCRIPT_DIR/bin
7+
BIN_NAME=viam-server
8+
BIN_PATH=$BIN_DIR/$BIN_NAME
9+
10+
mkdir -p $BIN_DIR
11+
12+
if [ "$(uname)" == "Linux" ]; then
13+
if [ "$(uname -m)" == "aarch64" ]; then
14+
curl https://storage.googleapis.com/packages.viam.com/apps/viam-server/viam-server-stable-aarch64.AppImage -o $BIN_PATH
15+
elif [ "$(uname -m)" == "x86_64" ]; then
16+
curl https://storage.googleapis.com/packages.viam.com/apps/viam-server/viam-server-stable-x86_64.AppImage -o $BIN_PATH
17+
else
18+
echo -e "Cannot run E2E tests on $(uname -m)"
19+
exit 1
20+
fi
21+
chmod +x $BIN_PATH
22+
elif [ "$(uname)" == "Darwin" ]; then
23+
brew tap viamrobotics/brews && brew install viam-server
24+
ln -s $(which viam-server) $BIN_PATH
25+
fi

e2e/src/main.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { createRobotClient } from '../../src/main';
2+
3+
const main = async () => {
4+
const machine = await createRobotClient({
5+
host: 'e2e-ts-sdk',
6+
signalingAddress: 'http://localhost:9090',
7+
iceServers: [{ urls: 'stun:global.stun.twilio.com:3478' }],
8+
});
9+
const resourceNames = await machine.resourceNames();
10+
11+
const resNamesDiv = document.createElement('div');
12+
resNamesDiv.dataset.testid = 'resource-names';
13+
for (const resourceName of resourceNames) {
14+
const resNameDiv = document.createElement('div');
15+
resNameDiv.textContent = resourceName.name;
16+
resNameDiv.dataset.testid = 'resource-name';
17+
resNamesDiv.append(resNameDiv);
18+
}
19+
document.body.append(resNamesDiv);
20+
21+
const stream = machine.streamStatus(resourceNames);
22+
const statusesDiv = document.createElement('div');
23+
statusesDiv.dataset.testid = 'statuses';
24+
25+
let i = 0;
26+
for await (const statuses of stream) {
27+
for await (const status of statuses) {
28+
const statusDiv = document.createElement('div');
29+
statusDiv.textContent = status.toJsonString();
30+
statusDiv.dataset.testid = 'status';
31+
statusesDiv.append(statusDiv);
32+
}
33+
34+
i += 1;
35+
if (i >= 3) {
36+
break;
37+
}
38+
}
39+
document.body.append(statusesDiv);
40+
};
41+
42+
main().catch(console.error); // eslint-disable-line no-console
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test('check resource names and multiple statuses', async ({ page }) => {
4+
await page.goto('/');
5+
6+
// see server_config.json for configuration
7+
const resourceNames = page
8+
.getByTestId('resource-names')
9+
.getByTestId('resource-name');
10+
await expect(resourceNames).toHaveCount(4);
11+
await expect(resourceNames.getByText('base1')).toHaveCount(1);
12+
await expect(resourceNames.getByText('servo1')).toHaveCount(1);
13+
await expect(resourceNames.getByText('builtin')).toHaveCount(2);
14+
15+
// 3 status iterations * 4 resource names (see main.ts for loop)
16+
const statuses = page.getByTestId('statuses').getByTestId('status');
17+
await expect(statuses).toHaveCount(12);
18+
});

0 commit comments

Comments
 (0)