Skip to content

Commit 3783227

Browse files
authored
Create Playwright test harness (#7)
* updated host.json and added test harness * updated github action for test * added installation of saw and azure function core tools to github action
1 parent de9b67e commit 3783227

File tree

9 files changed

+239
-2
lines changed

9 files changed

+239
-2
lines changed

.github/workflows/playwright.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Playwright Tests
2+
3+
# Controls when the workflow will run
4+
on:
5+
# Triggers the workflow on push or pull request and nightly
6+
push:
7+
pull_request:
8+
schedule:
9+
# nightly
10+
- cron: '0 0 * * *'
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
16+
jobs:
17+
playwright_tests:
18+
# Runs on an ubuntu runner
19+
runs-on: ubuntu-latest
20+
21+
strategy:
22+
matrix:
23+
node-version: [14.x, 16.x, 18.x]
24+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
25+
26+
steps:
27+
- uses: actions/checkout@v3
28+
- uses: actions/setup-node@v3
29+
- name: Install dependencies
30+
run: npm ci
31+
- name: Install SWA and Azure Function tool
32+
run: npm install -g @azure/static-web-apps-cli azure-functions-core-tools
33+
- name: Install Playwright
34+
run: npx playwright install --with-deps
35+
- name: Run playwright tests
36+
run: npm run playwright_test

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/playwright/.cache/

api/host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"version": "2.0",
33
"extensionBundle": {
44
"id": "Microsoft.Azure.Functions.ExtensionBundle",
5-
"version": "[1.*, 2.0.0)"
5+
"version": "2.*"
66
}
77
}

api/package-lock.json

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "vanilla-api",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "swa start src --api-location api",
8+
"playwright_test": "playwright test"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/HannahZhuSWE/vanilla-api.git"
13+
},
14+
"keywords": [],
15+
"author": "",
16+
"license": "ISC",
17+
"bugs": {
18+
"url": "https://github.com/HannahZhuSWE/vanilla-api/issues"
19+
},
20+
"homepage": "https://github.com/HannahZhuSWE/vanilla-api#readme",
21+
"devDependencies": {
22+
"@playwright/test": "^1.23.2"
23+
}
24+
}

playwright.config.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import type { PlaywrightTestConfig } from '@playwright/test';
2+
import { devices } from '@playwright/test';
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// require('dotenv').config();
9+
10+
/**
11+
* See https://playwright.dev/docs/test-configuration.
12+
*/
13+
const config: PlaywrightTestConfig = {
14+
testDir: './tests',
15+
/* Maximum time one test can run for. */
16+
timeout: 30 * 1000,
17+
expect: {
18+
/**
19+
* Maximum time expect() should wait for the condition to be met.
20+
* For example in `await expect(locator).toHaveText();`
21+
*/
22+
timeout: 5000
23+
},
24+
/* Run tests in files in parallel */
25+
fullyParallel: true,
26+
/* Fail the build on CI if you accidentally left test.only in the source code. */
27+
forbidOnly: !!process.env.CI,
28+
/* Retry on CI only */
29+
retries: process.env.CI ? 2 : 0,
30+
/* Opt out of parallel tests on CI. */
31+
workers: process.env.CI ? 1 : undefined,
32+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
33+
reporter: 'html',
34+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
35+
use: {
36+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
37+
actionTimeout: 0,
38+
/* Base URL to use in actions like `await page.goto('/')`. */
39+
baseURL: 'http://localhost:4280',
40+
41+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
42+
trace: 'on-first-retry',
43+
},
44+
45+
/* Configure projects for major browsers */
46+
projects: [
47+
{
48+
name: 'chromium',
49+
use: {
50+
...devices['Desktop Chrome'],
51+
},
52+
},
53+
54+
{
55+
name: 'firefox',
56+
use: {
57+
...devices['Desktop Firefox'],
58+
},
59+
},
60+
61+
{
62+
name: 'webkit',
63+
use: {
64+
...devices['Desktop Safari'],
65+
},
66+
},
67+
68+
],
69+
70+
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
71+
// outputDir: 'test-results/',
72+
73+
/* Run your local dev server before starting the tests */
74+
webServer: {
75+
command: 'npm run start',
76+
port: 4280,
77+
}
78+
};
79+
80+
export default config;

tests/Test.README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Testing
2+
3+
To run playwright tests run `npm run playwright_test`. In order to run the playwright tests the start script `swa start src --api-location api` was added.

tests/playwright.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('basic test', async ({ page }) => {
4+
await page.goto('/');
5+
await page.waitForSelector('h1')
6+
await expect(page.locator('h1')).toContainText('Vanilla JavaScript App');
7+
await expect(page.locator('b')).toContainText('Hello from the API')
8+
})

0 commit comments

Comments
 (0)