Skip to content

Commit

Permalink
debug picking random env var values
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfinnarn committed Mar 27, 2024
1 parent 785e094 commit 07d618e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
36 changes: 33 additions & 3 deletions .github/workflows/a11y.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,47 @@ jobs:
env:
BASE_URL: 'https://va.gov'
USE_PROXY: false
PW_TRACE: 'off'
PW_SCREENSHOT: 'off'
PW_VIDEO: 'off'
PW_BROWSER: '["chromium", "firefox", "webkit"]'
PW_WIDTH: '[320, 768, 1024, 1280, 1920]'
PW_HEIGHT: '[720, 1080, 1440]'
strategy:
fail-fast: false
matrix:
shardIndex: [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]
shardTotal: [64]
# shardIndex: [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]
shardIndex: [1, 2, 3]
shardTotal: [3]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18

- name: Install jq
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: Run command with random values from arrays
run: |
arrays=("PW_BROWSER" "PW_WIDTH" "PW_HEIGHT")
for array_name in "${arrays[@]}"; do
json_string="${{ env[$array_name] }}"
array=$(echo "$json_string" | jq -c '.')
random_index=$((RANDOM % $(echo "$array" | jq 'length')))
random_value=$(echo "$array" | jq -r ".[$random_index]")
echo "Selected random value from $array_name: $random_value"
echo "${array_name}_VALUE=$random_value" >> $GITHUB_ENV
done
- name: Use random values in a command
run: |
echo "Using random values: $PW_BROWSER_VALUE, $PW_WIDTH_VALUE, $PW_HEIGHT_VALUE"
cd foo-bar
- name: Install dependencies
run: yarn install

Expand Down Expand Up @@ -64,7 +94,7 @@ jobs:

- name: Merge reports
run: |
cat segment-*.json > all-segments.json
echo '[' > all-segments.json && cat segment-*.json >> all-segments.json && echo ']' >> all-segments.json
cat all-segments.json
- name: Upload report
Expand Down
22 changes: 16 additions & 6 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { defineConfig } from '@playwright/test'
import {
defineConfig,
ScreenshotMode,
TraceMode,
VideoMode,
ViewportSize,
} from '@playwright/test'

export default defineConfig({
testDir: './playwright/tests',
outputDir: './playwright/test-results',
reporter: [['html', { outputFolder: './playwright/test-report' }]],
fullyParallel: process.env.CI ? false : true,
fullyParallel: !process.env.CI,

// Fail the build on CI if you accidentally left test.only in the source code.
forbidOnly: !!process.env.CI,
Expand All @@ -23,10 +29,14 @@ export default defineConfig({
},

// Collect trace when retrying the failed test.
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'on-first-retry',
viewport: { width: 1280, height: 720 },
trace: (process.env.PW_TRACE as TraceMode) || 'on-first-retry',
screenshot:
(process.env.PW_SCREENSHOT as ScreenshotMode) || 'only-on-failure',
video: (process.env.PW_VIDEO as VideoMode) || 'on-first-retry',
viewport: ({
width: Number(process.env.PW_WIDTH_VALUE),
height: Number(process.env.PW_HEIGHT_VALUE),
} as ViewportSize) || { width: 1280, height: 720 },
},

projects: [
Expand Down
11 changes: 10 additions & 1 deletion playwright/tests/a11y.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ async function runA11yTestsForPages(pages, page, testInfo) {
if (scanResultsArray.length > 0) {
fs.writeFileSync(
`segment-${segmentNumber}.json`,
JSON.stringify(scanResultsArray, null, 2)
JSON.stringify(
scanResultsArray,
(key, value) => {
if (Array.isArray(value)) {
return value.join(',\n')
}
return value
},
2
)
)
}
}
Expand Down

0 comments on commit 07d618e

Please sign in to comment.