Skip to content

Commit

Permalink
Improve E2E Test Failure Handling and Reporting (#1191)
Browse files Browse the repository at this point in the history
* Fix configurations, increasing timeouts and enhancing test failure handling
  • Loading branch information
shammowla authored Oct 11, 2024
1 parent 22ebb10 commit 49395c8
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 54 deletions.
53 changes: 53 additions & 0 deletions .github/scripts/handle-test-failures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module.exports = async ({ github, context, browser }) => {
const fs = require('fs');
const path = require('path');

// Read the test results
const testResultsDir = './test-results';
const files = fs.readdirSync(testResultsDir);

for (const file of files) {
const content = fs.readFileSync(path.join(testResultsDir, file), 'utf8');
let result;
try {
result = JSON.parse(content);
} catch (error) {
console.error(`Error parsing JSON from ${file}: ${error}`);
continue;
}

if (result.status === 'failed') {
const testName = result.name;
const sauceLabsLink = `https://app.saucelabs.com/tests/${result.id}`;

// Search for an existing issue
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: ['test-failure', browser]
});

const existingIssue = issues.data.find(issue => issue.title.includes(testName));

if (existingIssue) {
// Update existing issue
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: existingIssue.number,
body: `Test failed again in the latest run.\nBrowser: ${browser}\nRun: ${context.runId}\n[View on SauceLabs](${sauceLabsLink})`
});
} else {
// Create new issue
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Test Failure: ${testName} (${browser})`,
body: `The test "${testName}" failed in the ${browser} browser.\n\nRun: ${context.runId}\n[View on SauceLabs](${sauceLabsLink})`,
labels: ['test-failure', browser]
});
}
}
}
};
60 changes: 18 additions & 42 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,14 @@ jobs:
echo "TEST_RESULTS=No test results found in ./test-results/" >> $GITHUB_ENV
fi
- name: Notify Slack on Failure
- name: Handle Test Failures
if: failure()
uses: 8398a7/action-slack@v3
uses: actions/github-script@v7
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow
text: |
Alloy Prod Firefox Tests Failed
Job ID: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').id }}
Build: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').build }}
Status: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').status }}
Error: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').error }}
Full Results: https://app.saucelabs.com/tests/${{ fromJson(steps.saucelabs-results.outputs.results || '{}').id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const handleTestFailures = require('./.github/scripts/handle-test-failures.js');
await handleTestFailures({ github, context, browser: 'safari' });
alloy-prod-e2e-firefox:
name: Firefox
Expand Down Expand Up @@ -244,22 +236,14 @@ jobs:
echo "TEST_RESULTS=No test results found in ./test-results/" >> $GITHUB_ENV
fi
- name: Notify Slack on Failure
- name: Handle Test Failures
if: failure()
uses: 8398a7/action-slack@v3
uses: actions/github-script@v7
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow
text: |
Alloy Prod Firefox Tests Failed
Job ID: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').id }}
Build: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').build }}
Status: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').status }}
Error: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').error }}
Full Results: https://app.saucelabs.com/tests/${{ fromJson(steps.saucelabs-results.outputs.results || '{}').id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const handleTestFailures = require('./.github/scripts/handle-test-failures.js');
await handleTestFailures({ github, context, browser: 'firefox' });
alloy-prod-e2e-chrome:
name: Chrome
Expand Down Expand Up @@ -328,19 +312,11 @@ jobs:
ALLOY_ENV=prod
config-file: ./.sauce/prod-chrome.yml

- name: Notify Slack on Failure
- name: Handle Test Failures
if: failure()
uses: 8398a7/action-slack@v3
uses: actions/github-script@v7
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow
text: |
Alloy Prod Firefox Tests Failed
Job ID: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').id }}
Build: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').build }}
Status: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').status }}
Error: ${{ fromJson(steps.saucelabs-results.outputs.results || '{}').error }}
Full Results: https://app.saucelabs.com/tests/${{ fromJson(steps.saucelabs-results.outputs.results || '{}').id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const handleTestFailures = require('./.github/scripts/handle-test-failures.js');
await handleTestFailures({ github, context, browser: 'chrome' });
10 changes: 7 additions & 3 deletions .sauce/prod-chrome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ apiVersion: v1alpha
kind: testcafe
sauce:
region: us-west-1
retries: 3
metadata:
name: Alloy Prod
rootDir: ./
env:
ALLOY_ENV: prod
ALLOY_PROD_VERSION: $ALLOY_PROD_VERSION
NPM_PACKAGE_VERSION: $NPM_PACKAGE_VERSION
PACKAGE_VERSION: $PACKAGE_VERSION
testcafe:
version: "package.json"
nodeVersion: "$NODE_VERSION"
speed: 1
pageLoadTimeout: 3000
disablePageCaching: true
speed: 0.5
pageLoadTimeout: 8000
disablePageCaching: false
timeZone: New_York
npm:
dependencies:
Expand All @@ -31,6 +33,8 @@ npm:
- "@adobe/reactor-object-assign"
suites:
- name: "Chrome"
smartRetry:
failedOnly: true
browserName: "chrome"
browserVersion: "latest"
src:
Expand Down
15 changes: 9 additions & 6 deletions .sauce/prod-firefox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ apiVersion: v1alpha
kind: testcafe
sauce:
region: us-west-1
retries: 3
metadata:
name: Alloy Prod
rootDir: ./
env:
ALLOY_ENV: prod
ALLOY_PROD_VERSION: $ALLOY_PROD_VERSION
NPM_PACKAGE_VERSION: $NPM_PACKAGE_VERSION
PACKAGE_VERSION: $PACKAGE_VERSION
testcafe:
version: 3.6.0
nodeVersion: "22"
speed: 1
pageLoadTimeout: 3000
version: "package.json"
nodeVersion: "$NODE_VERSION"
speed: 0.5
pageLoadTimeout: 8000
disablePageCaching: true
timeZone: New_York
timeout: 3600
npm:
dependencies:
- node-fetch
Expand All @@ -32,11 +33,13 @@ npm:
- "@adobe/reactor-object-assign"
suites:
- name: "Firefox"
smartRetry:
failedOnly: true
browserName: "firefox"
browserVersion: "latest"
src:
- "test/functional/specs/**/*.js"
platformName: "macOS 13"
platformName: "Windows 11"
excludedTestFiles:
[
"test/functional/specs/Data Collector/C81182.js",
Expand Down
10 changes: 7 additions & 3 deletions .sauce/prod-safari.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ apiVersion: v1alpha
kind: testcafe
sauce:
region: us-west-1
retries: 3
metadata:
name: Alloy Prod
rootDir: ./
env:
ALLOY_ENV: prod
ALLOY_PROD_VERSION: $ALLOY_PROD_VERSION
NPM_PACKAGE_VERSION: $NPM_PACKAGE_VERSION
PACKAGE_VERSION: $PACKAGE_VERSION
testcafe:
version: "package.json"
nodeVersion: "$NODE_VERSION"
speed: 1
pageLoadTimeout: 3000
disablePageCaching: true
speed: 0.5
pageLoadTimeout: 8000
disablePageCaching: false
timeZone: New_York
npm:
dependencies:
Expand All @@ -31,6 +33,8 @@ npm:
- "@adobe/reactor-object-assign"
suites:
- name: "Safari"
smartRetry:
failedOnly: true
browserName: "safari"
browserVersion: "latest"
src:
Expand Down

0 comments on commit 49395c8

Please sign in to comment.