-
Notifications
You must be signed in to change notification settings - Fork 85
added test runner for typescript tests #1349
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
Draft
0xDEnYO
wants to merge
1
commit into
main
Choose a base branch
from
ts-testing-setup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/usr/bin/env bun | ||
|
|
||
| /** | ||
| * TypeScript Test Runner Script | ||
| * | ||
| * This script finds and runs all TypeScript test files in the script/ directory | ||
| * while excluding external library tests from lib/ and node_modules/ directories. | ||
| * | ||
| * Features: | ||
| * - Automatically discovers all .test.ts files in script/ directory | ||
| * - Excludes lib/ and node_modules/ directories to avoid running external tests | ||
| * - Uses Bun's built-in test runner with Jest-like syntax | ||
| * - Provides clear output showing which test files were found and executed | ||
| * | ||
| * Usage: | ||
| * - npm run test:ts (runs all TypeScript tests) | ||
| * - bun script/runTypescriptTests.ts (direct execution) | ||
| * | ||
| * Output: | ||
| * - Lists found test files | ||
| * - Runs each test file with Bun's test runner | ||
| * - Shows test results and summary | ||
| */ | ||
|
|
||
| import { execSync } from 'child_process' | ||
| import { readdirSync, statSync } from 'fs' | ||
| import { join } from 'path' | ||
|
Comment on lines
+25
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid shell quoting pitfalls; use spawnSync with args instead of execSync with a string. Prevents issues if paths contain spaces/quotes and removes reliance on a shell. -import { execSync } from 'child_process'
+import { spawnSync } from 'child_process'
@@
-// Run all test files together with a specific pattern
-const testFilePatterns = testFiles.map((file) => `"${file}"`).join(' ')
-console.log(`Running all tests with: bun test ${testFilePatterns}`)
-
-try {
- execSync(`bun test ${testFilePatterns}`, { stdio: 'inherit' })
-} catch (error) {
- console.error('Some tests failed')
- process.exit(1)
-}
+console.log('Running all tests with: bun test', testFiles.join(' '))
+const { status } = spawnSync('bun', ['test', ...testFiles], { stdio: 'inherit' })
+if (status !== 0) {
+ console.error('Some tests failed')
+ process.exit(status ?? 1)
+}Also applies to: 65-74 |
||
|
|
||
| function findTestFiles(dir: string): string[] { | ||
| const testFiles: string[] = [] | ||
|
|
||
| try { | ||
| const items = readdirSync(dir) | ||
|
|
||
| for (const item of items) { | ||
| const fullPath = join(dir, item) | ||
| const stat = statSync(fullPath) | ||
|
|
||
| if (stat.isDirectory()) { | ||
| // Skip lib/ and node_modules/ directories | ||
| if (item === 'lib' || item === 'node_modules') continue | ||
|
|
||
| testFiles.push(...findTestFiles(fullPath)) | ||
| } else if (item.endsWith('.test.ts')) testFiles.push(fullPath) | ||
| } | ||
| } catch (error) { | ||
| // Ignore errors for directories we can't access | ||
| } | ||
|
|
||
| return testFiles | ||
| } | ||
|
|
||
| const scriptDir = join(process.cwd(), 'script') | ||
| const testFiles = findTestFiles(scriptDir) | ||
|
|
||
| if (testFiles.length === 0) { | ||
| console.log('No TypeScript test files found in script/ directory') | ||
| process.exit(0) | ||
| } | ||
|
|
||
| console.log(`Found ${testFiles.length} test file(s):`) | ||
| testFiles.forEach((file) => console.log(` - ${file}`)) | ||
| console.log() | ||
|
|
||
| // Run all test files together with a specific pattern | ||
| const testFilePatterns = testFiles.map((file) => `"${file}"`).join(' ') | ||
| console.log(`Running all tests with: bun test ${testFilePatterns}`) | ||
|
|
||
| try { | ||
| execSync(`bun test ${testFilePatterns}`, { stdio: 'inherit' }) | ||
| } catch (error) { | ||
| console.error('Some tests failed') | ||
| process.exit(1) | ||
| } | ||
|
|
||
| console.log('\n✅ All TypeScript tests completed successfully!') | ||
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.
🛠️ Refactor suggestion
Execute this script with bunx tsx per repo convention.
Replace the Bun shebang and usage notes to match our standard.
Note: If env -S is unavailable in some environments, drop the shebang and rely on package.json’s script.
Also applies to: 16-18
🤖 Prompt for AI Agents