Skip to content

Commit 0555de5

Browse files
committed
test: run against the ts files
1 parent 0ea4dd2 commit 0555de5

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ const config = {
1212
},
1313
extensionsToTreatAsEsm: ['.ts'],
1414
testMatch: ['**/__tests__/**/*.test.ts'],
15+
// Add direct testing of TypeScript files
16+
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
17+
collectCoverageFrom: [
18+
'src/**/*.ts',
19+
'!src/**/*.d.ts',
20+
'!src/**/*.test.ts',
21+
'!__tests__/**.ts'
22+
],
1523
};
1624

1725
export default config;

src/__tests__/cli.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,34 @@ import { dirname, join } from 'path'
55
import { readFileSync } from 'fs'
66
import { fileURLToPath } from 'url'
77

8+
const __filename = fileURLToPath(import.meta.url)
9+
const __dirname = dirname(__filename)
10+
811
// Get package.json data using a function to avoid top-level await
912
function getPackageJson () {
10-
const __filename = fileURLToPath(import.meta.url)
11-
const __dirname = dirname(__filename)
1213
return JSON.parse(readFileSync(join(__dirname, '../../package.json'), 'utf8'))
1314
}
1415

1516
const pkg = getPackageJson()
1617

18+
// Helper function to run the CLI using tsx (TypeScript executor)
19+
function runCLI (args = '') {
20+
return execSync(`tsx ${join(__dirname, '../index.ts')} ${args}`, { encoding: 'utf8' })
21+
}
22+
1723
describe('CLI', () => {
1824
test('version command should display correct version information', () => {
19-
// Run the CLI with the version command
20-
const output = execSync('node dist/index.js version', { encoding: 'utf8' })
25+
// Run the CLI with the version command directly from TypeScript source
26+
const output = runCLI('version')
2127

2228
// Verify the output contains version information and package details
2329
expect(output).toContain(pkg.name)
2430
expect(output).toContain(pkg.version)
2531
})
2632

2733
test('CLI should show help when no arguments are provided', () => {
28-
// Run the CLI without any arguments
29-
const output = execSync('node dist/index.js', { encoding: 'utf8' })
34+
// Run the CLI without any arguments directly from TypeScript source
35+
const output = runCLI('')
3036

3137
// Verify the output contains help information
3238
expect(output).toContain('Usage:')

0 commit comments

Comments
 (0)