Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit 9093fec

Browse files
committed
feat: move to TS
1 parent 3cb1437 commit 9093fec

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ node_js:
1212
- '10'
1313
script:
1414
- npm run lint
15+
- npm run transpile
1516
- npm test -- --record
1617
after_success:
1718
- npm run semantic-release

cypress/support/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
// https://on.cypress.io/configuration
1414
// ***********************************************************
1515

16-
import '../../lib'
16+
import '../../dist'

lib/index.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22
// but for now have to document methods in both places
33
// like this: import {mount} from './index'
44

5+
interface ReactModule {
6+
name: string
7+
type: string
8+
location: string
9+
source: string
10+
}
11+
512
declare namespace Cypress {
613
interface Cypress {
714
stylesCache: any
815
React: string
916
ReactDOM: string
1017
Styles: string
18+
modules: ReactModule[]
1119
}
20+
1221
// NOTE: By default, avoiding React.Component/Element typings
1322
// for many cases, we don't want to import @types/react
14-
interface Chainable<Subject = any> {
23+
interface Chainable<Subject> {
24+
state: (key) => any,
1525
injectReactDOM: () => Chainable<void>
1626
copyComponentStyles: (component: Symbol) => Chainable<void>
1727
/**

lib/index.js renamed to lib/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
/// <reference path="./index.d.ts" />
2+
13
// having weak reference to styles prevents garbage collection
24
// and "losing" styles when the next test starts
3-
// import { stylesCache, setXMLHttpRequest, setAlert } from './index'
4-
55
const stylesCache = new Map()
66

77
const setXMLHttpRequest = w => {
88
// by grabbing the XMLHttpRequest from app's iframe
99
// and putting it here - in the test iframe
1010
// we suddenly get spying and stubbing 😁
11+
// @ts-ignore
1112
window.XMLHttpRequest = w.XMLHttpRequest
1213
return w
1314
}
@@ -40,7 +41,8 @@ Cypress.Commands.add('injectReactDOM', () => {
4041
})
4142
})
4243

43-
cy.stylesCache = stylesCache
44+
Cypress.stylesCache = stylesCache
45+
4446
/** Caches styles from previously compiled components for reuse
4547
@function cy.copyComponentStyles
4648
@param {Object} component
@@ -54,11 +56,11 @@ Cypress.Commands.add('copyComponentStyles', component => {
5456
let styles = document.querySelectorAll('head style')
5557
if (styles.length) {
5658
cy.log('injected %d styles', styles.length)
57-
cy.stylesCache.set(hash, styles)
59+
Cypress.stylesCache.set(hash, styles)
5860
} else {
5961
cy.log('No styles injected for this component, checking cache')
60-
if (cy.stylesCache.has(hash)) {
61-
styles = cy.stylesCache.get(hash)
62+
if (Cypress.stylesCache.has(hash)) {
63+
styles = Cypress.stylesCache.get(hash)
6264
} else {
6365
styles = null
6466
}
@@ -67,9 +69,12 @@ Cypress.Commands.add('copyComponentStyles', component => {
6769
return
6870
}
6971
const parentDocument = window.parent.document
72+
// hmm, is this really project name?
73+
// @ts-ignore
7074
const projectName = Cypress.config('projectName')
7175
const appIframeId = "Your App: '" + projectName + "'"
7276
const appIframe = parentDocument.getElementById(appIframeId)
77+
// @ts-ignore
7378
var head = appIframe.contentDocument.querySelector('head')
7479
styles.forEach(function (style) {
7580
head.appendChild(style)

tsconfig.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/* Basic Options */
44
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
55
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6-
// "lib": [], /* Specify library files to be included in the compilation: */
7-
"allowJs": true, /* Allow javascript files to be compiled. */
6+
"lib": ["es2015", "dom"], /* Specify library files to be included in the compilation: */
7+
"allowJs": false, /* Allow javascript files to be compiled. */
88
// "checkJs": true, /* Report errors in .js files. */
99
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
1010
// "declaration": true, /* Generates corresponding '.d.ts' file. */
@@ -19,7 +19,7 @@
1919
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
2020

2121
/* Strict Type-Checking Options */
22-
"strict": false /* Enable all strict type-checking options. */
22+
"strict": false, /* Enable all strict type-checking options. */
2323
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
2424
// "strictNullChecks": true, /* Enable strict null checks. */
2525
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
@@ -38,7 +38,7 @@
3838
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
3939
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
4040
// "typeRoots": [], /* List of folders to include type definitions from. */
41-
// "types": [], /* Type declaration files to be included in compilation. */
41+
"types": ["cypress"] /* Type declaration files to be included in compilation. */
4242
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
4343
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
4444

@@ -53,6 +53,7 @@
5353
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
5454
},
5555
"include": [
56-
"lib/index.js"
56+
"lib/index.ts",
57+
"lib/index.d.ts"
5758
]
5859
}

0 commit comments

Comments
 (0)