From 552620f9b876ed589d0310a1e67d15ae5cb8c469 Mon Sep 17 00:00:00 2001 From: Raquel Amorim <36057168+amorimr@users.noreply.github.com> Date: Thu, 21 Jul 2022 12:40:51 -0400 Subject: [PATCH] chore(examples): Convert `with-cypress` example to TypeScript (#38818) - Update `with-cypress` example dependencies; - Convert `with-cypress` example to TypeScript as suggested in the Contribution docs. ## Documentation / Examples - [x] Make sure the linting passes by running `pnpm lint` - [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) --- examples/with-cypress/.gitignore | 3 +++ examples/with-cypress/cypress.config.ts | 7 ++++++ examples/with-cypress/cypress.json | 3 --- .../app.spec.js => e2e/app.cy.ts} | 0 .../with-cypress/cypress/plugins/index.js | 22 ------------------- .../support/{commands.js => commands.ts} | 14 +++++++++++- .../cypress/support/{index.js => e2e.ts} | 2 +- examples/with-cypress/cypress/tsconfig.json | 8 +++++++ examples/with-cypress/next-env.d.ts | 5 +++++ examples/with-cypress/package.json | 12 ++++++---- .../with-cypress/pages/{_app.js => _app.tsx} | 3 ++- .../pages/{about.js => about.tsx} | 0 .../pages/{index.js => index.tsx} | 0 examples/with-cypress/tsconfig.json | 20 +++++++++++++++++ 14 files changed, 67 insertions(+), 32 deletions(-) create mode 100644 examples/with-cypress/cypress.config.ts delete mode 100644 examples/with-cypress/cypress.json rename examples/with-cypress/cypress/{integration/app.spec.js => e2e/app.cy.ts} (100%) delete mode 100644 examples/with-cypress/cypress/plugins/index.js rename examples/with-cypress/cypress/support/{commands.js => commands.ts} (60%) rename examples/with-cypress/cypress/support/{index.js => e2e.ts} (92%) create mode 100644 examples/with-cypress/cypress/tsconfig.json create mode 100644 examples/with-cypress/next-env.d.ts rename examples/with-cypress/pages/{_app.js => _app.tsx} (50%) rename examples/with-cypress/pages/{about.js => about.tsx} (100%) rename examples/with-cypress/pages/{index.js => index.tsx} (100%) create mode 100644 examples/with-cypress/tsconfig.json diff --git a/examples/with-cypress/.gitignore b/examples/with-cypress/.gitignore index 1437c53f70bc..88b6f0d98164 100644 --- a/examples/with-cypress/.gitignore +++ b/examples/with-cypress/.gitignore @@ -32,3 +32,6 @@ yarn-error.log* # vercel .vercel + +# typescript +*.tsbuildinfo diff --git a/examples/with-cypress/cypress.config.ts b/examples/with-cypress/cypress.config.ts new file mode 100644 index 000000000000..b63e356440e3 --- /dev/null +++ b/examples/with-cypress/cypress.config.ts @@ -0,0 +1,7 @@ +const { defineConfig } = require('cypress') + +module.exports = defineConfig({ + e2e: { + baseUrl: 'http://localhost:3000', + }, +}) diff --git a/examples/with-cypress/cypress.json b/examples/with-cypress/cypress.json deleted file mode 100644 index 17ef242e711f..000000000000 --- a/examples/with-cypress/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "baseUrl": "http://localhost:3000" -} diff --git a/examples/with-cypress/cypress/integration/app.spec.js b/examples/with-cypress/cypress/e2e/app.cy.ts similarity index 100% rename from examples/with-cypress/cypress/integration/app.spec.js rename to examples/with-cypress/cypress/e2e/app.cy.ts diff --git a/examples/with-cypress/cypress/plugins/index.js b/examples/with-cypress/cypress/plugins/index.js deleted file mode 100644 index 59b2bab6e4e6..000000000000 --- a/examples/with-cypress/cypress/plugins/index.js +++ /dev/null @@ -1,22 +0,0 @@ -/// -// *********************************************************** -// 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) - -/** - * @type {Cypress.PluginConfig} - */ -// eslint-disable-next-line no-unused-vars -module.exports = (on, config) => { - // `on` is used to hook into various events Cypress emits - // `config` is the resolved Cypress config -} diff --git a/examples/with-cypress/cypress/support/commands.js b/examples/with-cypress/cypress/support/commands.ts similarity index 60% rename from examples/with-cypress/cypress/support/commands.js rename to examples/with-cypress/cypress/support/commands.ts index 119ab03f7cda..95857aea4cdf 100644 --- a/examples/with-cypress/cypress/support/commands.js +++ b/examples/with-cypress/cypress/support/commands.ts @@ -1,5 +1,6 @@ +/// // *********************************************** -// This example commands.js shows you how to +// This example commands.ts shows you how to // create various custom commands and overwrite // existing commands. // @@ -23,3 +24,14 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +// +// declare global { +// namespace Cypress { +// interface Chainable { +// login(email: string, password: string): Chainable +// drag(subject: string, options?: Partial): Chainable +// dismiss(subject: string, options?: Partial): Chainable +// visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable +// } +// } +// } diff --git a/examples/with-cypress/cypress/support/index.js b/examples/with-cypress/cypress/support/e2e.ts similarity index 92% rename from examples/with-cypress/cypress/support/index.js rename to examples/with-cypress/cypress/support/e2e.ts index d68db96df269..ed5730de1148 100644 --- a/examples/with-cypress/cypress/support/index.js +++ b/examples/with-cypress/cypress/support/e2e.ts @@ -1,5 +1,5 @@ // *********************************************************** -// This example support/index.js is processed and +// This example support/e2e.ts is processed and // loaded automatically before your test files. // // This is a great place to put global configuration and diff --git a/examples/with-cypress/cypress/tsconfig.json b/examples/with-cypress/cypress/tsconfig.json new file mode 100644 index 000000000000..18edb199acdb --- /dev/null +++ b/examples/with-cypress/cypress/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["es5", "dom"], + "types": ["cypress", "node"] + }, + "include": ["**/*.ts"] +} diff --git a/examples/with-cypress/next-env.d.ts b/examples/with-cypress/next-env.d.ts new file mode 100644 index 000000000000..4f11a03dc6cc --- /dev/null +++ b/examples/with-cypress/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-cypress/package.json b/examples/with-cypress/package.json index d277dee94d4a..a3b47a25ac36 100644 --- a/examples/with-cypress/package.json +++ b/examples/with-cypress/package.json @@ -11,11 +11,15 @@ }, "dependencies": { "next": "latest", - "react": "17.0.2", - "react-dom": "17.0.2" + "react": "18.2.0", + "react-dom": "18.2.0" }, "devDependencies": { - "cypress": "8.2.0", - "start-server-and-test": "1.13.1" + "@types/node": "18.0.6", + "@types/react": "18.0.15", + "@types/react-dom": "18.0.6", + "cypress": "10.3.1", + "start-server-and-test": "1.14.0", + "typescript": "4.7.4" } } diff --git a/examples/with-cypress/pages/_app.js b/examples/with-cypress/pages/_app.tsx similarity index 50% rename from examples/with-cypress/pages/_app.js rename to examples/with-cypress/pages/_app.tsx index 1e1cec92425c..c7e1bbcd1aef 100644 --- a/examples/with-cypress/pages/_app.js +++ b/examples/with-cypress/pages/_app.tsx @@ -1,6 +1,7 @@ +import type { AppProps } from 'next/app' import '../styles/globals.css' -function MyApp({ Component, pageProps }) { +function MyApp({ Component, pageProps }: AppProps) { return } diff --git a/examples/with-cypress/pages/about.js b/examples/with-cypress/pages/about.tsx similarity index 100% rename from examples/with-cypress/pages/about.js rename to examples/with-cypress/pages/about.tsx diff --git a/examples/with-cypress/pages/index.js b/examples/with-cypress/pages/index.tsx similarity index 100% rename from examples/with-cypress/pages/index.js rename to examples/with-cypress/pages/index.tsx diff --git a/examples/with-cypress/tsconfig.json b/examples/with-cypress/tsconfig.json new file mode 100644 index 000000000000..b8d597880a1a --- /dev/null +++ b/examples/with-cypress/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": false, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true + }, + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], + "exclude": ["node_modules"] +}