Skip to content

Commit c911168

Browse files
committed
feat: migrate to vitest
1 parent 54286cd commit c911168

7 files changed

Lines changed: 991 additions & 129 deletions

File tree

packages/cli/jest.config.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/cli/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"typecheck": "tsc --noEmit",
2525
"build": "tsc -p tsconfig.json",
2626
"dev": "tsc -p tsconfig.json --watch",
27-
"test": "jest"
27+
"test": "vitest run"
2828
},
2929
"keywords": [
3030
"react-native-brownfield",
@@ -71,14 +71,13 @@
7171
"@react-native/eslint-config": "0.82.1",
7272
"@types/babel__core": "^7",
7373
"@types/babel__preset-env": "^7",
74-
"@types/jest": "^30.0.0",
7574
"@types/lodash.clonedeep": "^4.5.9",
7675
"@types/node": "^25.0.3",
76+
"@vitest/coverage-v8": "^4.0.17",
7777
"eslint": "^8.57.1",
78-
"jest": "^29.7.0",
7978
"nodemon": "^3.1.11",
80-
"ts-jest": "^29.4.6",
81-
"typescript": "5.8.3"
79+
"typescript": "5.8.3",
80+
"vitest": "^4.0.17"
8281
},
8382
"engines": {
8483
"node": ">=20"

packages/cli/src/brownie/__tests__/commands/codegen.test.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
import fs from 'fs';
22
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
import { describe, it, expect, beforeEach, afterEach, vi, Mock } from 'vitest';
35
import { runCodegen } from '../../commands/codegen.js';
46
import * as swiftGenerator from '../../generators/swift.js';
57
import * as kotlinGenerator from '../../generators/kotlin.js';
68
import * as storeDiscovery from '../../store-discovery.js';
9+
import * as rockTools from '@rock-js/tools';
710

11+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
812
const FIXTURES_DIR = path.join(__dirname, '../../__fixtures__');
913

10-
jest.mock('../../generators/swift');
11-
jest.mock('../../generators/kotlin');
12-
jest.mock('../../store-discovery');
13-
14-
const mockGenerateSwift = swiftGenerator.generateSwift as jest.Mock;
15-
const mockGenerateKotlin = kotlinGenerator.generateKotlin as jest.Mock;
16-
const mockDiscoverStores = storeDiscovery.discoverStores as jest.Mock;
17-
const mockCwd = jest.spyOn(process, 'cwd');
18-
const mockConsoleError = jest.spyOn(console, 'error').mockImplementation();
19-
jest.spyOn(console, 'warn').mockImplementation();
20-
jest.spyOn(process, 'exit').mockImplementation((code) => {
14+
vi.mock('../../generators/swift');
15+
vi.mock('../../generators/kotlin');
16+
vi.mock('../../store-discovery');
17+
vi.mock('@rock-js/tools', async (importOriginal) => {
18+
const actual = await importOriginal<typeof rockTools>();
19+
return {
20+
...actual,
21+
logger: {
22+
...actual.logger,
23+
error: vi.fn(),
24+
warn: vi.fn(),
25+
info: vi.fn(),
26+
success: vi.fn(),
27+
},
28+
};
29+
});
30+
31+
const mockGenerateSwift = swiftGenerator.generateSwift as Mock;
32+
const mockGenerateKotlin = kotlinGenerator.generateKotlin as Mock;
33+
const mockDiscoverStores = storeDiscovery.discoverStores as Mock;
34+
const mockCwd = vi.spyOn(process, 'cwd');
35+
const mockLoggerError = rockTools.logger.error as Mock;
36+
vi.spyOn(process, 'exit').mockImplementation((code) => {
2137
throw new Error(`process.exit(${code})`);
2238
});
2339

@@ -48,7 +64,7 @@ describe('runCodegen', () => {
4864
cleanupTempDir(tempDir);
4965
tempDir = null;
5066
}
51-
jest.clearAllMocks();
67+
vi.clearAllMocks();
5268
});
5369

5470
it('generates swift files for discovered store', async () => {
@@ -166,7 +182,7 @@ describe('runCodegen', () => {
166182
await expect(runCodegen({ platform: 'invalid' })).rejects.toThrow(
167183
'process.exit(1)'
168184
);
169-
expect(mockConsoleError).toHaveBeenCalled();
185+
expect(mockLoggerError).toHaveBeenCalled();
170186
});
171187

172188
it('exits with error when generator fails', async () => {
@@ -179,7 +195,7 @@ describe('runCodegen', () => {
179195
mockGenerateSwift.mockRejectedValue(new Error('Generation failed'));
180196

181197
await expect(runCodegen({})).rejects.toThrow('process.exit(1)');
182-
expect(mockConsoleError).toHaveBeenCalled();
198+
expect(mockLoggerError).toHaveBeenCalled();
183199
});
184200

185201
it('warns when store has no output paths for selected platform', async () => {

packages/cli/src/brownie/__tests__/config.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import { describe, it, expect, afterEach, vi } from 'vitest';
35

46
import { loadConfig } from '../config.js';
57

8+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
69
const FIXTURES_DIR = path.join(__dirname, '../__fixtures__');
710

8-
const mockCwd = jest.spyOn(process, 'cwd');
11+
const mockCwd = vi.spyOn(process, 'cwd');
912

1013
function createTempPackageJson(config: object): string {
1114
const tempDir = fs.mkdtempSync(path.join(FIXTURES_DIR, 'temp-'));

packages/cli/src/brownie/__tests__/store-discovery.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import fs from 'fs';
22
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
import { describe, it, expect, afterEach } from 'vitest';
35
import { discoverStores } from '../store-discovery.js';
46

7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
58
const FIXTURES_DIR = path.join(__dirname, '../__fixtures__');
69

710
function createTempDir(): string {

packages/cli/vitest.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
watch: false,
6+
globals: true,
7+
environment: 'node',
8+
include: ['src/**/*.{test,spec}.{js,ts}'],
9+
clearMocks: true,
10+
},
11+
});

0 commit comments

Comments
 (0)