-
Notifications
You must be signed in to change notification settings - Fork 9
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
chore: move update pr script to actual script with tests #1684
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b3f162d
chore: enhance tests yml
github-actions[bot] 41722c8
chore: some test tests
github-actions[bot] 5aec532
fix: tests
github-actions[bot] 8926fb4
fix: move tests to github dir
github-actions[bot] dafb734
fix: copilot review
github-actions[bot] fd7c8e9
fix: copilot review
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import {generateBundleSizeSection, getBundleInfo} from '../utils/bundle'; | ||
|
||
describe('bundle utils', () => { | ||
describe('generateBundleSizeSection', () => { | ||
it('should generate section for increased bundle size', () => { | ||
const bundleInfo = { | ||
currentSize: 1024 * 1024 * 2, // 2MB | ||
mainSize: 1024 * 1024, // 1MB | ||
diff: 1024 * 1024, // 1MB increase | ||
percent: '100', | ||
}; | ||
|
||
const result = generateBundleSizeSection(bundleInfo); | ||
expect(result).toContain('Bundle Size: πΊ'); | ||
expect(result).toContain('Current: 2.00 MB | Main: 1.00 MB'); | ||
expect(result).toContain('Diff: +1.00 MB (100%)'); | ||
expect(result).toContain('β οΈ Bundle size increased. Please review.'); | ||
}); | ||
|
||
it('should generate section for decreased bundle size', () => { | ||
const bundleInfo = { | ||
currentSize: 1024 * 1024, // 1MB | ||
mainSize: 1024 * 1024 * 2, // 2MB | ||
diff: -1024 * 1024, // 1MB decrease | ||
percent: '-50', | ||
}; | ||
|
||
const result = generateBundleSizeSection(bundleInfo); | ||
expect(result).toContain('Bundle Size: π½'); | ||
expect(result).toContain('Current: 1.00 MB | Main: 2.00 MB'); | ||
expect(result).toContain('Diff: 1.00 MB (-50%)'); | ||
expect(result).toContain('β Bundle size decreased.'); | ||
}); | ||
|
||
it('should generate section for unchanged bundle size', () => { | ||
const bundleInfo = { | ||
currentSize: 1024 * 1024, // 1MB | ||
mainSize: 1024 * 1024, // 1MB | ||
diff: 0, | ||
percent: '0', | ||
}; | ||
|
||
const result = generateBundleSizeSection(bundleInfo); | ||
expect(result).toContain('Bundle Size: β '); | ||
expect(result).toContain('Current: 1.00 MB | Main: 1.00 MB'); | ||
expect(result).toContain('Diff: 0.00 KB (0%)'); | ||
expect(result).toContain('β Bundle size unchanged.'); | ||
}); | ||
|
||
it('should handle N/A percent', () => { | ||
const bundleInfo = { | ||
currentSize: 1024 * 1024, // 1MB | ||
mainSize: 0, | ||
diff: 1024 * 1024, | ||
percent: 'N/A', | ||
}; | ||
|
||
const result = generateBundleSizeSection(bundleInfo); | ||
expect(result).toContain('Bundle Size: β οΈ'); | ||
expect(result).toContain('Current: 1.00 MB | Main: 0.00 KB'); | ||
expect(result).toContain('Diff: +1.00 MB (N/A)'); | ||
expect(result).toContain('β οΈ Unable to calculate change.'); | ||
}); | ||
}); | ||
|
||
describe('getBundleInfo', () => { | ||
const originalEnv = process.env; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
process.env = {...originalEnv}; | ||
}); | ||
|
||
afterAll(() => { | ||
process.env = originalEnv; | ||
}); | ||
|
||
it('should get bundle info from environment variables', () => { | ||
process.env.CURRENT_SIZE = '2097152'; // 2MB | ||
process.env.MAIN_SIZE = '1048576'; // 1MB | ||
process.env.SIZE_DIFF = '1048576'; // 1MB | ||
process.env.SIZE_PERCENT = '100'; | ||
|
||
const result = getBundleInfo(); | ||
expect(result).toEqual({ | ||
currentSize: 2097152, | ||
mainSize: 1048576, | ||
diff: 1048576, | ||
percent: '100', | ||
}); | ||
}); | ||
|
||
it('should handle missing environment variables', () => { | ||
process.env.CURRENT_SIZE = undefined; | ||
process.env.MAIN_SIZE = undefined; | ||
process.env.SIZE_DIFF = undefined; | ||
process.env.SIZE_PERCENT = undefined; | ||
|
||
const result = getBundleInfo(); | ||
expect(result).toEqual({ | ||
currentSize: 0, | ||
mainSize: 0, | ||
diff: 0, | ||
percent: 'N/A', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import {formatSize, generateTestChangesSummary} from '../utils/format'; | ||
|
||
describe('format utils', () => { | ||
describe('formatSize', () => { | ||
it('should format size in KB when less than 1024 bytes', () => { | ||
const size = 512; // 512 bytes | ||
expect(formatSize(size)).toBe('0.50 KB'); | ||
}); | ||
|
||
it('should format size in MB when greater than or equal to 1024 bytes', () => { | ||
const size = 2.5 * 1024; // 2.5 KB -> will be shown in MB | ||
expect(formatSize(size)).toBe('2.50 KB'); | ||
}); | ||
|
||
it('should handle small sizes', () => { | ||
const size = 100; // 100 bytes | ||
expect(formatSize(size)).toBe('0.10 KB'); | ||
}); | ||
|
||
it('should handle zero', () => { | ||
expect(formatSize(0)).toBe('0.00 KB'); | ||
}); | ||
}); | ||
|
||
describe('generateTestChangesSummary', () => { | ||
it('should generate summary for new tests only', () => { | ||
const comparison = { | ||
new: ['Test 1 (file1.ts)', 'Test 2 (file2.ts)'], | ||
skipped: [], | ||
deleted: [], | ||
}; | ||
|
||
const summary = generateTestChangesSummary(comparison); | ||
expect(summary).toContain('β¨ New Tests (2)'); | ||
expect(summary).toContain('1. Test 1 (file1.ts)'); | ||
expect(summary).toContain('2. Test 2 (file2.ts)'); | ||
expect(summary).not.toContain('βοΈ Skipped Tests'); | ||
expect(summary).not.toContain('ποΈ Deleted Tests'); | ||
}); | ||
|
||
it('should generate summary for skipped tests only', () => { | ||
const comparison = { | ||
new: [], | ||
skipped: ['Test 1 (file1.ts)', 'Test 2 (file2.ts)'], | ||
deleted: [], | ||
}; | ||
|
||
const summary = generateTestChangesSummary(comparison); | ||
expect(summary).toContain('βοΈ Skipped Tests (2)'); | ||
expect(summary).toContain('1. Test 1 (file1.ts)'); | ||
expect(summary).toContain('2. Test 2 (file2.ts)'); | ||
expect(summary).not.toContain('β¨ New Tests'); | ||
expect(summary).not.toContain('ποΈ Deleted Tests'); | ||
}); | ||
|
||
it('should generate summary for deleted tests only', () => { | ||
const comparison = { | ||
new: [], | ||
skipped: [], | ||
deleted: ['Test 1 (file1.ts)', 'Test 2 (file2.ts)'], | ||
}; | ||
|
||
const summary = generateTestChangesSummary(comparison); | ||
expect(summary).toContain('ποΈ Deleted Tests (2)'); | ||
expect(summary).toContain('1. Test 1 (file1.ts)'); | ||
expect(summary).toContain('2. Test 2 (file2.ts)'); | ||
expect(summary).not.toContain('β¨ New Tests'); | ||
expect(summary).not.toContain('βοΈ Skipped Tests'); | ||
}); | ||
|
||
it('should generate summary for all types of changes', () => { | ||
const comparison = { | ||
new: ['New Test (file1.ts)'], | ||
skipped: ['Skipped Test (file2.ts)'], | ||
deleted: ['Deleted Test (file3.ts)'], | ||
}; | ||
|
||
const summary = generateTestChangesSummary(comparison); | ||
expect(summary).toContain('β¨ New Tests (1)'); | ||
expect(summary).toContain('βοΈ Skipped Tests (1)'); | ||
expect(summary).toContain('ποΈ Deleted Tests (1)'); | ||
expect(summary).toContain('New Test (file1.ts)'); | ||
expect(summary).toContain('Skipped Test (file2.ts)'); | ||
expect(summary).toContain('Deleted Test (file3.ts)'); | ||
}); | ||
|
||
it('should handle no changes', () => { | ||
const comparison = { | ||
new: [], | ||
skipped: [], | ||
deleted: [], | ||
}; | ||
|
||
const summary = generateTestChangesSummary(comparison); | ||
expect(summary).toBe('π No changes in tests. π'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved script from yml to scripts