Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
- name: Build, lint, and test
run: |
sudo chown -R testbot .
sudo -u testbot bash -lc 'make build lint test'
sudo -u testbot bash -lc 'make build lint test test-e2e'
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,20 @@ clean-docs:
.PHONY: build-docs
build-docs: clean-docs build-buf
npm run doc

# e2e tests

.PHONY: install-playwright
install-playwright:
cd e2e && npm install
cd e2e && npx playwright install --with-deps chrome

e2e/bin/viam-server:
bash e2e/setup.sh

.PHONY: run-e2e-server
run-e2e-server: e2e/bin/viam-server
e2e/bin/viam-server --config=./e2e/server_config.json

test-e2e: e2e/bin/viam-server build install-playwright
cd e2e && npm run e2e:playwright
2 changes: 2 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
artifacts
bin/viam-server
17 changes: 17 additions & 0 deletions e2e/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>E2E Harness</title>
</head>
<body>
<script
type="module"
src="/src/main.ts"
></script>
</body>
</html>
18 changes: 18 additions & 0 deletions e2e/server_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"network": {
"fqdn": "e2e-ts-sdk",
"bind_address": ":9090"
},
"components": [
{
"name": "base1",
"type": "base",
"model": "fake"
},
{
"name": "servo1",
"type": "servo",
"model": "fake"
}
]
}
25 changes: 25 additions & 0 deletions e2e/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

set -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
BIN_DIR=$SCRIPT_DIR/bin
BIN_NAME=viam-server
BIN_PATH=$BIN_DIR/$BIN_NAME

mkdir -p $BIN_DIR

if [ "$(uname)" == "Linux" ]; then
if [ "$(uname -m)" == "aarch64" ]; then
curl https://storage.googleapis.com/packages.viam.com/apps/viam-server/viam-server-stable-aarch64.AppImage -o $BIN_PATH
elif [ "$(uname -m)" == "x86_64" ]; then
curl https://storage.googleapis.com/packages.viam.com/apps/viam-server/viam-server-stable-x86_64.AppImage -o $BIN_PATH
else
echo -e "Cannot run E2E tests on $(uname -m)"
exit 1
fi
chmod +x $BIN_PATH
elif [ "$(uname)" == "Darwin" ]; then
brew tap viamrobotics/brews && brew install viam-server
ln -s $(which viam-server) $BIN_PATH
fi
42 changes: 42 additions & 0 deletions e2e/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createRobotClient } from '../../src/main';

const main = async () => {
const machine = await createRobotClient({
host: 'e2e-ts-sdk',
signalingAddress: 'http://localhost:9090',
iceServers: [{ urls: 'stun:global.stun.twilio.com:3478' }],
});
const resourceNames = await machine.resourceNames();

const resNamesDiv = document.createElement('div');
resNamesDiv.dataset.testid = 'resource-names';
for (const resourceName of resourceNames) {
const resNameDiv = document.createElement('div');
resNameDiv.textContent = resourceName.name;
resNameDiv.dataset.testid = 'resource-name';
resNamesDiv.append(resNameDiv);
}
document.body.append(resNamesDiv);

const stream = machine.streamStatus(resourceNames);
const statusesDiv = document.createElement('div');
statusesDiv.dataset.testid = 'statuses';

let i = 0;
for await (const statuses of stream) {
for await (const status of statuses) {
const statusDiv = document.createElement('div');
statusDiv.textContent = status.toJsonString();
statusDiv.dataset.testid = 'status';
statusesDiv.append(statusDiv);
}

i += 1;
if (i >= 3) {
break;
}
}
document.body.append(statusesDiv);
};

main().catch(console.error); // eslint-disable-line no-console
18 changes: 18 additions & 0 deletions e2e/tests/connect-and-status.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect, test } from '@playwright/test';

