Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Jan 3, 2024
1 parent 4e31e44 commit 06566e8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ describe('generateFilename - ', () => {

it('should generate name in form: name--browser--date', () => {
expect(generateFilename(maxTestNameCharacters, browser, name))
.toBe(`${name}--${browser}--${date}`)
.toBe(`video-${name}--${browser}--${date}`)
})

it('should replace space with -', () => {
const testname = name + ' space'
expect(generateFilename(maxTestNameCharacters, browser, testname))
.toBe(`${name}-space--${browser}--${date}`)
.toBe(`video-${name}-space--${browser}--${date}`)
})

it('should replace . with -', () => {
const testname = name + '.dot'
expect(generateFilename(maxTestNameCharacters, browser, testname))
.toBe(`${name}-dot--${browser}--${date}`)
.toBe(`video-${name}-dot--${browser}--${date}`)
})

it('should remove characters: /?<>\\/:*|"()[]\'<>%', () => {
const testname = name + '-/?<>\\/:*|"()[]\'<>%comment/'
expect(generateFilename(maxTestNameCharacters, browser, testname))
.toBe(`${name}-comment--${browser}--${date}`)
.toBe(`video-${name}-comment--${browser}--${date}`)
})

it('should keep filenames <= config.maxTestNameCharacters', () => {
Expand Down
20 changes: 11 additions & 9 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ vi.mock('@ffmpeg-installer/ffmpeg', () => ({
vi.mock('@wdio/reporter', () => ({
default: class {
options: unknown
write = vi.fn()
constructor (options: unknown) {
this.options = options
}
Expand Down Expand Up @@ -60,6 +61,9 @@ const sleep = (ms = 100) => new Promise((resolve) => setTimeout(resolve, ms))
const allureRunner: any = {
isMultiremote: false,
sessionId: '1234',
config: {
outputDir: '/foo/bar'
},
instanceOptions: {
1234: {
reporters: [['allure', { outputDir: '/foo/bar' }]]
Expand Down Expand Up @@ -136,29 +140,27 @@ describe('Video Reporter', () => {
excludedActions: ['click']
})
reporter.recordingPath = '/foo/bar'
reporter.onAfterCommand({ endpoint: '/session/1234/click' } as any)
expect(browser.getAlertText).toBeCalledTimes(0)
expect(reporter.onAfterCommand({ endpoint: '/session/1234/click' } as any))
.toBe(false)
})

it('should do nothing if recordingPath is not set', () => {
const reporter = new VideoReporter({})
reporter.onAfterCommand({ endpoint: '/session/1234/click' } as any)
expect(browser.getAlertText).toBeCalledTimes(0)
expect(reporter.onAfterCommand({ endpoint: '/session/1234/click' } as any))
.toBe(false)
})

it('should add frame if no alert is displayed', async () => {
const reporter = new VideoReporter({})
reporter.recordingPath = '/foo/bar'
await reporter.onAfterCommand({ endpoint: '/session/1234/click' } as any)
expect(browser.getAlertText).toBeCalledTimes(1)
expect(browser.saveScreenshot).toBeCalledTimes(1)
})

it('should add frame if recordAllActions is set', async () => {
const reporter = new VideoReporter({ recordAllActions: true })
reporter.recordingPath = '/foo/bar'
await reporter.onAfterCommand({ endpoint: '/session/1234/foobar' } as any)
expect(browser.getAlertText).toBeCalledTimes(1)
expect(browser.saveScreenshot).toBeCalledTimes(1)
})
})
Expand All @@ -178,10 +180,10 @@ describe('Video Reporter', () => {
it('should set recordingPath if suite is scenario', () => {
const reporter = new VideoReporter({})
reporter.onSuiteStart({ title: 'foo bar', type: 'scenario' } as any)
expect(reporter.recordingPath).toEqual(expect.stringContaining('/unknown--CHROME--'))
expect(reporter.recordingPath).toEqual(expect.stringContaining('/video-unknown--CHROME--'))
reporter.isCucumberFramework = true
reporter.onSuiteStart({ title: 'foo bar', type: 'scenario' } as any)
expect(reporter.recordingPath).toEqual(expect.stringContaining('/foo-bar--CHROME--'))
expect(reporter.recordingPath).toEqual(expect.stringContaining('/video-foo-bar--CHROME--'))
})
})

Expand Down Expand Up @@ -236,7 +238,7 @@ describe('Video Reporter', () => {
const reporter = new VideoReporter({})
reporter.onTestStart({ title: 'foo bar' } as any)
expect(fs.mkdirSync).toBeCalledWith(
expect.stringContaining('/foo-bar--CHROME--'),
expect.stringContaining('/video-foo-bar--CHROME--'),
{ recursive: true }
)
})
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default class VideoReporter extends WdioReporter {
) ||
!this.recordingPath
) {
return
return false
}

/**
Expand Down Expand Up @@ -272,7 +272,7 @@ export default class VideoReporter extends WdioReporter {

addFrame () {
if (!this.recordingPath) {
return
return false
}

const frame = this.frameNr++
Expand Down
4 changes: 3 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export default defineConfig({
coverage: {
enabled: true,
provider: 'v8',
exclude: ['__mocks__', 'node_modules', '.github', 'allure-report', 'tests', 'src/types.ts', '.eslintrc.cjs'],
exclude: [
'__mocks__', 'node_modules', '.github', 'allure-report', 'demo', 'src/types.ts', '.eslintrc.cjs'
],
thresholds: {
statements: 77,
branches: 87,
Expand Down

0 comments on commit 06566e8

Please sign in to comment.