Skip to content

Added EOL check before triggering layoutFn on tick event #584

Added EOL check before triggering layoutFn on tick event

Added EOL check before triggering layoutFn on tick event #584

name: Run Blits Tests
on:
pull_request:
branches:
- dev
- master
jobs:
run-blits-tests:
runs-on: ubuntu-latest
outputs:
tests_failed: ${{ steps.analyze-results.outputs.result && fromJSON(steps.analyze-results.outputs.result).testsFailed }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20.16.0
- name: Save PR Information
run: |
echo '${{ github.event.pull_request.number }}' > ./pr_number.txt
echo '${{ github.event.pull_request.head.repo.full_name }}' > ./pr_repo.txt
echo '${{ github.event.pull_request.head.ref }}' > ./pr_branch.txt
- name: Install Dependencies
run: npm install
- name: Run Tests
id: run-tests
continue-on-error: true
run: |
set -o pipefail
npm run test:run 2>&1 | tee test-report.txt
- name: Analyze Test Results
id: analyze-results
uses: actions/github-script@v7
with:
result-encoding: json
script: |
const fs = require('fs');
const timestamp = new Date().toISOString();
const results = {
timestamp,
summary: '',
testsFailed: false,
error: null
};
// Check if test report exists and has content
if (!fs.existsSync('test-report.txt') || !fs.statSync('test-report.txt').size) {
results.summary = 'Test execution error: No test output generated.';
results.testsFailed = true;
return outputResults(results);
}
// Read test report for summary extraction only
const testOutput = fs.readFileSync('test-report.txt', 'utf8');
const testsMatch = testOutput.match(/^# tests\s+(\d+)/m);
const passMatch = testOutput.match(/^# pass\s+(\d+)/m);
const failMatch = testOutput.match(/^# fail\s+(\d+)/m);
if (testsMatch && passMatch) {
const failed = failMatch ? failMatch[1] : '0';
results.summary = `passed: ${passMatch[1]} failed: ${failed} of ${testsMatch[1]} tests`;
results.testsFailed = failMatch ? parseInt(failMatch[1]) > 0 : false;
const failedBlocks = [];
let inBlock = false, currentBlock = [];
for (const line of testOutput.split('\n')) {
if (/^not ok /.test(line)) {
inBlock = true; currentBlock = [line];
} else if (inBlock) {
if (/^ \.\.\.$/.test(line)) {
currentBlock.push(line);
failedBlocks.push(currentBlock.join('\n'));
inBlock = false; currentBlock = [];
} else {
currentBlock.push(line);
}
}
}
fs.writeFileSync('./failing-tests.txt', failedBlocks.join('\n\n'));
} else if (results.testsFailed) {
results.summary = 'Tests failed. No summary found in output.';
results.error = testOutput;
} else {
results.summary = 'Tests passed. No summary found in output.';
}
return outputResults(results);
/**
* Outputs results and saves result files
*/
function outputResults(results) {
try {
fs.writeFileSync('./timestamp.txt', results.timestamp);
fs.writeFileSync('./summary.txt', results.summary);
fs.writeFileSync('./failed.txt', results.testsFailed.toString());
// Save error output if it exists
if (results.error) {
fs.writeFileSync('./error.txt', results.error);
}
} catch (err) {
core.warning(`Error saving test results: ${err.message}`);
}
return results;
}
- name: Upload Test Report Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: test-report
path: test-report.txt
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
./timestamp.txt
./summary.txt
./failed.txt
./failing-tests.txt
./pr_number.txt
./pr_repo.txt
./pr_branch.txt
continue-on-error: true
- name: Upload Error Log
if: fromJSON(steps.analyze-results.outputs.result).testsFailed == true
uses: actions/upload-artifact@v4
with:
name: error-log
path: ./error.txt
if-no-files-found: ignore
continue-on-error: true
# Fail the workflow if tests failed
- name: Check Test Status
if: fromJSON(steps.analyze-results.outputs.result).testsFailed == true
run: exit 1