From 7f408b1a750fbb837124ab3ddb1badf0d988f36c Mon Sep 17 00:00:00 2001 From: KHeo Date: Tue, 30 Jun 2020 19:09:02 +0900 Subject: [PATCH 01/18] Add typescript folder. --- examples/fundamentals__typescript/README.Md | 0 .../fundamentals__typescript/cypress.json | 1 + .../cypress/fixtures/example.json | 5 ++++ .../cypress/integration/tests.spec.ts | 1 + .../cypress/plugins/index.ts | 17 +++++++++++++ .../cypress/support/commands.ts | 25 +++++++++++++++++++ .../cypress/support/index.ts | 20 +++++++++++++++ .../fundamentals__typescript/package.json | 11 ++++++++ 8 files changed, 80 insertions(+) create mode 100644 examples/fundamentals__typescript/README.Md create mode 100644 examples/fundamentals__typescript/cypress.json create mode 100644 examples/fundamentals__typescript/cypress/fixtures/example.json create mode 100644 examples/fundamentals__typescript/cypress/integration/tests.spec.ts create mode 100644 examples/fundamentals__typescript/cypress/plugins/index.ts create mode 100644 examples/fundamentals__typescript/cypress/support/commands.ts create mode 100644 examples/fundamentals__typescript/cypress/support/index.ts create mode 100644 examples/fundamentals__typescript/package.json diff --git a/examples/fundamentals__typescript/README.Md b/examples/fundamentals__typescript/README.Md new file mode 100644 index 000000000..e69de29bb diff --git a/examples/fundamentals__typescript/cypress.json b/examples/fundamentals__typescript/cypress.json new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/examples/fundamentals__typescript/cypress.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/examples/fundamentals__typescript/cypress/fixtures/example.json b/examples/fundamentals__typescript/cypress/fixtures/example.json new file mode 100644 index 000000000..da18d9352 --- /dev/null +++ b/examples/fundamentals__typescript/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} \ No newline at end of file diff --git a/examples/fundamentals__typescript/cypress/integration/tests.spec.ts b/examples/fundamentals__typescript/cypress/integration/tests.spec.ts new file mode 100644 index 000000000..137a1e0d3 --- /dev/null +++ b/examples/fundamentals__typescript/cypress/integration/tests.spec.ts @@ -0,0 +1 @@ +/// diff --git a/examples/fundamentals__typescript/cypress/plugins/index.ts b/examples/fundamentals__typescript/cypress/plugins/index.ts new file mode 100644 index 000000000..fd170fba6 --- /dev/null +++ b/examples/fundamentals__typescript/cypress/plugins/index.ts @@ -0,0 +1,17 @@ +// *********************************************************** +// This example plugins/index.js can be used to load plugins +// +// You can change the location of this file or turn off loading +// the plugins file with the 'pluginsFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/plugins-guide +// *********************************************************** + +// This function is called when a project is opened or re-opened (e.g. due to +// the project's config changing) + +module.exports = (on, config) => { + // `on` is used to hook into various events Cypress emits + // `config` is the resolved Cypress config +} diff --git a/examples/fundamentals__typescript/cypress/support/commands.ts b/examples/fundamentals__typescript/cypress/support/commands.ts new file mode 100644 index 000000000..c1f5a772e --- /dev/null +++ b/examples/fundamentals__typescript/cypress/support/commands.ts @@ -0,0 +1,25 @@ +// *********************************************** +// This example commands.js shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add("login", (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This is will overwrite an existing command -- +// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) diff --git a/examples/fundamentals__typescript/cypress/support/index.ts b/examples/fundamentals__typescript/cypress/support/index.ts new file mode 100644 index 000000000..d68db96df --- /dev/null +++ b/examples/fundamentals__typescript/cypress/support/index.ts @@ -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') diff --git a/examples/fundamentals__typescript/package.json b/examples/fundamentals__typescript/package.json new file mode 100644 index 000000000..61398890c --- /dev/null +++ b/examples/fundamentals__typescript/package.json @@ -0,0 +1,11 @@ +{ + "name": "with-typescript", + "version": "1.0.0", + "description": "Use out-of-the-box TypeScript with TypeScript", + "scripts": { + "cypress:open": "../../node_modules/.bin/cypress open", + "cypress:run": "../../node_modules/.bin/cypress run", + "test:ci": "../../node_modules/.bin/cypress run", + "test:ci:windows": "bin-up cypress run" + } +} From 7d49b8813c124e88559d515abc251150baaa0f99 Mon Sep 17 00:00:00 2001 From: KHeo Date: Tue, 30 Jun 2020 19:12:38 +0900 Subject: [PATCH 02/18] Update typescript to 3.9.5. --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 08103652a..f5737b653 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30168,9 +30168,9 @@ } }, "typescript": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.3.3.tgz", - "integrity": "sha512-Y21Xqe54TBVp+VDSNbuDYdGw0BpoR/Q6wo/+35M8PAU0vipahnyduJWirxxdxjsAkS7hue53x2zp8gz7F05u0A==", + "version": "3.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.5.tgz", + "integrity": "sha512-hSAifV3k+i6lEoCJ2k6R2Z/rp/H3+8sdmcn5NrS3/3kE7+RyZXm9aqvxWqjEXHAd8b0pShatpcdMTvEdvAJltQ==", "dev": true }, "ua-parser-js": { diff --git a/package.json b/package.json index 54ca5d961..114c72f1e 100644 --- a/package.json +++ b/package.json @@ -132,7 +132,7 @@ "stop-only": "3.0.1", "terminal-banner": "1.1.0", "tslint": "5.9.1", - "typescript": "3.3.3", + "typescript": "3.9.5", "vue-loader": "14.2.4", "vue-template-compiler": "2.6.10", "wait-on": "3.2.0", From 05d73fa4cebfef8e583887f3f06628e4c04c3010 Mon Sep 17 00:00:00 2001 From: KHeo Date: Tue, 30 Jun 2020 19:24:18 +0900 Subject: [PATCH 03/18] Add custom command test. --- .../cypress/index.d.ts | 5 +++ .../cypress/integration/tests.spec.ts | 5 +++ .../cypress/plugins/index.ts | 16 ++-------- .../cypress/support/commands.ts | 31 ++++--------------- 4 files changed, 18 insertions(+), 39 deletions(-) create mode 100644 examples/fundamentals__typescript/cypress/index.d.ts diff --git a/examples/fundamentals__typescript/cypress/index.d.ts b/examples/fundamentals__typescript/cypress/index.d.ts new file mode 100644 index 000000000..18471ba05 --- /dev/null +++ b/examples/fundamentals__typescript/cypress/index.d.ts @@ -0,0 +1,5 @@ +declare namespace Cypress { + interface Chainable { + clickLink(label: string | number | RegExp): void + } +} diff --git a/examples/fundamentals__typescript/cypress/integration/tests.spec.ts b/examples/fundamentals__typescript/cypress/integration/tests.spec.ts index 137a1e0d3..326f5f781 100644 --- a/examples/fundamentals__typescript/cypress/integration/tests.spec.ts +++ b/examples/fundamentals__typescript/cypress/integration/tests.spec.ts @@ -1 +1,6 @@ /// + +it('test custom command', () => { + cy.visit('https://cypress.io') + cy.clickLink('get started') +}) diff --git a/examples/fundamentals__typescript/cypress/plugins/index.ts b/examples/fundamentals__typescript/cypress/plugins/index.ts index fd170fba6..aba156038 100644 --- a/examples/fundamentals__typescript/cypress/plugins/index.ts +++ b/examples/fundamentals__typescript/cypress/plugins/index.ts @@ -1,17 +1,5 @@ -// *********************************************************** -// This example plugins/index.js can be used to load plugins -// -// You can change the location of this file or turn off loading -// the plugins file with the 'pluginsFile' configuration option. -// -// You can read more here: -// https://on.cypress.io/plugins-guide -// *********************************************************** +/// -// This function is called when a project is opened or re-opened (e.g. due to -// the project's config changing) +export default (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => { -module.exports = (on, config) => { - // `on` is used to hook into various events Cypress emits - // `config` is the resolved Cypress config } diff --git a/examples/fundamentals__typescript/cypress/support/commands.ts b/examples/fundamentals__typescript/cypress/support/commands.ts index c1f5a772e..176bf4143 100644 --- a/examples/fundamentals__typescript/cypress/support/commands.ts +++ b/examples/fundamentals__typescript/cypress/support/commands.ts @@ -1,25 +1,6 @@ -// *********************************************** -// This example commands.js shows you how to -// create various custom commands and overwrite -// existing commands. -// -// For more comprehensive examples of custom -// commands please read more here: -// https://on.cypress.io/custom-commands -// *********************************************** -// -// -// -- This is a parent command -- -// Cypress.Commands.add("login", (email, password) => { ... }) -// -// -// -- This is a child command -- -// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) -// -// -// -- This is a dual command -- -// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) -// -// -// -- This is will overwrite an existing command -- -// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) +/// + +// 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() +}) From 03fabd626f8f776433cc6eff3fa39e93b61ef1cd Mon Sep 17 00:00:00 2001 From: KHeo Date: Wed, 1 Jul 2020 10:16:36 +0900 Subject: [PATCH 04/18] Add tests. --- .../cypress/integration/tests.spec.ts | 20 +++++++++++++++---- .../cypress/{index.d.ts => types.d.ts} | 6 ++++++ 2 files changed, 22 insertions(+), 4 deletions(-) rename examples/fundamentals__typescript/cypress/{index.d.ts => types.d.ts} (52%) diff --git a/examples/fundamentals__typescript/cypress/integration/tests.spec.ts b/examples/fundamentals__typescript/cypress/integration/tests.spec.ts index 326f5f781..9dfb64be0 100644 --- a/examples/fundamentals__typescript/cypress/integration/tests.spec.ts +++ b/examples/fundamentals__typescript/cypress/integration/tests.spec.ts @@ -1,6 +1,18 @@ -/// +/* global window */ +/// -it('test custom command', () => { - cy.visit('https://cypress.io') - cy.clickLink('get started') +// @ts-expect-error +window.add(2, 3) + +describe('tests', () => { + it('test custom command', () => { + cy.visit('https://cypress.io') + cy.clickLink('get started') + }) + + it('test extending AUTWindow', () => { + cy.window().then((win) => { + return win.add(2, 3) + }) + }) }) diff --git a/examples/fundamentals__typescript/cypress/index.d.ts b/examples/fundamentals__typescript/cypress/types.d.ts similarity index 52% rename from examples/fundamentals__typescript/cypress/index.d.ts rename to examples/fundamentals__typescript/cypress/types.d.ts index 18471ba05..f2bbd71b4 100644 --- a/examples/fundamentals__typescript/cypress/index.d.ts +++ b/examples/fundamentals__typescript/cypress/types.d.ts @@ -1,5 +1,11 @@ +/// + declare namespace Cypress { interface Chainable { clickLink(label: string | number | RegExp): void } + + interface ApplicationWindow { + add(a: number, b: number): number + } } From 42c4dd5999afc41d62bb79dbebf3bec07c782a88 Mon Sep 17 00:00:00 2001 From: KHeo Date: Wed, 1 Jul 2020 10:26:19 +0900 Subject: [PATCH 05/18] README content. --- README.md | 1 + examples/fundamentals__typescript/README.Md | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 38ad48ae4..3d9fd791d 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Recipe | Description [Cypress module API](./examples/fundamentals__module-api) | Run Cypress via its module API [Custom browsers](./examples/fundamentals__custom-browsers) | Control which browsers the project can use, or even add a custom browser into the list [use Chrome Remote Interface](./examples/fundamentals__chrome-remote-debugging) | Use Chrome debugger protocol to trigger hover state and print media style +[Out-of-the-box TypeScript](./examples/fundamentals__typescript) | Write tests in TypeScript without setting up preprocessors ## Testing the DOM diff --git a/examples/fundamentals__typescript/README.Md b/examples/fundamentals__typescript/README.Md index e69de29bb..048c6ed5f 100644 --- a/examples/fundamentals__typescript/README.Md +++ b/examples/fundamentals__typescript/README.Md @@ -0,0 +1,5 @@ +# 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://docs.cypress.io/guides/tooling/typescript-support.html). + From 409b4edaedd5de58d73f4a5c1320e5cde48d9b54 Mon Sep 17 00:00:00 2001 From: KHeo Date: Wed, 1 Jul 2020 10:43:54 +0900 Subject: [PATCH 06/18] Fix test failures. --- .../cypress/fixtures/example.json | 5 ----- .../cypress/fixtures/test.html | 9 +++++++++ .../cypress/integration/tests.spec.ts | 12 ++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) delete mode 100644 examples/fundamentals__typescript/cypress/fixtures/example.json create mode 100644 examples/fundamentals__typescript/cypress/fixtures/test.html diff --git a/examples/fundamentals__typescript/cypress/fixtures/example.json b/examples/fundamentals__typescript/cypress/fixtures/example.json deleted file mode 100644 index da18d9352..000000000 --- a/examples/fundamentals__typescript/cypress/fixtures/example.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Using fixtures to represent data", - "email": "hello@cypress.io", - "body": "Fixtures are a great way to mock data for responses to routes" -} \ No newline at end of file diff --git a/examples/fundamentals__typescript/cypress/fixtures/test.html b/examples/fundamentals__typescript/cypress/fixtures/test.html new file mode 100644 index 000000000..2f197a796 --- /dev/null +++ b/examples/fundamentals__typescript/cypress/fixtures/test.html @@ -0,0 +1,9 @@ + + + + Test + + + click me + + diff --git a/examples/fundamentals__typescript/cypress/integration/tests.spec.ts b/examples/fundamentals__typescript/cypress/integration/tests.spec.ts index 9dfb64be0..87967ec63 100644 --- a/examples/fundamentals__typescript/cypress/integration/tests.spec.ts +++ b/examples/fundamentals__typescript/cypress/integration/tests.spec.ts @@ -1,17 +1,21 @@ /* global window */ /// -// @ts-expect-error -window.add(2, 3) +before(() => { + // @ts-expect-error + window.add = (a, b) => a + b +}) describe('tests', () => { it('test custom command', () => { - cy.visit('https://cypress.io') - cy.clickLink('get started') + cy.visit('cypress/fixtures/test.html') + cy.clickLink('click me') }) it('test extending AUTWindow', () => { cy.window().then((win) => { + win.add = (a, b) => a + b + return win.add(2, 3) }) }) From b89a685cb80de3d2214d5e61a0df3057336ecda4 Mon Sep 17 00:00:00 2001 From: KHeo Date: Wed, 1 Jul 2020 12:19:15 +0900 Subject: [PATCH 07/18] Test types. --- .../fundamentals__typescript/cypress/types.d.ts | 13 ++++++++++++- examples/fundamentals__typescript/package.json | 5 ++++- examples/fundamentals__typescript/tsconfig.json | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 examples/fundamentals__typescript/tsconfig.json diff --git a/examples/fundamentals__typescript/cypress/types.d.ts b/examples/fundamentals__typescript/cypress/types.d.ts index f2bbd71b4..0c833c9f8 100644 --- a/examples/fundamentals__typescript/cypress/types.d.ts +++ b/examples/fundamentals__typescript/cypress/types.d.ts @@ -1,4 +1,15 @@ -/// +// reference code is written like below to avoid the clash in mocha types. +// in most of the cases, simple will do. +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// declare namespace Cypress { interface Chainable { diff --git a/examples/fundamentals__typescript/package.json b/examples/fundamentals__typescript/package.json index 61398890c..63f18998a 100644 --- a/examples/fundamentals__typescript/package.json +++ b/examples/fundamentals__typescript/package.json @@ -5,7 +5,10 @@ "scripts": { "cypress:open": "../../node_modules/.bin/cypress open", "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" + "test:ci:windows": "bin-up cypress run", + "tsc": "../../node_modules/.bin/tsc --pretty --noEmit" } } diff --git a/examples/fundamentals__typescript/tsconfig.json b/examples/fundamentals__typescript/tsconfig.json new file mode 100644 index 000000000..84d45e3cf --- /dev/null +++ b/examples/fundamentals__typescript/tsconfig.json @@ -0,0 +1,6 @@ +{ + "include": [ + "cypress/integration/*.ts", + "cypress/integration/**/*.ts", + ] +} \ No newline at end of file From f86936ae37da00f7404f9001ac7d562bfd77b970 Mon Sep 17 00:00:00 2001 From: KHeo Date: Wed, 1 Jul 2020 12:37:44 +0900 Subject: [PATCH 08/18] Add CI. More CI fix. --- circle.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/circle.yml b/circle.yml index 06fc63be5..ab391f5e5 100644 --- a/circle.yml +++ b/circle.yml @@ -275,6 +275,8 @@ jobs: <<: *defaults fundamentals__chrome-remote-debugging: <<: *defaults + fundamentals__typescript: + <<: *defaults # list all jobs to run and their dependencies here # and then use this list from workflow definition @@ -487,6 +489,9 @@ all_jobs: &all_jobs - fundamentals__module-api: requires: - build + - fundamentals__typescript: + requires: + - build # to avoid constantly tweaking required jobs on CircleCI # we can have a single job wait on all other test jobs here. @@ -516,6 +521,7 @@ all_jobs: &all_jobs - fundamentals__dynamic-tests - fundamentals__module-api - fundamentals__add-custom-command + - fundamentals__typescript - logging-in__csrf-tokens - logging-in__html-web-forms - logging-in__single-sign-on From fc17cf2fc157068f51ed93f52053e947a2e6c670 Mon Sep 17 00:00:00 2001 From: KHeo Date: Wed, 1 Jul 2020 12:45:46 +0900 Subject: [PATCH 09/18] Run lint. --- examples/fundamentals__typescript/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/fundamentals__typescript/package.json b/examples/fundamentals__typescript/package.json index 63f18998a..cc93f318e 100644 --- a/examples/fundamentals__typescript/package.json +++ b/examples/fundamentals__typescript/package.json @@ -4,6 +4,7 @@ "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", From 51a2f365a2a8753200e33f6111b0449d2ef45f9e Mon Sep 17 00:00:00 2001 From: KHeo Date: Wed, 1 Jul 2020 12:52:24 +0900 Subject: [PATCH 10/18] Add newlines. --- examples/fundamentals__typescript/cypress.json | 2 +- examples/fundamentals__typescript/tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/fundamentals__typescript/cypress.json b/examples/fundamentals__typescript/cypress.json index 9e26dfeeb..0967ef424 100644 --- a/examples/fundamentals__typescript/cypress.json +++ b/examples/fundamentals__typescript/cypress.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/examples/fundamentals__typescript/tsconfig.json b/examples/fundamentals__typescript/tsconfig.json index 84d45e3cf..be6a84f11 100644 --- a/examples/fundamentals__typescript/tsconfig.json +++ b/examples/fundamentals__typescript/tsconfig.json @@ -3,4 +3,4 @@ "cypress/integration/*.ts", "cypress/integration/**/*.ts", ] -} \ No newline at end of file +} From 9fcf0f0b78748fc8570c2e8d39e7431ace37d094 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Thu, 2 Jul 2020 15:30:07 -0400 Subject: [PATCH 11/18] Update examples/fundamentals__typescript/README.Md use "on" redirect --- examples/fundamentals__typescript/README.Md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/fundamentals__typescript/README.Md b/examples/fundamentals__typescript/README.Md index 048c6ed5f..de17b8782 100644 --- a/examples/fundamentals__typescript/README.Md +++ b/examples/fundamentals__typescript/README.Md @@ -1,5 +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://docs.cypress.io/guides/tooling/typescript-support.html). - +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). From 321b449ef25f063ac95bd3466d2e1272d98f7bf5 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Thu, 2 Jul 2020 15:33:05 -0400 Subject: [PATCH 12/18] Update examples/fundamentals__typescript/cypress/types.d.ts --- examples/fundamentals__typescript/cypress/types.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/fundamentals__typescript/cypress/types.d.ts b/examples/fundamentals__typescript/cypress/types.d.ts index 0c833c9f8..f2ef6a73a 100644 --- a/examples/fundamentals__typescript/cypress/types.d.ts +++ b/examples/fundamentals__typescript/cypress/types.d.ts @@ -13,6 +13,7 @@ declare namespace Cypress { interface Chainable { + // let TS know we have a custom command cy.clickLink(...) clickLink(label: string | number | RegExp): void } From ef21be50314084ab8786585bacba1980b248c883 Mon Sep 17 00:00:00 2001 From: KHeo Date: Fri, 3 Jul 2020 16:06:59 +0900 Subject: [PATCH 13/18] Add comment why tsconfig.json is necessary. --- examples/fundamentals__typescript/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/fundamentals__typescript/tsconfig.json b/examples/fundamentals__typescript/tsconfig.json index be6a84f11..698a066e7 100644 --- a/examples/fundamentals__typescript/tsconfig.json +++ b/examples/fundamentals__typescript/tsconfig.json @@ -1,3 +1,4 @@ +// This file is required to make `npm run tsc` work. { "include": [ "cypress/integration/*.ts", From 595597abedd26867bc0eba0003d6b0b497b40783 Mon Sep 17 00:00:00 2001 From: KHeo Date: Fri, 3 Jul 2020 16:16:47 +0900 Subject: [PATCH 14/18] Make test clearer. --- .../cypress/fixtures/test.html | 3 +++ .../cypress/integration/tests.spec.ts | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/fundamentals__typescript/cypress/fixtures/test.html b/examples/fundamentals__typescript/cypress/fixtures/test.html index 2f197a796..9a4bc48f0 100644 --- a/examples/fundamentals__typescript/cypress/fixtures/test.html +++ b/examples/fundamentals__typescript/cypress/fixtures/test.html @@ -6,4 +6,7 @@ click me + diff --git a/examples/fundamentals__typescript/cypress/integration/tests.spec.ts b/examples/fundamentals__typescript/cypress/integration/tests.spec.ts index 87967ec63..db5f99b00 100644 --- a/examples/fundamentals__typescript/cypress/integration/tests.spec.ts +++ b/examples/fundamentals__typescript/cypress/integration/tests.spec.ts @@ -1,11 +1,6 @@ /* global window */ /// -before(() => { - // @ts-expect-error - window.add = (a, b) => a + b -}) - describe('tests', () => { it('test custom command', () => { cy.visit('cypress/fixtures/test.html') @@ -13,9 +8,14 @@ describe('tests', () => { }) it('test extending AUTWindow', () => { - cy.window().then((win) => { - win.add = (a, b) => a + b + // Test Runner window object doesn't have add() function. + // So, it should fail the type check. + // @ts-expect-error + window.add = (a, b) => a + b + cy.window().then((win) => { + // AUT add() is defined in the fixture, test.html. + // So, it should pass the type check. return win.add(2, 3) }) }) From 61dd4ec53172179aecd82ffe2898dd9fc3280bc1 Mon Sep 17 00:00:00 2001 From: KHeo Date: Fri, 3 Jul 2020 16:24:41 +0900 Subject: [PATCH 15/18] Example list. --- examples/fundamentals__typescript/README.Md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/fundamentals__typescript/README.Md b/examples/fundamentals__typescript/README.Md index de17b8782..b5df6eb00 100644 --- a/examples/fundamentals__typescript/README.Md +++ b/examples/fundamentals__typescript/README.Md @@ -1,4 +1,10 @@ # 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). +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) for more details. + +- Use out-of-the-box TypeScript. +- Write spec, plugin, support files in TypeScript. +- Define type for the custom commands. +- Check types in the spec files. +- Show difference between Test Runner `window` and `AUTWindow` types. And how to extend `AUTWindow` type. From 9d600c4e46eb422fa524f224ca84adbcb30ddfc0 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Mon, 6 Jul 2020 09:25:45 -0400 Subject: [PATCH 16/18] Update examples/fundamentals__typescript/cypress/types.d.ts --- examples/fundamentals__typescript/cypress/types.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/fundamentals__typescript/cypress/types.d.ts b/examples/fundamentals__typescript/cypress/types.d.ts index f2ef6a73a..ad7603e40 100644 --- a/examples/fundamentals__typescript/cypress/types.d.ts +++ b/examples/fundamentals__typescript/cypress/types.d.ts @@ -18,6 +18,8 @@ declare namespace Cypress { } interface ApplicationWindow { + // let TS know the application's code will add + // method window.add with the following signature add(a: number, b: number): number } } From ba3bcefb209199dfb4f1f4888a8e261cd2714468 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Mon, 6 Jul 2020 09:26:52 -0400 Subject: [PATCH 17/18] Update examples/fundamentals__typescript/cypress/types.d.ts --- examples/fundamentals__typescript/cypress/types.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/fundamentals__typescript/cypress/types.d.ts b/examples/fundamentals__typescript/cypress/types.d.ts index ad7603e40..a50ef8182 100644 --- a/examples/fundamentals__typescript/cypress/types.d.ts +++ b/examples/fundamentals__typescript/cypress/types.d.ts @@ -12,6 +12,7 @@ /// declare namespace Cypress { + // add custom Cypress command to the interface Chainable interface Chainable { // let TS know we have a custom command cy.clickLink(...) clickLink(label: string | number | RegExp): void From 80674f527176543e216f8c6bba8059d65d7b7cb0 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Mon, 6 Jul 2020 09:27:45 -0400 Subject: [PATCH 18/18] Update examples/fundamentals__typescript/cypress/types.d.ts --- examples/fundamentals__typescript/cypress/types.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/fundamentals__typescript/cypress/types.d.ts b/examples/fundamentals__typescript/cypress/types.d.ts index a50ef8182..c3e43e81a 100644 --- a/examples/fundamentals__typescript/cypress/types.d.ts +++ b/examples/fundamentals__typescript/cypress/types.d.ts @@ -18,6 +18,8 @@ declare namespace Cypress { clickLink(label: string | number | RegExp): void } + // add properties the application adds to its "window" object + // by adding them to the interface ApplicationWindow interface ApplicationWindow { // let TS know the application's code will add // method window.add with the following signature