Skip to content

Commit

Permalink
Reduce notification to github (#6297)
Browse files Browse the repository at this point in the history
* reduce traces
Co-authored-by: Florian Schade <f.schade@icloud.com>
  • Loading branch information
ScharfViktor authored Feb 9, 2022
1 parent 846a2f2 commit 0399887
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
13 changes: 8 additions & 5 deletions tests/e2e/cucumber/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,22 @@ BeforeAll(async (): Promise<void> => {
}[config.browser]()
})

const defaults = {
reportHar: config.reportHar,
reportTracing: config.reportTracing
}

After(async function (this: World, { result }: ITestCaseHookParameter) {
if (!result) {
return
}

await this.attach(`Status: ${result?.status}. Duration:${result.duration?.seconds}s`)

if (result.status !== Status.PASSED) {
if (result.willBeRetried) {
config.reportHar = true
config.reportTracing = true
}
config.reportHar = result.willBeRetried || defaults.reportHar
config.reportTracing = result.willBeRetried || defaults.reportTracing

if (result.status !== Status.PASSED) {
await this.actorsEnvironment.close()
}
})
Expand Down
9 changes: 8 additions & 1 deletion tests/e2e/cucumber/step_definitions/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ import { Given, When } from '@cucumber/cucumber'
import { World } from '../environment'
import { config } from '../../config'
import { LoginPage, RuntimePage } from '../../support'
import { DateTime } from 'luxon'
import { kebabCase } from 'lodash'

async function LogInUser(this: World, stepUser: string): Promise<void> {
const user = this.usersEnvironment.getUser({ id: stepUser })
const actor = await this.actorsEnvironment.createActor({ id: stepUser })
const actor = await this.actorsEnvironment.createActor({
id: stepUser,
namespace: kebabCase(
[this.feature.name, stepUser, DateTime.now().toFormat('yyyy-M-d-hh-mm-ss')].join('-')
)
})
const loginPage = new LoginPage({ actor })

await actor.page.goto(config.frontendUrl)
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/support/environment/actor/actor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Actor } from '../../types'
import { ActorOptions, buildBrowserContextOptions } from './shared'
import { BrowserContext, Page } from 'playwright'
import { DateTime } from 'luxon'
import path from 'path'
import EventEmitter from 'events'

Expand All @@ -10,21 +9,17 @@ export declare interface ActorEnvironment {
}

export class ActorEnvironment extends EventEmitter implements Actor {
private readonly uuid: string
private readonly options: ActorOptions
public context: BrowserContext
public page: Page

constructor(options: ActorOptions) {
super()
this.uuid = [DateTime.now().toFormat('yyyy-M-d-hh-mm-ss'), options.id].join('-')
this.options = options
}

async setup(): Promise<void> {
this.context = await this.options.browser.newContext(
buildBrowserContextOptions(this.uuid, this.options.context)
)
this.context = await this.options.browser.newContext(buildBrowserContextOptions(this.options))

if (this.options.context.reportTracing) {
await this.context.tracing.start({ screenshots: true, snapshots: true, sources: true })
Expand All @@ -36,7 +31,12 @@ export class ActorEnvironment extends EventEmitter implements Actor {
async close(): Promise<void> {
if (this.options.context.reportTracing) {
await this.context?.tracing.stop({
path: path.join(this.options.context.reportDir, 'playwright', 'tracing', `${this.uuid}.zip`)
path: path.join(
this.options.context.reportDir,
'playwright',
'tracing',
`${this.options.namespace}.zip`
)
})
}

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/support/environment/actor/actors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export class ActorsEnvironment extends EventEmitter {
return this.store.get(id)
}

public async createActor({ id }: { id: string }): Promise<Actor> {
public async createActor({ id, namespace }: { id: string; namespace: string }): Promise<Actor> {
if (this.store.has(id)) {
return this.getActor({ id })
}

const actor = new ActorEnvironment({ id, ...this.options })
const actor = new ActorEnvironment({ id, namespace, ...this.options })
await actor.setup()
actor.on('closed', () => this.store.delete(id))
actor.page.on('console', (message) => {
Expand Down
16 changes: 7 additions & 9 deletions tests/e2e/support/environment/actor/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,24 @@ export interface ActorsOptions {

export interface ActorOptions extends ActorsOptions {
id: string
namespace: string
}

export const buildBrowserContextOptions = (
uuid: string,
options: ActorOptions['context']
): BrowserContextOptions => {
export const buildBrowserContextOptions = (options: ActorOptions): BrowserContextOptions => {
const contextOptions: BrowserContextOptions = {
acceptDownloads: options.acceptDownloads,
acceptDownloads: options.context.acceptDownloads,
ignoreHTTPSErrors: true
}

if (options.reportVideo) {
if (options.context.reportVideo) {
contextOptions.recordVideo = {
dir: path.join(options.reportDir, 'playwright', 'video')
dir: path.join(options.context.reportDir, 'playwright', 'video')
}
}

if (options.reportHar) {
if (options.context.reportHar) {
contextOptions.recordHar = {
path: path.join(options.reportDir, 'playwright', 'har', `${uuid}.har`)
path: path.join(options.context.reportDir, 'playwright', 'har', `${options.namespace}.har`)
}
}

Expand Down

0 comments on commit 0399887

Please sign in to comment.