Skip to content

Commit 9f695e5

Browse files
committed
✅ Migrate 257 spec files from Jasmine to Vitest API
1 parent 2ab9846 commit 9f695e5

265 files changed

Lines changed: 4159 additions & 3631 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ yarn build:apps
2222
yarn test:unit
2323

2424
# Run specific test file
25-
yarn test:unit --spec packages/core/src/path/to/feature.spec.ts
25+
yarn vitest run packages/core/src/path/to/feature.spec.ts
2626

2727
# Run tests on a specific seed
28-
yarn test:unit --seed 123
28+
yarn vitest run --sequence.seed 123
2929

3030
# setup E2E tests (installs Playwright and builds test apps)
3131
yarn test:e2e:init
@@ -66,7 +66,7 @@ test/
6666
├── apps/ # Test apps for E2E and performance testing
6767
├── e2e/ # Playwright E2E test scenarios
6868
├── performance/ # Performance benchmarking tests
69-
└── unit/ # Karma/Jasmine unit test configuration
69+
└── unit/ # Vitest unit test configuration
7070
7171
scripts/ # Build, deploy, release automation
7272
```
@@ -86,9 +86,9 @@ For deeper context, see:
8686

8787
### Unit Tests
8888

89-
- Test framework: Jasmine + Karma. Spec files co-located with implementation: `feature.ts``feature.spec.ts`
90-
- Focus tests with `fit()` / `fdescribe()`, skip with `xit()` / `xdescribe()`
89+
- Spec files co-located with implementation: `feature.ts``feature.spec.ts`
9190
- Use `registerCleanupTask()` for cleanup, NOT `afterEach()`
91+
- Test framework: Vitest (browser mode with Playwright)
9292
- Mock values/functions: wrap with `mockable()` in source, use `replaceMockable()` or `replaceMockableWithSpy()` in tests (auto-cleanup)
9393

9494
### Naming Conventions

developer-extension/src/panel/components/tabs/eventsTab/computeFacetState.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it } from 'vitest'
12
import type { RumActionEvent, RumResourceEvent } from '@datadog/browser-rum'
23
import { FacetRegistry } from '../../../hooks/useEvents'
34
import type { FacetValuesFilter } from '../../../hooks/useEvents'

developer-extension/src/panel/components/tabs/eventsTab/copyEvent.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it } from 'vitest'
12
import type { TelemetryEvent } from '../../../../../../packages/core/src/domain/telemetry'
23
import type { LogsEvent } from '../../../../../../packages/logs/src/logsEvent.types'
34
import type { RumEvent } from '../../../../../../packages/rum-core/src/rumEvent.types'

developer-extension/src/panel/flushEvents.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import { vi, beforeEach, describe, expect, it, type Mock } from 'vitest'
12
import type { Configuration } from '@datadog/browser-core'
23
import { registerCleanupTask } from '../../../packages/core/test'
34
import type { PageMayExitEvent } from '../../../packages/core/src/browser/pageMayExitObservable'
45
import { createPageMayExitObservable } from '../../../packages/core/src/browser/pageMayExitObservable'
56
import { flushScript } from './flushEvents'
67

78
describe('flushEvents', () => {
8-
let onExitSpy: jasmine.Spy<(event: PageMayExitEvent) => void>
9+
let onExitSpy: Mock<(event: PageMayExitEvent) => void>
910
let configuration: Configuration
1011

1112
beforeEach(() => {
12-
onExitSpy = jasmine.createSpy()
13+
onExitSpy = vi.fn()
1314
configuration = {} as Configuration
1415
registerCleanupTask(createPageMayExitObservable(configuration).subscribe(onExitSpy).unsubscribe)
1516
})

developer-extension/src/panel/hooks/useEvents/eventFilters.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it } from 'vitest'
12
import type { RumEvent } from '../../../../../packages/rum-core/src/rumEvent.types'
23
import type { LogsEvent } from '../../../../../packages/logs/src/logsEvent.types'
34
import { isSafari } from '../../../../../packages/core/src/tools/utils/browserDetection'

developer-extension/src/panel/hooks/useEvents/facetRegistry.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { beforeEach, describe, expect, it } from 'vitest'
12
import { isChromium } from '../../../../../packages/core/src/tools/utils/browserDetection'
23
import { getAllFields } from './facetRegistry'
34

45
describe('getAllFields', () => {
5-
beforeEach(() => {
6+
beforeEach((ctx) => {
67
if (!isChromium()) {
7-
pending('Extension only supported in chromium')
8+
ctx.skip()
9+
return
810
}
911
})
1012

packages/core/src/boot/displayAlreadyInitializedError.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
import { vi, describe, expect, it } from 'vitest'
12
import type { InitConfiguration } from '../domain/configuration'
23
import { display } from '../tools/display'
34
import { displayAlreadyInitializedError } from './displayAlreadyInitializedError'
45

56
describe('displayAlreadyInitializedError', () => {
67
it('should display an error', () => {
7-
const displayErrorSpy = spyOn(display, 'error')
8+
const displayErrorSpy = vi.spyOn(display, 'error')
89
displayAlreadyInitializedError('DD_RUM', {} as InitConfiguration)
910
expect(displayErrorSpy).toHaveBeenCalledTimes(1)
1011
expect(displayErrorSpy).toHaveBeenCalledWith('DD_RUM is already initialized.')
1112
})
1213

1314
it('should not display an error if the "silentMultipleInit" option is used', () => {
14-
const displayErrorSpy = spyOn(display, 'error')
15+
const displayErrorSpy = vi.spyOn(display, 'error')
1516
displayAlreadyInitializedError('DD_RUM', { silentMultipleInit: true } as InitConfiguration)
1617
expect(displayErrorSpy).not.toHaveBeenCalled()
1718
})

packages/core/src/boot/init.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi, describe, expect, it } from 'vitest'
12
import { display } from '../tools/display'
23
import { defineGlobal } from './init'
34

@@ -17,8 +18,8 @@ describe('defineGlobal', () => {
1718
})
1819

1920
it('run the queued callbacks on the old value', () => {
20-
const fn1 = jasmine.createSpy()
21-
const fn2 = jasmine.createSpy()
21+
const fn1 = vi.fn()
22+
const fn2 = vi.fn()
2223
const myGlobal: any = {
2324
foo: {
2425
q: [fn1, fn2],
@@ -42,7 +43,7 @@ describe('defineGlobal', () => {
4243
q: [onReady],
4344
},
4445
}
45-
const displaySpy = spyOn(display, 'error')
46+
const displaySpy = vi.spyOn(display, 'error')
4647

4748
defineGlobal(myGlobal, 'foo', {})
4849
expect(displaySpy).toHaveBeenCalledWith('onReady callback threw an error:', myError)

packages/core/src/browser/addEventListener.spec.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi, beforeEach, describe, expect, it } from 'vitest'
12
import type { Configuration } from '../domain/configuration'
23
import { createNewEvent, mockZoneJs, registerCleanupTask } from '../../test'
34
import type { MockZoneJs } from '../../test'
@@ -16,7 +17,7 @@ describe('addEventListener', () => {
1617
})
1718

1819
it('uses the original addEventListener method instead of the method patched by Zone.js', () => {
19-
const zoneJsPatchedAddEventListener = jasmine.createSpy()
20+
const zoneJsPatchedAddEventListener = vi.fn()
2021
const eventTarget = document.createElement('div')
2122
zoneJs.replaceProperty(eventTarget, 'addEventListener', zoneJsPatchedAddEventListener)
2223

@@ -25,7 +26,7 @@ describe('addEventListener', () => {
2526
})
2627

2728
it('uses the original removeEventListener method instead of the method patched by Zone.js', () => {
28-
const zoneJsPatchedRemoveEventListener = jasmine.createSpy()
29+
const zoneJsPatchedRemoveEventListener = vi.fn()
2930
const eventTarget = document.createElement('div')
3031
zoneJs.replaceProperty(eventTarget, 'removeEventListener', zoneJsPatchedRemoveEventListener)
3132

@@ -41,17 +42,17 @@ describe('addEventListener', () => {
4142
// eslint-disable-next-line @typescript-eslint/unbound-method
4243
const originalRemoveEventListener = EventTarget.prototype.removeEventListener
4344

44-
EventTarget.prototype.addEventListener = jasmine.createSpy()
45-
EventTarget.prototype.removeEventListener = jasmine.createSpy()
45+
EventTarget.prototype.addEventListener = vi.fn()
46+
EventTarget.prototype.removeEventListener = vi.fn()
4647

4748
registerCleanupTask(() => {
4849
EventTarget.prototype.addEventListener = originalAddEventListener
4950
EventTarget.prototype.removeEventListener = originalRemoveEventListener
5051
})
5152

5253
const htmlDivElement = document.createElement('div')
53-
htmlDivElement.addEventListener = jasmine.createSpy()
54-
htmlDivElement.removeEventListener = jasmine.createSpy()
54+
htmlDivElement.addEventListener = vi.fn()
55+
htmlDivElement.removeEventListener = vi.fn()
5556

5657
const { stop } = addEventListener({ allowUntrustedEvents: false }, htmlDivElement, DOM_EVENT.CLICK, noop)
5758

@@ -71,11 +72,11 @@ describe('addEventListener', () => {
7172
})
7273

7374
it('Use the addEventListener method when the eventTarget is not an instance of EventTarget', () => {
74-
const listener = jasmine.createSpy()
75+
const listener = vi.fn()
7576

7677
const customEventTarget = {
77-
addEventListener: jasmine.createSpy(),
78-
removeEventListener: jasmine.createSpy(),
78+
addEventListener: vi.fn(),
79+
removeEventListener: vi.fn(),
7980
} as unknown as HTMLElement
8081

8182
const { stop } = addEventListener({ allowUntrustedEvents: false }, customEventTarget, 'change', listener)
@@ -93,7 +94,7 @@ describe('addEventListener', () => {
9394
})
9495

9596
it('should be ignored if __ddIsTrusted is absent', () => {
96-
const listener = jasmine.createSpy()
97+
const listener = vi.fn()
9798
const eventTarget = document.createElement('div')
9899
addEventListener(configuration, eventTarget, DOM_EVENT.CLICK, listener)
99100

@@ -103,7 +104,7 @@ describe('addEventListener', () => {
103104
})
104105

105106
it('should be ignored if __ddIsTrusted is false', () => {
106-
const listener = jasmine.createSpy()
107+
const listener = vi.fn()
107108
const eventTarget = document.createElement('div')
108109
addEventListener(configuration, eventTarget, DOM_EVENT.CLICK, listener)
109110

@@ -113,7 +114,7 @@ describe('addEventListener', () => {
113114
})
114115

115116
it('should not be ignored if __ddIsTrusted is true', () => {
116-
const listener = jasmine.createSpy()
117+
const listener = vi.fn()
117118
const eventTarget = document.createElement('div')
118119
addEventListener(configuration, eventTarget, DOM_EVENT.CLICK, listener)
119120

@@ -124,7 +125,7 @@ describe('addEventListener', () => {
124125
})
125126

126127
it('should not be ignored if allowUntrustedEvents is true', () => {
127-
const listener = jasmine.createSpy()
128+
const listener = vi.fn()
128129
const eventTarget = document.createElement('div')
129130
configuration = { allowUntrustedEvents: true } as Configuration
130131

packages/core/src/browser/cookie.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it } from 'vitest'
12
import { mockCookies } from '../../test'
23
import { getCurrentSite } from './cookie'
34

0 commit comments

Comments
 (0)