Open 7alip opened 2 hours ago
You can achieve this by using a combination of Playwright and Git commands. Here's a general approach:
Step 1: Identify the changed files using Git.
git diff --name-only HEAD~1
Step 2: Filter the test files from the list of changed files.
Step 3: Run Playwright tests for those files.
const { execSync } = require('child_process');
const { test, expect } = require('@playwright/test');
const changedFiles = execSync('git diff --name-only HEAD~1').toString().split('\n');
const testFiles = changedFiles.filter(file => file.includes('.spec.ts'));
testFiles.forEach(file => {
test(file, async ({ page }) => {
// Your test logic here
});
});
test/
or /onboarding
in the CI/CD PipelineYou can configure your CI/CD pipeline (e.g., GitHub Actions) to check the branch name and run the tests accordingly.
GitHub Actions Configuration:
name: Run Tests
on:
push:
branches:
- 'test/*'
- '/onboarding/*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: |
git diff --name-only HEAD~1 > changed_files.txt
changed_files=$(cat changed_files.txt | grep '.spec.ts')
if [ -n "$changed_files" ]; then
npx playwright test $changed_files
else
echo "No test files changed"
fi
Description:
Implement a mechanism to run tests only for changed/updated files if the branch name starts with
test/
or/onboarding
.Steps to Implement:
Suggestions: