Skip to content

chore: update linters #2419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

36 changes: 0 additions & 36 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/scripts/__tests__/results.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs';

import {getTestStatus, readTestResults} from '../utils/results';

import type {TestResults, TestResultsInfo, TestStatusInfo} from './types';

jest.mock('fs');
Expand All @@ -27,7 +28,7 @@

test('should read and process test results correctly', () => {
const mockTestResults: TestResults = {
config: {} as any,

Check warning on line 31 in .github/workflows/scripts/__tests__/results.test.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
suites: [
{
title: 'Test Suite',
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/scripts/__tests__/test.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {compareTests, extractTestsFromSuite, isTestSkipped} from '../utils/test';

import type {Spec, Suite, TestInfo} from './types';

describe('test utils', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {generateBundleSizeSection, getBundleInfo} from '../utils/bundle';
import {generateTestChangesSummary} from '../utils/format';
import {getTestStatus, readTestResults} from '../utils/results';
import {compareTests} from '../utils/test';

import type {TestResultsInfo} from './types';

// Mock dependencies
Expand Down
84 changes: 42 additions & 42 deletions .github/workflows/scripts/update-pr-description.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
const { compareTests } = require('./utils/test');
const { generateTestChangesSummary } = require('./utils/format');
const { generateBundleSizeSection, getBundleInfo } = require('./utils/bundle');
const { readTestResults, getTestStatus } = require('./utils/results');
const {generateBundleSizeSection, getBundleInfo} = require('./utils/bundle');
const {generateTestChangesSummary} = require('./utils/format');
const {readTestResults, getTestStatus} = require('./utils/results');
const {compareTests} = require('./utils/test');

/**
* Main function to update PR description with test results and bundle size information
* @param {Object} github - GitHub API object
* @param {Object} context - GitHub Actions context
* @param {object} github - GitHub API object
* @param {object} context - GitHub Actions context
*/
async function updatePRDescription(github, context) {
// Read test results
const currentResults = readTestResults('playwright-artifacts/test-results.json');
const mainResults = readTestResults('gh-pages/main/test-results.json');
// Compare tests
const testComparison = compareTests(currentResults.tests, mainResults.tests);
// Get test status and report URL
const { status, statusColor } = getTestStatus(currentResults);
const reportUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/${context.issue.number}/`;

// Get bundle size information
const bundleInfo = getBundleInfo();

// Generate the CI section content
const ciSection = `## CI Results
// Read test results
const currentResults = readTestResults('playwright-artifacts/test-results.json');
const mainResults = readTestResults('gh-pages/main/test-results.json');

// Compare tests
const testComparison = compareTests(currentResults.tests, mainResults.tests);

// Get test status and report URL
const {status, statusColor} = getTestStatus(currentResults);
const reportUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/${context.issue.number}/`;

// Get bundle size information
const bundleInfo = getBundleInfo();

// Generate the CI section content
const ciSection = `## CI Results

### Test Status: <span style="color: ${statusColor};">${status}</span>
📊 [Full Report](${reportUrl})
Expand All @@ -46,26 +46,26 @@ async function updatePRDescription(github, context) {
- 🔺 indicates increase, 🔽 decrease, and ✅ no change in bundle size.
</details>`;

// Update PR description
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});

const currentBody = pullRequest.body || '';
const ciSectionRegex = /## CI Results[\s\S]*?(?=\n## (?!CI Results)|$)/;

const newBody = ciSectionRegex.test(currentBody)
? currentBody.replace(ciSectionRegex, ciSection)
: currentBody + '\n\n' + ciSection;

await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body: newBody,
});
// Update PR description
const {data: pullRequest} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});

const currentBody = pullRequest.body || '';
const ciSectionRegex = /## CI Results[\s\S]*?(?=\n## (?!CI Results)|$)/;

const newBody = ciSectionRegex.test(currentBody)
? currentBody.replace(ciSectionRegex, ciSection)
: currentBody + '\n\n' + ciSection;

await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body: newBody,
});
}

module.exports = updatePRDescription;
52 changes: 33 additions & 19 deletions .github/workflows/scripts/utils/bundle.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
const { formatSize } = require('./format');
const {formatSize} = require('./format');

/**
* Generates the bundle size status section
* @param {Object} bundleInfo - Bundle size information
* @param {object} bundleInfo - Bundle size information
* @param bundleInfo.currentSize

Check warning on line 6 in .github/workflows/scripts/utils/bundle.js

View workflow job for this annotation

GitHub Actions / Verify Files

Missing JSDoc @param "bundleInfo.currentSize" type
* @param bundleInfo.mainSize

Check warning on line 7 in .github/workflows/scripts/utils/bundle.js

View workflow job for this annotation

GitHub Actions / Verify Files

Missing JSDoc @param "bundleInfo.mainSize" type
* @param bundleInfo.diff

Check warning on line 8 in .github/workflows/scripts/utils/bundle.js

View workflow job for this annotation

GitHub Actions / Verify Files

Missing JSDoc @param "bundleInfo.diff" type
* @param bundleInfo.percent

Check warning on line 9 in .github/workflows/scripts/utils/bundle.js

View workflow job for this annotation

GitHub Actions / Verify Files

Missing JSDoc @param "bundleInfo.percent" type
* @returns {string} Formatted bundle size section
*/
function generateBundleSizeSection({ currentSize, mainSize, diff, percent }) {
const bundleStatus = percent === 'N/A' ? '⚠️' :
parseFloat(percent) > 0 ? '🔺' :
parseFloat(percent) < 0 ? '🔽' : '✅';
function generateBundleSizeSection({currentSize, mainSize, diff, percent}) {
const bundleStatus =
percent === 'N/A'

Check warning on line 14 in .github/workflows/scripts/utils/bundle.js

View workflow job for this annotation

GitHub Actions / Verify Files

Do not nest ternary expressions
? '⚠️'
: parseFloat(percent) > 0

Check warning on line 16 in .github/workflows/scripts/utils/bundle.js

View workflow job for this annotation

GitHub Actions / Verify Files

Do not nest ternary expressions
? '🔺'
: parseFloat(percent) < 0
? '🔽'
: '✅';

const sizeChangeMessage = percent === 'N/A' ? '⚠️ Unable to calculate change.' :
parseFloat(percent) > 0 ? '⚠️ Bundle size increased. Please review.' :
parseFloat(percent) < 0 ? '✅ Bundle size decreased.' : '✅ Bundle size unchanged.';
const sizeChangeMessage =
percent === 'N/A'

Check warning on line 23 in .github/workflows/scripts/utils/bundle.js

View workflow job for this annotation

GitHub Actions / Verify Files

Do not nest ternary expressions
? '⚠️ Unable to calculate change.'
: parseFloat(percent) > 0

Check warning on line 25 in .github/workflows/scripts/utils/bundle.js

View workflow job for this annotation

GitHub Actions / Verify Files

Do not nest ternary expressions
? '⚠️ Bundle size increased. Please review.'
: parseFloat(percent) < 0
? '✅ Bundle size decreased.'
: '✅ Bundle size unchanged.';

return `### Bundle Size: ${bundleStatus}
return `### Bundle Size: ${bundleStatus}
Current: ${formatSize(currentSize)} | Main: ${formatSize(mainSize)}
Diff: ${diff > 0 ? '+' : ''}${formatSize(Math.abs(diff))} (${percent === 'N/A' ? 'N/A' : `${percent}%`})

Expand All @@ -23,18 +37,18 @@

/**
* Gets bundle size information from environment variables
* @returns {Object} Bundle size information
* @returns {object} Bundle size information
*/
function getBundleInfo() {
return {
currentSize: parseInt(process.env.CURRENT_SIZE || '0'),
mainSize: parseInt(process.env.MAIN_SIZE || '0'),
diff: parseInt(process.env.SIZE_DIFF || '0'),
percent: process.env.SIZE_PERCENT || 'N/A'
};
return {
currentSize: parseInt(process.env.CURRENT_SIZE || '0'),

Check warning on line 44 in .github/workflows/scripts/utils/bundle.js

View workflow job for this annotation

GitHub Actions / Verify Files

Missing radix parameter
mainSize: parseInt(process.env.MAIN_SIZE || '0'),
diff: parseInt(process.env.SIZE_DIFF || '0'),
percent: process.env.SIZE_PERCENT || 'N/A',
};
}

module.exports = {
generateBundleSizeSection,
getBundleInfo
generateBundleSizeSection,
getBundleInfo,
};
62 changes: 34 additions & 28 deletions .github/workflows/scripts/utils/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,45 @@
* @returns {string} Formatted size string with units
*/
function formatSize(sizeInBytes) {
const MB_THRESHOLD = 10 * 1024;
if (sizeInBytes >= MB_THRESHOLD) {
return `${(sizeInBytes / (1024 * 1024)).toFixed(2)} MB`;
}
return `${(sizeInBytes / 1024).toFixed(2)} KB`;
const MB_THRESHOLD = 10 * 1024;
if (sizeInBytes >= MB_THRESHOLD) {
return `${(sizeInBytes / (1024 * 1024)).toFixed(2)} MB`;
}
return `${(sizeInBytes / 1024).toFixed(2)} KB`;
}

/**
* Generates a summary of test changes
* @param {Object} comparison - Test comparison results
* @param {object} comparison - Test comparison results
* @returns {string} Formatted test changes summary
*/
function generateTestChangesSummary(comparison) {
if (!comparison.new.length && !comparison.deleted.length && !comparison.skipped.length) {
return '😟 No changes in tests. 😕';
}

const summaryParts = [];
const { new: newTests, skipped, deleted } = comparison;

if (newTests.length) {
summaryParts.push(`#### ✨ New Tests (${newTests.length})\n${newTests.map((test, i) => `${i + 1}. ${test}`).join('\n')}\n`);
}

if (skipped.length) {
summaryParts.push(`#### ⏭️ Skipped Tests (${skipped.length})\n${skipped.map((test, i) => `${i + 1}. ${test}`).join('\n')}\n`);
}

if (deleted.length) {
summaryParts.push(`#### 🗑️ Deleted Tests (${deleted.length})\n${deleted.map((test, i) => `${i + 1}. ${test}`).join('\n')}`);
}

return `
if (!comparison.new.length && !comparison.deleted.length && !comparison.skipped.length) {
return '😟 No changes in tests. 😕';
}

const summaryParts = [];
const {new: newTests, skipped, deleted} = comparison;

if (newTests.length) {
summaryParts.push(
`#### ✨ New Tests (${newTests.length})\n${newTests.map((test, i) => `${i + 1}. ${test}`).join('\n')}\n`,
);
}

if (skipped.length) {
summaryParts.push(
`#### ⏭️ Skipped Tests (${skipped.length})\n${skipped.map((test, i) => `${i + 1}. ${test}`).join('\n')}\n`,
);
}

if (deleted.length) {
summaryParts.push(
`#### 🗑️ Deleted Tests (${deleted.length})\n${deleted.map((test, i) => `${i + 1}. ${test}`).join('\n')}`,
);
}

return `
<details>
<summary>Test Changes Summary ${newTests.length ? `✨${newTests.length} ` : ''}${skipped.length ? `⏭️${skipped.length} ` : ''}${deleted.length ? `🗑️${deleted.length}` : ''}</summary>

Expand All @@ -45,6 +51,6 @@ function generateTestChangesSummary(comparison) {
}

module.exports = {
formatSize,
generateTestChangesSummary
formatSize,
generateTestChangesSummary,
};
59 changes: 28 additions & 31 deletions .github/workflows/scripts/utils/results.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
const fs = require('fs');
const { extractTestsFromSuite } = require('./test');

const {extractTestsFromSuite} = require('./test');

/**
* Reads and processes test results from a JSON file
* @param {string} filePath - Path to the test results JSON file
* @returns {Object} Processed test results
* @returns {object} Processed test results
*/
function readTestResults(filePath) {
if (!fs.existsSync(filePath)) {
console.log(`Test results file not found: ${filePath}`);
return { total: 0, passed: 0, failed: 0, flaky: 0, skipped: 0, tests: [] };
}

const data = JSON.parse(fs.readFileSync(filePath));
const allTests = data.suites.flatMap(suite => extractTestsFromSuite(suite));
return {
total: data.stats.expected + data.stats.unexpected + data.stats.flaky + data.stats.skipped,
passed: data.stats.expected,
failed: data.stats.unexpected,
flaky: data.stats.flaky,
skipped: data.stats.skipped,
tests: allTests
};
if (!fs.existsSync(filePath)) {
console.info(`Test results file not found: ${filePath}`);
return {total: 0, passed: 0, failed: 0, flaky: 0, skipped: 0, tests: []};
}

const data = JSON.parse(fs.readFileSync(filePath));
const allTests = data.suites.flatMap((suite) => extractTestsFromSuite(suite));

return {
total: data.stats.expected + data.stats.unexpected + data.stats.flaky + data.stats.skipped,
passed: data.stats.expected,
failed: data.stats.unexpected,
flaky: data.stats.flaky,
skipped: data.stats.skipped,
tests: allTests,
};
}

/**
* Gets the test status information
* @param {Object} results - Test results object
* @returns {Object} Status information including color and label
* @param {object} results - Test results object
* @returns {object} Status information including color and label
*/
function getTestStatus(results) {
const status = results.failed > 0 ? '❌ FAILED' :
results.flaky > 0 ? '⚠️ FLAKY' :
'✅ PASSED';

const statusColor = results.failed > 0 ? 'red' :
results.flaky > 0 ? 'orange' :
'green';

return { status, statusColor };
const status = results.failed > 0 ? '❌ FAILED' : results.flaky > 0 ? '⚠️ FLAKY' : '✅ PASSED';

const statusColor = results.failed > 0 ? 'red' : results.flaky > 0 ? 'orange' : 'green';

return {status, statusColor};
}

module.exports = {
readTestResults,
getTestStatus
readTestResults,
getTestStatus,
};
Loading