Skip to content

Commit

Permalink
V8 reconciliation + bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanbs committed Oct 24, 2024
1 parent 7d570f7 commit 8648184
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 202 deletions.
62 changes: 58 additions & 4 deletions packages/wdio-browserstack-service/src/Percy/PercySDK.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import InsightsHandler from '../insights-handler.js'
import TestReporter from '../reporter.js'
import { PercyLogger } from './PercyLogger.js'

const tryRequire = async function (pkg: string, fallback: any) {
Expand All @@ -17,9 +19,19 @@ let snapshotHandler = (...args: any[]) => {
PercyLogger.error('Unsupported driver for percy')
}
if (percySnapshot) {
snapshotHandler = (browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser, name: string) => {
snapshotHandler = (browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser, snapshotName: string, options?: any) => {
if (process.env.PERCY_SNAPSHOT === 'true') {
return percySnapshot(browser, name)
let { name, uuid } = InsightsHandler._currentTest
if (!name || name === '') {
({ name, uuid } = TestReporter._currentTest)
}
options ||= {}
options = {
...options,
testCase: name || '',
thTestCaseExecutionId: uuid || '',
}
return percySnapshot(browser, snapshotName, options)
}
}
}
Expand All @@ -30,7 +42,28 @@ let screenshotHandler = async (...args: any[]) => {
PercyLogger.error('Unsupported driver for percy')
}
if (percySnapshot && percySnapshot.percyScreenshot) {
screenshotHandler = percySnapshot.percyScreenshot
screenshotHandler = (browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser | string, screenshotName: any, options?: any) => {
let { name, uuid } = InsightsHandler._currentTest
if (!name || name === '') {
({ name, uuid } = TestReporter._currentTest)
}
if (!browser || typeof browser === 'string') {
screenshotName ||= {}
screenshotName = {
...screenshotName,
testCase: name || '',
thTestCaseExecutionId: uuid || '',
}
} else {
options ||= {}
options = {
...options,
testCase: name || '',
thTestCaseExecutionId: uuid || '',
}
}
return percySnapshot.percyScreenshot(browser, screenshotName, options)
}
}
export const screenshot = screenshotHandler

Expand All @@ -39,6 +72,27 @@ let screenshotAppHandler = async (...args: any[]) => {
PercyLogger.error('Unsupported driver for percy')
}
if (percyAppScreenshot) {
screenshotAppHandler = percyAppScreenshot
screenshotAppHandler = (driverOrName: any, nameOrOptions?: any, options?: any) => {
let { name, uuid } = InsightsHandler._currentTest
if (!name || name === '') {
({ name, uuid } = TestReporter._currentTest)
}
if (!driverOrName || typeof driverOrName === 'string') {
nameOrOptions ||= {}
nameOrOptions = {
...nameOrOptions,
testCase: name || '',
thTestCaseExecutionId: uuid || '',
}
} else {
options ||= {}
options = {
...options,
testCase: name || '',
thTestCaseExecutionId: uuid || '',
}
}
return percyAppScreenshot(driverOrName, nameOrOptions, options)
}
}
export const screenshotApp = screenshotAppHandler
41 changes: 25 additions & 16 deletions packages/wdio-browserstack-service/src/accessibility-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { Capabilities, Frameworks } from '@wdio/types'

import type { ITestCaseHookParameter } from './cucumber-types.js'

import Listener from './testOps/listener.js'

import {
getA11yResultsSummary,
getA11yResults,
Expand All @@ -30,6 +32,7 @@ class _AccessibilityHandler {
private _testMetadata: { [key: string]: any; } = {}
private static _a11yScanSessionMap: { [key: string]: any; } = {}
private _sessionId: string | null = null
private listener = Listener.getInstance()

constructor (
private _browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser,
Expand Down Expand Up @@ -130,6 +133,8 @@ class _AccessibilityHandler {
this._framework !== 'mocha' ||
!this.shouldRunTestHooks(this._browser, this._accessibility)
) {
/* This is to be used when test events are sent */
Listener.setTestRunAccessibilityVar(false)
return
}

Expand All @@ -142,6 +147,9 @@ class _AccessibilityHandler {
AccessibilityHandler._a11yScanSessionMap[this._sessionId] = shouldScanTest
}

/* This is to be used when test events are sent */
Listener.setTestRunAccessibilityVar(this._accessibility && shouldScanTest)

if (!isPageOpened) {
return
}
Expand Down Expand Up @@ -176,17 +184,15 @@ class _AccessibilityHandler {

if (shouldScanTestForAccessibility) {
BStackLogger.info('Automate test case execution has ended. Processing for accessibility testing is underway. ')
}

const dataForExtension = {
'thTestRunUuid': process.env.TEST_ANALYTICS_ID,
'thBuildUuid': process.env.BROWSERSTACK_TESTHUB_UUID,
'thJwtToken': process.env.BROWSERSTACK_TESTHUB_JWT
}
const dataForExtension = {
'thTestRunUuid': process.env.TEST_ANALYTICS_ID,
'thBuildUuid': process.env.BROWSERSTACK_TESTHUB_UUID,
'thJwtToken': process.env.BROWSERSTACK_TESTHUB_JWT
}

await this.sendTestStopEvent((this._browser as WebdriverIO.Browser), dataForExtension)
await this.sendTestStopEvent((this._browser as WebdriverIO.Browser), dataForExtension)

if (shouldScanTestForAccessibility) {
BStackLogger.info('Accessibility testing for this test case has ended.')
}
} catch (error) {
Expand All @@ -203,6 +209,8 @@ class _AccessibilityHandler {
const featureData = gherkinDocument.feature
const uniqueId = getUniqueIdentifierForCucumber(world)
if (!this.shouldRunTestHooks(this._browser, this._accessibility)) {
/* This is to be used when test events are sent */
Listener.setTestRunAccessibilityVar(false)
return
}

Expand All @@ -215,6 +223,9 @@ class _AccessibilityHandler {
AccessibilityHandler._a11yScanSessionMap[this._sessionId] = shouldScanScenario
}

/* This is to be used when test events are sent */
Listener.setTestRunAccessibilityVar(this._accessibility && shouldScanScenario)

if (!isPageOpened) {
return
}
Expand Down Expand Up @@ -247,17 +258,15 @@ class _AccessibilityHandler {

if (shouldScanTestForAccessibility) {
BStackLogger.info('Automate test case execution has ended. Processing for accessibility testing is underway. ')
}

const dataForExtension = {
'thTestRunUuid': process.env.TEST_ANALYTICS_ID,
'thBuildUuid': process.env.BROWSERSTACK_TESTHUB_UUID,
'thJwtToken': process.env.BROWSERSTACK_TESTHUB_JWT
}
const dataForExtension = {
'thTestRunUuid': process.env.TEST_ANALYTICS_ID,
'thBuildUuid': process.env.BROWSERSTACK_TESTHUB_UUID,
'thJwtToken': process.env.BROWSERSTACK_TESTHUB_JWT
}

await this.sendTestStopEvent(( this._browser as WebdriverIO.Browser), dataForExtension)
await this.sendTestStopEvent(( this._browser as WebdriverIO.Browser), dataForExtension)

if (shouldScanTestForAccessibility) {
BStackLogger.info('Accessibility testing for this test case has ended.')
}
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions packages/wdio-browserstack-service/src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getErrorString, stopBuildUpstream } from './util.js'
import { BStackLogger } from './bstackLogger.js'
import fs from 'node:fs'
import { fireFunnelRequest } from './instrumentation/funnelInstrumentation.js'
import { BROWSERSTACK_TESTHUB_UUID, BROWSERSTACK_TESTHUB_JWT } from './constants.js'
import { BROWSERSTACK_TESTHUB_UUID, BROWSERSTACK_TESTHUB_JWT, BROWSERSTACK_OBSERVABILITY } from './constants.js'

export default class BStackCleanup {
static async startCleanup() {
Expand Down Expand Up @@ -36,7 +36,7 @@ export default class BStackCleanup {
try {
const killSignal = funnelData?.event_properties?.finishedMetadata?.signal
const result = await stopBuildUpstream(killSignal)
if (process.env[BROWSERSTACK_TESTHUB_UUID]) {
if (process.env[BROWSERSTACK_OBSERVABILITY] && process.env[BROWSERSTACK_TESTHUB_UUID]) {
BStackLogger.info(`\nVisit https://observability.browserstack.com/builds/${process.env[BROWSERSTACK_TESTHUB_UUID]} to view build report, insights, and many more debugging information all at one place!\n`)
}
const status = (result && result.status) || 'failed'
Expand Down
2 changes: 1 addition & 1 deletion packages/wdio-browserstack-service/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const DEFAULT_WAIT_TIMEOUT_FOR_PENDING_UPLOADS = 5000 // 5s
export const DEFAULT_WAIT_INTERVAL_FOR_PENDING_UPLOADS = 100 // 100ms
export const BSTACK_SERVICE_VERSION = bstackServiceVersion

export const ACCESSIBILITY_API_URL = 'https://accessibility.browserstack.com/api'
export const NOT_ALLOWED_KEYS_IN_CAPS = ['includeTagsInTestingScope', 'excludeTagsInTestingScope']

export const LOGS_FILE = 'logs/bstack-wdio-service.log'
Expand Down Expand Up @@ -116,6 +115,7 @@ export const BROWSERSTACK_ACCESSIBILITY = 'BROWSERSTACK_ACCESSIBILITY'

// Whether session is a observability session
export const BROWSERSTACK_OBSERVABILITY = 'BROWSERSTACK_OBSERVABILITY'

// Maximum size of VCS info which is allowed
export const MAX_GIT_META_DATA_SIZE_IN_BYTES = 64 * 1024

Expand Down
20 changes: 14 additions & 6 deletions packages/wdio-browserstack-service/src/insights-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class _InsightsHandler {
private _commands: Record<string, BeforeCommandArgs | AfterCommandArgs> = {}
private _gitConfigPath?: string
private _suiteFile?: string
private _currentTest: CurrentRunInfo = {}
public static _currentTest: CurrentRunInfo = {}
private _currentHook: CurrentRunInfo = {}
private _cucumberData: CucumberStore = {
stepsStarted: false,
Expand Down Expand Up @@ -207,7 +207,7 @@ class _InsightsHandler {
const hookMetaData = {
uuid: hookUUID,
startedAt: (new Date()).toISOString(),
testRunId: this._currentTest.uuid,
testRunId: InsightsHandler._currentTest.uuid,
hookType: hookType
}

Expand Down Expand Up @@ -368,7 +368,7 @@ class _InsightsHandler {

async beforeTest (test: Frameworks.Test) {
const uuid = uuidv4()
this._currentTest = {
InsightsHandler._currentTest = {
test, uuid
}
if (this._framework !== 'mocha') {
Expand Down Expand Up @@ -408,7 +408,7 @@ class _InsightsHandler {

async beforeScenario (world: ITestCaseHookParameter) {
const uuid = uuidv4()
this._currentTest = {
InsightsHandler._currentTest = {
uuid
}
this._cucumberData.scenario = world.pickle
Expand Down Expand Up @@ -503,8 +503,8 @@ class _InsightsHandler {
try {
if (this._currentHook.uuid && !this._currentHook.finished && (this._framework === 'mocha' || this._framework === 'cucumber')) {
stdLog.hook_run_uuid = this._currentHook.uuid
} else if (this._currentTest.uuid && (this._framework === 'mocha' || this._framework === 'cucumber')) {
stdLog.test_run_uuid = this._currentTest.uuid
} else if (InsightsHandler._currentTest.uuid && (this._framework === 'mocha' || this._framework === 'cucumber')) {
stdLog.test_run_uuid = InsightsHandler._currentTest.uuid
}
if (stdLog.hook_run_uuid || stdLog.test_run_uuid) {
this.listener.logCreated([stdLog])
Expand Down Expand Up @@ -630,6 +630,10 @@ class _InsightsHandler {
const filename = test.file || this._suiteFile
this._currentTestId = testMetaData.uuid

if (eventType === 'TestRunStarted') {
InsightsHandler._currentTest.name = test.title || test.description
}

const testData: TestData = {
uuid: testMetaData.uuid,
type: test.type || 'test',
Expand Down Expand Up @@ -745,6 +749,10 @@ class _InsightsHandler {

this._currentTestId = uuid

if (eventType === 'TestRunStarted') {
InsightsHandler._currentTest.name = fullNameWithExamples
}

const testData: TestData = {
uuid: uuid,
started_at: startedAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,27 @@ export function saveFunnelData(eventType: string, config: BrowserStackConfig): s
return filePath
}

function redactCredentialsFromFunnelData(data: any) {
if (data) {
if (data.userName) {
data.userName = '[REDACTED]'
}
if (data.accessKey) {
data.accessKey = '[REDACTED]'
}
}
return data
}

// Called from two different process
export async function fireFunnelRequest(data: any): Promise<void> {
const { userName, accessKey } = data
redactCredentialsFromFunnelData(data)
BStackLogger.debug('Sending SDK event with data ' + util.inspect(data, { depth: 6 }))
await got.post(FUNNEL_INSTRUMENTATION_URL, {
headers: {
'content-type': 'application/json'
}, username: data.userName, password: data.accessKey, json: data
}, username: userName, password: accessKey, json: data
})
}

Expand Down
Loading

0 comments on commit 8648184

Please sign in to comment.