Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(graphql): make tsconfig more strict #17909

Merged
merged 21 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/graphql/src/actions/BaseActions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { BaseContext } from '../context/BaseContext'
import type { RunGroup } from '../entities/run'
import type { FoundBrowser } from '@packages/launcher'
import type { FoundBrowser, OpenProjectLaunchOptions, FullConfig, LaunchOpts, LaunchArgs } from '@packages/types'
import type { LocalProject } from '../entities'
import type { LaunchArgs, LaunchOpts, OpenProject } from '@packages/server/lib/open_project'
import type { Cfg, OpenProjectLaunchOptions } from '@packages/server/lib/project-base'
import type { BrowserContract } from '../contracts/BrowserContract'

/**
Expand Down Expand Up @@ -31,7 +29,11 @@ export abstract class BaseActions {
abstract getRecordKeys (payload: { projectId: string, authToken: string }): Promise<string[]>
abstract getBrowsers (): Promise<FoundBrowser[]>

abstract initializeOpenProject (args: LaunchArgs, options: OpenProjectLaunchOptions): Promise<OpenProject>
abstract launchOpenProject (browser: BrowserContract, spec: Cypress.Cypress['spec'], options: LaunchOpts): Promise<void>
abstract resolveOpenProjectConfig (): Cfg | null
abstract initializeOpenProject (args: LaunchArgs, options: OpenProjectLaunchOptions): Promise<void>
abstract launchOpenProject (
browser: BrowserContract,
spec: any, // Cypress.Cypress['spec'],
options: LaunchOpts
): Promise<void>
abstract resolveOpenProjectConfig (): FullConfig | null
}
2 changes: 1 addition & 1 deletion packages/graphql/src/constants/browserConstants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { enumType } from 'nexus'
import { BROWSER_FAMILY } from '@packages/launcher/lib/types'
import { BROWSER_FAMILY } from '@packages/types'

export const BrowserFamilyEnum = enumType({
name: 'BrowserFamily',
Expand Down
3 changes: 1 addition & 2 deletions packages/graphql/src/context/BaseContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { LaunchArgs } from '@packages/server/lib/open_project'
import type { OpenProjectLaunchOptions } from '@packages/server/lib/project-base'
import type { LaunchArgs, OpenProjectLaunchOptions } from '@packages/types'
import type { BaseActions } from '../actions/BaseActions'
import { App, Wizard, NavigationMenu, LocalProject, Viewer, DashboardProject } from '../entities'

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/contracts/BrowserContract.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { FoundBrowser } from '@packages/launcher'
import type { FoundBrowser } from '@packages/types'

export type BrowserContract = FoundBrowser
2 changes: 1 addition & 1 deletion packages/graphql/src/entities/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const mutation = mutationType({
version: chrome.version,
}

const spec: Cypress.Cypress['spec'] = {
const spec: any = { // Cypress.Cypress['spec'] = {
name: '',
absolute: '',
relative: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/entities/ResolvedConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { enumType } from 'nexus'
import { nxs, NxsResult } from 'nexus-decorators'
import Debug from 'debug'
import type { ResolvedConfigurationOptions, ResolvedFromConfig } from '@packages/server/lib/config'
import type { ResolvedConfigurationOptions, ResolvedFromConfig } from '@packages/types'

const debug = Debug('cypress:graphql:resolved-config')

Expand Down
27 changes: 24 additions & 3 deletions packages/graphql/test/integration/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import axios from 'axios'
import type { FoundBrowser } from '@packages/launcher'
import type { FoundBrowser, FullConfig, LaunchArgs, OpenProjectLaunchOptions } from '@packages/types'
import { BaseActions, BaseContext, DashboardProject, LocalProject, Viewer, Wizard } from '../../src'
import { startGraphQLServer, closeGraphQLServer, setServerContext } from '../../src/server'

interface TestContextInjectionOptions {
wizard?: Wizard
launchArgs?: LaunchArgs
launchOptions?: OpenProjectLaunchOptions
}

export class TestActions extends BaseActions {
Expand Down Expand Up @@ -44,6 +46,14 @@ export class TestActions extends BaseActions {
return []
}

async launchOpenProject () {}
async initializeOpenProject () {}
resolveOpenProjectConfig (): FullConfig {
return {
resolved: {},
}
}

async getBrowsers () {
const browser: FoundBrowser = {
displayName: 'chrome',
Expand All @@ -67,8 +77,19 @@ export class TestContext extends BaseContext {
readonly actions: BaseActions
viewer = null

constructor ({ wizard }: TestContextInjectionOptions = {}) {
super()
constructor ({ wizard, launchArgs, launchOptions }: TestContextInjectionOptions = {}) {
super(launchArgs || {
config: {},
cwd: '/current/working/dir',
_: ['/current/working/dir'],
projectRoot: '/project/root',
invokedFromCli: false,
browser: null,
testingType: 'e2e',
project: '/project/root',
os: 'linux',
}, launchOptions || {})

this.actions = new TestActions(this)
if (wizard) {
this.wizard = wizard
Expand Down
13 changes: 10 additions & 3 deletions packages/graphql/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
"extends": "../ts/tsconfig.json",
"include": [
"src/*.ts",
"src/**/*.ts"
"src/**/*.ts",
"script/*.ts",
],
"compilerOptions": {
"importHelpers": true
"importHelpers": true,
"strict": true,
"noImplicitAny": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"noUncheckedIndexedAccess": true,
"importsNotUsedAsValues": "error"
},
"files": [
"./../ts/index.d.ts"
"../../cli/types/index.d.ts"
],
}
2 changes: 1 addition & 1 deletion packages/launcher/lib/browsers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from './log'
import * as cp from 'child_process'
import type { Browser, FoundBrowser } from './types'
import type { Browser, FoundBrowser } from '@packages/types'

