Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/build/src/getActualApiTypesContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ export const getActualApiTypesContent = (contentApi: string, contentExpect: stri
newLines.push(' (api: TestApi): Promise<void>')
newLines.push('}')
newLines.push('')
newLines.push("export type BrowserName = 'chromium' | 'firefox' | 'unknown' | 'webkit'")
newLines.push('export type Skip = boolean | number | readonly BrowserName[]')
newLines.push('')

const formatted = formatApiTypes(newLines)

Expand Down
26 changes: 26 additions & 0 deletions packages/test-worker/src/parts/GetBrowserName/GetBrowserName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export type BrowserName = 'chromium' | 'firefox' | 'unknown' | 'webkit'

const includes = (userAgent: string, value: string): boolean => {
return userAgent.includes(value)
}

export const getBrowserNameFromUserAgent = (userAgent: string): BrowserName => {
const normalized = userAgent.toLowerCase()
if (includes(normalized, 'firefox')) {
return 'firefox'
}
if (includes(normalized, 'chrome') || includes(normalized, 'chromium') || includes(normalized, 'edg')) {
return 'chromium'
}
if (includes(normalized, 'safari') || includes(normalized, 'applewebkit')) {
return 'webkit'
}
return 'unknown'
}

export const getBrowserName = (): BrowserName => {
if (typeof navigator === 'undefined') {
return 'unknown'
}
return getBrowserNameFromUserAgent(navigator.userAgent)
}
13 changes: 13 additions & 0 deletions packages/test-worker/src/parts/ShouldSkipTest/ShouldSkipTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as GetBrowserName from '../GetBrowserName/GetBrowserName.ts'

export const shouldSkipTestWithBrowserName = (skip: unknown, browserName: GetBrowserName.BrowserName): boolean => {
if (Array.isArray(skip)) {
return skip.includes(browserName)
}
return Boolean(skip)
}

export const shouldSkipTest = (skip: unknown): boolean => {
const browserName = GetBrowserName.getBrowserName()
return shouldSkipTestWithBrowserName(skip, browserName)
}
5 changes: 3 additions & 2 deletions packages/test-worker/src/parts/Test/Test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { formatDuration } from '../FormatDuration/FormatDuration.ts'
import { hotReloadEnabled } from '../HotReloadEnabled/HotReloadEnabled.ts'
import * as ImportTest from '../ImportTest/ImportTest.ts'
import { printTestError } from '../PrintTestError/PrintTestError.ts'
import * as ShouldSkipTest from '../ShouldSkipTest/ShouldSkipTest.ts'
import * as TestFrameWork from '../TestFrameWork/TestFrameWork.ts'
import * as TestFrameWorkComponentUrl from '../TestFrameWorkComponentUrl/TestFrameWorkComponentUrl.ts'
import * as TestInfoCache from '../TestInfoCache/TestInfoCache.ts'
Expand Down Expand Up @@ -86,7 +87,7 @@ const executeAllTest = async (item: ExecuteAllTest, globals: any): Promise<Execu
if (mockRpc) {
TestState.setMockRpc(mockRpc)
}
if (skip) {
if (ShouldSkipTest.shouldSkipTest(skip)) {
return getSkippedResult(item.name)
}
if (!test) {
Expand Down Expand Up @@ -167,7 +168,7 @@ export const execute = async (href: string, platform: number, assetDir: string):
TestState.setMockRpc(mockRpc)
}
if (test) {
if (skip) {
if (ShouldSkipTest.shouldSkipTest(skip)) {
await TestFrameWork.skipTest(name)
} else {
await ExecuteTest.executeTest(name, test, globals)
Expand Down
43 changes: 43 additions & 0 deletions packages/test-worker/test/ShouldSkipTest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect, test } from '@jest/globals'
import * as GetBrowserName from '../src/parts/GetBrowserName/GetBrowserName.ts'
import * as ShouldSkipTest from '../src/parts/ShouldSkipTest/ShouldSkipTest.ts'

test('shouldSkipTest returns true for true', () => {
expect(ShouldSkipTest.shouldSkipTestWithBrowserName(true, 'unknown')).toBe(true)
})

test('shouldSkipTest returns true for 1', () => {
expect(ShouldSkipTest.shouldSkipTestWithBrowserName(1, 'unknown')).toBe(true)
})

test('shouldSkipTest returns true for matching browser', () => {
expect(ShouldSkipTest.shouldSkipTestWithBrowserName(['webkit'], 'webkit')).toBe(true)
})

test('shouldSkipTest returns false for chromium when skip targets webkit', () => {
expect(ShouldSkipTest.shouldSkipTestWithBrowserName(['webkit'], 'chromium')).toBe(false)
})

test('shouldSkipTest returns false for firefox when skip targets webkit', () => {
expect(ShouldSkipTest.shouldSkipTestWithBrowserName(['webkit'], 'firefox')).toBe(false)
})

test('shouldSkipTest returns false for empty array', () => {
expect(ShouldSkipTest.shouldSkipTestWithBrowserName([], 'webkit')).toBe(false)
})

test('shouldSkipTest returns false for false', () => {
expect(ShouldSkipTest.shouldSkipTestWithBrowserName(false, 'unknown')).toBe(false)
})

test('getBrowserNameFromUserAgent detects firefox', () => {
expect(GetBrowserName.getBrowserNameFromUserAgent('Mozilla/5.0 Firefox/145.0')).toBe('firefox')
})

test('getBrowserNameFromUserAgent detects chromium', () => {
expect(GetBrowserName.getBrowserNameFromUserAgent('Mozilla/5.0 Chrome/145.0 Safari/537.36')).toBe('chromium')
})

test('getBrowserNameFromUserAgent detects webkit', () => {
expect(GetBrowserName.getBrowserNameFromUserAgent('Mozilla/5.0 Version/18.0 Safari/605.1.15')).toBe('webkit')
})