Skip to content

Commit 609ba2e

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 609ba2e

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

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

Lines changed: 14 additions & 3 deletions
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()
@@ -154,8 +162,11 @@ describe('cookieAccess', () => {
154162

155163
it('should pass all cookie values to callback', async (ctx) => {
156164
const browserVersion = detectVersion()
157-
if (!isChromium() || (browserVersion !== undefined && browserVersion < 145)) {
158-
ctx.skip(true, 'Only Recent Chromium supports multiple cookies with the same name with different options')
165+
if (!isChromium() || browserVersion === undefined || browserVersion < 145) {
166+
ctx.skip(true, 'Only recent Chromium (>=145) supports multiple cookies with the same name')
167+
}
168+
if (location.protocol !== 'https:') {
169+
ctx.skip(true, 'Partitioned cookies require a secure (HTTPS) context')
159170
}
160171

161172
const { createCookieAccess, setCookieWithCleanup } = setup()

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

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

118118
child.stdout!.pipe(process.stdout)
119119
child.stdout!.on('data', onOutput)
@@ -122,10 +122,12 @@ function runTests(): Promise<boolean> {
122122
child.stderr!.on('data', onOutput)
123123

124124
child.on('exit', (code, signal) => {
125-
if (testsCompleted && !hasFailures) {
126-
// Vitest hung after completion (vitest#10151) β€” treat as success
127-
resolve(true)
125+
if (killedByWrapper && testsCompleted) {
126+
// Vitest hung during teardown (vitest#10151) and we killed it.
127+
// No exit code to trust β€” check the output for failures.
128+
resolve(!hasTestFailures(output))
128129
} else {
130+
// Vitest exited on its own β€” trust its exit code.
129131
resolve(!signal && code === 0)
130132
}
131133
})
@@ -139,12 +141,6 @@ function runTests(): Promise<boolean> {
139141
return
140142
}
141143

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-
148144
clearTimeout(timeoutId)
149145

150146
if (hasUnrecoverableFailure(output)) {
@@ -160,11 +156,20 @@ function runTests(): Promise<boolean> {
160156

161157
function killIt(message: string): void {
162158
printError(`Killing the browserstack job because of ${message}`)
159+
killedByWrapper = true
163160
child.kill('SIGKILL')
164161
}
165162
})
166163
}
167164

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

0 commit comments

Comments
Β (0)