// Chrome started exposing CDP 1.3 in 64
const MIN_CHROME_VERSION = 64
Expand Down
6 changes: 0 additions & 6 deletions packages/launcher/lib/darwin/detection-workaround.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/launcher/lib/darwin/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { findApp, FindAppParams } from './util'
import type { Browser, DetectedBrowser } from '../types'
import type { Browser, DetectedBrowser } from '@packages/types'
import * as linuxHelper from '../linux'
import { log } from '../log'
import { merge } from 'ramda'
Expand Down
2 changes: 1 addition & 1 deletion packages/launcher/lib/darwin/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as os from 'os'
import * as path from 'path'
import * as plist from 'plist'
import * as semver from 'semver'
import type { FoundBrowser } from '../types'
import type { FoundBrowser } from '@packages/types'
import * as findSystemNode from '@packages/server/lib/util/find_system_node'

/** parses Info.plist file from given application and returns a property */
Expand Down
2 changes: 2 additions & 0 deletions packages/launcher/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import type {
Browser,
DetectedBrowser,
FoundBrowser,
} from '@packages/types'
import type {
NotDetectedAtPathError,
NotInstalledError, PathData,
} from './types'
Expand Down
3 changes: 2 additions & 1 deletion packages/launcher/lib/linux/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { log } from '../log'
import { partial, trim, tap, prop } from 'ramda'
import type { FoundBrowser, Browser, PathData } from '../types'
import type { PathData } from '../types'
import type { FoundBrowser, Browser } from '@packages/types'
import { notInstalledErr } from '../errors'
import { utils } from '../utils'
import os from 'os'
Expand Down
67 changes: 1 addition & 66 deletions packages/launcher/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,6 @@
import type { ChildProcess } from 'child_process'
import type Bluebird from 'bluebird'

// TODO: Clean up this file

// TODO: some of these types can be combined with cli/types/index.d.ts
export const BROWSER_FAMILY = ['chromium', 'firefox'] as const

type BrowserName = 'electron' | 'chrome' | 'chromium' | 'firefox' | string

export type BrowserChannel = 'stable' | 'canary' | 'beta' | 'dev' | 'nightly' | string

export type BrowserFamily = typeof BROWSER_FAMILY[number]

export type PlatformName = 'darwin' | 'linux' | 'win32'

/**
* Represents a typical browser to try to detect and turn into a `FoundBrowser`.
*/
export type Browser = {
/**
* Short browser name.
*/
name: BrowserName
/**
* The underlying engine for this browser.
*/
family: BrowserFamily
/**
* The release channel of the browser.
*/
channel: BrowserChannel
/**
* Human-readable browser name.
*/
displayName: string
/** RegExp to use to extract version from something like "Google Chrome 58.0.3029.110" */
versionRegex: RegExp
/** If set, this is the base path that will be used for setting userDataDir. Useful for creating profiles in snap confinement. */
profilePath?: string
/** A single binary name or array of binary names for this browser. Not used on Windows. */
binary: string | string[]
/** optional warning that will be shown in the GUI */
warning?: string
/** optional info that will be shown in the GUI */
info?: string
/** if set, the majorVersion must be >= this to be run in Cypress */
minSupportedVersion?: number
}

