Skip to content

Commit

Permalink
Merge pull request #203 from adobecom/force-integration-tests
Browse files Browse the repository at this point in the history
feat(MWPW-162743): enforce e2e tests for new components via GitHub action
  • Loading branch information
raissanjay authored Nov 20, 2024
2 parents 8ba48ef + 0b393a5 commit dcbcc7d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ on: [pull_request]
permissions: write-all

jobs:
check-test-requirements:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.13.1 # No cache line
- name: Install dependencies # Added explicit install step
run: npm install @actions/core @actions/github
- name: Check PR Type and Tests
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const script = require('./test-enforcement.js')
await script({github, context, core})
check-linting:
runs-on: ubuntu-latest
steps:
Expand Down
46 changes: 46 additions & 0 deletions test-enforcement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const enforceTestRequirements = async ({ github, context, core }) => {
try {
const { data: files } = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});

const prTitle = context.payload.pull_request.title;
const commitType = prTitle.split(':')[0].toLowerCase();

// Add debug logs
core.info(`PR Title: ${prTitle}`);
core.info(`Commit Type: ${commitType}`);
core.info(`Files changed: ${JSON.stringify(files.map(f => f.filename))}`);

const hasNewComponent = files.some(f => {
const isComponent = f.filename.includes('/components/');
const isNew = f.status === 'added';
// Add debug logs
core.info(`Checking file: ${f.filename}`);
core.info(`Is component? ${isComponent}`);
core.info(`Is new? ${isNew}`);
return isComponent && isNew;
});

const hasIntegrationTest = files.some(f =>
f.filename.includes('.e2e.js'),
);

// Add debug logs
core.info(`Has new component? ${hasNewComponent}`);
core.info(`Has integration test? ${hasIntegrationTest}`);

if (commitType === 'feat' && hasNewComponent && !hasIntegrationTest) {
core.setFailed('New feature components require integration tests');
return;
}

core.info('Test requirements check passed');
} catch (error) {
core.setFailed(error.message);
}
};

module.exports = enforceTestRequirements;

0 comments on commit dcbcc7d

Please sign in to comment.