Skip to content

Commit

Permalink
Merge pull request #6 from l-peacock/feature/prValidation2
Browse files Browse the repository at this point in the history
Tests: Fixed syntax error in workflow yaml
  • Loading branch information
l-peacock authored Feb 10, 2024
2 parents 4b72541 + ff2710c commit 170625b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/runTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ name: Run Tests
on: [pull_request]

jobs:
test:
Run_Jest_Tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install npm and run jest tests
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: "12"
node-version: "21"
- run: npm install
- run: npm run test:unit:coverage:
- run: npm run test:validate

- name: Tests Passed ✅
if: ${{ success() }}
Expand Down
41 changes: 41 additions & 0 deletions github-actions-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* A custom reporter for jest test results.
* This will convert jest test coverage output into the expected format for github actions.
* Referenced for https://joelhooks.com/jest-and-github-actions/
*/
class GithubActionsReporter {
constructor(globalConfig, options) {
this._globalConfig = globalConfig;
this._options = options;
}

onRunComplete(contexts, results) {
results.testResults.forEach((testResultItem) => {
const testFilePath = testResultItem.testFilePath;

testResultItem.testResults.forEach((result) => {
if (result.status !== "failed") {
return;
}

result.failureMessages.forEach((failureMessages) => {
const newLine = "%0A";
const message = failureMessages.replace(/\n/g, newLine);
const captureGroup = message.match(/:([0-9]+):([0-9]+)/);

if (!captureGroup) {
console.log("Unable to extract line number from call stack");
return;
}

const [, line, col] = captureGroup;
console.log(
`::error file=${testFilePath},line=${line},col=${col}::${message}`,
);
});
});
});
}
}

export default GithubActionsReporter;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test:unit": "jest",
"test:unit:coverage": "jest --coverage",
"test:unit:watch": "jest --watch",
"test:validate": "jest --ci --reporters='default' --reporters='./github-actions-reporter'",
"build": "lwr build --clean",
"build:prod-compat": "lwr build --clean --mode prod-compat",
"start": "lwr start",
Expand Down

0 comments on commit 170625b

Please sign in to comment.