-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprepare_playwright.sh
executable file
·80 lines (67 loc) · 1.73 KB
/
prepare_playwright.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
#
# Prepare for playwright tests in a single example directory.
# Eventually need to look through all example directories.
set -eux
export TYPE=typescript
export EXAMPLE=vanilla_webpack
function merge-json() {
# merge the second json file into the first.
TEMP_FILE=$(mktemp)
jq '. * input' $1 $2 > TEMP_FILE && mv TEMP_FILE $1
}
# 1. Create and build example code in temporary directory
cd $TYPE && bash ./create_$EXAMPLE.sh && cd ..
# 2. Create *-test directory
mkdir temp/$TYPE/$EXAMPLE-test
cd temp/$TYPE/$EXAMPLE-test
# 3. Create initial package.json
npm init --yes
# 4. Add dev dependencies
npm install --save-dev "@playwright/test"
npm install --save-dev ../$EXAMPLE
# 5. Create playwright.config.ts
cat > playwright.config.ts << EOF
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:4500',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
}
],
webServer: {
command: 'npm run serve',
url: 'http://localhost:4500',
reuseExistingServer: !process.env.CI
}
});
EOF
# 4. Add test commands to package.json
cat > temp.json << EOF
{
"scripts": {
"serve": "npm explore $EXAMPLE -- npm run serve",
"test": "playwright test",
"test:ui": "playwright test --ui"
}
}
EOF
merge-json package.json temp.json
rm temp.json
# 5. Copy tests into temp example directory
cp -r ../../../tests .
# 6. Install playwright browser
npx playwright install chromium
# 7. Run tests
npm run test