Skip to content

Commit 3f3a853

Browse files
committed
πŸ› Fix bs-wrapper masking test failures, skip CookieStore tests
bs-wrapper.ts: ANSI escape codes from FORCE_COLOR broke failure detection β€” the regex /\d+ failed \|/ didn't match colored output like '9 failed\x1b[39m |'. Strip ANSI before matching. cookieAccess.spec.ts: CookieStore API tests crashed with TypeError when globalObject.cookieStore was undefined (Jasmine's pending() inside setup() skipped the enclosing it(), but Vitest doesn't). Added beforeEach ctx.skip for the CookieStore describe block.
1 parent 5c2b96c commit 3f3a853

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

β€Žpackages/browser-core/src/browser/cookieAccess.spec.tsβ€Ž

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { vi, describe, expect, it, type Mock } from 'vitest'
1+
import { vi, beforeEach, describe, expect, it, type Mock } from 'vitest'
22
import { ONE_MINUTE, dateNow } from '@datadog/js-core/time'
33
import { globalObject } from '@datadog/js-core/util'
44
import type { Clock } from '../../test'
@@ -114,6 +114,14 @@ describe('cookieAccess', () => {
114114

115115
for (const { title, setup } of setups) {
116116
describe(title, () => {
117+
beforeEach((ctx) => {
118+
// Skip CookieStore API tests when the API is not available
119+
// (Jasmine's pending() inside setup() threw and skipped the enclosing it())
120+
if (title === 'CookieStore API' && !globalObject.cookieStore) {
121+
ctx.skip(true, 'CookieStore API not available')
122+
}
123+
})
124+
117125
describe('getAllAndSet', () => {
118126
it('should pass current cookie values to callback', async () => {
119127
const { createCookieAccess, setCookieWithCleanup } = setup()

β€Žscripts/test/bs-wrapper.tsβ€Ž

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ function runTests(): Promise<boolean> {
113113
let output = ''
114114
let timeoutId: NodeJS.Timeout
115115
let testsCompleted = false
116-
let hasFailures = false
117116

118117
child.stdout!.pipe(process.stdout)
119118
child.stdout!.on('data', onOutput)
@@ -122,9 +121,10 @@ function runTests(): Promise<boolean> {
122121
child.stderr!.on('data', onOutput)
123122

124123
child.on('exit', (code, signal) => {
125-
if (testsCompleted && !hasFailures) {
126-
// Vitest hung after completion (vitest#10151) β€” treat as success
127-
resolve(true)
124+
if (testsCompleted) {
125+
// Vitest printed results but hung during teardown (vitest#10151).
126+
// We killed it β€” check the output for failures instead of the exit code.
127+
resolve(!hasTestFailures(output))
128128
} else {
129129
resolve(!signal && code === 0)
130130
}
@@ -139,12 +139,6 @@ function runTests(): Promise<boolean> {
139139
return
140140
}
141141

142-
// Match Vitest's failure summary line (e.g. "Test Files 2 failed | 40 passed")
143-
// but not test console output like "3 failed retries" or "Session Replay failed to start"
144-
if (/\d+ failed \|/.test(chunk)) {
145-
hasFailures = true
146-
}
147-
148142
clearTimeout(timeoutId)
149143

150144
if (hasUnrecoverableFailure(output)) {
@@ -165,6 +159,14 @@ function runTests(): Promise<boolean> {
165159
})
166160
}
167161

162+
function hasTestFailures(output: string): boolean {
163+
// Strip ANSI escape codes β€” FORCE_COLOR inserts sequences between "failed" and "|"
164+
// eslint-disable-next-line no-control-regex
165+
const plain = output.replace(/\x1b\[[0-9;]*m/g, '')
166+
// Match Vitest's summary line: "Test Files 2 failed | 40 passed (42)"
167+
return /\d+ failed \|/.test(plain)
168+
}
169+
168170
function hasUnrecoverableFailure(stdout: string): boolean {
169171
return stdout.includes('is set to true but local testing through BrowserStack is not connected.')
170172
}

0 commit comments

Comments
Β (0)