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 Apr 27, 2021
1 parent 46e9b30 commit 60b217c
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

4 comments on commit 60b217c

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 60b217c Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.1/circle-develop-60b217cccedf28c56b0573665f0b3ee81813a4cc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 60b217c Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.1/appveyor-develop-60b217cccedf28c56b0573665f0b3ee81813a4cc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 60b217c Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.1/appveyor-develop-60b217cccedf28c56b0573665f0b3ee81813a4cc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 60b217c Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.1/circle-develop-60b217cccedf28c56b0573665f0b3ee81813a4cc/cypress.tgz

Please sign in to comment.