Skip to content

Commit 6c51bca

Browse files
committed
✅ add a Jasmine to Vitest codemod and a migration guard
Groundwork to migrate specs from the Jasmine API to the Vitest API in small PRs, without blocking other work (unmigrated specs keep running through the Jasmine compatibility shim). - scripts/test/jasmine-to-vitest.ts: deterministic codemod (TypeScript AST, in-place text edits, Prettier) converting spies, spy strategies, calls, matchers, asymmetric matchers, done callbacks, pending(), fail(), focus/ skip and types; constructs it can't convert safely are reported. On a conflict, take the file from main and re-run it. - eslint.config.ts: VITEST_API_SPEC_FILES, where Jasmine globals are forbidden and test functions must be imported from 'vitest' - vitest declared as a devDependency of every workspace with specs - AGENTS.md: write new specs with the Vitest API - remove the unused mockContextManager helper
1 parent e6dae91 commit 6c51bca

22 files changed

Lines changed: 1083 additions & 19 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ For deeper context, see:
102102

103103
- Test framework: Jasmine API on Vitest Browser Mode (via a shim in `test/unit-vitest/`). Spec files co-located with implementation: `feature.ts` → `feature.spec.ts`
104104
- Focus tests with `fit()` / `fdescribe()`, skip with `xit()` / `xdescribe()`
105+
- Specs are being migrated from the Jasmine API to the Vitest API. Write new specs with the Vitest API (`import { describe, expect, it, vi } from 'vitest'`), unless they depend on a test helper that still returns Jasmine spies. Convert existing specs with `node scripts/test/jasmine-to-vitest.ts <files or directories>`, fix what it reports, then add the paths to `VITEST_API_SPEC_FILES` in `eslint.config.ts`
105106
- Use `registerCleanupTask()` for cleanup, NOT `afterEach()`
106107
- Prefer `collectAsyncCalls(spy, n)` over `waitFor(() => spy.calls.count() > 0)` for waiting on spy calls
107108
- Don't destructure methods from `spy.calls` (e.g., `argsFor`, `mostRecent`) - use `calls.argsFor()` to avoid `@typescript-eslint/unbound-method` errors

‎developer-extension/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"@types/react-dom": "19.3.0",
1313
"@wxt-dev/module-react": "1.2.2",
1414
"typescript": "6.0.3",
15-
"vite": "8.3.2"
15+
"vite": "8.3.2",
16+
"vitest": "4.1.8"
1617
},
1718
"dependencies": {
1819
"@datadog/browser-core": "workspace:*",

‎eslint.config.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import eslint from '@eslint/js'
22
import { defineConfig } from 'eslint/config'
3+
import type { Linter } from 'eslint'
34
import * as tseslint from 'typescript-eslint'
45
import { importX } from 'eslint-plugin-import-x'
56
import unicornPlugin from 'eslint-plugin-unicorn'
@@ -12,6 +13,28 @@ import eslintLocalRules from './eslint-local-rules/index.ts'
1213
import { SCHEMAS } from './scripts/lib/generatedSchemaTypes.ts'
1314

1415
const SPEC_FILES = '**/*.{spec,specHelper}.{ts,tsx,js}'
16+
// Spec files migrated from the Jasmine API to the Vitest API (see scripts/test/jasmine-to-vitest.ts).
17+
// Add the migrated paths here so the Jasmine API doesn't come back.
18+
const VITEST_API_SPEC_FILES: string[] = []
19+
const JASMINE_GLOBALS = [
20+
'jasmine',
21+
'spyOn',
22+
'spyOnProperty',
23+
'fail',
24+
'pending',
25+
'expectAsync',
26+
'fdescribe',
27+
'fit',
28+
'xdescribe',
29+
'xit',
30+
]
31+
// Provided as globals by the Jasmine compatibility shim: migrated files import them from 'vitest'
32+
const SHIM_TEST_GLOBALS = ['describe', 'it', 'expect', 'beforeEach', 'afterEach', 'beforeAll', 'afterAll']
33+
const NO_JASMINE_GLOBALS_RULE: Linter.RuleEntry = [
34+
'error',
35+
...JASMINE_GLOBALS.map((name) => ({ name, message: 'Use the Vitest API instead of the Jasmine API.' })),
36+
...SHIM_TEST_GLOBALS.map((name) => ({ name, message: `Import \`${name}\` from 'vitest'.` })),
37+
]
1538
const PUBLIC_PACKAGE_ENTRIES = 'packages/{browser-rum,browser-logs,browser-rum-slim}/src/entries/*.ts'
1639
const MONITOR_UNTIL_COMMENT_EXPIRED_LEVEL =
1740
(process.env.MONITOR_UNTIL_COMMENT_EXPIRED_LEVEL as 'warn' | 'error' | undefined) || 'warn'
@@ -524,5 +547,16 @@ export default defineConfig(
524547
},
525548
],
526549
},
527-
}
550+
},
551+
552+
...(VITEST_API_SPEC_FILES.length
553+
? [
554+
{
555+
files: VITEST_API_SPEC_FILES,
556+
rules: {
557+
'no-restricted-globals': NO_JASMINE_GLOBALS_RULE,
558+
},
559+
},
560+
]
561+
: [])
528562
)

‎packages/browser-core/test/mockGlobalContext.ts‎

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

‎packages/browser-debugger/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"prepack": "yarn build"
2020
},
2121
"devDependencies": {
22-
"acorn": "8.19.0"
22+
"acorn": "8.19.0",
23+
"vitest": "4.1.8"
2324
},
2425
"dependencies": {
2526
"@datadog/browser-core": "workspace:*",

‎packages/browser-logs/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@
4040
},
4141
"publishConfig": {
4242
"access": "public"
43+
},
44+
"devDependencies": {
45+
"vitest": "4.1.8"
4346
}
4447
}

‎packages/browser-plugin-wasm/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@
4646
},
4747
"publishConfig": {
4848
"access": "public"
49+
},
50+
"devDependencies": {
51+
"vitest": "4.1.8"
4952
}
5053
}

‎packages/browser-rum-angular/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@angular/core": "22.2.1",
4444
"@angular/platform-browser": "22.2.1",
4545
"@angular/router": "22.2.1",
46-
"rxjs": "7.8.2"
46+
"rxjs": "7.8.2",
47+
"vitest": "4.1.8"
4748
}
4849
}

‎packages/browser-rum-core/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"@datadog/js-core": "workspace:*"
2222
},
2323
"devDependencies": {
24-
"ajv": "8.20.0"
24+
"ajv": "8.20.0",
25+
"vitest": "4.1.8"
2526
},
2627
"repository": {
2728
"type": "git",

‎packages/browser-rum-nextjs/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@types/react": "19.3.0",
4747
"next": "16.3.8",
4848
"react": "19.3.0",
49-
"react-dom": "19.3.0"
49+
"react-dom": "19.3.0",
50+
"vitest": "4.1.8"
5051
}
5152
}

0 commit comments

Comments
 (0)