-
Notifications
You must be signed in to change notification settings - Fork 0
chore(ci): add Node.js v20 to CI #204
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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,25 @@ | ||
| #!/usr/bin/env node | ||
| import { globSync } from 'glob'; | ||
| import { execFileSync } from 'node:child_process'; | ||
|
|
||
| /** | ||
| * Test runner for Node.js v20 | ||
| * | ||
| * Node.js v20's `node --test` command doesn't support glob patterns. This | ||
| * script uses the `glob` package to find test files and passes them to `node | ||
| * --test`. | ||
| */ | ||
|
|
||
| const pattern = process.argv[2] || 'test/**/*.test.ts'; | ||
| const files = globSync(pattern); | ||
|
|
||
| if (files.length === 0) { | ||
| console.error(`No files matched pattern: ${pattern}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| execFileSync( | ||
| process.execPath, | ||
| ['--import', 'tsx', '--test', '--test-reporter=spec', ...files], | ||
| { stdio: 'inherit' }, | ||
| ); |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,99 +1,152 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { execSync } from 'node:child_process'; | ||
| import { execSync, spawnSync } from 'node:child_process'; | ||
| import { mkdtemp, rm, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { dirname, join } from 'node:path'; | ||
| import { describe, it } from 'node:test'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| import { isNode20 } from '../util.js'; | ||
| import { fixtures } from './fixture-paths.js'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
|
|
||
| // Node.js v20 doesn't allow --cpu-prof in NODE_OPTIONS for security reasons | ||
| // Tests are split into two groups: Node 20 tests and Node 22+ tests | ||
| const node20Test = isNode20 ? it : it.skip; | ||
| const node22PlusTest = isNode20 ? it.skip : it; | ||
|
|
||
| describe('Profile Command Integration', () => { | ||
| it('should profile a simple script and generate report', async () => { | ||
| const tmpDir = await mkdtemp(join(tmpdir(), 'modestbench-profile-')); | ||
|
|
||
| try { | ||
| // Create package.json | ||
| await writeFile( | ||
| join(tmpDir, 'package.json'), | ||
| JSON.stringify({ name: 'test-project' }), | ||
| ); | ||
|
|
||
| // Run profile command using fixture | ||
| const output = execSync( | ||
| `node ${join(__dirname, '../../dist/cli/index.js')} analyze "node ${fixtures.profileHotFunction}"`, | ||
| { | ||
| cwd: tmpDir, | ||
| encoding: 'utf-8', | ||
| }, | ||
| ); | ||
|
|
||
| // Verify output contains expected sections | ||
| assert.ok(output.includes('Profile Analysis'), 'Should contain header'); | ||
| assert.ok( | ||
| output.includes('Benchmark Candidates'), | ||
| 'Should contain candidates section', | ||
| ); | ||
| assert.ok( | ||
| output.includes('hotFunction') || output.includes('ticks'), | ||
| 'Should contain function data', | ||
| ); | ||
| } finally { | ||
| await rm(tmpDir, { force: true, recursive: true }); | ||
| } | ||
| }); | ||
| describe('on Node.js 20', () => { | ||
| node20Test( | ||
| 'should show helpful error when profiling is unavailable', | ||
| async () => { | ||
| const tmpDir = await mkdtemp(join(tmpdir(), 'modestbench-profile-')); | ||
|
|
||
| try { | ||
| await writeFile( | ||
| join(tmpDir, 'package.json'), | ||
| JSON.stringify({ name: 'test-project' }), | ||
| ); | ||
|
|
||
| // Use process.execPath to ensure we run with the same Node version | ||
| const result = spawnSync( | ||
| process.execPath, | ||
| [ | ||
| join(__dirname, '../../dist/cli/index.js'), | ||
| 'analyze', | ||
| `node ${fixtures.profileHotFunction}`, | ||
| ], | ||
| { | ||
| cwd: tmpDir, | ||
| encoding: 'utf-8', | ||
| }, | ||
| ); | ||
|
|
||
| it('should support --group-by-file option', async () => { | ||
| const tmpDir = await mkdtemp(join(tmpdir(), 'modestbench-profile-')); | ||
|
|
||
| try { | ||
| await writeFile( | ||
| join(tmpDir, 'package.json'), | ||
| JSON.stringify({ name: 'test-project' }), | ||
| ); | ||
|
|
||
| const output = execSync( | ||
| `node ${join(__dirname, '../../dist/cli/index.js')} analyze "node ${fixtures.profileMultiFunction}" --group-by-file`, | ||
| { | ||
| cwd: tmpDir, | ||
| encoding: 'utf-8', | ||
| }, | ||
| ); | ||
|
|
||
| assert.ok( | ||
| output.includes('Grouped by File'), | ||
| 'Should contain grouped by file header', | ||
| ); | ||
| } finally { | ||
| await rm(tmpDir, { force: true, recursive: true }); | ||
| } | ||
| assert.notEqual(result.status, 0, 'Should exit with non-zero code'); | ||
| assert.ok( | ||
| result.stderr.includes('Node.js 22 or later') || | ||
| result.stderr.includes('CPU profiling requires'), | ||
| 'Should show helpful error message about Node.js version', | ||
| ); | ||
| } finally { | ||
| await rm(tmpDir, { force: true, recursive: true }); | ||
| } | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| it('should respect --min-percent threshold', async () => { | ||
| const tmpDir = await mkdtemp(join(tmpdir(), 'modestbench-profile-')); | ||
|
|
||
| try { | ||
| await writeFile( | ||
| join(tmpDir, 'package.json'), | ||
| JSON.stringify({ name: 'test-project' }), | ||
| ); | ||
|
|
||
| // Run with high threshold - should filter out most functions | ||
| const output = execSync( | ||
| `node ${join(__dirname, '../../dist/cli/index.js')} analyze "node ${fixtures.profileHotFunction}" --min-percent 50`, | ||
| { | ||
| cwd: tmpDir, | ||
| encoding: 'utf-8', | ||
| }, | ||
| ); | ||
|
|
||
| // Should still have header but fewer functions | ||
| assert.ok(output.includes('Profile Analysis'), 'Should have header'); | ||
| } finally { | ||
| await rm(tmpDir, { force: true, recursive: true }); | ||
| } | ||
| describe('on Node.js 22+', () => { | ||
| node22PlusTest( | ||
| 'should profile a simple script and generate report', | ||
| async () => { | ||
| const tmpDir = await mkdtemp(join(tmpdir(), 'modestbench-profile-')); | ||
|
|
||
| try { | ||
| // Create package.json | ||
| await writeFile( | ||
| join(tmpDir, 'package.json'), | ||
| JSON.stringify({ name: 'test-project' }), | ||
| ); | ||
|
|
||
| // Run profile command using fixture | ||
| const output = execSync( | ||
| `node ${join(__dirname, '../../dist/cli/index.js')} analyze "node ${fixtures.profileHotFunction}"`, | ||
| { | ||
| cwd: tmpDir, | ||
| encoding: 'utf-8', | ||
| }, | ||
| ); | ||
|
|
||
| // Verify output contains expected sections | ||
| assert.ok( | ||
| output.includes('Profile Analysis'), | ||
| 'Should contain header', | ||
| ); | ||
| assert.ok( | ||
| output.includes('Benchmark Candidates'), | ||
| 'Should contain candidates section', | ||
| ); | ||
| assert.ok( | ||
| output.includes('hotFunction') || output.includes('ticks'), | ||
| 'Should contain function data', | ||
| ); | ||
| } finally { | ||
| await rm(tmpDir, { force: true, recursive: true }); | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| node22PlusTest('should support --group-by-file option', async () => { | ||
| const tmpDir = await mkdtemp(join(tmpdir(), 'modestbench-profile-')); | ||
|
|
||
| try { | ||
| await writeFile( | ||
| join(tmpDir, 'package.json'), | ||
| JSON.stringify({ name: 'test-project' }), | ||
| ); | ||
|
|
||
| const output = execSync( | ||
| `node ${join(__dirname, '../../dist/cli/index.js')} analyze "node ${fixtures.profileMultiFunction}" --group-by-file`, | ||
boneskull marked this conversation as resolved.
Dismissed
Show dismissed
Hide dismissed
|
||
| { | ||
| cwd: tmpDir, | ||
| encoding: 'utf-8', | ||
| }, | ||
| ); | ||
|
|
||
| assert.ok( | ||
| output.includes('Grouped by File'), | ||
| 'Should contain grouped by file header', | ||
| ); | ||
| } finally { | ||
| await rm(tmpDir, { force: true, recursive: true }); | ||
| } | ||
| }); | ||
|
|
||
| node22PlusTest('should respect --min-percent threshold', async () => { | ||
| const tmpDir = await mkdtemp(join(tmpdir(), 'modestbench-profile-')); | ||
|
|
||
| try { | ||
| await writeFile( | ||
| join(tmpDir, 'package.json'), | ||
| JSON.stringify({ name: 'test-project' }), | ||
| ); | ||
|
|
||
| // Run with high threshold - should filter out most functions | ||
| const output = execSync( | ||
| `node ${join(__dirname, '../../dist/cli/index.js')} analyze "node ${fixtures.profileHotFunction}" --min-percent 50`, | ||
boneskull marked this conversation as resolved.
Dismissed
Show dismissed
Hide dismissed
|
||
| { | ||
| cwd: tmpDir, | ||
| encoding: 'utf-8', | ||
| }, | ||
| ); | ||
|
|
||
| // Should still have header but fewer functions | ||
| assert.ok(output.includes('Profile Analysis'), 'Should have header'); | ||
| } finally { | ||
| await rm(tmpDir, { force: true, recursive: true }); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.