Skip to content

Commit 8a83bb1

Browse files
lmiller1990Barthélémy Ledoux
authored andcommitted
fix(npm/react): support transpiling typescript files in support (#16197)
* 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>
1 parent 112e658 commit 8a83bb1

File tree

10 files changed

+103
-1
lines changed

10 files changed

+103
-1
lines changed

npm/react/examples.env

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
/examples/nextjs
33
# /examples/nextjs-webpack-5
44
/examples/react-scripts
5+
/examples/react-scripts-typescript
56
/examples/webpack-file
67
/examples/react-scripts-folder
78
/examples/using-babel-typescript
89
/examples/webpack-options
910
# /examples/rollup
10-
/examples/sass-and-ts
11+
/examples/sass-and-ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"video": false,
3+
"testFiles": "**/*cy-spec.tsx",
4+
"viewportWidth": 500,
5+
"viewportHeight": 800,
6+
"componentFolder": "src"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference types="cypress" />
2+
describe('integration spec', () => {
3+
it('works', () => {
4+
expect(1).to.equal(1)
5+
})
6+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const injectDevServer = require('@cypress/react/plugins/react-scripts')
2+
3+
module.exports = (on, config) => {
4+
injectDevServer(on, config)
5+
6+
return config
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare namespace Cypress {
2+
interface Chainable {
3+
/**
4+
* Custom command to select DOM element by data-cy attribute.
5+
* @example cy.dataCy('greeting')
6+
*/
7+
clickButtonWithText(value: string): Chainable
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="cypress" />
2+
3+
Cypress.Commands.add('clickButtonWithText', (value: string) => {
4+
return cy.get('button').contains(value).click()
5+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"cy:open": "node ../../../../scripts/cypress open-ct",
5+
"start": "react-scripts start",
6+
"test": "node ../../../../scripts/cypress run-ct"
7+
},
8+
"devDependencies": {
9+
"@cypress/react": "file:../../dist",
10+
"@types/react": "^17.0.0",
11+
"@types/react-dom": "^17.0.0",
12+
"cypress-circleci-reporter": "0.2.0",
13+
"react": "^17.0.1",
14+
"react-dom": "^17.0.1",
15+
"react-scripts": "4.0.3",
16+
"typescript": "^4.2.3"
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="../cypress/support/index.d.ts" />
2+
3+
import React from 'react'
4+
import { mount } from '@cypress/react'
5+
6+
it('works', () => {
7+
const click = cy.stub()
8+
const App = () => {
9+
return (<button onClick={click}>Button!</button>)
10+
}
11+
12+
mount(<App />)
13+
cy.clickButtonWithText('Button!').then(() => {
14+
expect(click).to.have.been.calledWith()
15+
})
16+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
9+
"allowJs": true,
10+
"skipLibCheck": true,
11+
"esModuleInterop": true,
12+
"allowSyntheticDefaultImports": true,
13+
"strict": true,
14+
"forceConsistentCasingInFileNames": true,
15+
"noFallthroughCasesInSwitch": true,
16+
"module": "esnext",
17+
"moduleResolution": "node",
18+
"resolveJsonModule": true,
19+
"isolatedModules": true,
20+
"noEmit": true,
21+
"jsx": "react-jsx",
22+
"types": [
23+
"cypress"
24+
]
25+
},
26+
"include": [
27+
"src"
28+
]
29+
}

npm/react/plugins/utils/get-transpile-folders.js

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ function getTranspileFolders (config) {
1111
folders.push(config.fixturesFolder)
1212
}
1313

14+
if (config.supportFolder) {
15+
folders.push(config.supportFolder)
16+
}
17+
1418
return folders
1519
}
1620

0 commit comments

Comments
 (0)