From a639e1d0249d89964ef1016b2f77cdc35397e949 Mon Sep 17 00:00:00 2001 From: ElevateBart Date: Thu, 1 Apr 2021 17:40:34 -0500 Subject: [PATCH 1/5] fix: make vite dev server open on a free port --- npm/vite-dev-server/package.json | 5 +- npm/vite-dev-server/src/index.ts | 18 +----- npm/vite-dev-server/src/makeCypressPlugin.ts | 3 +- npm/vite-dev-server/src/startServer.ts | 68 ++++++++++---------- 4 files changed, 41 insertions(+), 53 deletions(-) diff --git a/npm/vite-dev-server/package.json b/npm/vite-dev-server/package.json index 52696b2f61c1..497c5eb12c45 100644 --- a/npm/vite-dev-server/package.json +++ b/npm/vite-dev-server/package.json @@ -12,7 +12,8 @@ "watch": "tsc -w" }, "dependencies": { - "debug": "4.3.2" + "debug": "^4.3.2", + "get-port": "^5.1.1" }, "devDependencies": { "@cypress/react": "0.0.0-development", @@ -27,7 +28,7 @@ "vue": "3.0.9" }, "peerDependencies": { - "vite": ">= 2" + "vite": ">= 2.1.3" }, "files": [ "dist", diff --git a/npm/vite-dev-server/src/index.ts b/npm/vite-dev-server/src/index.ts index 6f748d5663fb..c027b05a0752 100644 --- a/npm/vite-dev-server/src/index.ts +++ b/npm/vite-dev-server/src/index.ts @@ -1,23 +1,9 @@ -import { EventEmitter } from 'events' import { debug as debugFn } from 'debug' -import { start as createDevServer } from './startServer' -import { UserConfig } from 'vite' import { Server } from 'http' +import { start as createDevServer, StartDevServer } from './startServer' const debug = debugFn('cypress:vite-dev-server:vite') -interface Options { - specs: any[] // Cypress.Cypress['spec'][] // Why isn't this working? It works for webpack-dev-server - config: Record - devServerEvents: EventEmitter - [key: string]: unknown -} - -export interface StartDevServer { - /* this is the Cypress options object */ - options: Options - /* support passing a path to the user's webpack config */ - viteConfig?: UserConfig // TODO: implement taking in the user's vite configuration. Right now we don't -} +export { StartDevServer } export interface ResolvedDevServerConfig { port: number diff --git a/npm/vite-dev-server/src/makeCypressPlugin.ts b/npm/vite-dev-server/src/makeCypressPlugin.ts index 58e657878e84..86ddcb258119 100644 --- a/npm/vite-dev-server/src/makeCypressPlugin.ts +++ b/npm/vite-dev-server/src/makeCypressPlugin.ts @@ -1,4 +1,3 @@ -import { EventEmitter } from 'events' import { resolve } from 'path' import { readFile } from 'fs' import { promisify } from 'util' @@ -24,7 +23,7 @@ export const makeCypressPlugin = ( if (env) { return { define: { - 'import.meta.env.__cypress_supportPath': JSON.stringify(resolve(projectRoot, supportFilePath)), + 'import.meta.env.__cypress_supportPath': JSON.stringify(supportFilePath ? resolve(projectRoot, supportFilePath) : undefined), 'import.meta.env.__cypress_originAutUrl': JSON.stringify('__cypress/iframes/'), }, } diff --git a/npm/vite-dev-server/src/startServer.ts b/npm/vite-dev-server/src/startServer.ts index da8a3a15cf46..324a026802d6 100644 --- a/npm/vite-dev-server/src/startServer.ts +++ b/npm/vite-dev-server/src/startServer.ts @@ -1,47 +1,49 @@ import Debug from 'debug' -import { StartDevServer } from '.' -import { createServer, ViteDevServer, InlineConfig } from 'vite' +import { createServer, ViteDevServer, InlineConfig, UserConfig } from 'vite' import { dirname, resolve } from 'path' +import getPort from 'get-port' import { makeCypressPlugin } from './makeCypressPlugin' -import { EventEmitter } from 'events' const debug = Debug('cypress:vite-dev-server:start') -// TODO: Pull in types for Options so we can infer these -const serverConfig = (projectRoot: string, supportFilePath: string, devServerEvents: EventEmitter): InlineConfig => { - return { - root: resolve(__dirname, projectRoot), - base: '/__cypress/src/', - plugins: [makeCypressPlugin(projectRoot, supportFilePath, devServerEvents)], - server: { - port: 0, - }, - resolve: { - alias: { - // Necessary to avoid a "prefixIdentifiers" issue from slots mounting - // Could be resolved in test-utils - '@vue/compiler-core': resolve(dirname(require.resolve('@vue/compiler-core')), 'dist', 'compiler-core.cjs.js'), - }, - }, - } +interface Options { + specs: Cypress.Cypress['spec'][] + config: Record + devServerEvents: EventEmitter + [key: string]: unknown +} + +export interface StartDevServer { + /* this is the Cypress options object */ + options: Options + /* support passing a path to the user's webpack config */ + viteConfig?: UserConfig // TODO: implement taking in the user's vite configuration. Right now we don't } -const resolveServerConfig = ({ viteConfig, options }: StartDevServer) => { - const defaultServerConfig = serverConfig( - options.config.projectRoot, - options.config.supportFile, - options.devServerEvents, - ) +const resolveServerConfig = async ({ viteConfig, options }: StartDevServer): Promise => { + const { projectRoot, supportFile } = options.config - const requiredOptions = { - base: defaultServerConfig.base, - root: defaultServerConfig.root, + const requiredOptions: InlineConfig = { + base: '/__cypress/src/', + root: projectRoot, } - const finalConfig = { ...defaultServerConfig, ...viteConfig, ...requiredOptions } + const finalConfig: InlineConfig = { ...viteConfig, ...requiredOptions } + + finalConfig.plugins = [...(viteConfig.plugins || []), makeCypressPlugin(projectRoot, supportFile, options.devServerEvents)] + + // This alias is necessary to avoid a "prefixIdentifiers" issue from slots mounting + // only cjs compiler-core accepts using prefixIdentifiers in slots which vue test utils use. + // Could we resolve this usage in test-utils? + finalConfig.resolve = finalConfig.resolve || {} + finalConfig.resolve.alias = { + ...finalConfig.resolve.alias, + '@vue/compiler-core': resolve(dirname(require.resolve('@vue/compiler-core')), 'dist', 'compiler-core.cjs.js'), + }, + + finalConfig.server = finalConfig.server || {} - finalConfig.plugins = [...(viteConfig.plugins || []), defaultServerConfig.plugins[0]] - finalConfig.server.port = defaultServerConfig.server.port + finalConfig.server.port = await getPort({ port: 3000, host: 'localhost' }), debug(`the resolved server config is ${JSON.stringify(finalConfig, null, 2)}`) @@ -55,7 +57,7 @@ export async function start (devServerOptions: StartDevServer): Promise Date: Thu, 1 Apr 2021 17:45:55 -0500 Subject: [PATCH 2/5] ci: only run vite test in Ci to see flake --- circle.yml | 329 ----------------------------------------------------- 1 file changed, 329 deletions(-) diff --git a/circle.yml b/circle.yml index d829c9e4edc1..a516aada92a9 100644 --- a/circle.yml +++ b/circle.yml @@ -1773,341 +1773,12 @@ jobs: linux-workflow: &linux-workflow jobs: - build - - lint: - name: Linux lint - requires: - - build - - percy-finalize: - context: test-runner:poll-circle-workflow - required_env_var: PERCY_TOKEN # skips job if not defined (external PR) - requires: - - build - - lint-types: - requires: - - build - # unit, integration and e2e tests - - cli-visual-tests: - requires: - - build - - unit-tests: - requires: - - build - - server-unit-tests: - requires: - - build - - server-integration-tests: - requires: - - build - - server-performance-tests: - requires: - - build - - server-e2e-tests-chrome: - requires: - - build - - server-e2e-tests-electron: - requires: - - build - - server-e2e-tests-firefox: - requires: - - build - - server-e2e-tests-non-root: - executor: non-root-docker-user - requires: - - build - - driver-integration-tests-chrome: - requires: - - build - - driver-integration-tests-firefox: - requires: - - build - - runner-integration-tests-chrome: - requires: - - build - - runner-integration-tests-firefox: - requires: - - build - - runner-ct-integration-tests-chrome: - requires: - - build - - ## TODO: add these back in when flaky tests are fixed - # - driver-integration-tests-electron: - # requires: - # - build - - desktop-gui-integration-tests-2x: - requires: - - build - - desktop-gui-component-tests: - requires: - - build - - reporter-integration-tests: - requires: - - build - - ui-components-integration-tests: - requires: - - build - - run-launcher: - requires: - - build - - - npm-webpack-dev-server: - requires: - - build - npm-vite-dev-server: requires: - build - - npm-rollup-dev-server: - requires: - - build - - npm-webpack-preprocessor: - requires: - - build - - npm-webpack-batteries-included-preprocessor: - requires: - - build - npm-design-system: requires: - build - - npm-vue: - requires: - - build - - npm-react: - requires: - - build - - npm-create-cypress-tests: - requires: - - build - - npm-eslint-plugin-dev: - requires: - - build - # This release definition must be updated with any new jobs - # Any attempts to automate this are welcome - # If CircleCI provided an "after all" hook, then this wouldn't be necessary - - npm-release: - requires: - - build - - npm-eslint-plugin-dev - - npm-create-cypress-tests - - npm-react - - npm-vue - - npm-design-system - - npm-webpack-batteries-included-preprocessor - - npm-webpack-preprocessor - - npm-rollup-dev-server - - npm-vite-dev-server - - npm-webpack-dev-server - - run-launcher - - ui-components-integration-tests - - reporter-integration-tests - - Linux lint - - desktop-gui-component-tests - - desktop-gui-integration-tests-2x - - runner-ct-integration-tests-chrome - - runner-integration-tests-firefox - - runner-integration-tests-chrome - - driver-integration-tests-firefox - - driver-integration-tests-chrome - - server-e2e-tests-non-root - - server-e2e-tests-firefox - - server-e2e-tests-electron - - server-e2e-tests-chrome - - server-performance-tests - - server-integration-tests - - server-unit-tests - - unit-tests - - cli-visual-tests - - # various testing scenarios, like building full binary - # and testing it on a real project - - test-against-staging: - context: test-runner:record-tests - filters: - branches: - only: - - develop - - fix-next-version - requires: - - build - - test-kitchensink: - requires: - - build - - test-kitchensink-against-staging: - context: test-runner:record-tests - filters: - branches: - only: - - develop - - fix-next-version - requires: - - build - - create-build-artifacts: - context: - - test-runner:upload - - test-runner:commit-status-checks - requires: - - build - - test-npm-module-on-minimum-node-version: - requires: - - create-build-artifacts - - test-types-cypress-and-jest: - requires: - - create-build-artifacts - - test-cypress-scaffold: - requires: - - create-build-artifacts - - test-full-typescript-project: - requires: - - create-build-artifacts - - test-binary-against-kitchensink: - requires: - - create-build-artifacts - # when working on a feature or a fix, - # you are probably working in a branch - # and you want to run a specific PR in the cypress-example-recipes - # against this branch. This workflow job includes - # the job but only when it runs on specific branch - # DO NOT DELETE THIS JOB BEFORE MERGING TO DEVELOP - # on "develop" this branch will be ignored anyway - # and someone else might use this job definition for another - # feature branch and would just update the branch filter - # - test-binary-against-recipe-pull-request: - # name: Test cypress run parsing - # filters: - # branches: - # only: - # - cli-to-module-api-7760 - # requires: - # - create-build-artifacts - - test-binary-against-awesome-typescript-loader: - requires: - - create-build-artifacts - - test-binary-and-npm-against-other-projects: - context: test-runner:trigger-test-jobs - filters: - branches: - only: - - develop - - fix-next-version - requires: - - create-build-artifacts - - test-npm-module-and-verify-binary: - filters: - branches: - only: - - develop - - fix-next-version - requires: - - create-build-artifacts - - test-binary-against-staging: - context: test-runner:record-tests - filters: - branches: - only: - - develop - - fix-next-version - requires: - - create-build-artifacts - - - test-binary-against-recipes-firefox: - <<: *testBinaryFirefox - - test-binary-against-kitchensink-firefox: - <<: *testBinaryFirefox - - test-binary-against-kitchensink-chrome: - <<: *testBinaryFirefox - - test-binary-against-todomvc-firefox: - <<: *testBinaryFirefox - - test-binary-against-documentation-firefox: - <<: *testBinaryFirefox - - test-binary-against-api-testing-firefox: - <<: *testBinaryFirefox - - test-binary-against-realworld-firefox: - <<: *testBinaryFirefox - - test-binary-against-piechopper-firefox: - <<: *testBinaryFirefox - - test-binary-against-cypress-realworld-app: - executor: cy-doc-plus - filters: - branches: - only: - - develop - - fix-next-version - requires: - - create-build-artifacts - - - test-binary-as-specific-user: - name: "test binary as a non-root user" - executor: non-root-docker-user - requires: - - create-build-artifacts - - test-binary-as-specific-user: - name: "test binary as a root user" - requires: - - create-build-artifacts - -mac-workflow: &mac-workflow - jobs: - - build: - name: darwin-build - executor: mac - <<: *macBuildFilters - - - lint: - name: darwin-lint - executor: mac - <<: *macBuildFilters - requires: - - darwin-build - - # maybe run all unit tests? - - - create-build-artifacts: - name: darwin-create-build-artifacts - context: - - test-runner:sign-mac-binary - - test-runner:upload - - test-runner:commit-status-checks - executor: mac - <<: *macBuildFilters - requires: - - darwin-build - - - test-kitchensink: - name: darwin-test-kitchensink - executor: mac - <<: *macBuildFilters - requires: - - darwin-build - - - test-binary-against-kitchensink: - name: darwin-test-binary-against-kitchensink - executor: mac - <<: *macBuildFilters - requires: - - darwin-create-build-artifacts - - - test-binary-against-staging: - context: test-runner:record-tests - name: darwin-test-binary-against-staging - executor: mac - filters: - branches: - only: - - develop - - fix-next-version - requires: - - darwin-create-build-artifacts - - - test-binary-and-npm-against-other-projects: - context: test-runner:trigger-test-jobs - name: darwin-test-binary-and-npm-against-other-projects - executor: mac - filters: - branches: - only: - - develop - - fix-next-version - requires: - - darwin-create-build-artifacts workflows: linux: From fd1a6a7eada9972fcdf0e998f3e1fe5e7909edfc Mon Sep 17 00:00:00 2001 From: ElevateBart Date: Thu, 1 Apr 2021 17:52:27 -0500 Subject: [PATCH 3/5] ci: fix circle config --- circle.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index a516aada92a9..4ef480395b87 100644 --- a/circle.yml +++ b/circle.yml @@ -1779,7 +1779,32 @@ linux-workflow: &linux-workflow - npm-design-system: requires: - build - +mac-workflow: &mac-workflow + jobs: + - build: + name: darwin-build + executor: mac + <<: *macBuildFilters + + - lint: + name: darwin-lint + executor: mac + <<: *macBuildFilters + requires: + - darwin-build + + # maybe run all unit tests? + + - create-build-artifacts: + name: darwin-create-build-artifacts + context: + - test-runner:sign-mac-binary + - test-runner:upload + - test-runner:commit-status-checks + executor: mac + <<: *macBuildFilters + requires: + - darwin-build workflows: linux: <<: *linux-workflow From 67c5fea626dfc40437775822498319a26a476d22 Mon Sep 17 00:00:00 2001 From: ElevateBart Date: Thu, 1 Apr 2021 18:23:07 -0500 Subject: [PATCH 4/5] ci: remove circle ci changes --- circle.yml | 304 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 304 insertions(+) diff --git a/circle.yml b/circle.yml index 4ef480395b87..d829c9e4edc1 100644 --- a/circle.yml +++ b/circle.yml @@ -1773,12 +1773,277 @@ jobs: linux-workflow: &linux-workflow jobs: - build + - lint: + name: Linux lint + requires: + - build + - percy-finalize: + context: test-runner:poll-circle-workflow + required_env_var: PERCY_TOKEN # skips job if not defined (external PR) + requires: + - build + - lint-types: + requires: + - build + # unit, integration and e2e tests + - cli-visual-tests: + requires: + - build + - unit-tests: + requires: + - build + - server-unit-tests: + requires: + - build + - server-integration-tests: + requires: + - build + - server-performance-tests: + requires: + - build + - server-e2e-tests-chrome: + requires: + - build + - server-e2e-tests-electron: + requires: + - build + - server-e2e-tests-firefox: + requires: + - build + - server-e2e-tests-non-root: + executor: non-root-docker-user + requires: + - build + - driver-integration-tests-chrome: + requires: + - build + - driver-integration-tests-firefox: + requires: + - build + - runner-integration-tests-chrome: + requires: + - build + - runner-integration-tests-firefox: + requires: + - build + - runner-ct-integration-tests-chrome: + requires: + - build + + ## TODO: add these back in when flaky tests are fixed + # - driver-integration-tests-electron: + # requires: + # - build + - desktop-gui-integration-tests-2x: + requires: + - build + - desktop-gui-component-tests: + requires: + - build + - reporter-integration-tests: + requires: + - build + - ui-components-integration-tests: + requires: + - build + - run-launcher: + requires: + - build + + - npm-webpack-dev-server: + requires: + - build - npm-vite-dev-server: requires: - build + - npm-rollup-dev-server: + requires: + - build + - npm-webpack-preprocessor: + requires: + - build + - npm-webpack-batteries-included-preprocessor: + requires: + - build - npm-design-system: requires: - build + - npm-vue: + requires: + - build + - npm-react: + requires: + - build + - npm-create-cypress-tests: + requires: + - build + - npm-eslint-plugin-dev: + requires: + - build + # This release definition must be updated with any new jobs + # Any attempts to automate this are welcome + # If CircleCI provided an "after all" hook, then this wouldn't be necessary + - npm-release: + requires: + - build + - npm-eslint-plugin-dev + - npm-create-cypress-tests + - npm-react + - npm-vue + - npm-design-system + - npm-webpack-batteries-included-preprocessor + - npm-webpack-preprocessor + - npm-rollup-dev-server + - npm-vite-dev-server + - npm-webpack-dev-server + - run-launcher + - ui-components-integration-tests + - reporter-integration-tests + - Linux lint + - desktop-gui-component-tests + - desktop-gui-integration-tests-2x + - runner-ct-integration-tests-chrome + - runner-integration-tests-firefox + - runner-integration-tests-chrome + - driver-integration-tests-firefox + - driver-integration-tests-chrome + - server-e2e-tests-non-root + - server-e2e-tests-firefox + - server-e2e-tests-electron + - server-e2e-tests-chrome + - server-performance-tests + - server-integration-tests + - server-unit-tests + - unit-tests + - cli-visual-tests + + # various testing scenarios, like building full binary + # and testing it on a real project + - test-against-staging: + context: test-runner:record-tests + filters: + branches: + only: + - develop + - fix-next-version + requires: + - build + - test-kitchensink: + requires: + - build + - test-kitchensink-against-staging: + context: test-runner:record-tests + filters: + branches: + only: + - develop + - fix-next-version + requires: + - build + - create-build-artifacts: + context: + - test-runner:upload + - test-runner:commit-status-checks + requires: + - build + - test-npm-module-on-minimum-node-version: + requires: + - create-build-artifacts + - test-types-cypress-and-jest: + requires: + - create-build-artifacts + - test-cypress-scaffold: + requires: + - create-build-artifacts + - test-full-typescript-project: + requires: + - create-build-artifacts + - test-binary-against-kitchensink: + requires: + - create-build-artifacts + # when working on a feature or a fix, + # you are probably working in a branch + # and you want to run a specific PR in the cypress-example-recipes + # against this branch. This workflow job includes + # the job but only when it runs on specific branch + # DO NOT DELETE THIS JOB BEFORE MERGING TO DEVELOP + # on "develop" this branch will be ignored anyway + # and someone else might use this job definition for another + # feature branch and would just update the branch filter + # - test-binary-against-recipe-pull-request: + # name: Test cypress run parsing + # filters: + # branches: + # only: + # - cli-to-module-api-7760 + # requires: + # - create-build-artifacts + - test-binary-against-awesome-typescript-loader: + requires: + - create-build-artifacts + - test-binary-and-npm-against-other-projects: + context: test-runner:trigger-test-jobs + filters: + branches: + only: + - develop + - fix-next-version + requires: + - create-build-artifacts + - test-npm-module-and-verify-binary: + filters: + branches: + only: + - develop + - fix-next-version + requires: + - create-build-artifacts + - test-binary-against-staging: + context: test-runner:record-tests + filters: + branches: + only: + - develop + - fix-next-version + requires: + - create-build-artifacts + + - test-binary-against-recipes-firefox: + <<: *testBinaryFirefox + - test-binary-against-kitchensink-firefox: + <<: *testBinaryFirefox + - test-binary-against-kitchensink-chrome: + <<: *testBinaryFirefox + - test-binary-against-todomvc-firefox: + <<: *testBinaryFirefox + - test-binary-against-documentation-firefox: + <<: *testBinaryFirefox + - test-binary-against-api-testing-firefox: + <<: *testBinaryFirefox + - test-binary-against-realworld-firefox: + <<: *testBinaryFirefox + - test-binary-against-piechopper-firefox: + <<: *testBinaryFirefox + - test-binary-against-cypress-realworld-app: + executor: cy-doc-plus + filters: + branches: + only: + - develop + - fix-next-version + requires: + - create-build-artifacts + + - test-binary-as-specific-user: + name: "test binary as a non-root user" + executor: non-root-docker-user + requires: + - create-build-artifacts + - test-binary-as-specific-user: + name: "test binary as a root user" + requires: + - create-build-artifacts + mac-workflow: &mac-workflow jobs: - build: @@ -1805,6 +2070,45 @@ mac-workflow: &mac-workflow <<: *macBuildFilters requires: - darwin-build + + - test-kitchensink: + name: darwin-test-kitchensink + executor: mac + <<: *macBuildFilters + requires: + - darwin-build + + - test-binary-against-kitchensink: + name: darwin-test-binary-against-kitchensink + executor: mac + <<: *macBuildFilters + requires: + - darwin-create-build-artifacts + + - test-binary-against-staging: + context: test-runner:record-tests + name: darwin-test-binary-against-staging + executor: mac + filters: + branches: + only: + - develop + - fix-next-version + requires: + - darwin-create-build-artifacts + + - test-binary-and-npm-against-other-projects: + context: test-runner:trigger-test-jobs + name: darwin-test-binary-and-npm-against-other-projects + executor: mac + filters: + branches: + only: + - develop + - fix-next-version + requires: + - darwin-create-build-artifacts + workflows: linux: <<: *linux-workflow From 61645a0438aee89acca98384ebbda63191b28fb8 Mon Sep 17 00:00:00 2001 From: ElevateBart Date: Thu, 1 Apr 2021 20:17:57 -0500 Subject: [PATCH 5/5] test: avoid running video for speed --- npm/vite-dev-server/cypress.json | 1 + 1 file changed, 1 insertion(+) diff --git a/npm/vite-dev-server/cypress.json b/npm/vite-dev-server/cypress.json index 7db3fb3fcf33..86c35bca1415 100644 --- a/npm/vite-dev-server/cypress.json +++ b/npm/vite-dev-server/cypress.json @@ -1,5 +1,6 @@ { "pluginsFile": "cypress/plugins.js", + "video": false, "testFiles": "**/*.spec.*", "componentFolder": "cypress/components", "supportFile": "cypress/support/support.js"