Skip to content

Commit

Permalink
chore: fix system tests types and add type checking (#20430)
Browse files Browse the repository at this point in the history
Co-authored-by: Emily Rohrbough  <emilyrohrbough@users.noreply.github.com>
  • Loading branch information
flotwig and emilyrohrbough authored Mar 3, 2022
1 parent a8fdcdc commit 731c7fe
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions system-tests/globals.d.ts
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 3 additions & 3 deletions system-tests/lib/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions system-tests/lib/resultsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion system-tests/lib/serverStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
12 changes: 7 additions & 5 deletions system-tests/lib/system-tests.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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) => {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion system-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
27 changes: 19 additions & 8 deletions system-tests/test/deprecated_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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', {
Expand All @@ -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', {
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion system-tests/test/firefox_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('e2e firefox', function () {
config: {
video: false,
},
exit: false,
onRun: (exec) => {
return exec()
.then(() => {
Expand Down
8 changes: 4 additions & 4 deletions system-tests/test/headless_spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import systemTests from '../lib/system-tests'
import systemTests, { BrowserName } from '../lib/system-tests'

describe('e2e headless', function () {
systemTests.setup()
Expand All @@ -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 }) => {
Expand Down Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion system-tests/test/request_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions system-tests/test/testConfigOverrides_spec.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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'],
]
Expand Down
23 changes: 23 additions & 0 deletions system-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
29 changes: 17 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -18687,10 +18692,10 @@ execa@1.0.0, execa@^1.0.0:
signal-exit "^3.0.0"
strip-eof "^1.0.0"

execa@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.0.tgz#7f37d6ec17f09e6b8fc53288611695b6d12b9daf"
integrity sha512-JbDUxwV3BoT5ZVXQrSVbAiaXhXUkIwvbhPIwZ0N13kX+5yCzOhUNdocxB/UQRuYOHRYYwAxKYwJYc0T4D12pDA==
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"
Expand All @@ -18702,10 +18707,10 @@ execa@4.0.0:
signal-exit "^3.0.2"
strip-final-newline "^2.0.0"

execa@4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.2.tgz#ad87fb7b2d9d564f70d2b62d511bee41d5cbb240"
integrity sha512-QI2zLa6CjGWdiQsmSkZoGtDx2N+cQIGb3yNolGTdjSQzydzLgYYf8LRuagp7S7fPimjcrzUDSUFd/MgzELMi4Q==
execa@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.0.tgz#7f37d6ec17f09e6b8fc53288611695b6d12b9daf"
integrity sha512-JbDUxwV3BoT5ZVXQrSVbAiaXhXUkIwvbhPIwZ0N13kX+5yCzOhUNdocxB/UQRuYOHRYYwAxKYwJYc0T4D12pDA==
dependencies:
cross-spawn "^7.0.0"
get-stream "^5.0.0"
Expand All @@ -18717,10 +18722,10 @@ 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==
execa@4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.2.tgz#ad87fb7b2d9d564f70d2b62d511bee41d5cbb240"
integrity sha512-QI2zLa6CjGWdiQsmSkZoGtDx2N+cQIGb3yNolGTdjSQzydzLgYYf8LRuagp7S7fPimjcrzUDSUFd/MgzELMi4Q==
dependencies:
cross-spawn "^7.0.0"
get-stream "^5.0.0"
Expand Down

3 comments on commit 731c7fe

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 731c7fe Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.2/linux-x64/circle-develop-731c7febd1d130a7bd0a8d7ac863eecb1a62c648/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 731c7fe Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.2/win32-x64/circle-develop-731c7febd1d130a7bd0a8d7ac863eecb1a62c648/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 731c7fe Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.2/darwin-x64/circle-develop-731c7febd1d130a7bd0a8d7ac863eecb1a62c648/cypress.tgz

Please sign in to comment.