Skip to content

Commit 7197b3b

Browse files
committed
chore: update linters
1 parent 25b7bf9 commit 7197b3b

File tree

27 files changed

+2529
-2013
lines changed

27 files changed

+2529
-2013
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/scripts/__tests__/results.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs';
22

33
import {getTestStatus, readTestResults} from '../utils/results';
4+
45
import type {TestResults, TestResultsInfo, TestStatusInfo} from './types';
56

67
jest.mock('fs');

.github/workflows/scripts/__tests__/test.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {compareTests, extractTestsFromSuite, isTestSkipped} from '../utils/test';
2+
23
import type {Spec, Suite, TestInfo} from './types';
34

45
describe('test utils', () => {

.github/workflows/scripts/__tests__/update-pr-description.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {generateBundleSizeSection, getBundleInfo} from '../utils/bundle';
33
import {generateTestChangesSummary} from '../utils/format';
44
import {getTestStatus, readTestResults} from '../utils/results';
55
import {compareTests} from '../utils/test';
6+
67
import type {TestResultsInfo} from './types';
78

89
// Mock dependencies
Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
const { compareTests } = require('./utils/test');
2-
const { generateTestChangesSummary } = require('./utils/format');
3-
const { generateBundleSizeSection, getBundleInfo } = require('./utils/bundle');
4-
const { readTestResults, getTestStatus } = require('./utils/results');
1+
const {generateBundleSizeSection, getBundleInfo} = require('./utils/bundle');
2+
const {generateTestChangesSummary} = require('./utils/format');
3+
const {readTestResults, getTestStatus} = require('./utils/results');
4+
const {compareTests} = require('./utils/test');
55

66
/**
77
* Main function to update PR description with test results and bundle size information
8-
* @param {Object} github - GitHub API object
9-
* @param {Object} context - GitHub Actions context
8+
* @param {object} github - GitHub API object
9+
* @param {object} context - GitHub Actions context
1010
*/
1111
async function updatePRDescription(github, context) {
12-
// Read test results
13-
const currentResults = readTestResults('playwright-artifacts/test-results.json');
14-
const mainResults = readTestResults('gh-pages/main/test-results.json');
15-
16-
// Compare tests
17-
const testComparison = compareTests(currentResults.tests, mainResults.tests);
18-
19-
// Get test status and report URL
20-
const { status, statusColor } = getTestStatus(currentResults);
21-
const reportUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/${context.issue.number}/`;
22-
23-
// Get bundle size information
24-
const bundleInfo = getBundleInfo();
25-
26-
// Generate the CI section content
27-
const ciSection = `## CI Results
12+
// Read test results
13+
const currentResults = readTestResults('playwright-artifacts/test-results.json');
14+
const mainResults = readTestResults('gh-pages/main/test-results.json');
15+
16+
// Compare tests
17+
const testComparison = compareTests(currentResults.tests, mainResults.tests);
18+
19+
// Get test status and report URL
20+
const {status, statusColor} = getTestStatus(currentResults);
21+
const reportUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/${context.issue.number}/`;
22+
23+
// Get bundle size information
24+
const bundleInfo = getBundleInfo();
25+
26+
// Generate the CI section content
27+
const ciSection = `## CI Results
2828
2929
### Test Status: <span style="color: ${statusColor};">${status}</span>
3030
📊 [Full Report](${reportUrl})
@@ -46,26 +46,26 @@ async function updatePRDescription(github, context) {
4646
- 🔺 indicates increase, 🔽 decrease, and ✅ no change in bundle size.
4747
</details>`;
4848

49-
// Update PR description
50-
const { data: pullRequest } = await github.rest.pulls.get({
51-
owner: context.repo.owner,
52-
repo: context.repo.repo,
53-
pull_number: context.issue.number,
54-
});
55-
56-
const currentBody = pullRequest.body || '';
57-
const ciSectionRegex = /## CI Results[\s\S]*?(?=\n## (?!CI Results)|$)/;
58-
59-
const newBody = ciSectionRegex.test(currentBody)
60-
? currentBody.replace(ciSectionRegex, ciSection)
61-
: currentBody + '\n\n' + ciSection;
62-
63-
await github.rest.pulls.update({
64-
owner: context.repo.owner,
65-
repo: context.repo.repo,
66-
pull_number: context.issue.number,
67-
body: newBody,
68-
});
49+
// Update PR description
50+
const {data: pullRequest} = await github.rest.pulls.get({
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
pull_number: context.issue.number,
54+
});
55+
56+
const currentBody = pullRequest.body || '';
57+
const ciSectionRegex = /## CI Results[\s\S]*?(?=\n## (?!CI Results)|$)/;
58+
59+
const newBody = ciSectionRegex.test(currentBody)
60+
? currentBody.replace(ciSectionRegex, ciSection)
61+
: currentBody + '\n\n' + ciSection;
62+
63+
await github.rest.pulls.update({
64+
owner: context.repo.owner,
65+
repo: context.repo.repo,
66+
pull_number: context.issue.number,
67+
body: newBody,
68+
});
6969
}
7070

7171
module.exports = updatePRDescription;
Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1-
const { formatSize } = require('./format');
1+
const {formatSize} = require('./format');
22

33
/**
44
* Generates the bundle size status section
5-
* @param {Object} bundleInfo - Bundle size information
5+
* @param {object} bundleInfo - Bundle size information
6+
* @param bundleInfo.currentSize
7+
* @param bundleInfo.mainSize
8+
* @param bundleInfo.diff
9+
* @param bundleInfo.percent
610
* @returns {string} Formatted bundle size section
711
*/
8-
function generateBundleSizeSection({ currentSize, mainSize, diff, percent }) {
9-
const bundleStatus = percent === 'N/A' ? '⚠️' :
10-
parseFloat(percent) > 0 ? '🔺' :
11-
parseFloat(percent) < 0 ? '🔽' : '✅';
12+
function generateBundleSizeSection({currentSize, mainSize, diff, percent}) {
13+
const bundleStatus =
14+
percent === 'N/A'
15+
? '⚠️'
16+
: parseFloat(percent) > 0
17+
? '🔺'
18+
: parseFloat(percent) < 0
19+
? '🔽'
20+
: '✅';
1221

13-
const sizeChangeMessage = percent === 'N/A' ? '⚠️ Unable to calculate change.' :
14-
parseFloat(percent) > 0 ? '⚠️ Bundle size increased. Please review.' :
15-
parseFloat(percent) < 0 ? '✅ Bundle size decreased.' : '✅ Bundle size unchanged.';
22+
const sizeChangeMessage =
23+
percent === 'N/A'
24+
? '⚠️ Unable to calculate change.'
25+
: parseFloat(percent) > 0
26+
? '⚠️ Bundle size increased. Please review.'
27+
: parseFloat(percent) < 0
28+
? '✅ Bundle size decreased.'
29+
: '✅ Bundle size unchanged.';
1630

17-
return `### Bundle Size: ${bundleStatus}
31+
return `### Bundle Size: ${bundleStatus}
1832
Current: ${formatSize(currentSize)} | Main: ${formatSize(mainSize)}
1933
Diff: ${diff > 0 ? '+' : ''}${formatSize(Math.abs(diff))} (${percent === 'N/A' ? 'N/A' : `${percent}%`})
2034
@@ -23,18 +37,18 @@ function generateBundleSizeSection({ currentSize, mainSize, diff, percent }) {
2337

2438
/**
2539
* Gets bundle size information from environment variables
26-
* @returns {Object} Bundle size information
40+
* @returns {object} Bundle size information
2741
*/
2842
function getBundleInfo() {
29-
return {
30-
currentSize: parseInt(process.env.CURRENT_SIZE || '0'),
31-
mainSize: parseInt(process.env.MAIN_SIZE || '0'),
32-
diff: parseInt(process.env.SIZE_DIFF || '0'),
33-
percent: process.env.SIZE_PERCENT || 'N/A'
34-
};
43+
return {
44+
currentSize: parseInt(process.env.CURRENT_SIZE || '0'),
45+
mainSize: parseInt(process.env.MAIN_SIZE || '0'),
46+
diff: parseInt(process.env.SIZE_DIFF || '0'),
47+
percent: process.env.SIZE_PERCENT || 'N/A',
48+
};
3549
}
3650

3751
module.exports = {
38-
generateBundleSizeSection,
39-
getBundleInfo
52+
generateBundleSizeSection,
53+
getBundleInfo,
4054
};

.github/workflows/scripts/utils/format.js

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,45 @@
44
* @returns {string} Formatted size string with units
55
*/
66
function formatSize(sizeInBytes) {
7-
const MB_THRESHOLD = 10 * 1024;
8-
if (sizeInBytes >= MB_THRESHOLD) {
9-
return `${(sizeInBytes / (1024 * 1024)).toFixed(2)} MB`;
10-
}
11-
return `${(sizeInBytes / 1024).toFixed(2)} KB`;
7+
const MB_THRESHOLD = 10 * 1024;
8+
if (sizeInBytes >= MB_THRESHOLD) {
9+
return `${(sizeInBytes / (1024 * 1024)).toFixed(2)} MB`;
10+
}
11+
return `${(sizeInBytes / 1024).toFixed(2)} KB`;
1212
}
1313

1414
/**
1515
* Generates a summary of test changes
16-
* @param {Object} comparison - Test comparison results
16+
* @param {object} comparison - Test comparison results
1717
* @returns {string} Formatted test changes summary
1818
*/
1919
function generateTestChangesSummary(comparison) {
20-
if (!comparison.new.length && !comparison.deleted.length && !comparison.skipped.length) {
21-
return '😟 No changes in tests. 😕';
22-
}
23-
24-
const summaryParts = [];
25-
const { new: newTests, skipped, deleted } = comparison;
26-
27-
if (newTests.length) {
28-
summaryParts.push(`#### ✨ New Tests (${newTests.length})\n${newTests.map((test, i) => `${i + 1}. ${test}`).join('\n')}\n`);
29-
}
30-
31-
if (skipped.length) {
32-
summaryParts.push(`#### ⏭️ Skipped Tests (${skipped.length})\n${skipped.map((test, i) => `${i + 1}. ${test}`).join('\n')}\n`);
33-
}
34-
35-
if (deleted.length) {
36-
summaryParts.push(`#### 🗑️ Deleted Tests (${deleted.length})\n${deleted.map((test, i) => `${i + 1}. ${test}`).join('\n')}`);
37-
}
38-
39-
return `
20+
if (!comparison.new.length && !comparison.deleted.length && !comparison.skipped.length) {
21+
return '😟 No changes in tests. 😕';
22+
}
23+
24+
const summaryParts = [];
25+
const {new: newTests, skipped, deleted} = comparison;
26+
27+
if (newTests.length) {
28+
summaryParts.push(
29+
`#### ✨ New Tests (${newTests.length})\n${newTests.map((test, i) => `${i + 1}. ${test}`).join('\n')}\n`,
30+
);
31+
}
32+
33+
if (skipped.length) {
34+
summaryParts.push(
35+
`#### ⏭️ Skipped Tests (${skipped.length})\n${skipped.map((test, i) => `${i + 1}. ${test}`).join('\n')}\n`,
36+
);
37+
}
38+
39+
if (deleted.length) {
40+
summaryParts.push(
41+
`#### 🗑️ Deleted Tests (${deleted.length})\n${deleted.map((test, i) => `${i + 1}. ${test}`).join('\n')}`,
42+
);
43+
}
44+
45+
return `
4046
<details>
4147
<summary>Test Changes Summary ${newTests.length ? `✨${newTests.length} ` : ''}${skipped.length ? `⏭️${skipped.length} ` : ''}${deleted.length ? `🗑️${deleted.length}` : ''}</summary>
4248
@@ -45,6 +51,6 @@ function generateTestChangesSummary(comparison) {
4551
}
4652

4753
module.exports = {
48-
formatSize,
49-
generateTestChangesSummary
54+
formatSize,
55+
generateTestChangesSummary,
5056
};
Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,45 @@
11
const fs = require('fs');
2-
const { extractTestsFromSuite } = require('./test');
2+
3+
const {extractTestsFromSuite} = require('./test');
34

45
/**
56
* Reads and processes test results from a JSON file
67
* @param {string} filePath - Path to the test results JSON file
7-
* @returns {Object} Processed test results
8+
* @returns {object} Processed test results
89
*/
910
function readTestResults(filePath) {
10-
if (!fs.existsSync(filePath)) {
11-
console.log(`Test results file not found: ${filePath}`);
12-
return { total: 0, passed: 0, failed: 0, flaky: 0, skipped: 0, tests: [] };
13-
}
14-
15-
const data = JSON.parse(fs.readFileSync(filePath));
16-
const allTests = data.suites.flatMap(suite => extractTestsFromSuite(suite));
17-
18-
return {
19-
total: data.stats.expected + data.stats.unexpected + data.stats.flaky + data.stats.skipped,
20-
passed: data.stats.expected,
21-
failed: data.stats.unexpected,
22-
flaky: data.stats.flaky,
23-
skipped: data.stats.skipped,
24-
tests: allTests
25-
};
11+
if (!fs.existsSync(filePath)) {
12+
console.info(`Test results file not found: ${filePath}`);
13+
return {total: 0, passed: 0, failed: 0, flaky: 0, skipped: 0, tests: []};
14+
}
15+
16+
const data = JSON.parse(fs.readFileSync(filePath));
17+
const allTests = data.suites.flatMap((suite) => extractTestsFromSuite(suite));
18+
19+
return {
20+
total: data.stats.expected + data.stats.unexpected + data.stats.flaky + data.stats.skipped,
21+
passed: data.stats.expected,
22+
failed: data.stats.unexpected,
23+
flaky: data.stats.flaky,
24+
skipped: data.stats.skipped,
25+
tests: allTests,
26+
};
2627
}
2728

2829
/**
2930
* Gets the test status information
30-
* @param {Object} results - Test results object
31-
* @returns {Object} Status information including color and label
31+
* @param {object} results - Test results object
32+
* @returns {object} Status information including color and label
3233
*/
3334
function getTestStatus(results) {
34-
const status = results.failed > 0 ? '❌ FAILED' :
35-
results.flaky > 0 ? '⚠️ FLAKY' :
36-
'✅ PASSED';
37-
38-
const statusColor = results.failed > 0 ? 'red' :
39-
results.flaky > 0 ? 'orange' :
40-
'green';
41-
42-
return { status, statusColor };
35+
const status = results.failed > 0 ? '❌ FAILED' : results.flaky > 0 ? '⚠️ FLAKY' : '✅ PASSED';
36+
37+
const statusColor = results.failed > 0 ? 'red' : results.flaky > 0 ? 'orange' : 'green';
38+
39+
return {status, statusColor};
4340
}
4441

4542
module.exports = {
46-
readTestResults,
47-
getTestStatus
43+
readTestResults,
44+
getTestStatus,
4845
};

0 commit comments

Comments
 (0)