test: move contentTracing specs to main process (#19229)
This commit is contained in:
parent
4d8a05568b
commit
3957a791b7
2 changed files with 19 additions and 29 deletions
|
@ -1,30 +1,18 @@
|
||||||
const { remote } = require('electron')
|
import { expect } from 'chai'
|
||||||
const chai = require('chai')
|
import { app, contentTracing, TraceConfig, TraceCategoriesAndOptions } from 'electron'
|
||||||
const dirtyChai = require('dirty-chai')
|
import * as fs from 'fs'
|
||||||
const fs = require('fs')
|
import * as path from 'path'
|
||||||
const path = require('path')
|
import { ifdescribe } from './spec-helpers'
|
||||||
|
|
||||||
const { expect } = chai
|
const timeout = async (milliseconds: number) => {
|
||||||
const { app, contentTracing } = remote
|
|
||||||
|
|
||||||
chai.use(dirtyChai)
|
|
||||||
|
|
||||||
const timeout = async (milliseconds) => {
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
setTimeout(resolve, milliseconds)
|
setTimeout(resolve, milliseconds)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('contentTracing', () => {
|
// FIXME: The tests are skipped on arm/arm64.
|
||||||
beforeEach(function () {
|
ifdescribe(!(process.platform === 'linux' && ['arm', 'arm64'].includes(process.arch)))('contentTracing', () => {
|
||||||
// FIXME: The tests are skipped on arm/arm64.
|
const record = async (options: TraceConfig | TraceCategoriesAndOptions, outputFilePath: string | undefined, recordTimeInMilliseconds = 1e1) => {
|
||||||
if (process.platform === 'linux' &&
|
|
||||||
['arm', 'arm64'].includes(process.arch)) {
|
|
||||||
this.skip()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const record = async (options, outputFilePath, recordTimeInMilliseconds = 1e3) => {
|
|
||||||
await app.whenReady()
|
await app.whenReady()
|
||||||
|
|
||||||
await contentTracing.startRecording(options)
|
await contentTracing.startRecording(options)
|
||||||
|
@ -44,7 +32,7 @@ describe('contentTracing', () => {
|
||||||
describe('startRecording', function () {
|
describe('startRecording', function () {
|
||||||
this.timeout(5e3)
|
this.timeout(5e3)
|
||||||
|
|
||||||
const getFileSizeInKiloBytes = (filePath) => {
|
const getFileSizeInKiloBytes = (filePath: string) => {
|
||||||
const stats = fs.statSync(filePath)
|
const stats = fs.statSync(filePath)
|
||||||
const fileSizeInBytes = stats.size
|
const fileSizeInBytes = stats.size
|
||||||
const fileSizeInKiloBytes = fileSizeInBytes / 1024
|
const fileSizeInKiloBytes = fileSizeInBytes / 1024
|
||||||
|
@ -55,7 +43,7 @@ describe('contentTracing', () => {
|
||||||
const config = {}
|
const config = {}
|
||||||
await record(config, outputFilePath)
|
await record(config, outputFilePath)
|
||||||
|
|
||||||
expect(fs.existsSync(outputFilePath)).to.be.true()
|
expect(fs.existsSync(outputFilePath)).to.be.true('output exists')
|
||||||
|
|
||||||
const fileSizeInKiloBytes = getFileSizeInKiloBytes(outputFilePath)
|
const fileSizeInKiloBytes = getFileSizeInKiloBytes(outputFilePath)
|
||||||
expect(fileSizeInKiloBytes).to.be.above(0,
|
expect(fileSizeInKiloBytes).to.be.above(0,
|
||||||
|
@ -70,7 +58,7 @@ describe('contentTracing', () => {
|
||||||
}
|
}
|
||||||
await record(config, outputFilePath)
|
await record(config, outputFilePath)
|
||||||
|
|
||||||
expect(fs.existsSync(outputFilePath)).to.be.true()
|
expect(fs.existsSync(outputFilePath)).to.be.true('output exists')
|
||||||
|
|
||||||
// If the `excluded_categories` param above is not respected
|
// If the `excluded_categories` param above is not respected
|
||||||
// the file size will be above 50KB.
|
// the file size will be above 50KB.
|
||||||
|
@ -93,7 +81,7 @@ describe('contentTracing', () => {
|
||||||
}
|
}
|
||||||
await record(config, outputFilePath)
|
await record(config, outputFilePath)
|
||||||
|
|
||||||
expect(fs.existsSync(outputFilePath)).to.be.true()
|
expect(fs.existsSync(outputFilePath)).to.be.true('output exists')
|
||||||
|
|
||||||
// If the `categoryFilter` param above is not respected
|
// If the `categoryFilter` param above is not respected
|
||||||
// the file size will be above 50KB.
|
// the file size will be above 50KB.
|
||||||
|
@ -119,8 +107,8 @@ describe('contentTracing', () => {
|
||||||
|
|
||||||
await contentTracing.startRecording(options)
|
await contentTracing.startRecording(options)
|
||||||
const path = await contentTracing.stopRecording('')
|
const path = await contentTracing.stopRecording('')
|
||||||
expect(path).to.be.a('string').that.is.not.empty()
|
expect(path).to.be.a('string').that.is.not.empty('result path')
|
||||||
expect(fs.statSync(path).isFile()).to.be.true()
|
expect(fs.statSync(path).isFile()).to.be.true('output exists')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls its callback with a result file path', async () => {
|
it('calls its callback with a result file path', async () => {
|
||||||
|
@ -130,12 +118,12 @@ describe('contentTracing', () => {
|
||||||
|
|
||||||
it('creates a temporary file when an empty string is passed', async function () {
|
it('creates a temporary file when an empty string is passed', async function () {
|
||||||
const resultFilePath = await record(/* options */ {}, /* outputFilePath */ '')
|
const resultFilePath = await record(/* options */ {}, /* outputFilePath */ '')
|
||||||
expect(resultFilePath).to.be.a('string').that.is.not.empty()
|
expect(resultFilePath).to.be.a('string').that.is.not.empty('result path')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('creates a temporary file when no path is passed', async function () {
|
it('creates a temporary file when no path is passed', async function () {
|
||||||
const resultFilePath = await record(/* options */ {}, /* outputFilePath */ undefined)
|
const resultFilePath = await record(/* options */ {}, /* outputFilePath */ undefined)
|
||||||
expect(resultFilePath).to.be.a('string').that.is.not.empty()
|
expect(resultFilePath).to.be.a('string').that.is.not.empty('result path')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
2
spec-main/spec-helpers.ts
Normal file
2
spec-main/spec-helpers.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export const ifit = (condition: boolean) => (condition ? it : it.skip)
|
||||||
|
export const ifdescribe = (condition: boolean) => (condition ? describe : describe.skip)
|
Loading…
Add table
Add a link
Reference in a new issue