mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-26 00:50:41 -05:00
chore: fix system tests types and add type checking (#20430)
Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
This commit is contained in:
+1
-1
@@ -62,7 +62,7 @@
|
||||
"test-unit": "lerna exec yarn test-unit --ignore \"'{@packages/{desktop-gui,driver,root,static,web-config,net-stubbing,rewriter,ui-components},@cypress/{webpack-dev-server,eslint-plugin-dev}}'\"",
|
||||
"pretest-watch": "yarn ensure-deps",
|
||||
"test-watch": "lerna exec yarn test-watch --ignore \"'@packages/{desktop-gui,driver,root,static,web-config}'\"",
|
||||
"type-check": "node scripts/type_check",
|
||||
"type-check": "yarn lerna exec yarn type-check --scope @tooling/system-tests && node scripts/type_check",
|
||||
"verify:mocha:results": "node ./scripts/verify_mocha_results",
|
||||
"prewatch": "yarn ensure-deps",
|
||||
"watch": "lerna exec yarn watch --parallel --stream",
|
||||
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
import { expect as _expect } from 'chai'
|
||||
import _sinon from 'sinon'
|
||||
|
||||
declare global {
|
||||
// these are made global in `spec_helper`
|
||||
const expect: typeof _expect
|
||||
const sinon: typeof _sinon
|
||||
}
|
||||
@@ -174,7 +174,7 @@ export async function scaffoldProjectNodeModules (project: string, updateYarnLoc
|
||||
|
||||
const runCmd = async (cmd) => {
|
||||
console.log(`📦 Running "${cmd}" in ${projectDir}`)
|
||||
await execa.shell(cmd, { cwd: projectDir, stdio: 'inherit' })
|
||||
await execa(cmd, { cwd: projectDir, stdio: 'inherit', shell: true })
|
||||
}
|
||||
|
||||
const cacheDir = _path.join(cachedir('cy-system-tests-node-modules'), project, 'node_modules')
|
||||
@@ -326,8 +326,8 @@ export function remove () {
|
||||
|
||||
// returns the path to project fixture
|
||||
// in the cyTmpDir
|
||||
export function project (...args) {
|
||||
return this.projectPath.apply(this, args)
|
||||
export function project (name) {
|
||||
return projectPath(name)
|
||||
}
|
||||
|
||||
export function projectPath (name) {
|
||||
|
||||
@@ -2,8 +2,6 @@ import systemTests from './system-tests'
|
||||
import dayjs from 'dayjs'
|
||||
import _ from 'lodash'
|
||||
|
||||
const expect = global.expect as unknown as Chai.ExpectStatic
|
||||
|
||||
const STATIC_DATE = '2018-02-01T20:14:19.323Z'
|
||||
|
||||
const expectDurationWithin = function (obj, duration, low, high, reset) {
|
||||
|
||||
@@ -166,7 +166,7 @@ const getResponse = function (responseSchema) {
|
||||
}
|
||||
|
||||
const sendResponse = function (req, res, responseBody) {
|
||||
return new Promise((resolve) => {
|
||||
return new Promise<void>((resolve) => {
|
||||
const _writeRaw = res._writeRaw
|
||||
|
||||
res._writeRaw = function () {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
const snapshot = require('snap-shot-it')
|
||||
|
||||
import { SpawnOptions } from 'child_process'
|
||||
import type { SpawnOptions } from 'child_process'
|
||||
import stream from 'stream'
|
||||
import { expect } from './spec_helper'
|
||||
import { dockerSpawner } from './docker'
|
||||
import Express from 'express'
|
||||
|
||||
require('mocha-banner').register()
|
||||
const chalk = require('chalk').default
|
||||
@@ -13,7 +14,6 @@ const path = require('path')
|
||||
const http = require('http')
|
||||
const human = require('human-interval')
|
||||
const morgan = require('morgan')
|
||||
const express = require('express')
|
||||
const Bluebird = require('bluebird')
|
||||
const debug = require('debug')('cypress:system-tests')
|
||||
const httpsProxy = require('@packages/https-proxy')
|
||||
@@ -30,7 +30,8 @@ require(`@packages/server/lib/project-base`)
|
||||
|
||||
type CypressConfig = { [key: string]: any }
|
||||
|
||||
type BrowserName = 'electron' | 'firefox' | 'chrome'
|
||||
export type BrowserName = 'electron' | 'firefox' | 'chrome'
|
||||
| '!electron' | '!chrome' | '!firefox'
|
||||
|
||||
type ExecResult = {
|
||||
code: number
|
||||
@@ -496,7 +497,7 @@ const startServer = function (obj) {
|
||||
|
||||
ensurePort(port)
|
||||
|
||||
const app = express()
|
||||
const app = Express()
|
||||
|
||||
const srv = https ? httpsProxy.httpsServer(app) : new http.Server(app)
|
||||
|
||||
@@ -509,7 +510,7 @@ const startServer = function (obj) {
|
||||
}
|
||||
|
||||
if (obj.static) {
|
||||
app.use(express.static(path.join(__dirname, '../projects/e2e'), {}))
|
||||
app.use(Express.static(path.join(__dirname, '../projects/e2e'), {}) as Express.RequestHandler)
|
||||
}
|
||||
|
||||
return new Bluebird((resolve) => {
|
||||
@@ -692,6 +693,7 @@ const systemTests = {
|
||||
args = _.compact(args)
|
||||
|
||||
// avoid snapshot cwd issue - see /patches/snap-shot* for more information
|
||||
// @ts-ignore
|
||||
global.CACHED_CWD_FOR_SNAP_SHOT_IT = path.join(__dirname, '..')
|
||||
|
||||
return snapshot.apply(null, args)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"private": true,
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"type-check": "tsc --project .",
|
||||
"projects:yarn:install": "node ./scripts/projects-yarn-install.js",
|
||||
"test": "node ./scripts/run.js --glob-in-dir='{test,test-binary}'",
|
||||
"test:ci": "node ./scripts/run.js"
|
||||
@@ -27,6 +28,8 @@
|
||||
"@packages/server": "0.0.0-development",
|
||||
"@packages/socket": "0.0.0-development",
|
||||
"@packages/ts": "0.0.0-development",
|
||||
"@types/chai": "4.2.15",
|
||||
"@types/mocha": "9.1.0",
|
||||
"babel-loader": "8.1.0",
|
||||
"bluebird": "3.7.2",
|
||||
"body-parser": "1.19.0",
|
||||
@@ -44,7 +47,7 @@
|
||||
"dayjs": "^1.9.3",
|
||||
"debug": "^4.3.2",
|
||||
"dockerode": "3.3.1",
|
||||
"execa": "1.0.0",
|
||||
"execa": "4",
|
||||
"express": "4.17.1",
|
||||
"express-session": "1.16.1",
|
||||
"express-useragent": "1.0.15",
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// the project's config changing)
|
||||
|
||||
const _ = require('lodash')
|
||||
const execa = require('execa')
|
||||
const { execa } = require('execa')
|
||||
const util = require('util')
|
||||
const si = require('systeminformation')
|
||||
|
||||
|
||||
@@ -2,6 +2,18 @@ import systemTests from '../lib/system-tests'
|
||||
|
||||
const beforeBrowserLaunchProject = 'plugin-before-browser-launch-deprecation'
|
||||
|
||||
const includesString = (s: string) => {
|
||||
return (stdout: string) => {
|
||||
expect(stdout).to.include(s)
|
||||
}
|
||||
}
|
||||
|
||||
const excludesString = (s: string) => {
|
||||
return (stdout: string) => {
|
||||
expect(stdout).to.not.include(s)
|
||||
}
|
||||
}
|
||||
|
||||
describe('deprecated before:browser:launch args', () => {
|
||||
systemTests.setup()
|
||||
|
||||
@@ -28,8 +40,7 @@ describe('deprecated before:browser:launch args', () => {
|
||||
project: beforeBrowserLaunchProject,
|
||||
spec: 'app_spec.js',
|
||||
snapshot: true,
|
||||
stdoutInclude: 'Deprecation Warning:',
|
||||
psInclude: ['--foo', '--bar'],
|
||||
onStdout: includesString('Deprecation Warning:'),
|
||||
})
|
||||
|
||||
systemTests.it('using non-deprecated API - no warning', {
|
||||
@@ -46,8 +57,7 @@ describe('deprecated before:browser:launch args', () => {
|
||||
project: beforeBrowserLaunchProject,
|
||||
spec: 'app_spec.js',
|
||||
snapshot: true,
|
||||
stdoutExclude: 'Deprecation Warning:',
|
||||
psInclude: ['--foo', '--bar'],
|
||||
onStdout: excludesString('Deprecation Warning:'),
|
||||
})
|
||||
|
||||
systemTests.it('concat return returns once per spec', {
|
||||
@@ -64,10 +74,12 @@ describe('deprecated before:browser:launch args', () => {
|
||||
project: beforeBrowserLaunchProject,
|
||||
spec: 'app_spec.js,app_spec2.js',
|
||||
snapshot: true,
|
||||
stdoutInclude: 'Deprecation Warning:',
|
||||
onStdout: includesString('Deprecation Warning:'),
|
||||
})
|
||||
|
||||
systemTests.it('no mutate return', {
|
||||
// TODO: fix/remove this test, it should be warning but is not
|
||||
// https://github.com/cypress-io/cypress/issues/20436
|
||||
systemTests.it.skip('no mutate return', {
|
||||
// TODO: implement webPreferences.additionalArgs here
|
||||
// once we decide if/what we're going to make the implemenation
|
||||
// SUGGESTION: add this to Cypress.browser.args which will capture
|
||||
@@ -81,8 +93,7 @@ describe('deprecated before:browser:launch args', () => {
|
||||
project: beforeBrowserLaunchProject,
|
||||
spec: 'app_spec.js',
|
||||
snapshot: true,
|
||||
stdoutInclude: 'Deprecation Warning:',
|
||||
psInclude: '--foo',
|
||||
onStdout: includesString('Deprecation Warning:'),
|
||||
})
|
||||
|
||||
// TODO: these errors could be greatly improved by the code frame
|
||||
|
||||
@@ -25,7 +25,6 @@ describe('e2e firefox', function () {
|
||||
config: {
|
||||
video: false,
|
||||
},
|
||||
exit: false,
|
||||
onRun: (exec) => {
|
||||
return exec()
|
||||
.then(() => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import systemTests from '../lib/system-tests'
|
||||
import systemTests, { BrowserName } from '../lib/system-tests'
|
||||
|
||||
describe('e2e headless', function () {
|
||||
systemTests.setup()
|
||||
@@ -25,7 +25,7 @@ describe('e2e headless', function () {
|
||||
|
||||
systemTests.it('pass for browsers that do not need xvfb', {
|
||||
...baseSpec,
|
||||
browser: ['chrome', 'chrome-beta', 'firefox'],
|
||||
browser: ['chrome', 'firefox'],
|
||||
expectedExitCode: 0,
|
||||
onRun (exec) {
|
||||
return exec().then(({ stderr }) => {
|
||||
@@ -60,10 +60,10 @@ describe('e2e headless', function () {
|
||||
// "can not record video in headed mode" error
|
||||
// this trick allows us to have 1 snapshot for electron
|
||||
// and 1 for every other browser
|
||||
;[
|
||||
;([
|
||||
'electron',
|
||||
'!electron',
|
||||
].map((b) => {
|
||||
] as BrowserName[]).map((b) => {
|
||||
systemTests.it(`tests in headed mode pass in ${b}`, {
|
||||
spec: 'headless_spec.js',
|
||||
config: {
|
||||
|
||||
@@ -2,7 +2,7 @@ import bodyParser from 'body-parser'
|
||||
import cookieParser from 'cookie-parser'
|
||||
import systemTests from '../lib/system-tests'
|
||||
|
||||
let counts = null
|
||||
let counts: Record<string, number> | null = null
|
||||
|
||||
const urlencodedParser = bodyParser.urlencoded({ extended: false })
|
||||
const jsonParser = bodyParser.json()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import fs from 'fs-extra'
|
||||
import path from 'path'
|
||||
import systemTests, { expect } from '../lib/system-tests'
|
||||
import systemTests, { expect, BrowserName } from '../lib/system-tests'
|
||||
import Fixtures from '../lib/fixtures'
|
||||
|
||||
const e2ePath = Fixtures.projectPath('e2e')
|
||||
@@ -35,7 +35,7 @@ describe('testConfigOverrides', () => {
|
||||
|
||||
// window.Error throws differently for firefox. break into
|
||||
// browser permutations for snapshot comparisons
|
||||
const permutations = [
|
||||
const permutations: BrowserName[][] = [
|
||||
['chrome', 'electron'],
|
||||
['firefox'],
|
||||
]
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"extends": "../packages/ts/tsconfig.json",
|
||||
"include": [
|
||||
"test",
|
||||
"lib",
|
||||
],
|
||||
"files": [
|
||||
"../packages/ts/index.d.ts",
|
||||
"./globals.d.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"types": [
|
||||
"mocha",
|
||||
"node",
|
||||
"chai"
|
||||
],
|
||||
"noEmit": true,
|
||||
"lib": ["esnext"],
|
||||
"skipLibCheck": true,
|
||||
"noImplicitReturns": false,
|
||||
"strictNullChecks": false
|
||||
}
|
||||
}
|
||||
@@ -8140,6 +8140,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.0.0.tgz#3205bcd15ada9bc681ac20bef64e9e6df88fd297"
|
||||
integrity sha512-scN0hAWyLVAvLR9AyW7HoFF5sJZglyBsbPuHO4fv7JRvfmPBMfp1ozWqOf/e4wwPNxezBZXRfWzMb6iFLgEVRA==
|
||||
|
||||
"@types/mocha@9.1.0":
|
||||
version "9.1.0"
|
||||
resolved "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.0.tgz#baf17ab2cca3fcce2d322ebc30454bff487efad5"
|
||||
integrity sha512-QCWHkbMv4Y5U9oW10Uxbr45qMMSzl4OzijsozynUAgx3kEHUdXB00udx2dWDQ7f2TU2a2uuiFaRZjCe3unPpeg==
|
||||
|
||||
"@types/mock-fs@4.10.0":
|
||||
version "4.10.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/mock-fs/-/mock-fs-4.10.0.tgz#460061b186993d76856f669d5317cda8a007c24b"
|
||||
@@ -18687,6 +18692,21 @@ execa@1.0.0, execa@^1.0.0:
|
||||
signal-exit "^3.0.0"
|
||||
strip-eof "^1.0.0"
|
||||
|
||||
execa@4, execa@4.1.0, execa@^4.0.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/execa/-/execa-4.1.0.tgz#4e5491ad1572f2f17a77d388c6c857135b22847a"
|
||||
integrity sha512-j5W0//W7f8UxAn8hXVnwG8tLwdiUy4FJLcSupCg6maBYZDpyBvTApK7KyuI4bKj8KOh1r2YH+6ucuYtJv1bTZA==
|
||||
dependencies:
|
||||
cross-spawn "^7.0.0"
|
||||
get-stream "^5.0.0"
|
||||
human-signals "^1.1.1"
|
||||
is-stream "^2.0.0"
|
||||
merge-stream "^2.0.0"
|
||||
npm-run-path "^4.0.0"
|
||||
onetime "^5.1.0"
|
||||
signal-exit "^3.0.2"
|
||||
strip-final-newline "^2.0.0"
|
||||
|
||||
execa@4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.0.tgz#7f37d6ec17f09e6b8fc53288611695b6d12b9daf"
|
||||
@@ -18717,21 +18737,6 @@ execa@4.0.2:
|
||||
signal-exit "^3.0.2"
|
||||
strip-final-newline "^2.0.0"
|
||||
|
||||
execa@4.1.0, execa@^4.0.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/execa/-/execa-4.1.0.tgz#4e5491ad1572f2f17a77d388c6c857135b22847a"
|
||||
integrity sha512-j5W0//W7f8UxAn8hXVnwG8tLwdiUy4FJLcSupCg6maBYZDpyBvTApK7KyuI4bKj8KOh1r2YH+6ucuYtJv1bTZA==
|
||||
dependencies:
|
||||
cross-spawn "^7.0.0"
|
||||
get-stream "^5.0.0"
|
||||
human-signals "^1.1.1"
|
||||
is-stream "^2.0.0"
|
||||
merge-stream "^2.0.0"
|
||||
npm-run-path "^4.0.0"
|
||||
onetime "^5.1.0"
|
||||
signal-exit "^3.0.2"
|
||||
strip-final-newline "^2.0.0"
|
||||
|
||||
execa@^0.2.2:
|
||||
version "0.2.2"
|
||||
resolved "https://registry.yarnpkg.com/execa/-/execa-0.2.2.tgz#e2ead472c2c31aad6f73f1ac956eef45e12320cb"
|
||||
|
||||
Reference in New Issue
Block a user