-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add TypeScript example. #515
Merged
Merged
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7f408b1
Add typescript folder.
sainthkh 7d49b88
Update typescript to 3.9.5.
sainthkh 05d73fa
Add custom command test.
sainthkh 03fabd6
Add tests.
sainthkh 42c4dd5
README content.
sainthkh 409b4ed
Fix test failures.
sainthkh b89a685
Test types.
sainthkh f86936a
Add CI.
sainthkh fc17cf2
Run lint.
sainthkh 51a2f36
Add newlines.
sainthkh 9fcf0f0
Update examples/fundamentals__typescript/README.Md
bahmutov 321b449
Update examples/fundamentals__typescript/cypress/types.d.ts
bahmutov ef21be5
Add comment why tsconfig.json is necessary.
sainthkh 595597a
Make test clearer.
sainthkh 61dd4ec
Example list.
sainthkh 9d600c4
Update examples/fundamentals__typescript/cypress/types.d.ts
bahmutov ba3bcef
Update examples/fundamentals__typescript/cypress/types.d.ts
bahmutov 80674f5
Update examples/fundamentals__typescript/cypress/types.d.ts
bahmutov a42194f
Merge branch '5.0.0' into ts-local
chrisbreiding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Out-of-the-box TypeScript | ||
> Write tests in TypeScript without setting up preprocessors | ||
|
||
From Cypress 4.4.0, you can write tests in TypeScript without setting up preprocessors. See [the official doc](https://on.cypress.io/typescript-support). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Test</title> | ||
</head> | ||
<body> | ||
<a href="#">click me</a> | ||
</body> | ||
</html> |
22 changes: 22 additions & 0 deletions
22
examples/fundamentals__typescript/cypress/integration/tests.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* global window */ | ||
/// <reference path="../types.d.ts" /> | ||
|
||
before(() => { | ||
// @ts-expect-error | ||
window.add = (a, b) => a + b | ||
}) | ||
|
||
describe('tests', () => { | ||
it('test custom command', () => { | ||
cy.visit('cypress/fixtures/test.html') | ||
cy.clickLink('click me') | ||
sainthkh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
it('test extending AUTWindow', () => { | ||
cy.window().then((win) => { | ||
win.add = (a, b) => a + b | ||
|
||
return win.add(2, 3) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="cypress" /> | ||
|
||
export default (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => { | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
examples/fundamentals__typescript/cypress/support/commands.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/// <reference types="cypress" /> | ||
|
||
// Copied an example command from https://on.cypress.io/custom-commands | ||
Cypress.Commands.add('clickLink', (label: string | number | RegExp) => { | ||
cy.get('a').contains(label).click() | ||
}) |
20 changes: 20 additions & 0 deletions
20
examples/fundamentals__typescript/cypress/support/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// *********************************************************** | ||
// This example support/index.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// reference code is written like below to avoid the clash in mocha types. | ||
// in most of the cases, simple <reference types="cypress" /> will do. | ||
/// <reference path="../../../node_modules/cypress/types/cy-blob-util.d.ts" /> | ||
/// <reference path="../../../node_modules/cypress/types/cy-bluebird.d.ts" /> | ||
/// <reference path="../../../node_modules/cypress/types/cy-moment.d.ts" /> | ||
/// <reference path="../../../node_modules/cypress/types/cy-minimatch.d.ts" /> | ||
/// <reference path="../../../node_modules/cypress/types/lodash/index.d.ts" /> | ||
/// <reference path="../../../node_modules/cypress/types/sinon/index.d.ts" /> | ||
/// <reference path="../../../node_modules/cypress/types/jquery/index.d.ts" /> | ||
/// <reference path="../../../node_modules/cypress/types/cypress.d.ts" /> | ||
/// <reference path="../../../node_modules/cypress/types/cypress-type-helpers.d.ts" /> | ||
/// <reference path="../../../node_modules/cypress/types/cypress-global-vars.d.ts" /> | ||
|
||
declare namespace Cypress { | ||
interface Chainable<Subject=any> { | ||
bahmutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// let TS know we have a custom command cy.clickLink(...) | ||
clickLink(label: string | number | RegExp): void | ||
bahmutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
interface ApplicationWindow { | ||
bahmutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
add(a: number, b: number): number | ||
bahmutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "with-typescript", | ||
"version": "1.0.0", | ||
"description": "Use out-of-the-box TypeScript with TypeScript", | ||
"scripts": { | ||
"cypress:open": "../../node_modules/.bin/cypress open", | ||
"precypress:run": "npm run lint", | ||
"cypress:run": "../../node_modules/.bin/cypress run", | ||
"lint": "../../node_modules/.bin/tslint --project ./tsconfig.json", | ||
"postlint": "npm run tsc", | ||
"test:ci": "../../node_modules/.bin/cypress run", | ||
"test:ci:windows": "bin-up cypress run", | ||
"tsc": "../../node_modules/.bin/tsc --pretty --noEmit" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
bahmutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"include": [ | ||
"cypress/integration/*.ts", | ||
"cypress/integration/**/*.ts", | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move it to fixtures test.html file :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It cannot be removed entirely because it shows that the type of Test Runner
window
fails because it's not extended.I rewrote the test like below: