mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-04 14:00:22 -05:00
chore: optimize server unit test perf (#32402)
* chore: improve performance of server unit-tests * update screenshots spec to run faster * improve timing of more server unit tests * revert the project spec changes * fix path resolutions
This commit is contained in:
@@ -2,27 +2,32 @@ require('../spec_helper')
|
||||
|
||||
const files = require('../../lib/files')
|
||||
const FixturesHelper = require('@tooling/system-tests')
|
||||
const { getCtx } = require('../../lib/makeDataContext')
|
||||
|
||||
let ctx
|
||||
|
||||
describe('lib/files', () => {
|
||||
beforeEach(async function () {
|
||||
ctx = getCtx()
|
||||
FixturesHelper.scaffold()
|
||||
before(async function () {
|
||||
const { setCtx, makeDataContext, clearCtx } = require('../../lib/makeDataContext')
|
||||
|
||||
// Clear and set up DataContext
|
||||
await clearCtx()
|
||||
setCtx(makeDataContext({}))
|
||||
ctx = require('../../lib/makeDataContext').getCtx()
|
||||
|
||||
FixturesHelper.scaffold()
|
||||
this.todosPath = FixturesHelper.projectPath('todos')
|
||||
|
||||
await ctx.actions.project.setCurrentProjectAndTestingTypeForTestSetup(this.todosPath)
|
||||
|
||||
return ctx.lifecycleManager.getFullInitialConfig().then(async (cfg) => {
|
||||
this.config = cfg;
|
||||
({ projectRoot: this.projectRoot } = cfg)
|
||||
await ctx.actions.project.setCurrentProjectAndTestingTypeForTestSetup(this.projectRoot)
|
||||
})
|
||||
const cfg = await ctx.lifecycleManager.getFullInitialConfig()
|
||||
|
||||
this.config = cfg
|
||||
this.projectRoot = cfg.projectRoot
|
||||
|
||||
await ctx.actions.project.setCurrentProjectAndTestingTypeForTestSetup(this.projectRoot)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
after(() => {
|
||||
return FixturesHelper.remove()
|
||||
})
|
||||
|
||||
|
||||
@@ -5,30 +5,37 @@ const Promise = require('bluebird')
|
||||
const fixture = require(`../../lib/fixture`)
|
||||
const { fs } = require(`../../lib/util/fs`)
|
||||
const FixturesHelper = require('@tooling/system-tests')
|
||||
const { getCtx } = require(`../../lib/makeDataContext`)
|
||||
const snapshot = require('snap-shot-it')
|
||||
|
||||
let ctx
|
||||
|
||||
describe('lib/fixture', () => {
|
||||
beforeEach(async function () {
|
||||
ctx = getCtx()
|
||||
before(async function () {
|
||||
const { setCtx, makeDataContext, clearCtx } = require('../../lib/makeDataContext')
|
||||
|
||||
// Clear and set up DataContext
|
||||
await clearCtx()
|
||||
setCtx(makeDataContext({}))
|
||||
ctx = require('../../lib/makeDataContext').getCtx()
|
||||
|
||||
FixturesHelper.scaffold()
|
||||
|
||||
this.todosPath = FixturesHelper.projectPath('todos')
|
||||
this.read = (folder, image, encoding) => {
|
||||
return fs.readFileAsync(path.join(folder, image), encoding)
|
||||
}
|
||||
|
||||
await ctx.actions.project.setCurrentProjectAndTestingTypeForTestSetup(this.todosPath)
|
||||
|
||||
return ctx.lifecycleManager.getFullInitialConfig()
|
||||
.then((cfg) => {
|
||||
({ fixturesFolder: this.fixturesFolder } = cfg)
|
||||
})
|
||||
const cfg = await ctx.lifecycleManager.getFullInitialConfig()
|
||||
|
||||
this.fixturesFolder = cfg.fixturesFolder
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
beforeEach(function () {
|
||||
this.read = (folder, image, encoding) => {
|
||||
return fs.readFileAsync(path.join(folder, image), encoding)
|
||||
}
|
||||
})
|
||||
|
||||
after(() => {
|
||||
return FixturesHelper.remove()
|
||||
})
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ require('../spec_helper')
|
||||
const _ = require('lodash')
|
||||
const path = require('path')
|
||||
const Jimp = require('jimp')
|
||||
const sinon = require('sinon')
|
||||
const { Buffer } = require('buffer')
|
||||
const dataUriToBuffer = require('data-uri-to-buffer')
|
||||
const sizeOf = require('image-size')
|
||||
@@ -11,23 +12,35 @@ const screenshots = require(`../../lib/screenshots`)
|
||||
const { fs } = require(`../../lib/util/fs`)
|
||||
const plugins = require(`../../lib/plugins`)
|
||||
const { Screenshot } = require(`../../lib/automation/screenshot`)
|
||||
const { getCtx } = require(`../../lib/makeDataContext`)
|
||||
|
||||
const image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAALlJREFUeNpi1F3xYAIDA4MBA35wgQWqyB5dRoaVmeHJ779wPhOM0aQtyBAoyglmOwmwM6z1lWY44CMDFgcBFmRTGp3EGGJe/WIQ5mZm4GRlBGJmhlm3PqGaeODpNzCtKsbGIARUCALvvv6FWw9XeOvrH4bbQNOQwfabnzHdGK3AwyAjyAqX2HPzC0Pn7Y9wPtyNIMGlD74wmAqwMZz+8AvFxzATVZAFQIqwABWQiWtgAY5uCnKAAwQYAPr8OZysiz4PAAAAAElFTkSuQmCC'
|
||||
const iso8601Regex = /^\d{4}\-\d{2}\-\d{2}T\d{2}\:\d{2}\:\d{2}\.?\d*Z?$/
|
||||
|
||||
let ctx
|
||||
|
||||
describe('lib/screenshots', () => {
|
||||
beforeEach(async function () {
|
||||
ctx = getCtx()
|
||||
// make each test timeout after only 1 sec
|
||||
// so that durations are handled correctly
|
||||
this.currentTest.timeout(1000)
|
||||
before(async function () {
|
||||
const { setCtx, makeDataContext, clearCtx } = require('../../lib/makeDataContext')
|
||||
|
||||
// Clear and set up DataContext
|
||||
await clearCtx()
|
||||
setCtx(makeDataContext({}))
|
||||
ctx = require('../../lib/makeDataContext').getCtx()
|
||||
|
||||
Fixtures.scaffold()
|
||||
this.todosPath = Fixtures.projectPath('todos')
|
||||
|
||||
await ctx.actions.project.setCurrentProjectAndTestingTypeForTestSetup(this.todosPath)
|
||||
|
||||
const config1 = await ctx.lifecycleManager.getFullInitialConfig()
|
||||
|
||||
this.config = config1
|
||||
})
|
||||
|
||||
beforeEach(async function () {
|
||||
// make each test timeout after only 1 sec
|
||||
// so that durations are handled correctly
|
||||
this.currentTest.timeout(1000)
|
||||
|
||||
this.appData = {
|
||||
capture: 'viewport',
|
||||
appOnly: true,
|
||||
@@ -60,16 +73,9 @@ describe('lib/screenshots', () => {
|
||||
|
||||
Jimp.prototype.composite = sinon.stub()
|
||||
// Jimp.prototype.getBuffer = sinon.stub().resolves(@buffer)
|
||||
|
||||
await ctx.actions.project.setCurrentProjectAndTestingTypeForTestSetup(this.todosPath)
|
||||
|
||||
return ctx.lifecycleManager.getFullInitialConfig()
|
||||
.then((config1) => {
|
||||
this.config = config1
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
after(() => {
|
||||
return Fixtures.remove()
|
||||
})
|
||||
|
||||
|
||||
@@ -53,6 +53,27 @@ const copyContents = (fromFile, toFile) => {
|
||||
// copies all of the project fixtures
|
||||
// to the cyTmpDir .projects in the root
|
||||
export function scaffold () {
|
||||
// Prevent copying directory into itself
|
||||
const resolvedProjects = _path.resolve(projects)
|
||||
const resolvedCyTmpDir = _path.resolve(cyTmpDir)
|
||||
|
||||
if (resolvedProjects === resolvedCyTmpDir ||
|
||||
resolvedCyTmpDir.startsWith(resolvedProjects + _path.sep) ||
|
||||
resolvedProjects.startsWith(resolvedCyTmpDir + _path.sep)) {
|
||||
throw new Error(`Cannot copy directory into itself: projects=${projects}, cyTmpDir=${cyTmpDir}`)
|
||||
}
|
||||
|
||||
// Ensure temp directory is clean before copying
|
||||
try {
|
||||
fs.removeSync(cyTmpDir)
|
||||
} catch (err) {
|
||||
// Ignore errors if directory doesn't exist
|
||||
}
|
||||
|
||||
// Create temp directory if it doesn't exist
|
||||
fs.ensureDirSync(cyTmpDir)
|
||||
|
||||
// Copy projects to temp directory
|
||||
fs.copySync(projects, cyTmpDir)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user