Skip to content

Commit e068471

Browse files
committed
test: improve mock cleanup in evaluator and runner tests
- Move mock.restore() from beforeEach to afterAll in evaluator.unit.test.ts - Move mock.restore() from beforeEach to afterAll in runner.unit.test.ts - Add cleanup comments for clarity - Update Bun package manager from 1.1.0 to 1.3.0 in package.json 🤖 Generated with Claude via commitment
1 parent c09977a commit e068471

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
],
4242
"license": "ISC",
4343
"name": "@arittr/commitment",
44-
"packageManager": "bun@1.1.0",
44+
"packageManager": "bun@1.3.0",
4545
"scripts": {
4646
"build": "bun run build.ts",
4747
"check-types": "bun tsc --noEmit",

src/eval/__tests__/evaluator.unit.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, mock, spyOn } from 'bun:test';
1+
import { afterAll, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test';
22
/**
33
* Unit tests for Evaluator module
44
*
@@ -31,17 +31,18 @@ describe('Evaluator', () => {
3131
let mockChatGptAgent: ChatGPTAgent;
3232

3333
beforeEach(() => {
34-
// Reset mocks
35-
mock.restore();
36-
3734
// Create evaluator instance
3835
evaluator = new Evaluator();
3936

4037
// Get mocked ChatGPT agent instance
41-
4238
mockChatGptAgent = (evaluator as unknown as { agent: ChatGPTAgent }).agent;
4339
});
4440

41+
afterAll(() => {
42+
// Clean up module mocks after this test suite
43+
mock.restore();
44+
});
45+
4546
describe('evaluate', () => {
4647
it('should call ChatGPT agent with correct parameters', async () => {
4748
// Arrange

src/eval/__tests__/runner.unit.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, mock, spyOn } from 'bun:test';
1+
import { afterAll, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test';
22
/**
33
* Unit tests for EvalRunner module
44
*
@@ -63,10 +63,14 @@ describe('EvalRunner', () => {
6363
let runner: EvalRunner;
6464

6565
beforeEach(() => {
66-
mock.restore();
6766
runner = new EvalRunner();
6867
});
6968

69+
afterAll(() => {
70+
// Clean up module mocks after this test suite
71+
mock.restore();
72+
});
73+
7074
describe('loadFixture', () => {
7175
it('should load mocked fixture with all required fields', async () => {
7276
// Arrange

0 commit comments

Comments
 (0)