test('check resource names and multiple statuses', async ({ page }) => {
await page.goto('/');

// see server_config.json for configuration
const resourceNames = page
.getByTestId('resource-names')
.getByTestId('resource-name');
await expect(resourceNames).toHaveCount(4);
await expect(resourceNames.getByText('base1')).toHaveCount(1);
await expect(resourceNames.getByText('servo1')).toHaveCount(1);
await expect(resourceNames.getByText('builtin')).toHaveCount(2);

// 3 status iterations * 4 resource names (see main.ts for loop)
const statuses = page.getByTestId('statuses').getByTestId('status');
await expect(statuses).toHaveCount(12);
});
12 changes: 12 additions & 0 deletions e2e/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';

import pkg from '../package.json';

// https://vitejs.dev/config/
export default defineConfig({
define: {
'process.env.NODE_ENV': '"production"',
__VERSION__: JSON.stringify(pkg.version),
},
});
64 changes: 64 additions & 0 deletions package-lock.json

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

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"typecheck": "concurrently -g npm:typecheck:*",
"typecheck:src": "tsc",
"typecheck:node": "tsc --project tsconfig.node.json",
"e2e:playwright": "playwright test",
"e2e:playwright-ui": "playwright test --ui",
"e2e:playwright-debug": "playwright test --debug",
"e2e:playwright-install": "playwright install",
"e2e:test-harness": "vite e2e",
"_eslint": "eslint '.*.cjs' '**/*.{ts,js,cjs}'",
"_prettier": "prettier '.*.cjs' '**/*.{ts,js,cjs}'"
},
Expand All @@ -53,6 +58,7 @@
},
"devDependencies": {
"@bufbuild/buf": "^1.15.0-1",
"@playwright/test": "1.45.3",
"@types/node": "^20.11.10",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
Expand Down
31 changes: 31 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
testDir: 'e2e/tests',
outputDir: 'e2e/artifacts',
forbidOnly: Boolean(process.env.CI),
retries: process.env.CI ? 1 : 0,
workers: process.env.CI ? 1 : 3,
reporter: [['html', { open: 'never' }]],
use: {
baseURL: 'http://localhost:5173',
trace: process.env.CI ? 'on-first-retry' : 'retain-on-failure',
},

projects: [
// only using chrome because firefox won't allow localhost CORS
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'make run-e2e-server & npm run e2e:test-harness',
reuseExistingServer: false,
url: `http://localhost:5173`,
stdout: 'ignore',
stderr: 'pipe',
},
});
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"declaration": true,
"emitDeclarationOnly": true
},
"exclude": ["**/*.test.ts"]
"exclude": ["**/*.test.ts", "e2e/**/*.ts"]
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"compilerOptions": {
"types": ["vite/client", "node"],
"noEmit": true,
"rootDir": "src",
"rootDirs": ["src", "e2e"],
"outDir": "dist",

// TODO(mc, 2023-04-06): remove overrides to default to error, fix issues
"exactOptionalPropertyTypes": false,
},
"include": ["src/**/*.ts"],
"include": ["src/**/*.ts", "e2e/**/*.ts"],
}
4 changes: 2 additions & 2 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"noEmit": true
},
"include": ["./vite.config.ts", "./*.cjs", "./.*.cjs"],
"exclude": ["**/src/**", "**/examples/**", "**/scripts/**"]
"include": ["./vite.config.ts", "./playwright.config.ts", "./*.cjs", "./.*.cjs"],
"exclude": ["**/src/**", "**/e2e/**", "**/examples/**", "**/scripts/**"]
}
1 change: 1 addition & 0 deletions typedoc.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
customCss: './docs/docs.css',
cname: 'ts.viam.dev',
disableSources: true,
exclude: ['e2e/**/*.spec.ts'],
// see: https://typedoc.org/options/organization/#kindsortorder
kindSortOrder: [
'Function',
Expand Down
8 changes: 8 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@ export default defineConfig({
},
test: {
mockReset: true,
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/cypress/**',
'**/.{idea,git,cache,output,temp}/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/e2e/**',
],
},
});