mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-20 07:09:46 -05:00
strict typescript options in launcher project
This commit is contained in:
Vendored
+11
@@ -13,6 +13,17 @@ type LauncherLaunch = (browsers?: any[]) => Promise<any>
|
||||
|
||||
type LauncherApi = LauncherLaunch & ExtraLauncherMethods
|
||||
|
||||
type Browser = {
|
||||
name: string,
|
||||
re: RegExp,
|
||||
profile: boolean,
|
||||
binary: string,
|
||||
executable: string,
|
||||
version?: string,
|
||||
majorVersion?: string,
|
||||
page?: string
|
||||
}
|
||||
|
||||
// missing type definitions for 3rd party libraries
|
||||
// https://glebbahmutov.com/blog/trying-typescript/#manual-types-for-3rd-party-libraries
|
||||
declare module 'execa' {
|
||||
|
||||
@@ -4,7 +4,7 @@ import cp = require('child_process')
|
||||
|
||||
type FoundBrowser = {
|
||||
name: string,
|
||||
path: string
|
||||
path?: string
|
||||
}
|
||||
|
||||
const browserNotFoundErr = (browsers:FoundBrowser[], name: string): BrowserNotFoundError => {
|
||||
@@ -26,6 +26,10 @@ export function launch (browsers:FoundBrowser[],
|
||||
throw browserNotFoundErr(browsers, name)
|
||||
}
|
||||
|
||||
if (!browser.path) {
|
||||
throw new Error(`Found browser ${name} is missing path`)
|
||||
}
|
||||
|
||||
if (url) {
|
||||
args.unshift(url)
|
||||
}
|
||||
|
||||
@@ -6,16 +6,6 @@ import _ = require('lodash')
|
||||
import os = require('os')
|
||||
import Promise = require('bluebird')
|
||||
|
||||
type Browser = {
|
||||
name: string,
|
||||
re: RegExp,
|
||||
profile: boolean,
|
||||
binary: string,
|
||||
executable: string,
|
||||
version?: string,
|
||||
majorVersion?: string
|
||||
}
|
||||
|
||||
const browsers:Browser[] = [
|
||||
{
|
||||
name: 'chrome',
|
||||
@@ -88,7 +78,10 @@ function checkOneBrowser(browser:Browser) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = () => {
|
||||
/** returns list of detected browsers */
|
||||
function detectBrowsers (): Promise<Browser[]> {
|
||||
return Promise.map(browsers, checkOneBrowser)
|
||||
.then(_.compact)
|
||||
.then(_.compact) as Promise<Browser[]>
|
||||
}
|
||||
|
||||
export default detectBrowsers
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import {writeJson} from 'fs-extra'
|
||||
import {launch} from './browsers'
|
||||
import detect from './detect'
|
||||
|
||||
const Promise = require('bluebird')
|
||||
const detect = require('./detect')
|
||||
|
||||
const missingConfig = () =>
|
||||
Promise.reject(new Error('You must provide a path to a config file.'))
|
||||
|
||||
const wrap = all => ({
|
||||
launch: (name, url, args = []) =>
|
||||
const wrap = (all:Browser[]) => ({
|
||||
launch: (name:string, url:string, args = []) =>
|
||||
launch(all, name, url, args)
|
||||
})
|
||||
|
||||
const init = browsers =>
|
||||
const init = (browsers:Browser[]) =>
|
||||
browsers ? wrap(browsers) : detect().then(wrap)
|
||||
|
||||
const api: LauncherApi = init as LauncherApi
|
||||
const api: LauncherApi = init as any as LauncherApi
|
||||
|
||||
const update = (pathToConfig) => {
|
||||
const update = (pathToConfig?: string) => {
|
||||
if (!pathToConfig) {
|
||||
return missingConfig()
|
||||
}
|
||||
|
||||
// detect the browsers and set the config
|
||||
const saveBrowsers = browers =>
|
||||
const saveBrowsers = (browers:Browser[]) =>
|
||||
writeJson(pathToConfig, browers, {spaces: 2})
|
||||
|
||||
return detect()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
require("../spec_helper")
|
||||
detect = require('../../lib/detect')
|
||||
detect = require('../../lib/detect').default
|
||||
|
||||
describe "browser detection", ->
|
||||
it 'detects available browsers', ->
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
// "strict": true, /* Enable all strict type-checking options. */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"strictNullChecks": true, /* Enable strict null checks. */
|
||||
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
|
||||
Reference in New Issue
Block a user