Skip to content

Commit

Permalink
fix(npm/react): support transpiling typescript files in support (#16197)
Browse files Browse the repository at this point in the history
* fix: transpile typescript in supportFolder for react-scripts

* lint

* lint

* lint

* lint

* update package.json deps

* Remove yarn lock

* inject dev serverg

* add circleci reporter

Co-authored-by: Barthélémy Ledoux <bart@cypress.io>
  • Loading branch information
lmiller1990 and elevatebart committed May 5, 2021
1 parent 112e658 commit 8a83bb1
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 1 deletion.
3 changes: 2 additions & 1 deletion npm/react/examples.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/examples/nextjs
# /examples/nextjs-webpack-5
/examples/react-scripts
/examples/react-scripts-typescript
/examples/webpack-file
/examples/react-scripts-folder
/examples/using-babel-typescript
/examples/webpack-options
# /examples/rollup
/examples/sass-and-ts
/examples/sass-and-ts
7 changes: 7 additions & 0 deletions npm/react/examples/react-scripts-typescript/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"video": false,
"testFiles": "**/*cy-spec.tsx",
"viewportWidth": 500,
"viewportHeight": 800,
"componentFolder": "src"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference types="cypress" />
describe('integration spec', () => {
it('works', () => {
expect(1).to.equal(1)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const injectDevServer = require('@cypress/react/plugins/react-scripts')

module.exports = (on, config) => {
injectDevServer(on, config)

return config
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare namespace Cypress {
interface Chainable {
/**
* Custom command to select DOM element by data-cy attribute.
* @example cy.dataCy('greeting')
*/
clickButtonWithText(value: string): Chainable
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="cypress" />

Cypress.Commands.add('clickButtonWithText', (value: string) => {
return cy.get('button').contains(value).click()
})
18 changes: 18 additions & 0 deletions npm/react/examples/react-scripts-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"private": true,
"scripts": {
"cy:open": "node ../../../../scripts/cypress open-ct",
"start": "react-scripts start",
"test": "node ../../../../scripts/cypress run-ct"
},
"devDependencies": {
"@cypress/react": "file:../../dist",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"cypress-circleci-reporter": "0.2.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.3",
"typescript": "^4.2.3"
}
}
16 changes: 16 additions & 0 deletions npm/react/examples/react-scripts-typescript/src/App.cy-spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="../cypress/support/index.d.ts" />

import React from 'react'
import { mount } from '@cypress/react'

it('works', () => {
const click = cy.stub()
const App = () => {
return (<button onClick={click}>Button!</button>)
}

mount(<App />)
cy.clickButtonWithText('Button!').then(() => {
expect(click).to.have.been.calledWith()
})
})
29 changes: 29 additions & 0 deletions npm/react/examples/react-scripts-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"types": [
"cypress"
]
},
"include": [
"src"
]
}
4 changes: 4 additions & 0 deletions npm/react/plugins/utils/get-transpile-folders.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function getTranspileFolders (config) {
folders.push(config.fixturesFolder)
}

if (config.supportFolder) {
folders.push(config.supportFolder)
}

return folders
}

Expand Down

0 comments on commit 8a83bb1

Please sign in to comment.