Skip to content

Commit 4dd4a4d

Browse files
committed
Refactor tests to use Bun's built-in test framework
1 parent 8765eee commit 4dd4a4d

File tree

3 files changed

+34
-40
lines changed

3 files changed

+34
-40
lines changed

bun.lockb

-28.9 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import { expect } from 'chai';
21
import fs from 'fs';
32
import path from 'path';
4-
import { fileURLToPath } from 'url';
53
import { execSync } from 'child_process';
6-
import { describe, beforeEach, afterEach, it } from 'mocha';
7-
8-
const __filename = fileURLToPath(import.meta.url);
9-
const __dirname = path.dirname(__filename);
4+
import { describe, beforeEach, afterEach, expect, test } from "bun:test";
105

116
describe('files-to-prompt.ts', () => {
127
const testDir = path.join(__dirname, 'test-data');
@@ -19,40 +14,40 @@ describe('files-to-prompt.ts', () => {
1914
fs.rmSync(testDir, { recursive: true, force: true });
2015
});
2116

22-
it('should include single file passed on the command line', () => {
17+
test('should include single file passed on the command line', () => {
2318
const filePath = path.join(testDir, 'file1.txt');
2419
fs.writeFileSync(filePath, 'File 1 contents');
2520

2621
const output = execSync(`bun ./files-to-prompt.ts ${filePath}`).toString();
27-
expect(output).to.include(filePath);
28-
expect(output).to.include('File 1 contents');
22+
expect(output).toContain(filePath);
23+
expect(output).toContain('File 1 contents');
2924
});
3025

31-
it('should include multiple files passed on the command line', () => {
26+
test('should include multiple files passed on the command line', () => {
3227
const file1Path = path.join(testDir, 'file1.txt');
3328
const file2Path = path.join(testDir, 'file2.txt');
3429
fs.writeFileSync(file1Path, 'File 1 contents');
3530
fs.writeFileSync(file2Path, 'File 2 contents');
3631

3732
const output = execSync(`bun ./files-to-prompt.ts ${file1Path} ${file2Path}`).toString();
38-
expect(output).to.include(file1Path);
39-
expect(output).to.include('File 1 contents');
40-
expect(output).to.include(file2Path);
41-
expect(output).to.include('File 2 contents');
33+
expect(output).toContain(file1Path);
34+
expect(output).toContain('File 1 contents');
35+
expect(output).toContain(file2Path);
36+
expect(output).toContain('File 2 contents');
4237
});
4338

44-
it('should include files in directories passed on the command line', () => {
39+
test('should include files in directories passed on the command line', () => {
4540
const dirPath = path.join(testDir, 'dir');
4641
fs.mkdirSync(dirPath);
4742
const filePath = path.join(dirPath, 'file.txt');
4843
fs.writeFileSync(filePath, 'File contents');
4944

5045
const output = execSync(`bun ./files-to-prompt.ts ${dirPath}`).toString();
51-
expect(output).to.include(filePath);
52-
expect(output).to.include('File contents');
46+
expect(output).toContain(filePath);
47+
expect(output).toContain('File contents');
5348
});
5449

55-
it('should include files a few levels deep in a directory structure', () => {
50+
test('should include files a few levels deep in a directory structure', () => {
5651
const dir1Path = path.join(testDir, 'dir1');
5752
const dir2Path = path.join(dir1Path, 'dir2');
5853
fs.mkdirSync(dir1Path);
@@ -61,34 +56,34 @@ describe('files-to-prompt.ts', () => {
6156
fs.writeFileSync(filePath, 'File contents');
6257

6358
const output = execSync(`bun ./files-to-prompt.ts ${testDir}`).toString();
64-
expect(output).to.include(filePath);
65-
expect(output).to.include('File contents');
59+
expect(output).toContain(filePath);
60+
expect(output).toContain('File contents');
6661
});
6762

68-
it('should exclude files matching patterns passed via --ignore', () => {
63+
test('should exclude files matching patterns passed via --ignore', () => {
6964
const file1Path = path.join(testDir, 'file1.txt');
7065
const file2Path = path.join(testDir, 'file2.txt');
7166
fs.writeFileSync(file1Path, 'File 1 contents');
7267
fs.writeFileSync(file2Path, 'File 2 contents');
7368

7469
const output = execSync(`bun ./files-to-prompt.ts ${testDir} --ignore "file1.txt"`).toString();
75-
expect(output).to.not.include(file1Path);
76-
expect(output).to.include(file2Path);
70+
expect(output).not.toContain(file1Path);
71+
expect(output).toContain(file2Path);
7772
});
7873

79-
it('should exclude files matching patterns in .gitignore', () => {
74+
test('should exclude files matching patterns in .gitignore', () => {
8075
const file1Path = path.join(testDir, 'file1.txt');
8176
const file2Path = path.join(testDir, 'file2.txt');
8277
fs.writeFileSync(file1Path, 'File 1 contents');
8378
fs.writeFileSync(file2Path, 'File 2 contents');
8479
fs.writeFileSync(path.join(testDir, '.gitignore'), 'file1.txt');
8580

8681
const output = execSync(`bun ./files-to-prompt.ts ${testDir}`).toString();
87-
expect(output).to.not.include(file1Path);
88-
expect(output).to.include(file2Path);
82+
expect(output).not.toContain(file1Path);
83+
expect(output).toContain(file2Path);
8984
});
9085

91-
it('should include hidden files and directories when --include-hidden is passed', () => {
86+
test('should include hidden files and directories when --include-hidden is passed', () => {
9287
const hiddenFilePath = path.join(testDir, '.hidden-file.txt');
9388
const hiddenDirPath = path.join(testDir, '.hidden-dir');
9489
const hiddenDirFilePath = path.join(hiddenDirPath, 'file.txt');
@@ -97,19 +92,19 @@ describe('files-to-prompt.ts', () => {
9792
fs.writeFileSync(hiddenDirFilePath, 'Hidden dir file contents');
9893

9994
const output = execSync(`bun ./files-to-prompt.ts ${testDir} --include-hidden`).toString();
100-
expect(output).to.include(hiddenFilePath);
101-
expect(output).to.include('Hidden file contents');
102-
expect(output).to.include(hiddenDirFilePath);
103-
expect(output).to.include('Hidden dir file contents');
95+
expect(output).toContain(hiddenFilePath);
96+
expect(output).toContain('Hidden file contents');
97+
expect(output).toContain(hiddenDirFilePath);
98+
expect(output).toContain('Hidden dir file contents');
10499
});
105100

106-
it('should ignore .gitignore files when --ignore-gitignore is passed', () => {
101+
test('should ignore .gitignore files when --ignore-gitignore is passed', () => {
107102
const file1Path = path.join(testDir, 'file1.txt');
108103
fs.writeFileSync(file1Path, 'File 1 contents');
109104
fs.writeFileSync(path.join(testDir, '.gitignore'), 'file1.txt');
110105

111106
const output = execSync(`bun ./files-to-prompt.ts ${testDir} --ignore-gitignore`).toString();
112-
expect(output).to.include(file1Path);
113-
expect(output).to.include('File 1 contents');
107+
expect(output).toContain(file1Path);
108+
expect(output).toContain('File 1 contents');
114109
});
115110
});

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
"name": "files-to-prompt-ts",
33
"module": "files-to-prompt.ts",
44
"devDependencies": {
5-
"@types/bun": "latest",
6-
"@types/chai": "^4.3.14",
7-
"@types/mocha": "^10.0.6",
8-
"chai": "^5.1.0",
9-
"mocha": "^10.4.0"
5+
"@types/bun": "latest"
106
},
117
"peerDependencies": {
128
"typescript": "^5.0.0"
139
},
1410
"type": "module",
1511
"dependencies": {
1612
"commander": "^12.0.0"
17-
}
13+
},
14+
"scripts": {
15+
"test": "bun test ./files-to-prompt.test.ts"
16+
}
1817
}

0 commit comments

Comments
 (0)