/**
* Represents a real browser that exists on the user's system.
*/
export type FoundBrowser = Omit<Browser, 'versionRegex' | 'binary'> & {
path: string
version: string
majorVersion?: string
/** is this a user-supplied browser? */
custom?: boolean
unsupportedVersion?: boolean
}

/**
* Partial browser object, returned by an OS-specific launcher helper.
*/
export type DetectedBrowser = Pick<FoundBrowser, 'name' | 'path' | 'version'>

// all common type definition for this module
import type { Browser, FoundBrowser } from '@packages/types'

export type NotInstalledError = Error & { notInstalled: boolean }

Expand Down
3 changes: 2 additions & 1 deletion packages/launcher/lib/windows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { tap, trim, prop } from 'ramda'
import { get } from 'lodash'
import { notInstalledErr } from '../errors'
import { log } from '../log'
import type { Browser, FoundBrowser, PathData } from '../types'
import type { PathData } from '../types'
import type { Browser, FoundBrowser } from '@packages/types'
import { utils } from '../utils'

function formFullAppPath (name: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/launcher/test/unit/windows_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Bluebird from 'bluebird'
import fse from 'fs-extra'
import os from 'os'
import snapshot from 'snap-shot-it'
import { Browser } from '../../lib/types'
import type { Browser } from '@packages/types'
import { detectByPath } from '../../lib/detect'
import { goalBrowsers } from '../fixtures'

Expand Down
3 changes: 3 additions & 0 deletions packages/launcher/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"include": [
"**/*.ts"
],
"compilerOptions": {
"skipLibCheck": true
},
"files": [
"./../ts/index.d.ts"
],
Expand Down
3 changes: 2 additions & 1 deletion packages/server-ct/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */
import browsers from '@packages/server/lib/browsers'
import { LaunchArgs, openProject } from '@packages/server/lib/open_project'
import type { LaunchArgs } from '@packages/types'
import { openProject } from '@packages/server/lib/open_project'
import chalk from 'chalk'
import human from 'human-interval'
import _ from 'lodash'
Expand Down
13 changes: 1 addition & 12 deletions packages/server/lib/automation/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@ import { v4 as uuidv4 } from 'uuid'
import { Cookies } from './cookies'
import { Screenshot } from './screenshot'
import type { BrowserPreRequest } from '@packages/proxy'

type NullableMiddlewareHook = (() => void) | null
import type { AutomationMiddleware, OnRequestEvent } from '@packages/types'

export type OnBrowserPreRequest = (browserPreRequest: BrowserPreRequest) => void

export type OnRequestEvent = (eventName: string, data: any) => void

export interface AutomationMiddleware {
onPush?: NullableMiddlewareHook
onBeforeRequest?: OnRequestEvent | null
onRequest?: OnRequestEvent | null
onResponse?: NullableMiddlewareHook
onAfterResponse?: NullableMiddlewareHook
}

export class Automation {
private requests: Record<number, (any) => void>
private middleware: AutomationMiddleware
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/browsers/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FoundBrowser } from '@packages/launcher'
import type { FoundBrowser } from '@packages/types'
import type { EventEmitter } from 'events'

export type Browser = FoundBrowser & {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/browsers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash'
import type { FoundBrowser } from '@packages/launcher'
import type { FoundBrowser } from '@packages/types'
// @ts-ignore
import errors from '../errors'
// @ts-ignore
Expand Down
15 changes: 1 addition & 14 deletions packages/server/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import R from 'ramda'
import path from 'path'
import Promise from 'bluebird'
import deepDiff from 'return-deep-diff'
import type { ResolvedConfigurationOptions, ResolvedFromConfig, ResolvedConfigurationOptionSource } from '@packages/types'

import errors from './errors'
import scaffold from './scaffold'
Expand All @@ -19,20 +20,6 @@ const debug = Debug('cypress:server:config')
import { options, breakingOptions } from './config_options'
import { getProcessEnvVars } from './util/config'

export const RESOLVED_FROM = ['plugin', 'env', 'default', 'runtime', 'config'] as const

export type ResolvedConfigurationOptionSource = typeof RESOLVED_FROM[number]

export type ResolvedFromConfig = {
from: ResolvedConfigurationOptionSource
// TODO: Generic somehow with better type safety
value: any
}

export type ResolvedConfigurationOptions = Partial<{
[x in keyof Cypress.ResolvedConfigOptions]: ResolvedFromConfig
}>

export const CYPRESS_ENV_PREFIX = 'CYPRESS_'

export const CYPRESS_ENV_PREFIX_LENGTH = 'CYPRESS_'.length
Expand Down
Loading