Skip to content

Commit

Permalink
Fixed new type errors after rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Dec 4, 2019
1 parent 64e4beb commit 68cbba8
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"@types/classnames": "2.2.9",
"@types/debug": "4.1.4",
"@types/enzyme": "3.9.1",
"@types/enzyme-adapter-react-16": "1.0.5",
"@types/execa": "0.7.2",
"@types/fs-extra": "8.0.0",
"@types/glob": "7.1.1",
Expand Down Expand Up @@ -114,6 +115,7 @@
"decaffeinate": "6.0.1",
"del": "3.0.0",
"electron-builder": "20.39.0",
"enzyme-adapter-react-16": "1.12.1",
"eslint": "6.1.0",
"eslint-plugin-cypress": "2.6.0",
"eslint-plugin-json-format": "2.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/reporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"css-element-queries": "1.2.0",
"enzyme": "3.9.0",
"enzyme-adapter-react-16": "1.12.1",
"font-awesome": "4.7.0",
"jsdom": "14.1.0",
"lodash": "4.17.15",
"markdown-it": "6.1.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/reporter/src/header/header.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { ReactElement } from 'react'
import { shallow } from 'enzyme'
import sinon, { SinonSpy } from 'sinon'

Expand All @@ -24,7 +24,7 @@ describe('<Header />', () => {
it('renders a tooltip around focus tests button', () => {
const title = shallow(<Header appState={appState} statsStore={statsStore} />)
.find('Tooltip')
.prop('title')
.prop<ReactElement>('title')

const component = shallow(title)

Expand Down
2 changes: 1 addition & 1 deletion packages/reporter/src/lib/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class Scroller {
this._container = null
this._userScroll = true
this._userScrollCount = 0
clearTimeout(this._countUserScrollsTimeout)
clearTimeout(this._countUserScrollsTimeout as TimeoutID)
this._countUserScrollsTimeout = undefined
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"cross-env": "5.2.1",
"enzyme": "3.9.0",
"enzyme-adapter-react-16": "1.12.1",
"font-awesome": "4.7.0",
"jsdom": "14.1.0",
"lodash": "4.17.15",
"mobx": "5.11.0",
Expand Down
32 changes: 23 additions & 9 deletions packages/web-config/node-jsdom-setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import mockRequire from 'mock-require'
import { JSDOM } from 'jsdom'
import * as ansiEscapes from 'ansi-escapes'
import enzyme from 'enzyme'
import EnzymeAdapter from 'enzyme-adapter-react-16'
import ChaiEnzyme from 'chai-enzyme'

declare global {
module NodeJS {
Expand All @@ -10,11 +13,19 @@ declare global {
}
}

interface RegisterDeps {
enzyme: typeof enzyme
EnzymeAdapter: typeof EnzymeAdapter
chaiEnzyme: typeof ChaiEnzyme
}

type TimeoutID = number

export const register = ({
enzyme,
EnzymeAdapter,
chaiEnzyme,
}) => {
}: RegisterDeps) => {
const jsdom = new JSDOM('<!doctype html><html><body></body></html>')
const { window } = jsdom

Expand All @@ -23,28 +34,31 @@ export const register = ({
// const chaiEnzyme = require('chai-enzyme')

global.window = window
global.document = window.document
window.Selection = { prototype: { isCollapsed: {} } }
global.document = window.document;

// DOMWindow doesn't have Selection yet.
(window as any).Selection = { prototype: { isCollapsed: {} } }

global.navigator = {
userAgent: 'node.js',
}

global.requestAnimationFrame = function (callback) {
global.requestAnimationFrame = function (callback: ((...args: any[]) => void)) {
return setTimeout(callback, 0)
}

global.cancelAnimationFrame = function (id) {
global.cancelAnimationFrame = function (id: TimeoutID) {
clearTimeout(id)
}

Object.keys(window.document.defaultView).forEach((property) => {
Object.keys(window.document.defaultView as Record<string, any>).forEach((property) => {
if (
property === 'localStorage' ||
property === 'sessionStorage' ||
typeof global[property] !== 'undefined'
) return

global[property] = window.document.defaultView[property]
global[property] = (window.document.defaultView as Record<string, any>)[property]
})

// enzyme, and therefore chai-enzyme, needs to be required after
Expand All @@ -62,7 +76,7 @@ export const register = ({
const overrideRequire = () => {
const _load = Module._load

Module._load = function (...args) {
Module._load = function (...args: any[]) {
let browserPkg = args

// Follow browser-field spec for importing modules
Expand Down Expand Up @@ -93,7 +107,7 @@ after(() => {
process.stdout.write(ansiEscapes.cursorShow)
})

export const returnMockRequire = (name, modExport = {}) => {
export const returnMockRequire = (name: string, modExport: object = {}) => {
mockRequire(name, modExport)

return require(name)
Expand Down
2 changes: 2 additions & 0 deletions packages/web-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"@babel/register": "7.4.4",
"@types/copy-webpack-plugin": "5.0.0",
"@types/html-webpack-plugin": "3.2.0",
"@types/jsdom": "^12.2.4",
"@types/mock-require": "^2.0.0",
"@types/webpack": "4.4.25",
"ansi-escapes": "4.3.0",
"autoprefixer": "9.6.1",
Expand Down

0 comments on commit 68cbba8

Please sign in to comment.