From d6f172b95636b214a8884883426e297642486e50 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Wed, 20 Oct 2021 22:01:08 -0500 Subject: [PATCH 01/57] feat: Use .config files --- .../src/actions/ProjectActions.ts | 12 +++-- .../data-context/src/actions/WizardActions.ts | 4 +- .../data-context/src/data/coreDataShape.ts | 4 +- .../src/sources/ProjectDataSource.ts | 54 +++++++++---------- .../support/mock-graphql/stubgql-Mutation.ts | 4 +- .../support/mock-graphql/stubgql-Project.ts | 4 +- packages/graphql/schemas/schema.graphql | 4 +- .../schemaTypes/objectTypes/gql-Mutation.ts | 8 +-- .../schemaTypes/objectTypes/gql-Project.ts | 10 ++-- .../src/global/GlobalProjectCard.vue | 5 -- .../src/setup/TestingTypeCards.spec.tsx | 12 ++--- .../launchpad/src/setup/TestingTypeCards.vue | 16 +++--- packages/server/lib/cache.js | 14 +++++ packages/server/lib/configFiles.ts | 2 +- packages/server/lib/makeDataContext.ts | 12 +++-- packages/server/lib/util/settings.ts | 44 +++++++-------- packages/types/src/cache.ts | 6 +++ packages/types/src/config.ts | 8 +++ 18 files changed, 127 insertions(+), 96 deletions(-) diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 46fa7c44f0b9..13bc2067f548 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -1,12 +1,12 @@ import type { MutationAddProjectArgs, MutationAppCreateConfigFileArgs, MutationSetProjectPreferencesArgs, TestingTypeEnum } from '@packages/graphql/src/gen/nxs.gen' -import type { FindSpecs, FoundBrowser, FoundSpec, FullConfig, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, Preferences } from '@packages/types' +import type { FindSpecs, FoundBrowser, FoundSpec, FullConfig, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, Preferences, ProjectConfigCache, SettingsOptions } from '@packages/types' import path from 'path' import type { ProjectShape } from '../data/coreDataShape' import type { DataContext } from '..' export interface ProjectApiShape { - getConfig(projectRoot: string): Promise + getConfig(projectRoot: string, options?: SettingsOptions): Promise findSpecs(payload: FindSpecs): Promise /** * "Initializes" the given mode, since plugins can define the browsers available @@ -24,6 +24,8 @@ export interface ProjectApiShape { clearProjectPreferences(projectTitle: string): Promise clearAllProjectPreferences(): Promise closeActiveProject(): Promise + setProjectConfig(projectRoot: string, projectId: Partial | null): Promise + getProjectConfig (projectRoot: string): Promise } export class ProjectActions { @@ -61,8 +63,8 @@ export class ProjectActions { title, ctPluginsInitialized: false, e2ePluginsInitialized: false, - isFirstTimeCT: await this.ctx.project.isFirstTimeAccessing(projectRoot, 'component'), - isFirstTimeE2E: await this.ctx.project.isFirstTimeAccessing(projectRoot, 'e2e'), + isCTConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'component'), + isE2EConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'e2e'), config: await this.ctx.project.getResolvedConfigFields(projectRoot), preferences: await this.ctx.project.getProjectPreferences(title), generatedSpec: null, @@ -224,7 +226,7 @@ export class ProjectActions { throw Error(`Cannot create index.html without activeProject.`) } - if (this.ctx.activeProject?.isFirstTimeCT) { + if (this.ctx.activeProject?.isCTConfigured) { const indexHtmlPath = path.resolve(this.ctx.activeProject.projectRoot, 'cypress/component/support/index.html') await this.ctx.fs.outputFile(indexHtmlPath, template) diff --git a/packages/data-context/src/actions/WizardActions.ts b/packages/data-context/src/actions/WizardActions.ts index 108d53af5b84..41cb24dafb57 100644 --- a/packages/data-context/src/actions/WizardActions.ts +++ b/packages/data-context/src/actions/WizardActions.ts @@ -120,7 +120,7 @@ export class WizardActions { } if (this.data.currentStep === 'welcome' && this.data.chosenTestingType === 'component') { - if (this.ctx.activeProject?.isFirstTimeCT) { + if (this.ctx.activeProject?.isCTConfigured) { this.navigateToStep('selectFramework') } else if (!this.ctx.activeProject?.ctPluginsInitialized) { // not first time, and we haven't initialized plugins - initialize them @@ -134,7 +134,7 @@ export class WizardActions { } if (this.data.currentStep === 'welcome' && this.data.chosenTestingType === 'e2e') { - if (this.ctx.activeProject?.isFirstTimeE2E) { + if (this.ctx.activeProject?.isE2EConfigured) { this.navigateToStep('configFiles') } else if (!this.ctx.activeProject?.e2ePluginsInitialized) { // not first time, and we haven't initialized plugins - initialize them diff --git a/packages/data-context/src/data/coreDataShape.ts b/packages/data-context/src/data/coreDataShape.ts index 91c0f8b2b39f..eab9bd288308 100644 --- a/packages/data-context/src/data/coreDataShape.ts +++ b/packages/data-context/src/data/coreDataShape.ts @@ -22,8 +22,8 @@ export interface ActiveProjectShape extends ProjectShape { title: string ctPluginsInitialized: Maybe e2ePluginsInitialized: Maybe - isFirstTimeCT: Maybe - isFirstTimeE2E: Maybe + isCTConfigured: Maybe + isE2EConfigured: Maybe currentSpecId?: Maybe specs?: FoundSpec[] config: ResolvedFromConfig[] diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index fba0b9f4d337..8817f03cf559 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -1,5 +1,5 @@ import type { SpecType } from '@packages/graphql/src/gen/nxs.gen' -import type { FullConfig, ResolvedFromConfig, RESOLVED_FROM } from '@packages/types' +import type { FullConfig, ResolvedFromConfig, RESOLVED_FROM, SettingsOptions } from '@packages/types' import path from 'path' import type { DataContext } from '..' @@ -13,9 +13,9 @@ export class ProjectDataSource { } async projectId (projectRoot: string) { - const config = await this.getConfig(projectRoot) + const config = await this.api.getProjectConfig(projectRoot) - return config.projectId + return config?.projectId ?? null } projectTitle (projectRoot: string) { @@ -53,12 +53,14 @@ export class ProjectDataSource { return specs.find((x) => x.absolute === currentSpecAbs) ?? null } - getConfig (projectRoot: string) { - return this.configLoader.load(projectRoot) + async getConfig (projectRoot: string) { + return this.configLoader({ + // configFile: 'cypress.config.ts', + }).load(projectRoot) } async getResolvedConfigFields (projectRoot: string): Promise { - const config = await this.configLoader.load(projectRoot) + const config = await this.getConfig(projectRoot) interface ResolvedFromWithField extends ResolvedFromConfig { field: typeof RESOLVED_FROM[number] @@ -86,34 +88,28 @@ export class ProjectDataSource { }) as ResolvedFromConfig[] } - private configLoader = this.ctx.loader((projectRoots) => { - return Promise.all(projectRoots.map((root) => this.ctx._apis.projectApi.getConfig(root))) - }) - - async isFirstTimeAccessing (projectRoot: string, testingType: 'e2e' | 'component') { - try { - const config = await this.ctx.file.readJsonFile<{ e2e?: object, component?: object }>(path.join(projectRoot, 'cypress.json')) - - // If we have a cypress.json file, even with no overrides, assume that it's not our - // first time accessing (for now, until the config refactor lands) - if (testingType === 'e2e') { - return false - } + private configLoader (options?: SettingsOptions) { + return this.ctx.loader((projectRoots) => { + return Promise.all(projectRoots.map((root) => this.ctx._apis.projectApi.getConfig(root, options))) // 12 + }) + } - const overrides = config.component || {} + async isTestingTypeConfigured (projectRoot: string, testingType: 'e2e' | 'component') { + const config = await this.api.getProjectConfig(projectRoot) - return Object.keys(overrides).length === 0 - } catch (e) { - const err = e as Error & { code?: string } + if (!config) { + return true + } - // if they do not have a cypress.json, it's definitely their first time using Cypress. - if (err.code === 'ENOENT') { - return true - } + if (testingType === 'e2e') { + return config.isE2EConfigured + } - // unexpected error - throw err + if (testingType === 'component') { + return config.isCTConfigured } + + return false } async getProjectPreferences (projectTitle: string) { diff --git a/packages/frontend-shared/cypress/support/mock-graphql/stubgql-Mutation.ts b/packages/frontend-shared/cypress/support/mock-graphql/stubgql-Mutation.ts index 5959280fd741..27d6fd802afe 100644 --- a/packages/frontend-shared/cypress/support/mock-graphql/stubgql-Mutation.ts +++ b/packages/frontend-shared/cypress/support/mock-graphql/stubgql-Mutation.ts @@ -11,8 +11,8 @@ export const stubMutation: MaybeResolver = { id: `project:${args.path}`, title: path.basename(args.path), projectRoot: args.path, - isFirstTimeCT: true, - isFirstTimeE2E: true, + isCTConfigured: true, + isE2EConfigured: true, __typename: 'Project', config, } diff --git a/packages/frontend-shared/cypress/support/mock-graphql/stubgql-Project.ts b/packages/frontend-shared/cypress/support/mock-graphql/stubgql-Project.ts index 5086eb608d91..656d7b025cfc 100644 --- a/packages/frontend-shared/cypress/support/mock-graphql/stubgql-Project.ts +++ b/packages/frontend-shared/cypress/support/mock-graphql/stubgql-Project.ts @@ -14,8 +14,8 @@ export const createTestProject = (title: string): CodegenTypeMap['Project'] => { // TODO: What a mess, type this without all the hacks return { ...testNodeId('Project'), - isFirstTimeCT: true, - isFirstTimeE2E: true, + isCTConfigured: true, + isE2EConfigured: true, projectId: `${snakeTitle}-id`, title, projectRoot: `/usr/local/dev/projects/${snakeTitle}`, diff --git a/packages/graphql/schemas/schema.graphql b/packages/graphql/schemas/schema.graphql index 392da2641a84..35d633057fd4 100644 --- a/packages/graphql/schemas/schema.graphql +++ b/packages/graphql/schemas/schema.graphql @@ -520,10 +520,10 @@ type Project implements Node { id: ID! """Whether the user configured this project to use Component Testing""" - isFirstTimeCT: Boolean! + isCTConfigured: Boolean! """Whether the user configured this project to use e2e Testing""" - isFirstTimeE2E: Boolean! + isE2EConfigured: Boolean! """Cached preferences for this project""" preferences: ProjectPreferences diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index f30ef2294e16..dad983446f94 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -221,11 +221,13 @@ export const mutation = mutationType({ try { await ctx.actions.wizard.initializeOpenProject() ctx.coreData.baseError = null - } catch (error: any) { + } catch (error) { + const e = error as Error + ctx.coreData.baseError = { title: 'Cypress Configuration Error', - message: error.message, - stack: error.stack, + message: e.message, + stack: e.stack, } } }, diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts index a5e82ad63411..823e1e495ba7 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts @@ -25,7 +25,7 @@ export const Project = objectType({ t.string('projectId', { description: 'Used to associate project with Cypress cloud', - resolve: (source, args, ctx) => ctx.project.projectId(source.projectRoot).then((val) => val ?? null), + resolve: async (source, args, ctx) => ctx.project.projectId(source.projectRoot), }) t.nonNull.string('projectRoot') @@ -34,17 +34,17 @@ export const Project = objectType({ resolve: (source, args, ctx) => ctx.project.projectTitle(source.projectRoot), }) - t.nonNull.boolean('isFirstTimeCT', { + t.nonNull.boolean('isCTConfigured', { description: 'Whether the user configured this project to use Component Testing', resolve: (source, args, ctx) => { - return ctx.project.isFirstTimeAccessing(source.projectRoot, 'component') + return ctx.project.isTestingTypeConfigured(source.projectRoot, 'component') }, }) - t.nonNull.boolean('isFirstTimeE2E', { + t.nonNull.boolean('isE2EConfigured', { description: 'Whether the user configured this project to use e2e Testing', resolve: (source, args, ctx) => { - return ctx.project.isFirstTimeAccessing(source.projectRoot, 'e2e') + return ctx.project.isTestingTypeConfigured(source.projectRoot, 'e2e') }, }) diff --git a/packages/launchpad/src/global/GlobalProjectCard.vue b/packages/launchpad/src/global/GlobalProjectCard.vue index 23ffb1c657a3..d66baac3757f 100644 --- a/packages/launchpad/src/global/GlobalProjectCard.vue +++ b/packages/launchpad/src/global/GlobalProjectCard.vue @@ -73,11 +73,6 @@ fragment GlobalProjectCard on Project { id title projectRoot - cloudProject { - latestRun { - status - } - } } ` diff --git a/packages/launchpad/src/setup/TestingTypeCards.spec.tsx b/packages/launchpad/src/setup/TestingTypeCards.spec.tsx index 5f46f0983cbf..9534fc0b0a8b 100644 --- a/packages/launchpad/src/setup/TestingTypeCards.spec.tsx +++ b/packages/launchpad/src/setup/TestingTypeCards.spec.tsx @@ -9,8 +9,8 @@ describe('TestingTypeCards', () => { cy.mountFragment(TestingTypeCardsFragmentDoc, { onResult: (result, ctx) => { if (result.app.activeProject) { - result.app.activeProject.isFirstTimeCT = true - result.app.activeProject.isFirstTimeE2E = true + result.app.activeProject.isCTConfigured = true + result.app.activeProject.isE2EConfigured = true } }, render: (gqlVal) => { @@ -28,8 +28,8 @@ describe('TestingTypeCards', () => { cy.mountFragment(TestingTypeCardsFragmentDoc, { onResult: (result, ctx) => { if (result.app.activeProject) { - result.app.activeProject.isFirstTimeCT = false - result.app.activeProject.isFirstTimeE2E = false + result.app.activeProject.isCTConfigured = false + result.app.activeProject.isE2EConfigured = false } }, render: (gqlVal) => { @@ -45,8 +45,8 @@ describe('TestingTypeCards', () => { cy.mountFragment(TestingTypeCardsFragmentDoc, { onResult: (result, ctx) => { if (result.app.activeProject) { - result.app.activeProject.isFirstTimeCT = false - result.app.activeProject.isFirstTimeE2E = true + result.app.activeProject.isCTConfigured = false + result.app.activeProject.isE2EConfigured = true } }, render: (gqlVal) => { diff --git a/packages/launchpad/src/setup/TestingTypeCards.vue b/packages/launchpad/src/setup/TestingTypeCards.vue index d7c19a2d33d7..7da5c5a3ed25 100644 --- a/packages/launchpad/src/setup/TestingTypeCards.vue +++ b/packages/launchpad/src/setup/TestingTypeCards.vue @@ -5,8 +5,8 @@ :id="e2e.type" :data-cy-testingType="e2e.type" :title="e2e.title" - :description="firstTimeE2E ? e2e.description : 'LAUNCH'" - :configured="!firstTimeE2E" + :description="isE2EConfigured ? 'LAUNCH' : e2e.description " + :configured="isE2EConfigured" :image="e2ePreview" role="button" @click="e2eNextStep" @@ -19,8 +19,8 @@ :id="ct.type" :data-cy-testingType="ct.type" :title="ct.title" - :description="firstTimeCT ? ct.description : 'LAUNCH'" - :configured="!firstTimeCT" + :description="isCTConfigured ? 'LAUNCH' : ct.description" + :configured="isCTConfigured" :image="ctPreview" role="button" @click="ctNextStep" @@ -48,8 +48,8 @@ fragment TestingTypeCards on Query { app { activeProject { id - isFirstTimeCT - isFirstTimeE2E + isCTConfigured + isE2EConfigured } } wizard { @@ -79,8 +79,8 @@ const ct = computed(() => { return props.gql.wizard.testingTypes.find((x) => x.type === 'component') }) -const firstTimeCT = computed(() => props.gql.app.activeProject?.isFirstTimeCT) -const firstTimeE2E = computed(() => props.gql.app.activeProject?.isFirstTimeE2E) +const isCTConfigured = computed(() => props.gql.app.activeProject?.isCTConfigured) +const isE2EConfigured = computed(() => props.gql.app.activeProject?.isE2EConfigured) const ctNextStep = async () => { return mutation.executeMutation({ input: { testingType: 'component', direction: 'forward' } }) diff --git a/packages/server/lib/cache.js b/packages/server/lib/cache.js index 2e8410612043..2c483ceea820 100644 --- a/packages/server/lib/cache.js +++ b/packages/server/lib/cache.js @@ -39,6 +39,7 @@ module.exports = { USER: {}, PROJECTS: [], PROJECT_PREFERENCES: {}, + PROJECTS_CONFIG: {}, } }, @@ -144,6 +145,19 @@ module.exports = { return fileUtil.set({ USER: {} }) }, + // We may need to set this value every time the config file is read, or updated + // having it on the cache, will help us preventing to read the file on a cp + // to get the projectId + setProjectConfig (projectRoot, config) { + return fileUtil.set({ PROJECTS_CONFIG: { [projectRoot]: config } }) + }, + + getProjectConfig (projectRoot) { + return fileUtil.get('PROJECTS_CONFIG').then((projects) => { + return projects && projects[projectRoot] ? projects[projectRoot] : null + }) + }, + removeLatestProjects () { return fileUtil.set({ PROJECTS: [] }) }, diff --git a/packages/server/lib/configFiles.ts b/packages/server/lib/configFiles.ts index b8a0495b1bce..3989758e5251 100644 --- a/packages/server/lib/configFiles.ts +++ b/packages/server/lib/configFiles.ts @@ -1,2 +1,2 @@ // the first file is the default created file -export const CYPRESS_CONFIG_FILES = ['cypress.json', 'cypress.config.js', 'cypress.config.ts'] +export const CYPRESS_CONFIG_FILES = ['cypress.config.js', 'cypress.config.ts'] diff --git a/packages/server/lib/makeDataContext.ts b/packages/server/lib/makeDataContext.ts index 7168b21490b6..63afe2a7d891 100644 --- a/packages/server/lib/makeDataContext.ts +++ b/packages/server/lib/makeDataContext.ts @@ -1,6 +1,6 @@ import { DataContext } from '@packages/data-context' import specsUtil from './util/specs' -import type { FindSpecs, FoundBrowser, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, PlatformName, Preferences } from '@packages/types' +import type { FindSpecs, FoundBrowser, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, PlatformName, Preferences, ProjectConfigCache, SettingsOptions } from '@packages/types' import { checkAuthQuery } from '@packages/graphql/src/stitching/remoteGraphQLCalls' import browserUtils from './browsers/utils' import auth from './gui/auth' @@ -39,8 +39,8 @@ export function makeDataContext (options: MakeDataContextOptions) { }, }, projectApi: { - getConfig (projectRoot: string) { - return config.get(projectRoot) + getConfig (projectRoot: string, options?: SettingsOptions) { + return config.get(projectRoot, options) }, launchProject (browser: FoundBrowser, spec: Cypress.Spec, options?: LaunchOpts) { return openProject.launch({ ...browser }, spec, options) @@ -57,6 +57,12 @@ export function makeDataContext (options: MakeDataContextOptions) { findSpecs (payload: FindSpecs) { return specsUtil.findSpecs(payload) }, + setProjectConfig (projectRoot: string, config: Partial | null) { + return cache.setProjectConfig(projectRoot, config) + }, + getProjectConfig (projectRoot: string) { + return cache.getProjectConfig(projectRoot) + }, clearLatestProjectsCache () { return cache.removeLatestProjects() }, diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index fcc17c276ff3..8a9aabbf4c02 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -5,17 +5,11 @@ import errors from '../errors' import { fs } from '../util/fs' import { requireAsync } from './require_async' import Debug from 'debug' +import { setProjectConfig } from '../cache' +import type { SettingsOptions } from '@packages/types' const debug = Debug('cypress:server:settings') -interface SettingsOptions { - testingType?: 'component' |'e2e' - configFile?: string | false - args?: { - runProject?: string - } -} - function jsCode (obj) { const objJSON = obj && !_.isEmpty(obj) ? JSON.stringify(_.omit(obj, 'configFile'), null, 2) @@ -126,7 +120,7 @@ export function configFile (options: SettingsOptions = {}) { // default is only used in tests. // This prevents a the change from becoming bigger than it should // FIXME: remove the default - return options.configFile === false ? false : (options.configFile || 'cypress.json') + return options.configFile === false ? false : (options.configFile || 'cypress.config.js') } export function id (projectRoot, options = {}) { @@ -146,12 +140,10 @@ export function read (projectRoot, options: SettingsOptions = {}) { const file = pathToConfigFile(projectRoot, options) - const readPromise = /\.json$/.test(file) ? fs.readJSON(path.resolve(projectRoot, file)) : requireAsync(file, { + return requireAsync(file, { projectRoot, loadErrorCode: 'CONFIG_FILE_ERROR', }) - - return readPromise .catch((err) => { if (err.type === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') { if (options.args?.runProject) { @@ -173,18 +165,28 @@ export function read (projectRoot, options: SettingsOptions = {}) { } debug('resolved configObject', configObject) - const changed = _applyRewriteRules(configObject) + const changed: { projectId?: string, component?: {}, e2e?: {} } = _applyRewriteRules(configObject) - // if our object is unchanged + const isCTConfigured = Boolean(Object.keys(changed?.component ?? {}).length) + const isE2EConfigured = Boolean(Object.keys(changed?.e2e ?? {}).length) + + return setProjectConfig(projectRoot, { + projectId: changed?.projectId, + isCTConfigured, + isE2EConfigured, + }) + .then(() => { + // if our object is unchanged // then just return it - if (_.isEqual(configObject, changed)) { - return configObject - } + if (_.isEqual(configObject, changed)) { + return configObject + } - // else write the new reduced obj - return _write(file, changed) - .then((config) => { - return config + // else write the new reduced obj and store the projectId on the cache + return _write(file, changed) + .then((config) => { + return config + }) }) }).catch((err) => { debug('an error occured when reading config', err) diff --git a/packages/types/src/cache.ts b/packages/types/src/cache.ts index 24f46381bdc7..4461f0e07cdc 100644 --- a/packages/types/src/cache.ts +++ b/packages/types/src/cache.ts @@ -14,3 +14,9 @@ export interface CachedUser { name: string email: string } + +export interface ProjectConfigCache { + projectId?: string | null + isCTConfigured: boolean + isE2EConfigured: boolean +} diff --git a/packages/types/src/config.ts b/packages/types/src/config.ts index ab71a73b5d1c..f069098e2bd4 100644 --- a/packages/types/src/config.ts +++ b/packages/types/src/config.ts @@ -30,3 +30,11 @@ export interface SampleConfigFile{ warningText?: string warningLink?: string } + +export interface SettingsOptions { + testingType?: 'component' |'e2e' + configFile?: string | false + args?: { + runProject?: string + } +} From 614ed508945920fbc8b6313f11909cbc7f2f312c Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 21 Oct 2021 14:36:08 -0500 Subject: [PATCH 02/57] Update cache --- npm/vue/cypress.config.ts | 9 +++++ npm/vue/cypress.json | 9 ----- .../src/actions/ProjectActions.ts | 7 ++-- .../src/sources/ProjectDataSource.ts | 37 +++++++++++++++++-- .../schemaTypes/objectTypes/gql-Mutation.ts | 13 ++++++- .../schemaTypes/objectTypes/gql-Project.ts | 2 +- packages/launchpad/cypress.config.ts | 27 ++++++++++++++ packages/launchpad/cypress.json | 27 -------------- .../launchpad/src/setup/TestingTypeCards.vue | 4 +- packages/server/lib/config.ts | 6 +++ packages/server/lib/makeDataContext.ts | 8 +++- packages/server/lib/project-base.ts | 8 ++++ packages/server/lib/util/settings.ts | 29 +++++---------- packages/types/src/cache.ts | 6 --- 14 files changed, 117 insertions(+), 75 deletions(-) create mode 100644 npm/vue/cypress.config.ts delete mode 100644 npm/vue/cypress.json create mode 100644 packages/launchpad/cypress.config.ts delete mode 100644 packages/launchpad/cypress.json diff --git a/npm/vue/cypress.config.ts b/npm/vue/cypress.config.ts new file mode 100644 index 000000000000..36eb552fea7e --- /dev/null +++ b/npm/vue/cypress.config.ts @@ -0,0 +1,9 @@ +module.exports = { + 'viewportWidth': 500, + 'viewportHeight': 500, + 'video': false, + 'responseTimeout': 2500, + 'projectId': '134ej7', + 'testFiles': '**/*spec.{js,ts,tsx}', + 'experimentalFetchPolyfill': true, +} diff --git a/npm/vue/cypress.json b/npm/vue/cypress.json deleted file mode 100644 index a25995a3f06c..000000000000 --- a/npm/vue/cypress.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "viewportWidth": 500, - "viewportHeight": 500, - "video": false, - "responseTimeout": 2500, - "projectId": "134ej7", - "testFiles": "**/*spec.{js,ts,tsx}", - "experimentalFetchPolyfill": true -} \ No newline at end of file diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 13bc2067f548..c8baf3fa1e3f 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -1,5 +1,5 @@ import type { MutationAddProjectArgs, MutationAppCreateConfigFileArgs, MutationSetProjectPreferencesArgs, TestingTypeEnum } from '@packages/graphql/src/gen/nxs.gen' -import type { FindSpecs, FoundBrowser, FoundSpec, FullConfig, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, Preferences, ProjectConfigCache, SettingsOptions } from '@packages/types' +import type { FindSpecs, FoundBrowser, FoundSpec, FullConfig, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, Preferences, SettingsOptions } from '@packages/types' import path from 'path' import type { ProjectShape } from '../data/coreDataShape' @@ -24,8 +24,9 @@ export interface ProjectApiShape { clearProjectPreferences(projectTitle: string): Promise clearAllProjectPreferences(): Promise closeActiveProject(): Promise - setProjectConfig(projectRoot: string, projectId: Partial | null): Promise - getProjectConfig (projectRoot: string): Promise + setProjectConfig(projectRoot: string, projectId: Partial | null): Promise + getProjectConfig (projectRoot: string): Promise + error(type: string, ...args: any): Error } export class ProjectActions { diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index e51d85ec935f..d5a644682b38 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -14,7 +14,7 @@ export class ProjectDataSource { } async projectId (projectRoot: string) { - const config = await this.api.getProjectConfig(projectRoot) + const config = await this.getConfig(projectRoot) return config?.projectId ?? null } @@ -54,9 +54,38 @@ export class ProjectDataSource { return specs.find((x) => x.absolute === currentSpecAbs) ?? null } + private async getDefaultConfigFilePath (projectRoot: string) { + const cypressConfigFiles = ['cypress.config.js', 'cypress.config.ts'] + const filesInProjectDir = await this.ctx.fs.readdir(projectRoot) + + const foundConfigFiles = cypressConfigFiles.filter((file) => filesInProjectDir.includes(file)) + + // if we only found one default file, it is the one + if (foundConfigFiles.length === 1) { + return foundConfigFiles[0] + } + + // if we found more than one, throw a language conflict + if (foundConfigFiles.length > 1) { + throw this.ctx._apis.projectApi.error('CONFIG_FILES_LANGUAGE_CONFLICT', projectRoot, ...foundConfigFiles) + } + + return cypressConfigFiles[0] + } + async getConfig (projectRoot: string) { + // Check first the config files, to be sure there are not to config files + const configFile = await this.getDefaultConfigFilePath(projectRoot) + + // Check if we have already cached the config + const config = await this.api.getProjectConfig(projectRoot) + + if (config) { + return config + } + return this.configLoader({ - // configFile: 'cypress.config.ts', + configFile, }).load(projectRoot) } @@ -103,11 +132,11 @@ export class ProjectDataSource { } if (testingType === 'e2e') { - return config.isE2EConfigured + return Boolean(Object.keys(config.e2e ?? {}).length) } if (testingType === 'component') { - return config.isCTConfigured + return Boolean(Object.keys(config.component ?? {}).length) } return false diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index dad983446f94..436df63dc457 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -272,7 +272,18 @@ export const mutation = mutationType({ path: nonNull(stringArg()), }, resolve: async (_, args, ctx) => { - await ctx.actions.project.setActiveProject(args.path) + try { + await ctx.actions.project.setActiveProject(args.path) + ctx.coreData.baseError = null + } catch (error) { + const e = error as Error + + ctx.coreData.baseError = { + title: 'Cypress Configuration Error', + message: e.message, + stack: e.stack, + } + } }, }) diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts index 482ce4775887..aa895c54a6c1 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts @@ -44,7 +44,7 @@ export const Project = objectType({ t.string('projectId', { description: 'Used to associate project with Cypress cloud', - resolve: async (source, args, ctx) => ctx.project.projectId(source.projectRoot), + resolve: (source, args, ctx) => ctx.project.projectId(source.projectRoot), }) t.nonNull.string('projectRoot') diff --git a/packages/launchpad/cypress.config.ts b/packages/launchpad/cypress.config.ts new file mode 100644 index 000000000000..272ce4ac47a2 --- /dev/null +++ b/packages/launchpad/cypress.config.ts @@ -0,0 +1,27 @@ +module.exports = { + '$schema': '../../cli/schema/cypress.schema.json', + 'projectId': 'sehy69', + 'viewportWidth': 800, + 'viewportHeight': 850, + 'retries': { + 'runMode': 2, + 'openMode': 0, + }, + 'nodeVersion': 'system', + 'testFiles': '**/*.spec.{js,ts,tsx,jsx}', + 'reporter': '../../node_modules/cypress-multi-reporters/index.js', + 'reporterOptions': { + 'configFile': '../../mocha-reporter-config.json', + }, + 'componentFolder': 'src', + 'component': { + 'testFiles': '**/*.spec.{js,ts,tsx,jsx}', + 'supportFile': 'cypress/component/support/index.ts', + 'pluginsFile': 'cypress/component/plugins/index.js', + }, + 'e2e': { + 'supportFile': 'cypress/e2e/support/e2eSupport.ts', + 'integrationFolder': 'cypress/e2e/integration', + 'pluginsFile': 'cypress/e2e/plugins/index.ts', + }, +} diff --git a/packages/launchpad/cypress.json b/packages/launchpad/cypress.json deleted file mode 100644 index ee408115b831..000000000000 --- a/packages/launchpad/cypress.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "$schema": "../../cli/schema/cypress.schema.json", - "projectId": "sehy69", - "viewportWidth": 800, - "viewportHeight": 850, - "retries": { - "runMode": 2, - "openMode": 0 - }, - "nodeVersion": "system", - "testFiles": "**/*.spec.{js,ts,tsx,jsx}", - "reporter": "../../node_modules/cypress-multi-reporters/index.js", - "reporterOptions": { - "configFile": "../../mocha-reporter-config.json" - }, - "componentFolder": "src", - "component": { - "testFiles": "**/*.spec.{js,ts,tsx,jsx}", - "supportFile": "cypress/component/support/index.ts", - "pluginsFile": "cypress/component/plugins/index.js" - }, - "e2e": { - "supportFile": "cypress/e2e/support/e2eSupport.ts", - "integrationFolder": "cypress/e2e/integration", - "pluginsFile": "cypress/e2e/plugins/index.ts" - } -} diff --git a/packages/launchpad/src/setup/TestingTypeCards.vue b/packages/launchpad/src/setup/TestingTypeCards.vue index 7da5c5a3ed25..03750091c0d8 100644 --- a/packages/launchpad/src/setup/TestingTypeCards.vue +++ b/packages/launchpad/src/setup/TestingTypeCards.vue @@ -79,8 +79,8 @@ const ct = computed(() => { return props.gql.wizard.testingTypes.find((x) => x.type === 'component') }) -const isCTConfigured = computed(() => props.gql.app.activeProject?.isCTConfigured) -const isE2EConfigured = computed(() => props.gql.app.activeProject?.isE2EConfigured) +const isCTConfigured = computed(() => Boolean(props.gql.app.activeProject?.isCTConfigured)) +const isE2EConfigured = computed(() => Boolean(props.gql.app.activeProject?.isE2EConfigured)) const ctNextStep = async () => { return mutation.executeMutation({ input: { testingType: 'component', direction: 'forward' } }) diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index 6b3a350d5f45..e96ff1d1f7c3 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -14,6 +14,7 @@ import * as settings from './util/settings' import Debug from 'debug' import pathHelpers from './util/path_helpers' import findSystemNode from './util/find_system_node' +import { setProjectConfig } from './cache' export interface ConfigSettingsConfig { testingType: TestingType @@ -217,6 +218,11 @@ export function get (projectRoot, options = {}): Promise { options, }) }) + .then((fullConfig) => { + return setProjectConfig(projectRoot, fullConfig).then(() => { + return fullConfig + }) + }) } export function set (obj: Record = {}) { diff --git a/packages/server/lib/makeDataContext.ts b/packages/server/lib/makeDataContext.ts index 63afe2a7d891..3a968bd0b888 100644 --- a/packages/server/lib/makeDataContext.ts +++ b/packages/server/lib/makeDataContext.ts @@ -1,6 +1,6 @@ import { DataContext } from '@packages/data-context' import specsUtil from './util/specs' -import type { FindSpecs, FoundBrowser, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, PlatformName, Preferences, ProjectConfigCache, SettingsOptions } from '@packages/types' +import type { FindSpecs, FoundBrowser, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, PlatformName, Preferences, FullConfig, SettingsOptions } from '@packages/types' import { checkAuthQuery } from '@packages/graphql/src/stitching/remoteGraphQLCalls' import browserUtils from './browsers/utils' import auth from './gui/auth' @@ -9,6 +9,7 @@ import * as config from './config' import type { EventEmitter } from 'events' import { openProject } from './open_project' import cache from './cache' +import errors from './errors' const { getBrowsers } = browserUtils @@ -57,7 +58,7 @@ export function makeDataContext (options: MakeDataContextOptions) { findSpecs (payload: FindSpecs) { return specsUtil.findSpecs(payload) }, - setProjectConfig (projectRoot: string, config: Partial | null) { + setProjectConfig (projectRoot: string, config: Partial | null) { return cache.setProjectConfig(projectRoot, config) }, getProjectConfig (projectRoot: string) { @@ -84,6 +85,9 @@ export function makeDataContext (options: MakeDataContextOptions) { closeActiveProject () { return openProject.closeActiveProject() }, + error (type: string, ...args: any) { + throw errors.throw(type, ...args) + }, }, }) } diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index b57c180b7809..6a5a4cc73943 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -34,6 +34,7 @@ import { SpecsStore } from './specs-store' import { checkSupportFile, getDefaultConfigFilePath } from './project_utils' import type { FoundBrowser, OpenProjectLaunchOptions } from '@packages/types' import { DataContextShell } from '@packages/data-context/src/DataContextShell' +import { getProjectConfig } from './cache' // Cannot just use RuntimeConfigOptions as is because some types are not complete. // Instead, this is an interface of values that have been manually validated to exist @@ -859,6 +860,13 @@ export class ProjectBase extends EE { async getProjectId () { await this.verifyExistence() + + const config = await getProjectConfig(this.projectRoot) + + if (config?.projectId) { + return config.projectId + } + const readSettings = await settings.read(this.projectRoot, this.options) if (readSettings && readSettings.projectId) { diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index 8a9aabbf4c02..41066cb24e38 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -5,7 +5,6 @@ import errors from '../errors' import { fs } from '../util/fs' import { requireAsync } from './require_async' import Debug from 'debug' -import { setProjectConfig } from '../cache' import type { SettingsOptions } from '@packages/types' const debug = Debug('cypress:server:settings') @@ -120,7 +119,7 @@ export function configFile (options: SettingsOptions = {}) { // default is only used in tests. // This prevents a the change from becoming bigger than it should // FIXME: remove the default - return options.configFile === false ? false : (options.configFile || 'cypress.config.js') + return options.configFile === false ? false : options.configFile } export function id (projectRoot, options = {}) { @@ -167,26 +166,16 @@ export function read (projectRoot, options: SettingsOptions = {}) { debug('resolved configObject', configObject) const changed: { projectId?: string, component?: {}, e2e?: {} } = _applyRewriteRules(configObject) - const isCTConfigured = Boolean(Object.keys(changed?.component ?? {}).length) - const isE2EConfigured = Boolean(Object.keys(changed?.e2e ?? {}).length) - - return setProjectConfig(projectRoot, { - projectId: changed?.projectId, - isCTConfigured, - isE2EConfigured, - }) - .then(() => { - // if our object is unchanged + // if our object is unchanged // then just return it - if (_.isEqual(configObject, changed)) { - return configObject - } + if (_.isEqual(configObject, changed)) { + return configObject + } - // else write the new reduced obj and store the projectId on the cache - return _write(file, changed) - .then((config) => { - return config - }) + // else write the new reduced obj and store the projectId on the cache + return _write(file, changed) + .then((config) => { + return config }) }).catch((err) => { debug('an error occured when reading config', err) diff --git a/packages/types/src/cache.ts b/packages/types/src/cache.ts index 4461f0e07cdc..24f46381bdc7 100644 --- a/packages/types/src/cache.ts +++ b/packages/types/src/cache.ts @@ -14,9 +14,3 @@ export interface CachedUser { name: string email: string } - -export interface ProjectConfigCache { - projectId?: string | null - isCTConfigured: boolean - isE2EConfigured: boolean -} From 7b65e936c6a8efbda758ff7ed003393492147597 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 21 Oct 2021 15:18:17 -0500 Subject: [PATCH 03/57] Replace cypress.json files for cypress.config.{ts|js} --- npm/angular/cypress.config.ts | 11 +++++++ npm/angular/cypress.json | 11 ------- .../src/schematics/ng-add/files/cypress.json | 9 ------ npm/design-system/cypress.config.js | 16 ++++++++++ npm/design-system/cypress.json | 16 ---------- npm/react/cypress.config.js | 15 ++++++++++ npm/react/cypress.json | 15 ---------- npm/react/examples/a11y/cypress.config.js | 7 +++++ npm/react/examples/a11y/cypress.json | 7 ----- npm/react/examples/craco/cypress.config.js | 6 ++++ npm/react/examples/craco/cypress.json | 6 ---- .../examples/find-webpack/cypress.config.ts | 13 +++++++++ npm/react/examples/find-webpack/cypress.json | 13 --------- .../nextjs-webpack-5/cypress.config.js | 8 +++++ .../examples/nextjs-webpack-5/cypress.json | 8 ----- npm/react/examples/nextjs/cypress.config.js | 11 +++++++ npm/react/examples/nextjs/cypress.json | 11 ------- .../react-scripts-folder/cypress.config.js | 8 +++++ .../react-scripts-folder/cypress.json | 8 ----- .../cypress.config.js | 7 +++++ .../react-scripts-typescript/cypress.json | 7 ----- .../examples/react-scripts/cypress.config.js | 8 +++++ npm/react/examples/react-scripts/cypress.json | 8 ----- .../examples/sass-and-ts/cypress.config.js | 12 ++++++++ npm/react/examples/sass-and-ts/cypress.json | 12 -------- .../examples/snapshots/cypress.config.js | 16 ++++++++++ npm/react/examples/snapshots/cypress.json | 16 ---------- npm/react/examples/tailwind/cypress.config.js | 11 +++++++ npm/react/examples/tailwind/cypress.json | 11 ------- .../using-babel-typescript/cypress.config.js | 8 +++++ .../using-babel-typescript/cypress.json | 8 ----- .../examples/using-babel/cypress.config.js | 8 +++++ npm/react/examples/using-babel/cypress.json | 8 ----- .../{cypress.json => cypress.config.js} | 2 +- .../cypress.config.js | 11 +++++++ .../cypress.json | 11 ------- .../cypress.config.js | 7 +++++ .../visual-testing-with-happo/cypress.json | 7 ----- .../cypress.config.js | 8 +++++ .../visual-testing-with-percy/cypress.json | 8 ----- .../examples/webpack-file/cypress.config.js | 7 +++++ npm/react/examples/webpack-file/cypress.json | 7 ----- .../webpack-options/cypress.config.js | 7 +++++ .../examples/webpack-options/cypress.json | 7 ----- npm/vite-dev-server/cypress.config.ts | 7 +++++ npm/vite-dev-server/cypress.json | 7 ----- .../examples/code-coverage/cypress.config.js | 6 ++++ npm/vue/examples/code-coverage/cypress.json | 6 ---- npm/vue/examples/vue-cli/cypress.config.js | 6 ++++ npm/vue/examples/vue-cli/cypress.json | 6 ---- npm/webpack-preprocessor/cypress.config.js | 3 ++ npm/webpack-preprocessor/cypress.json | 3 -- .../examples/react-app/cypress.config.js | 6 ++++ .../examples/react-app/cypress.json | 6 ---- .../examples/use-babelrc/cypress.config.js | 4 +++ .../examples/use-babelrc/cypress.json | 4 --- .../examples/use-ts-loader/cypress.config.ts | 4 +++ .../examples/use-ts-loader/cypress.json | 4 --- packages/app/cypress.config.ts | 29 +++++++++++++++++++ packages/app/cypress.json | 29 ------------------- packages/desktop-gui/cypress.config.js | 21 ++++++++++++++ packages/desktop-gui/cypress.json | 21 -------------- packages/driver/cypress.config.ts | 12 ++++++++ packages/driver/cypress.json | 12 -------- .../{cypress.json => cypress.config.js} | 2 +- packages/frontend-shared/cypress.config.ts | 22 ++++++++++++++ packages/frontend-shared/cypress.json | 22 -------------- .../{cypress.json => cypress.config.ts} | 2 +- packages/reporter/cypress.config.ts | 14 +++++++++ packages/reporter/cypress.json | 14 --------- packages/runner-ct/cypress.config.ts | 11 +++++++ packages/runner-ct/cypress.json | 11 ------- packages/runner/cypress.config.js | 15 ++++++++++ packages/runner/cypress.json | 15 ---------- packages/ui-components/cypress.config.js | 12 ++++++++ packages/ui-components/cypress.json | 12 -------- .../browser-extensions/cypress.config.js | 1 + .../projects/browser-extensions/cypress.json | 1 - .../busted-support-file/cypress.config.js | 1 + .../projects/busted-support-file/cypress.json | 1 - .../cypress.config.js | 1 + .../chrome-browser-preferences/cypress.json | 1 - .../component-tests/cypress.config.js | 3 ++ .../projects/component-tests/cypress.json | 3 -- .../cypress.config.js | 12 ++++++++ .../config-with-invalid-browser/cypress.json | 12 -------- .../cypress.config.js | 3 ++ .../config-with-invalid-viewport/cypress.json | 3 -- .../cypress.config.js | 5 ++++ .../config-with-short-timeout/cypress.json | 5 ---- .../projects/cookies/cypress.config.js | 1 + system-tests/projects/cookies/cypress.json | 1 - .../projects/default-layout/cypress.config.js | 1 + .../projects/default-layout/cypress.json | 1 - .../projects/downloads/cypress.config.js | 5 ++++ system-tests/projects/downloads/cypress.json | 5 ---- system-tests/projects/e2e/cypress.config.js | 3 ++ system-tests/projects/e2e/cypress.json | 3 -- .../projects/empty-folders/cypress.config.js | 1 + .../projects/empty-folders/cypress.json | 1 - .../failures/cypress/cypress.config.js | 1 + .../projects/failures/cypress/cypress.json | 1 - .../projects/firefox-memory/cypress.config.js | 1 + .../projects/firefox-memory/cypress.json | 1 - .../cypress.config.js | 7 +++++ .../cypress.json | 7 ----- .../folder-same-as-fixture/cypress.config.js | 1 + .../folder-same-as-fixture/cypress.json | 1 - .../hooks-after-rerun/cypress.config.js | 1 + .../projects/hooks-after-rerun/cypress.json | 1 - system-tests/projects/ids/cypress.config.js | 1 + system-tests/projects/ids/cypress.json | 1 - .../project-root/cypress.config.js | 3 ++ .../project-root/cypress.json | 3 -- .../issue-8111-iframe-input/cypress.config.js | 3 ++ .../issue-8111-iframe-input/cypress.json | 3 -- .../projects/max-listeners/cypress.config.js | 1 + .../projects/max-listeners/cypress.json | 1 - .../cypress.config.js | 1 + .../multiple-task-registrations/cypress.json | 1 - .../projects/no-scaffolding/cypress.config.js | 1 + .../projects/no-scaffolding/cypress.json | 1 - .../projects/no-server/cypress.config.js | 6 ++++ system-tests/projects/no-server/cypress.json | 6 ---- .../non-existent-spec/cypress.config.js | 3 ++ .../projects/non-existent-spec/cypress.json | 3 -- .../projects/non-proxied/cypress.config.js | 1 + .../projects/non-proxied/cypress.json | 1 - .../plugin-after-screenshot/cypress.config.js | 1 + .../plugin-after-screenshot/cypress.json | 1 - .../cypress.config.js | 4 +++ .../cypress.json | 4 --- .../cypress.config.js | 1 + .../cypress.json | 1 - .../projects/plugin-browser/cypress.config.js | 1 + .../projects/plugin-browser/cypress.json | 1 - .../plugin-config-version/cypress.config.js | 1 + .../plugin-config-version/cypress.json | 1 - .../projects/plugin-config/cypress.config.js | 1 + .../projects/plugin-config/cypress.json | 1 - .../projects/plugin-empty/cypress.config.js | 1 + .../projects/plugin-empty/cypress.json | 1 - .../plugin-event-deprecated/cypress.config.js | 1 + .../plugin-event-deprecated/cypress.json | 1 - .../plugin-extension/cypress.config.js | 1 + .../projects/plugin-extension/cypress.json | 1 - .../plugin-filter-browsers/cypress.config.js | 1 + .../plugin-filter-browsers/cypress.json | 1 - .../projects/plugin-retries/cypress.config.js | 1 + .../projects/plugin-retries/cypress.json | 1 - .../cypress.config.js | 1 + .../plugin-returns-bad-config/cypress.json | 1 - .../cypress.config.js | 1 + .../cypress.json | 1 - .../cypress.config.js | 1 + .../cypress.json | 1 - .../plugin-run-event-throws/cypress.config.js | 4 +++ .../plugin-run-event-throws/cypress.json | 4 --- .../plugin-run-events/cypress.config.js | 4 +++ .../projects/plugin-run-events/cypress.json | 4 --- .../plugin-validation-error/cypress.config.js | 1 + .../plugin-validation-error/cypress.json | 1 - .../plugins-absolute-path/cypress.config.js | 1 + .../plugins-absolute-path/cypress.json | 1 - .../plugins-async-error/cypress.config.js | 1 + .../projects/plugins-async-error/cypress.json | 1 - .../cypress.config.js | 1 + .../plugins-root-async-error/cypress.json | 1 - .../read-only-project-root/cypress.config.js | 3 ++ .../read-only-project-root/cypress.json | 3 -- .../projects/record/cypress.config.js | 3 ++ system-tests/projects/record/cypress.json | 3 -- .../cypress.config.js | 1 + .../remote-debugging-disconnect/cypress.json | 1 - .../cypress.config.js | 1 + .../cypress.json | 1 - .../projects/retries-2/cypress.config.js | 3 ++ system-tests/projects/retries-2/cypress.json | 3 -- .../cypress.config.js | 6 ++++ .../cypress.json | 6 ---- .../projects/screen-size/cypress.config.js | 1 + .../projects/screen-size/cypress.json | 1 - .../cypress.config.js | 5 ++++ .../shadow-dom-global-inclusion/cypress.json | 5 ---- .../spec-generation/cypress.config.js | 3 ++ .../projects/spec-generation/cypress.json | 3 -- .../studio-no-source-maps/cypress.config.js | 3 ++ .../studio-no-source-maps/cypress.json | 3 -- .../projects/studio/cypress.config.js | 3 ++ system-tests/projects/studio/cypress.json | 3 -- .../projects/system-node/cypress.config.js | 3 ++ .../projects/system-node/cypress.json | 3 -- .../task-not-registered/cypress.config.js | 3 ++ .../projects/task-not-registered/cypress.json | 3 -- system-tests/projects/todos/cypress.config.js | 8 +++++ system-tests/projects/todos/cypress.json | 8 ----- .../projects/ts-installed/cypress.config.js | 1 + .../projects/ts-installed/cypress.json | 1 - .../ts-proj-custom-names/cypress.config.js | 4 +++ .../ts-proj-custom-names/cypress.json | 4 --- .../cypress.config.js | 3 ++ .../ts-proj-esmoduleinterop-true/cypress.json | 3 -- .../cypress.config.js | 3 ++ .../ts-proj-tsconfig-in-plugins/cypress.json | 3 -- .../cypress.config.js | 3 ++ .../ts-proj-with-module-esnext/cypress.json | 3 -- .../ts-proj-with-paths/cypress.config.js | 1 + .../projects/ts-proj-with-paths/cypress.json | 1 - .../projects/ts-proj/cypress.config.js | 1 + system-tests/projects/ts-proj/cypress.json | 1 - .../uncaught-support-file/cypress.config.js | 1 + .../uncaught-support-file/cypress.json | 1 - .../unify-plugin-errors/cypress.config.js | 1 + .../projects/unify-plugin-errors/cypress.json | 1 - .../cypress.config.js | 3 ++ .../cypress.json | 3 -- .../cypress.config.js | 3 ++ .../cypress.json | 3 -- .../cypress.config.js | 3 ++ .../cypress.json | 3 -- .../webpack-preprocessor/cypress.config.js | 3 ++ .../webpack-preprocessor/cypress.json | 3 -- .../working-preprocessor/cypress.config.js | 1 + .../working-preprocessor/cypress.json | 1 - .../projects/yarn-v2-pnp/cypress.config.js | 1 + .../projects/yarn-v2-pnp/cypress.json | 1 - 226 files changed, 555 insertions(+), 564 deletions(-) create mode 100644 npm/angular/cypress.config.ts delete mode 100644 npm/angular/cypress.json delete mode 100644 npm/cypress-schematic/src/schematics/ng-add/files/cypress.json create mode 100644 npm/design-system/cypress.config.js delete mode 100644 npm/design-system/cypress.json create mode 100644 npm/react/cypress.config.js delete mode 100644 npm/react/cypress.json create mode 100644 npm/react/examples/a11y/cypress.config.js delete mode 100644 npm/react/examples/a11y/cypress.json create mode 100644 npm/react/examples/craco/cypress.config.js delete mode 100644 npm/react/examples/craco/cypress.json create mode 100644 npm/react/examples/find-webpack/cypress.config.ts delete mode 100644 npm/react/examples/find-webpack/cypress.json create mode 100644 npm/react/examples/nextjs-webpack-5/cypress.config.js delete mode 100644 npm/react/examples/nextjs-webpack-5/cypress.json create mode 100644 npm/react/examples/nextjs/cypress.config.js delete mode 100644 npm/react/examples/nextjs/cypress.json create mode 100644 npm/react/examples/react-scripts-folder/cypress.config.js delete mode 100644 npm/react/examples/react-scripts-folder/cypress.json create mode 100644 npm/react/examples/react-scripts-typescript/cypress.config.js delete mode 100644 npm/react/examples/react-scripts-typescript/cypress.json create mode 100644 npm/react/examples/react-scripts/cypress.config.js delete mode 100644 npm/react/examples/react-scripts/cypress.json create mode 100644 npm/react/examples/sass-and-ts/cypress.config.js delete mode 100644 npm/react/examples/sass-and-ts/cypress.json create mode 100644 npm/react/examples/snapshots/cypress.config.js delete mode 100644 npm/react/examples/snapshots/cypress.json create mode 100644 npm/react/examples/tailwind/cypress.config.js delete mode 100644 npm/react/examples/tailwind/cypress.json create mode 100644 npm/react/examples/using-babel-typescript/cypress.config.js delete mode 100644 npm/react/examples/using-babel-typescript/cypress.json create mode 100644 npm/react/examples/using-babel/cypress.config.js delete mode 100644 npm/react/examples/using-babel/cypress.json rename npm/react/examples/visual-sudoku/{cypress.json => cypress.config.js} (89%) create mode 100644 npm/react/examples/visual-testing-with-applitools/cypress.config.js delete mode 100644 npm/react/examples/visual-testing-with-applitools/cypress.json create mode 100644 npm/react/examples/visual-testing-with-happo/cypress.config.js delete mode 100644 npm/react/examples/visual-testing-with-happo/cypress.json create mode 100644 npm/react/examples/visual-testing-with-percy/cypress.config.js delete mode 100644 npm/react/examples/visual-testing-with-percy/cypress.json create mode 100644 npm/react/examples/webpack-file/cypress.config.js delete mode 100644 npm/react/examples/webpack-file/cypress.json create mode 100644 npm/react/examples/webpack-options/cypress.config.js delete mode 100644 npm/react/examples/webpack-options/cypress.json create mode 100644 npm/vite-dev-server/cypress.config.ts delete mode 100644 npm/vite-dev-server/cypress.json create mode 100644 npm/vue/examples/code-coverage/cypress.config.js delete mode 100644 npm/vue/examples/code-coverage/cypress.json create mode 100644 npm/vue/examples/vue-cli/cypress.config.js delete mode 100644 npm/vue/examples/vue-cli/cypress.json create mode 100644 npm/webpack-preprocessor/cypress.config.js delete mode 100644 npm/webpack-preprocessor/cypress.json create mode 100644 npm/webpack-preprocessor/examples/react-app/cypress.config.js delete mode 100644 npm/webpack-preprocessor/examples/react-app/cypress.json create mode 100644 npm/webpack-preprocessor/examples/use-babelrc/cypress.config.js delete mode 100644 npm/webpack-preprocessor/examples/use-babelrc/cypress.json create mode 100644 npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts delete mode 100644 npm/webpack-preprocessor/examples/use-ts-loader/cypress.json create mode 100644 packages/app/cypress.config.ts delete mode 100644 packages/app/cypress.json create mode 100644 packages/desktop-gui/cypress.config.js delete mode 100644 packages/desktop-gui/cypress.json create mode 100644 packages/driver/cypress.config.ts delete mode 100644 packages/driver/cypress.json rename packages/example/{cypress.json => cypress.config.js} (59%) create mode 100644 packages/frontend-shared/cypress.config.ts delete mode 100644 packages/frontend-shared/cypress.json rename packages/launchpad/cypress/fixtures/test-project/{cypress.json => cypress.config.ts} (56%) create mode 100644 packages/reporter/cypress.config.ts delete mode 100644 packages/reporter/cypress.json create mode 100644 packages/runner-ct/cypress.config.ts delete mode 100644 packages/runner-ct/cypress.json create mode 100644 packages/runner/cypress.config.js delete mode 100644 packages/runner/cypress.json create mode 100644 packages/ui-components/cypress.config.js delete mode 100644 packages/ui-components/cypress.json create mode 100644 system-tests/projects/browser-extensions/cypress.config.js delete mode 100644 system-tests/projects/browser-extensions/cypress.json create mode 100644 system-tests/projects/busted-support-file/cypress.config.js delete mode 100644 system-tests/projects/busted-support-file/cypress.json create mode 100644 system-tests/projects/chrome-browser-preferences/cypress.config.js delete mode 100644 system-tests/projects/chrome-browser-preferences/cypress.json create mode 100644 system-tests/projects/component-tests/cypress.config.js delete mode 100644 system-tests/projects/component-tests/cypress.json create mode 100644 system-tests/projects/config-with-invalid-browser/cypress.config.js delete mode 100644 system-tests/projects/config-with-invalid-browser/cypress.json create mode 100644 system-tests/projects/config-with-invalid-viewport/cypress.config.js delete mode 100644 system-tests/projects/config-with-invalid-viewport/cypress.json create mode 100644 system-tests/projects/config-with-short-timeout/cypress.config.js delete mode 100644 system-tests/projects/config-with-short-timeout/cypress.json create mode 100644 system-tests/projects/cookies/cypress.config.js delete mode 100644 system-tests/projects/cookies/cypress.json create mode 100644 system-tests/projects/default-layout/cypress.config.js delete mode 100644 system-tests/projects/default-layout/cypress.json create mode 100644 system-tests/projects/downloads/cypress.config.js delete mode 100644 system-tests/projects/downloads/cypress.json create mode 100644 system-tests/projects/e2e/cypress.config.js delete mode 100644 system-tests/projects/e2e/cypress.json create mode 100644 system-tests/projects/empty-folders/cypress.config.js delete mode 100644 system-tests/projects/empty-folders/cypress.json create mode 100644 system-tests/projects/failures/cypress/cypress.config.js delete mode 100644 system-tests/projects/failures/cypress/cypress.json create mode 100644 system-tests/projects/firefox-memory/cypress.config.js delete mode 100644 system-tests/projects/firefox-memory/cypress.json create mode 100644 system-tests/projects/fixture-subfolder-of-integration/cypress.config.js delete mode 100644 system-tests/projects/fixture-subfolder-of-integration/cypress.json create mode 100644 system-tests/projects/folder-same-as-fixture/cypress.config.js delete mode 100644 system-tests/projects/folder-same-as-fixture/cypress.json create mode 100644 system-tests/projects/hooks-after-rerun/cypress.config.js delete mode 100644 system-tests/projects/hooks-after-rerun/cypress.json create mode 100644 system-tests/projects/ids/cypress.config.js delete mode 100644 system-tests/projects/ids/cypress.json create mode 100644 system-tests/projects/integration-outside-project-root/project-root/cypress.config.js delete mode 100644 system-tests/projects/integration-outside-project-root/project-root/cypress.json create mode 100644 system-tests/projects/issue-8111-iframe-input/cypress.config.js delete mode 100644 system-tests/projects/issue-8111-iframe-input/cypress.json create mode 100644 system-tests/projects/max-listeners/cypress.config.js delete mode 100644 system-tests/projects/max-listeners/cypress.json create mode 100644 system-tests/projects/multiple-task-registrations/cypress.config.js delete mode 100644 system-tests/projects/multiple-task-registrations/cypress.json create mode 100644 system-tests/projects/no-scaffolding/cypress.config.js delete mode 100644 system-tests/projects/no-scaffolding/cypress.json create mode 100644 system-tests/projects/no-server/cypress.config.js delete mode 100644 system-tests/projects/no-server/cypress.json create mode 100644 system-tests/projects/non-existent-spec/cypress.config.js delete mode 100644 system-tests/projects/non-existent-spec/cypress.json create mode 100644 system-tests/projects/non-proxied/cypress.config.js delete mode 100644 system-tests/projects/non-proxied/cypress.json create mode 100644 system-tests/projects/plugin-after-screenshot/cypress.config.js delete mode 100644 system-tests/projects/plugin-after-screenshot/cypress.json create mode 100644 system-tests/projects/plugin-after-spec-deletes-video/cypress.config.js delete mode 100644 system-tests/projects/plugin-after-spec-deletes-video/cypress.json create mode 100644 system-tests/projects/plugin-before-browser-launch-deprecation/cypress.config.js delete mode 100644 system-tests/projects/plugin-before-browser-launch-deprecation/cypress.json create mode 100644 system-tests/projects/plugin-browser/cypress.config.js delete mode 100644 system-tests/projects/plugin-browser/cypress.json create mode 100644 system-tests/projects/plugin-config-version/cypress.config.js delete mode 100644 system-tests/projects/plugin-config-version/cypress.json create mode 100644 system-tests/projects/plugin-config/cypress.config.js delete mode 100644 system-tests/projects/plugin-config/cypress.json create mode 100644 system-tests/projects/plugin-empty/cypress.config.js delete mode 100644 system-tests/projects/plugin-empty/cypress.json create mode 100644 system-tests/projects/plugin-event-deprecated/cypress.config.js delete mode 100644 system-tests/projects/plugin-event-deprecated/cypress.json create mode 100644 system-tests/projects/plugin-extension/cypress.config.js delete mode 100644 system-tests/projects/plugin-extension/cypress.json create mode 100644 system-tests/projects/plugin-filter-browsers/cypress.config.js delete mode 100644 system-tests/projects/plugin-filter-browsers/cypress.json create mode 100644 system-tests/projects/plugin-retries/cypress.config.js delete mode 100644 system-tests/projects/plugin-retries/cypress.json create mode 100644 system-tests/projects/plugin-returns-bad-config/cypress.config.js delete mode 100644 system-tests/projects/plugin-returns-bad-config/cypress.json create mode 100644 system-tests/projects/plugin-returns-empty-browsers-list/cypress.config.js delete mode 100644 system-tests/projects/plugin-returns-empty-browsers-list/cypress.json create mode 100644 system-tests/projects/plugin-returns-invalid-browser/cypress.config.js delete mode 100644 system-tests/projects/plugin-returns-invalid-browser/cypress.json create mode 100644 system-tests/projects/plugin-run-event-throws/cypress.config.js delete mode 100644 system-tests/projects/plugin-run-event-throws/cypress.json create mode 100644 system-tests/projects/plugin-run-events/cypress.config.js delete mode 100644 system-tests/projects/plugin-run-events/cypress.json create mode 100644 system-tests/projects/plugin-validation-error/cypress.config.js delete mode 100644 system-tests/projects/plugin-validation-error/cypress.json create mode 100644 system-tests/projects/plugins-absolute-path/cypress.config.js delete mode 100644 system-tests/projects/plugins-absolute-path/cypress.json create mode 100644 system-tests/projects/plugins-async-error/cypress.config.js delete mode 100644 system-tests/projects/plugins-async-error/cypress.json create mode 100644 system-tests/projects/plugins-root-async-error/cypress.config.js delete mode 100644 system-tests/projects/plugins-root-async-error/cypress.json create mode 100644 system-tests/projects/read-only-project-root/cypress.config.js delete mode 100644 system-tests/projects/read-only-project-root/cypress.json create mode 100644 system-tests/projects/record/cypress.config.js delete mode 100644 system-tests/projects/record/cypress.json create mode 100644 system-tests/projects/remote-debugging-disconnect/cypress.config.js delete mode 100644 system-tests/projects/remote-debugging-disconnect/cypress.json create mode 100644 system-tests/projects/remote-debugging-port-removed/cypress.config.js delete mode 100644 system-tests/projects/remote-debugging-port-removed/cypress.json create mode 100644 system-tests/projects/retries-2/cypress.config.js delete mode 100644 system-tests/projects/retries-2/cypress.json create mode 100644 system-tests/projects/same-fixtures-integration-folders/cypress.config.js delete mode 100644 system-tests/projects/same-fixtures-integration-folders/cypress.json create mode 100644 system-tests/projects/screen-size/cypress.config.js delete mode 100644 system-tests/projects/screen-size/cypress.json create mode 100644 system-tests/projects/shadow-dom-global-inclusion/cypress.config.js delete mode 100644 system-tests/projects/shadow-dom-global-inclusion/cypress.json create mode 100644 system-tests/projects/spec-generation/cypress.config.js delete mode 100644 system-tests/projects/spec-generation/cypress.json create mode 100644 system-tests/projects/studio-no-source-maps/cypress.config.js delete mode 100644 system-tests/projects/studio-no-source-maps/cypress.json create mode 100644 system-tests/projects/studio/cypress.config.js delete mode 100644 system-tests/projects/studio/cypress.json create mode 100644 system-tests/projects/system-node/cypress.config.js delete mode 100644 system-tests/projects/system-node/cypress.json create mode 100644 system-tests/projects/task-not-registered/cypress.config.js delete mode 100644 system-tests/projects/task-not-registered/cypress.json create mode 100644 system-tests/projects/todos/cypress.config.js delete mode 100644 system-tests/projects/todos/cypress.json create mode 100644 system-tests/projects/ts-installed/cypress.config.js delete mode 100644 system-tests/projects/ts-installed/cypress.json create mode 100644 system-tests/projects/ts-proj-custom-names/cypress.config.js delete mode 100644 system-tests/projects/ts-proj-custom-names/cypress.json create mode 100644 system-tests/projects/ts-proj-esmoduleinterop-true/cypress.config.js delete mode 100644 system-tests/projects/ts-proj-esmoduleinterop-true/cypress.json create mode 100644 system-tests/projects/ts-proj-tsconfig-in-plugins/cypress.config.js delete mode 100644 system-tests/projects/ts-proj-tsconfig-in-plugins/cypress.json create mode 100644 system-tests/projects/ts-proj-with-module-esnext/cypress.config.js delete mode 100644 system-tests/projects/ts-proj-with-module-esnext/cypress.json create mode 100644 system-tests/projects/ts-proj-with-paths/cypress.config.js delete mode 100644 system-tests/projects/ts-proj-with-paths/cypress.json create mode 100644 system-tests/projects/ts-proj/cypress.config.js delete mode 100644 system-tests/projects/ts-proj/cypress.json create mode 100644 system-tests/projects/uncaught-support-file/cypress.config.js delete mode 100644 system-tests/projects/uncaught-support-file/cypress.json create mode 100644 system-tests/projects/unify-plugin-errors/cypress.config.js delete mode 100644 system-tests/projects/unify-plugin-errors/cypress.json create mode 100644 system-tests/projects/webpack-preprocessor-awesome-typescript-loader/cypress.config.js delete mode 100644 system-tests/projects/webpack-preprocessor-awesome-typescript-loader/cypress.json create mode 100644 system-tests/projects/webpack-preprocessor-ts-loader-compiler-options/cypress.config.js delete mode 100644 system-tests/projects/webpack-preprocessor-ts-loader-compiler-options/cypress.json create mode 100644 system-tests/projects/webpack-preprocessor-ts-loader/cypress.config.js delete mode 100644 system-tests/projects/webpack-preprocessor-ts-loader/cypress.json create mode 100644 system-tests/projects/webpack-preprocessor/cypress.config.js delete mode 100644 system-tests/projects/webpack-preprocessor/cypress.json create mode 100644 system-tests/projects/working-preprocessor/cypress.config.js delete mode 100644 system-tests/projects/working-preprocessor/cypress.json create mode 100644 system-tests/projects/yarn-v2-pnp/cypress.config.js delete mode 100644 system-tests/projects/yarn-v2-pnp/cypress.json diff --git a/npm/angular/cypress.config.ts b/npm/angular/cypress.config.ts new file mode 100644 index 000000000000..47c2b29c3550 --- /dev/null +++ b/npm/angular/cypress.config.ts @@ -0,0 +1,11 @@ +module.exports = { + 'experimentalFetchPolyfill': true, + 'fixturesFolder': false, + 'includeShadowDom': true, + 'fileServerFolder': 'src', + 'projectId': 'nf7zag', + 'component': { + 'componentFolder': 'src/app', + 'testFiles': '**/*cy-spec.ts', + }, +} diff --git a/npm/angular/cypress.json b/npm/angular/cypress.json deleted file mode 100644 index ebe21a31c348..000000000000 --- a/npm/angular/cypress.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "experimentalFetchPolyfill": true, - "fixturesFolder": false, - "includeShadowDom": true, - "fileServerFolder": "src", - "projectId": "nf7zag", - "component": { - "componentFolder": "src/app", - "testFiles": "**/*cy-spec.ts" - } -} diff --git a/npm/cypress-schematic/src/schematics/ng-add/files/cypress.json b/npm/cypress-schematic/src/schematics/ng-add/files/cypress.json deleted file mode 100644 index 4426d4e7d71a..000000000000 --- a/npm/cypress-schematic/src/schematics/ng-add/files/cypress.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "integrationFolder": "<%= root%>cypress/integration", - "supportFile": "<%= root%>cypress/support/index.ts", - "videosFolder": "<%= root%>cypress/videos", - "screenshotsFolder": "<%= root%>cypress/screenshots", - "pluginsFile": "<%= root%>cypress/plugins/index.ts", - "fixturesFolder": "<%= root%>cypress/fixtures", - "baseUrl": "<%= baseUrl%>" -} \ No newline at end of file diff --git a/npm/design-system/cypress.config.js b/npm/design-system/cypress.config.js new file mode 100644 index 000000000000..dcbf918782a3 --- /dev/null +++ b/npm/design-system/cypress.config.js @@ -0,0 +1,16 @@ +module.exports = { + viewportWidth: 1024, + viewportHeight: 800, + video: false, + projectId: 'z9dxah', + testFiles: '**/*spec.{js,jsx,ts,tsx}', + env: { + reactDevtools: true, + }, + ignoreTestFiles: [ + '**/__snapshots__/*', + '**/__image_snapshots__/*', + ], + componentFolder: 'src', + fixturesFolder: false, +} diff --git a/npm/design-system/cypress.json b/npm/design-system/cypress.json deleted file mode 100644 index 00494ad9b75c..000000000000 --- a/npm/design-system/cypress.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "viewportWidth": 1024, - "viewportHeight": 800, - "video": false, - "projectId": "z9dxah", - "testFiles": "**/*spec.{js,jsx,ts,tsx}", - "env": { - "reactDevtools": true - }, - "ignoreTestFiles": [ - "**/__snapshots__/*", - "**/__image_snapshots__/*" - ], - "componentFolder": "src", - "fixturesFolder": false -} diff --git a/npm/react/cypress.config.js b/npm/react/cypress.config.js new file mode 100644 index 000000000000..82d715eee618 --- /dev/null +++ b/npm/react/cypress.config.js @@ -0,0 +1,15 @@ +module.exports = { + 'viewportWidth': 400, + 'viewportHeight': 400, + 'video': false, + 'projectId': 'z9dxah', + 'testFiles': '**/*spec.{js,jsx,ts,tsx}', + 'env': { + 'reactDevtools': true, + }, + 'ignoreTestFiles': [ + '**/__snapshots__/*', + '**/__image_snapshots__/*', + ], + 'experimentalFetchPolyfill': true, +} diff --git a/npm/react/cypress.json b/npm/react/cypress.json deleted file mode 100644 index a6b5db93e737..000000000000 --- a/npm/react/cypress.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "viewportWidth": 400, - "viewportHeight": 400, - "video": false, - "projectId": "z9dxah", - "testFiles": "**/*spec.{js,jsx,ts,tsx}", - "env": { - "reactDevtools": true - }, - "ignoreTestFiles": [ - "**/__snapshots__/*", - "**/__image_snapshots__/*" - ], - "experimentalFetchPolyfill": true -} \ No newline at end of file diff --git a/npm/react/examples/a11y/cypress.config.js b/npm/react/examples/a11y/cypress.config.js new file mode 100644 index 000000000000..51a4ad540b1a --- /dev/null +++ b/npm/react/examples/a11y/cypress.config.js @@ -0,0 +1,7 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*spec.js', + 'viewportWidth': 500, + 'viewportHeight': 500, +} diff --git a/npm/react/examples/a11y/cypress.json b/npm/react/examples/a11y/cypress.json deleted file mode 100644 index 49b616efaf97..000000000000 --- a/npm/react/examples/a11y/cypress.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*spec.js", - "viewportWidth": 500, - "viewportHeight": 500 -} \ No newline at end of file diff --git a/npm/react/examples/craco/cypress.config.js b/npm/react/examples/craco/cypress.config.js new file mode 100644 index 000000000000..438a9f7531ad --- /dev/null +++ b/npm/react/examples/craco/cypress.config.js @@ -0,0 +1,6 @@ +module.exports = { + 'component': { + 'testFiles': '**/*.test.{js,ts,jsx,tsx}', + 'componentFolder': 'src', + }, +} diff --git a/npm/react/examples/craco/cypress.json b/npm/react/examples/craco/cypress.json deleted file mode 100644 index 0b8d0666485b..000000000000 --- a/npm/react/examples/craco/cypress.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "component": { - "testFiles": "**/*.test.{js,ts,jsx,tsx}", - "componentFolder": "src" - } -} diff --git a/npm/react/examples/find-webpack/cypress.config.ts b/npm/react/examples/find-webpack/cypress.config.ts new file mode 100644 index 000000000000..a858801d4a78 --- /dev/null +++ b/npm/react/examples/find-webpack/cypress.config.ts @@ -0,0 +1,13 @@ +module.exports = { + 'video': true, + 'projectId': 'jq5xpp', + 'component': { + 'testFiles': '**/*.spec.{js,ts,jsx,tsx}', + 'componentFolder': 'src', + }, + 'env': { + 'cypress-react-selector': { + 'root': '#__cy_root', + }, + }, +} diff --git a/npm/react/examples/find-webpack/cypress.json b/npm/react/examples/find-webpack/cypress.json deleted file mode 100644 index 03ad0d3676ef..000000000000 --- a/npm/react/examples/find-webpack/cypress.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "video": true, - "projectId": "jq5xpp", - "component": { - "testFiles": "**/*.spec.{js,ts,jsx,tsx}", - "componentFolder": "src" - }, - "env": { - "cypress-react-selector": { - "root": "#__cy_root" - } - } -} diff --git a/npm/react/examples/nextjs-webpack-5/cypress.config.js b/npm/react/examples/nextjs-webpack-5/cypress.config.js new file mode 100644 index 000000000000..55ae64aba890 --- /dev/null +++ b/npm/react/examples/nextjs-webpack-5/cypress.config.js @@ -0,0 +1,8 @@ +module.exports = { + 'video': false, + 'testFiles': '**/*.spec.{js,jsx}', + 'viewportWidth': 500, + 'viewportHeight': 800, + 'componentFolder': 'cypress/components', + 'pluginsFile': 'cypress/plugins.js', +} diff --git a/npm/react/examples/nextjs-webpack-5/cypress.json b/npm/react/examples/nextjs-webpack-5/cypress.json deleted file mode 100644 index 18c2d6098b91..000000000000 --- a/npm/react/examples/nextjs-webpack-5/cypress.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "video": false, - "testFiles": "**/*.spec.{js,jsx}", - "viewportWidth": 500, - "viewportHeight": 800, - "componentFolder": "cypress/components", - "pluginsFile": "cypress/plugins.js" -} \ No newline at end of file diff --git a/npm/react/examples/nextjs/cypress.config.js b/npm/react/examples/nextjs/cypress.config.js new file mode 100644 index 000000000000..f657fd615a47 --- /dev/null +++ b/npm/react/examples/nextjs/cypress.config.js @@ -0,0 +1,11 @@ +module.exports = { + 'video': false, + 'testFiles': '**/*.spec.{js,jsx}', + 'viewportWidth': 500, + 'viewportHeight': 800, + 'experimentalFetchPolyfill': true, + 'componentFolder': 'cypress/components', + 'env': { + 'coverage': true, + }, +} diff --git a/npm/react/examples/nextjs/cypress.json b/npm/react/examples/nextjs/cypress.json deleted file mode 100644 index a281a06f60e6..000000000000 --- a/npm/react/examples/nextjs/cypress.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "video": false, - "testFiles": "**/*.spec.{js,jsx}", - "viewportWidth": 500, - "viewportHeight": 800, - "experimentalFetchPolyfill": true, - "componentFolder": "cypress/components", - "env": { - "coverage": true - } -} \ No newline at end of file diff --git a/npm/react/examples/react-scripts-folder/cypress.config.js b/npm/react/examples/react-scripts-folder/cypress.config.js new file mode 100644 index 000000000000..edb62d592bf7 --- /dev/null +++ b/npm/react/examples/react-scripts-folder/cypress.config.js @@ -0,0 +1,8 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*cy-spec.js', + 'viewportWidth': 500, + 'viewportHeight': 800, + 'componentFolder': 'cypress/component', +} diff --git a/npm/react/examples/react-scripts-folder/cypress.json b/npm/react/examples/react-scripts-folder/cypress.json deleted file mode 100644 index a595a1acd3c8..000000000000 --- a/npm/react/examples/react-scripts-folder/cypress.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*cy-spec.js", - "viewportWidth": 500, - "viewportHeight": 800, - "componentFolder": "cypress/component" -} \ No newline at end of file diff --git a/npm/react/examples/react-scripts-typescript/cypress.config.js b/npm/react/examples/react-scripts-typescript/cypress.config.js new file mode 100644 index 000000000000..8cb0f4f57f58 --- /dev/null +++ b/npm/react/examples/react-scripts-typescript/cypress.config.js @@ -0,0 +1,7 @@ +module.exports = { + 'video': false, + 'testFiles': '**/*cy-spec.tsx', + 'viewportWidth': 500, + 'viewportHeight': 800, + 'componentFolder': 'src', +} diff --git a/npm/react/examples/react-scripts-typescript/cypress.json b/npm/react/examples/react-scripts-typescript/cypress.json deleted file mode 100644 index 67ebf9f708b3..000000000000 --- a/npm/react/examples/react-scripts-typescript/cypress.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "video": false, - "testFiles": "**/*cy-spec.tsx", - "viewportWidth": 500, - "viewportHeight": 800, - "componentFolder": "src" -} diff --git a/npm/react/examples/react-scripts/cypress.config.js b/npm/react/examples/react-scripts/cypress.config.js new file mode 100644 index 000000000000..1c05b4fca685 --- /dev/null +++ b/npm/react/examples/react-scripts/cypress.config.js @@ -0,0 +1,8 @@ +module.exports = { + 'video': false, + 'testFiles': '**/*cy-spec.js', + 'viewportWidth': 500, + 'viewportHeight': 800, + 'experimentalFetchPolyfill': true, + 'componentFolder': 'src', +} diff --git a/npm/react/examples/react-scripts/cypress.json b/npm/react/examples/react-scripts/cypress.json deleted file mode 100644 index 6c8427ea332a..000000000000 --- a/npm/react/examples/react-scripts/cypress.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "video": false, - "testFiles": "**/*cy-spec.js", - "viewportWidth": 500, - "viewportHeight": 800, - "experimentalFetchPolyfill": true, - "componentFolder": "src" -} \ No newline at end of file diff --git a/npm/react/examples/sass-and-ts/cypress.config.js b/npm/react/examples/sass-and-ts/cypress.config.js new file mode 100644 index 000000000000..60e7ff2475a5 --- /dev/null +++ b/npm/react/examples/sass-and-ts/cypress.config.js @@ -0,0 +1,12 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*spec.*', + 'viewportWidth': 500, + 'viewportHeight': 500, + 'componentFolder': 'src', + 'nodeVersion': 'system', + 'env': { + 'coverage': true, + }, +} diff --git a/npm/react/examples/sass-and-ts/cypress.json b/npm/react/examples/sass-and-ts/cypress.json deleted file mode 100644 index 1341d16e3bbe..000000000000 --- a/npm/react/examples/sass-and-ts/cypress.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*spec.*", - "viewportWidth": 500, - "viewportHeight": 500, - "componentFolder": "src", - "nodeVersion": "system", - "env": { - "coverage": true - } -} \ No newline at end of file diff --git a/npm/react/examples/snapshots/cypress.config.js b/npm/react/examples/snapshots/cypress.config.js new file mode 100644 index 000000000000..ef71668a5ee1 --- /dev/null +++ b/npm/react/examples/snapshots/cypress.config.js @@ -0,0 +1,16 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*-spec.js', + 'viewportWidth': 500, + 'viewportHeight': 500, + 'ignoreTestFiles': [ + '**/__snapshots__/*', + '**/__image_snapshots__/*', + ], + 'env': { + 'cypress-plugin-snapshots': { + 'prettier': true, + }, + }, +} diff --git a/npm/react/examples/snapshots/cypress.json b/npm/react/examples/snapshots/cypress.json deleted file mode 100644 index 4abcd4d5d358..000000000000 --- a/npm/react/examples/snapshots/cypress.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*-spec.js", - "viewportWidth": 500, - "viewportHeight": 500, - "ignoreTestFiles": [ - "**/__snapshots__/*", - "**/__image_snapshots__/*" - ], - "env": { - "cypress-plugin-snapshots": { - "prettier": true - } - } -} \ No newline at end of file diff --git a/npm/react/examples/tailwind/cypress.config.js b/npm/react/examples/tailwind/cypress.config.js new file mode 100644 index 000000000000..07c510021f0e --- /dev/null +++ b/npm/react/examples/tailwind/cypress.config.js @@ -0,0 +1,11 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*cy-spec.js', + 'viewportWidth': 500, + 'viewportHeight': 500, + 'componentFolder': 'src', + 'env': { + 'coverage': true, + }, +} diff --git a/npm/react/examples/tailwind/cypress.json b/npm/react/examples/tailwind/cypress.json deleted file mode 100644 index b3055fbcbb9e..000000000000 --- a/npm/react/examples/tailwind/cypress.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*cy-spec.js", - "viewportWidth": 500, - "viewportHeight": 500, - "componentFolder": "src", - "env": { - "coverage": true - } -} \ No newline at end of file diff --git a/npm/react/examples/using-babel-typescript/cypress.config.js b/npm/react/examples/using-babel-typescript/cypress.config.js new file mode 100644 index 000000000000..223bca975ea8 --- /dev/null +++ b/npm/react/examples/using-babel-typescript/cypress.config.js @@ -0,0 +1,8 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*spec.tsx', + 'viewportWidth': 500, + 'viewportHeight': 500, + 'componentFolder': 'src', +} diff --git a/npm/react/examples/using-babel-typescript/cypress.json b/npm/react/examples/using-babel-typescript/cypress.json deleted file mode 100644 index 86ef45a150ab..000000000000 --- a/npm/react/examples/using-babel-typescript/cypress.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*spec.tsx", - "viewportWidth": 500, - "viewportHeight": 500, - "componentFolder": "src" -} \ No newline at end of file diff --git a/npm/react/examples/using-babel/cypress.config.js b/npm/react/examples/using-babel/cypress.config.js new file mode 100644 index 000000000000..6a6e4fa40233 --- /dev/null +++ b/npm/react/examples/using-babel/cypress.config.js @@ -0,0 +1,8 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*spec.js', + 'viewportWidth': 500, + 'viewportHeight': 500, + 'componentFolder': 'src', +} diff --git a/npm/react/examples/using-babel/cypress.json b/npm/react/examples/using-babel/cypress.json deleted file mode 100644 index f97af0417f45..000000000000 --- a/npm/react/examples/using-babel/cypress.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*spec.js", - "viewportWidth": 500, - "viewportHeight": 500, - "componentFolder": "src" -} \ No newline at end of file diff --git a/npm/react/examples/visual-sudoku/cypress.json b/npm/react/examples/visual-sudoku/cypress.config.js similarity index 89% rename from npm/react/examples/visual-sudoku/cypress.json rename to npm/react/examples/visual-sudoku/cypress.config.js index 561f83d47bf8..d1a1bddfbf9c 100644 --- a/npm/react/examples/visual-sudoku/cypress.json +++ b/npm/react/examples/visual-sudoku/cypress.config.js @@ -1,4 +1,4 @@ -{ +module.exports = { "video": false, "fixturesFolder": false, "testFiles": "**/*cy-spec.js", diff --git a/npm/react/examples/visual-testing-with-applitools/cypress.config.js b/npm/react/examples/visual-testing-with-applitools/cypress.config.js new file mode 100644 index 000000000000..cedc749551e3 --- /dev/null +++ b/npm/react/examples/visual-testing-with-applitools/cypress.config.js @@ -0,0 +1,11 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*spec.js', + 'viewportWidth': 1000, + 'viewportHeight': 1000, + 'componentFolder': 'src', + 'env': { + 'coverage': false, + }, +} diff --git a/npm/react/examples/visual-testing-with-applitools/cypress.json b/npm/react/examples/visual-testing-with-applitools/cypress.json deleted file mode 100644 index a86687662f4f..000000000000 --- a/npm/react/examples/visual-testing-with-applitools/cypress.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*spec.js", - "viewportWidth": 1000, - "viewportHeight": 1000, - "componentFolder": "src", - "env": { - "coverage": false - } -} \ No newline at end of file diff --git a/npm/react/examples/visual-testing-with-happo/cypress.config.js b/npm/react/examples/visual-testing-with-happo/cypress.config.js new file mode 100644 index 000000000000..09a196f5ac0d --- /dev/null +++ b/npm/react/examples/visual-testing-with-happo/cypress.config.js @@ -0,0 +1,7 @@ +module.exports = { + 'video': false, + 'testFiles': '**/*cy-spec.js', + 'viewportWidth': 400, + 'viewportHeight': 700, + 'componentFolder': 'src', +} diff --git a/npm/react/examples/visual-testing-with-happo/cypress.json b/npm/react/examples/visual-testing-with-happo/cypress.json deleted file mode 100644 index 18d423f08d94..000000000000 --- a/npm/react/examples/visual-testing-with-happo/cypress.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "video": false, - "testFiles": "**/*cy-spec.js", - "viewportWidth": 400, - "viewportHeight": 700, - "componentFolder": "src" -} \ No newline at end of file diff --git a/npm/react/examples/visual-testing-with-percy/cypress.config.js b/npm/react/examples/visual-testing-with-percy/cypress.config.js new file mode 100644 index 000000000000..933303bfff30 --- /dev/null +++ b/npm/react/examples/visual-testing-with-percy/cypress.config.js @@ -0,0 +1,8 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*cy-spec.js', + 'viewportWidth': 500, + 'viewportHeight': 500, + 'componentFolder': 'src', +} diff --git a/npm/react/examples/visual-testing-with-percy/cypress.json b/npm/react/examples/visual-testing-with-percy/cypress.json deleted file mode 100644 index b268172ca3f4..000000000000 --- a/npm/react/examples/visual-testing-with-percy/cypress.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*cy-spec.js", - "viewportWidth": 500, - "viewportHeight": 500, - "componentFolder": "src" -} \ No newline at end of file diff --git a/npm/react/examples/webpack-file/cypress.config.js b/npm/react/examples/webpack-file/cypress.config.js new file mode 100644 index 000000000000..fea79636c340 --- /dev/null +++ b/npm/react/examples/webpack-file/cypress.config.js @@ -0,0 +1,7 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*cy-spec.js', + 'viewportWidth': 500, + 'viewportHeight': 500, +} diff --git a/npm/react/examples/webpack-file/cypress.json b/npm/react/examples/webpack-file/cypress.json deleted file mode 100644 index 707979192c3d..000000000000 --- a/npm/react/examples/webpack-file/cypress.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*cy-spec.js", - "viewportWidth": 500, - "viewportHeight": 500 -} \ No newline at end of file diff --git a/npm/react/examples/webpack-options/cypress.config.js b/npm/react/examples/webpack-options/cypress.config.js new file mode 100644 index 000000000000..fea79636c340 --- /dev/null +++ b/npm/react/examples/webpack-options/cypress.config.js @@ -0,0 +1,7 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*cy-spec.js', + 'viewportWidth': 500, + 'viewportHeight': 500, +} diff --git a/npm/react/examples/webpack-options/cypress.json b/npm/react/examples/webpack-options/cypress.json deleted file mode 100644 index 707979192c3d..000000000000 --- a/npm/react/examples/webpack-options/cypress.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*cy-spec.js", - "viewportWidth": 500, - "viewportHeight": 500 -} \ No newline at end of file diff --git a/npm/vite-dev-server/cypress.config.ts b/npm/vite-dev-server/cypress.config.ts new file mode 100644 index 000000000000..ae1800936c68 --- /dev/null +++ b/npm/vite-dev-server/cypress.config.ts @@ -0,0 +1,7 @@ +module.exports = { + 'pluginsFile': 'cypress/plugins.js', + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*.spec.*', + 'componentFolder': 'cypress/components', +} diff --git a/npm/vite-dev-server/cypress.json b/npm/vite-dev-server/cypress.json deleted file mode 100644 index d5c8178ca335..000000000000 --- a/npm/vite-dev-server/cypress.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "pluginsFile": "cypress/plugins.js", - "video": false, - "fixturesFolder": false, - "testFiles": "**/*.spec.*", - "componentFolder": "cypress/components" -} \ No newline at end of file diff --git a/npm/vue/examples/code-coverage/cypress.config.js b/npm/vue/examples/code-coverage/cypress.config.js new file mode 100644 index 000000000000..a0c1176e100e --- /dev/null +++ b/npm/vue/examples/code-coverage/cypress.config.js @@ -0,0 +1,6 @@ +module.exports = { + 'componentFolder': 'src', + 'fixturesFolder': false, + 'testFiles': '**/*.spec.js', + 'video': false, +} diff --git a/npm/vue/examples/code-coverage/cypress.json b/npm/vue/examples/code-coverage/cypress.json deleted file mode 100644 index 4110fa4e4784..000000000000 --- a/npm/vue/examples/code-coverage/cypress.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "componentFolder": "src", - "fixturesFolder": false, - "testFiles": "**/*.spec.js", - "video": false -} diff --git a/npm/vue/examples/vue-cli/cypress.config.js b/npm/vue/examples/vue-cli/cypress.config.js new file mode 100644 index 000000000000..a8fd106f6a07 --- /dev/null +++ b/npm/vue/examples/vue-cli/cypress.config.js @@ -0,0 +1,6 @@ +module.exports = { + 'video': false, + 'fixturesFolder': false, + 'testFiles': '**/*spec.js', + 'componentFolder': 'src', +} diff --git a/npm/vue/examples/vue-cli/cypress.json b/npm/vue/examples/vue-cli/cypress.json deleted file mode 100644 index 7d2950c00110..000000000000 --- a/npm/vue/examples/vue-cli/cypress.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "video": false, - "fixturesFolder": false, - "testFiles": "**/*spec.js", - "componentFolder": "src" -} \ No newline at end of file diff --git a/npm/webpack-preprocessor/cypress.config.js b/npm/webpack-preprocessor/cypress.config.js new file mode 100644 index 000000000000..3cc3dd401641 --- /dev/null +++ b/npm/webpack-preprocessor/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'integrationFolder': 'cypress/tests', +} diff --git a/npm/webpack-preprocessor/cypress.json b/npm/webpack-preprocessor/cypress.json deleted file mode 100644 index 63c52f7bf802..000000000000 --- a/npm/webpack-preprocessor/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "integrationFolder": "cypress/tests" -} diff --git a/npm/webpack-preprocessor/examples/react-app/cypress.config.js b/npm/webpack-preprocessor/examples/react-app/cypress.config.js new file mode 100644 index 000000000000..0cf1222180f5 --- /dev/null +++ b/npm/webpack-preprocessor/examples/react-app/cypress.config.js @@ -0,0 +1,6 @@ +module.exports = { + 'baseUrl': 'http://localhost:3000', + 'fixturesFolder': false, + 'supportFile': false, + 'viewportWidth': 600, +} diff --git a/npm/webpack-preprocessor/examples/react-app/cypress.json b/npm/webpack-preprocessor/examples/react-app/cypress.json deleted file mode 100644 index fc7e1f9c6243..000000000000 --- a/npm/webpack-preprocessor/examples/react-app/cypress.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "baseUrl": "http://localhost:3000", - "fixturesFolder": false, - "supportFile": false, - "viewportWidth": 600 -} diff --git a/npm/webpack-preprocessor/examples/use-babelrc/cypress.config.js b/npm/webpack-preprocessor/examples/use-babelrc/cypress.config.js new file mode 100644 index 000000000000..4f64c2459252 --- /dev/null +++ b/npm/webpack-preprocessor/examples/use-babelrc/cypress.config.js @@ -0,0 +1,4 @@ +module.exports = { + 'fixturesFolder': false, + 'supportFile': false, +} diff --git a/npm/webpack-preprocessor/examples/use-babelrc/cypress.json b/npm/webpack-preprocessor/examples/use-babelrc/cypress.json deleted file mode 100644 index a84f6e38c9e9..000000000000 --- a/npm/webpack-preprocessor/examples/use-babelrc/cypress.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "fixturesFolder": false, - "supportFile": false -} diff --git a/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts b/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts new file mode 100644 index 000000000000..4f64c2459252 --- /dev/null +++ b/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts @@ -0,0 +1,4 @@ +module.exports = { + 'fixturesFolder': false, + 'supportFile': false, +} diff --git a/npm/webpack-preprocessor/examples/use-ts-loader/cypress.json b/npm/webpack-preprocessor/examples/use-ts-loader/cypress.json deleted file mode 100644 index a84f6e38c9e9..000000000000 --- a/npm/webpack-preprocessor/examples/use-ts-loader/cypress.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "fixturesFolder": false, - "supportFile": false -} diff --git a/packages/app/cypress.config.ts b/packages/app/cypress.config.ts new file mode 100644 index 000000000000..50b8569ed981 --- /dev/null +++ b/packages/app/cypress.config.ts @@ -0,0 +1,29 @@ +module.exports = { + '$schema': '../../cli/schema/cypress.schema.json', + 'projectId': 'sehy69', + 'viewportWidth': 800, + 'viewportHeight': 850, + 'fixturesFolder': false, + 'retries': { + 'runMode': 2, + 'openMode': 0, + }, + 'nodeVersion': 'system', + 'testFiles': '**/*.spec.{j,ts,tsx,jsx}', + 'reporter': '../../node_modules/cypress-multi-reporters/index.js', + 'reporterOptions': { + 'configFile': '../../mocha-reporter-config.json', + }, + 'integrationFolder': 'cypress/e2e/integration', + 'componentFolder': 'src', + 'supportFile': false, + 'component': { + 'testFiles': '**/*.spec.{js,ts,tsx,jsx}', + 'supportFile': 'cypress/component/support/index.ts', + 'pluginsFile': 'cypress/component/plugins/index.js', + }, + 'e2e': { + 'pluginsFile': 'cypress/e2e/plugins/index.ts', + 'supportFile': 'cypress/e2e/support/e2eSupport.ts', + }, +} diff --git a/packages/app/cypress.json b/packages/app/cypress.json deleted file mode 100644 index 2c12d46efcaf..000000000000 --- a/packages/app/cypress.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "$schema": "../../cli/schema/cypress.schema.json", - "projectId": "sehy69", - "viewportWidth": 800, - "viewportHeight": 850, - "fixturesFolder": false, - "retries": { - "runMode": 2, - "openMode": 0 - }, - "nodeVersion": "system", - "testFiles": "**/*.spec.{j,ts,tsx,jsx}", - "reporter": "../../node_modules/cypress-multi-reporters/index.js", - "reporterOptions": { - "configFile": "../../mocha-reporter-config.json" - }, - "integrationFolder": "cypress/e2e/integration", - "componentFolder": "src", - "supportFile": false, - "component": { - "testFiles": "**/*.spec.{js,ts,tsx,jsx}", - "supportFile": "cypress/component/support/index.ts", - "pluginsFile": "cypress/component/plugins/index.js" - }, - "e2e": { - "pluginsFile": "cypress/e2e/plugins/index.ts", - "supportFile": "cypress/e2e/support/e2eSupport.ts" - } -} diff --git a/packages/desktop-gui/cypress.config.js b/packages/desktop-gui/cypress.config.js new file mode 100644 index 000000000000..58733de46e1b --- /dev/null +++ b/packages/desktop-gui/cypress.config.js @@ -0,0 +1,21 @@ +module.exports = { + 'baseUrl': 'http://localhost:5005', + 'projectId': 'ypt4pf', + 'viewportWidth': 800, + 'viewportHeight': 850, + 'env': { + 'webpackFilename': 'webpack.config.ts', + 'coverage': false, + }, + 'retries': { + 'runMode': 2, + 'openMode': 0, + }, + 'nodeVersion': 'system', + 'testFiles': '**/*_spec.{js,jsx}', + 'componentFolder': 'src', + 'reporter': '../../node_modules/cypress-multi-reporters/index.js', + 'reporterOptions': { + 'configFile': '../../mocha-reporter-config.json', + }, +} diff --git a/packages/desktop-gui/cypress.json b/packages/desktop-gui/cypress.json deleted file mode 100644 index 431581dce2ff..000000000000 --- a/packages/desktop-gui/cypress.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "baseUrl": "http://localhost:5005", - "projectId": "ypt4pf", - "viewportWidth": 800, - "viewportHeight": 850, - "env": { - "webpackFilename": "webpack.config.ts", - "coverage": false - }, - "retries": { - "runMode": 2, - "openMode": 0 - }, - "nodeVersion": "system", - "testFiles": "**/*_spec.{js,jsx}", - "componentFolder": "src", - "reporter": "../../node_modules/cypress-multi-reporters/index.js", - "reporterOptions": { - "configFile": "../../mocha-reporter-config.json" - } -} \ No newline at end of file diff --git a/packages/driver/cypress.config.ts b/packages/driver/cypress.config.ts new file mode 100644 index 000000000000..921ad91a8373 --- /dev/null +++ b/packages/driver/cypress.config.ts @@ -0,0 +1,12 @@ +module.exports = { + 'projectId': 'ypt4pf', + 'baseUrl': 'http://localhost:3500', + 'testFiles': '**/*', + 'hosts': { + '*.foobar.com': '127.0.0.1', + }, + 'reporter': 'cypress-multi-reporters', + 'reporterOptions': { + 'configFile': '../../mocha-reporter-config.json', + }, +} diff --git a/packages/driver/cypress.json b/packages/driver/cypress.json deleted file mode 100644 index 0128042adffd..000000000000 --- a/packages/driver/cypress.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "projectId": "ypt4pf", - "baseUrl": "http://localhost:3500", - "testFiles": "**/*", - "hosts": { - "*.foobar.com": "127.0.0.1" - }, - "reporter": "cypress-multi-reporters", - "reporterOptions": { - "configFile": "../../mocha-reporter-config.json" - } -} diff --git a/packages/example/cypress.json b/packages/example/cypress.config.js similarity index 59% rename from packages/example/cypress.json rename to packages/example/cypress.config.js index 628b3740dedd..c43d27f47714 100644 --- a/packages/example/cypress.json +++ b/packages/example/cypress.config.js @@ -1,4 +1,4 @@ -{ +module.exports = { "projectId": "2pz86o" } \ No newline at end of file diff --git a/packages/frontend-shared/cypress.config.ts b/packages/frontend-shared/cypress.config.ts new file mode 100644 index 000000000000..9510990ad0b4 --- /dev/null +++ b/packages/frontend-shared/cypress.config.ts @@ -0,0 +1,22 @@ +module.exports = { + 'projectId': 'sehy69', + 'baseUrl': 'http://localhost:5555', + 'viewportWidth': 800, + 'viewportHeight': 850, + 'retries': { + 'runMode': 2, + 'openMode': 0, + }, + 'nodeVersion': 'system', + 'testFiles': '**/*.spec.{js,ts,tsx,jsx}', + 'reporter': '../../node_modules/cypress-multi-reporters/index.js', + 'reporterOptions': { + 'configFile': '../../mocha-reporter-config.json', + }, + 'component': { + 'componentFolder': 'src/components', + }, + 'e2e': { + 'supportFile': 'cypress/e2e/support/e2eSupport.ts', + }, +} diff --git a/packages/frontend-shared/cypress.json b/packages/frontend-shared/cypress.json deleted file mode 100644 index aa7055a91851..000000000000 --- a/packages/frontend-shared/cypress.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "projectId": "sehy69", - "baseUrl": "http://localhost:5555", - "viewportWidth": 800, - "viewportHeight": 850, - "retries": { - "runMode": 2, - "openMode": 0 - }, - "nodeVersion": "system", - "testFiles": "**/*.spec.{js,ts,tsx,jsx}", - "reporter": "../../node_modules/cypress-multi-reporters/index.js", - "reporterOptions": { - "configFile": "../../mocha-reporter-config.json" - }, - "component": { - "componentFolder": "src/components" - }, - "e2e": { - "supportFile": "cypress/e2e/support/e2eSupport.ts" - } -} diff --git a/packages/launchpad/cypress/fixtures/test-project/cypress.json b/packages/launchpad/cypress/fixtures/test-project/cypress.config.ts similarity index 56% rename from packages/launchpad/cypress/fixtures/test-project/cypress.json rename to packages/launchpad/cypress/fixtures/test-project/cypress.config.ts index fdaf8410dd73..c92eb34ba2ec 100644 --- a/packages/launchpad/cypress/fixtures/test-project/cypress.json +++ b/packages/launchpad/cypress/fixtures/test-project/cypress.config.ts @@ -1,3 +1,3 @@ -{ +module.exports = { "projectId": "test01" } \ No newline at end of file diff --git a/packages/reporter/cypress.config.ts b/packages/reporter/cypress.config.ts new file mode 100644 index 000000000000..aa00292e49cf --- /dev/null +++ b/packages/reporter/cypress.config.ts @@ -0,0 +1,14 @@ +module.exports = { + 'projectId': 'ypt4pf', + 'baseUrl': 'http://localhost:5006', + 'viewportWidth': 400, + 'viewportHeight': 450, + 'reporter': '../../node_modules/cypress-multi-reporters/index.js', + 'reporterOptions': { + 'configFile': '../../mocha-reporter-config.json', + }, + 'retries': { + 'runMode': 2, + 'openMode': 0, + }, +} diff --git a/packages/reporter/cypress.json b/packages/reporter/cypress.json deleted file mode 100644 index bbf940fae4c6..000000000000 --- a/packages/reporter/cypress.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "projectId": "ypt4pf", - "baseUrl": "http://localhost:5006", - "viewportWidth": 400, - "viewportHeight": 450, - "reporter": "../../node_modules/cypress-multi-reporters/index.js", - "reporterOptions": { - "configFile": "../../mocha-reporter-config.json" - }, - "retries": { - "runMode": 2, - "openMode": 0 - } -} diff --git a/packages/runner-ct/cypress.config.ts b/packages/runner-ct/cypress.config.ts new file mode 100644 index 000000000000..164662b3065b --- /dev/null +++ b/packages/runner-ct/cypress.config.ts @@ -0,0 +1,11 @@ +module.exports = { + testFiles: '**/*spec.{ts,tsx}', + video: true, + env: { + reactDevtools: false, + }, + reporter: '../../node_modules/cypress-multi-reporters/index.js', + reporterOptions: { + configFile: '../../mocha-reporter-config.json', + }, +} diff --git a/packages/runner-ct/cypress.json b/packages/runner-ct/cypress.json deleted file mode 100644 index 986e4f21b711..000000000000 --- a/packages/runner-ct/cypress.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "testFiles": "**/*spec.{ts,tsx}", - "video": true, - "env": { - "reactDevtools": false - }, - "reporter": "../../node_modules/cypress-multi-reporters/index.js", - "reporterOptions": { - "configFile": "../../mocha-reporter-config.json" - } -} diff --git a/packages/runner/cypress.config.js b/packages/runner/cypress.config.js new file mode 100644 index 000000000000..3b33ab67a183 --- /dev/null +++ b/packages/runner/cypress.config.js @@ -0,0 +1,15 @@ +module.exports = { + 'projectId': 'ypt4pf', + 'baseUrl': 'http://localhost:3500', + 'retries': { + 'runMode': 2, + 'openMode': 0, + }, + 'env': { + 'CypressInternal_UseInlineSpecList': true, + }, + 'reporter': '../../node_modules/cypress-multi-reporters/index.js', + 'reporterOptions': { + 'configFile': '../../mocha-reporter-config.json', + }, +} diff --git a/packages/runner/cypress.json b/packages/runner/cypress.json deleted file mode 100644 index e944678dde18..000000000000 --- a/packages/runner/cypress.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "projectId": "ypt4pf", - "baseUrl": "http://localhost:3500", - "retries": { - "runMode": 2, - "openMode": 0 - }, - "env": { - "CypressInternal_UseInlineSpecList": true - }, - "reporter": "../../node_modules/cypress-multi-reporters/index.js", - "reporterOptions": { - "configFile": "../../mocha-reporter-config.json" - } -} diff --git a/packages/ui-components/cypress.config.js b/packages/ui-components/cypress.config.js new file mode 100644 index 000000000000..64f641119e33 --- /dev/null +++ b/packages/ui-components/cypress.config.js @@ -0,0 +1,12 @@ +module.exports = { + 'fixturesFolder': false, + 'projectId': 'ypt4pf', + 'reporter': '../../node_modules/cypress-multi-reporters/index.js', + 'reporterOptions': { + 'configFile': '../../mocha-reporter-config.json', + }, + 'retries': { + 'runMode': 2, + 'openMode': 0, + }, +} diff --git a/packages/ui-components/cypress.json b/packages/ui-components/cypress.json deleted file mode 100644 index 88a0a5a24700..000000000000 --- a/packages/ui-components/cypress.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "fixturesFolder": false, - "projectId": "ypt4pf", - "reporter": "../../node_modules/cypress-multi-reporters/index.js", - "reporterOptions": { - "configFile": "../../mocha-reporter-config.json" - }, - "retries": { - "runMode": 2, - "openMode": 0 - } -} diff --git a/system-tests/projects/browser-extensions/cypress.config.js b/system-tests/projects/browser-extensions/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/browser-extensions/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/browser-extensions/cypress.json b/system-tests/projects/browser-extensions/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/browser-extensions/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/busted-support-file/cypress.config.js b/system-tests/projects/busted-support-file/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/busted-support-file/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/busted-support-file/cypress.json b/system-tests/projects/busted-support-file/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/busted-support-file/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/chrome-browser-preferences/cypress.config.js b/system-tests/projects/chrome-browser-preferences/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/chrome-browser-preferences/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/chrome-browser-preferences/cypress.json b/system-tests/projects/chrome-browser-preferences/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/chrome-browser-preferences/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/component-tests/cypress.config.js b/system-tests/projects/component-tests/cypress.config.js new file mode 100644 index 000000000000..fcff9a0c965e --- /dev/null +++ b/system-tests/projects/component-tests/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'componentFolder': 'cypress/component-tests', +} diff --git a/system-tests/projects/component-tests/cypress.json b/system-tests/projects/component-tests/cypress.json deleted file mode 100644 index ccb8342370df..000000000000 --- a/system-tests/projects/component-tests/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "componentFolder": "cypress/component-tests" -} \ No newline at end of file diff --git a/system-tests/projects/config-with-invalid-browser/cypress.config.js b/system-tests/projects/config-with-invalid-browser/cypress.config.js new file mode 100644 index 000000000000..2277b0787ed5 --- /dev/null +++ b/system-tests/projects/config-with-invalid-browser/cypress.config.js @@ -0,0 +1,12 @@ +module.exports = { + 'browsers': [ + { + 'name': 'bad browser', + 'family': 'unknown family', + 'displayName': 'Bad browser', + 'version': 'no version', + 'path': '/path/to', + 'majorVersion': 123, + }, + ], +} diff --git a/system-tests/projects/config-with-invalid-browser/cypress.json b/system-tests/projects/config-with-invalid-browser/cypress.json deleted file mode 100644 index 71c2cfbbf0ad..000000000000 --- a/system-tests/projects/config-with-invalid-browser/cypress.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "browsers": [ - { - "name": "bad browser", - "family": "unknown family", - "displayName": "Bad browser", - "version": "no version", - "path": "/path/to", - "majorVersion": 123 - } - ] -} diff --git a/system-tests/projects/config-with-invalid-viewport/cypress.config.js b/system-tests/projects/config-with-invalid-viewport/cypress.config.js new file mode 100644 index 000000000000..cda4d27347e5 --- /dev/null +++ b/system-tests/projects/config-with-invalid-viewport/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'viewportWidth': 'foo', +} diff --git a/system-tests/projects/config-with-invalid-viewport/cypress.json b/system-tests/projects/config-with-invalid-viewport/cypress.json deleted file mode 100644 index 3e411ccd676a..000000000000 --- a/system-tests/projects/config-with-invalid-viewport/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "viewportWidth": "foo" -} diff --git a/system-tests/projects/config-with-short-timeout/cypress.config.js b/system-tests/projects/config-with-short-timeout/cypress.config.js new file mode 100644 index 000000000000..dfb84e7cd15e --- /dev/null +++ b/system-tests/projects/config-with-short-timeout/cypress.config.js @@ -0,0 +1,5 @@ +module.exports = { + 'defaultCommandTimeout': 1000, + 'pluginsFile': false, + 'supportFile': false, +} diff --git a/system-tests/projects/config-with-short-timeout/cypress.json b/system-tests/projects/config-with-short-timeout/cypress.json deleted file mode 100644 index 9dd38efd5217..000000000000 --- a/system-tests/projects/config-with-short-timeout/cypress.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "defaultCommandTimeout": 1000, - "pluginsFile": false, - "supportFile": false -} diff --git a/system-tests/projects/cookies/cypress.config.js b/system-tests/projects/cookies/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/cookies/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/cookies/cypress.json b/system-tests/projects/cookies/cypress.json deleted file mode 100644 index 9e26dfeeb6e6..000000000000 --- a/system-tests/projects/cookies/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/system-tests/projects/default-layout/cypress.config.js b/system-tests/projects/default-layout/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/default-layout/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/default-layout/cypress.json b/system-tests/projects/default-layout/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/default-layout/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/downloads/cypress.config.js b/system-tests/projects/downloads/cypress.config.js new file mode 100644 index 000000000000..3a77c847f08c --- /dev/null +++ b/system-tests/projects/downloads/cypress.config.js @@ -0,0 +1,5 @@ +module.exports = { + 'fixturesFolder': false, + 'pluginsFile': false, + 'supportFile': false, +} diff --git a/system-tests/projects/downloads/cypress.json b/system-tests/projects/downloads/cypress.json deleted file mode 100644 index e81c35571a05..000000000000 --- a/system-tests/projects/downloads/cypress.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "fixturesFolder": false, - "pluginsFile": false, - "supportFile": false -} diff --git a/system-tests/projects/e2e/cypress.config.js b/system-tests/projects/e2e/cypress.config.js new file mode 100644 index 000000000000..877daa2db3e4 --- /dev/null +++ b/system-tests/projects/e2e/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'retries': null, +} diff --git a/system-tests/projects/e2e/cypress.json b/system-tests/projects/e2e/cypress.json deleted file mode 100644 index 0f77b44749ce..000000000000 --- a/system-tests/projects/e2e/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "retries": null -} diff --git a/system-tests/projects/empty-folders/cypress.config.js b/system-tests/projects/empty-folders/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/empty-folders/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/empty-folders/cypress.json b/system-tests/projects/empty-folders/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/empty-folders/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/failures/cypress/cypress.config.js b/system-tests/projects/failures/cypress/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/failures/cypress/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/failures/cypress/cypress.json b/system-tests/projects/failures/cypress/cypress.json deleted file mode 100644 index 9e26dfeeb6e6..000000000000 --- a/system-tests/projects/failures/cypress/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/system-tests/projects/firefox-memory/cypress.config.js b/system-tests/projects/firefox-memory/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/firefox-memory/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/firefox-memory/cypress.json b/system-tests/projects/firefox-memory/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/firefox-memory/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/fixture-subfolder-of-integration/cypress.config.js b/system-tests/projects/fixture-subfolder-of-integration/cypress.config.js new file mode 100644 index 000000000000..5c5433c400de --- /dev/null +++ b/system-tests/projects/fixture-subfolder-of-integration/cypress.config.js @@ -0,0 +1,7 @@ +module.exports = { + 'pluginsFile': false, + 'supportFile': false, + 'integrationFolder': 'test', + 'fixturesFolder': 'test/fixtures', + 'testFiles': '**/*spec.js', +} diff --git a/system-tests/projects/fixture-subfolder-of-integration/cypress.json b/system-tests/projects/fixture-subfolder-of-integration/cypress.json deleted file mode 100644 index d324ec085e59..000000000000 --- a/system-tests/projects/fixture-subfolder-of-integration/cypress.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "pluginsFile": false, - "supportFile": false, - "integrationFolder": "test", - "fixturesFolder": "test/fixtures", - "testFiles": "**/*spec.js" -} diff --git a/system-tests/projects/folder-same-as-fixture/cypress.config.js b/system-tests/projects/folder-same-as-fixture/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/folder-same-as-fixture/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/folder-same-as-fixture/cypress.json b/system-tests/projects/folder-same-as-fixture/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/folder-same-as-fixture/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/hooks-after-rerun/cypress.config.js b/system-tests/projects/hooks-after-rerun/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/hooks-after-rerun/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/hooks-after-rerun/cypress.json b/system-tests/projects/hooks-after-rerun/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/hooks-after-rerun/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/ids/cypress.config.js b/system-tests/projects/ids/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/ids/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/ids/cypress.json b/system-tests/projects/ids/cypress.json deleted file mode 100644 index 9e26dfeeb6e6..000000000000 --- a/system-tests/projects/ids/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/system-tests/projects/integration-outside-project-root/project-root/cypress.config.js b/system-tests/projects/integration-outside-project-root/project-root/cypress.config.js new file mode 100644 index 000000000000..0f2dc30b98f3 --- /dev/null +++ b/system-tests/projects/integration-outside-project-root/project-root/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'integrationFolder': '../integration', +} diff --git a/system-tests/projects/integration-outside-project-root/project-root/cypress.json b/system-tests/projects/integration-outside-project-root/project-root/cypress.json deleted file mode 100644 index a3f0bee68816..000000000000 --- a/system-tests/projects/integration-outside-project-root/project-root/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "integrationFolder": "../integration" -} diff --git a/system-tests/projects/issue-8111-iframe-input/cypress.config.js b/system-tests/projects/issue-8111-iframe-input/cypress.config.js new file mode 100644 index 000000000000..85067c9cc962 --- /dev/null +++ b/system-tests/projects/issue-8111-iframe-input/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'supportFolder': false, +} diff --git a/system-tests/projects/issue-8111-iframe-input/cypress.json b/system-tests/projects/issue-8111-iframe-input/cypress.json deleted file mode 100644 index 9c5417cd8268..000000000000 --- a/system-tests/projects/issue-8111-iframe-input/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "supportFolder": false -} diff --git a/system-tests/projects/max-listeners/cypress.config.js b/system-tests/projects/max-listeners/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/max-listeners/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/max-listeners/cypress.json b/system-tests/projects/max-listeners/cypress.json deleted file mode 100644 index 9e26dfeeb6e6..000000000000 --- a/system-tests/projects/max-listeners/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/system-tests/projects/multiple-task-registrations/cypress.config.js b/system-tests/projects/multiple-task-registrations/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/multiple-task-registrations/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/multiple-task-registrations/cypress.json b/system-tests/projects/multiple-task-registrations/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/multiple-task-registrations/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/no-scaffolding/cypress.config.js b/system-tests/projects/no-scaffolding/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/no-scaffolding/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/no-scaffolding/cypress.json b/system-tests/projects/no-scaffolding/cypress.json deleted file mode 100644 index 9e26dfeeb6e6..000000000000 --- a/system-tests/projects/no-scaffolding/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/system-tests/projects/no-server/cypress.config.js b/system-tests/projects/no-server/cypress.config.js new file mode 100644 index 000000000000..8e9b800a298b --- /dev/null +++ b/system-tests/projects/no-server/cypress.config.js @@ -0,0 +1,6 @@ +module.exports = { + 'cypress': { + 'integrationFolder': 'my-tests', + 'fileServerFolder': 'dev', + }, +} diff --git a/system-tests/projects/no-server/cypress.json b/system-tests/projects/no-server/cypress.json deleted file mode 100644 index a2f26c3597d9..000000000000 --- a/system-tests/projects/no-server/cypress.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cypress": { - "integrationFolder": "my-tests", - "fileServerFolder": "dev" - } -} \ No newline at end of file diff --git a/system-tests/projects/non-existent-spec/cypress.config.js b/system-tests/projects/non-existent-spec/cypress.config.js new file mode 100644 index 000000000000..f0064695754a --- /dev/null +++ b/system-tests/projects/non-existent-spec/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'supportFile': false, +} diff --git a/system-tests/projects/non-existent-spec/cypress.json b/system-tests/projects/non-existent-spec/cypress.json deleted file mode 100644 index 0c2bdde8665b..000000000000 --- a/system-tests/projects/non-existent-spec/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "supportFile": false -} diff --git a/system-tests/projects/non-proxied/cypress.config.js b/system-tests/projects/non-proxied/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/non-proxied/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/non-proxied/cypress.json b/system-tests/projects/non-proxied/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/non-proxied/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-after-screenshot/cypress.config.js b/system-tests/projects/plugin-after-screenshot/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-after-screenshot/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-after-screenshot/cypress.json b/system-tests/projects/plugin-after-screenshot/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-after-screenshot/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-after-spec-deletes-video/cypress.config.js b/system-tests/projects/plugin-after-spec-deletes-video/cypress.config.js new file mode 100644 index 000000000000..4f64c2459252 --- /dev/null +++ b/system-tests/projects/plugin-after-spec-deletes-video/cypress.config.js @@ -0,0 +1,4 @@ +module.exports = { + 'fixturesFolder': false, + 'supportFile': false, +} diff --git a/system-tests/projects/plugin-after-spec-deletes-video/cypress.json b/system-tests/projects/plugin-after-spec-deletes-video/cypress.json deleted file mode 100644 index a84f6e38c9e9..000000000000 --- a/system-tests/projects/plugin-after-spec-deletes-video/cypress.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "fixturesFolder": false, - "supportFile": false -} diff --git a/system-tests/projects/plugin-before-browser-launch-deprecation/cypress.config.js b/system-tests/projects/plugin-before-browser-launch-deprecation/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-before-browser-launch-deprecation/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-before-browser-launch-deprecation/cypress.json b/system-tests/projects/plugin-before-browser-launch-deprecation/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-before-browser-launch-deprecation/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-browser/cypress.config.js b/system-tests/projects/plugin-browser/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-browser/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-browser/cypress.json b/system-tests/projects/plugin-browser/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-browser/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-config-version/cypress.config.js b/system-tests/projects/plugin-config-version/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-config-version/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-config-version/cypress.json b/system-tests/projects/plugin-config-version/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-config-version/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-config/cypress.config.js b/system-tests/projects/plugin-config/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-config/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-config/cypress.json b/system-tests/projects/plugin-config/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-config/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-empty/cypress.config.js b/system-tests/projects/plugin-empty/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-empty/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-empty/cypress.json b/system-tests/projects/plugin-empty/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-empty/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-event-deprecated/cypress.config.js b/system-tests/projects/plugin-event-deprecated/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-event-deprecated/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-event-deprecated/cypress.json b/system-tests/projects/plugin-event-deprecated/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-event-deprecated/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-extension/cypress.config.js b/system-tests/projects/plugin-extension/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-extension/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-extension/cypress.json b/system-tests/projects/plugin-extension/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-extension/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-filter-browsers/cypress.config.js b/system-tests/projects/plugin-filter-browsers/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-filter-browsers/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-filter-browsers/cypress.json b/system-tests/projects/plugin-filter-browsers/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-filter-browsers/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-retries/cypress.config.js b/system-tests/projects/plugin-retries/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-retries/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-retries/cypress.json b/system-tests/projects/plugin-retries/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-retries/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-returns-bad-config/cypress.config.js b/system-tests/projects/plugin-returns-bad-config/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-returns-bad-config/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-returns-bad-config/cypress.json b/system-tests/projects/plugin-returns-bad-config/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-returns-bad-config/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-returns-empty-browsers-list/cypress.config.js b/system-tests/projects/plugin-returns-empty-browsers-list/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-returns-empty-browsers-list/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-returns-empty-browsers-list/cypress.json b/system-tests/projects/plugin-returns-empty-browsers-list/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-returns-empty-browsers-list/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-returns-invalid-browser/cypress.config.js b/system-tests/projects/plugin-returns-invalid-browser/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-returns-invalid-browser/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-returns-invalid-browser/cypress.json b/system-tests/projects/plugin-returns-invalid-browser/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-returns-invalid-browser/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugin-run-event-throws/cypress.config.js b/system-tests/projects/plugin-run-event-throws/cypress.config.js new file mode 100644 index 000000000000..4f64c2459252 --- /dev/null +++ b/system-tests/projects/plugin-run-event-throws/cypress.config.js @@ -0,0 +1,4 @@ +module.exports = { + 'fixturesFolder': false, + 'supportFile': false, +} diff --git a/system-tests/projects/plugin-run-event-throws/cypress.json b/system-tests/projects/plugin-run-event-throws/cypress.json deleted file mode 100644 index a84f6e38c9e9..000000000000 --- a/system-tests/projects/plugin-run-event-throws/cypress.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "fixturesFolder": false, - "supportFile": false -} diff --git a/system-tests/projects/plugin-run-events/cypress.config.js b/system-tests/projects/plugin-run-events/cypress.config.js new file mode 100644 index 000000000000..4f64c2459252 --- /dev/null +++ b/system-tests/projects/plugin-run-events/cypress.config.js @@ -0,0 +1,4 @@ +module.exports = { + 'fixturesFolder': false, + 'supportFile': false, +} diff --git a/system-tests/projects/plugin-run-events/cypress.json b/system-tests/projects/plugin-run-events/cypress.json deleted file mode 100644 index a84f6e38c9e9..000000000000 --- a/system-tests/projects/plugin-run-events/cypress.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "fixturesFolder": false, - "supportFile": false -} diff --git a/system-tests/projects/plugin-validation-error/cypress.config.js b/system-tests/projects/plugin-validation-error/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugin-validation-error/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugin-validation-error/cypress.json b/system-tests/projects/plugin-validation-error/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugin-validation-error/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugins-absolute-path/cypress.config.js b/system-tests/projects/plugins-absolute-path/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugins-absolute-path/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugins-absolute-path/cypress.json b/system-tests/projects/plugins-absolute-path/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugins-absolute-path/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugins-async-error/cypress.config.js b/system-tests/projects/plugins-async-error/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugins-async-error/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugins-async-error/cypress.json b/system-tests/projects/plugins-async-error/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugins-async-error/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/plugins-root-async-error/cypress.config.js b/system-tests/projects/plugins-root-async-error/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/plugins-root-async-error/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/plugins-root-async-error/cypress.json b/system-tests/projects/plugins-root-async-error/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/plugins-root-async-error/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/read-only-project-root/cypress.config.js b/system-tests/projects/read-only-project-root/cypress.config.js new file mode 100644 index 000000000000..877daa2db3e4 --- /dev/null +++ b/system-tests/projects/read-only-project-root/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'retries': null, +} diff --git a/system-tests/projects/read-only-project-root/cypress.json b/system-tests/projects/read-only-project-root/cypress.json deleted file mode 100644 index 0f77b44749ce..000000000000 --- a/system-tests/projects/read-only-project-root/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "retries": null -} diff --git a/system-tests/projects/record/cypress.config.js b/system-tests/projects/record/cypress.config.js new file mode 100644 index 000000000000..411b63264e86 --- /dev/null +++ b/system-tests/projects/record/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'projectId': 'abc123', +} diff --git a/system-tests/projects/record/cypress.json b/system-tests/projects/record/cypress.json deleted file mode 100644 index 45fc46124471..000000000000 --- a/system-tests/projects/record/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "projectId": "abc123" -} diff --git a/system-tests/projects/remote-debugging-disconnect/cypress.config.js b/system-tests/projects/remote-debugging-disconnect/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/remote-debugging-disconnect/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/remote-debugging-disconnect/cypress.json b/system-tests/projects/remote-debugging-disconnect/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/remote-debugging-disconnect/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/remote-debugging-port-removed/cypress.config.js b/system-tests/projects/remote-debugging-port-removed/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/remote-debugging-port-removed/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/remote-debugging-port-removed/cypress.json b/system-tests/projects/remote-debugging-port-removed/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/remote-debugging-port-removed/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/retries-2/cypress.config.js b/system-tests/projects/retries-2/cypress.config.js new file mode 100644 index 000000000000..aceff2a31cc0 --- /dev/null +++ b/system-tests/projects/retries-2/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'retries': 2, +} diff --git a/system-tests/projects/retries-2/cypress.json b/system-tests/projects/retries-2/cypress.json deleted file mode 100644 index cd6342eef42e..000000000000 --- a/system-tests/projects/retries-2/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "retries": 2 -} diff --git a/system-tests/projects/same-fixtures-integration-folders/cypress.config.js b/system-tests/projects/same-fixtures-integration-folders/cypress.config.js new file mode 100644 index 000000000000..88a6bdbc4ed7 --- /dev/null +++ b/system-tests/projects/same-fixtures-integration-folders/cypress.config.js @@ -0,0 +1,6 @@ +module.exports = { + 'pluginsFile': false, + 'supportFile': false, + 'fixturesFolder': 'cypress/integration', + 'testFiles': '**/*spec.js', +} diff --git a/system-tests/projects/same-fixtures-integration-folders/cypress.json b/system-tests/projects/same-fixtures-integration-folders/cypress.json deleted file mode 100644 index 8aaf4cebbc0f..000000000000 --- a/system-tests/projects/same-fixtures-integration-folders/cypress.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "pluginsFile": false, - "supportFile": false, - "fixturesFolder": "cypress/integration", - "testFiles": "**/*spec.js" -} diff --git a/system-tests/projects/screen-size/cypress.config.js b/system-tests/projects/screen-size/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/screen-size/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/screen-size/cypress.json b/system-tests/projects/screen-size/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/screen-size/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/shadow-dom-global-inclusion/cypress.config.js b/system-tests/projects/shadow-dom-global-inclusion/cypress.config.js new file mode 100644 index 000000000000..361b5c94d55a --- /dev/null +++ b/system-tests/projects/shadow-dom-global-inclusion/cypress.config.js @@ -0,0 +1,5 @@ +module.exports = { + 'includeShadowDom': true, + 'pluginsFile': false, + 'supportFile': false, +} diff --git a/system-tests/projects/shadow-dom-global-inclusion/cypress.json b/system-tests/projects/shadow-dom-global-inclusion/cypress.json deleted file mode 100644 index 1ae377bbf7fd..000000000000 --- a/system-tests/projects/shadow-dom-global-inclusion/cypress.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "includeShadowDom": true, - "pluginsFile": false, - "supportFile": false -} diff --git a/system-tests/projects/spec-generation/cypress.config.js b/system-tests/projects/spec-generation/cypress.config.js new file mode 100644 index 000000000000..79ad5c8c1402 --- /dev/null +++ b/system-tests/projects/spec-generation/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'componentFolder': 'src', +} diff --git a/system-tests/projects/spec-generation/cypress.json b/system-tests/projects/spec-generation/cypress.json deleted file mode 100644 index e89f59283819..000000000000 --- a/system-tests/projects/spec-generation/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "componentFolder": "src" -} \ No newline at end of file diff --git a/system-tests/projects/studio-no-source-maps/cypress.config.js b/system-tests/projects/studio-no-source-maps/cypress.config.js new file mode 100644 index 000000000000..8638ba2f105b --- /dev/null +++ b/system-tests/projects/studio-no-source-maps/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'experimentalStudio': true, +} diff --git a/system-tests/projects/studio-no-source-maps/cypress.json b/system-tests/projects/studio-no-source-maps/cypress.json deleted file mode 100644 index 156a3ac524c8..000000000000 --- a/system-tests/projects/studio-no-source-maps/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "experimentalStudio": true -} diff --git a/system-tests/projects/studio/cypress.config.js b/system-tests/projects/studio/cypress.config.js new file mode 100644 index 000000000000..8638ba2f105b --- /dev/null +++ b/system-tests/projects/studio/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'experimentalStudio': true, +} diff --git a/system-tests/projects/studio/cypress.json b/system-tests/projects/studio/cypress.json deleted file mode 100644 index 156a3ac524c8..000000000000 --- a/system-tests/projects/studio/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "experimentalStudio": true -} diff --git a/system-tests/projects/system-node/cypress.config.js b/system-tests/projects/system-node/cypress.config.js new file mode 100644 index 000000000000..8d21334bfe8b --- /dev/null +++ b/system-tests/projects/system-node/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'nodeVersion': 'system', +} diff --git a/system-tests/projects/system-node/cypress.json b/system-tests/projects/system-node/cypress.json deleted file mode 100644 index ceb03f061915..000000000000 --- a/system-tests/projects/system-node/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "nodeVersion": "system" -} diff --git a/system-tests/projects/task-not-registered/cypress.config.js b/system-tests/projects/task-not-registered/cypress.config.js new file mode 100644 index 000000000000..877daa2db3e4 --- /dev/null +++ b/system-tests/projects/task-not-registered/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'retries': null, +} diff --git a/system-tests/projects/task-not-registered/cypress.json b/system-tests/projects/task-not-registered/cypress.json deleted file mode 100644 index 0f77b44749ce..000000000000 --- a/system-tests/projects/task-not-registered/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "retries": null -} diff --git a/system-tests/projects/todos/cypress.config.js b/system-tests/projects/todos/cypress.config.js new file mode 100644 index 000000000000..98b8373d51d2 --- /dev/null +++ b/system-tests/projects/todos/cypress.config.js @@ -0,0 +1,8 @@ +module.exports = { + 'integrationFolder': 'tests', + 'fixturesFolder': 'tests/_fixtures', + 'supportFile': 'tests/_support/spec_helper.js', + 'port': 8888, + 'projectId': 'abc123', + 'pluginsFile': false, +} diff --git a/system-tests/projects/todos/cypress.json b/system-tests/projects/todos/cypress.json deleted file mode 100644 index c98ed7c0b3ac..000000000000 --- a/system-tests/projects/todos/cypress.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "integrationFolder": "tests", - "fixturesFolder": "tests/_fixtures", - "supportFile": "tests/_support/spec_helper.js", - "port": 8888, - "projectId": "abc123", - "pluginsFile": false -} diff --git a/system-tests/projects/ts-installed/cypress.config.js b/system-tests/projects/ts-installed/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/ts-installed/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/ts-installed/cypress.json b/system-tests/projects/ts-installed/cypress.json deleted file mode 100644 index 9e26dfeeb6e6..000000000000 --- a/system-tests/projects/ts-installed/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/system-tests/projects/ts-proj-custom-names/cypress.config.js b/system-tests/projects/ts-proj-custom-names/cypress.config.js new file mode 100644 index 000000000000..946f26dbc696 --- /dev/null +++ b/system-tests/projects/ts-proj-custom-names/cypress.config.js @@ -0,0 +1,4 @@ +module.exports = { + 'supportFile': 'cypress/support.ts', + 'pluginsFile': 'cypress/plugins.ts', +} diff --git a/system-tests/projects/ts-proj-custom-names/cypress.json b/system-tests/projects/ts-proj-custom-names/cypress.json deleted file mode 100644 index a054eca6f9e0..000000000000 --- a/system-tests/projects/ts-proj-custom-names/cypress.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "supportFile": "cypress/support.ts", - "pluginsFile": "cypress/plugins.ts" -} diff --git a/system-tests/projects/ts-proj-esmoduleinterop-true/cypress.config.js b/system-tests/projects/ts-proj-esmoduleinterop-true/cypress.config.js new file mode 100644 index 000000000000..f0064695754a --- /dev/null +++ b/system-tests/projects/ts-proj-esmoduleinterop-true/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'supportFile': false, +} diff --git a/system-tests/projects/ts-proj-esmoduleinterop-true/cypress.json b/system-tests/projects/ts-proj-esmoduleinterop-true/cypress.json deleted file mode 100644 index 0c2bdde8665b..000000000000 --- a/system-tests/projects/ts-proj-esmoduleinterop-true/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "supportFile": false -} diff --git a/system-tests/projects/ts-proj-tsconfig-in-plugins/cypress.config.js b/system-tests/projects/ts-proj-tsconfig-in-plugins/cypress.config.js new file mode 100644 index 000000000000..f0064695754a --- /dev/null +++ b/system-tests/projects/ts-proj-tsconfig-in-plugins/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'supportFile': false, +} diff --git a/system-tests/projects/ts-proj-tsconfig-in-plugins/cypress.json b/system-tests/projects/ts-proj-tsconfig-in-plugins/cypress.json deleted file mode 100644 index 0c2bdde8665b..000000000000 --- a/system-tests/projects/ts-proj-tsconfig-in-plugins/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "supportFile": false -} diff --git a/system-tests/projects/ts-proj-with-module-esnext/cypress.config.js b/system-tests/projects/ts-proj-with-module-esnext/cypress.config.js new file mode 100644 index 000000000000..85067c9cc962 --- /dev/null +++ b/system-tests/projects/ts-proj-with-module-esnext/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'supportFolder': false, +} diff --git a/system-tests/projects/ts-proj-with-module-esnext/cypress.json b/system-tests/projects/ts-proj-with-module-esnext/cypress.json deleted file mode 100644 index 9c5417cd8268..000000000000 --- a/system-tests/projects/ts-proj-with-module-esnext/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "supportFolder": false -} diff --git a/system-tests/projects/ts-proj-with-paths/cypress.config.js b/system-tests/projects/ts-proj-with-paths/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/ts-proj-with-paths/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/ts-proj-with-paths/cypress.json b/system-tests/projects/ts-proj-with-paths/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/ts-proj-with-paths/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/ts-proj/cypress.config.js b/system-tests/projects/ts-proj/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/ts-proj/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/ts-proj/cypress.json b/system-tests/projects/ts-proj/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/ts-proj/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/uncaught-support-file/cypress.config.js b/system-tests/projects/uncaught-support-file/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/uncaught-support-file/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/uncaught-support-file/cypress.json b/system-tests/projects/uncaught-support-file/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/uncaught-support-file/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/unify-plugin-errors/cypress.config.js b/system-tests/projects/unify-plugin-errors/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/unify-plugin-errors/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/unify-plugin-errors/cypress.json b/system-tests/projects/unify-plugin-errors/cypress.json deleted file mode 100644 index 9e26dfeeb6e6..000000000000 --- a/system-tests/projects/unify-plugin-errors/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/system-tests/projects/webpack-preprocessor-awesome-typescript-loader/cypress.config.js b/system-tests/projects/webpack-preprocessor-awesome-typescript-loader/cypress.config.js new file mode 100644 index 000000000000..877daa2db3e4 --- /dev/null +++ b/system-tests/projects/webpack-preprocessor-awesome-typescript-loader/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'retries': null, +} diff --git a/system-tests/projects/webpack-preprocessor-awesome-typescript-loader/cypress.json b/system-tests/projects/webpack-preprocessor-awesome-typescript-loader/cypress.json deleted file mode 100644 index 0f77b44749ce..000000000000 --- a/system-tests/projects/webpack-preprocessor-awesome-typescript-loader/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "retries": null -} diff --git a/system-tests/projects/webpack-preprocessor-ts-loader-compiler-options/cypress.config.js b/system-tests/projects/webpack-preprocessor-ts-loader-compiler-options/cypress.config.js new file mode 100644 index 000000000000..877daa2db3e4 --- /dev/null +++ b/system-tests/projects/webpack-preprocessor-ts-loader-compiler-options/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'retries': null, +} diff --git a/system-tests/projects/webpack-preprocessor-ts-loader-compiler-options/cypress.json b/system-tests/projects/webpack-preprocessor-ts-loader-compiler-options/cypress.json deleted file mode 100644 index 0f77b44749ce..000000000000 --- a/system-tests/projects/webpack-preprocessor-ts-loader-compiler-options/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "retries": null -} diff --git a/system-tests/projects/webpack-preprocessor-ts-loader/cypress.config.js b/system-tests/projects/webpack-preprocessor-ts-loader/cypress.config.js new file mode 100644 index 000000000000..877daa2db3e4 --- /dev/null +++ b/system-tests/projects/webpack-preprocessor-ts-loader/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'retries': null, +} diff --git a/system-tests/projects/webpack-preprocessor-ts-loader/cypress.json b/system-tests/projects/webpack-preprocessor-ts-loader/cypress.json deleted file mode 100644 index 0f77b44749ce..000000000000 --- a/system-tests/projects/webpack-preprocessor-ts-loader/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "retries": null -} diff --git a/system-tests/projects/webpack-preprocessor/cypress.config.js b/system-tests/projects/webpack-preprocessor/cypress.config.js new file mode 100644 index 000000000000..877daa2db3e4 --- /dev/null +++ b/system-tests/projects/webpack-preprocessor/cypress.config.js @@ -0,0 +1,3 @@ +module.exports = { + 'retries': null, +} diff --git a/system-tests/projects/webpack-preprocessor/cypress.json b/system-tests/projects/webpack-preprocessor/cypress.json deleted file mode 100644 index 0f77b44749ce..000000000000 --- a/system-tests/projects/webpack-preprocessor/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "retries": null -} diff --git a/system-tests/projects/working-preprocessor/cypress.config.js b/system-tests/projects/working-preprocessor/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/working-preprocessor/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/working-preprocessor/cypress.json b/system-tests/projects/working-preprocessor/cypress.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/system-tests/projects/working-preprocessor/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/system-tests/projects/yarn-v2-pnp/cypress.config.js b/system-tests/projects/yarn-v2-pnp/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/yarn-v2-pnp/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/yarn-v2-pnp/cypress.json b/system-tests/projects/yarn-v2-pnp/cypress.json deleted file mode 100644 index 9e26dfeeb6e6..000000000000 --- a/system-tests/projects/yarn-v2-pnp/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file From cd1635126a8c740e4368d55596262f08290b1619 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 21 Oct 2021 20:12:44 -0500 Subject: [PATCH 04/57] Update cypress.json usage for config file --- .../init-component-testing.test.ts.js | 14 +++----- npm/create-cypress-tests/cypress.config.js | 1 + .../init-component-testing.test.ts | 32 +++++++++---------- .../src/installCypress.ts | 19 +++++------ npm/create-cypress-tests/src/main.test.ts | 2 +- 5 files changed, 32 insertions(+), 36 deletions(-) create mode 100644 npm/create-cypress-tests/cypress.config.js diff --git a/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js b/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js index 9947ff4275af..f9c47ba4e953 100644 --- a/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js +++ b/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js @@ -1,8 +1,5 @@ -exports['injects guessed next.js template cypress.json'] = ` -{ - "componentFolder": "src", - "testFiles": "**/*.spec.{js,ts,jsx,tsx}" -} +exports['injects guessed next.js template cypress.config.ts'] = ` +module.exports = {} ` exports['injects guessed next.js template plugins/index.js'] = ` @@ -18,11 +15,8 @@ module.exports = (on, config) => { ` -exports['Injected overridden webpack template cypress.json'] = ` -{ - "componentFolder": "cypress/component", - "testFiles": "**/*.spec.{js,ts,jsx,tsx}" -} +exports['Injected overridden webpack template cypress.config.ts'] = ` +module.exports = {} ` exports['Injected overridden webpack template plugins/index.js'] = ` diff --git a/npm/create-cypress-tests/cypress.config.js b/npm/create-cypress-tests/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/npm/create-cypress-tests/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts b/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts index e070b836ff89..2ebf5978cec2 100644 --- a/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts +++ b/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts @@ -20,7 +20,7 @@ describe('init component tests script', () => { let execStub: SinonStub | null = null const e2eTestOutputPath = path.resolve(__dirname, '..', 'test-output') - const cypressConfigPath = path.join(e2eTestOutputPath, 'cypress.json') + const cypressConfigPath = path.join(e2eTestOutputPath, 'cypress.config.ts') beforeEach(async () => { logSpy = sinon.spy(global.console, 'log') @@ -55,9 +55,9 @@ describe('init component tests script', () => { function snapshotGeneratedFiles (name: string) { snapshot( - `${name} cypress.json`, + `${name} cypress.config.ts`, fs.readFileSync( - path.join(e2eTestOutputPath, 'cypress.json'), + path.join(e2eTestOutputPath, 'cypress.config.ts'), { encoding: 'utf-8' }, ), ) @@ -91,7 +91,7 @@ describe('init component tests script', () => { it('determines more presumable configuration to suggest', async () => { createTempFiles({ - '/cypress.json': '{}', + '/cypress.config.ts': 'module.exports = {}', '/cypress/support/index.js': '', '/cypress/plugins/index.js': 'module.exports = (on, config) => {}', // For next.js user will have babel config, but we want to suggest to use the closest config for the application code @@ -114,7 +114,7 @@ describe('init component tests script', () => { it('automatically suggests to the user which config to use', async () => { createTempFiles({ - '/cypress.json': '{}', + '/cypress.config.ts': 'module.exports = {}', '/cypress/support/index.js': 'import "./commands.js";', '/cypress/plugins/index.js': 'module.exports = () => {}', '/package.json': JSON.stringify({ @@ -145,7 +145,7 @@ describe('init component tests script', () => { it('Asks for preferred bundling tool if can not determine the right one', async () => { createTempFiles({ - '/cypress.json': '{}', + '/cypress.config.ts': 'module.exports = {}', '/webpack.config.js': 'module.exports = { }', '/package.json': JSON.stringify({ dependencies: { } }), }) @@ -170,7 +170,7 @@ describe('init component tests script', () => { it('Asks for framework if more than 1 option was auto detected', async () => { createTempFiles({ - '/cypress.json': '{}', + '/cypress.config.ts': 'module.exports = {}', '/webpack.config.js': 'module.exports = { }', '/package.json': JSON.stringify({ dependencies: { react: '*', vue: '^2.4.5' } }), }) @@ -195,7 +195,7 @@ describe('init component tests script', () => { it('installs the right adapter', async () => { createTempFiles({ - '/cypress.json': '{}', + '/cypress.config.ts': 'module.exports = {}', '/webpack.config.js': 'module.exports = { }', '/package.json': JSON.stringify({ dependencies: { react: '16.4.5' } }), }) @@ -213,7 +213,7 @@ describe('init component tests script', () => { it('installs the right adapter for vue 3', async () => { createTempFiles({ - '/cypress.json': '{}', + '/cypress.config.ts': 'module.exports = {}', '/vite.config.js': 'module.exports = { }', '/package.json': JSON.stringify({ dependencies: { vue: '^3.0.0' } }), }) @@ -236,7 +236,7 @@ describe('init component tests script', () => { react: '^16.0.0', }, }), - '/cypress.json': '{}', + '/cypress.config.ts': 'module.exports = {}', }) promptSpy = sinon.stub(inquirer, 'prompt').returns(Promise.resolve({ @@ -253,9 +253,9 @@ describe('init component tests script', () => { ).to.be.true }) - it('suggests right docs example and cypress.json config based on the `componentFolder` answer', async () => { + it('suggests right docs example and cypress.config.ts config based on the `componentFolder` answer', async () => { createTempFiles({ - '/cypress.json': '{}', + '/cypress.config.ts': 'module.exports = {}', '/package.json': JSON.stringify({ dependencies: { react: '^16.0.0', @@ -270,9 +270,9 @@ describe('init component tests script', () => { await initComponentTesting({ config: {}, cypressConfigPath, useYarn: true }) - const injectedCode = fs.readFileSync(path.join(e2eTestOutputPath, 'cypress.json'), { encoding: 'utf-8' }) + const injectedCode = await require(path.join(e2eTestOutputPath, 'cypress.config.ts')) - expect(injectedCode).to.equal(JSON.stringify( + expect(injectedCode.default).to.equal(JSON.stringify( { componentFolder: 'cypress/component', testFiles: '**/*.spec.{js,ts,jsx,tsx}', @@ -284,7 +284,7 @@ describe('init component tests script', () => { it('Shows help message if cypress files are not created', async () => { createTempFiles({ - '/cypress.json': '{}', + '/cypress.config.ts': 'module.exports = {}', '/package.json': JSON.stringify({ dependencies: { react: '^16.0.0', @@ -310,7 +310,7 @@ describe('init component tests script', () => { it('Doesn\'t affect injected code if user has custom babel.config.js', async () => { createTempFiles({ '/cypress/plugins/index.js': 'module.exports = (on, config) => {}', - '/cypress.json': '{}', + '/cypress.config.ts': 'module.exports = {}', 'babel.config.js': `module.exports = ${JSON.stringify({ presets: [ '@babel/preset-env', diff --git a/npm/create-cypress-tests/src/installCypress.ts b/npm/create-cypress-tests/src/installCypress.ts index ffb2727b1c4a..524045de649d 100644 --- a/npm/create-cypress-tests/src/installCypress.ts +++ b/npm/create-cypress-tests/src/installCypress.ts @@ -15,7 +15,7 @@ type InstallCypressOpts = { async function copyFiles ({ ignoreExamples, useTypescript }: InstallCypressOpts) { let fileSpinner = ora('Creating config files').start() - await fs.outputFile(path.resolve(process.cwd(), 'cypress.json'), '{}\n') + await fs.outputFile(path.resolve(process.cwd(), useTypescript ? 'cypress.config.ts' : 'cypress.config.js'), `module.exports = {}\n`) await fs.copy( initialTemplate.getInitialPluginsFilePath(), path.resolve('cypress', 'plugins/index.js'), @@ -54,23 +54,24 @@ async function copyFiles ({ ignoreExamples, useTypescript }: InstallCypressOpts) } export async function findInstalledOrInstallCypress (options: InstallCypressOpts) { - let cypressJsonPath = await findUp('cypress.json') + const configFile = options.useTypescript ? 'cypress.config.ts' : 'cypress.config.js' + let cypressConfigPath = await findUp(configFile) - if (!cypressJsonPath) { + if (!cypressConfigPath) { await installDependency('cypress', options) await copyFiles(options) - cypressJsonPath = await findUp('cypress.json') + cypressConfigPath = await findUp(configFile) } - if (!cypressJsonPath) { + if (!cypressConfigPath) { throw new Error('Unexpected error during cypress installation.') } + const config = await import(cypressConfigPath) + return { - cypressConfigPath: cypressJsonPath, - config: JSON.parse( - fs.readFileSync(cypressJsonPath, { encoding: 'utf-8' }).toString(), - ) as Record, + cypressConfigPath, + config: config.default, } } diff --git a/npm/create-cypress-tests/src/main.test.ts b/npm/create-cypress-tests/src/main.test.ts index 0381b5ff55fd..44382821a725 100644 --- a/npm/create-cypress-tests/src/main.test.ts +++ b/npm/create-cypress-tests/src/main.test.ts @@ -150,7 +150,7 @@ describe('create-cypress-tests', () => { expect(await fsExtra.pathExists(path.resolve(e2eTestOutputPath, 'cypress', 'plugins', 'index.js'))).to.equal(true) expect(await fsExtra.pathExists(path.resolve(e2eTestOutputPath, 'cypress', 'support', 'index.js'))).to.equal(true) expect(await fsExtra.pathExists(path.resolve(e2eTestOutputPath, 'cypress', 'support', 'commands.js'))).to.equal(true) - expect(await fsExtra.pathExists(path.resolve(e2eTestOutputPath, 'cypress.json'))).to.equal(true) + expect(await fsExtra.pathExists(path.resolve(e2eTestOutputPath, 'cypress.config.ts'))).to.equal(true) }) it('Copies tsconfig if typescript is installed', async () => { From 9e03d46b06004ae7260e808fbbb5a358034efe8d Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 21 Oct 2021 20:26:25 -0500 Subject: [PATCH 05/57] Update cypress.json usage for config file --- circle.yml | 2 +- cli/test/lib/cypress_spec.js | 6 ++--- cli/test/lib/exec/open_spec.js | 4 +-- cli/test/lib/exec/run_spec.js | 4 +-- cli/types/cypress-npm-api.d.ts | 2 +- cli/types/cypress.d.ts | 8 +++--- npm/angular/README.md | 6 ++--- .../assets-image.component.cy-spec.ts | 4 +-- .../use-custom-element.component.cy-spec.ts | 2 +- .../visual-testing-with-happo/.happo.js | 4 +-- .../webpack-file/cypress/plugins/index.js | 2 +- npm/react/plugins/load-webpack/index.js | 2 +- .../desktop-gui/cypress/fixtures/config.json | 2 +- .../cypress/integration/error_message_spec.js | 4 +-- .../cypress/integration/settings_spec.js | 8 +++--- .../cypress/integration/setup_project_spec.js | 6 ++--- .../src/lib/config-file-formatted.jsx | 6 ++--- packages/desktop-gui/src/runs/runs-list.jsx | 2 +- .../integration/commands/files_spec.js | 2 +- .../integration/commands/net_stubbing_spec.ts | 2 +- .../driver/src/cypress/shadow_dom_utils.ts | 2 +- .../cypress/fixtures/config.json | 2 +- .../schemaTypes/objectTypes/gql-Project.ts | 2 +- .../component/support/attachFileWithPath.ts | 2 +- .../launchpad/src/global/GlobalPage.spec.tsx | 2 +- .../src/global/GlobalPageHeader.spec.tsx | 2 +- .../src/settings/project/ConfigCode.spec.tsx | 8 +++--- packages/server/lib/project-base.ts | 2 +- packages/server/lib/project_static.ts | 4 +-- packages/server/lib/project_utils.ts | 3 ++- packages/server/lib/server-base.ts | 2 +- packages/server/lib/util/settings.ts | 5 ++-- .../server/test/integration/cypress_spec.js | 10 +++---- .../test/integration/websockets_spec.js | 2 +- packages/server/test/unit/cache_spec.js | 1 + packages/server/test/unit/config_spec.js | 16 ++++++------ packages/server/test/unit/files_spec.js | 2 +- packages/server/test/unit/fixture_spec.js | 4 +-- .../server/test/unit/plugins/index_spec.js | 2 +- packages/server/test/unit/project_spec.js | 8 +++--- .../server/test/unit/project_utils_spec.ts | 16 ++++++------ packages/server/test/unit/scaffold_spec.js | 12 ++++----- packages/server/test/unit/screenshots_spec.js | 2 +- packages/server/test/unit/socket_spec.js | 2 +- packages/server/test/unit/specs_spec.js | 18 ++++++------- .../server/test/unit/util/settings_spec.js | 26 +++++++++---------- packages/types/src/server.ts | 2 +- system-tests/__snapshots__/config_spec.js | 4 +-- system-tests/__snapshots__/record_spec.js | 4 +-- system-tests/__snapshots__/visit_spec.js | 4 +-- .../__snapshots__/web_security_spec.js | 6 ++--- system-tests/test/plugins_spec.js | 2 +- 52 files changed, 129 insertions(+), 128 deletions(-) diff --git a/circle.yml b/circle.yml index c9fbe370f41d..b0afac78cdcc 100644 --- a/circle.yml +++ b/circle.yml @@ -1837,7 +1837,7 @@ jobs: environment: CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" command: | - echo '{}' > cypress.json + echo 'module.exports = {}' > cypress.config.js npx cypress run test-full-typescript-project: diff --git a/cli/test/lib/cypress_spec.js b/cli/test/lib/cypress_spec.js index 2edaa3b0e169..12694b5611e3 100644 --- a/cli/test/lib/cypress_spec.js +++ b/cli/test/lib/cypress_spec.js @@ -234,12 +234,12 @@ describe('cypress', function () { }) }) - it('coerces --config-file cypress.json to string', async () => { - const args = 'cypress run --config-file cypress.json'.split(' ') + it('coerces --config-file cypress.config.js to string', async () => { + const args = 'cypress run --config-file cypress.config.js'.split(' ') const options = await cypress.cli.parseRunArguments(args) expect(options).to.deep.equal({ - configFile: 'cypress.json', + configFile: 'cypress.config.js', }) }) diff --git a/cli/test/lib/exec/open_spec.js b/cli/test/lib/exec/open_spec.js index f9d3aa5878b5..fcb975f8dd9c 100644 --- a/cli/test/lib/exec/open_spec.js +++ b/cli/test/lib/exec/open_spec.js @@ -66,10 +66,10 @@ describe('exec open', function () { }) it('spawns with --config-file set', function () { - return open.start({ configFile: 'special-cypress.json' }) + return open.start({ configFile: 'special-cypress.config.js' }) .then(() => { expect(spawn.start).to.be.calledWith( - ['--config-file', 'special-cypress.json'], + ['--config-file', 'special-cypress.config.js'], ) }) }) diff --git a/cli/test/lib/exec/run_spec.js b/cli/test/lib/exec/run_spec.js index 2b932d5c8f3a..8e151f96238a 100644 --- a/cli/test/lib/exec/run_spec.js +++ b/cli/test/lib/exec/run_spec.js @@ -150,10 +150,10 @@ describe('exec run', function () { }) it('spawns with --config-file set', function () { - return run.start({ configFile: 'special-cypress.json' }) + return run.start({ configFile: 'special-cypress.config.js' }) .then(() => { expect(spawn.start).to.be.calledWith( - ['--run-project', process.cwd(), '--config-file', 'special-cypress.json'], + ['--run-project', process.cwd(), '--config-file', 'special-cypress.config.js'], ) }) }) diff --git a/cli/types/cypress-npm-api.d.ts b/cli/types/cypress-npm-api.d.ts index c60a34713812..c001524cb4f1 100644 --- a/cli/types/cypress-npm-api.d.ts +++ b/cli/types/cypress-npm-api.d.ts @@ -144,7 +144,7 @@ declare namespace CypressCommandLine { * * If `false` is passed, no config file will be used. * - * @default "cypress.json" + * @default "cypress.config.{ts|js}" */ configFile: string | false /** diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index 4e58c6e5c14a..4066838336ca 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -353,7 +353,7 @@ declare namespace Cypress { // no real way to type without generics /** - * Returns all environment variables set with CYPRESS_ prefix or in "env" object in "cypress.json" + * Returns all environment variables set with CYPRESS_ prefix or in "env" object in "cypress.config.{ts|js}" * * @see https://on.cypress.io/env */ @@ -362,7 +362,7 @@ declare namespace Cypress { * Returns specific environment variable or undefined * @see https://on.cypress.io/env * @example - * // cypress.json + * // cypress.config.js * { "env": { "foo": "bar" } } * Cypress.env("foo") // => bar */ @@ -2756,7 +2756,7 @@ declare namespace Cypress { retries: Nullable, openMode?: Nullable }> /** * Enables including elements within the shadow DOM when using querying - * commands (e.g. cy.get(), cy.find()). Can be set globally in cypress.json, + * commands (e.g. cy.get(), cy.find()). Can be set globally in cypress.config.{ts|js}, * per-suite or per-test in the test configuration object, or programmatically * with Cypress.config() * @default false @@ -2894,7 +2894,7 @@ declare namespace Cypress { interface PluginConfigOptions extends ResolvedConfigOptions { /** - * Absolute path to the config file (default: /cypress.json) or false + * Absolute path to the config file (default: /cypress.config.{ts|js}) or false */ configFile: string | false /** diff --git a/npm/angular/README.md b/npm/angular/README.md index 4455fcafaa7f..82358a40ca23 100644 --- a/npm/angular/README.md +++ b/npm/angular/README.md @@ -22,10 +22,10 @@ require('core-js/es7/reflect'); require('@cypress/angular/support'); ``` -Enable component testing in `cypress.json`. +Enable component testing in `cypress.config.js`. -```json -{ +```js +module.exports = { "component": { "componentFolder": "src/app", "testFiles": "**/*cy-spec.ts" diff --git a/npm/angular/src/app/assets-image/assets-image.component.cy-spec.ts b/npm/angular/src/app/assets-image/assets-image.component.cy-spec.ts index cfe6f9e672fa..9770b55586d2 100644 --- a/npm/angular/src/app/assets-image/assets-image.component.cy-spec.ts +++ b/npm/angular/src/app/assets-image/assets-image.component.cy-spec.ts @@ -7,7 +7,7 @@ describe('AssetsImageComponent', () => { it.skip('should create', () => { initEnv(AssetsImageComponent) mount(AssetsImageComponent) - // add "fileServerFolder": "src" in cypress.json + // add "fileServerFolder": "src" in cypress.config.{ts|js} cy.get('img#noSlash') .should('be.visible') .and(($img) => { @@ -29,7 +29,7 @@ describe('AssetsImageComponent', () => { it.skip('should create with AppModule', () => { initEnv({ imports: [AppModule] }) mount(AssetsImageComponent) - // add "fileServerFolder": "src" in cypress.json + // add "fileServerFolder": "src" in cypress.config.{ts|js} cy.get('img#noSlash') .should('be.visible') .and(($img) => { diff --git a/npm/angular/src/app/use-custom-element/use-custom-element.component.cy-spec.ts b/npm/angular/src/app/use-custom-element/use-custom-element.component.cy-spec.ts index de7528ea0b22..1046008f3210 100644 --- a/npm/angular/src/app/use-custom-element/use-custom-element.component.cy-spec.ts +++ b/npm/angular/src/app/use-custom-element/use-custom-element.component.cy-spec.ts @@ -1,7 +1,7 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' import { initEnv, mount } from '@cypress/angular' // You have to import your custom element -// And in cypress.json activate "includeShadowDom" configuration +// And in cypress.config.{ts|js} activate "includeShadowDom" configuration import '../my-custom-element' import { UseCustomElementComponent } from './use-custom-element.component' diff --git a/npm/react/examples/visual-testing-with-happo/.happo.js b/npm/react/examples/visual-testing-with-happo/.happo.js index 60e799c22bfc..a05a232d5ba8 100644 --- a/npm/react/examples/visual-testing-with-happo/.happo.js +++ b/npm/react/examples/visual-testing-with-happo/.happo.js @@ -1,8 +1,8 @@ // https://docs.happo.io/docs/cypress const { RemoteBrowserTarget } = require('happo.io') -// use the same resolution as cypress.json -const cypressConfig = require('./cypress.json') +// use the same resolution as cypress.config.js +const cypressConfig = require('./cypress.config.js') const width = cypressConfig.viewportWidth || 1000 const height = cypressConfig.viewportHeight || 660 const viewport = `${width}x${height}` diff --git a/npm/react/examples/webpack-file/cypress/plugins/index.js b/npm/react/examples/webpack-file/cypress/plugins/index.js index 84c951a31093..8f0558a51d7c 100644 --- a/npm/react/examples/webpack-file/cypress/plugins/index.js +++ b/npm/react/examples/webpack-file/cypress/plugins/index.js @@ -5,7 +5,7 @@ */ module.exports = (on, config) => { require('@cypress/react/plugins/load-webpack')(on, config, { - // from the root of the project (folder with cypress.json file) + // from the root of the project (folder with cypress.config.js file) webpackFilename: 'webpack.config.js', }) diff --git a/npm/react/plugins/load-webpack/index.js b/npm/react/plugins/load-webpack/index.js index bed7f22d470c..e14acd8a8482 100644 --- a/npm/react/plugins/load-webpack/index.js +++ b/npm/react/plugins/load-webpack/index.js @@ -12,7 +12,7 @@ function normalizeWebpackPath (config, webpackConfigPath) { /** * Injects dev-server based on the webpack config file. * - * **Important:** `webpackFilename` path is relative to the project root (cypress.json location) + * **Important:** `webpackFilename` path is relative to the project root (cypress.config.js location) * @type {(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions, options: { webpackFilename: string }) => Cypress.PluginConfigOptions} */ function devServer (cypressDevServerConfig, { webpackFilename, indexHtml }) { diff --git a/packages/desktop-gui/cypress/fixtures/config.json b/packages/desktop-gui/cypress/fixtures/config.json index 91fe1742a429..5c63a3c9a182 100644 --- a/packages/desktop-gui/cypress/fixtures/config.json +++ b/packages/desktop-gui/cypress/fixtures/config.json @@ -147,7 +147,7 @@ "requestTimeout": 5000, "resolvedNodePath": null, "resolvedNodeVersion": "1.2.3", - "configFile": "cypress.json", + "configFile": "cypress.config.js", "hosts": { "*.foobar.com": "127.0.0.1" }, diff --git a/packages/desktop-gui/cypress/integration/error_message_spec.js b/packages/desktop-gui/cypress/integration/error_message_spec.js index f0a21e48030d..f576458591b6 100644 --- a/packages/desktop-gui/cypress/integration/error_message_spec.js +++ b/packages/desktop-gui/cypress/integration/error_message_spec.js @@ -57,12 +57,12 @@ describe('Error Message', function () { }) it('displays error message with html escaped', function () { - this.err.message = 'Error reading from: /Users/cypress.json

SyntaxError' + this.err.message = 'Error reading from: /Users/cypress.config.js

SyntaxError' this.ipc.openProject.rejects(this.err) this.start() cy.get('.error') - .should('contain', 'Error reading from: /Users/cypress.json') + .should('contain', 'Error reading from: /Users/cypress.config.js') .should('not.contain', ' { openConfiguration() }) - it('notes that cypress.json is disabled', () => { - cy.contains('set from cypress.json file (currently disabled by --config-file false)') + it('notes that cypress.config.js is disabled', () => { + cy.contains('set from cypress.config.js file (currently disabled by --config-file false)') }) }) context('when configFile is set', function () { beforeEach(function () { this.openProject.resolve(Cypress._.assign(this.config, { - configFile: 'special-cypress.json', + configFile: 'special-cypress.config.js', })) this.goToSettings() @@ -352,7 +352,7 @@ describe('Settings', () => { }) it('notes that a custom config is in use', () => { - cy.contains('set from custom config file special-cypress.json') + cy.contains('set from custom config file special-cypress.config.js') }) }) }) diff --git a/packages/desktop-gui/cypress/integration/setup_project_spec.js b/packages/desktop-gui/cypress/integration/setup_project_spec.js index debe728add18..ddb558a288fb 100644 --- a/packages/desktop-gui/cypress/integration/setup_project_spec.js +++ b/packages/desktop-gui/cypress/integration/setup_project_spec.js @@ -8,7 +8,7 @@ const onSubmitNewProject = function (orgId) { projectName: this.config.projectName, orgId, public: false, - configFile: 'cypress.json', + configFile: 'cypress.config.js', }) }) }) @@ -26,7 +26,7 @@ const onSubmitNewProject = function (orgId) { projectRoot: '/foo/bar', orgId, public: true, - configFile: 'cypress.json', + configFile: 'cypress.config.js', }) }) }) @@ -492,7 +492,7 @@ describe('Connect to Dashboard', function () { expect(this.ipc.setProjectId).to.be.calledWith({ id: this.dashboardProjects[1].id, projectRoot: '/foo/bar', - configFile: 'cypress.json' }) + configFile: 'cypress.config.js' }) }) }) diff --git a/packages/desktop-gui/src/lib/config-file-formatted.jsx b/packages/desktop-gui/src/lib/config-file-formatted.jsx index d8d57092aa04..86e84ca9a473 100644 --- a/packages/desktop-gui/src/lib/config-file-formatted.jsx +++ b/packages/desktop-gui/src/lib/config-file-formatted.jsx @@ -3,14 +3,14 @@ import { isUndefined } from 'lodash' const configFileFormatted = (configFile) => { if (configFile === false) { - return <>cypress.json file (currently disabled by --config-file false) + return <>cypress.config.js file (currently disabled by --config-file false) } if (isUndefined(configFile)) { - return <>cypress.json file + return <>cypress.config.js file } - if (['cypress.json', 'cypress.config.js'].includes(configFile)) { + if (['cypress.config.ts', 'cypress.config.js'].includes(configFile)) { return <>{configFile} file } diff --git a/packages/desktop-gui/src/runs/runs-list.jsx b/packages/desktop-gui/src/runs/runs-list.jsx index 35b887a72102..c59c5a1e8b5c 100644 --- a/packages/desktop-gui/src/runs/runs-list.jsx +++ b/packages/desktop-gui/src/runs/runs-list.jsx @@ -161,7 +161,7 @@ class RunsList extends Component { // OR if there is an error getting the runs if (this.runsStore.error) { - // project id missing, probably removed manually from cypress.json + // project id missing, probably removed manually from cypress.config.{ts|js} if (errors.isMissingProjectId(this.runsStore.error)) { return this._projectNotSetup() diff --git a/packages/driver/cypress/integration/commands/files_spec.js b/packages/driver/cypress/integration/commands/files_spec.js index 8050db9b1b9f..181bd57c98ba 100644 --- a/packages/driver/cypress/integration/commands/files_spec.js +++ b/packages/driver/cypress/integration/commands/files_spec.js @@ -90,7 +90,7 @@ describe('src/cy/commands/files', () => { }) it('really works', () => { - cy.readFile('cypress.json').its('baseUrl').should('eq', 'http://localhost:3500') + cy.readFile('cypress.config.ts').its('baseUrl').should('eq', 'http://localhost:3500') }) it('works when contents are supposed to be null', () => { diff --git a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts index de7df1a9eeab..bd706723fed9 100644 --- a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts +++ b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts @@ -968,7 +968,7 @@ describe('network stubbing', function () { context('cors preflight', function () { // a different domain from the page own domain // NOTE: this domain is redirected back to the local host test server - // using "hosts" setting in the "cypress.json" file + // using "hosts" setting in the "cypress.config.ts" file const corsUrl = 'http://diff.foobar.com:3501/no-cors' before(() => { diff --git a/packages/driver/src/cypress/shadow_dom_utils.ts b/packages/driver/src/cypress/shadow_dom_utils.ts index 06790502eef2..473b5f12cb00 100644 --- a/packages/driver/src/cypress/shadow_dom_utils.ts +++ b/packages/driver/src/cypress/shadow_dom_utils.ts @@ -1,6 +1,6 @@ /** * Order of preference for including shadow dom: -* command-level > programmatic config > test-level > suite-level > cypress.json +* command-level > programmatic config > test-level > suite-level > cypress.config.{ts|js} */ export const resolveShadowDomInclusion = (Cypress: Cypress.Cypress, commandValue?: boolean): boolean => { if (commandValue != null) return commandValue diff --git a/packages/frontend-shared/cypress/fixtures/config.json b/packages/frontend-shared/cypress/fixtures/config.json index 91fe1742a429..5c63a3c9a182 100644 --- a/packages/frontend-shared/cypress/fixtures/config.json +++ b/packages/frontend-shared/cypress/fixtures/config.json @@ -147,7 +147,7 @@ "requestTimeout": 5000, "resolvedNodePath": null, "resolvedNodeVersion": "1.2.3", - "configFile": "cypress.json", + "configFile": "cypress.config.js", "hosts": { "*.foobar.com": "127.0.0.1" }, diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts index aa895c54a6c1..654ee875611b 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Project.ts @@ -29,7 +29,7 @@ const GeneratedSpec = objectType({ export const Project = objectType({ name: 'Project', - description: 'A Cypress Project is represented by a cypress.json file', + description: 'A Cypress Project is represented by a cypress.config.{ts|js} file', node: 'projectRoot', definition (t) { t.field('cloudProject', { diff --git a/packages/launchpad/cypress/component/support/attachFileWithPath.ts b/packages/launchpad/cypress/component/support/attachFileWithPath.ts index d74b11bfce07..96480817f489 100644 --- a/packages/launchpad/cypress/component/support/attachFileWithPath.ts +++ b/packages/launchpad/cypress/component/support/attachFileWithPath.ts @@ -7,7 +7,7 @@ declare global { } export function attachedFileWithPath (subject: HTMLInputElement, path: string) { - const attachedFile = new File([new Blob()], 'cypress.json') + const attachedFile = new File([new Blob()], 'cypress.config.ts') Object.defineProperty(attachedFile, 'path', { value: path }) diff --git a/packages/launchpad/src/global/GlobalPage.spec.tsx b/packages/launchpad/src/global/GlobalPage.spec.tsx index 45989aa0654e..37ba341240e1 100644 --- a/packages/launchpad/src/global/GlobalPage.spec.tsx +++ b/packages/launchpad/src/global/GlobalPage.spec.tsx @@ -48,7 +48,7 @@ describe('', { viewportHeight: 900, viewportWidth: 1200 }, () => { it('can add a project when clicking the button', () => { cy.contains('button', defaultMessages.globalPage.addProjectButton).click() cy.get('input[type=file]') - .attachFileWithPath('absolute/path/to/yet-another-test-project/cypress.json') + .attachFileWithPath('absolute/path/to/yet-another-test-project/cypress.config.ts') .trigger('change', { force: true }) // .findByText('yet-another-test-project').should('be.visible') }) diff --git a/packages/launchpad/src/global/GlobalPageHeader.spec.tsx b/packages/launchpad/src/global/GlobalPageHeader.spec.tsx index 4e527bdd1085..acde8620f1bc 100644 --- a/packages/launchpad/src/global/GlobalPageHeader.spec.tsx +++ b/packages/launchpad/src/global/GlobalPageHeader.spec.tsx @@ -44,7 +44,7 @@ describe('', () => { it('handles a file upload', () => { cy.get(fileInputSelector) - .attachFile('test-project/cypress.json') + .attachFile('test-project/cypress.config.ts') .get(addProjectSelector) .click() .get('@fileUpload').should('have.been.called') diff --git a/packages/launchpad/src/settings/project/ConfigCode.spec.tsx b/packages/launchpad/src/settings/project/ConfigCode.spec.tsx index b394867939d1..b6603b9e46ea 100644 --- a/packages/launchpad/src/settings/project/ConfigCode.spec.tsx +++ b/packages/launchpad/src/settings/project/ConfigCode.spec.tsx @@ -1,9 +1,9 @@ import ConfigCode from './ConfigCode.vue' -import jsonObject from '../../../cypress.json' +import config from '../../../cypress.config' import { defaultMessages } from '@cy/i18n' const selector = '[data-testid=code]' -const jsonString = JSON.stringify(jsonObject, null, 2) +const configString = JSON.stringify(config, null, 2) describe('', () => { beforeEach(() => { @@ -16,12 +16,12 @@ describe('', () => { */ } { /* @ts-ignore */ } - + )) }) it('renders the code passed in', () => { - cy.get(selector).should('contain.text', jsonString) + cy.get(selector).should('contain.text', configString) }) // This needs to be skipped because it cannot be tested unless "Emulate a focused page" is checked. diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index 6a5a4cc73943..daa44850ee37 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -756,7 +756,7 @@ export class ProjectBase extends EE { return this._cfg } - // returns project config (user settings + defaults + cypress.json) + // returns project config (user settings + defaults + cypress.config.{ts|js}) // with additional object "state" which are transient things like // window width and height, DevTools open or not, etc. getConfig (): Cfg { diff --git a/packages/server/lib/project_static.ts b/packages/server/lib/project_static.ts index b216451b2662..0d0653818a93 100644 --- a/packages/server/lib/project_static.ts +++ b/packages/server/lib/project_static.ts @@ -26,7 +26,7 @@ export function paths () { export async function getPathsAndIds () { const projectRoots: string[] = await cache.getProjectRoots() - // this assumes that the configFile for a cached project is 'cypress.json' + // this assumes that the configFile for a cached project is 'cypress.config.{ts|js}' // https://git.io/JeGyF return Promise.all(projectRoots.map(async (projectRoot) => { return { @@ -137,7 +137,7 @@ export function remove (path) { export async function add (path, options) { // don't cache a project if a non-default configFile is set // https://git.io/JeGyF - if (settings.configFile(options) !== 'cypress.json') { + if (settings.configFile(options) !== 'cypress.config.js' && settings.configFile(options) !== 'cypress.config.ts') { return Promise.resolve({ path }) } diff --git a/packages/server/lib/project_utils.ts b/packages/server/lib/project_utils.ts index 1b51b642e29e..f72c08de6e4a 100644 --- a/packages/server/lib/project_utils.ts +++ b/packages/server/lib/project_utils.ts @@ -148,8 +148,9 @@ export async function getDefaultConfigFilePath (projectRoot: string, returnDefau throw errors.throw('CONFIG_FILES_LANGUAGE_CONFLICT', projectRoot, ...foundConfigFiles) } + // TODO: Should we check if there's a tsConfig to create the correct file? if (returnDefaultValueIfNotFound) { - // Default is to create a new `cypress.json` file if one does not exist. + // Default is to create a new `cypress.config.ts` file if one does not exist. return CYPRESS_CONFIG_FILES[0] } diff --git a/packages/server/lib/server-base.ts b/packages/server/lib/server-base.ts index 80a0d5f5d4a3..c0ee87d15f52 100644 --- a/packages/server/lib/server-base.ts +++ b/packages/server/lib/server-base.ts @@ -241,7 +241,7 @@ export abstract class ServerBase { const { morgan, clientRoute } = config const app = express() - // set the cypress config from the cypress.json file + // set the cypress config from the cypress.config.{ts|js} file app.set('view engine', 'html') // since we use absolute paths, configure express-handlebars to not automatically find layouts diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index 41066cb24e38..3274753e0a83 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -122,10 +122,9 @@ export function configFile (options: SettingsOptions = {}) { return options.configFile === false ? false : options.configFile } +// TODO: Should we get it from the cache (?) export function id (projectRoot, options = {}) { - const file = pathToConfigFile(projectRoot, options) - - return fs.readJson(file) + return read(projectRoot, options) .then((config) => config.projectId) .catch(() => { return null diff --git a/packages/server/test/integration/cypress_spec.js b/packages/server/test/integration/cypress_spec.js index 7a4d14fff8e6..0fa9fb165fc4 100644 --- a/packages/server/test/integration/cypress_spec.js +++ b/packages/server/test/integration/cypress_spec.js @@ -457,7 +457,7 @@ describe('lib/cypress', () => { }) it('scaffolds out integration and example specs if they do not exist when not runMode', function () { - return config.get(this.pristinePath) + return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) .then((cfg) => { return fs.statAsync(cfg.integrationFolder) .then(() => { @@ -520,7 +520,7 @@ describe('lib/cypress', () => { }) it('scaffolds out fixtures + files if they do not exist', function () { - return config.get(this.pristinePath) + return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) .then((cfg) => { return fs.statAsync(cfg.fixturesFolder) .then(() => { @@ -538,7 +538,7 @@ describe('lib/cypress', () => { it('scaffolds out support + files if they do not exist', function () { const supportFolder = path.join(this.pristinePath, 'cypress/support') - return config.get(this.pristinePath) + return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) .then(() => { return fs.statAsync(supportFolder) .then(() => { @@ -556,7 +556,7 @@ describe('lib/cypress', () => { }) it('removes fixtures when they exist and fixturesFolder is false', function (done) { - config.get(this.idsPath) + config.get(this.idsPath, { configFile: 'cypress.config.js' }) .then((cfg) => { this.cfg = cfg @@ -614,7 +614,7 @@ describe('lib/cypress', () => { it('can change the reporter with cypress.json', function () { sinon.spy(Reporter, 'create') - return config.get(this.idsPath) + return config.get(this.idsPath, { configFile: 'cypress.config.js' }) .then((cfg) => { this.cfg = cfg diff --git a/packages/server/test/integration/websockets_spec.js b/packages/server/test/integration/websockets_spec.js index 51dcef5381db..774883f5533c 100644 --- a/packages/server/test/integration/websockets_spec.js +++ b/packages/server/test/integration/websockets_spec.js @@ -28,7 +28,7 @@ describe('Web Sockets', () => { this.idsPath = Fixtures.projectPath('ids') - return config.get(this.idsPath, { port: cyPort }) + return config.get(this.idsPath, { port: cyPort, configFile: 'cypress.config.js' }) .then((cfg) => { this.cfg = cfg this.ws = new ws.Server({ port: wsPort }) diff --git a/packages/server/test/unit/cache_spec.js b/packages/server/test/unit/cache_spec.js index 96d81c24e9ce..0dd80d5e1625 100644 --- a/packages/server/test/unit/cache_spec.js +++ b/packages/server/test/unit/cache_spec.js @@ -255,6 +255,7 @@ describe('lib/cache', () => { }, PROJECTS: ['foo'], PROJECT_PREFERENCES: {}, + PROJECTS_CONFIG: {}, }) }) }) diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index 8a712138ffd8..b751a98c747d 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -65,7 +65,7 @@ describe('lib/config', () => { it('sets projectRoot', function () { this.setup({}, { foo: 'bar' }) - return config.get(this.projectRoot) + return config.get(this.projectRoot, { configFile: 'cypress.config.js' }) .then((obj) => { expect(obj.projectRoot).to.eq(this.projectRoot) @@ -76,7 +76,7 @@ describe('lib/config', () => { it('sets projectName', function () { this.setup({}, { foo: 'bar' }) - return config.get(this.projectRoot) + return config.get(this.projectRoot, { configFile: 'cypress.config.js' }) .then((obj) => { expect(obj.projectName).to.eq('project') }) @@ -88,7 +88,7 @@ describe('lib/config', () => { this.setup(settings, envSettings) - return config.get(this.projectRoot) + return config.get(this.projectRoot, { configFile: 'cypress.config.js' }) .then(() => { expect(settings).to.deep.equal({ foo: 'bar' }) expect(envSettings).to.deep.equal({ baz: 'qux' }) @@ -101,21 +101,21 @@ describe('lib/config', () => { }) it('can override default port', function () { - return config.get(this.projectRoot, { port: 8080 }) + return config.get(this.projectRoot, { port: 8080, configFile: 'cypress.config.js' }) .then((obj) => { expect(obj.port).to.eq(8080) }) }) it('updates browserUrl', function () { - return config.get(this.projectRoot, { port: 8080 }) + return config.get(this.projectRoot, { port: 8080, configFile: 'cypress.config.js' }) .then((obj) => { expect(obj.browserUrl).to.eq('http://localhost:8080/__/') }) }) it('updates proxyUrl', function () { - return config.get(this.projectRoot, { port: 8080 }) + return config.get(this.projectRoot, { port: 8080, configFile: 'cypress.config.js' }) .then((obj) => { expect(obj.proxyUrl).to.eq('http://localhost:8080') }) @@ -125,11 +125,11 @@ describe('lib/config', () => { context('validation', () => { beforeEach(function () { this.expectValidationPasses = () => { - return config.get(this.projectRoot) // shouldn't throw + return config.get(this.projectRoot, { configFile: 'cypress.config.js' }) // shouldn't throw } this.expectValidationFails = (errorMessage = 'validation error') => { - return config.get(this.projectRoot) + return config.get(this.projectRoot, { configFile: 'cypress.config.js' }) .then(() => { throw new Error('should throw validation error') }).catch((err) => { diff --git a/packages/server/test/unit/files_spec.js b/packages/server/test/unit/files_spec.js index 7361badf75c8..f42d3e87cbc3 100644 --- a/packages/server/test/unit/files_spec.js +++ b/packages/server/test/unit/files_spec.js @@ -10,7 +10,7 @@ describe('lib/files', () => { this.todosPath = FixturesHelper.projectPath('todos') - return config.get(this.todosPath).then((cfg) => { + return config.get(this.todosPath, { configFile: 'cypress.config.js' }).then((cfg) => { this.config = cfg; ({ projectRoot: this.projectRoot } = cfg) }) diff --git a/packages/server/test/unit/fixture_spec.js b/packages/server/test/unit/fixture_spec.js index 9046a19f395c..4564d54dd009 100644 --- a/packages/server/test/unit/fixture_spec.js +++ b/packages/server/test/unit/fixture_spec.js @@ -19,7 +19,7 @@ describe('lib/fixture', () => { this.todosPath = FixturesHelper.projectPath('todos') - return config.get(this.todosPath).then((cfg) => { + return config.get(this.todosPath, { configFile: 'cypress.config.js' }).then((cfg) => { ({ fixturesFolder: this.fixturesFolder } = cfg) }) }) @@ -169,7 +169,7 @@ Expecting 'EOF', '}', ':', ',', ']', got 'STRING'\ it('can load a fixture with no extension when a same-named folder also exists', () => { const projectPath = FixturesHelper.projectPath('folder-same-as-fixture') - return config.get(projectPath) + return config.get(projectPath, { configFile: 'cypress.config.js' }) .then((cfg) => { return fixture.get(cfg.fixturesFolder, 'foo') .then((fixture) => { diff --git a/packages/server/test/unit/plugins/index_spec.js b/packages/server/test/unit/plugins/index_spec.js index e76df148fb9f..6d5099326389 100644 --- a/packages/server/test/unit/plugins/index_spec.js +++ b/packages/server/test/unit/plugins/index_spec.js @@ -20,7 +20,7 @@ describe('lib/plugins/index', () => { configExtras = { projectRoot: '/path/to/project/root', - configFile: '/path/to/project/root/cypress.json', + configFile: '/path/to/project/root/cypress.config.js', } getOptions = (overrides = {}) => { diff --git a/packages/server/test/unit/project_spec.js b/packages/server/test/unit/project_spec.js index 2387cd11115e..3d6386e3133e 100644 --- a/packages/server/test/unit/project_spec.js +++ b/packages/server/test/unit/project_spec.js @@ -53,7 +53,7 @@ describe('lib/project-base', () => { sinon.stub(runEvents, 'execute').resolves() - return settings.read(this.todosPath).then((obj = {}) => { + return settings.read(this.todosPath, { configFile: 'cypress.config.js' }).then((obj = {}) => { ({ projectId: this.projectId } = obj) return config.set({ projectName: 'project', projectRoot: '/foo/bar' }) @@ -149,7 +149,7 @@ describe('lib/project-base', () => { const integrationFolder = 'foo/bar/baz' beforeEach(function () { - sinon.stub(config, 'get').withArgs(this.todosPath, { foo: 'bar', configFile: 'cypress.json' }) + sinon.stub(config, 'get').withArgs(this.todosPath, { foo: 'bar', configFile: 'cypress.config.js' }) .resolves({ baz: 'quux', integrationFolder, browsers: [] }) }) @@ -968,7 +968,7 @@ This option will not have an effect in Some-other-name. Tests that rely on web s }) it('inserts path into cache', function () { - return add(this.pristinePath, {}) + return add(this.pristinePath, { configFile: 'cypress.config.js' }) .then(() => cache.read()).then((json) => { expect(json.PROJECTS).to.deep.eq([this.pristinePath]) }) @@ -991,7 +991,7 @@ This option will not have an effect in Some-other-name. Tests that rely on web s it('returns object containing just the path', function () { sinon.stub(settings, 'read').rejects() - return add(this.pristinePath, {}) + return add(this.pristinePath, { configFile: 'cypress.config.js' }) .then((project) => { expect(project.id).to.be.undefined diff --git a/packages/server/test/unit/project_utils_spec.ts b/packages/server/test/unit/project_utils_spec.ts index c8c1acedd5a7..c5494fbecfcc 100644 --- a/packages/server/test/unit/project_utils_spec.ts +++ b/packages/server/test/unit/project_utils_spec.ts @@ -101,7 +101,7 @@ describe('lib/project_utils', () => { describe('checkSupportFile', () => { it('does nothing when {supportFile: false}', async () => { const ret = await checkSupportFile({ - configFile: 'cypress.json', + configFile: 'cypress.config.ts', supportFile: false, }) @@ -111,7 +111,7 @@ describe('lib/project_utils', () => { it('throws when support file does not exist', async () => { try { await checkSupportFile({ - configFile: 'cypress.json', + configFile: 'cypress.config.ts', supportFile: '/this/file/does/not/exist/foo/bar/cypress/support/index.js', }) } catch (e) { @@ -132,11 +132,11 @@ describe('lib/project_utils', () => { readdirStub.restore() }) - it('finds cypress.json when present', async () => { - readdirStub.withArgs(projectRoot).resolves(['cypress.json']) + it('finds cypress.config.ts when present', async () => { + readdirStub.withArgs(projectRoot).resolves(['cypress.config.ts']) const ret = await getDefaultConfigFilePath(projectRoot) - expect(ret).to.equal('cypress.json') + expect(ret).to.equal('cypress.config.ts') }) it('defaults to cypress.config.js when present', async () => { @@ -146,15 +146,15 @@ describe('lib/project_utils', () => { expect(ret).to.equal('cypress.config.js') }) - it('defaults to cypress.json when no file is returned', async () => { + it('defaults to cypress.config.js when no file is returned', async () => { readdirStub.withArgs(projectRoot).resolves([]) const ret = await getDefaultConfigFilePath(projectRoot) - expect(ret).to.equal('cypress.json') + expect(ret).to.equal('cypress.config.js') }) it('errors if two default files are present', async () => { - readdirStub.withArgs(projectRoot).resolves(['cypress.config.js', 'cypress.json']) + readdirStub.withArgs(projectRoot).resolves(['cypress.config.js', 'cypress.config.ts']) try { await getDefaultConfigFilePath(projectRoot) throw Error('should have failed') diff --git a/packages/server/test/unit/scaffold_spec.js b/packages/server/test/unit/scaffold_spec.js index 8001b3f3ca59..fbc18f1e18eb 100644 --- a/packages/server/test/unit/scaffold_spec.js +++ b/packages/server/test/unit/scaffold_spec.js @@ -131,7 +131,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const pristinePath = Fixtures.projectPath('pristine') - return config.get(pristinePath).then((cfg) => { + return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg; ({ integrationFolder: this.integrationFolder } = this.cfg) }) @@ -214,7 +214,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const pristinePath = Fixtures.projectPath('pristine') - return config.get(pristinePath).then((cfg) => { + return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg; ({ integrationFolder: this.integrationFolder } = this.cfg) }) @@ -325,7 +325,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const pristinePath = Fixtures.projectPath('pristine') - return config.get(pristinePath).then((cfg) => { + return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg; ({ supportFolder: this.supportFolder } = this.cfg) }) @@ -402,7 +402,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const pristinePath = Fixtures.projectPath('pristine') - return config.get(pristinePath).then((cfg) => { + return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg; ({ pluginsFile: this.pluginsFile } = this.cfg) this.pluginsFolder = path.dirname(this.pluginsFile) @@ -458,7 +458,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const pristinePath = Fixtures.projectPath('pristine') - return config.get(pristinePath).then((cfg) => { + return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg; ({ fixturesFolder: this.fixturesFolder } = this.cfg) }) @@ -533,7 +533,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const todosPath = Fixtures.projectPath('todos') - return config.get(todosPath).then((cfg) => { + return config.get(todosPath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg this.cfg.pluginsFile = path.join(this.cfg.projectRoot, 'cypress/plugins/index.js') }) diff --git a/packages/server/test/unit/screenshots_spec.js b/packages/server/test/unit/screenshots_spec.js index 2cebcfeefa45..19805d3ec2dd 100644 --- a/packages/server/test/unit/screenshots_spec.js +++ b/packages/server/test/unit/screenshots_spec.js @@ -56,7 +56,7 @@ describe('lib/screenshots', () => { Jimp.prototype.composite = sinon.stub() // Jimp.prototype.getBuffer = sinon.stub().resolves(@buffer) - return config.get(this.todosPath).then((config1) => { + return config.get(this.todosPath, { configFile: 'cypress.config.js' }).then((config1) => { this.config = config1 }) }) diff --git a/packages/server/test/unit/socket_spec.js b/packages/server/test/unit/socket_spec.js index cc055b97ca5a..e7a5afeac397 100644 --- a/packages/server/test/unit/socket_spec.js +++ b/packages/server/test/unit/socket_spec.js @@ -26,7 +26,7 @@ describe('lib/socket', () => { this.todosPath = Fixtures.projectPath('todos') this.server = new ServerE2E(this.todosPath) - return config.get(this.todosPath) + return config.get(this.todosPath, { configFile: 'cypress.config.js' }) .then((cfg) => { this.cfg = cfg }) diff --git a/packages/server/test/unit/specs_spec.js b/packages/server/test/unit/specs_spec.js index 2f72cfb4aaf9..634e23872927 100644 --- a/packages/server/test/unit/specs_spec.js +++ b/packages/server/test/unit/specs_spec.js @@ -13,7 +13,7 @@ describe('lib/util/specs', () => { this.todosPath = FixturesHelper.projectPath('todos') - return config.get(this.todosPath) + return config.get(this.todosPath, { configFile: 'cypress.config.js' }) .then((cfg) => { this.config = cfg }) @@ -47,7 +47,7 @@ describe('lib/util/specs', () => { }) it('by default, returns all files as long as they have a name and extension', () => { - return config.get(FixturesHelper.projectPath('various-file-types')) + return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) .then((cfg) => { return specsUtil.findSpecs(cfg) }).then((files) => { @@ -60,7 +60,7 @@ describe('lib/util/specs', () => { }) it('finds integration and component tests and assigns correct specType', () => { - return config.get(FixturesHelper.projectPath('component-tests')) + return config.get(FixturesHelper.projectPath('component-tests'), { configFile: 'cypress.config.js' }) .then((cfg) => { cfg.resolved.testingType = { value: 'component' } @@ -85,7 +85,7 @@ describe('lib/util/specs', () => { }) it('returns files matching config.testFiles', () => { - return config.get(FixturesHelper.projectPath('various-file-types')) + return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) .then((cfg) => { cfg.testFiles = '**/*.coffee' @@ -98,7 +98,7 @@ describe('lib/util/specs', () => { }) it('uses glob to process config.testFiles', () => { - return config.get(FixturesHelper.projectPath('various-file-types')) + return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) .then((cfg) => { cfg.testFiles = '{coffee_*.coffee,js_spec.js}' @@ -113,7 +113,7 @@ describe('lib/util/specs', () => { }) it('allows array in config.testFiles', () => { - return config.get(FixturesHelper.projectPath('various-file-types')) + return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) .then((cfg) => { cfg.testFiles = ['coffee_*.coffee', 'js_spec.js'] @@ -128,7 +128,7 @@ describe('lib/util/specs', () => { }) it('filters using specPattern', () => { - return config.get(FixturesHelper.projectPath('various-file-types')) + return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) .then((cfg) => { const specPattern = [ path.join(cfg.projectRoot, 'cypress', 'integration', 'js_spec.js'), @@ -143,7 +143,7 @@ describe('lib/util/specs', () => { }) it('filters using specPattern as array of glob patterns', () => { - return config.get(FixturesHelper.projectPath('various-file-types')) + return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) .then((cfg) => { debug('test config testFiles is %o', cfg.testFiles) const specPattern = [ @@ -161,7 +161,7 @@ describe('lib/util/specs', () => { }) it('properly handles directories with names including \'.\'', () => { - return config.get(FixturesHelper.projectPath('odd-directory-name')) + return config.get(FixturesHelper.projectPath('odd-directory-name'), { configFile: 'cypress.config.js' }) .then((cfg) => { return specsUtil.findSpecs(cfg) }).then((files) => { diff --git a/packages/server/test/unit/util/settings_spec.js b/packages/server/test/unit/util/settings_spec.js index a7c4f2c2aaeb..06b490214990 100644 --- a/packages/server/test/unit/util/settings_spec.js +++ b/packages/server/test/unit/util/settings_spec.js @@ -6,19 +6,19 @@ const settings = require(`../../../lib/util/settings`) const projectRoot = process.cwd() const defaultOptions = { - configFile: 'cypress.json', + configFile: 'cypress.config.js', } describe('lib/util/settings', () => { context('with default configFile option', () => { beforeEach(function () { this.setup = (obj = {}) => { - return fs.writeJsonAsync('cypress.json', obj) + return fs.writeFileAsync('cypress.config.js', `module.exports = ${JSON.stringify(obj)}`) } }) afterEach(() => { - return fs.removeAsync('cypress.json') + return fs.removeAsync('cypress.config.js') }) context('nested cypress object', () => { @@ -29,7 +29,7 @@ describe('lib/util/settings', () => { }).then((obj) => { expect(obj).to.deep.eq({ foo: 'bar' }) - return fs.readJsonAsync('cypress.json') + return require(path.join(projectRoot, 'cypress.config.js')) }).then((obj) => { expect(obj).to.deep.eq({ foo: 'bar' }) }) @@ -84,13 +84,13 @@ describe('lib/util/settings', () => { }) afterEach(function () { - return fs.removeAsync(`${this.projectRoot}cypress.json`) + return fs.removeAsync(`${this.projectRoot}cypress.config.js`) }) it('returns project id for project', function () { - return fs.writeJsonAsync(`${this.projectRoot}cypress.json`, { + return fs.writeFileAsync(`${this.projectRoot}cypress.config.js`, `module.exports = { projectId: 'id-123', - }) + }`) .then(() => { return settings.id(this.projectRoot, defaultOptions) }).then((id) => { @@ -100,7 +100,7 @@ describe('lib/util/settings', () => { }) context('.read', () => { - it('promises cypress.json', function () { + it('promises cypress.config.js', function () { return this.setup({ foo: 'bar' }) .then(() => { return settings.read(projectRoot, defaultOptions) @@ -109,7 +109,7 @@ describe('lib/util/settings', () => { }) }) - it('promises cypress.json and merges CT specific properties for via testingType: component', function () { + it('promises cypress.config.js and merges CT specific properties for via testingType: component', function () { return this.setup({ a: 'b', component: { a: 'c' } }) .then(() => { return settings.read(projectRoot, { ...defaultOptions, testingType: 'component' }) @@ -118,7 +118,7 @@ describe('lib/util/settings', () => { }) }) - it('promises cypress.json and merges e2e specific properties', function () { + it('promises cypress.config.js and merges e2e specific properties', function () { return this.setup({ a: 'b', e2e: { a: 'c' } }) .then(() => { return settings.read(projectRoot, defaultOptions) @@ -170,7 +170,7 @@ describe('lib/util/settings', () => { }).catch((err) => { expect(err.type).to.equal('CONFIG_FILE_NOT_FOUND') - return fs.access(path.join(projectRoot, 'cypress.json')) + return fs.access(path.join(projectRoot, 'cypress.config.js')) .then(() => { throw Error('file should not have been created here') }).catch((err) => { @@ -181,7 +181,7 @@ describe('lib/util/settings', () => { }) context('.write', () => { - it('promises cypress.json updates', function () { + it('promises cypress.config.js updates', function () { return this.setup().then(() => { return settings.write(projectRoot, { foo: 'bar' }, defaultOptions) }).then((obj) => { @@ -212,7 +212,7 @@ describe('lib/util/settings', () => { it('.write does not create a file', function () { return settings.write(this.projectRoot, {}, this.options) .then(() => { - return fs.access(path.join(this.projectRoot, 'cypress.json')) + return fs.access(path.join(this.projectRoot, 'cypress.config.js')) .then(() => { throw Error('file shuold not have been created here') }).catch((err) => { diff --git a/packages/types/src/server.ts b/packages/types/src/server.ts index 92d7a98a5e2b..d33621ec58c9 100644 --- a/packages/types/src/server.ts +++ b/packages/types/src/server.ts @@ -67,7 +67,7 @@ export interface OpenProjectLaunchOptions { configFile?: string | false browsers?: Cypress.Browser[] - // Callback to reload the Desktop GUI when cypress.json is changed. + // Callback to reload the Desktop GUI when cypress.config.{ts|js} is changed. onSettingsChanged?: false | (() => void) // Optional callbacks used for triggering events via the web socket diff --git a/system-tests/__snapshots__/config_spec.js b/system-tests/__snapshots__/config_spec.js index 7b09652976ff..4ac0a778537d 100644 --- a/system-tests/__snapshots__/config_spec.js +++ b/system-tests/__snapshots__/config_spec.js @@ -140,14 +140,14 @@ exports['e2e config applies defaultCommandTimeout globally 1'] = ` ` exports['e2e config throws error when invalid viewportWidth in the configuration file 1'] = ` -We found an invalid value in the file: \`cypress.json\` +We found an invalid value in the file: \`cypress.config.js\` Expected \`viewportWidth\` to be a number. Instead the value was: \`"foo"\` ` exports['e2e config throws error when invalid browser in the configuration file 1'] = ` -We found an invalid value in the file: \`cypress.json\` +We found an invalid value in the file: \`cypress.config.js\` Found an error while validating the \`browsers\` list. Expected \`family\` to be either chromium or firefox. Instead the value was: \`{"name":"bad browser","family":"unknown family","displayName":"Bad browser","version":"no version","path":"/path/to","majorVersion":123}\` diff --git a/system-tests/__snapshots__/record_spec.js b/system-tests/__snapshots__/record_spec.js index 1ecb387ff6e8..f20e2330745d 100644 --- a/system-tests/__snapshots__/record_spec.js +++ b/system-tests/__snapshots__/record_spec.js @@ -259,7 +259,7 @@ We dynamically generated a new test to display this failure. exports['e2e record api interaction errors project 404 errors and exits 1'] = ` We could not find a project with the ID: pid123 -This projectId came from your 'cypress.json' file or an environment variable. +This projectId came from your 'cypress.config.js' file or an environment variable. Please log into the Dashboard and find your project. @@ -369,7 +369,7 @@ https://on.cypress.io/how-do-i-record-runs exports['e2e record projectId errors and exits without projectId 1'] = ` You passed the --record flag but this project has not been setup to record. -This project is missing the 'projectId' inside of 'cypress.json'. +This project is missing the 'projectId' inside of 'cypress.config.js'. We cannot uniquely identify this project without this id. diff --git a/system-tests/__snapshots__/visit_spec.js b/system-tests/__snapshots__/visit_spec.js index 948ebf2aaa8d..879e7ef4b031 100644 --- a/system-tests/__snapshots__/visit_spec.js +++ b/system-tests/__snapshots__/visit_spec.js @@ -473,7 +473,7 @@ exports['e2e visit / normal response timeouts / fails when visit times out'] = ` Your page did not fire its \`load\` event within \`1000ms\`. -You can try increasing the \`pageLoadTimeout\` value in \`cypress.json\` to wait longer. +You can try increasing the \`pageLoadTimeout\` value in \`cypress.config.js\` to wait longer. Browsers will not fire the \`load\` event until all stylesheets and scripts are done downloading. @@ -486,7 +486,7 @@ When this \`load\` event occurs, Cypress will continue running commands. Your page did not fire its \`load\` event within \`500ms\`. -You can try increasing the \`pageLoadTimeout\` value in \`cypress.json\` to wait longer. +You can try increasing the \`pageLoadTimeout\` value in \`cypress.config.js\` to wait longer. Browsers will not fire the \`load\` event until all stylesheets and scripts are done downloading. diff --git a/system-tests/__snapshots__/web_security_spec.js b/system-tests/__snapshots__/web_security_spec.js index 8ab2521a70ed..9832c07ced6a 100644 --- a/system-tests/__snapshots__/web_security_spec.js +++ b/system-tests/__snapshots__/web_security_spec.js @@ -45,7 +45,7 @@ Cypress does not allow you to navigate to a different origin URL within a single You may need to restructure some of your test code to avoid this problem. -Alternatively you can also disable Chrome Web Security in Chromium-based browsers which will turn off this restriction by setting { chromeWebSecurity: false } in \`cypress.json\`. +Alternatively you can also disable Chrome Web Security in Chromium-based browsers which will turn off this restriction by setting { chromeWebSecurity: false } in \`cypress.config.js\`. https://on.cypress.io/cross-origin-violation [stack trace lines] @@ -68,7 +68,7 @@ Cypress does not allow you to navigate to a different origin URL within a single You may need to restructure some of your test code to avoid this problem. -Alternatively you can also disable Chrome Web Security in Chromium-based browsers which will turn off this restriction by setting { chromeWebSecurity: false } in \`cypress.json\`. +Alternatively you can also disable Chrome Web Security in Chromium-based browsers which will turn off this restriction by setting { chromeWebSecurity: false } in \`cypress.config.js\`. https://on.cypress.io/cross-origin-violation [stack trace lines] @@ -91,7 +91,7 @@ Cypress does not allow you to navigate to a different origin URL within a single You may need to restructure some of your test code to avoid this problem. -Alternatively you can also disable Chrome Web Security in Chromium-based browsers which will turn off this restriction by setting { chromeWebSecurity: false } in \`cypress.json\`. +Alternatively you can also disable Chrome Web Security in Chromium-based browsers which will turn off this restriction by setting { chromeWebSecurity: false } in \`cypress.config.js\`. https://on.cypress.io/cross-origin-violation [stack trace lines] diff --git a/system-tests/test/plugins_spec.js b/system-tests/test/plugins_spec.js index 211ee1b94f02..e85909cbc648 100644 --- a/system-tests/test/plugins_spec.js +++ b/system-tests/test/plugins_spec.js @@ -194,7 +194,7 @@ describe('e2e plugins', function () { config: { env: { projectRoot: e2eProject, - configFile: path.join(e2eProject, 'cypress.json'), + configFile: path.join(e2eProject, 'cypress.config.js'), }, }, }) From 936ede52256cc5224a7109182d36a6234d74d2d1 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 22 Oct 2021 13:04:51 -0500 Subject: [PATCH 06/57] Fix some tests --- npm/angular/cypress.config.ts | 2 +- .../examples/find-webpack/cypress.config.ts | 2 +- npm/vite-dev-server/cypress.config.ts | 2 +- npm/vue/cypress.config.ts | 2 +- .../examples/use-ts-loader/cypress.config.ts | 2 +- packages/app/cypress.config.ts | 2 +- .../cypress/integration/settings_spec.js | 9 ++------- .../src/lib/config-file-formatted.jsx | 4 ++-- .../desktop-gui/src/settings/project-id.jsx | 18 +++--------------- packages/driver/cypress.config.ts | 2 +- packages/driver/cypress/fixtures/fileSpec.json | 3 +++ .../cypress/integration/commands/files_spec.js | 2 +- .../integration/commands/request_spec.js | 4 ++-- packages/driver/src/cypress/error_messages.ts | 2 +- packages/frontend-shared/cypress.config.ts | 2 +- packages/graphql/schemas/schema.graphql | 2 +- packages/launchpad/cypress.config.ts | 2 +- .../fixtures/test-project/cypress.config.ts | 2 +- packages/reporter/cypress.config.ts | 2 +- packages/runner-ct/cypress.config.ts | 2 +- .../src/config-file-formatted.tsx | 12 ++++++++---- packages/server/lib/config.ts | 4 ++-- packages/server/lib/errors.js | 2 +- 23 files changed, 38 insertions(+), 48 deletions(-) create mode 100644 packages/driver/cypress/fixtures/fileSpec.json diff --git a/npm/angular/cypress.config.ts b/npm/angular/cypress.config.ts index 47c2b29c3550..236dab170ba3 100644 --- a/npm/angular/cypress.config.ts +++ b/npm/angular/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { 'experimentalFetchPolyfill': true, 'fixturesFolder': false, 'includeShadowDom': true, diff --git a/npm/react/examples/find-webpack/cypress.config.ts b/npm/react/examples/find-webpack/cypress.config.ts index a858801d4a78..802087880d0e 100644 --- a/npm/react/examples/find-webpack/cypress.config.ts +++ b/npm/react/examples/find-webpack/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { 'video': true, 'projectId': 'jq5xpp', 'component': { diff --git a/npm/vite-dev-server/cypress.config.ts b/npm/vite-dev-server/cypress.config.ts index ae1800936c68..56f91c2d8aed 100644 --- a/npm/vite-dev-server/cypress.config.ts +++ b/npm/vite-dev-server/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { 'pluginsFile': 'cypress/plugins.js', 'video': false, 'fixturesFolder': false, diff --git a/npm/vue/cypress.config.ts b/npm/vue/cypress.config.ts index 36eb552fea7e..5c42e3305f10 100644 --- a/npm/vue/cypress.config.ts +++ b/npm/vue/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { 'viewportWidth': 500, 'viewportHeight': 500, 'video': false, diff --git a/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts b/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts index 4f64c2459252..80c1b7ede1af 100644 --- a/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts +++ b/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { 'fixturesFolder': false, 'supportFile': false, } diff --git a/packages/app/cypress.config.ts b/packages/app/cypress.config.ts index 50b8569ed981..551c746c5be6 100644 --- a/packages/app/cypress.config.ts +++ b/packages/app/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { '$schema': '../../cli/schema/cypress.schema.json', 'projectId': 'sehy69', 'viewportWidth': 800, diff --git a/packages/desktop-gui/cypress/integration/settings_spec.js b/packages/desktop-gui/cypress/integration/settings_spec.js index b3b631fea81c..7c80bd65845a 100644 --- a/packages/desktop-gui/cypress/integration/settings_spec.js +++ b/packages/desktop-gui/cypress/integration/settings_spec.js @@ -336,7 +336,7 @@ describe('Settings', () => { }) it('notes that cypress.config.js is disabled', () => { - cy.contains('set from cypress.config.js file (currently disabled by --config-file false)') + cy.contains('set from cypress.config.{ts|js} file (currently disabled by --config-file false)') }) }) @@ -381,12 +381,7 @@ describe('Settings', () => { it('copies project id config to clipboard', function () { cy.get('.action-copy').click() .then(() => { - const expectedJsonConfig = { - projectId: this.config.projectId, - } - const expectedCopyCommand = JSON.stringify(expectedJsonConfig, null, 2) - - expect(this.ipc.setClipboardText).to.be.calledWith(expectedCopyCommand) + expect(this.ipc.setClipboardText).to.be.calledWith('module.exports = {') }) }) }) diff --git a/packages/desktop-gui/src/lib/config-file-formatted.jsx b/packages/desktop-gui/src/lib/config-file-formatted.jsx index 86e84ca9a473..93aab8b73a1f 100644 --- a/packages/desktop-gui/src/lib/config-file-formatted.jsx +++ b/packages/desktop-gui/src/lib/config-file-formatted.jsx @@ -3,11 +3,11 @@ import { isUndefined } from 'lodash' const configFileFormatted = (configFile) => { if (configFile === false) { - return <>cypress.config.js file (currently disabled by --config-file false) + return <>cypress.config.{`{ts|js}`} file (currently disabled by --config-file false) } if (isUndefined(configFile)) { - return <>cypress.config.js file + return <>cypress.config.{`{ts|js}`} file } if (['cypress.config.ts', 'cypress.config.js'].includes(configFile)) { diff --git a/packages/desktop-gui/src/settings/project-id.jsx b/packages/desktop-gui/src/settings/project-id.jsx index 18593a8e77cf..2e40f4fa1602 100644 --- a/packages/desktop-gui/src/settings/project-id.jsx +++ b/packages/desktop-gui/src/settings/project-id.jsx @@ -3,7 +3,6 @@ import React from 'react' import Tooltip from '@cypress/react-tooltip' import ipc from '../lib/ipc' -import { isFileJSON } from '../lib/utils' import { configFileFormatted } from '../lib/config-file-formatted' const openProjectIdHelp = (e) => { @@ -39,20 +38,9 @@ const ProjectId = observer(({ project }) => { - { - isFileJSON(project.configFile) ? - <> - {'{'} - {` "projectId": "${project.id}"`} - {'}'} - - : - <> - {'module.exports = {'} - {` projectId: "${project.id}"`} - {'}'} - - } + {'module.exports = {'} + {` projectId: "${project.id}"`} + {'}'} ) diff --git a/packages/driver/cypress.config.ts b/packages/driver/cypress.config.ts index 921ad91a8373..91d140ee4609 100644 --- a/packages/driver/cypress.config.ts +++ b/packages/driver/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { 'projectId': 'ypt4pf', 'baseUrl': 'http://localhost:3500', 'testFiles': '**/*', diff --git a/packages/driver/cypress/fixtures/fileSpec.json b/packages/driver/cypress/fixtures/fileSpec.json new file mode 100644 index 000000000000..da4f53f4b122 --- /dev/null +++ b/packages/driver/cypress/fixtures/fileSpec.json @@ -0,0 +1,3 @@ +{ + "baseUrl": "http://localhost:3500" +} \ No newline at end of file diff --git a/packages/driver/cypress/integration/commands/files_spec.js b/packages/driver/cypress/integration/commands/files_spec.js index 181bd57c98ba..104558a88da5 100644 --- a/packages/driver/cypress/integration/commands/files_spec.js +++ b/packages/driver/cypress/integration/commands/files_spec.js @@ -90,7 +90,7 @@ describe('src/cy/commands/files', () => { }) it('really works', () => { - cy.readFile('cypress.config.ts').its('baseUrl').should('eq', 'http://localhost:3500') + cy.readFile('./cypress/fixtures/fileSpec.json').its('baseUrl').should('eq', 'http://localhost:3500') }) it('works when contents are supposed to be null', () => { diff --git a/packages/driver/cypress/integration/commands/request_spec.js b/packages/driver/cypress/integration/commands/request_spec.js index b466141e3613..0e9509f2fdf7 100644 --- a/packages/driver/cypress/integration/commands/request_spec.js +++ b/packages/driver/cypress/integration/commands/request_spec.js @@ -830,7 +830,7 @@ describe('src/cy/commands/request', () => { expect(this.logs.length).to.eq(1) expect(lastLog.get('error')).to.eq(err) expect(lastLog.get('state')).to.eq('failed') - expect(err.message).to.eq('`cy.request()` must be provided a fully qualified `url` - one that begins with `http`. By default `cy.request()` will use either the current window\'s origin or the `baseUrl` in `cypress.json`. Neither of those values were present.') + expect(err.message).to.eq('`cy.request()` must be provided a fully qualified `url` - one that begins with `http`. By default `cy.request()` will use either the current window\'s origin or the `baseUrl` in `cypress.config.ts`. Neither of those values were present.') expect(err.docsUrl).to.eq('https://on.cypress.io/request') done() @@ -851,7 +851,7 @@ describe('src/cy/commands/request', () => { expect(this.logs.length).to.eq(1) expect(lastLog.get('error')).to.eq(err) expect(lastLog.get('state')).to.eq('failed') - expect(err.message).to.eq('`cy.request()` must be provided a fully qualified `url` - one that begins with `http`. By default `cy.request()` will use either the current window\'s origin or the `baseUrl` in `cypress.json` (currently disabled by --config-file=false). Neither of those values were present.') + expect(err.message).to.eq('`cy.request()` must be provided a fully qualified `url` - one that begins with `http`. By default `cy.request()` will use either the current window\'s origin or the `baseUrl` in `cypress.config.{ts|js}` (currently disabled by --config-file=false). Neither of those values were present.') done() }) diff --git a/packages/driver/src/cypress/error_messages.ts b/packages/driver/src/cypress/error_messages.ts index 3438c3b79581..e0953bcdb244 100644 --- a/packages/driver/src/cypress/error_messages.ts +++ b/packages/driver/src/cypress/error_messages.ts @@ -21,7 +21,7 @@ const format = (data) => { const formatConfigFile = (configFile) => { if (configFile === false) { - return '`cypress.json` (currently disabled by --config-file=false)' + return '`cypress.config.{ts|js}` (currently disabled by --config-file=false)' } return `\`${format(configFile)}\`` diff --git a/packages/frontend-shared/cypress.config.ts b/packages/frontend-shared/cypress.config.ts index 9510990ad0b4..aa26459fd8e4 100644 --- a/packages/frontend-shared/cypress.config.ts +++ b/packages/frontend-shared/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { 'projectId': 'sehy69', 'baseUrl': 'http://localhost:5555', 'viewportWidth': 800, diff --git a/packages/graphql/schemas/schema.graphql b/packages/graphql/schemas/schema.graphql index d91c8c131132..749630e44c9a 100644 --- a/packages/graphql/schemas/schema.graphql +++ b/packages/graphql/schemas/schema.graphql @@ -511,7 +511,7 @@ enum PluginsState { uninitialized } -"""A Cypress Project is represented by a cypress.json file""" +"""A Cypress Project is represented by a cypress.config.{ts|js} file""" type Project implements Node { """The remote associated project from Cypress Cloud""" cloudProject: CloudProject diff --git a/packages/launchpad/cypress.config.ts b/packages/launchpad/cypress.config.ts index 272ce4ac47a2..42bef84793f5 100644 --- a/packages/launchpad/cypress.config.ts +++ b/packages/launchpad/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { '$schema': '../../cli/schema/cypress.schema.json', 'projectId': 'sehy69', 'viewportWidth': 800, diff --git a/packages/launchpad/cypress/fixtures/test-project/cypress.config.ts b/packages/launchpad/cypress/fixtures/test-project/cypress.config.ts index c92eb34ba2ec..a6261aad3d26 100644 --- a/packages/launchpad/cypress/fixtures/test-project/cypress.config.ts +++ b/packages/launchpad/cypress/fixtures/test-project/cypress.config.ts @@ -1,3 +1,3 @@ -module.exports = { +export default { "projectId": "test01" } \ No newline at end of file diff --git a/packages/reporter/cypress.config.ts b/packages/reporter/cypress.config.ts index aa00292e49cf..f8ad5c41999c 100644 --- a/packages/reporter/cypress.config.ts +++ b/packages/reporter/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { 'projectId': 'ypt4pf', 'baseUrl': 'http://localhost:5006', 'viewportWidth': 400, diff --git a/packages/runner-ct/cypress.config.ts b/packages/runner-ct/cypress.config.ts index 164662b3065b..b6b77d6421dd 100644 --- a/packages/runner-ct/cypress.config.ts +++ b/packages/runner-ct/cypress.config.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { testFiles: '**/*spec.{ts,tsx}', video: true, env: { diff --git a/packages/runner-shared/src/config-file-formatted.tsx b/packages/runner-shared/src/config-file-formatted.tsx index 92f95e07bea4..4fc087d8e796 100644 --- a/packages/runner-shared/src/config-file-formatted.tsx +++ b/packages/runner-shared/src/config-file-formatted.tsx @@ -1,11 +1,13 @@ import React from 'react' -import { isUndefined } from 'lodash' const configFileFormatted = (configFile) => { if (configFile === false) { return ( <> - cypress.json + +cypress.config. + {`{ts | js}`} + {' '} file (currently disabled by {' '} @@ -15,10 +17,12 @@ file (currently disabled by ) } - if (isUndefined(configFile) || configFile === 'cypress.json') { + if (['cypress.config.ts', 'cypress.config.js'].includes(configFile)) { return ( <> - cypress.json + + {configFile} + {' '} file diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index e96ff1d1f7c3..e88162c9848c 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -206,7 +206,7 @@ export type FullConfig = export function get (projectRoot, options = {}): Promise { return Promise.all([ - settings.read(projectRoot, options).then(validateFile('cypress.json')), + settings.read(projectRoot, options).then(validateFile('cypress.config.{ts|js}')), settings.readEnv(projectRoot).then(validateFile('cypress.env.json')), ]) .spread((settings, envFile) => { @@ -428,7 +428,7 @@ export function updateWithPluginValues (cfg, overrides) { } // combines the default configuration object with values specified in the -// configuration file like "cypress.json". Values in configuration file +// configuration file like "cypress.{ts|js}". Values in configuration file // overwrite the defaults. export function resolveConfigValues (config, defaults, resolved = {}) { // pick out only known configuration keys diff --git a/packages/server/lib/errors.js b/packages/server/lib/errors.js index 3191983ac81d..7792fae525dc 100644 --- a/packages/server/lib/errors.js +++ b/packages/server/lib/errors.js @@ -625,7 +625,7 @@ const getMsgByType = function (type, arg1 = {}, arg2, arg3) { Fix the error in your code and re-run your tests.` - // happens when there is an error in configuration file like "cypress.json" + // happens when there is an error in configuration file like "cypress.config.{ts|js}" case 'SETTINGS_VALIDATION_ERROR': filePath = `\`${arg1}\`` From c143e9210945f8368b17d31dbfee656318e8f15f Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 22 Oct 2021 15:50:54 -0500 Subject: [PATCH 07/57] Fix more tests --- packages/server/lib/project-base.ts | 7 ---- packages/server/lib/project_static.ts | 2 +- packages/server/lib/util/settings.ts | 12 +++++- .../server/test/integration/cypress_spec.js | 38 +++++++++---------- packages/server/test/unit/config_spec.js | 2 +- system-tests/lib/system-tests.ts | 2 +- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index daa44850ee37..9c80fdfb763d 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -34,7 +34,6 @@ import { SpecsStore } from './specs-store' import { checkSupportFile, getDefaultConfigFilePath } from './project_utils' import type { FoundBrowser, OpenProjectLaunchOptions } from '@packages/types' import { DataContextShell } from '@packages/data-context/src/DataContextShell' -import { getProjectConfig } from './cache' // Cannot just use RuntimeConfigOptions as is because some types are not complete. // Instead, this is an interface of values that have been manually validated to exist @@ -861,12 +860,6 @@ export class ProjectBase extends EE { async getProjectId () { await this.verifyExistence() - const config = await getProjectConfig(this.projectRoot) - - if (config?.projectId) { - return config.projectId - } - const readSettings = await settings.read(this.projectRoot, this.options) if (readSettings && readSettings.projectId) { diff --git a/packages/server/lib/project_static.ts b/packages/server/lib/project_static.ts index 0d0653818a93..fa8bc935525b 100644 --- a/packages/server/lib/project_static.ts +++ b/packages/server/lib/project_static.ts @@ -137,7 +137,7 @@ export function remove (path) { export async function add (path, options) { // don't cache a project if a non-default configFile is set // https://git.io/JeGyF - if (settings.configFile(options) !== 'cypress.config.js' && settings.configFile(options) !== 'cypress.config.ts') { + if (options.configFile !== undefined && settings.configFile(options) !== 'cypress.config.js' && settings.configFile(options) !== 'cypress.config.ts') { return Promise.resolve({ path }) } diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index 3274753e0a83..331661667faf 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -9,13 +9,17 @@ import type { SettingsOptions } from '@packages/types' const debug = Debug('cypress:server:settings') -function jsCode (obj) { +function configCode (obj, isTS?: boolean) { const objJSON = obj && !_.isEmpty(obj) ? JSON.stringify(_.omit(obj, 'configFile'), null, 2) : `{ }` + if (isTS) { + return `export default ${objJSON}` + } + return `module.exports = ${objJSON} ` } @@ -96,7 +100,11 @@ function _write (file, obj = {}) { debug('writing javascript file') - return fs.writeFileAsync(file, jsCode(obj)) + const fileExtension = file?.split('.').pop() + + const isTSFile = fileExtension === 'ts' + + return fs.writeFileAsync(file, configCode(obj, isTSFile)) .return(obj) .catch((err) => { return _logWriteErr(file, err) diff --git a/packages/server/test/integration/cypress_spec.js b/packages/server/test/integration/cypress_spec.js index 0fa9fb165fc4..0cd6001e8b9f 100644 --- a/packages/server/test/integration/cypress_spec.js +++ b/packages/server/test/integration/cypress_spec.js @@ -370,7 +370,7 @@ describe('lib/cypress', () => { }).then(() => { expect(api.createProject).not.to.be.called - return (new ProjectBase({ projectRoot: this.noScaffolding, testingType: 'e2e' })).getProjectId() + return (new ProjectBase({ projectRoot: this.noScaffolding, testingType: 'e2e', options: { configFile: 'cypress.config.js' } })).getProjectId() .then(() => { throw new Error('should have caught error but did not') }).catch((err) => { @@ -488,7 +488,7 @@ describe('lib/cypress', () => { return Promise.all([ fs.statAsync(path.join(this.pristinePath, 'cypress')).reflect(), - fs.statAsync(path.join(this.pristinePath, 'cypress.json')).reflect(), + fs.statAsync(path.join(this.pristinePath, 'cypress.config.js')).reflect(), ]) .each(ensureDoesNotExist) .then(() => { @@ -505,7 +505,7 @@ describe('lib/cypress', () => { }) it('does not scaffold integration or example specs when runMode', function () { - return settings.write(this.pristinePath, {}) + return settings.write(this.pristinePath, {}, { configFile: 'cypress.config.js' }) .then(() => { return cypress.start([`--run-project=${this.pristinePath}`]) }).then(() => { @@ -562,11 +562,11 @@ describe('lib/cypress', () => { return fs.statAsync(this.cfg.fixturesFolder) }).then(() => { - return settings.read(this.idsPath) + return settings.read(this.idsPath, { configFile: 'cypress.config.js' }) }).then((json) => { json.fixturesFolder = false - return settings.write(this.idsPath, json) + return settings.write(this.idsPath, json, { configFile: 'cypress.config.js' }) }).then(() => { return cypress.start([`--run-project=${this.idsPath}`]) }).then(() => { @@ -611,18 +611,18 @@ describe('lib/cypress', () => { }) }) - it('can change the reporter with cypress.json', function () { + it('can change the reporter with cypress.config.js', function () { sinon.spy(Reporter, 'create') return config.get(this.idsPath, { configFile: 'cypress.config.js' }) .then((cfg) => { this.cfg = cfg - return settings.read(this.idsPath) + return settings.read(this.idsPath, { configFile: 'cypress.config.js' }) }).then((json) => { json.reporter = 'dot' - return settings.write(this.idsPath, json) + return settings.write(this.idsPath, json, { configFile: 'cypress.config.js' }) }).then(() => { return cypress.start([`--run-project=${this.idsPath}`]) }).then(() => { @@ -680,7 +680,7 @@ describe('lib/cypress', () => { }) it('logs error when supportFile doesn\'t exist', function () { - return settings.write(this.idsPath, { supportFile: '/does/not/exist' }) + return settings.write(this.idsPath, { supportFile: '/does/not/exist' }, { configFile: 'cypress.config.js' }) .then(() => { return cypress.start([`--run-project=${this.idsPath}`]) }).then(() => { @@ -767,8 +767,8 @@ describe('lib/cypress', () => { }) }) - it('logs error and exits when project has cypress.json syntax error', function () { - return fs.writeFileAsync(`${this.todosPath}/cypress.json`, '{\'foo\': \'bar}') + it('logs error and exits when project has cypress.config.js syntax error', function () { + return fs.writeFileAsync(`${this.todosPath}/cypress.config.js`, `module.exports = {`) .then(() => { return cypress.start([`--run-project=${this.todosPath}`]) }).then(() => { @@ -785,12 +785,12 @@ describe('lib/cypress', () => { }) }) - it('logs error and exits when project has invalid cypress.json values', function () { - return settings.write(this.todosPath, { baseUrl: 'localhost:9999' }) + it('logs error and exits when project has invalid cypress.config.js values', function () { + return settings.write(this.todosPath, { baseUrl: 'localhost:9999' }, { configFile: 'cypress.config.js' }) .then(() => { return cypress.start([`--run-project=${this.todosPath}`]) }).then(() => { - this.expectExitWithErr('SETTINGS_VALIDATION_ERROR', 'cypress.json') + this.expectExitWithErr('SETTINGS_VALIDATION_ERROR', 'cypress.config.{ts|js}') }) }) @@ -839,18 +839,18 @@ describe('lib/cypress', () => { // for headed projects! // also make sure we test the rest of the integration functionality // for headed errors! <-- not unit tests, but integration tests! - it('logs error and exits when project folder has read permissions only and cannot write cypress.json', function () { + it('logs error and exits when project folder has read permissions only and cannot write cypress.config.js', function () { // test disabled if running as root (such as inside docker) - root can write all things at all times if (process.geteuid() === 0) { return } const permissionsPath = path.resolve('./permissions') - const cypressJson = path.join(permissionsPath, 'cypress.json') + const cypressConfig = path.join(permissionsPath, 'cypress.config.js') return fs.mkdirAsync(permissionsPath) .then(() => { - return fs.outputFileAsync(cypressJson, '{}') + return fs.outputFileAsync(cypressConfig, 'module.exports = {}') }).then(() => { // read only return fs.chmodAsync(permissionsPath, '555') @@ -1695,12 +1695,12 @@ describe('lib/cypress', () => { return user.set({ name: 'brian', authToken: 'auth-token-123' }) .then(() => { - return settings.read(this.todosPath) + return settings.read(this.todosPath, { configFile: 'cypress.config.js' }) }).then((json) => { // this should be overriden by the env argument json.baseUrl = 'http://localhost:8080' - return settings.write(this.todosPath, json) + return settings.write(this.todosPath, json, { configFile: 'cypress.config.js' }) }).then(() => { return cypress.start([ '--port=2121', diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index b751a98c747d..f3a19fb650b9 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -147,7 +147,7 @@ describe('lib/config', () => { it('validates cypress.json', function () { this.setup({ reporter: 5 }) - return this.expectValidationFails('cypress.json') + return this.expectValidationFails('cypress.config.{ts|js}') }) it('validates cypress.env.json', function () { diff --git a/system-tests/lib/system-tests.ts b/system-tests/lib/system-tests.ts index f739cc359687..b7d7ec69bd83 100644 --- a/system-tests/lib/system-tests.ts +++ b/system-tests/lib/system-tests.ts @@ -683,7 +683,7 @@ const systemTests = { const s = options.settings if (s) { - await settings.write(e2ePath, s) + await settings.write(e2ePath, s, { configFile: 'cypress.config.js' }) } }) From e598f48afa6237be8e8d433c129d81f3404ae790 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 25 Oct 2021 11:03:27 -0500 Subject: [PATCH 08/57] Fix more tests --- packages/server/lib/config.ts | 4 ++-- packages/server/lib/modes/run.js | 32 +++++++++++++++------------- packages/server/lib/util/settings.ts | 3 --- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index e88162c9848c..a499b6cc0340 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -204,9 +204,9 @@ export type FullConfig = resolved: ResolvedConfigurationOptions } -export function get (projectRoot, options = {}): Promise { +export function get (projectRoot, options: {configFile?: string | false } = { configFile: undefined }): Promise { return Promise.all([ - settings.read(projectRoot, options).then(validateFile('cypress.config.{ts|js}')), + settings.read(projectRoot, options).then(validateFile(options.configFile ?? 'cypress.config.{ts|js}')), settings.readEnv(projectRoot).then(validateFile('cypress.env.json')), ]) .spread((settings, envFile) => { diff --git a/packages/server/lib/modes/run.js b/packages/server/lib/modes/run.js index 7d212a772f13..5eee127813a2 100644 --- a/packages/server/lib/modes/run.js +++ b/packages/server/lib/modes/run.js @@ -624,19 +624,21 @@ const createAndOpenProject = async (socketId, options) => { await checkAccess(projectRoot) - return openProjectCreate(projectRoot, socketId, options) - .then((open_project) => open_project.getProject()) - .then((project) => { - return Promise.all([ - project, - project.getConfig(), - getProjectId(project, projectId), - ]).then(([project, config, projectId]) => ({ - project, - config, - projectId, - })) - }) + const open_project = await openProjectCreate(projectRoot, socketId, options) + const project = open_project.getProject() + + const [_project, _config, _projectId] = await Promise.all([ + project, + project.getConfig(), + getProjectId(project, projectId), + ]) + + return { + project: _project, + config: _config, + projectId: _projectId, + configFile: project.options.configFile, + } } const removeOldProfiles = (browser) => { @@ -1533,7 +1535,7 @@ module.exports = { options.browsers = browsers return createAndOpenProject(socketId, options) - .then(({ project, projectId, config }) => { + .then(({ project, projectId, config, configFile }) => { debug('project created and opened with config %o', config) // if we have a project id and a key but record hasnt been given @@ -1541,7 +1543,7 @@ module.exports = { recordMode.throwIfRecordParamsWithoutRecording(record, ciBuildId, parallel, group, tag) if (record) { - recordMode.throwIfNoProjectId(projectId, settings.configFile(options)) + recordMode.throwIfNoProjectId(projectId, settings.configFile(options.configFile === undefined || options.configFile === null ? { configFile } : options)) // recordMode.throwIfIncorrectCiBuildIdUsage(ciBuildId, parallel, group) recordMode.throwIfIndeterminateCiBuildId(ciBuildId, parallel, group) } diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index 331661667faf..be2ac6505a8a 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -124,9 +124,6 @@ export function isComponentTesting (options: SettingsOptions = {}) { } export function configFile (options: SettingsOptions = {}) { - // default is only used in tests. - // This prevents a the change from becoming bigger than it should - // FIXME: remove the default return options.configFile === false ? false : options.configFile } From 1b354420aa4422a0c3eb4536d8517141790ffc38 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 25 Oct 2021 16:33:04 -0500 Subject: [PATCH 09/57] Fix more tests --- .../src/schematics/ng-add/index.spec.ts | 2 +- .../src/schematics/ng-add/index.ts | 15 ++++++++++++--- npm/react/cypress/component/viewport-spec.jsx | 2 +- packages/driver/src/cypress/mocha.ts | 2 +- .../src/settings/project/Config.spec.tsx | 4 ++-- .../launchpad/src/settings/project/Config.vue | 4 ++-- .../src/setup/TestingTypeCards.spec.tsx | 12 ++++++------ packages/server/lib/config.ts | 2 +- packages/server/lib/config_options.ts | 2 +- packages/server/lib/errors.js | 2 +- packages/server/lib/modes/record.js | 1 + packages/server/lib/modes/run.js | 2 +- packages/server/lib/project-base.ts | 7 +++++++ packages/server/lib/saved_state.js | 18 +++++++++++++++--- .../server/test/integration/cypress_spec.js | 10 +++++----- packages/server/test/unit/config_spec.js | 4 ++-- packages/server/test/unit/gui/events_spec.js | 4 ++-- packages/server/test/unit/project_spec.js | 12 ++++++------ 18 files changed, 67 insertions(+), 38 deletions(-) diff --git a/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts b/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts index 0bf90878cb31..9ba48125f0bf 100644 --- a/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts +++ b/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts @@ -32,7 +32,7 @@ describe('@cypress/schematic: ng-add', () => { }) it('should create cypress files', async () => { - const files = ['cypress/integration/spec.ts', 'cypress/plugins/index.ts', 'cypress/support/commands.ts', 'cypress/support/index.ts', 'cypress/tsconfig.json', 'cypress.json'] + const files = ['cypress/integration/spec.ts', 'cypress/plugins/index.ts', 'cypress/support/commands.ts', 'cypress/support/index.ts', 'cypress/tsconfig.json', 'cypress.config.js'] const homePath = '/projects/sandbox/' return schematicRunner.runSchematicAsync('ng-add', {}, appTree).toPromise().then((tree) => { diff --git a/npm/cypress-schematic/src/schematics/ng-add/index.ts b/npm/cypress-schematic/src/schematics/ng-add/index.ts index 6d56862523fd..f5dc5bf7bbc1 100644 --- a/npm/cypress-schematic/src/schematics/ng-add/index.ts +++ b/npm/cypress-schematic/src/schematics/ng-add/index.ts @@ -195,9 +195,7 @@ function modifyAngularJson (options: any): Rule { }, } - const configFile = projects[project].root - ? `${projects[project].root}/cypress.json` - : null + const configFile = getCypressConfigFile(angularJsonVal, project) if (configFile) { Object.assign(runJson.options, { configFile }) @@ -233,6 +231,17 @@ function modifyAngularJson (options: any): Rule { } } +export const getCypressConfigFile = (angularJsonVal: any, projectName: string) => { + const project = angularJsonVal.projects[projectName] + let tsConfig = project?.architect?.lint?.options?.tsConfig + + if (project.root) { + return `${project.root}/cypress.config.${tsConfig ? 'ts' : 'js'}` + } + + return null +} + export const addCypressTsConfig = (tree: Tree, angularJsonVal: any, projectName: string) => { const project = angularJsonVal.projects[projectName] let tsConfig = project?.architect?.lint?.options?.tsConfig diff --git a/npm/react/cypress/component/viewport-spec.jsx b/npm/react/cypress/component/viewport-spec.jsx index 74ac9ec72ca4..94353f5647da 100644 --- a/npm/react/cypress/component/viewport-spec.jsx +++ b/npm/react/cypress/component/viewport-spec.jsx @@ -1,7 +1,7 @@ const viewportWidth = 200 const viewportHeight = 100 -describe('cypress.json viewport', +describe('cypress.config.{ts|js} viewport', { viewportWidth, viewportHeight }, () => { it('should have the correct dimensions', () => { diff --git a/packages/driver/src/cypress/mocha.ts b/packages/driver/src/cypress/mocha.ts index 8b46babf1dde..ad43cd564193 100644 --- a/packages/driver/src/cypress/mocha.ts +++ b/packages/driver/src/cypress/mocha.ts @@ -144,7 +144,7 @@ const setMochaProps = (specWindow, _mocha) => { // to the mocha instance for clarity m.Mocha = M - // this needs to be part of the configuration of cypress.json + // this needs to be part of the configuration of cypress.config.{ts|js} // we can't just forcibly use bdd return ui(specWindow, _mocha) } diff --git a/packages/launchpad/src/settings/project/Config.spec.tsx b/packages/launchpad/src/settings/project/Config.spec.tsx index 507ab962db61..57a0373ba66f 100644 --- a/packages/launchpad/src/settings/project/Config.spec.tsx +++ b/packages/launchpad/src/settings/project/Config.spec.tsx @@ -1,12 +1,12 @@ import Config from './Config.vue' -import jsonObject from '../../../cypress.json?raw' +import cypressConfig from '../../../cypress.config' import { defaultMessages } from '@cy/i18n' import { each } from 'lodash' describe('', () => { it('renders the title, description, code, and legend', () => { cy.mount(() =>
) - cy.get('[data-testid=config-code]').contains(jsonObject) + cy.get('[data-testid=config-code]').contains(JSON.stringify(cypressConfig, null, 2)) cy.contains(defaultMessages.settingsPage.config.title) // TODO: write a support file helper for ignoring the {0} values etc diff --git a/packages/launchpad/src/settings/project/Config.vue b/packages/launchpad/src/settings/project/Config.vue index 8b6baf6eda2e..05f56d86329d 100644 --- a/packages/launchpad/src/settings/project/Config.vue +++ b/packages/launchpad/src/settings/project/Config.vue @@ -28,10 +28,10 @@ import { ref } from 'vue' import SettingsSection from '../SettingsSection.vue' import { useI18n } from '@cy/i18n' -import cypressJson from '../../../cypress.json?raw' // TODO: remove this +import cypressConfig from '../../../cypress.config' import ConfigLegend from './ConfigLegend.vue' import ConfigCode from './ConfigCode.vue' -const code = ref(JSON.parse(JSON.stringify(cypressJson, null, 2))) +const code = ref(JSON.parse(JSON.stringify(cypressConfig, null, 2))) const { t } = useI18n() diff --git a/packages/launchpad/src/setup/TestingTypeCards.spec.tsx b/packages/launchpad/src/setup/TestingTypeCards.spec.tsx index 9534fc0b0a8b..4c7a0e4d9de4 100644 --- a/packages/launchpad/src/setup/TestingTypeCards.spec.tsx +++ b/packages/launchpad/src/setup/TestingTypeCards.spec.tsx @@ -9,8 +9,8 @@ describe('TestingTypeCards', () => { cy.mountFragment(TestingTypeCardsFragmentDoc, { onResult: (result, ctx) => { if (result.app.activeProject) { - result.app.activeProject.isCTConfigured = true - result.app.activeProject.isE2EConfigured = true + result.app.activeProject.isCTConfigured = false + result.app.activeProject.isE2EConfigured = false } }, render: (gqlVal) => { @@ -28,8 +28,8 @@ describe('TestingTypeCards', () => { cy.mountFragment(TestingTypeCardsFragmentDoc, { onResult: (result, ctx) => { if (result.app.activeProject) { - result.app.activeProject.isCTConfigured = false - result.app.activeProject.isE2EConfigured = false + result.app.activeProject.isCTConfigured = true + result.app.activeProject.isE2EConfigured = true } }, render: (gqlVal) => { @@ -45,8 +45,8 @@ describe('TestingTypeCards', () => { cy.mountFragment(TestingTypeCardsFragmentDoc, { onResult: (result, ctx) => { if (result.app.activeProject) { - result.app.activeProject.isCTConfigured = false - result.app.activeProject.isE2EConfigured = true + result.app.activeProject.isCTConfigured = true + result.app.activeProject.isE2EConfigured = false } }, render: (gqlVal) => { diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index a499b6cc0340..2d9240e22e0d 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -749,7 +749,7 @@ export function parseEnv (cfg: Record, envCLI: Record, resolveFrom('env', envProc) resolveFrom('cli', envCLI) - // envCfg is from cypress.json + // envCfg is from cypress.config.{ts|js} // envFile is from cypress.env.json // envProc is from process env vars // envCLI is from CLI arguments diff --git a/packages/server/lib/config_options.ts b/packages/server/lib/config_options.ts index 2c02b10dada7..0029ca7ed4e7 100644 --- a/packages/server/lib/config_options.ts +++ b/packages/server/lib/config_options.ts @@ -52,7 +52,7 @@ export const options = [ isFolder: true, }, { name: 'configFile', - defaultValue: 'cypress.json', + defaultValue: 'cypress.config.js', validation: v.isStringOrFalse, // not truly internal, but can only be set via cli, // so we don't consider it a "public" option diff --git a/packages/server/lib/errors.js b/packages/server/lib/errors.js index 7792fae525dc..0dd147a52779 100644 --- a/packages/server/lib/errors.js +++ b/packages/server/lib/errors.js @@ -932,7 +932,7 @@ const getMsgByType = function (type, arg1 = {}, arg2, arg3) { You can safely remove this option from your config.` case 'EXPERIMENTAL_COMPONENT_TESTING_REMOVED': return stripIndent`\ - The ${chalk.yellow(`\`experimentalComponentTesting\``)} configuration option was removed in Cypress version \`7.0.0\`. Please remove this flag from \`cypress.json\`. + The ${chalk.yellow(`\`experimentalComponentTesting\``)} configuration option was removed in Cypress version \`7.0.0\`. Please remove this flag from \`cypress.config.{ts|js}\`. Cypress Component Testing is now a standalone command. You can now run your component tests with: diff --git a/packages/server/lib/modes/record.js b/packages/server/lib/modes/record.js index 7fae7dd0dcf9..a1d9739f5345 100644 --- a/packages/server/lib/modes/record.js +++ b/packages/server/lib/modes/record.js @@ -620,6 +620,7 @@ const createRunAndRecordSpecs = (options = {}) => { projectId, specPattern, testingType, + configFile: config.configFile, }) .then((resp) => { if (!resp) { diff --git a/packages/server/lib/modes/run.js b/packages/server/lib/modes/run.js index 5eee127813a2..3acc6cded4c7 100644 --- a/packages/server/lib/modes/run.js +++ b/packages/server/lib/modes/run.js @@ -625,7 +625,7 @@ const createAndOpenProject = async (socketId, options) => { await checkAccess(projectRoot) const open_project = await openProjectCreate(projectRoot, socketId, options) - const project = open_project.getProject() + const project = await open_project.getProject() const [_project, _config, _projectId] = await Promise.all([ project, diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index 9c80fdfb763d..daa44850ee37 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -34,6 +34,7 @@ import { SpecsStore } from './specs-store' import { checkSupportFile, getDefaultConfigFilePath } from './project_utils' import type { FoundBrowser, OpenProjectLaunchOptions } from '@packages/types' import { DataContextShell } from '@packages/data-context/src/DataContextShell' +import { getProjectConfig } from './cache' // Cannot just use RuntimeConfigOptions as is because some types are not complete. // Instead, this is an interface of values that have been manually validated to exist @@ -860,6 +861,12 @@ export class ProjectBase extends EE { async getProjectId () { await this.verifyExistence() + const config = await getProjectConfig(this.projectRoot) + + if (config?.projectId) { + return config.projectId + } + const readSettings = await settings.read(this.projectRoot, this.options) if (readSettings && readSettings.projectId) { diff --git a/packages/server/lib/saved_state.js b/packages/server/lib/saved_state.js index abef16ff4590..bf619f2d1785 100644 --- a/packages/server/lib/saved_state.js +++ b/packages/server/lib/saved_state.js @@ -49,12 +49,24 @@ const formStatePath = (projectRoot) => { debug('missing project path, looking for project here') - const cypressJsonPath = cwd('cypress.json') + let cypressConfigPath = cwd('cypress.config.js') - return fs.pathExistsAsync(cypressJsonPath) + return fs.pathExistsAsync(cypressConfigPath) .then((found) => { if (found) { - debug('found cypress file %s', cypressJsonPath) + debug('found cypress file %s', cypressConfigPath) + projectRoot = cwd() + + return + } + + cypressConfigPath = cwd('cypress.config.ts') + + return fs.pathExistsAsync(cypressConfigPath) + }) + .then((found) => { + if (found) { + debug('found cypress file %s', cypressConfigPath) projectRoot = cwd() } diff --git a/packages/server/test/integration/cypress_spec.js b/packages/server/test/integration/cypress_spec.js index 0cd6001e8b9f..6c40f55747f8 100644 --- a/packages/server/test/integration/cypress_spec.js +++ b/packages/server/test/integration/cypress_spec.js @@ -496,7 +496,7 @@ describe('lib/cypress', () => { }).then(() => { return Promise.all([ fs.statAsync(path.join(this.pristinePath, 'cypress')).reflect(), - fs.statAsync(path.join(this.pristinePath, 'cypress.json')).reflect(), + fs.statAsync(path.join(this.pristinePath, 'cypress.config.js')).reflect(), ]) }).each(ensureDoesNotExist) .then(() => { @@ -790,7 +790,7 @@ describe('lib/cypress', () => { .then(() => { return cypress.start([`--run-project=${this.todosPath}`]) }).then(() => { - this.expectExitWithErr('SETTINGS_VALIDATION_ERROR', 'cypress.config.{ts|js}') + this.expectExitWithErr('SETTINGS_VALIDATION_ERROR', 'cypress.config.js') }) }) @@ -1178,10 +1178,10 @@ describe('lib/cypress', () => { }) describe('--config-file', () => { - it('false does not require cypress.json to run', function () { - return fs.statAsync(path.join(this.pristinePath, 'cypress.json')) + it('false does not require cypress.config.js to run', function () { + return fs.statAsync(path.join(this.pristinePath, 'cypress.config.js')) .then(() => { - throw new Error('cypress.json should not exist') + throw new Error('cypress.config.js should not exist') }).catch({ code: 'ENOENT' }, () => { return cypress.start([ `--run-project=${this.pristinePath}`, diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index f3a19fb650b9..91ed07d03b67 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -144,10 +144,10 @@ describe('lib/config', () => { return this.expectValidationPasses() }) - it('validates cypress.json', function () { + it('validates cypress.config.js', function () { this.setup({ reporter: 5 }) - return this.expectValidationFails('cypress.config.{ts|js}') + return this.expectValidationFails('cypress.config.js') }) it('validates cypress.env.json', function () { diff --git a/packages/server/test/unit/gui/events_spec.js b/packages/server/test/unit/gui/events_spec.js index 8c4002cb14f8..e334f7629014 100644 --- a/packages/server/test/unit/gui/events_spec.js +++ b/packages/server/test/unit/gui/events_spec.js @@ -926,7 +926,7 @@ describe('lib/gui/events', () => { describe('set:project:id', () => { it('calls writeProjectId with projectRoot', function () { - const arg = { id: '1', projectRoot: '/project/root/', configFile: 'cypress.json' } + const arg = { id: '1', projectRoot: '/project/root/', configFile: 'cypress.config.js' } const stubWriteProjectId = sinon.stub(ProjectStatic, 'writeProjectId').resolves() return this.handleEvent('set:project:id', arg) @@ -940,7 +940,7 @@ describe('lib/gui/events', () => { describe('setup:dashboard:project', () => { it('returns result of ProjectStatic.createCiProject', function () { - const arg = { projectRoot: '/project/root/', configFile: 'cypress.json' } + const arg = { projectRoot: '/project/root/', configFile: 'cypress.config.js' } const stubCreateCiProject = sinon.stub(ProjectStatic, 'createCiProject').resolves() return this.handleEvent('setup:dashboard:project', arg) diff --git a/packages/server/test/unit/project_spec.js b/packages/server/test/unit/project_spec.js index 3d6386e3133e..baceb23364c3 100644 --- a/packages/server/test/unit/project_spec.js +++ b/packages/server/test/unit/project_spec.js @@ -345,7 +345,7 @@ This option will not have an effect in Some-other-name. Tests that rely on web s it('calls checkSupportFile with server config when scaffolding is finished', function () { return this.project.open().then(() => { expect(this.checkSupportFileStub).to.be.calledWith({ - configFile: 'cypress.json', + configFile: 'cypress.config.js', supportFile: '/foo/bar/cypress/support/index.js', }) }) @@ -383,9 +383,9 @@ This option will not have an effect in Some-other-name. Tests that rely on web s }) // TODO: skip this for now - it.skip('watches cypress.json', function () { + it.skip('watches cypress.config.js', function () { return this.server.open().bind(this).then(() => { - expect(Watchers.prototype.watch).to.be.calledWith('/Users/brian/app/cypress.json') + expect(Watchers.prototype.watch).to.be.calledWith('/Users/brian/app/cypress.config.js') }) }) @@ -713,17 +713,17 @@ This option will not have an effect in Some-other-name. Tests that rely on web s beforeEach(function () { this.project = new ProjectBase({ projectRoot: '/_test-output/path/to/project-e2e', testingType: 'e2e' }) this.project._server = { close () {}, startWebsockets () {} } - sinon.stub(settings, 'pathToConfigFile').returns('/path/to/cypress.json') + sinon.stub(settings, 'pathToConfigFile').returns('/path/to/cypress.config.js') sinon.stub(settings, 'pathToCypressEnvJson').returns('/path/to/cypress.env.json') this.watch = sinon.stub(this.project.watchers, 'watch') this.watchTree = sinon.stub(this.project.watchers, 'watchTree') }) - it('watches cypress.json and cypress.env.json', function () { + it('watches cypress.config.js and cypress.env.json', function () { this.project.watchSettings({ onSettingsChanged () {} }, {}) expect(this.watch).to.be.calledOnce expect(this.watchTree).to.be.calledOnce - expect(this.watchTree).to.be.calledWith('/path/to/cypress.json') + expect(this.watchTree).to.be.calledWith('/path/to/cypress.config.js') expect(this.watch).to.be.calledWith('/path/to/cypress.env.json') }) From f944cbdc0759340a8ffc6dc1c6227012e3ad00c7 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 25 Oct 2021 18:13:09 -0500 Subject: [PATCH 10/57] Fix more tests --- packages/data-context/src/sources/ProjectDataSource.ts | 2 +- .../desktop-gui/cypress/integration/settings_spec.js | 2 +- .../cypress/e2e/integration/open-mode.spec.ts | 10 +++------- packages/server/lib/modes/record.js | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index e7e2dc5d09f4..7278fe89de5e 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -125,7 +125,7 @@ export class ProjectDataSource { } async isTestingTypeConfigured (projectRoot: string, testingType: 'e2e' | 'component') { - const config = await this.api.getProjectConfig(projectRoot) + const config = await this.getConfig(projectRoot) if (!config) { return true diff --git a/packages/desktop-gui/cypress/integration/settings_spec.js b/packages/desktop-gui/cypress/integration/settings_spec.js index 7c80bd65845a..716b4b151af1 100644 --- a/packages/desktop-gui/cypress/integration/settings_spec.js +++ b/packages/desktop-gui/cypress/integration/settings_spec.js @@ -381,7 +381,7 @@ describe('Settings', () => { it('copies project id config to clipboard', function () { cy.get('.action-copy').click() .then(() => { - expect(this.ipc.setClipboardText).to.be.calledWith('module.exports = {') + expect(this.ipc.setClipboardText).to.be.calledWith('module.exports = {\n projectId: "d8104707-a348-4653-baea-7da9c7d52448"\n}') }) }) }) diff --git a/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts b/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts index abed8857052a..18a6e382c513 100644 --- a/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts +++ b/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts @@ -1,21 +1,17 @@ import defaultMessages from '../../../../frontend-shared/src/locales/en-US.json' describe('Launchpad: Open Mode', () => { - beforeEach(() => { + it('Shows the open page', () => { cy.setupE2E() cy.visitLaunchpad() - }) - it('Shows the open page', () => { cy.get('h1').should('contain', defaultMessages.globalPage.empty.title) }) describe('when there is a list of projects', () => { it('goes to an active project if one is added', () => { - cy.withCtx(async (ctx, o) => { - await ctx.actions.project.setActiveProject(o.projectDir('todos')) - ctx.emitter.toLaunchpad() - }) + cy.setupE2E('todos') + cy.visitLaunchpad() cy.get('h1').should('contain', 'Welcome to Cypress!') }) diff --git a/packages/server/lib/modes/record.js b/packages/server/lib/modes/record.js index a1d9739f5345..a78b154af5c2 100644 --- a/packages/server/lib/modes/record.js +++ b/packages/server/lib/modes/record.js @@ -620,7 +620,7 @@ const createRunAndRecordSpecs = (options = {}) => { projectId, specPattern, testingType, - configFile: config.configFile, + configFile: config ? config.configFile : null, }) .then((resp) => { if (!resp) { From 51859db87ee5f44d772a83473f729412ab0f84bf Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 25 Oct 2021 20:14:01 -0500 Subject: [PATCH 11/57] Attempt to fix CI projects --- circle.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/circle.yml b/circle.yml index b0afac78cdcc..8ce3f6ccff64 100644 --- a/circle.yml +++ b/circle.yml @@ -1869,6 +1869,14 @@ jobs: name: Scaffold full TypeScript project 🏗 working_directory: <> command: npx @bahmutov/cly@1 init --typescript + - run: + name: Remove previous config file + working_directory: <> + command: rm -rf cypress.json + - run: + name: Add new config file + working_directory: <> + command: echo 'module.exports = {}' > cypress.config.ts - run: name: Run project tests 🗳 working_directory: <> @@ -2047,6 +2055,14 @@ jobs: name: Add Cypress demo working_directory: test-binary command: npx @bahmutov/cly init + - run: + name: Remove previous config file + working_directory: <> + command: rm -rf cypress.json + - run: + name: Add new config file + working_directory: <> + command: echo 'module.exports = {}' > cypress.config.js - run: name: Verify Cypress binary working_directory: test-binary From 1864cec974c55b5b8d0cc6aba8fc95a76562c38a Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 25 Oct 2021 20:17:29 -0500 Subject: [PATCH 12/57] Fix CircleCI --- circle.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/circle.yml b/circle.yml index 8ce3f6ccff64..e7a428c1ed2a 100644 --- a/circle.yml +++ b/circle.yml @@ -1870,13 +1870,13 @@ jobs: working_directory: <> command: npx @bahmutov/cly@1 init --typescript - run: - name: Remove previous config file - working_directory: <> - command: rm -rf cypress.json + name: Remove previous config file + working_directory: <> + command: rm -rf cypress.json - run: - name: Add new config file - working_directory: <> - command: echo 'module.exports = {}' > cypress.config.ts + name: Add new config file + working_directory: <> + command: echo 'module.exports = {}' > cypress.config.ts - run: name: Run project tests 🗳 working_directory: <> @@ -2056,13 +2056,13 @@ jobs: working_directory: test-binary command: npx @bahmutov/cly init - run: - name: Remove previous config file - working_directory: <> - command: rm -rf cypress.json + name: Remove previous config file + working_directory: <> + command: rm -rf cypress.json - run: - name: Add new config file - working_directory: <> - command: echo 'module.exports = {}' > cypress.config.js + name: Add new config file + working_directory: <> + command: echo 'module.exports = {}' > cypress.config.js - run: name: Verify Cypress binary working_directory: test-binary From e66e49ce59b7b1aeac935ed66a5aac75a148933a Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 25 Oct 2021 20:30:41 -0500 Subject: [PATCH 13/57] Attempt to fix CircleCI --- circle.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/circle.yml b/circle.yml index e7a428c1ed2a..553fdc98cbe1 100644 --- a/circle.yml +++ b/circle.yml @@ -1870,13 +1870,13 @@ jobs: working_directory: <> command: npx @bahmutov/cly@1 init --typescript - run: - name: Remove previous config file + name: Scaffold new config file working_directory: <> - command: rm -rf cypress.json - - run: - name: Add new config file - working_directory: <> - command: echo 'module.exports = {}' > cypress.config.ts + environment: + CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" + command: | + rm -rf cypress.json + echo 'export default {}' > cypress.config.ts - run: name: Run project tests 🗳 working_directory: <> @@ -2055,14 +2055,14 @@ jobs: name: Add Cypress demo working_directory: test-binary command: npx @bahmutov/cly init - - run: - name: Remove previous config file + - run: + name: Scaffold new config file working_directory: <> - command: rm -rf cypress.json - - run: - name: Add new config file - working_directory: <> - command: echo 'module.exports = {}' > cypress.config.js + environment: + CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" + command: | + rm -rf cypress.json + echo 'module.exports = {}' > cypress.config.js - run: name: Verify Cypress binary working_directory: test-binary From 88abc8dbbabf55b244778d2e6e0890da9722bcb8 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 25 Oct 2021 20:34:52 -0500 Subject: [PATCH 14/57] Attempt to fix CircleCI --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 553fdc98cbe1..30e0864e115b 100644 --- a/circle.yml +++ b/circle.yml @@ -2055,7 +2055,7 @@ jobs: name: Add Cypress demo working_directory: test-binary command: npx @bahmutov/cly init - - run: + - run: name: Scaffold new config file working_directory: <> environment: From c9cf43efd753bb811f5b0906e27b525f46e547cd Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 25 Oct 2021 20:36:37 -0500 Subject: [PATCH 15/57] Attempt to fix CircleCI --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 30e0864e115b..9b1c2f4dfeee 100644 --- a/circle.yml +++ b/circle.yml @@ -2057,7 +2057,7 @@ jobs: command: npx @bahmutov/cly init - run: name: Scaffold new config file - working_directory: <> + working_directory: test-binary environment: CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" command: | From 4d7a1c225d5dab402d1c2a5f5c7045facf23251f Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 26 Oct 2021 11:20:46 -0500 Subject: [PATCH 16/57] Attempt to fix CircleCI --- circle.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/circle.yml b/circle.yml index 9b1c2f4dfeee..5666e73d39a7 100644 --- a/circle.yml +++ b/circle.yml @@ -724,6 +724,14 @@ commands: CYPRESS_INSTALL_BINARY=~/cypress/cypress.zip npm install ~/cypress/cypress.tgz fi working_directory: /tmp/<> + - run: + name: Scaffold new config file + working_directory: /tmp/<> + environment: + CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" + command: | + rm -rf cypress.json + echo 'module.exports = {}' > cypress.config.js - run: name: Print Cypress version working_directory: /tmp/<> From 289b56fdd8d4faf5ce9a08c6032e9788e4ed3d81 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 26 Oct 2021 11:40:07 -0500 Subject: [PATCH 17/57] Attempt to fix CircleCI --- circle.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/circle.yml b/circle.yml index 5666e73d39a7..8c9c746d1594 100644 --- a/circle.yml +++ b/circle.yml @@ -1612,6 +1612,14 @@ jobs: - clone-repo-and-checkout-release-branch: repo: cypress-example-kitchensink - install-required-node + - run: + name: Scaffold new config file + working_directory: /tmp/cypress-example-kitchensink + environment: + CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" + command: | + rm -rf cypress.json + echo 'module.exports = {}' > cypress.config.js - run: name: Install prod dependencies command: yarn --production From 7c25bed858d0b744c98645fdd08e9818b9bff69d Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 26 Oct 2021 15:23:35 -0500 Subject: [PATCH 18/57] Fix more tests --- .../src/schematics/ng-add/index.spec.ts | 2 +- .../src/schematics/ng-add/index.ts | 2 +- .../unify-onboarding/cypress.config.js | 6 ++++++ .../unify-onboarding/cypress/plugins/index.js | 21 +++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 system-tests/projects/unify-onboarding/cypress.config.js create mode 100644 system-tests/projects/unify-onboarding/cypress/plugins/index.js diff --git a/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts b/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts index 9ba48125f0bf..01f26fcc4747 100644 --- a/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts +++ b/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts @@ -32,7 +32,7 @@ describe('@cypress/schematic: ng-add', () => { }) it('should create cypress files', async () => { - const files = ['cypress/integration/spec.ts', 'cypress/plugins/index.ts', 'cypress/support/commands.ts', 'cypress/support/index.ts', 'cypress/tsconfig.json', 'cypress.config.js'] + const files = ['cypress/integration/spec.ts', 'cypress/plugins/index.ts', 'cypress/support/commands.ts', 'cypress/support/index.ts', 'cypress/tsconfig.json', 'cypress.config.ts'] const homePath = '/projects/sandbox/' return schematicRunner.runSchematicAsync('ng-add', {}, appTree).toPromise().then((tree) => { diff --git a/npm/cypress-schematic/src/schematics/ng-add/index.ts b/npm/cypress-schematic/src/schematics/ng-add/index.ts index f5dc5bf7bbc1..23979cd2c782 100644 --- a/npm/cypress-schematic/src/schematics/ng-add/index.ts +++ b/npm/cypress-schematic/src/schematics/ng-add/index.ts @@ -233,7 +233,7 @@ function modifyAngularJson (options: any): Rule { export const getCypressConfigFile = (angularJsonVal: any, projectName: string) => { const project = angularJsonVal.projects[projectName] - let tsConfig = project?.architect?.lint?.options?.tsConfig + const tsConfig = project?.architect?.lint?.options?.tsConfig if (project.root) { return `${project.root}/cypress.config.${tsConfig ? 'ts' : 'js'}` diff --git a/system-tests/projects/unify-onboarding/cypress.config.js b/system-tests/projects/unify-onboarding/cypress.config.js new file mode 100644 index 000000000000..39e12cab152c --- /dev/null +++ b/system-tests/projects/unify-onboarding/cypress.config.js @@ -0,0 +1,6 @@ +module.exports = { + component: { + testFiles: '**/*cy-spec.{js,jsx,ts,tsx}', + componentFolder: 'src', + }, +} diff --git a/system-tests/projects/unify-onboarding/cypress/plugins/index.js b/system-tests/projects/unify-onboarding/cypress/plugins/index.js new file mode 100644 index 000000000000..d8e8f3f055c6 --- /dev/null +++ b/system-tests/projects/unify-onboarding/cypress/plugins/index.js @@ -0,0 +1,21 @@ +/// +const { startDevServer } = require('@cypress/webpack-dev-server') + +const webpackConfig = { + output: { + publicPath: '/', + }, +} + +/** + * @type Cypress.PluginConfig + */ +module.exports = (on, config) => { + if (config.testingType !== 'component') { + throw Error(`This is an component testing project. testingType should be 'component'. Received ${config.testingType}`) + } + + on('dev-server:start', (options) => startDevServer({ options, webpackConfig })) + + return config +} From ed4593ed14ac7709c64915d54c6f6cae374c4bca Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 26 Oct 2021 16:24:37 -0500 Subject: [PATCH 19/57] Attempt to fix test --- npm/cypress-schematic/src/schematics/ng-add/index.spec.ts | 2 +- npm/cypress-schematic/src/schematics/ng-add/index.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts b/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts index 01f26fcc4747..9ba48125f0bf 100644 --- a/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts +++ b/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts @@ -32,7 +32,7 @@ describe('@cypress/schematic: ng-add', () => { }) it('should create cypress files', async () => { - const files = ['cypress/integration/spec.ts', 'cypress/plugins/index.ts', 'cypress/support/commands.ts', 'cypress/support/index.ts', 'cypress/tsconfig.json', 'cypress.config.ts'] + const files = ['cypress/integration/spec.ts', 'cypress/plugins/index.ts', 'cypress/support/commands.ts', 'cypress/support/index.ts', 'cypress/tsconfig.json', 'cypress.config.js'] const homePath = '/projects/sandbox/' return schematicRunner.runSchematicAsync('ng-add', {}, appTree).toPromise().then((tree) => { diff --git a/npm/cypress-schematic/src/schematics/ng-add/index.ts b/npm/cypress-schematic/src/schematics/ng-add/index.ts index 23979cd2c782..6391a3148c28 100644 --- a/npm/cypress-schematic/src/schematics/ng-add/index.ts +++ b/npm/cypress-schematic/src/schematics/ng-add/index.ts @@ -233,10 +233,11 @@ function modifyAngularJson (options: any): Rule { export const getCypressConfigFile = (angularJsonVal: any, projectName: string) => { const project = angularJsonVal.projects[projectName] - const tsConfig = project?.architect?.lint?.options?.tsConfig + // const tsConfig = project?.architect?.lint?.options?.tsConfig if (project.root) { - return `${project.root}/cypress.config.${tsConfig ? 'ts' : 'js'}` + return `${project.root}/cypress.config.js` + // return `${project.root}/cypress.config.${tsConfig ? 'ts' : 'js'}` } return null From 2f183ba9556d592ffb09c7b0bc1576e729c2497f Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 26 Oct 2021 16:34:37 -0500 Subject: [PATCH 20/57] Revert change --- npm/cypress-schematic/src/schematics/ng-add/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/npm/cypress-schematic/src/schematics/ng-add/index.ts b/npm/cypress-schematic/src/schematics/ng-add/index.ts index 6391a3148c28..23979cd2c782 100644 --- a/npm/cypress-schematic/src/schematics/ng-add/index.ts +++ b/npm/cypress-schematic/src/schematics/ng-add/index.ts @@ -233,11 +233,10 @@ function modifyAngularJson (options: any): Rule { export const getCypressConfigFile = (angularJsonVal: any, projectName: string) => { const project = angularJsonVal.projects[projectName] - // const tsConfig = project?.architect?.lint?.options?.tsConfig + const tsConfig = project?.architect?.lint?.options?.tsConfig if (project.root) { - return `${project.root}/cypress.config.js` - // return `${project.root}/cypress.config.${tsConfig ? 'ts' : 'js'}` + return `${project.root}/cypress.config.${tsConfig ? 'ts' : 'js'}` } return null From c7904084240047de25f4bc5de30bcd4a7b3103b1 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 26 Oct 2021 17:59:44 -0500 Subject: [PATCH 21/57] Handle cypress.json files --- .../cypress/e2e/support/e2eProjectDirs.ts | 2 ++ packages/server/lib/configFiles.ts | 2 ++ packages/server/lib/errors.js | 14 +++++++++++++ packages/server/lib/project_utils.ts | 18 ++++++++++++++--- system-tests/__snapshots__/config_spec.js | 18 +++++++++++++++++ .../projects/config-with-json/cypress.json | 7 +++++++ .../cypress.config.js | 7 +++++++ .../multiples-config-with-json/cypress.json | 7 +++++++ system-tests/test/config_spec.js | 20 +++++++++++++++++++ 9 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 system-tests/projects/config-with-json/cypress.json create mode 100644 system-tests/projects/multiples-config-with-json/cypress.config.js create mode 100644 system-tests/projects/multiples-config-with-json/cypress.json diff --git a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts index ea9d637c7075..e7017479f46f 100644 --- a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts +++ b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts @@ -10,6 +10,7 @@ export const e2eProjectDirs = [ 'config-with-invalid-browser', 'config-with-invalid-viewport', 'config-with-js', + 'config-with-json', 'config-with-short-timeout', 'config-with-ts', 'cookies', @@ -26,6 +27,7 @@ export const e2eProjectDirs = [ 'integration-outside-project-root', 'issue-8111-iframe-input', 'max-listeners', + 'multiples-config-with-json', 'multiple-task-registrations', 'no-scaffolding', 'no-server', diff --git a/packages/server/lib/configFiles.ts b/packages/server/lib/configFiles.ts index 3989758e5251..de1b7c53351d 100644 --- a/packages/server/lib/configFiles.ts +++ b/packages/server/lib/configFiles.ts @@ -1,2 +1,4 @@ // the first file is the default created file export const CYPRESS_CONFIG_FILES = ['cypress.config.js', 'cypress.config.ts'] + +export const LEGACY_CONFIG_FILE = 'cypress.json' diff --git a/packages/server/lib/errors.js b/packages/server/lib/errors.js index 3f0cf79b69da..131b79251961 100644 --- a/packages/server/lib/errors.js +++ b/packages/server/lib/errors.js @@ -700,6 +700,20 @@ const getMsgByType = function (type, arg1 = {}, arg2, arg3) { Could not find a Cypress configuration file, exiting. We looked but did not find a default config file in this folder: ${chalk.blue(arg1)}` + case 'CONFIG_FILE_MIGRATION_NEEDED': + return stripIndent` + There is both a cypress.json file ar the location below: + ${arg1} + + Cypress does not support any more 'cypress.json' config, migrate to 'cypress.config.{ts|js}'. + ` + case 'LEGACY_CONFIG_FILE': + return stripIndent` + There is both a \`${arg2}\` and a cypress.json file at the location below: + ${arg1} + + Cypress does not support any more 'cypress.json' config, remove it from your files. + ` // TODO: update with vetted cypress language case 'CONFIG_FILES_LANGUAGE_CONFLICT': return stripIndent` diff --git a/packages/server/lib/project_utils.ts b/packages/server/lib/project_utils.ts index f72c08de6e4a..bb87d22ceb9a 100644 --- a/packages/server/lib/project_utils.ts +++ b/packages/server/lib/project_utils.ts @@ -5,7 +5,7 @@ import * as settings from './util/settings' import errors from './errors' import { fs } from './util/fs' import { escapeFilenameInUrl } from './util/escape_filename' -import { CYPRESS_CONFIG_FILES } from './configFiles' +import { CYPRESS_CONFIG_FILES, LEGACY_CONFIG_FILE } from './configFiles' const debug = Debug('cypress:server:project_utils') @@ -136,15 +136,27 @@ export const checkSupportFile = async ({ export async function getDefaultConfigFilePath (projectRoot: string, returnDefaultValueIfNotFound: boolean = true): Promise { const filesInProjectDir = await fs.readdir(projectRoot) - const foundConfigFiles = CYPRESS_CONFIG_FILES.filter((file) => filesInProjectDir.includes(file)) + const foundConfigFiles = [...CYPRESS_CONFIG_FILES, LEGACY_CONFIG_FILE].filter((file) => filesInProjectDir.includes(file)) // if we only found one default file, it is the one if (foundConfigFiles.length === 1) { - return foundConfigFiles[0] + const configFile = foundConfigFiles[0] + + if (configFile === LEGACY_CONFIG_FILE) { + throw errors.throw('CONFIG_FILE_MIGRATION_NEEDED', projectRoot, configFile) + } + + return configFile } // if we found more than one, throw a language conflict if (foundConfigFiles.length > 1) { + if (foundConfigFiles.includes(LEGACY_CONFIG_FILE)) { + const foundFiles = foundConfigFiles.filter((f) => f !== LEGACY_CONFIG_FILE) + + throw errors.throw('LEGACY_CONFIG_FILE', projectRoot, ...foundFiles) + } + throw errors.throw('CONFIG_FILES_LANGUAGE_CONFLICT', projectRoot, ...foundConfigFiles) } diff --git a/system-tests/__snapshots__/config_spec.js b/system-tests/__snapshots__/config_spec.js index 4ac0a778537d..57c83f453305 100644 --- a/system-tests/__snapshots__/config_spec.js +++ b/system-tests/__snapshots__/config_spec.js @@ -160,4 +160,22 @@ There is both a \`cypress.config.js\` and a \`cypress.config.ts\` at the locatio Cypress does not know which one to read for config. Please remove one of the two and try again. +` + +exports['e2e config throws error when cypress.json is found in project and need migration 1'] = ` +There is both a cypress.json file ar the location below: +/foo/bar/.projects/config-with-json + +Cypress does not support any more 'cypress.json' config, migrate to 'cypress.config.{ts|js}'. + + +` + +exports['e2e config throws error when cypress.json is found in project and cypress.config.{ts|js} exists as well 1'] = ` +There is both a \`cypress.config.js\` and a cypress.json file at the location below: +/foo/bar/.projects/multiples-config-with-json + +Cypress does not support any more 'cypress.json' config, remove it from your files. + + ` diff --git a/system-tests/projects/config-with-json/cypress.json b/system-tests/projects/config-with-json/cypress.json new file mode 100644 index 000000000000..8ad5c80f7eab --- /dev/null +++ b/system-tests/projects/config-with-json/cypress.json @@ -0,0 +1,7 @@ +{ + "pageLoadTimeout": 10000, + "e2e": { + "defaultCommandTimeout": 500, + "videoCompression": 20 + } +} \ No newline at end of file diff --git a/system-tests/projects/multiples-config-with-json/cypress.config.js b/system-tests/projects/multiples-config-with-json/cypress.config.js new file mode 100644 index 000000000000..d95722d5dddc --- /dev/null +++ b/system-tests/projects/multiples-config-with-json/cypress.config.js @@ -0,0 +1,7 @@ +module.exports = { + pageLoadTimeout: 10000, + e2e: { + defaultCommandTimeout: 500, + videoCompression: 20, + }, +} diff --git a/system-tests/projects/multiples-config-with-json/cypress.json b/system-tests/projects/multiples-config-with-json/cypress.json new file mode 100644 index 000000000000..8ad5c80f7eab --- /dev/null +++ b/system-tests/projects/multiples-config-with-json/cypress.json @@ -0,0 +1,7 @@ +{ + "pageLoadTimeout": 10000, + "e2e": { + "defaultCommandTimeout": 500, + "videoCompression": 20 + } +} \ No newline at end of file diff --git a/system-tests/test/config_spec.js b/system-tests/test/config_spec.js index c39a9eebff95..63a67da02d7f 100644 --- a/system-tests/test/config_spec.js +++ b/system-tests/test/config_spec.js @@ -90,4 +90,24 @@ describe('e2e config', () => { }) }) }) + + it('throws error when cypress.json is found in project and need migration', function () { + const projectRoot = Fixtures.projectPath('config-with-json') + + return systemTests.exec(this, { + project: projectRoot, + expectedExitCode: 1, + snapshot: true, + }) + }) + + it('throws error when cypress.json is found in project and cypress.config.{ts|js} exists as well', function () { + const projectRoot = Fixtures.projectPath('multiples-config-with-json') + + return systemTests.exec(this, { + project: projectRoot, + expectedExitCode: 1, + snapshot: true, + }) + }) }) From deaf156f8f26e1da1ad1f355a59c302464bd7375 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 26 Oct 2021 19:09:41 -0500 Subject: [PATCH 22/57] Add e2e tests --- .../data-context/src/actions/FileActions.ts | 8 ++ .../cypress/e2e/support/e2eProjectDirs.ts | 2 +- .../config-files-error-handling.spec.ts | 75 +++++++++++++++++++ system-tests/__snapshots__/config_spec.js | 2 +- .../cypress.config.js | 1 + .../cypress.json | 0 .../cypress.config.js | 7 -- system-tests/test/config_spec.js | 2 +- 8 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts create mode 100644 system-tests/projects/multiples-config-files-with-json/cypress.config.js rename system-tests/projects/{multiples-config-with-json => multiples-config-files-with-json}/cypress.json (100%) delete mode 100644 system-tests/projects/multiples-config-with-json/cypress.config.js diff --git a/packages/data-context/src/actions/FileActions.ts b/packages/data-context/src/actions/FileActions.ts index 59a1ad4e0924..b6501957c353 100644 --- a/packages/data-context/src/actions/FileActions.ts +++ b/packages/data-context/src/actions/FileActions.ts @@ -15,4 +15,12 @@ export class FileActions { data, ) } + + async removeFileInProject (relativePath: string) { + if (!this.ctx.activeProject) { + throw new Error(`Cannot remove file in project without active project`) + } + + await this.ctx.fs.remove(path.join(this.ctx.activeProject?.projectRoot, relativePath)) + } } diff --git a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts index e7017479f46f..437844619407 100644 --- a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts +++ b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts @@ -27,7 +27,7 @@ export const e2eProjectDirs = [ 'integration-outside-project-root', 'issue-8111-iframe-input', 'max-listeners', - 'multiples-config-with-json', + 'multiples-config-files-with-json', 'multiple-task-registrations', 'no-scaffolding', 'no-server', diff --git a/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts b/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts new file mode 100644 index 000000000000..531a6e4805e6 --- /dev/null +++ b/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts @@ -0,0 +1,75 @@ +describe('Config files error handling', () => { + it('it handles multiples config files', () => { + cy.setupE2E('pristine') + cy.visitLaunchpad() + + cy.withCtx(async (ctx) => { + await Promise.all([ + ctx.actions.file.writeFileInProject('cypress.config.js', 'module.exports = {}'), + ctx.actions.file.writeFileInProject('cypress.config.ts', 'export default {}'), + ]) + }) + + cy.get('[data-cy-testingType=e2e]').click() + cy.wait(2000) + + cy.get('body') + .should('contain.text', 'Cypress Configuration Error') + .and('contain.text', 'There is both a `cypress.config.js` and a `cypress.config.ts` at the location below') + + cy.withCtx(async (ctx) => { + await ctx.actions.file.removeFileInProject('cypress.config.js') + }) + + cy.get('[data-testid=error-retry-button]').click() + cy.wait(2000) + + cy.get('body') + .should('not.contain.text', 'Cypress Configuration Error') + }) + + it('it handles legacy config file', () => { + cy.setupE2E('config-with-json') + cy.visitLaunchpad() + + cy.get('[data-cy-testingType=e2e]').click() + cy.wait(2000) + + cy.get('body') + .should('contain.text', 'Cypress Configuration Error') + .and('contain.text', 'There is both a `cypress.config.js` and a cypress.json file at the location below') + + cy.withCtx(async (ctx) => { + await ctx.actions.file.removeFileInProject('cypress.json') + }) + + cy.get('[data-testid=error-retry-button]').click() + cy.wait(2000) + + cy.get('body') + .should('not.contain.text', 'Cypress Configuration Error') + }) + + it('it handles config files with legacy config file in same project', () => { + cy.setupE2E('multiples-config-files-with-json') + cy.visitLaunchpad() + + cy.get('[data-cy-testingType=e2e]').click() + + cy.wait(2000) + + cy.get('body') + .should('contain.text', 'Cypress Configuration Error') + .and('contain.text', 'There is both a `cypress.config.js` and a cypress.json file at the location below') + + cy.withCtx(async (ctx) => { + await ctx.actions.file.removeFileInProject('cypress.json') + }) + + cy.get('[data-testid=error-retry-button]').click() + cy.wait(2000) + + cy.get('body') + .should('not.contain.text', 'Cypress Configuration Error') + }) +}) diff --git a/system-tests/__snapshots__/config_spec.js b/system-tests/__snapshots__/config_spec.js index 57c83f453305..cf4907f5a052 100644 --- a/system-tests/__snapshots__/config_spec.js +++ b/system-tests/__snapshots__/config_spec.js @@ -173,7 +173,7 @@ Cypress does not support any more 'cypress.json' config, migrate to 'cypress.con exports['e2e config throws error when cypress.json is found in project and cypress.config.{ts|js} exists as well 1'] = ` There is both a \`cypress.config.js\` and a cypress.json file at the location below: -/foo/bar/.projects/multiples-config-with-json +/foo/bar/.projects/multiples-config-files-with-json Cypress does not support any more 'cypress.json' config, remove it from your files. diff --git a/system-tests/projects/multiples-config-files-with-json/cypress.config.js b/system-tests/projects/multiples-config-files-with-json/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/multiples-config-files-with-json/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/multiples-config-with-json/cypress.json b/system-tests/projects/multiples-config-files-with-json/cypress.json similarity index 100% rename from system-tests/projects/multiples-config-with-json/cypress.json rename to system-tests/projects/multiples-config-files-with-json/cypress.json diff --git a/system-tests/projects/multiples-config-with-json/cypress.config.js b/system-tests/projects/multiples-config-with-json/cypress.config.js deleted file mode 100644 index d95722d5dddc..000000000000 --- a/system-tests/projects/multiples-config-with-json/cypress.config.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - pageLoadTimeout: 10000, - e2e: { - defaultCommandTimeout: 500, - videoCompression: 20, - }, -} diff --git a/system-tests/test/config_spec.js b/system-tests/test/config_spec.js index 63a67da02d7f..c38d4538549e 100644 --- a/system-tests/test/config_spec.js +++ b/system-tests/test/config_spec.js @@ -102,7 +102,7 @@ describe('e2e config', () => { }) it('throws error when cypress.json is found in project and cypress.config.{ts|js} exists as well', function () { - const projectRoot = Fixtures.projectPath('multiples-config-with-json') + const projectRoot = Fixtures.projectPath('multiples-config-files-with-json') return systemTests.exec(this, { project: projectRoot, From cf0476ce1b578ef611af8cf4d7a532a2fa3586b7 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Wed, 27 Oct 2021 10:41:24 -0500 Subject: [PATCH 23/57] Remove write when config file do not exist --- packages/server/lib/util/settings.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index be2ac6505a8a..0c505cd8dc47 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -149,11 +149,7 @@ export function read (projectRoot, options: SettingsOptions = {}) { }) .catch((err) => { if (err.type === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') { - if (options.args?.runProject) { - return Promise.reject(errors.get('CONFIG_FILE_NOT_FOUND', options.configFile, projectRoot)) - } - - return _write(file, {}) + return Promise.reject(errors.get('CONFIG_FILE_NOT_FOUND', options.configFile, projectRoot)) } return Promise.reject(err) From 07dc4d5131081b980de433e05129def508d3a92f Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Wed, 27 Oct 2021 14:20:55 -0500 Subject: [PATCH 24/57] Fix tests --- .../src/sources/ProjectDataSource.ts | 17 ++++++-- .../cypress/e2e/support/e2eProjectDirs.ts | 1 - .../config-files-error-handling.spec.ts | 15 +++---- packages/server/lib/project-base.ts | 2 +- packages/server/lib/project_utils.ts | 8 +--- .../server/test/integration/cypress_spec.js | 39 +++++++------------ packages/server/test/unit/project_spec.js | 7 ++-- .../server/test/unit/project_utils_spec.ts | 9 +---- system-tests/__snapshots__/config_spec.js | 2 +- .../projects/config-with-json/cypress.json | 7 ---- system-tests/test/config_spec.js | 19 +++++---- 11 files changed, 52 insertions(+), 74 deletions(-) delete mode 100644 system-tests/projects/config-with-json/cypress.json diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index 7278fe89de5e..67b9615ad6ac 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -60,17 +60,28 @@ export class ProjectDataSource { const foundConfigFiles = cypressConfigFiles.filter((file) => filesInProjectDir.includes(file)) - // if we only found one default file, it is the one if (foundConfigFiles.length === 1) { - return foundConfigFiles[0] + const configFile = foundConfigFiles[0] + + if (configFile === 'cypress.json') { + throw this.ctx._apis.projectApi.error('CONFIG_FILE_MIGRATION_NEEDED', projectRoot, configFile) + } + + return configFile } // if we found more than one, throw a language conflict if (foundConfigFiles.length > 1) { + if (foundConfigFiles.includes('cypress.json')) { + const foundFiles = foundConfigFiles.filter((f) => f !== 'cypress.json') + + throw this.ctx._apis.projectApi.error('LEGACY_CONFIG_FILE', projectRoot, ...foundFiles) + } + throw this.ctx._apis.projectApi.error('CONFIG_FILES_LANGUAGE_CONFLICT', projectRoot, ...foundConfigFiles) } - return cypressConfigFiles[0] + throw this.ctx._apis.projectApi.error('NO_DEFAULT_CONFIG_FILE_FOUND', projectRoot) } async getConfig (projectRoot: string) { diff --git a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts index 437844619407..5f48a0a12215 100644 --- a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts +++ b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts @@ -10,7 +10,6 @@ export const e2eProjectDirs = [ 'config-with-invalid-browser', 'config-with-invalid-viewport', 'config-with-js', - 'config-with-json', 'config-with-short-timeout', 'config-with-ts', 'cookies', diff --git a/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts b/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts index 531a6e4805e6..6827d0a29741 100644 --- a/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts +++ b/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts @@ -1,13 +1,10 @@ describe('Config files error handling', () => { it('it handles multiples config files', () => { - cy.setupE2E('pristine') + cy.setupE2E('config-with-js') cy.visitLaunchpad() cy.withCtx(async (ctx) => { - await Promise.all([ - ctx.actions.file.writeFileInProject('cypress.config.js', 'module.exports = {}'), - ctx.actions.file.writeFileInProject('cypress.config.ts', 'export default {}'), - ]) + await ctx.actions.file.writeFileInProject('cypress.config.ts', 'export default {}') }) cy.get('[data-cy-testingType=e2e]').click() @@ -18,7 +15,7 @@ describe('Config files error handling', () => { .and('contain.text', 'There is both a `cypress.config.js` and a `cypress.config.ts` at the location below') cy.withCtx(async (ctx) => { - await ctx.actions.file.removeFileInProject('cypress.config.js') + await ctx.actions.file.removeFileInProject('cypress.config.ts') }) cy.get('[data-testid=error-retry-button]').click() @@ -29,9 +26,13 @@ describe('Config files error handling', () => { }) it('it handles legacy config file', () => { - cy.setupE2E('config-with-json') + cy.setupE2E('config-with-js') cy.visitLaunchpad() + cy.withCtx(async (ctx) => { + await ctx.actions.file.writeFileInProject('cypress.json', '{}') + }) + cy.get('[data-cy-testingType=e2e]').click() cy.wait(2000) diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index daa44850ee37..80a166d5a214 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -703,7 +703,7 @@ export class ProjectBase extends EE { async initializeConfig (browsers: FoundBrowser[] = []): Promise { // set default for "configFile" if undefined if (this.options.configFile === undefined || this.options.configFile === null) { - this.options.configFile = await getDefaultConfigFilePath(this.projectRoot, !this.options.args?.runProject) + this.options.configFile = await getDefaultConfigFilePath(this.projectRoot) } let theCfg: Cfg = await config.get(this.projectRoot, this.options) diff --git a/packages/server/lib/project_utils.ts b/packages/server/lib/project_utils.ts index bb87d22ceb9a..f4de7a4238b3 100644 --- a/packages/server/lib/project_utils.ts +++ b/packages/server/lib/project_utils.ts @@ -133,7 +133,7 @@ export const checkSupportFile = async ({ return } -export async function getDefaultConfigFilePath (projectRoot: string, returnDefaultValueIfNotFound: boolean = true): Promise { +export async function getDefaultConfigFilePath (projectRoot: string): Promise { const filesInProjectDir = await fs.readdir(projectRoot) const foundConfigFiles = [...CYPRESS_CONFIG_FILES, LEGACY_CONFIG_FILE].filter((file) => filesInProjectDir.includes(file)) @@ -160,11 +160,5 @@ export async function getDefaultConfigFilePath (projectRoot: string, returnDefau throw errors.throw('CONFIG_FILES_LANGUAGE_CONFLICT', projectRoot, ...foundConfigFiles) } - // TODO: Should we check if there's a tsConfig to create the correct file? - if (returnDefaultValueIfNotFound) { - // Default is to create a new `cypress.config.ts` file if one does not exist. - return CYPRESS_CONFIG_FILES[0] - } - throw errors.get('NO_DEFAULT_CONFIG_FILE_FOUND', projectRoot) } diff --git a/packages/server/test/integration/cypress_spec.js b/packages/server/test/integration/cypress_spec.js index 6c40f55747f8..1a1063b1c27c 100644 --- a/packages/server/test/integration/cypress_spec.js +++ b/packages/server/test/integration/cypress_spec.js @@ -12,7 +12,6 @@ const commitInfo = require('@cypress/commit-info') const Fixtures = require('@tooling/system-tests/lib/fixtures') const snapshot = require('snap-shot-it') const stripAnsi = require('strip-ansi') -const debug = require('debug')('test') const pkg = require('@packages/root') const detect = require('@packages/launcher/lib/detect') const launch = require('@packages/launcher/lib/browsers') @@ -457,7 +456,10 @@ describe('lib/cypress', () => { }) it('scaffolds out integration and example specs if they do not exist when not runMode', function () { - return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) + return fs.writeFileAsync(path.join(this.pristinePath, 'cypress.config.js'), 'module.exports = {}') + .then(() => { + return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) + }) .then((cfg) => { return fs.statAsync(cfg.integrationFolder) .then(() => { @@ -505,7 +507,7 @@ describe('lib/cypress', () => { }) it('does not scaffold integration or example specs when runMode', function () { - return settings.write(this.pristinePath, {}, { configFile: 'cypress.config.js' }) + return fs.writeFileAsync(path.join(this.pristinePath, 'cypress.config.js'), 'module.exports = {}') .then(() => { return cypress.start([`--run-project=${this.pristinePath}`]) }).then(() => { @@ -520,7 +522,10 @@ describe('lib/cypress', () => { }) it('scaffolds out fixtures + files if they do not exist', function () { - return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) + return fs.writeFileAsync(path.join(this.pristinePath, 'cypress.config.js'), 'module.exports = {}') + .then(() => { + return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) + }) .then((cfg) => { return fs.statAsync(cfg.fixturesFolder) .then(() => { @@ -538,7 +543,10 @@ describe('lib/cypress', () => { it('scaffolds out support + files if they do not exist', function () { const supportFolder = path.join(this.pristinePath, 'cypress/support') - return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) + return fs.writeFileAsync(path.join(this.pristinePath, 'cypress.config.js'), 'module.exports = {}') + .then(() => { + return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) + }) .then(() => { return fs.statAsync(supportFolder) .then(() => { @@ -1823,27 +1831,6 @@ describe('lib/cypress', () => { }) }) }) - - it('creates custom config file if it does not exist', function () { - return cypress.start([ - `--config-file=${this.filename}`, - ]) - .then(() => { - debug('cypress started with config %s', this.filename) - const options = Events.start.firstCall.args[0] - - debug('first call arguments %o', Events.start.firstCall.args) - - return Events.handleEvent(options, {}, {}, 123, 'open:project', this.pristinePath) - }).then(() => { - expect(this.open, 'open was called').to.be.called - - return fs.readJsonAsync(path.join(this.pristinePath, this.filename)) - .then((json) => { - expect(json, 'json file is empty').to.deep.equal({}) - }) - }) - }) }) }) diff --git a/packages/server/test/unit/project_spec.js b/packages/server/test/unit/project_spec.js index baceb23364c3..b62e5b8e262a 100644 --- a/packages/server/test/unit/project_spec.js +++ b/packages/server/test/unit/project_spec.js @@ -44,6 +44,7 @@ describe('lib/project-base', () => { this.todosPath = Fixtures.projectPath('todos') this.idsPath = Fixtures.projectPath('ids') this.pristinePath = Fixtures.projectPath('pristine') + this.configWithJsPath = Fixtures.projectPath('config-with-js') sinon.stub(scaffold, 'isNewProject').resolves(false) sinon.stub(chokidar, 'watch').returns({ @@ -91,7 +92,7 @@ describe('lib/project-base', () => { sinon.stub(ServerE2E.prototype, 'open').resolves([]) sinon.stub(ProjectBase.prototype, 'startCtDevServer').resolves({ port: 9999 }) - const projectCt = new ProjectBase({ projectRoot: this.pristinePath, testingType: 'component' }) + const projectCt = new ProjectBase({ projectRoot: this.configWithJsPath, testingType: 'component' }) await projectCt.initializeConfig() @@ -978,11 +979,11 @@ This option will not have an effect in Some-other-name. Tests that rely on web s it('returns object containing path and id', function () { sinon.stub(settings, 'read').resolves({ projectId: 'id-123' }) - return add(this.pristinePath, {}) + return add(this.configWithJsPath, {}) .then((project) => { expect(project.id).to.equal('id-123') - expect(project.path).to.equal(this.pristinePath) + expect(project.path).to.equal(this.configWithJsPath) }) }) }) diff --git a/packages/server/test/unit/project_utils_spec.ts b/packages/server/test/unit/project_utils_spec.ts index c5494fbecfcc..dd22774515b3 100644 --- a/packages/server/test/unit/project_utils_spec.ts +++ b/packages/server/test/unit/project_utils_spec.ts @@ -146,13 +146,6 @@ describe('lib/project_utils', () => { expect(ret).to.equal('cypress.config.js') }) - it('defaults to cypress.config.js when no file is returned', async () => { - readdirStub.withArgs(projectRoot).resolves([]) - const ret = await getDefaultConfigFilePath(projectRoot) - - expect(ret).to.equal('cypress.config.js') - }) - it('errors if two default files are present', async () => { readdirStub.withArgs(projectRoot).resolves(['cypress.config.js', 'cypress.config.ts']) try { @@ -166,7 +159,7 @@ describe('lib/project_utils', () => { it('errors if no file is present and we asked not to create any', async () => { readdirStub.withArgs(projectRoot).resolves([]) try { - await getDefaultConfigFilePath(projectRoot, false) + await getDefaultConfigFilePath(projectRoot) throw Error('should have failed') } catch (err) { expect(err).to.have.property('type', 'NO_DEFAULT_CONFIG_FILE_FOUND') diff --git a/system-tests/__snapshots__/config_spec.js b/system-tests/__snapshots__/config_spec.js index cf4907f5a052..0ecbc04f1dc2 100644 --- a/system-tests/__snapshots__/config_spec.js +++ b/system-tests/__snapshots__/config_spec.js @@ -164,7 +164,7 @@ Cypress does not know which one to read for config. Please remove one of the two exports['e2e config throws error when cypress.json is found in project and need migration 1'] = ` There is both a cypress.json file ar the location below: -/foo/bar/.projects/config-with-json +/foo/bar/.projects/config-with-js Cypress does not support any more 'cypress.json' config, migrate to 'cypress.config.{ts|js}'. diff --git a/system-tests/projects/config-with-json/cypress.json b/system-tests/projects/config-with-json/cypress.json deleted file mode 100644 index 8ad5c80f7eab..000000000000 --- a/system-tests/projects/config-with-json/cypress.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "pageLoadTimeout": 10000, - "e2e": { - "defaultCommandTimeout": 500, - "videoCompression": 20 - } -} \ No newline at end of file diff --git a/system-tests/test/config_spec.js b/system-tests/test/config_spec.js index c38d4538549e..fc195281d0a8 100644 --- a/system-tests/test/config_spec.js +++ b/system-tests/test/config_spec.js @@ -77,12 +77,9 @@ describe('e2e config', () => { }) it('throws error when multiple default config file are found in project', function () { - const projectRoot = Fixtures.projectPath('pristine') + const projectRoot = Fixtures.projectPath('config-with-js') - return Promise.all([ - fs.writeFile(path.join(projectRoot, 'cypress.config.js'), 'module.exports = {}'), - fs.writeFile(path.join(projectRoot, 'cypress.config.ts'), 'export default {}'), - ]).then(() => { + return fs.writeFile(path.join(projectRoot, 'cypress.config.ts'), 'export default {}').then(() => { return systemTests.exec(this, { project: projectRoot, expectedExitCode: 1, @@ -92,12 +89,14 @@ describe('e2e config', () => { }) it('throws error when cypress.json is found in project and need migration', function () { - const projectRoot = Fixtures.projectPath('config-with-json') + const projectRoot = Fixtures.projectPath('config-with-js') - return systemTests.exec(this, { - project: projectRoot, - expectedExitCode: 1, - snapshot: true, + return fs.writeFile(path.join(projectRoot, 'cypress.json'), '{}').then(() => { + return systemTests.exec(this, { + project: projectRoot, + expectedExitCode: 1, + snapshot: true, + }) }) }) From 01891c1b15e41b974cabe3d5a6645802db7bc9c8 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Wed, 27 Oct 2021 14:55:35 -0500 Subject: [PATCH 25/57] Fix tests --- .../cypress/e2e/support/e2eProjectDirs.ts | 1 + .../server/test/integration/cypress_spec.js | 30 +++++++------------ packages/server/test/unit/project_spec.js | 7 ++--- packages/server/test/unit/scaffold_spec.js | 12 ++++---- .../projects/pristine-with-config-file/app.js | 0 .../cypress.config.js | 1 + 6 files changed, 21 insertions(+), 30 deletions(-) create mode 100644 system-tests/projects/pristine-with-config-file/app.js create mode 100644 system-tests/projects/pristine-with-config-file/cypress.config.js diff --git a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts index 5f48a0a12215..4d903fba6cd5 100644 --- a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts +++ b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts @@ -54,6 +54,7 @@ export const e2eProjectDirs = [ 'plugins-async-error', 'plugins-root-async-error', 'pristine', + 'pristine-with-config-file', 'read-only-project-root', 'record', 'remote-debugging-disconnect', diff --git a/packages/server/test/integration/cypress_spec.js b/packages/server/test/integration/cypress_spec.js index 1a1063b1c27c..4fac28a289fd 100644 --- a/packages/server/test/integration/cypress_spec.js +++ b/packages/server/test/integration/cypress_spec.js @@ -115,6 +115,7 @@ describe('lib/cypress', () => { Fixtures.scaffold() this.todosPath = Fixtures.projectPath('todos') this.pristinePath = Fixtures.projectPath('pristine') + this.pristineWithConfigPath = Fixtures.projectPath('pristine-with-config-file') this.noScaffolding = Fixtures.projectPath('no-scaffolding') this.recordPath = Fixtures.projectPath('record') this.pluginConfig = Fixtures.projectPath('plugin-config') @@ -456,16 +457,13 @@ describe('lib/cypress', () => { }) it('scaffolds out integration and example specs if they do not exist when not runMode', function () { - return fs.writeFileAsync(path.join(this.pristinePath, 'cypress.config.js'), 'module.exports = {}') - .then(() => { - return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) - }) + return config.get(this.pristineWithConfigPath, { configFile: 'cypress.config.js' }) .then((cfg) => { return fs.statAsync(cfg.integrationFolder) .then(() => { throw new Error('integrationFolder should not exist!') }).catch(() => { - return cypress.start([`--run-project=${this.pristinePath}`, '--no-run-mode']) + return cypress.start([`--run-project=${this.pristineWithConfigPath}`, '--no-run-mode']) }).then(() => { return fs.statAsync(cfg.integrationFolder) }).then(() => { @@ -507,11 +505,9 @@ describe('lib/cypress', () => { }) it('does not scaffold integration or example specs when runMode', function () { - return fs.writeFileAsync(path.join(this.pristinePath, 'cypress.config.js'), 'module.exports = {}') + return cypress.start([`--run-project=${this.pristineWithConfigPath}`]) .then(() => { - return cypress.start([`--run-project=${this.pristinePath}`]) - }).then(() => { - return fs.statAsync(path.join(this.pristinePath, 'cypress', 'integration')) + return fs.statAsync(path.join(this.pristineWithConfigPath, 'cypress', 'integration')) }).then(() => { throw new Error('integration folder should not exist!') }).catch((err) => { @@ -522,16 +518,13 @@ describe('lib/cypress', () => { }) it('scaffolds out fixtures + files if they do not exist', function () { - return fs.writeFileAsync(path.join(this.pristinePath, 'cypress.config.js'), 'module.exports = {}') - .then(() => { - return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) - }) + return config.get(this.pristineWithConfigPath, { configFile: 'cypress.config.js' }) .then((cfg) => { return fs.statAsync(cfg.fixturesFolder) .then(() => { throw new Error('fixturesFolder should not exist!') }).catch(() => { - return cypress.start([`--run-project=${this.pristinePath}`, '--no-run-mode']) + return cypress.start([`--run-project=${this.pristineWithConfigPath}`, '--no-run-mode']) }).then(() => { return fs.statAsync(cfg.fixturesFolder) }).then(() => { @@ -541,18 +534,15 @@ describe('lib/cypress', () => { }) it('scaffolds out support + files if they do not exist', function () { - const supportFolder = path.join(this.pristinePath, 'cypress/support') + const supportFolder = path.join(this.pristineWithConfigPath, 'cypress/support') - return fs.writeFileAsync(path.join(this.pristinePath, 'cypress.config.js'), 'module.exports = {}') - .then(() => { - return config.get(this.pristinePath, { configFile: 'cypress.config.js' }) - }) + return config.get(this.pristineWithConfigPath, { configFile: 'cypress.config.js' }) .then(() => { return fs.statAsync(supportFolder) .then(() => { throw new Error('supportFolder should not exist!') }).catch({ code: 'ENOENT' }, () => { - return cypress.start([`--run-project=${this.pristinePath}`, '--no-run-mode']) + return cypress.start([`--run-project=${this.pristineWithConfigPath}`, '--no-run-mode']) }).then(() => { return fs.statAsync(supportFolder) }).then(() => { diff --git a/packages/server/test/unit/project_spec.js b/packages/server/test/unit/project_spec.js index b62e5b8e262a..1a7b4da83dea 100644 --- a/packages/server/test/unit/project_spec.js +++ b/packages/server/test/unit/project_spec.js @@ -43,8 +43,7 @@ describe('lib/project-base', () => { this.todosPath = Fixtures.projectPath('todos') this.idsPath = Fixtures.projectPath('ids') - this.pristinePath = Fixtures.projectPath('pristine') - this.configWithJsPath = Fixtures.projectPath('config-with-js') + this.pristinePath = Fixtures.projectPath('pristine-with-config-file') sinon.stub(scaffold, 'isNewProject').resolves(false) sinon.stub(chokidar, 'watch').returns({ @@ -92,7 +91,7 @@ describe('lib/project-base', () => { sinon.stub(ServerE2E.prototype, 'open').resolves([]) sinon.stub(ProjectBase.prototype, 'startCtDevServer').resolves({ port: 9999 }) - const projectCt = new ProjectBase({ projectRoot: this.configWithJsPath, testingType: 'component' }) + const projectCt = new ProjectBase({ projectRoot: this.pristinePath, testingType: 'component' }) await projectCt.initializeConfig() @@ -965,7 +964,7 @@ This option will not have an effect in Some-other-name. Tests that rely on web s context('.add', () => { beforeEach(function () { - this.pristinePath = Fixtures.projectPath('pristine') + this.pristinePath = Fixtures.projectPath('pristine-with-config-file') }) it('inserts path into cache', function () { diff --git a/packages/server/test/unit/scaffold_spec.js b/packages/server/test/unit/scaffold_spec.js index fbc18f1e18eb..e880242e1cf2 100644 --- a/packages/server/test/unit/scaffold_spec.js +++ b/packages/server/test/unit/scaffold_spec.js @@ -22,7 +22,7 @@ describe('lib/scaffold', () => { context('.isNewProject', () => { beforeEach(function () { - this.pristinePath = Fixtures.projectPath('pristine') + this.pristinePath = Fixtures.projectPath('pristine-with-config-file') }) it('is true when integrationFolder is empty', function () { @@ -129,7 +129,7 @@ describe('lib/scaffold', () => { context('.integration', () => { beforeEach(function () { - const pristinePath = Fixtures.projectPath('pristine') + const pristinePath = Fixtures.projectPath('pristine-with-config-file') return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg; @@ -212,7 +212,7 @@ describe('lib/scaffold', () => { context('.removeIntegration', () => { beforeEach(function () { - const pristinePath = Fixtures.projectPath('pristine') + const pristinePath = Fixtures.projectPath('pristine-with-config-file') return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg; @@ -323,7 +323,7 @@ describe('lib/scaffold', () => { context('.support', () => { beforeEach(function () { - const pristinePath = Fixtures.projectPath('pristine') + const pristinePath = Fixtures.projectPath('pristine-with-config-file') return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg; @@ -400,7 +400,7 @@ describe('lib/scaffold', () => { context('.plugins', () => { beforeEach(function () { - const pristinePath = Fixtures.projectPath('pristine') + const pristinePath = Fixtures.projectPath('pristine-with-config-file') return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg; @@ -456,7 +456,7 @@ describe('lib/scaffold', () => { context('.fixture', () => { beforeEach(function () { - const pristinePath = Fixtures.projectPath('pristine') + const pristinePath = Fixtures.projectPath('pristine-with-config-file') return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { this.cfg = cfg; diff --git a/system-tests/projects/pristine-with-config-file/app.js b/system-tests/projects/pristine-with-config-file/app.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/system-tests/projects/pristine-with-config-file/cypress.config.js b/system-tests/projects/pristine-with-config-file/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/pristine-with-config-file/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} From 803b1722af669d7b90ef8d1cc423bce0b0b8507f Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Wed, 27 Oct 2021 15:27:06 -0500 Subject: [PATCH 26/57] Fix tests --- .../e2e/integration/config-files-error-handling.spec.ts | 4 ++-- packages/server/test/unit/project_spec.js | 4 ++-- system-tests/__snapshots__/config_spec.js | 4 ++-- system-tests/projects/odd-directory-name/cypress.config.js | 1 + system-tests/projects/various-file-types/cypress.config.js | 1 + system-tests/test/config_spec.js | 4 ++-- 6 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 system-tests/projects/odd-directory-name/cypress.config.js create mode 100644 system-tests/projects/various-file-types/cypress.config.js diff --git a/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts b/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts index 6827d0a29741..739a7b2f58ee 100644 --- a/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts +++ b/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts @@ -1,6 +1,6 @@ describe('Config files error handling', () => { it('it handles multiples config files', () => { - cy.setupE2E('config-with-js') + cy.setupE2E('pristine-with-config-file') cy.visitLaunchpad() cy.withCtx(async (ctx) => { @@ -26,7 +26,7 @@ describe('Config files error handling', () => { }) it('it handles legacy config file', () => { - cy.setupE2E('config-with-js') + cy.setupE2E('pristine-with-config-file') cy.visitLaunchpad() cy.withCtx(async (ctx) => { diff --git a/packages/server/test/unit/project_spec.js b/packages/server/test/unit/project_spec.js index 1a7b4da83dea..62a2d6cec3e4 100644 --- a/packages/server/test/unit/project_spec.js +++ b/packages/server/test/unit/project_spec.js @@ -978,11 +978,11 @@ This option will not have an effect in Some-other-name. Tests that rely on web s it('returns object containing path and id', function () { sinon.stub(settings, 'read').resolves({ projectId: 'id-123' }) - return add(this.configWithJsPath, {}) + return add(this.pristinePath, {}) .then((project) => { expect(project.id).to.equal('id-123') - expect(project.path).to.equal(this.configWithJsPath) + expect(project.path).to.equal(this.pristinePath) }) }) }) diff --git a/system-tests/__snapshots__/config_spec.js b/system-tests/__snapshots__/config_spec.js index 0ecbc04f1dc2..ccda31c3fe80 100644 --- a/system-tests/__snapshots__/config_spec.js +++ b/system-tests/__snapshots__/config_spec.js @@ -155,7 +155,7 @@ Found an error while validating the \`browsers\` list. Expected \`family\` to be exports['e2e config throws error when multiple default config file are found in project 1'] = ` There is both a \`cypress.config.js\` and a \`cypress.config.ts\` at the location below: -/foo/bar/.projects/pristine +/foo/bar/.projects/pristine-with-config-file Cypress does not know which one to read for config. Please remove one of the two and try again. @@ -164,7 +164,7 @@ Cypress does not know which one to read for config. Please remove one of the two exports['e2e config throws error when cypress.json is found in project and need migration 1'] = ` There is both a cypress.json file ar the location below: -/foo/bar/.projects/config-with-js +/foo/bar/.projects/pristine Cypress does not support any more 'cypress.json' config, migrate to 'cypress.config.{ts|js}'. diff --git a/system-tests/projects/odd-directory-name/cypress.config.js b/system-tests/projects/odd-directory-name/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/odd-directory-name/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/projects/various-file-types/cypress.config.js b/system-tests/projects/various-file-types/cypress.config.js new file mode 100644 index 000000000000..4ba52ba2c8df --- /dev/null +++ b/system-tests/projects/various-file-types/cypress.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/system-tests/test/config_spec.js b/system-tests/test/config_spec.js index fc195281d0a8..3954734321f7 100644 --- a/system-tests/test/config_spec.js +++ b/system-tests/test/config_spec.js @@ -77,7 +77,7 @@ describe('e2e config', () => { }) it('throws error when multiple default config file are found in project', function () { - const projectRoot = Fixtures.projectPath('config-with-js') + const projectRoot = Fixtures.projectPath('pristine-with-config-file') return fs.writeFile(path.join(projectRoot, 'cypress.config.ts'), 'export default {}').then(() => { return systemTests.exec(this, { @@ -89,7 +89,7 @@ describe('e2e config', () => { }) it('throws error when cypress.json is found in project and need migration', function () { - const projectRoot = Fixtures.projectPath('config-with-js') + const projectRoot = Fixtures.projectPath('pristine') return fs.writeFile(path.join(projectRoot, 'cypress.json'), '{}').then(() => { return systemTests.exec(this, { From e677247308c88c042fa2c01cb42cea54221b2bec Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Wed, 27 Oct 2021 19:46:08 -0500 Subject: [PATCH 27/57] Update test --- .../init-component-testing.test.ts.js | 4 ++-- .../init-component-testing.test.ts | 20 +++++++++---------- .../src/installCypress.ts | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js b/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js index f9c47ba4e953..e1d70451496a 100644 --- a/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js +++ b/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js @@ -1,5 +1,5 @@ exports['injects guessed next.js template cypress.config.ts'] = ` -module.exports = {} +export default {} ` exports['injects guessed next.js template plugins/index.js'] = ` @@ -16,7 +16,7 @@ module.exports = (on, config) => { ` exports['Injected overridden webpack template cypress.config.ts'] = ` -module.exports = {} +export default {} ` exports['Injected overridden webpack template plugins/index.js'] = ` diff --git a/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts b/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts index 2ebf5978cec2..18bebe1ec1a1 100644 --- a/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts +++ b/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts @@ -91,7 +91,7 @@ describe('init component tests script', () => { it('determines more presumable configuration to suggest', async () => { createTempFiles({ - '/cypress.config.ts': 'module.exports = {}', + '/cypress.config.ts': 'export default {}', '/cypress/support/index.js': '', '/cypress/plugins/index.js': 'module.exports = (on, config) => {}', // For next.js user will have babel config, but we want to suggest to use the closest config for the application code @@ -114,7 +114,7 @@ describe('init component tests script', () => { it('automatically suggests to the user which config to use', async () => { createTempFiles({ - '/cypress.config.ts': 'module.exports = {}', + '/cypress.config.ts': 'export default {}', '/cypress/support/index.js': 'import "./commands.js";', '/cypress/plugins/index.js': 'module.exports = () => {}', '/package.json': JSON.stringify({ @@ -145,7 +145,7 @@ describe('init component tests script', () => { it('Asks for preferred bundling tool if can not determine the right one', async () => { createTempFiles({ - '/cypress.config.ts': 'module.exports = {}', + '/cypress.config.ts': 'export default {}', '/webpack.config.js': 'module.exports = { }', '/package.json': JSON.stringify({ dependencies: { } }), }) @@ -170,7 +170,7 @@ describe('init component tests script', () => { it('Asks for framework if more than 1 option was auto detected', async () => { createTempFiles({ - '/cypress.config.ts': 'module.exports = {}', + '/cypress.config.ts': 'export default {}', '/webpack.config.js': 'module.exports = { }', '/package.json': JSON.stringify({ dependencies: { react: '*', vue: '^2.4.5' } }), }) @@ -195,7 +195,7 @@ describe('init component tests script', () => { it('installs the right adapter', async () => { createTempFiles({ - '/cypress.config.ts': 'module.exports = {}', + '/cypress.config.ts': 'export default {}', '/webpack.config.js': 'module.exports = { }', '/package.json': JSON.stringify({ dependencies: { react: '16.4.5' } }), }) @@ -213,7 +213,7 @@ describe('init component tests script', () => { it('installs the right adapter for vue 3', async () => { createTempFiles({ - '/cypress.config.ts': 'module.exports = {}', + '/cypress.config.ts': 'export default {}', '/vite.config.js': 'module.exports = { }', '/package.json': JSON.stringify({ dependencies: { vue: '^3.0.0' } }), }) @@ -236,7 +236,7 @@ describe('init component tests script', () => { react: '^16.0.0', }, }), - '/cypress.config.ts': 'module.exports = {}', + '/cypress.config.ts': 'export default {}', }) promptSpy = sinon.stub(inquirer, 'prompt').returns(Promise.resolve({ @@ -255,7 +255,7 @@ describe('init component tests script', () => { it('suggests right docs example and cypress.config.ts config based on the `componentFolder` answer', async () => { createTempFiles({ - '/cypress.config.ts': 'module.exports = {}', + '/cypress.config.ts': 'export default {}', '/package.json': JSON.stringify({ dependencies: { react: '^16.0.0', @@ -284,7 +284,7 @@ describe('init component tests script', () => { it('Shows help message if cypress files are not created', async () => { createTempFiles({ - '/cypress.config.ts': 'module.exports = {}', + '/cypress.config.ts': 'export default {}', '/package.json': JSON.stringify({ dependencies: { react: '^16.0.0', @@ -310,7 +310,7 @@ describe('init component tests script', () => { it('Doesn\'t affect injected code if user has custom babel.config.js', async () => { createTempFiles({ '/cypress/plugins/index.js': 'module.exports = (on, config) => {}', - '/cypress.config.ts': 'module.exports = {}', + '/cypress.config.ts': 'export default {}', 'babel.config.js': `module.exports = ${JSON.stringify({ presets: [ '@babel/preset-env', diff --git a/npm/create-cypress-tests/src/installCypress.ts b/npm/create-cypress-tests/src/installCypress.ts index 524045de649d..de649a2a2a52 100644 --- a/npm/create-cypress-tests/src/installCypress.ts +++ b/npm/create-cypress-tests/src/installCypress.ts @@ -15,7 +15,7 @@ type InstallCypressOpts = { async function copyFiles ({ ignoreExamples, useTypescript }: InstallCypressOpts) { let fileSpinner = ora('Creating config files').start() - await fs.outputFile(path.resolve(process.cwd(), useTypescript ? 'cypress.config.ts' : 'cypress.config.js'), `module.exports = {}\n`) + await fs.outputFile(path.resolve(process.cwd(), useTypescript ? 'cypress.config.ts' : 'cypress.config.js'), useTypescript ? `export default {}` : `module.exports = {}\n`) await fs.copy( initialTemplate.getInitialPluginsFilePath(), path.resolve('cypress', 'plugins/index.js'), From bb479bc6ad2a8b87fc8a97c9f5440728dcd7ba8f Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Wed, 27 Oct 2021 20:01:08 -0500 Subject: [PATCH 28/57] Update tests --- .../src/schematics/ng-add/files/cypress.config.ts | 9 +++++++++ .../src/schematics/ng-add/index.spec.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 npm/cypress-schematic/src/schematics/ng-add/files/cypress.config.ts diff --git a/npm/cypress-schematic/src/schematics/ng-add/files/cypress.config.ts b/npm/cypress-schematic/src/schematics/ng-add/files/cypress.config.ts new file mode 100644 index 000000000000..2e57a7a50702 --- /dev/null +++ b/npm/cypress-schematic/src/schematics/ng-add/files/cypress.config.ts @@ -0,0 +1,9 @@ +export default { + 'integrationFolder': '<%= root%>cypress/integration', + 'supportFile': '<%= root%>cypress/support/index.ts', + 'videosFolder': '<%= root%>cypress/videos', + 'screenshotsFolder': '<%= root%>cypress/screenshots', + 'pluginsFile': '<%= root%>cypress/plugins/index.ts', + 'fixturesFolder': '<%= root%>cypress/fixtures', + 'baseUrl': '<%= baseUrl%>', +} diff --git a/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts b/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts index 9ba48125f0bf..01f26fcc4747 100644 --- a/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts +++ b/npm/cypress-schematic/src/schematics/ng-add/index.spec.ts @@ -32,7 +32,7 @@ describe('@cypress/schematic: ng-add', () => { }) it('should create cypress files', async () => { - const files = ['cypress/integration/spec.ts', 'cypress/plugins/index.ts', 'cypress/support/commands.ts', 'cypress/support/index.ts', 'cypress/tsconfig.json', 'cypress.config.js'] + const files = ['cypress/integration/spec.ts', 'cypress/plugins/index.ts', 'cypress/support/commands.ts', 'cypress/support/index.ts', 'cypress/tsconfig.json', 'cypress.config.ts'] const homePath = '/projects/sandbox/' return schematicRunner.runSchematicAsync('ng-add', {}, appTree).toPromise().then((tree) => { From 83aa113ce168990e6f380c36a148920cc349509a Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Wed, 27 Oct 2021 21:48:59 -0500 Subject: [PATCH 29/57] Update tests --- cli/__snapshots__/cli_spec.js | 16 +- cli/lib/cli.js | 8 +- cli/schema/cypress.schema.json | 2 +- .../init-component-testing.test.ts.js | 12 +- npm/create-cypress-tests/package.json | 3 +- .../component-testing/babel/babelTransform.ts | 14 +- .../configFileUpdater.test.ts | 423 ++++++++++++++++++ .../config-file-updater/configFileUpdater.ts | 293 ++++++++++++ .../init-component-testing.test.ts | 2 +- .../init-component-testing.ts | 12 +- npm/create-cypress-tests/src/utils.ts | 14 + 11 files changed, 762 insertions(+), 37 deletions(-) create mode 100644 npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.test.ts create mode 100644 npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.ts diff --git a/cli/__snapshots__/cli_spec.js b/cli/__snapshots__/cli_spec.js index 398d6bdc721d..bce318c81a54 100644 --- a/cli/__snapshots__/cli_spec.js +++ b/cli/__snapshots__/cli_spec.js @@ -21,19 +21,19 @@ exports['shows help for open --foo 1'] = ` --component runs component tests -c, --config sets configuration values. separate multiple values with a comma. overrides any value in - cypress.json. + cypress.config.{ts|js}. -C, --config-file path to JSON file where configuration values - are set. defaults to "cypress.json". pass + are set. defaults to "cypress.config.{ts|js}". pass "false" to disable. -d, --detached [bool] runs Cypress application in detached mode --e2e runs end to end tests -e, --env sets environment variables. separate multiple values with a comma. overrides any - value in cypress.json or cypress.env.json + value in cypress.config.{ts|js} or cypress.env.json --global force Cypress into global mode as if its globally installed -p, --port runs Cypress on a specific port. overrides - any value in cypress.json. + any value in cypress.config.{ts|js}. -P, --project path to the project --dev runs cypress in development and bypasses binary check @@ -67,17 +67,17 @@ exports['shows help for run --foo 1'] = ` -b, --browser runs Cypress in the browser with the given name. if a filesystem path is supplied, Cypress will attempt to use the browser at that path. --ci-build-id the unique identifier for a run on your CI provider. typically a "BUILD_ID" env var. this value is automatically detected for most CI providers --component runs component tests - -c, --config sets configuration values. separate multiple values with a comma. overrides any value in cypress.json. - -C, --config-file path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable. + -c, --config sets configuration values. separate multiple values with a comma. overrides any value in cypress.config.{ts|js}. + -C, --config-file path to JSON file where configuration values are set. defaults to "cypress.config.{ts|js}". pass "false" to disable. --e2e runs end to end tests - -e, --env sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json + -e, --env sets environment variables. separate multiple values with a comma. overrides any value in cypress.config.{ts|js} or cypress.env.json --group a named group for recorded runs in the Cypress Dashboard -k, --key your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY environment variable. --headed displays the browser instead of running headlessly --headless hide the browser instead of running headed (default for cypress run) --no-exit keep the browser open after tests finish --parallel enables concurrent runs and automatic load balancing of specs across multiple machines or processes - -p, --port runs Cypress on a specific port. overrides any value in cypress.json. + -p, --port runs Cypress on a specific port. overrides any value in cypress.config.{ts|js}. -P, --project path to the project -q, --quiet run quietly, using only the configured reporter --record [bool] records the run. sends test results, screenshots and videos to your Cypress Dashboard. diff --git a/cli/lib/cli.js b/cli/lib/cli.js index 778d60f710cc..83ed03901c21 100644 --- a/cli/lib/cli.js +++ b/cli/lib/cli.js @@ -107,12 +107,12 @@ const descriptions = { cacheSize: 'Used with the list command to show the sizes of the cached folders', ciBuildId: 'the unique identifier for a run on your CI provider. typically a "BUILD_ID" env var. this value is automatically detected for most CI providers', component: 'runs component tests', - config: 'sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.', - configFile: 'path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable.', + config: 'sets configuration values. separate multiple values with a comma. overrides any value in cypress.config.{ts|js}.', + configFile: 'path to JSON file where configuration values are set. defaults to "cypress.config.{ts|js}". pass "false" to disable.', detached: 'runs Cypress application in detached mode', dev: 'runs cypress in development and bypasses binary check', e2e: 'runs end to end tests', - env: 'sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json', + env: 'sets environment variables. separate multiple values with a comma. overrides any value in cypress.config.{ts|js} or cypress.env.json', exit: 'keep the browser open after tests finish', forceInstall: 'force install the Cypress binary', global: 'force Cypress into global mode as if its globally installed', @@ -121,7 +121,7 @@ const descriptions = { headless: 'hide the browser instead of running headed (default for cypress run)', key: 'your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY environment variable.', parallel: 'enables concurrent runs and automatic load balancing of specs across multiple machines or processes', - port: 'runs Cypress on a specific port. overrides any value in cypress.json.', + port: 'runs Cypress on a specific port. overrides any value in cypress.config.{ts|js}.', project: 'path to the project', quiet: 'run quietly, using only the configured reporter', record: 'records the run. sends test results, screenshots and videos to your Cypress Dashboard.', diff --git a/cli/schema/cypress.schema.json b/cli/schema/cypress.schema.json index 617664c1028d..baa58a927905 100644 --- a/cli/schema/cypress.schema.json +++ b/cli/schema/cypress.schema.json @@ -282,7 +282,7 @@ "includeShadowDom": { "type": "boolean", "default": false, - "description": "Enables including elements within the shadow DOM when using querying commands (e.g. cy.get(), cy.find()). Can be set globally in cypress.json, per-suite or per-test in the test configuration object, or programmatically with Cypress.config()" + "description": "Enables including elements within the shadow DOM when using querying commands (e.g. cy.get(), cy.find()). Can be set globally in cypress.config.{ts|js}, per-suite or per-test in the test configuration object, or programmatically with Cypress.config()" }, "clientCertificates": { "description": "Defines client certificates to use when sending requests to the specified URLs", diff --git a/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js b/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js index e1d70451496a..da624fe495ba 100644 --- a/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js +++ b/npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js @@ -1,5 +1,9 @@ exports['injects guessed next.js template cypress.config.ts'] = ` -export default {} +export default { + componentFolder: "src", + testFiles: "**/*.spec.{js,ts,jsx,tsx}" +}; + ` exports['injects guessed next.js template plugins/index.js'] = ` @@ -16,7 +20,11 @@ module.exports = (on, config) => { ` exports['Injected overridden webpack template cypress.config.ts'] = ` -export default {} +export default { + componentFolder: "cypress/component", + testFiles: "**/*.spec.{js,ts,jsx,tsx}" +}; + ` exports['Injected overridden webpack template plugins/index.js'] = ` diff --git a/npm/create-cypress-tests/package.json b/npm/create-cypress-tests/package.json index 5901324bfb42..48a49781d1e4 100644 --- a/npm/create-cypress-tests/package.json +++ b/npm/create-cypress-tests/package.json @@ -26,7 +26,8 @@ "fs-extra": "^9.0.1", "glob": "^7.1.6", "inquirer": "7.3.3", - "ora": "^5.1.0" + "ora": "^5.1.0", + "recast": "0.20.4" }, "devDependencies": { "@types/babel__core": "^7.1.2", diff --git a/npm/create-cypress-tests/src/component-testing/babel/babelTransform.ts b/npm/create-cypress-tests/src/component-testing/babel/babelTransform.ts index 22e5858dca3a..b7089d3cc158 100644 --- a/npm/create-cypress-tests/src/component-testing/babel/babelTransform.ts +++ b/npm/create-cypress-tests/src/component-testing/babel/babelTransform.ts @@ -2,6 +2,7 @@ import path from 'path' import * as fs from 'fs-extra' import * as babel from '@babel/core' import * as babelTypes from '@babel/types' +import { prettifyCode } from '../../utils' type AST = ReturnType @@ -11,13 +12,6 @@ export type PluginsConfigAst = { requiresReturnConfig?: true } -function tryRequirePrettier () { - try { - return require('prettier') - } catch (e) { - return null - } -} const sharedBabelOptions = { // disable user config configFile: false, @@ -47,11 +41,7 @@ async function transformFileViaPlugin (filePath: string, babelPlugin: babel.Plug return false } - const maybePrettier = tryRequirePrettier() - - if (maybePrettier && maybePrettier.format) { - finalCode = maybePrettier.format(finalCode, { parser: 'babel' }) - } + finalCode = await prettifyCode(finalCode) await fs.writeFile(filePath, finalCode) diff --git a/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.test.ts b/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.test.ts new file mode 100644 index 000000000000..94ec10262142 --- /dev/null +++ b/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.test.ts @@ -0,0 +1,423 @@ +/// + +import * as path from 'path' +import { expect } from 'chai' + +import * as fs from 'fs-extra' +import { insertValueInJSString, insertValuesInConfigFile } from './configFileUpdater' +const projectRoot = process.cwd() + +const stripIndent = (strings: any, ...args: any) => { + const parts = [] + + for (let i = 0; i < strings.length; i++) { + parts.push(strings[i]) + + if (i < strings.length - 1) { + parts.push(`<<${i}>>`) + } + } + + const lines = parts.join('').split('\n') + const firstLine = lines[0].length === 0 ? lines[1] : lines[0] + let indentSize = 0 + + for (let i = 0; i < firstLine.length; i++) { + if (firstLine[i] === ' ') { + indentSize++ + continue + } + + break + } + + const strippedLines = lines.map((line) => line.substring(indentSize)) + + let result = strippedLines.join('\n').trimLeft() + + args.forEach((arg: any, i: any) => { + result = result.replace(`<<${i}>>`, `${arg}`) + }) + + return result +} + +describe('lib/util/config-file-updater', () => { + context('with configFile: false', () => { + beforeEach(function () { + this.projectRoot = path.join(projectRoot, '_test-output/path/to/project/') + }) + + it('.insertValuesInConfigFile does not create a file', function () { + return insertValuesInConfigFile(this.projectRoot, {}) + .then(() => { + throw Error('file shuold not have been created here') + }).catch((err) => { + expect(err.code).to.equal('ENOENT') + }) + }) + }) + + context('with js files', () => { + describe('#insertValueInJSString', () => { + describe('es6 vs es5', () => { + it('finds the object litteral and adds the values to it es6', async () => { + const src = stripIndent`\ + export default { + foo: 42, + } + ` + + const expectedOutput = stripIndent`\ + export default { + projectId: "id1234", + viewportWidth: 400, + foo: 42, + } + ` + + const output = await insertValueInJSString(src, { projectId: 'id1234', viewportWidth: 400 }) + + expect(output).to.equal(expectedOutput) + }) + + it('finds the object litteral and adds the values to it es5', async () => { + const src = stripIndent`\ + module.exports = { + foo: 42, + } + ` + + const expectedOutput = stripIndent`\ + module.exports = { + projectId: "id1234", + viewportWidth: 400, + foo: 42, + } + ` + + const output = await insertValueInJSString(src, { projectId: 'id1234', viewportWidth: 400 }) + + expect(output).to.equal(expectedOutput) + }) + + it('works with and without the quotes around keys', async () => { + const src = stripIndent`\ + export default { + "foo": 42, + } + ` + + const expectedOutput = stripIndent`\ + export default { + projectId: "id1234", + viewportWidth: 400, + "foo": 42, + } + ` + + const output = await insertValueInJSString(src, { projectId: 'id1234', viewportWidth: 400 }) + + expect(output).to.equal(expectedOutput) + }) + }) + + describe('defineConfig', () => { + it('skips defineConfig and add to the object inside', async () => { + const src = stripIndent`\ + import { defineConfig } from "cypress" + export default defineConfig({ + foo: 42, + }) + ` + + const expectedOutput = stripIndent`\ + import { defineConfig } from "cypress" + export default defineConfig({ + projectId: "id1234", + viewportWidth: 400, + foo: 42, + }) + ` + + const output = await insertValueInJSString(src, { projectId: 'id1234', viewportWidth: 400 }) + + expect(output).to.equal(expectedOutput) + }) + + it('skips defineConfig even if it renamed in an import (es6)', async () => { + const src = stripIndent`\ + import { defineConfig as cy_defineConfig } from "cypress" + export default cy_defineConfig({ + foo: 42, + }) + ` + + const expectedOutput = stripIndent`\ + import { defineConfig as cy_defineConfig } from "cypress" + export default cy_defineConfig({ + projectId: "id1234", + viewportWidth: 400, + foo: 42, + }) + ` + + const output = await insertValueInJSString(src, { projectId: 'id1234', viewportWidth: 400 }) + + expect(output).to.equal(expectedOutput) + }) + + it('skips defineConfig even if it renamed in a require (es5)', async () => { + const src = stripIndent`\ + const { defineConfig: cy_defineConfig } = require("cypress") + module.exports = cy_defineConfig({ + foo: 42, + }) + ` + + const expectedOutput = stripIndent`\ + const { defineConfig: cy_defineConfig } = require("cypress") + module.exports = cy_defineConfig({ + projectId: "id1234", + viewportWidth: 400, + foo: 42, + }) + ` + + const output = await insertValueInJSString(src, { projectId: 'id1234', viewportWidth: 400 }) + + expect(output).to.equal(expectedOutput) + }) + }) + + describe('updates', () => { + it('updates a value if the same value is found in resolved config', async () => { + const src = stripIndent`\ + export default { + foo: 42, + } + ` + const expectedOutput = stripIndent`\ + export default { + foo: 1000, + } + ` + + const output = await insertValueInJSString(src, { foo: 1000 }) + + expect(output).to.equal(expectedOutput) + }) + + it('accepts inline comments', async () => { + const src = stripIndent`\ + export default { + foo: 12, // will do this later + viewportWidth: 800, + } + ` + const expectedOutput = stripIndent`\ + export default { + foo: 1000, // will do this later + viewportWidth: 800, + } + ` + + const output = await insertValueInJSString(src, { foo: 1000 }) + + expect(output).to.equal(expectedOutput) + }) + + it('updates a value even when this value is explicitely undefined', async () => { + const src = stripIndent`\ + export default { + foo: undefined, // will do this later + viewportWidth: 800, + } + ` + const expectedOutput = stripIndent`\ + export default { + foo: 1000, // will do this later + viewportWidth: 800, + } + ` + + const output = await insertValueInJSString(src, { foo: 1000 }) + + expect(output).to.equal(expectedOutput) + }) + + it('updates values and inserts config', async () => { + const src = stripIndent`\ + export default { + foo: 42, + bar: 84, + component: { + devServer() { + return null + } + } + } + ` + + const expectedOutput = stripIndent`\ + export default { + projectId: "id1234", + foo: 1000, + bar: 3000, + component: { + devServer() { + return null + } + } + } + ` + + const output = await insertValueInJSString(src, { foo: 1000, bar: 3000, projectId: 'id1234' }) + + expect(output).to.equal(expectedOutput) + }) + }) + + describe('subkeys', () => { + it('inserts nested values', async () => { + const src = stripIndent`\ + module.exports = { + foo: 42 + } + ` + + const output = await insertValueInJSString(src, { component: { specFilePattern: 'src/**/*.spec.cy.js' } }) + + const expectedOutput = stripIndent`\ + module.exports = { + component: { + specFilePattern: "src/**/*.spec.cy.js", + }, + foo: 42 + } + ` + + expect(output).to.equal(expectedOutput) + }) + + it('inserts nested values into existing keys', async () => { + const src = stripIndent`\ + module.exports = { + component: { + viewportWidth: 800 + }, + foo: 42 + } + ` + + const output = await insertValueInJSString(src, { component: { specFilePattern: 'src/**/*.spec.cy.js' } }) + + const expectedOutput = stripIndent`\ + module.exports = { + component: { + specFilePattern: "src/**/*.spec.cy.js", + viewportWidth: 800 + }, + foo: 42 + } + ` + + expect(output).to.equal(expectedOutput) + }) + + it('updates nested values', async () => { + const src = stripIndent`\ + module.exports = { + foo: 42, + component: { + specFilePattern: 'components/**/*.spec.cy.js', + foo: 82 + } + }` + + const output = await insertValueInJSString(src, { component: { specFilePattern: 'src/**/*.spec.cy.js' } }) + + const expectedOutput = stripIndent`\ + module.exports = { + foo: 42, + component: { + specFilePattern: "src/**/*.spec.cy.js", + foo: 82 + } + }` + + expect(output).to.equal(expectedOutput) + }) + }) + + describe('failures', () => { + it('fails if not an object litteral', () => { + const src = [ + 'const foo = {}', + 'export default foo', + ].join('\n') + + return insertValueInJSString(src, { bar: 10 }) + .then(() => { + throw Error('this should not succeed') + }) + .catch((err) => { + expect(err.message).to.equal('Cypress was unable to add/update values in your configuration file.') + }) + }) + + it('fails if one of the values to update is not a literal', () => { + const src = [ + 'const bar = 12', + 'export default {', + ' foo: bar', + '}', + ].join('\n') + + return insertValueInJSString(src, { foo: 10 }) + .then(() => { + throw Error('this should not succeed') + }) + .catch((err) => { + expect(err.message).to.equal('Cypress was unable to add/update values in your configuration file.') + }) + }) + + it('fails with inlined values', () => { + const src = stripIndent`\ + const foo = 12 + export default { + foo + } + ` + + return insertValueInJSString(src, { foo: 10 }) + .then(() => { + throw Error('this should not succeed') + }) + .catch((err) => { + expect(err.message).to.equal('Cypress was unable to add/update values in your configuration file.') + }) + }) + + it('fails if there is a spread', () => { + const src = stripIndent`\ + const foo = { bar: 12 } + export default { + bar: 8, + ...foo + } + ` + + return insertValueInJSString(src, { bar: 10 }) + .then(() => { + throw Error('this should not succeed') + }) + .catch((err) => { + expect(err.message).to.equal('Cypress was unable to add/update values in your configuration file.') + }) + }) + }) + }) + }) +}) diff --git a/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.ts b/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.ts new file mode 100644 index 000000000000..5363203f1ab8 --- /dev/null +++ b/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.ts @@ -0,0 +1,293 @@ +import _ from 'lodash' +import { parse } from '@babel/parser' +import type { File } from '@babel/types' +import type { NodePath } from 'ast-types/lib/node-path' +import { visit } from 'recast' +import type { namedTypes } from 'ast-types' +import * as fs from 'fs-extra' +import { prettifyCode } from '../../utils' + +export async function insertValuesInConfigFile (filePath: string, obj: Record = {}) { + return await insertValuesInJavaScript(filePath, obj) +} + +export async function insertValuesInJavaScript (filePath: string, obj: Record) { + const fileContents = await fs.readFile(filePath, { encoding: 'utf8' }) + + let finalCode = await insertValueInJSString(fileContents, obj) + + const prettifiedCode = await prettifyCode(finalCode) + + if (prettifiedCode) { + finalCode = prettifiedCode + } + + await fs.writeFile(filePath, finalCode) +} + +export async function insertValueInJSString (fileContents: string, obj: Record): Promise { + const ast = parse(fileContents, { plugins: ['typescript'], sourceType: 'module' }) + + let objectLiteralNode: namedTypes.ObjectExpression | undefined + + function handleExport (nodePath: NodePath | NodePath): void { + if (nodePath.node.type === 'CallExpression' + && nodePath.node.callee.type === 'Identifier') { + const functionName = nodePath.node.callee.name + + if (isDefineConfigFunction(ast, functionName)) { + return handleExport(nodePath.get('arguments', 0)) + } + } + + if (nodePath.node.type === 'ObjectExpression' && !nodePath.node.properties.find((prop) => prop.type !== 'ObjectProperty')) { + objectLiteralNode = nodePath.node + + return + } + + throw new Error('Cypress was unable to add/update values in your configuration file.') + } + + visit(ast, { + visitAssignmentExpression (nodePath) { + if (nodePath.node.left.type === 'MemberExpression') { + if (nodePath.node.left.object.type === 'Identifier' && nodePath.node.left.object.name === 'module' + && nodePath.node.left.property.type === 'Identifier' && nodePath.node.left.property.name === 'exports') { + handleExport(nodePath.get('right')) + } + } + + return false + }, + visitExportDefaultDeclaration (nodePath) { + handleExport(nodePath.get('declaration')) + + return false + }, + }) + + const splicers: Splicer[] = [] + + if (!objectLiteralNode) { + // if the export is no object litteral + throw new Error('Cypress was unable to add/update values in your configuration file.') + } + + setRootKeysSplicers(splicers, obj, objectLiteralNode!, ' ') + setSubKeysSplicers(splicers, obj, objectLiteralNode!, ' ', ' ') + + // sort splicers to keep the order of the original file + const sortedSplicers = splicers.sort((a, b) => a.start === b.start ? 0 : a.start > b.start ? 1 : -1) + + if (!sortedSplicers.length) return fileContents + + let nextStartingIndex = 0 + let resultCode = '' + + sortedSplicers.forEach((splicer) => { + resultCode += fileContents.slice(nextStartingIndex, splicer.start) + splicer.replaceString + nextStartingIndex = splicer.end + }) + + return resultCode + fileContents.slice(nextStartingIndex) +} + +export function isDefineConfigFunction (ast: File, functionName: string): boolean { + let value = false + + visit(ast, { + visitVariableDeclarator (nodePath) { + // if this is a require of cypress + if (nodePath.node.init?.type === 'CallExpression' + && nodePath.node.init.callee.type === 'Identifier' + && nodePath.node.init.callee.name === 'require' + && nodePath.node.init.arguments[0].type === 'StringLiteral' + && nodePath.node.init.arguments[0].value === 'cypress') { + if (nodePath.node.id?.type === 'ObjectPattern') { + const defineConfigFunctionNode = nodePath.node.id.properties.find((prop) => { + return prop.type === 'ObjectProperty' + && prop.key.type === 'Identifier' + && prop.key.name === 'defineConfig' + }) + + if (defineConfigFunctionNode) { + value = (defineConfigFunctionNode as any).value?.name === functionName + } + } + } + + return false + }, + visitImportDeclaration (nodePath) { + if (nodePath.node.source.type === 'StringLiteral' + && nodePath.node.source.value === 'cypress') { + const defineConfigFunctionNode = nodePath.node.specifiers?.find((specifier) => { + return specifier.type === 'ImportSpecifier' + && specifier.imported.type === 'Identifier' + && specifier.imported.name === 'defineConfig' + }) + + if (defineConfigFunctionNode) { + value = (defineConfigFunctionNode as any).local?.name === functionName + } + } + + return false + }, + }) + + return value +} + +function setRootKeysSplicers ( + splicers: Splicer[], + obj: Record, + objectLiteralNode: namedTypes.ObjectExpression, + lineStartSpacer: string, +) { + const objectLiteralStartIndex = (objectLiteralNode as any).start + 1 + // add values + const objKeys = Object.keys(obj).filter((key) => ['boolean', 'number', 'string'].includes(typeof obj[key])) + + // update values + const keysToUpdate = objKeys.filter((key) => { + return objectLiteralNode.properties.find((prop) => { + return prop.type === 'ObjectProperty' + && prop.key.type === 'Identifier' + && prop.key.name === key + }) + }) + + keysToUpdate.forEach( + (key) => { + const propertyToUpdate = propertyFromKey(objectLiteralNode, key) + + if (propertyToUpdate) { + setSplicerToUpdateProperty(splicers, propertyToUpdate, obj[key], key, obj) + } + }, + ) + + const keysToInsert = objKeys.filter((key) => !keysToUpdate.includes(key)) + + if (keysToInsert.length) { + const valuesInserted = `\n${lineStartSpacer}${ keysToInsert.map((key) => `${key}: ${JSON.stringify(obj[key])},`).join(`\n${lineStartSpacer}`)}` + + splicers.push({ + start: objectLiteralStartIndex, + end: objectLiteralStartIndex, + replaceString: valuesInserted, + }) + } +} + +function setSubKeysSplicers ( + splicers: Splicer[], + obj: Record, + objectLiteralNode: namedTypes.ObjectExpression, + lineStartSpacer: string, + parentLineStartSpacer: string, +) { + const objectLiteralStartIndex = (objectLiteralNode as any).start + 1 + + const keysToUpdateWithObjects: string[] = [] + + const objSubkeys = Object.keys(obj).filter((key) => typeof obj[key] === 'object').reduce((acc: Array<{parent: string, subkey: string}>, key) => { + keysToUpdateWithObjects.push(key) + Object.entries(obj[key]).forEach(([subkey, value]) => { + if (['boolean', 'number', 'string'].includes(typeof value)) { + acc.push({ parent: key, subkey }) + } + }) + + return acc + }, []) + + // add values where the parent key needs to be created + const subkeysToInsertWithoutKey = objSubkeys.filter(({ parent }) => { + return !objectLiteralNode.properties.find((prop) => { + return prop.type === 'ObjectProperty' + && prop.key.type === 'Identifier' + && prop.key.name === parent + }) + }) + const keysToInsertForSubKeys: Record = {} + + subkeysToInsertWithoutKey.forEach((keyTuple) => { + const subkeyList = keysToInsertForSubKeys[keyTuple.parent] || [] + + subkeyList.push(keyTuple.subkey) + keysToInsertForSubKeys[keyTuple.parent] = subkeyList + }) + + let subvaluesInserted = '' + + for (const key in keysToInsertForSubKeys) { + subvaluesInserted += `\n${parentLineStartSpacer}${key}: {` + keysToInsertForSubKeys[key].forEach((subkey) => { + subvaluesInserted += `\n${parentLineStartSpacer}${lineStartSpacer}${subkey}: ${JSON.stringify(obj[key][subkey])},` + }) + + subvaluesInserted += `\n${parentLineStartSpacer}},` + } + + if (subkeysToInsertWithoutKey.length) { + splicers.push({ + start: objectLiteralStartIndex, + end: objectLiteralStartIndex, + replaceString: subvaluesInserted, + }) + } + + // add/update values where parent key already exists + keysToUpdateWithObjects.filter((parent) => { + return objectLiteralNode.properties.find((prop) => { + return prop.type === 'ObjectProperty' + && prop.key.type === 'Identifier' + && prop.key.name === parent + }) + }).forEach((key) => { + const propertyToUpdate = propertyFromKey(objectLiteralNode, key) + + if (propertyToUpdate?.value.type === 'ObjectExpression') { + setRootKeysSplicers(splicers, obj[key], propertyToUpdate.value, parentLineStartSpacer + lineStartSpacer) + } + }) +} + +function setSplicerToUpdateProperty (splicers: Splicer[], + propertyToUpdate: namedTypes.ObjectProperty, + updatedValue: any, + key: string, + obj: Record) { + if (propertyToUpdate && (isPrimitive(propertyToUpdate.value) || isUndefinedOrNull(propertyToUpdate.value))) { + splicers.push({ + start: (propertyToUpdate.value as any).start, + end: (propertyToUpdate.value as any).end, + replaceString: JSON.stringify(updatedValue), + }) + } else { + throw new Error('Cypress was unable to add/update values in your configuration file.') + } +} + +function propertyFromKey (objectLiteralNode: namedTypes.ObjectExpression | undefined, key: string): namedTypes.ObjectProperty | undefined { + return objectLiteralNode?.properties.find((prop) => { + return prop.type === 'ObjectProperty' && prop.key.type === 'Identifier' && prop.key.name === key + }) as namedTypes.ObjectProperty +} + +function isPrimitive (value: NodePath['node']): value is namedTypes.NumericLiteral | namedTypes.StringLiteral | namedTypes.BooleanLiteral { + return value.type === 'NumericLiteral' || value.type === 'StringLiteral' || value.type === 'BooleanLiteral' +} + +function isUndefinedOrNull (value: NodePath['node']): value is namedTypes.Identifier { + return value.type === 'Identifier' && ['undefined', 'null'].includes(value.name) +} + +interface Splicer{ + start: number + end: number + replaceString: string +} diff --git a/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts b/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts index 18bebe1ec1a1..b939096de464 100644 --- a/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts +++ b/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts @@ -272,7 +272,7 @@ describe('init component tests script', () => { const injectedCode = await require(path.join(e2eTestOutputPath, 'cypress.config.ts')) - expect(injectedCode.default).to.equal(JSON.stringify( + expect(JSON.stringify(injectedCode.default, null, 2)).to.equal(JSON.stringify( { componentFolder: 'cypress/component', testFiles: '**/*.spec.{js,ts,jsx,tsx}', diff --git a/npm/create-cypress-tests/src/component-testing/init-component-testing.ts b/npm/create-cypress-tests/src/component-testing/init-component-testing.ts index 726747048798..25b2d7073c04 100644 --- a/npm/create-cypress-tests/src/component-testing/init-component-testing.ts +++ b/npm/create-cypress-tests/src/component-testing/init-component-testing.ts @@ -8,6 +8,7 @@ import { guessTemplate } from './templates/guessTemplate' import { installFrameworkAdapter } from './installFrameworkAdapter' import { injectPluginsCode, getPluginsSourceExample } from './babel/babelTransform' import { installDependency } from '../utils' +import { insertValuesInConfigFile } from './config-file-updater/configFileUpdater' async function injectOrShowConfigCode (injectFn: () => Promise, { code, @@ -51,7 +52,7 @@ async function injectOrShowConfigCode (injectFn: () => Promise, { injected ? printSuccess() : printFailure() } -async function injectAndShowCypressJsonConfig ( +async function injectAndShowCypressConfig ( cypressJsonPath: string, componentFolder: string, ) { @@ -61,12 +62,7 @@ async function injectAndShowCypressJsonConfig ( } async function autoInjectCypressJson () { - const currentConfig = JSON.parse(await fs.readFile(cypressJsonPath, { encoding: 'utf-8' })) - - await fs.writeFile(cypressJsonPath, JSON.stringify({ - ...currentConfig, - ...configToInject, - }, null, 2)) + await insertValuesInConfigFile(cypressJsonPath, configToInject) return true } @@ -171,7 +167,7 @@ export async function initComponentTesting ({ config, useYarn, cypressConfigP console.log(`Let's setup everything for component testing with ${chalk.cyan(chosenTemplateName)}:`) console.log() - await injectAndShowCypressJsonConfig(cypressConfigPath, componentFolder) + await injectAndShowCypressConfig(cypressConfigPath, componentFolder) await injectAndShowPluginConfig(chosenTemplate, { templatePayload, pluginsFilePath, diff --git a/npm/create-cypress-tests/src/utils.ts b/npm/create-cypress-tests/src/utils.ts index c42a92855e93..e79055e60283 100644 --- a/npm/create-cypress-tests/src/utils.ts +++ b/npm/create-cypress-tests/src/utils.ts @@ -60,3 +60,17 @@ export async function installDependency (name: string, options: { useYarn: boole cliSpinner.succeed() } + +export async function prettifyCode (finalCode?: string | null) { + try { + const maybePrettier = require('prettier') + + if (maybePrettier && maybePrettier.format) { + finalCode = maybePrettier.format(finalCode, { parser: 'babel' }) + } + } catch (e) { + return null + } finally { + return finalCode + } +} From 16d5ebcc1f4709c5af48f20907167ffe7f24ab7c Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Wed, 27 Oct 2021 22:07:06 -0500 Subject: [PATCH 30/57] Update snapshots --- cli/__snapshots__/cli_spec.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/__snapshots__/cli_spec.js b/cli/__snapshots__/cli_spec.js index bce318c81a54..aea378cff865 100644 --- a/cli/__snapshots__/cli_spec.js +++ b/cli/__snapshots__/cli_spec.js @@ -23,13 +23,15 @@ exports['shows help for open --foo 1'] = ` values with a comma. overrides any value in cypress.config.{ts|js}. -C, --config-file path to JSON file where configuration values - are set. defaults to "cypress.config.{ts|js}". pass - "false" to disable. + are set. defaults to + "cypress.config.{ts|js}". pass "false" to + disable. -d, --detached [bool] runs Cypress application in detached mode --e2e runs end to end tests -e, --env sets environment variables. separate multiple values with a comma. overrides any - value in cypress.config.{ts|js} or cypress.env.json + value in cypress.config.{ts|js} or + cypress.env.json --global force Cypress into global mode as if its globally installed -p, --port runs Cypress on a specific port. overrides From d2fb6185eb1acb7d072264128ec0bcdce6f9a306 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 11:55:16 -0500 Subject: [PATCH 31/57] Cleanup code --- .../config-file-updater/configFileUpdater.test.ts | 1 + .../config-file-updater/configFileUpdater.ts | 4 +++- .../component-testing/init-component-testing.test.ts | 2 +- .../src/component-testing/init-component-testing.ts | 8 +------- .../examples/webpack-file/cypress/plugins/index.js | 2 +- npm/react/plugins/load-webpack/index.js | 2 +- packages/data-context/src/sources/ProjectDataSource.ts | 2 +- .../cypress/integration/commands/net_stubbing_spec.ts | 2 +- packages/server/lib/config.ts | 3 +++ packages/server/lib/modes/run.js | 2 +- packages/server/lib/util/settings.ts | 10 ++++++++-- 11 files changed, 22 insertions(+), 16 deletions(-) diff --git a/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.test.ts b/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.test.ts index 94ec10262142..0168ad9d95ef 100644 --- a/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.test.ts +++ b/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.test.ts @@ -7,6 +7,7 @@ import * as fs from 'fs-extra' import { insertValueInJSString, insertValuesInConfigFile } from './configFileUpdater' const projectRoot = process.cwd() +// Test util - if needed outside the tests we can move it to utils const stripIndent = (strings: any, ...args: any) => { const parts = [] diff --git a/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.ts b/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.ts index 5363203f1ab8..6d16505c40e3 100644 --- a/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.ts +++ b/npm/create-cypress-tests/src/component-testing/config-file-updater/configFileUpdater.ts @@ -8,7 +8,9 @@ import * as fs from 'fs-extra' import { prettifyCode } from '../../utils' export async function insertValuesInConfigFile (filePath: string, obj: Record = {}) { - return await insertValuesInJavaScript(filePath, obj) + await insertValuesInJavaScript(filePath, obj) + + return true } export async function insertValuesInJavaScript (filePath: string, obj: Record) { diff --git a/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts b/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts index b939096de464..0d4182a858e7 100644 --- a/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts +++ b/npm/create-cypress-tests/src/component-testing/init-component-testing.test.ts @@ -270,7 +270,7 @@ describe('init component tests script', () => { await initComponentTesting({ config: {}, cypressConfigPath, useYarn: true }) - const injectedCode = await require(path.join(e2eTestOutputPath, 'cypress.config.ts')) + const injectedCode = require(path.join(e2eTestOutputPath, 'cypress.config.ts')) expect(JSON.stringify(injectedCode.default, null, 2)).to.equal(JSON.stringify( { diff --git a/npm/create-cypress-tests/src/component-testing/init-component-testing.ts b/npm/create-cypress-tests/src/component-testing/init-component-testing.ts index 25b2d7073c04..110f6c2f9c5a 100644 --- a/npm/create-cypress-tests/src/component-testing/init-component-testing.ts +++ b/npm/create-cypress-tests/src/component-testing/init-component-testing.ts @@ -61,13 +61,7 @@ async function injectAndShowCypressConfig ( testFiles: '**/*.spec.{js,ts,jsx,tsx}', } - async function autoInjectCypressJson () { - await insertValuesInConfigFile(cypressJsonPath, configToInject) - - return true - } - - await injectOrShowConfigCode(autoInjectCypressJson, { + await injectOrShowConfigCode(() => insertValuesInConfigFile(cypressJsonPath, configToInject), { code: JSON.stringify(configToInject, null, 2), language: 'js', filePath: cypressJsonPath, diff --git a/npm/react/examples/webpack-file/cypress/plugins/index.js b/npm/react/examples/webpack-file/cypress/plugins/index.js index 8f0558a51d7c..83513e0b198b 100644 --- a/npm/react/examples/webpack-file/cypress/plugins/index.js +++ b/npm/react/examples/webpack-file/cypress/plugins/index.js @@ -5,7 +5,7 @@ */ module.exports = (on, config) => { require('@cypress/react/plugins/load-webpack')(on, config, { - // from the root of the project (folder with cypress.config.js file) + // from the root of the project (folder with cypress.config.{ts|js} file) webpackFilename: 'webpack.config.js', }) diff --git a/npm/react/plugins/load-webpack/index.js b/npm/react/plugins/load-webpack/index.js index e14acd8a8482..368d1ea549ba 100644 --- a/npm/react/plugins/load-webpack/index.js +++ b/npm/react/plugins/load-webpack/index.js @@ -12,7 +12,7 @@ function normalizeWebpackPath (config, webpackConfigPath) { /** * Injects dev-server based on the webpack config file. * - * **Important:** `webpackFilename` path is relative to the project root (cypress.config.js location) + * **Important:** `webpackFilename` path is relative to the project root (cypress.config.{ts|js} location) * @type {(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions, options: { webpackFilename: string }) => Cypress.PluginConfigOptions} */ function devServer (cypressDevServerConfig, { webpackFilename, indexHtml }) { diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index 67b9615ad6ac..a1d7d54db011 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -131,7 +131,7 @@ export class ProjectDataSource { private configLoader (options?: SettingsOptions) { return this.ctx.loader((projectRoots) => { - return Promise.all(projectRoots.map((root) => this.ctx._apis.projectApi.getConfig(root, options))) // 12 + return Promise.all(projectRoots.map((root) => this.ctx._apis.projectApi.getConfig(root, options))) }) } diff --git a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts index bd706723fed9..0fa3850db63e 100644 --- a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts +++ b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts @@ -968,7 +968,7 @@ describe('network stubbing', function () { context('cors preflight', function () { // a different domain from the page own domain // NOTE: this domain is redirected back to the local host test server - // using "hosts" setting in the "cypress.config.ts" file + // using "hosts" setting in the "cypress.config.{ts|js}" file const corsUrl = 'http://diff.foobar.com:3501/no-cors' before(() => { diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index 2d9240e22e0d..e993d93ad3ca 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -223,6 +223,9 @@ export function get (projectRoot, options: {configFile?: string | false } = { co return fullConfig }) }) + .catch(() => { + return setProjectConfig(projectRoot, null) + }) } export function set (obj: Record = {}) { diff --git a/packages/server/lib/modes/run.js b/packages/server/lib/modes/run.js index 3acc6cded4c7..fb81137a915f 100644 --- a/packages/server/lib/modes/run.js +++ b/packages/server/lib/modes/run.js @@ -1543,7 +1543,7 @@ module.exports = { recordMode.throwIfRecordParamsWithoutRecording(record, ciBuildId, parallel, group, tag) if (record) { - recordMode.throwIfNoProjectId(projectId, settings.configFile(options.configFile === undefined || options.configFile === null ? { configFile } : options)) // + recordMode.throwIfNoProjectId(projectId, settings.configFile(options.configFile === undefined || options.configFile === null ? { configFile } : options)) recordMode.throwIfIncorrectCiBuildIdUsage(ciBuildId, parallel, group) recordMode.throwIfIndeterminateCiBuildId(ciBuildId, parallel, group) } diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index 0c505cd8dc47..56c70a46c349 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -6,6 +6,7 @@ import { fs } from '../util/fs' import { requireAsync } from './require_async' import Debug from 'debug' import type { SettingsOptions } from '@packages/types' +import { getProjectConfig } from '../cache' const debug = Debug('cypress:server:settings') @@ -127,9 +128,14 @@ export function configFile (options: SettingsOptions = {}) { return options.configFile === false ? false : options.configFile } -// TODO: Should we get it from the cache (?) export function id (projectRoot, options = {}) { - return read(projectRoot, options) + return getProjectConfig(projectRoot).then((config) => { + if (config) { + return Promise.resolve(config) + } + + return read(projectRoot, options) + }) .then((config) => config.projectId) .catch(() => { return null From c6d2fd4c986171bb04a6ce4c4aa5dbcad8b59aa1 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 14:43:04 -0500 Subject: [PATCH 32/57] Fix tests --- packages/server/lib/config.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index e993d93ad3ca..b1c7a930b8bb 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -223,8 +223,12 @@ export function get (projectRoot, options: {configFile?: string | false } = { co return fullConfig }) }) - .catch(() => { + .catch((e) => { + // Cleanup the cache if there's an error to prevent showing stale data return setProjectConfig(projectRoot, null) + .then(() => { + throw e + }) }) } From 602ff9f1ac4716fbb77b80182641cee3decd85ee Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 17:25:47 -0500 Subject: [PATCH 33/57] Update CircleCi job, refactor cache, use defineConfig --- circle.yml | 42 +++++++++++-------- npm/angular/cypress.config.ts | 6 ++- .../schematics/ng-add/files/cypress.config.ts | 6 ++- .../examples/find-webpack/cypress.config.ts | 6 ++- npm/vite-dev-server/cypress.config.ts | 6 ++- npm/vue/cypress.config.ts | 6 ++- .../examples/use-ts-loader/cypress.config.ts | 6 ++- packages/app/cypress.config.ts | 7 ++-- .../src/actions/ProjectActions.ts | 2 - .../src/sources/ProjectDataSource.ts | 11 +---- packages/driver/cypress.config.ts | 9 ++-- packages/frontend-shared/cypress.config.ts | 6 ++- packages/launchpad/cypress.config.ts | 7 ++-- .../fixtures/test-project/cypress.config.ts | 6 ++- packages/reporter/cypress.config.ts | 6 ++- packages/runner-ct/cypress.config.ts | 6 ++- packages/server/lib/cache.js | 2 +- packages/server/lib/config.ts | 29 +++++++------ packages/server/lib/makeDataContext.ts | 8 +--- 19 files changed, 98 insertions(+), 79 deletions(-) diff --git a/circle.yml b/circle.yml index b6eac3603a00..de9a7e0039b1 100644 --- a/circle.yml +++ b/circle.yml @@ -523,13 +523,17 @@ commands: repo: description: "Name of the github repo to clone like: cypress-example-kitchensink" type: string + checkout_branch: + description: "Name of the branch to checkout" + type: string + default: $(node ./scripts/get-next-version) steps: - restore_cached_binary - run: name: "Cloning test project: <>" command: | git clone --depth 1 --no-single-branch https://github.com/cypress-io/<>.git /tmp/<> - cd /tmp/<> && (git checkout $(node ./scripts/get-next-version) || true) + cd /tmp/<> && (git checkout <> || true) test-binary-against-rwa: description: | @@ -700,9 +704,13 @@ commands: description: Server start command for repo type: string default: "npm start --if-present" + checkout_branch: + description: "Name of the branch to checkout" + type: string steps: - clone-repo-and-checkout-release-branch: repo: <> + checkout_branch: <> - when: condition: <> steps: @@ -724,14 +732,18 @@ commands: CYPRESS_INSTALL_BINARY=~/cypress/cypress.zip npm install ~/cypress/cypress.tgz fi working_directory: /tmp/<> - - run: - name: Scaffold new config file - working_directory: /tmp/<> - environment: - CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" - command: | - rm -rf cypress.json - echo 'module.exports = {}' > cypress.config.js + - when: + condition: + - not: <> + steps: + - run: + name: Scaffold new config file + working_directory: /tmp/<> + environment: + CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" + command: | + rm -rf cypress.json + echo 'module.exports = {}' > cypress.config.js - run: name: Print Cypress version working_directory: /tmp/<> @@ -1620,15 +1632,8 @@ jobs: steps: - clone-repo-and-checkout-release-branch: repo: cypress-example-kitchensink + checkout_branch: feat/use-config-file - install-required-node - - run: - name: Scaffold new config file - working_directory: /tmp/cypress-example-kitchensink - environment: - CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" - command: | - rm -rf cypress.json - echo 'module.exports = {}' > cypress.config.js - run: name: Install prod dependencies command: yarn --production @@ -1964,6 +1969,7 @@ jobs: - test-binary-against-repo: repo: cypress-example-kitchensink browser: "electron" + checkout_branch: feat/use-config-file test-binary-against-awesome-typescript-loader: <<: *defaults @@ -1979,6 +1985,7 @@ jobs: - test-binary-against-repo: repo: cypress-example-kitchensink browser: firefox + checkout_branch: feat/use-config-file "test-binary-against-kitchensink-chrome": <<: *defaults @@ -1987,6 +1994,7 @@ jobs: - test-binary-against-repo: repo: cypress-example-kitchensink browser: chrome + checkout_branch: feat/use-config-file "test-binary-against-todomvc-firefox": <<: *defaults diff --git a/npm/angular/cypress.config.ts b/npm/angular/cypress.config.ts index 236dab170ba3..1b17dee3806b 100644 --- a/npm/angular/cypress.config.ts +++ b/npm/angular/cypress.config.ts @@ -1,4 +1,6 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ 'experimentalFetchPolyfill': true, 'fixturesFolder': false, 'includeShadowDom': true, @@ -8,4 +10,4 @@ export default { 'componentFolder': 'src/app', 'testFiles': '**/*cy-spec.ts', }, -} +}) diff --git a/npm/cypress-schematic/src/schematics/ng-add/files/cypress.config.ts b/npm/cypress-schematic/src/schematics/ng-add/files/cypress.config.ts index 2e57a7a50702..c3dffeeb7539 100644 --- a/npm/cypress-schematic/src/schematics/ng-add/files/cypress.config.ts +++ b/npm/cypress-schematic/src/schematics/ng-add/files/cypress.config.ts @@ -1,4 +1,6 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ 'integrationFolder': '<%= root%>cypress/integration', 'supportFile': '<%= root%>cypress/support/index.ts', 'videosFolder': '<%= root%>cypress/videos', @@ -6,4 +8,4 @@ export default { 'pluginsFile': '<%= root%>cypress/plugins/index.ts', 'fixturesFolder': '<%= root%>cypress/fixtures', 'baseUrl': '<%= baseUrl%>', -} +}) diff --git a/npm/react/examples/find-webpack/cypress.config.ts b/npm/react/examples/find-webpack/cypress.config.ts index 802087880d0e..1075dcd8916d 100644 --- a/npm/react/examples/find-webpack/cypress.config.ts +++ b/npm/react/examples/find-webpack/cypress.config.ts @@ -1,4 +1,6 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ 'video': true, 'projectId': 'jq5xpp', 'component': { @@ -10,4 +12,4 @@ export default { 'root': '#__cy_root', }, }, -} +}) diff --git a/npm/vite-dev-server/cypress.config.ts b/npm/vite-dev-server/cypress.config.ts index 56f91c2d8aed..bce9fa83d67e 100644 --- a/npm/vite-dev-server/cypress.config.ts +++ b/npm/vite-dev-server/cypress.config.ts @@ -1,7 +1,9 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ 'pluginsFile': 'cypress/plugins.js', 'video': false, 'fixturesFolder': false, 'testFiles': '**/*.spec.*', 'componentFolder': 'cypress/components', -} +}) diff --git a/npm/vue/cypress.config.ts b/npm/vue/cypress.config.ts index 5c42e3305f10..f63bc5d24707 100644 --- a/npm/vue/cypress.config.ts +++ b/npm/vue/cypress.config.ts @@ -1,4 +1,6 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ 'viewportWidth': 500, 'viewportHeight': 500, 'video': false, @@ -6,4 +8,4 @@ export default { 'projectId': '134ej7', 'testFiles': '**/*spec.{js,ts,tsx}', 'experimentalFetchPolyfill': true, -} +}) diff --git a/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts b/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts index 80c1b7ede1af..737a9350d876 100644 --- a/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts +++ b/npm/webpack-preprocessor/examples/use-ts-loader/cypress.config.ts @@ -1,4 +1,6 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ 'fixturesFolder': false, 'supportFile': false, -} +}) diff --git a/packages/app/cypress.config.ts b/packages/app/cypress.config.ts index 551c746c5be6..63354e1f5225 100644 --- a/packages/app/cypress.config.ts +++ b/packages/app/cypress.config.ts @@ -1,5 +1,6 @@ -export default { - '$schema': '../../cli/schema/cypress.schema.json', +import { defineConfig } from 'cypress' + +export default defineConfig({ 'projectId': 'sehy69', 'viewportWidth': 800, 'viewportHeight': 850, @@ -26,4 +27,4 @@ export default { 'pluginsFile': 'cypress/e2e/plugins/index.ts', 'supportFile': 'cypress/e2e/support/e2eSupport.ts', }, -} +}) diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 1b44e9cf73c2..bc9c6a85017d 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -25,8 +25,6 @@ export interface ProjectApiShape { clearProjectPreferences(projectTitle: string): Promise clearAllProjectPreferences(): Promise closeActiveProject(): Promise - setProjectConfig(projectRoot: string, projectId: Partial | null): Promise - getProjectConfig (projectRoot: string): Promise error(type: string, ...args: any): Error } diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index a1d7d54db011..bfc0f74f4037 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -24,7 +24,7 @@ export class ProjectDataSource { } async findSpecs (projectRoot: string, specType: Maybe) { - const config = await this.ctx.project.getConfig(projectRoot) + const config = await this.getConfig(projectRoot) const specs = await this.api.findSpecs({ projectRoot, fixturesFolder: config.fixturesFolder ?? false, @@ -85,16 +85,9 @@ export class ProjectDataSource { } async getConfig (projectRoot: string) { - // Check first the config files, to be sure there are not to config files + // Check first the config files, to be sure there are no 2 config files const configFile = await this.getDefaultConfigFilePath(projectRoot) - // Check if we have already cached the config - const config = await this.api.getProjectConfig(projectRoot) - - if (config) { - return config - } - return this.configLoader({ configFile, }).load(projectRoot) diff --git a/packages/driver/cypress.config.ts b/packages/driver/cypress.config.ts index 91d140ee4609..cd5def98aefe 100644 --- a/packages/driver/cypress.config.ts +++ b/packages/driver/cypress.config.ts @@ -1,12 +1,11 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ 'projectId': 'ypt4pf', 'baseUrl': 'http://localhost:3500', 'testFiles': '**/*', - 'hosts': { - '*.foobar.com': '127.0.0.1', - }, 'reporter': 'cypress-multi-reporters', 'reporterOptions': { 'configFile': '../../mocha-reporter-config.json', }, -} +}) diff --git a/packages/frontend-shared/cypress.config.ts b/packages/frontend-shared/cypress.config.ts index d6d3b36338a6..b083724d2fa9 100644 --- a/packages/frontend-shared/cypress.config.ts +++ b/packages/frontend-shared/cypress.config.ts @@ -1,4 +1,6 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ 'projectId': 'sehy69', 'baseUrl': 'http://localhost:5555', 'viewportWidth': 800, @@ -20,4 +22,4 @@ export default { 'e2e': { 'supportFile': 'cypress/e2e/support/e2eSupport.ts', }, -} +}) diff --git a/packages/launchpad/cypress.config.ts b/packages/launchpad/cypress.config.ts index 42bef84793f5..0e349a0e6b66 100644 --- a/packages/launchpad/cypress.config.ts +++ b/packages/launchpad/cypress.config.ts @@ -1,5 +1,6 @@ -export default { - '$schema': '../../cli/schema/cypress.schema.json', +import { defineConfig } from 'cypress' + +export default defineConfig({ 'projectId': 'sehy69', 'viewportWidth': 800, 'viewportHeight': 850, @@ -24,4 +25,4 @@ export default { 'integrationFolder': 'cypress/e2e/integration', 'pluginsFile': 'cypress/e2e/plugins/index.ts', }, -} +}) diff --git a/packages/launchpad/cypress/fixtures/test-project/cypress.config.ts b/packages/launchpad/cypress/fixtures/test-project/cypress.config.ts index a6261aad3d26..eaf31cec46f1 100644 --- a/packages/launchpad/cypress/fixtures/test-project/cypress.config.ts +++ b/packages/launchpad/cypress/fixtures/test-project/cypress.config.ts @@ -1,3 +1,5 @@ -export default { +import { defineConfig } from "cypress"; + +export default defineConfig({ "projectId": "test01" -} \ No newline at end of file +}) \ No newline at end of file diff --git a/packages/reporter/cypress.config.ts b/packages/reporter/cypress.config.ts index f8ad5c41999c..55704573b981 100644 --- a/packages/reporter/cypress.config.ts +++ b/packages/reporter/cypress.config.ts @@ -1,4 +1,6 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ 'projectId': 'ypt4pf', 'baseUrl': 'http://localhost:5006', 'viewportWidth': 400, @@ -11,4 +13,4 @@ export default { 'runMode': 2, 'openMode': 0, }, -} +}) diff --git a/packages/runner-ct/cypress.config.ts b/packages/runner-ct/cypress.config.ts index b6b77d6421dd..b0f18a30e8c1 100644 --- a/packages/runner-ct/cypress.config.ts +++ b/packages/runner-ct/cypress.config.ts @@ -1,4 +1,6 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ testFiles: '**/*spec.{ts,tsx}', video: true, env: { @@ -8,4 +10,4 @@ export default { reporterOptions: { configFile: '../../mocha-reporter-config.json', }, -} +}) diff --git a/packages/server/lib/cache.js b/packages/server/lib/cache.js index 2c483ceea820..c8d134a91133 100644 --- a/packages/server/lib/cache.js +++ b/packages/server/lib/cache.js @@ -149,7 +149,7 @@ module.exports = { // having it on the cache, will help us preventing to read the file on a cp // to get the projectId setProjectConfig (projectRoot, config) { - return fileUtil.set({ PROJECTS_CONFIG: { [projectRoot]: config } }) + return fileUtil.set({ PROJECTS_CONFIG: { [projectRoot]: config } }).return(config) }, getProjectConfig (projectRoot) { diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index b1c7a930b8bb..effe02373f92 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -14,7 +14,7 @@ import * as settings from './util/settings' import Debug from 'debug' import pathHelpers from './util/path_helpers' import findSystemNode from './util/find_system_node' -import { setProjectConfig } from './cache' +import { setProjectConfig, getProjectConfig } from './cache' export interface ConfigSettingsConfig { testingType: TestingType @@ -205,24 +205,29 @@ export type FullConfig = } export function get (projectRoot, options: {configFile?: string | false } = { configFile: undefined }): Promise { - return Promise.all([ - settings.read(projectRoot, options).then(validateFile(options.configFile ?? 'cypress.config.{ts|js}')), - settings.readEnv(projectRoot).then(validateFile('cypress.env.json')), - ]) + return getProjectConfig(projectRoot) + .then((config) => { + if (config) { + return Promise.resolve([config.settings, config.envFile]) + } + + return Promise.all([ + settings.read(projectRoot, options).then(validateFile(options.configFile ?? 'cypress.config.{ts|js}')), + settings.readEnv(projectRoot).then(validateFile('cypress.env.json')), + ]) + }) .spread((settings, envFile) => { + return setProjectConfig(projectRoot, { settings, envFile }) + }) + .then((config) => { return set({ projectName: getNameFromRoot(projectRoot), projectRoot, - config: _.cloneDeep(settings), - envFile: _.cloneDeep(envFile), + config: _.cloneDeep(config.settings), + envFile: _.cloneDeep(config.envFile), options, }) }) - .then((fullConfig) => { - return setProjectConfig(projectRoot, fullConfig).then(() => { - return fullConfig - }) - }) .catch((e) => { // Cleanup the cache if there's an error to prevent showing stale data return setProjectConfig(projectRoot, null) diff --git a/packages/server/lib/makeDataContext.ts b/packages/server/lib/makeDataContext.ts index e50f59b79c32..647fe6f7d63c 100644 --- a/packages/server/lib/makeDataContext.ts +++ b/packages/server/lib/makeDataContext.ts @@ -1,6 +1,6 @@ import { DataContext } from '@packages/data-context' import specsUtil from './util/specs' -import type { FindSpecs, FoundBrowser, FullConfig, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, PlatformName, Preferences, SettingsOptions } from '@packages/types' +import type { FindSpecs, FoundBrowser, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, PlatformName, Preferences, SettingsOptions } from '@packages/types' import browserUtils from './browsers/utils' import auth from './gui/auth' import user from './user' @@ -57,12 +57,6 @@ export function makeDataContext (options: MakeDataContextOptions) { findSpecs (payload: FindSpecs) { return specsUtil.findSpecs(payload) }, - setProjectConfig (projectRoot: string, config: Partial | null) { - return cache.setProjectConfig(projectRoot, config) - }, - getProjectConfig (projectRoot: string) { - return cache.getProjectConfig(projectRoot) - }, clearLatestProjectsCache () { return cache.removeLatestProjects() }, From 3b38404a8e0850cd73eb908c444b121c028ba676 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 17:28:55 -0500 Subject: [PATCH 34/57] Attempt to fix Ci --- circle.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/circle.yml b/circle.yml index de9a7e0039b1..9b48e9428294 100644 --- a/circle.yml +++ b/circle.yml @@ -733,17 +733,17 @@ commands: fi working_directory: /tmp/<> - when: - condition: - - not: <> - steps: - - run: - name: Scaffold new config file - working_directory: /tmp/<> - environment: - CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" - command: | - rm -rf cypress.json - echo 'module.exports = {}' > cypress.config.js + condition: + - not: <> + steps: + - run: + name: Scaffold new config file + working_directory: /tmp/<> + environment: + CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" + command: | + rm -rf cypress.json + echo 'module.exports = {}' > cypress.config.js - run: name: Print Cypress version working_directory: /tmp/<> From 82372e9c3ab333beb654e6c14d60d109eaad2768 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 17:35:58 -0500 Subject: [PATCH 35/57] Attempt to fix Ci --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 9b48e9428294..65d475cd14c9 100644 --- a/circle.yml +++ b/circle.yml @@ -733,7 +733,7 @@ commands: fi working_directory: /tmp/<> - when: - condition: + condition: - not: <> steps: - run: From 3e19cc86c5229abfd315f75a801b0502fb26aee7 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 17:37:13 -0500 Subject: [PATCH 36/57] Attempt to fix Ci --- circle.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 65d475cd14c9..f08403f6b352 100644 --- a/circle.yml +++ b/circle.yml @@ -734,7 +734,8 @@ commands: working_directory: /tmp/<> - when: condition: - - not: <> + and: + - not: <> steps: - run: name: Scaffold new config file From 59e6d2cbd547c2263c994b463bd10a1ecf6d2bb6 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 17:41:22 -0500 Subject: [PATCH 37/57] Attempt to fix Ci --- circle.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/circle.yml b/circle.yml index f08403f6b352..1dbad5621cc3 100644 --- a/circle.yml +++ b/circle.yml @@ -707,6 +707,7 @@ commands: checkout_branch: description: "Name of the branch to checkout" type: string + default: $(node ./scripts/get-next-version) steps: - clone-repo-and-checkout-release-branch: repo: <> From 001b1094333eed813ecd757acae79f823d5193f6 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 18:36:46 -0500 Subject: [PATCH 38/57] Update tests, revert cache read --- circle.yml | 7 +++++ .../src/actions/ProjectActions.ts | 1 + .../src/sources/ProjectDataSource.ts | 7 +++++ packages/driver/cypress.config.ts | 9 +++--- packages/launchpad/cypress.config.ts | 6 ++-- packages/server/lib/cache.js | 2 +- packages/server/lib/config.ts | 29 ++++++++----------- packages/server/lib/errors.js | 2 +- packages/server/lib/makeDataContext.ts | 3 ++ system-tests/__snapshots__/config_spec.js | 2 +- 10 files changed, 40 insertions(+), 28 deletions(-) diff --git a/circle.yml b/circle.yml index 1dbad5621cc3..efad47033f1e 100644 --- a/circle.yml +++ b/circle.yml @@ -1636,6 +1636,13 @@ jobs: repo: cypress-example-kitchensink checkout_branch: feat/use-config-file - install-required-node + - run: + name: Remove cypress.json + description: Remove cypress.json in case it exists + working_directory: /tmp/cypress-example-kitchensink + environment: + CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" + command: rm -rf cypress.json - run: name: Install prod dependencies command: yarn --production diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index bc9c6a85017d..7decce03884b 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -25,6 +25,7 @@ export interface ProjectApiShape { clearProjectPreferences(projectTitle: string): Promise clearAllProjectPreferences(): Promise closeActiveProject(): Promise + getProjectConfig (projectRoot: string): Promise error(type: string, ...args: any): Error } diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index bfc0f74f4037..c6180417a7df 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -88,6 +88,13 @@ export class ProjectDataSource { // Check first the config files, to be sure there are no 2 config files const configFile = await this.getDefaultConfigFilePath(projectRoot) + // Check if we have already cached the config + const config = await this.api.getProjectConfig(projectRoot) + + if (config) { + return config + } + return this.configLoader({ configFile, }).load(projectRoot) diff --git a/packages/driver/cypress.config.ts b/packages/driver/cypress.config.ts index cd5def98aefe..91d140ee4609 100644 --- a/packages/driver/cypress.config.ts +++ b/packages/driver/cypress.config.ts @@ -1,11 +1,12 @@ -import { defineConfig } from 'cypress' - -export default defineConfig({ +export default { 'projectId': 'ypt4pf', 'baseUrl': 'http://localhost:3500', 'testFiles': '**/*', + 'hosts': { + '*.foobar.com': '127.0.0.1', + }, 'reporter': 'cypress-multi-reporters', 'reporterOptions': { 'configFile': '../../mocha-reporter-config.json', }, -}) +} diff --git a/packages/launchpad/cypress.config.ts b/packages/launchpad/cypress.config.ts index 0e349a0e6b66..0c82f6f8f473 100644 --- a/packages/launchpad/cypress.config.ts +++ b/packages/launchpad/cypress.config.ts @@ -1,6 +1,4 @@ -import { defineConfig } from 'cypress' - -export default defineConfig({ +export default { 'projectId': 'sehy69', 'viewportWidth': 800, 'viewportHeight': 850, @@ -25,4 +23,4 @@ export default defineConfig({ 'integrationFolder': 'cypress/e2e/integration', 'pluginsFile': 'cypress/e2e/plugins/index.ts', }, -}) +} diff --git a/packages/server/lib/cache.js b/packages/server/lib/cache.js index c8d134a91133..2c483ceea820 100644 --- a/packages/server/lib/cache.js +++ b/packages/server/lib/cache.js @@ -149,7 +149,7 @@ module.exports = { // having it on the cache, will help us preventing to read the file on a cp // to get the projectId setProjectConfig (projectRoot, config) { - return fileUtil.set({ PROJECTS_CONFIG: { [projectRoot]: config } }).return(config) + return fileUtil.set({ PROJECTS_CONFIG: { [projectRoot]: config } }) }, getProjectConfig (projectRoot) { diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index effe02373f92..b1c7a930b8bb 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -14,7 +14,7 @@ import * as settings from './util/settings' import Debug from 'debug' import pathHelpers from './util/path_helpers' import findSystemNode from './util/find_system_node' -import { setProjectConfig, getProjectConfig } from './cache' +import { setProjectConfig } from './cache' export interface ConfigSettingsConfig { testingType: TestingType @@ -205,29 +205,24 @@ export type FullConfig = } export function get (projectRoot, options: {configFile?: string | false } = { configFile: undefined }): Promise { - return getProjectConfig(projectRoot) - .then((config) => { - if (config) { - return Promise.resolve([config.settings, config.envFile]) - } - - return Promise.all([ - settings.read(projectRoot, options).then(validateFile(options.configFile ?? 'cypress.config.{ts|js}')), - settings.readEnv(projectRoot).then(validateFile('cypress.env.json')), - ]) - }) + return Promise.all([ + settings.read(projectRoot, options).then(validateFile(options.configFile ?? 'cypress.config.{ts|js}')), + settings.readEnv(projectRoot).then(validateFile('cypress.env.json')), + ]) .spread((settings, envFile) => { - return setProjectConfig(projectRoot, { settings, envFile }) - }) - .then((config) => { return set({ projectName: getNameFromRoot(projectRoot), projectRoot, - config: _.cloneDeep(config.settings), - envFile: _.cloneDeep(config.envFile), + config: _.cloneDeep(settings), + envFile: _.cloneDeep(envFile), options, }) }) + .then((fullConfig) => { + return setProjectConfig(projectRoot, fullConfig).then(() => { + return fullConfig + }) + }) .catch((e) => { // Cleanup the cache if there's an error to prevent showing stale data return setProjectConfig(projectRoot, null) diff --git a/packages/server/lib/errors.js b/packages/server/lib/errors.js index 131b79251961..4237bd52293b 100644 --- a/packages/server/lib/errors.js +++ b/packages/server/lib/errors.js @@ -702,7 +702,7 @@ const getMsgByType = function (type, arg1 = {}, arg2, arg3) { We looked but did not find a default config file in this folder: ${chalk.blue(arg1)}` case 'CONFIG_FILE_MIGRATION_NEEDED': return stripIndent` - There is both a cypress.json file ar the location below: + There is cypress.json file at the location below: ${arg1} Cypress does not support any more 'cypress.json' config, migrate to 'cypress.config.{ts|js}'. diff --git a/packages/server/lib/makeDataContext.ts b/packages/server/lib/makeDataContext.ts index 647fe6f7d63c..0a4c9c2ed7a4 100644 --- a/packages/server/lib/makeDataContext.ts +++ b/packages/server/lib/makeDataContext.ts @@ -57,6 +57,9 @@ export function makeDataContext (options: MakeDataContextOptions) { findSpecs (payload: FindSpecs) { return specsUtil.findSpecs(payload) }, + getProjectConfig (projectRoot: string) { + return cache.getProjectConfig(projectRoot) + }, clearLatestProjectsCache () { return cache.removeLatestProjects() }, diff --git a/system-tests/__snapshots__/config_spec.js b/system-tests/__snapshots__/config_spec.js index ccda31c3fe80..5071a64f57d3 100644 --- a/system-tests/__snapshots__/config_spec.js +++ b/system-tests/__snapshots__/config_spec.js @@ -163,7 +163,7 @@ Cypress does not know which one to read for config. Please remove one of the two ` exports['e2e config throws error when cypress.json is found in project and need migration 1'] = ` -There is both a cypress.json file ar the location below: +There is cypress.json file at the location below: /foo/bar/.projects/pristine Cypress does not support any more 'cypress.json' config, migrate to 'cypress.config.{ts|js}'. From bd503ecad69f2cdb85332ff299db24de4408fe69 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 18:37:53 -0500 Subject: [PATCH 39/57] Fix circleCi file --- circle.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/circle.yml b/circle.yml index efad47033f1e..0bfed5344571 100644 --- a/circle.yml +++ b/circle.yml @@ -1637,12 +1637,12 @@ jobs: checkout_branch: feat/use-config-file - install-required-node - run: - name: Remove cypress.json - description: Remove cypress.json in case it exists - working_directory: /tmp/cypress-example-kitchensink - environment: - CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" - command: rm -rf cypress.json + name: Remove cypress.json + description: Remove cypress.json in case it exists + working_directory: /tmp/cypress-example-kitchensink + environment: + CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" + command: rm -rf cypress.json - run: name: Install prod dependencies command: yarn --production From d7322d17ca40dbce8fab20197f0bfbc89a5797b3 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 19:04:10 -0500 Subject: [PATCH 40/57] Update circleCi file --- circle.yml | 42 ++++++++--------------- packages/server/lib/errors.js | 2 +- system-tests/__snapshots__/config_spec.js | 2 +- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/circle.yml b/circle.yml index 0bfed5344571..5f66af90f40a 100644 --- a/circle.yml +++ b/circle.yml @@ -523,17 +523,13 @@ commands: repo: description: "Name of the github repo to clone like: cypress-example-kitchensink" type: string - checkout_branch: - description: "Name of the branch to checkout" - type: string - default: $(node ./scripts/get-next-version) steps: - restore_cached_binary - run: name: "Cloning test project: <>" command: | git clone --depth 1 --no-single-branch https://github.com/cypress-io/<>.git /tmp/<> - cd /tmp/<> && (git checkout <> || true) + cd /tmp/<> && (git checkout $(node ./scripts/get-next-version) || true) test-binary-against-rwa: description: | @@ -704,14 +700,9 @@ commands: description: Server start command for repo type: string default: "npm start --if-present" - checkout_branch: - description: "Name of the branch to checkout" - type: string - default: $(node ./scripts/get-next-version) steps: - clone-repo-and-checkout-release-branch: repo: <> - checkout_branch: <> - when: condition: <> steps: @@ -733,19 +724,16 @@ commands: CYPRESS_INSTALL_BINARY=~/cypress/cypress.zip npm install ~/cypress/cypress.tgz fi working_directory: /tmp/<> - - when: - condition: - and: - - not: <> - steps: - - run: - name: Scaffold new config file - working_directory: /tmp/<> - environment: - CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" - command: | - rm -rf cypress.json - echo 'module.exports = {}' > cypress.config.js + - run: + name: Scaffold new config file + working_directory: /tmp/<> + environment: + CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" + command: | + if [[ -f cypress.json ]]; then + rm -rf cypress.json + echo 'module.exports = {}' > cypress.config.js + fi - run: name: Print Cypress version working_directory: /tmp/<> @@ -1634,7 +1622,7 @@ jobs: steps: - clone-repo-and-checkout-release-branch: repo: cypress-example-kitchensink - checkout_branch: feat/use-config-file + pull_request_id: 510 - install-required-node - run: name: Remove cypress.json @@ -1978,7 +1966,7 @@ jobs: - test-binary-against-repo: repo: cypress-example-kitchensink browser: "electron" - checkout_branch: feat/use-config-file + pull_request_id: 510 test-binary-against-awesome-typescript-loader: <<: *defaults @@ -1994,7 +1982,7 @@ jobs: - test-binary-against-repo: repo: cypress-example-kitchensink browser: firefox - checkout_branch: feat/use-config-file + pull_request_id: 510 "test-binary-against-kitchensink-chrome": <<: *defaults @@ -2003,7 +1991,7 @@ jobs: - test-binary-against-repo: repo: cypress-example-kitchensink browser: chrome - checkout_branch: feat/use-config-file + pull_request_id: 510 "test-binary-against-todomvc-firefox": <<: *defaults diff --git a/packages/server/lib/errors.js b/packages/server/lib/errors.js index 4237bd52293b..95fc0ba6dfe7 100644 --- a/packages/server/lib/errors.js +++ b/packages/server/lib/errors.js @@ -702,7 +702,7 @@ const getMsgByType = function (type, arg1 = {}, arg2, arg3) { We looked but did not find a default config file in this folder: ${chalk.blue(arg1)}` case 'CONFIG_FILE_MIGRATION_NEEDED': return stripIndent` - There is cypress.json file at the location below: + There is a cypress.json file at the location below: ${arg1} Cypress does not support any more 'cypress.json' config, migrate to 'cypress.config.{ts|js}'. diff --git a/system-tests/__snapshots__/config_spec.js b/system-tests/__snapshots__/config_spec.js index 5071a64f57d3..b5667cab8849 100644 --- a/system-tests/__snapshots__/config_spec.js +++ b/system-tests/__snapshots__/config_spec.js @@ -163,7 +163,7 @@ Cypress does not know which one to read for config. Please remove one of the two ` exports['e2e config throws error when cypress.json is found in project and need migration 1'] = ` -There is cypress.json file at the location below: +There is a cypress.json file at the location below: /foo/bar/.projects/pristine Cypress does not support any more 'cypress.json' config, migrate to 'cypress.config.{ts|js}'. From 3a0f9d2b5b975f0b3c7af4b5a559d97864e447f1 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 19:05:05 -0500 Subject: [PATCH 41/57] Update circleCi file --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 5f66af90f40a..b2da5dc24e3f 100644 --- a/circle.yml +++ b/circle.yml @@ -729,7 +729,7 @@ commands: working_directory: /tmp/<> environment: CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" - command: | + command: | if [[ -f cypress.json ]]; then rm -rf cypress.json echo 'module.exports = {}' > cypress.config.js From f8e291b3ef5dd64b4a73ca27a04a286f6b564014 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 28 Oct 2021 19:09:20 -0500 Subject: [PATCH 42/57] Update circleCi file --- circle.yml | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/circle.yml b/circle.yml index b2da5dc24e3f..05941114e508 100644 --- a/circle.yml +++ b/circle.yml @@ -516,13 +516,17 @@ commands: steps: - run: yarn verify:mocha:results <> - clone-repo-and-checkout-release-branch: + clone-repo-and-checkout-branch: description: | Clones an external repo and then checks out the branch that matches the next version otherwise uses 'master' branch. parameters: repo: description: "Name of the github repo to clone like: cypress-example-kitchensink" type: string + pull_request_id: + description: Pull request number to check out before installing and testing + type: integer + default: 0 steps: - restore_cached_binary - run: @@ -530,6 +534,16 @@ commands: command: | git clone --depth 1 --no-single-branch https://github.com/cypress-io/<>.git /tmp/<> cd /tmp/<> && (git checkout $(node ./scripts/get-next-version) || true) + - when: + condition: <> + steps: + - run: + name: Check out PR <> + working_directory: /tmp/<> + command: | + git fetch origin pull/<>/head:pr-<> + git checkout pr-<> + git log -n 2 test-binary-against-rwa: description: | @@ -571,7 +585,7 @@ commands: type: string default: "CI=true yarn start" steps: - - clone-repo-and-checkout-release-branch: + - clone-repo-and-checkout-branch: repo: <> - when: condition: <> @@ -701,18 +715,9 @@ commands: type: string default: "npm start --if-present" steps: - - clone-repo-and-checkout-release-branch: + - clone-repo-and-checkout-branch: repo: <> - - when: - condition: <> - steps: - - run: - name: Check out PR <> - working_directory: /tmp/<> - command: | - git fetch origin pull/<>/head:pr-<> - git checkout pr-<> - git log -n 2 + pull_request_id: <> - run: # Install deps + Cypress binary with yarn if yarn.lock present command: | @@ -1620,7 +1625,7 @@ jobs: test-kitchensink: <<: *defaults steps: - - clone-repo-and-checkout-release-branch: + - clone-repo-and-checkout-branch: repo: cypress-example-kitchensink pull_request_id: 510 - install-required-node @@ -1655,7 +1660,7 @@ jobs: <<: *defaults resource_class: medium steps: - - clone-repo-and-checkout-release-branch: + - clone-repo-and-checkout-branch: repo: cypress-example-kitchensink - run: name: Install prod dependencies @@ -1680,7 +1685,7 @@ jobs: <<: *defaults resource_class: medium steps: - - clone-repo-and-checkout-release-branch: + - clone-repo-and-checkout-branch: repo: cypress-test-tiny - run: name: Run test project @@ -1914,7 +1919,7 @@ jobs: <<: *defaults steps: - restore_workspace_binaries - - clone-repo-and-checkout-release-branch: + - clone-repo-and-checkout-branch: repo: cypress-test-tiny - run: name: Install Cypress From 108b7f834ddc742e38f97a6c3256a192e155da6c Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 29 Oct 2021 09:31:14 -0500 Subject: [PATCH 43/57] Revert default config file for tests --- cli/test/lib/exec/open_spec.js | 2 +- cli/test/lib/exec/run_spec.js | 2 +- packages/server/lib/util/settings.ts | 4 ++- .../server/test/integration/cypress_spec.js | 28 +++++++++---------- packages/server/test/unit/config_spec.js | 10 +++---- packages/server/test/unit/files_spec.js | 2 +- packages/server/test/unit/fixture_spec.js | 4 +-- packages/server/test/unit/project_spec.js | 6 ++-- packages/server/test/unit/scaffold_spec.js | 12 ++++---- packages/server/test/unit/screenshots_spec.js | 2 +- packages/server/test/unit/socket_spec.js | 2 +- packages/server/test/unit/specs_spec.js | 18 ++++++------ system-tests/lib/system-tests.ts | 2 +- 13 files changed, 48 insertions(+), 46 deletions(-) diff --git a/cli/test/lib/exec/open_spec.js b/cli/test/lib/exec/open_spec.js index fcb975f8dd9c..33c4d2d9e640 100644 --- a/cli/test/lib/exec/open_spec.js +++ b/cli/test/lib/exec/open_spec.js @@ -66,7 +66,7 @@ describe('exec open', function () { }) it('spawns with --config-file set', function () { - return open.start({ configFile: 'special-cypress.config.js' }) + return open.start() .then(() => { expect(spawn.start).to.be.calledWith( ['--config-file', 'special-cypress.config.js'], diff --git a/cli/test/lib/exec/run_spec.js b/cli/test/lib/exec/run_spec.js index 0f23ef74c234..d01fa4cdbdf7 100644 --- a/cli/test/lib/exec/run_spec.js +++ b/cli/test/lib/exec/run_spec.js @@ -150,7 +150,7 @@ describe('exec run', function () { }) it('spawns with --config-file set', function () { - return run.start({ configFile: 'special-cypress.config.js' }) + return run.start() .then(() => { expect(spawn.start).to.be.calledWith( ['--run-project', process.cwd(), '--config-file', 'special-cypress.config.js'], diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index 56c70a46c349..ff50e69f4ab5 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -125,7 +125,9 @@ export function isComponentTesting (options: SettingsOptions = {}) { } export function configFile (options: SettingsOptions = {}) { - return options.configFile === false ? false : options.configFile + // default is only used in tests. + // This prevents a the change from becoming bigger than it should + return options.configFile === false ? false : (options.configFile || 'cypress.config.js') } export function id (projectRoot, options = {}) { diff --git a/packages/server/test/integration/cypress_spec.js b/packages/server/test/integration/cypress_spec.js index 4fac28a289fd..53b4aa11de9c 100644 --- a/packages/server/test/integration/cypress_spec.js +++ b/packages/server/test/integration/cypress_spec.js @@ -370,7 +370,7 @@ describe('lib/cypress', () => { }).then(() => { expect(api.createProject).not.to.be.called - return (new ProjectBase({ projectRoot: this.noScaffolding, testingType: 'e2e', options: { configFile: 'cypress.config.js' } })).getProjectId() + return (new ProjectBase({ projectRoot: this.noScaffolding, testingType: 'e2e' })).getProjectId() .then(() => { throw new Error('should have caught error but did not') }).catch((err) => { @@ -457,7 +457,7 @@ describe('lib/cypress', () => { }) it('scaffolds out integration and example specs if they do not exist when not runMode', function () { - return config.get(this.pristineWithConfigPath, { configFile: 'cypress.config.js' }) + return config.get(this.pristineWithConfigPath) .then((cfg) => { return fs.statAsync(cfg.integrationFolder) .then(() => { @@ -518,7 +518,7 @@ describe('lib/cypress', () => { }) it('scaffolds out fixtures + files if they do not exist', function () { - return config.get(this.pristineWithConfigPath, { configFile: 'cypress.config.js' }) + return config.get(this.pristineWithConfigPath) .then((cfg) => { return fs.statAsync(cfg.fixturesFolder) .then(() => { @@ -536,7 +536,7 @@ describe('lib/cypress', () => { it('scaffolds out support + files if they do not exist', function () { const supportFolder = path.join(this.pristineWithConfigPath, 'cypress/support') - return config.get(this.pristineWithConfigPath, { configFile: 'cypress.config.js' }) + return config.get(this.pristineWithConfigPath) .then(() => { return fs.statAsync(supportFolder) .then(() => { @@ -554,17 +554,17 @@ describe('lib/cypress', () => { }) it('removes fixtures when they exist and fixturesFolder is false', function (done) { - config.get(this.idsPath, { configFile: 'cypress.config.js' }) + config.get(this.idsPath) .then((cfg) => { this.cfg = cfg return fs.statAsync(this.cfg.fixturesFolder) }).then(() => { - return settings.read(this.idsPath, { configFile: 'cypress.config.js' }) + return settings.read(this.idsPath) }).then((json) => { json.fixturesFolder = false - return settings.write(this.idsPath, json, { configFile: 'cypress.config.js' }) + return settings.write(this.idsPath, json) }).then(() => { return cypress.start([`--run-project=${this.idsPath}`]) }).then(() => { @@ -612,15 +612,15 @@ describe('lib/cypress', () => { it('can change the reporter with cypress.config.js', function () { sinon.spy(Reporter, 'create') - return config.get(this.idsPath, { configFile: 'cypress.config.js' }) + return config.get(this.idsPath) .then((cfg) => { this.cfg = cfg - return settings.read(this.idsPath, { configFile: 'cypress.config.js' }) + return settings.read(this.idsPath) }).then((json) => { json.reporter = 'dot' - return settings.write(this.idsPath, json, { configFile: 'cypress.config.js' }) + return settings.write(this.idsPath, json) }).then(() => { return cypress.start([`--run-project=${this.idsPath}`]) }).then(() => { @@ -678,7 +678,7 @@ describe('lib/cypress', () => { }) it('logs error when supportFile doesn\'t exist', function () { - return settings.write(this.idsPath, { supportFile: '/does/not/exist' }, { configFile: 'cypress.config.js' }) + return settings.write(this.idsPath, { supportFile: '/does/not/exist' }) .then(() => { return cypress.start([`--run-project=${this.idsPath}`]) }).then(() => { @@ -784,7 +784,7 @@ describe('lib/cypress', () => { }) it('logs error and exits when project has invalid cypress.config.js values', function () { - return settings.write(this.todosPath, { baseUrl: 'localhost:9999' }, { configFile: 'cypress.config.js' }) + return settings.write(this.todosPath, { baseUrl: 'localhost:9999' }) .then(() => { return cypress.start([`--run-project=${this.todosPath}`]) }).then(() => { @@ -1693,12 +1693,12 @@ describe('lib/cypress', () => { return user.set({ name: 'brian', authToken: 'auth-token-123' }) .then(() => { - return settings.read(this.todosPath, { configFile: 'cypress.config.js' }) + return settings.read(this.todosPath) }).then((json) => { // this should be overriden by the env argument json.baseUrl = 'http://localhost:8080' - return settings.write(this.todosPath, json, { configFile: 'cypress.config.js' }) + return settings.write(this.todosPath, json) }).then(() => { return cypress.start([ '--port=2121', diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index 91ed07d03b67..1c5733059da8 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -65,7 +65,7 @@ describe('lib/config', () => { it('sets projectRoot', function () { this.setup({}, { foo: 'bar' }) - return config.get(this.projectRoot, { configFile: 'cypress.config.js' }) + return config.get(this.projectRoot) .then((obj) => { expect(obj.projectRoot).to.eq(this.projectRoot) @@ -76,7 +76,7 @@ describe('lib/config', () => { it('sets projectName', function () { this.setup({}, { foo: 'bar' }) - return config.get(this.projectRoot, { configFile: 'cypress.config.js' }) + return config.get(this.projectRoot) .then((obj) => { expect(obj.projectName).to.eq('project') }) @@ -88,7 +88,7 @@ describe('lib/config', () => { this.setup(settings, envSettings) - return config.get(this.projectRoot, { configFile: 'cypress.config.js' }) + return config.get(this.projectRoot) .then(() => { expect(settings).to.deep.equal({ foo: 'bar' }) expect(envSettings).to.deep.equal({ baz: 'qux' }) @@ -125,11 +125,11 @@ describe('lib/config', () => { context('validation', () => { beforeEach(function () { this.expectValidationPasses = () => { - return config.get(this.projectRoot, { configFile: 'cypress.config.js' }) // shouldn't throw + return config.get(this.projectRoot) // shouldn't throw } this.expectValidationFails = (errorMessage = 'validation error') => { - return config.get(this.projectRoot, { configFile: 'cypress.config.js' }) + return config.get(this.projectRoot) .then(() => { throw new Error('should throw validation error') }).catch((err) => { diff --git a/packages/server/test/unit/files_spec.js b/packages/server/test/unit/files_spec.js index f42d3e87cbc3..7361badf75c8 100644 --- a/packages/server/test/unit/files_spec.js +++ b/packages/server/test/unit/files_spec.js @@ -10,7 +10,7 @@ describe('lib/files', () => { this.todosPath = FixturesHelper.projectPath('todos') - return config.get(this.todosPath, { configFile: 'cypress.config.js' }).then((cfg) => { + return config.get(this.todosPath).then((cfg) => { this.config = cfg; ({ projectRoot: this.projectRoot } = cfg) }) diff --git a/packages/server/test/unit/fixture_spec.js b/packages/server/test/unit/fixture_spec.js index 4564d54dd009..9046a19f395c 100644 --- a/packages/server/test/unit/fixture_spec.js +++ b/packages/server/test/unit/fixture_spec.js @@ -19,7 +19,7 @@ describe('lib/fixture', () => { this.todosPath = FixturesHelper.projectPath('todos') - return config.get(this.todosPath, { configFile: 'cypress.config.js' }).then((cfg) => { + return config.get(this.todosPath).then((cfg) => { ({ fixturesFolder: this.fixturesFolder } = cfg) }) }) @@ -169,7 +169,7 @@ Expecting 'EOF', '}', ':', ',', ']', got 'STRING'\ it('can load a fixture with no extension when a same-named folder also exists', () => { const projectPath = FixturesHelper.projectPath('folder-same-as-fixture') - return config.get(projectPath, { configFile: 'cypress.config.js' }) + return config.get(projectPath) .then((cfg) => { return fixture.get(cfg.fixturesFolder, 'foo') .then((fixture) => { diff --git a/packages/server/test/unit/project_spec.js b/packages/server/test/unit/project_spec.js index 62a2d6cec3e4..82540674e8bb 100644 --- a/packages/server/test/unit/project_spec.js +++ b/packages/server/test/unit/project_spec.js @@ -53,7 +53,7 @@ describe('lib/project-base', () => { sinon.stub(runEvents, 'execute').resolves() - return settings.read(this.todosPath, { configFile: 'cypress.config.js' }).then((obj = {}) => { + return settings.read(this.todosPath).then((obj = {}) => { ({ projectId: this.projectId } = obj) return config.set({ projectName: 'project', projectRoot: '/foo/bar' }) @@ -968,7 +968,7 @@ This option will not have an effect in Some-other-name. Tests that rely on web s }) it('inserts path into cache', function () { - return add(this.pristinePath, { configFile: 'cypress.config.js' }) + return add(this.pristinePath) .then(() => cache.read()).then((json) => { expect(json.PROJECTS).to.deep.eq([this.pristinePath]) }) @@ -991,7 +991,7 @@ This option will not have an effect in Some-other-name. Tests that rely on web s it('returns object containing just the path', function () { sinon.stub(settings, 'read').rejects() - return add(this.pristinePath, { configFile: 'cypress.config.js' }) + return add(this.pristinePath) .then((project) => { expect(project.id).to.be.undefined diff --git a/packages/server/test/unit/scaffold_spec.js b/packages/server/test/unit/scaffold_spec.js index e880242e1cf2..2a6a8d00dd4a 100644 --- a/packages/server/test/unit/scaffold_spec.js +++ b/packages/server/test/unit/scaffold_spec.js @@ -131,7 +131,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const pristinePath = Fixtures.projectPath('pristine-with-config-file') - return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { + return config.get(pristinePath).then((cfg) => { this.cfg = cfg; ({ integrationFolder: this.integrationFolder } = this.cfg) }) @@ -214,7 +214,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const pristinePath = Fixtures.projectPath('pristine-with-config-file') - return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { + return config.get(pristinePath).then((cfg) => { this.cfg = cfg; ({ integrationFolder: this.integrationFolder } = this.cfg) }) @@ -325,7 +325,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const pristinePath = Fixtures.projectPath('pristine-with-config-file') - return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { + return config.get(pristinePath).then((cfg) => { this.cfg = cfg; ({ supportFolder: this.supportFolder } = this.cfg) }) @@ -402,7 +402,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const pristinePath = Fixtures.projectPath('pristine-with-config-file') - return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { + return config.get(pristinePath).then((cfg) => { this.cfg = cfg; ({ pluginsFile: this.pluginsFile } = this.cfg) this.pluginsFolder = path.dirname(this.pluginsFile) @@ -458,7 +458,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const pristinePath = Fixtures.projectPath('pristine-with-config-file') - return config.get(pristinePath, { configFile: 'cypress.config.js' }).then((cfg) => { + return config.get(pristinePath).then((cfg) => { this.cfg = cfg; ({ fixturesFolder: this.fixturesFolder } = this.cfg) }) @@ -533,7 +533,7 @@ describe('lib/scaffold', () => { beforeEach(function () { const todosPath = Fixtures.projectPath('todos') - return config.get(todosPath, { configFile: 'cypress.config.js' }).then((cfg) => { + return config.get(todosPath).then((cfg) => { this.cfg = cfg this.cfg.pluginsFile = path.join(this.cfg.projectRoot, 'cypress/plugins/index.js') }) diff --git a/packages/server/test/unit/screenshots_spec.js b/packages/server/test/unit/screenshots_spec.js index 19805d3ec2dd..2cebcfeefa45 100644 --- a/packages/server/test/unit/screenshots_spec.js +++ b/packages/server/test/unit/screenshots_spec.js @@ -56,7 +56,7 @@ describe('lib/screenshots', () => { Jimp.prototype.composite = sinon.stub() // Jimp.prototype.getBuffer = sinon.stub().resolves(@buffer) - return config.get(this.todosPath, { configFile: 'cypress.config.js' }).then((config1) => { + return config.get(this.todosPath).then((config1) => { this.config = config1 }) }) diff --git a/packages/server/test/unit/socket_spec.js b/packages/server/test/unit/socket_spec.js index e7a5afeac397..cc055b97ca5a 100644 --- a/packages/server/test/unit/socket_spec.js +++ b/packages/server/test/unit/socket_spec.js @@ -26,7 +26,7 @@ describe('lib/socket', () => { this.todosPath = Fixtures.projectPath('todos') this.server = new ServerE2E(this.todosPath) - return config.get(this.todosPath, { configFile: 'cypress.config.js' }) + return config.get(this.todosPath) .then((cfg) => { this.cfg = cfg }) diff --git a/packages/server/test/unit/specs_spec.js b/packages/server/test/unit/specs_spec.js index 634e23872927..2f72cfb4aaf9 100644 --- a/packages/server/test/unit/specs_spec.js +++ b/packages/server/test/unit/specs_spec.js @@ -13,7 +13,7 @@ describe('lib/util/specs', () => { this.todosPath = FixturesHelper.projectPath('todos') - return config.get(this.todosPath, { configFile: 'cypress.config.js' }) + return config.get(this.todosPath) .then((cfg) => { this.config = cfg }) @@ -47,7 +47,7 @@ describe('lib/util/specs', () => { }) it('by default, returns all files as long as they have a name and extension', () => { - return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) + return config.get(FixturesHelper.projectPath('various-file-types')) .then((cfg) => { return specsUtil.findSpecs(cfg) }).then((files) => { @@ -60,7 +60,7 @@ describe('lib/util/specs', () => { }) it('finds integration and component tests and assigns correct specType', () => { - return config.get(FixturesHelper.projectPath('component-tests'), { configFile: 'cypress.config.js' }) + return config.get(FixturesHelper.projectPath('component-tests')) .then((cfg) => { cfg.resolved.testingType = { value: 'component' } @@ -85,7 +85,7 @@ describe('lib/util/specs', () => { }) it('returns files matching config.testFiles', () => { - return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) + return config.get(FixturesHelper.projectPath('various-file-types')) .then((cfg) => { cfg.testFiles = '**/*.coffee' @@ -98,7 +98,7 @@ describe('lib/util/specs', () => { }) it('uses glob to process config.testFiles', () => { - return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) + return config.get(FixturesHelper.projectPath('various-file-types')) .then((cfg) => { cfg.testFiles = '{coffee_*.coffee,js_spec.js}' @@ -113,7 +113,7 @@ describe('lib/util/specs', () => { }) it('allows array in config.testFiles', () => { - return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) + return config.get(FixturesHelper.projectPath('various-file-types')) .then((cfg) => { cfg.testFiles = ['coffee_*.coffee', 'js_spec.js'] @@ -128,7 +128,7 @@ describe('lib/util/specs', () => { }) it('filters using specPattern', () => { - return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) + return config.get(FixturesHelper.projectPath('various-file-types')) .then((cfg) => { const specPattern = [ path.join(cfg.projectRoot, 'cypress', 'integration', 'js_spec.js'), @@ -143,7 +143,7 @@ describe('lib/util/specs', () => { }) it('filters using specPattern as array of glob patterns', () => { - return config.get(FixturesHelper.projectPath('various-file-types'), { configFile: 'cypress.config.js' }) + return config.get(FixturesHelper.projectPath('various-file-types')) .then((cfg) => { debug('test config testFiles is %o', cfg.testFiles) const specPattern = [ @@ -161,7 +161,7 @@ describe('lib/util/specs', () => { }) it('properly handles directories with names including \'.\'', () => { - return config.get(FixturesHelper.projectPath('odd-directory-name'), { configFile: 'cypress.config.js' }) + return config.get(FixturesHelper.projectPath('odd-directory-name')) .then((cfg) => { return specsUtil.findSpecs(cfg) }).then((files) => { diff --git a/system-tests/lib/system-tests.ts b/system-tests/lib/system-tests.ts index b7d7ec69bd83..f739cc359687 100644 --- a/system-tests/lib/system-tests.ts +++ b/system-tests/lib/system-tests.ts @@ -683,7 +683,7 @@ const systemTests = { const s = options.settings if (s) { - await settings.write(e2ePath, s, { configFile: 'cypress.config.js' }) + await settings.write(e2ePath, s) } }) From 7ec7622035d4c676a43eb8491ef6477601e1e949 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 29 Oct 2021 09:32:47 -0500 Subject: [PATCH 44/57] Update error message --- packages/server/lib/errors.js | 4 ++-- system-tests/__snapshots__/config_spec.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/server/lib/errors.js b/packages/server/lib/errors.js index 95fc0ba6dfe7..3d121e2301fc 100644 --- a/packages/server/lib/errors.js +++ b/packages/server/lib/errors.js @@ -705,14 +705,14 @@ const getMsgByType = function (type, arg1 = {}, arg2, arg3) { There is a cypress.json file at the location below: ${arg1} - Cypress does not support any more 'cypress.json' config, migrate to 'cypress.config.{ts|js}'. + Cypress no longer supports 'cypress.json', please migrate to 'cypress.config.{ts|js}'. ` case 'LEGACY_CONFIG_FILE': return stripIndent` There is both a \`${arg2}\` and a cypress.json file at the location below: ${arg1} - Cypress does not support any more 'cypress.json' config, remove it from your files. + Cypress no longer supports 'cypress.json' config, please remove it from your project. ` // TODO: update with vetted cypress language case 'CONFIG_FILES_LANGUAGE_CONFLICT': diff --git a/system-tests/__snapshots__/config_spec.js b/system-tests/__snapshots__/config_spec.js index b5667cab8849..59b4710799e6 100644 --- a/system-tests/__snapshots__/config_spec.js +++ b/system-tests/__snapshots__/config_spec.js @@ -166,7 +166,7 @@ exports['e2e config throws error when cypress.json is found in project and need There is a cypress.json file at the location below: /foo/bar/.projects/pristine -Cypress does not support any more 'cypress.json' config, migrate to 'cypress.config.{ts|js}'. +Cypress no longer supports 'cypress.json', please migrate to 'cypress.config.{ts|js}'. ` @@ -175,7 +175,7 @@ exports['e2e config throws error when cypress.json is found in project and cypre There is both a \`cypress.config.js\` and a cypress.json file at the location below: /foo/bar/.projects/multiples-config-files-with-json -Cypress does not support any more 'cypress.json' config, remove it from your files. +Cypress no longer supports 'cypress.json' config, please remove it from your project. ` From 1a40e5a3e6aecbf74e4c12f4dd953e28b3196459 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 29 Oct 2021 10:42:39 -0500 Subject: [PATCH 45/57] Update wizard step --- .../data-context/src/actions/WizardActions.ts | 4 ++-- .../cypress/e2e/support/e2eProjectDirs.ts | 1 + .../e2e/integration/onboarding-flow.spec.ts | 12 ++++++++--- .../cypress.config.js | 6 ++++++ .../cypress/plugins/index.js | 21 +++++++++++++++++++ .../unify-onboarding-with-config/index.html | 0 .../unify-onboarding/cypress.config.js | 7 +------ 7 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 system-tests/projects/unify-onboarding-with-config/cypress.config.js create mode 100644 system-tests/projects/unify-onboarding-with-config/cypress/plugins/index.js create mode 100644 system-tests/projects/unify-onboarding-with-config/index.html diff --git a/packages/data-context/src/actions/WizardActions.ts b/packages/data-context/src/actions/WizardActions.ts index 41cb24dafb57..7d6a672a4915 100644 --- a/packages/data-context/src/actions/WizardActions.ts +++ b/packages/data-context/src/actions/WizardActions.ts @@ -120,7 +120,7 @@ export class WizardActions { } if (this.data.currentStep === 'welcome' && this.data.chosenTestingType === 'component') { - if (this.ctx.activeProject?.isCTConfigured) { + if (!this.ctx.activeProject?.isCTConfigured) { this.navigateToStep('selectFramework') } else if (!this.ctx.activeProject?.ctPluginsInitialized) { // not first time, and we haven't initialized plugins - initialize them @@ -134,7 +134,7 @@ export class WizardActions { } if (this.data.currentStep === 'welcome' && this.data.chosenTestingType === 'e2e') { - if (this.ctx.activeProject?.isE2EConfigured) { + if (!this.ctx.activeProject?.isE2EConfigured) { this.navigateToStep('configFiles') } else if (!this.ctx.activeProject?.e2ePluginsInitialized) { // not first time, and we haven't initialized plugins - initialize them diff --git a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts index 4d903fba6cd5..449a9a82ec80 100644 --- a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts +++ b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts @@ -78,6 +78,7 @@ export const e2eProjectDirs = [ 'ts-proj-with-paths', 'uncaught-support-file', 'unify-onboarding', + 'unify-onboarding-with-config', 'unify-plugin-errors', 'various-file-types', 'webpack-preprocessor', diff --git a/packages/launchpad/cypress/e2e/integration/onboarding-flow.spec.ts b/packages/launchpad/cypress/e2e/integration/onboarding-flow.spec.ts index fea2270ea945..a53ef1db6481 100644 --- a/packages/launchpad/cypress/e2e/integration/onboarding-flow.spec.ts +++ b/packages/launchpad/cypress/e2e/integration/onboarding-flow.spec.ts @@ -1,10 +1,8 @@ describe('Onboarding Flow', () => { - beforeEach(() => { + it('can scaffold a project in e2e mode', () => { cy.setupE2E('unify-onboarding') cy.loginUser() - }) - it('can scaffold a project in e2e mode', () => { cy.visitLaunchpad() cy.get('[data-cy-testingType=component]').click() cy.get('[data-cy=select-framework]').click() @@ -19,4 +17,12 @@ describe('Onboarding Flow', () => { cy.findByText('Next Step').click() cy.get('h1').should('contain', 'Dependencies') }) + + it('redirects to initialize plugin if CT is configured', () => { + cy.setupE2E('unify-onboarding-with-config') + + cy.visitLaunchpad() + cy.get('[data-cy-testingType=component]').click() + cy.get('h1').should('contain', 'Initializing Config...') + }) }) diff --git a/system-tests/projects/unify-onboarding-with-config/cypress.config.js b/system-tests/projects/unify-onboarding-with-config/cypress.config.js new file mode 100644 index 000000000000..39e12cab152c --- /dev/null +++ b/system-tests/projects/unify-onboarding-with-config/cypress.config.js @@ -0,0 +1,6 @@ +module.exports = { + component: { + testFiles: '**/*cy-spec.{js,jsx,ts,tsx}', + componentFolder: 'src', + }, +} diff --git a/system-tests/projects/unify-onboarding-with-config/cypress/plugins/index.js b/system-tests/projects/unify-onboarding-with-config/cypress/plugins/index.js new file mode 100644 index 000000000000..d8e8f3f055c6 --- /dev/null +++ b/system-tests/projects/unify-onboarding-with-config/cypress/plugins/index.js @@ -0,0 +1,21 @@ +/// +const { startDevServer } = require('@cypress/webpack-dev-server') + +const webpackConfig = { + output: { + publicPath: '/', + }, +} + +/** + * @type Cypress.PluginConfig + */ +module.exports = (on, config) => { + if (config.testingType !== 'component') { + throw Error(`This is an component testing project. testingType should be 'component'. Received ${config.testingType}`) + } + + on('dev-server:start', (options) => startDevServer({ options, webpackConfig })) + + return config +} diff --git a/system-tests/projects/unify-onboarding-with-config/index.html b/system-tests/projects/unify-onboarding-with-config/index.html new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/system-tests/projects/unify-onboarding/cypress.config.js b/system-tests/projects/unify-onboarding/cypress.config.js index 39e12cab152c..4ba52ba2c8df 100644 --- a/system-tests/projects/unify-onboarding/cypress.config.js +++ b/system-tests/projects/unify-onboarding/cypress.config.js @@ -1,6 +1 @@ -module.exports = { - component: { - testFiles: '**/*cy-spec.{js,jsx,ts,tsx}', - componentFolder: 'src', - }, -} +module.exports = {} From 0702fbbf974683971e7f6fa82ed23c083ec50e26 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 29 Oct 2021 12:01:03 -0500 Subject: [PATCH 46/57] Do not save confi in file cache --- packages/data-context/src/DataContext.ts | 16 +--- packages/data-context/src/DataContextShell.ts | 14 ++- .../src/actions/ProjectActions.ts | 1 - .../data-context/src/data/coreDataShape.ts | 9 ++ .../src/sources/ProjectDataSource.ts | 7 -- packages/server/lib/cache.js | 13 --- packages/server/lib/config.ts | 46 +++++++--- packages/server/lib/makeDataContext.ts | 91 +++++++++---------- packages/server/lib/project-base.ts | 9 +- packages/server/lib/util/settings.ts | 9 +- 10 files changed, 105 insertions(+), 110 deletions(-) diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index da4946542ed7..5559b7290890 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -5,7 +5,6 @@ import type { NexusGenAbstractTypeMembers } from '@packages/graphql/src/gen/nxs. import type { AuthApiShape } from './actions/AuthActions' import debugLib from 'debug' import fsExtra from 'fs-extra' -import { CoreDataShape, makeCoreData } from './data/coreDataShape' import { DataActions } from './DataActions' import { AppDataSource, @@ -27,21 +26,15 @@ export interface DataContextConfig extends DataContextShellConfig { os: PlatformName launchArgs: LaunchArgs launchOptions: OpenProjectLaunchOptions - /** - * Default is to - */ - coreData?: CoreDataShape /** * Injected from the server */ appApi: AppApiShape authApi: AuthApiShape - projectApi: ProjectApiShape + projectApi: (ctx: DataContext) => ProjectApiShape } export class DataContext extends DataContextShell { - private _coreData: CoreDataShape - @cached get fs () { return fsExtra @@ -54,7 +47,6 @@ export class DataContext extends DataContextShell { constructor (private config: DataContextConfig) { super(config) - this._coreData = config.coreData ?? makeCoreData() } async initializeData () { @@ -98,10 +90,6 @@ export class DataContext extends DataContextShell { return this.config.launchOptions } - get coreData () { - return this._coreData - } - get user () { return this.coreData.user } @@ -188,7 +176,7 @@ export class DataContext extends DataContextShell { return { appApi: this.config.appApi, authApi: this.config.authApi, - projectApi: this.config.projectApi, + projectApi: this.config.projectApi(this), busApi: this.config.rootBus, } } diff --git a/packages/data-context/src/DataContextShell.ts b/packages/data-context/src/DataContextShell.ts index 97692c675c3d..d399437b8391 100644 --- a/packages/data-context/src/DataContextShell.ts +++ b/packages/data-context/src/DataContextShell.ts @@ -3,9 +3,14 @@ import type { Server } from 'http' import type { AddressInfo } from 'net' import { DataEmitterActions } from './actions/DataEmitterActions' import { cached } from './util/cached' +import { CoreDataShape, makeCoreData } from './data/coreDataShape' export interface DataContextShellConfig { rootBus: EventEmitter + /** + * Default is to + */ + coreData?: CoreDataShape } // Used in places where we have to create a "shell" data context, @@ -14,8 +19,11 @@ export class DataContextShell { private _gqlServer?: Server private _appServerPort: number | undefined private _gqlServerPort: number | undefined + private _coreData: CoreDataShape - constructor (private shellConfig: DataContextShellConfig = { rootBus: new EventEmitter }) {} + constructor (private shellConfig: DataContextShellConfig = { rootBus: new EventEmitter }) { + this._coreData = shellConfig.coreData ?? makeCoreData() + } setAppServerPort (port: number | undefined) { this._appServerPort = port @@ -45,6 +53,10 @@ export class DataContextShell { } } + get coreData () { + return this._coreData + } + destroy () { this._gqlServer?.close() } diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 7decce03884b..bc9c6a85017d 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -25,7 +25,6 @@ export interface ProjectApiShape { clearProjectPreferences(projectTitle: string): Promise clearAllProjectPreferences(): Promise closeActiveProject(): Promise - getProjectConfig (projectRoot: string): Promise error(type: string, ...args: any): Error } diff --git a/packages/data-context/src/data/coreDataShape.ts b/packages/data-context/src/data/coreDataShape.ts index eab9bd288308..d8fa97a6bd0d 100644 --- a/packages/data-context/src/data/coreDataShape.ts +++ b/packages/data-context/src/data/coreDataShape.ts @@ -63,6 +63,11 @@ export interface BaseErrorDataShape { stack?: string } +export interface ActiveProjectConfig { + settings: Cypress.ConfigOptions + envFile: Cypress.ObjectLike +} + export interface CoreDataShape { baseError: BaseErrorDataShape | null dev: DevStateShape @@ -70,6 +75,9 @@ export interface CoreDataShape { wizard: WizardDataShape user: AuthenticatedUserShape | null electron: ElectronShape + activeProjectConfig: { + [key: string]: ActiveProjectConfig | null + } } /** @@ -77,6 +85,7 @@ export interface CoreDataShape { */ export function makeCoreData (): CoreDataShape { return { + activeProjectConfig: {}, baseError: null, dev: { refreshState: null, diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index c6180417a7df..bfc0f74f4037 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -88,13 +88,6 @@ export class ProjectDataSource { // Check first the config files, to be sure there are no 2 config files const configFile = await this.getDefaultConfigFilePath(projectRoot) - // Check if we have already cached the config - const config = await this.api.getProjectConfig(projectRoot) - - if (config) { - return config - } - return this.configLoader({ configFile, }).load(projectRoot) diff --git a/packages/server/lib/cache.js b/packages/server/lib/cache.js index 2c483ceea820..adba40cbb4d0 100644 --- a/packages/server/lib/cache.js +++ b/packages/server/lib/cache.js @@ -145,19 +145,6 @@ module.exports = { return fileUtil.set({ USER: {} }) }, - // We may need to set this value every time the config file is read, or updated - // having it on the cache, will help us preventing to read the file on a cp - // to get the projectId - setProjectConfig (projectRoot, config) { - return fileUtil.set({ PROJECTS_CONFIG: { [projectRoot]: config } }) - }, - - getProjectConfig (projectRoot) { - return fileUtil.get('PROJECTS_CONFIG').then((projects) => { - return projects && projects[projectRoot] ? projects[projectRoot] : null - }) - }, - removeLatestProjects () { return fileUtil.set({ PROJECTS: [] }) }, diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index b1c7a930b8bb..f7e879e827d3 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -14,7 +14,6 @@ import * as settings from './util/settings' import Debug from 'debug' import pathHelpers from './util/path_helpers' import findSystemNode from './util/find_system_node' -import { setProjectConfig } from './cache' export interface ConfigSettingsConfig { testingType: TestingType @@ -25,6 +24,7 @@ const debug = Debug('cypress:server:config') import { options, breakingOptions } from './config_options' import { getProcessEnvVars } from './util/config' +import type { DataContextShell } from '@packages/data-context/src/DataContextShell' export const CYPRESS_ENV_PREFIX = 'CYPRESS_' @@ -204,12 +204,29 @@ export type FullConfig = resolved: ResolvedConfigurationOptions } -export function get (projectRoot, options: {configFile?: string | false } = { configFile: undefined }): Promise { - return Promise.all([ - settings.read(projectRoot, options).then(validateFile(options.configFile ?? 'cypress.config.{ts|js}')), - settings.readEnv(projectRoot).then(validateFile('cypress.env.json')), - ]) +export function get (projectRoot, options: {configFile?: string | false } = { configFile: undefined }, ctx?: DataContextShell): Promise { + return Promise.resolve(ctx?.coreData.activeProjectConfig[projectRoot]) + .then((config) => { + if (config) { + return Promise.resolve([config.settings, config.envFile]) + } + + return Promise.all([ + settings.read(projectRoot, options).then(validateFile(options.configFile ?? 'cypress.config.{ts|js}')), + settings.readEnv(projectRoot).then(validateFile('cypress.env.json')), + ]) + }) .spread((settings, envFile) => { + if (ctx) { + ctx.coreData.activeProjectConfig = { + ...ctx.coreData.activeProjectConfig, + [projectRoot]: { + settings, + envFile, + }, + } + } + return set({ projectName: getNameFromRoot(projectRoot), projectRoot, @@ -218,17 +235,16 @@ export function get (projectRoot, options: {configFile?: string | false } = { co options, }) }) - .then((fullConfig) => { - return setProjectConfig(projectRoot, fullConfig).then(() => { - return fullConfig - }) - }) .catch((e) => { // Cleanup the cache if there's an error to prevent showing stale data - return setProjectConfig(projectRoot, null) - .then(() => { - throw e - }) + if (ctx?.coreData.activeProjectConfig) { + ctx.coreData.activeProjectConfig = { + ...ctx.coreData.activeProjectConfig, + [projectRoot]: null, + } + } + + throw e }) } diff --git a/packages/server/lib/makeDataContext.ts b/packages/server/lib/makeDataContext.ts index 0a4c9c2ed7a4..605152e4e8b3 100644 --- a/packages/server/lib/makeDataContext.ts +++ b/packages/server/lib/makeDataContext.ts @@ -38,52 +38,51 @@ export function makeDataContext (options: MakeDataContextOptions) { return user.logOut() }, }, - projectApi: { - getConfig (projectRoot: string, options?: SettingsOptions) { - return config.get(projectRoot, options) - }, - launchProject (browser: FoundBrowser, spec: Cypress.Spec, options?: LaunchOpts) { - return openProject.launch({ ...browser }, spec, options) - }, - initializeProject (args: LaunchArgs, options: OpenProjectLaunchOptions, browsers: FoundBrowser[]) { - return openProject.create(args.projectRoot, args, options, browsers) - }, - insertProjectToCache (projectRoot: string) { - cache.insertProject(projectRoot) - }, - getProjectRootsFromCache () { - return cache.getProjectRoots() - }, - findSpecs (payload: FindSpecs) { - return specsUtil.findSpecs(payload) - }, - getProjectConfig (projectRoot: string) { - return cache.getProjectConfig(projectRoot) - }, - clearLatestProjectsCache () { - return cache.removeLatestProjects() - }, - getProjectPreferencesFromCache () { - return cache.getProjectPreferences() - }, - clearProjectPreferences (projectTitle: string) { - return cache.removeProjectPreferences(projectTitle) - }, - clearAllProjectPreferences () { - return cache.removeAllProjectPreferences() - }, - insertProjectPreferencesToCache (projectTitle: string, preferences: Preferences) { - cache.insertProjectPreferences(projectTitle, preferences) - }, - removeProjectFromCache (path: string) { - return cache.removeProject(path) - }, - closeActiveProject () { - return openProject.closeActiveProject() - }, - error (type: string, ...args: any) { - throw errors.throw(type, ...args) - }, + projectApi (ctx: DataContext) { + return { + getConfig (projectRoot: string, options?: SettingsOptions) { + return config.get(projectRoot, options, ctx) + }, + launchProject (browser: FoundBrowser, spec: Cypress.Spec, options?: LaunchOpts) { + return openProject.launch({ ...browser }, spec, options) + }, + initializeProject (args: LaunchArgs, options: OpenProjectLaunchOptions, browsers: FoundBrowser[]) { + return openProject.create(args.projectRoot, args, options, browsers) + }, + insertProjectToCache (projectRoot: string) { + cache.insertProject(projectRoot) + }, + getProjectRootsFromCache () { + return cache.getProjectRoots() + }, + findSpecs (payload: FindSpecs) { + return specsUtil.findSpecs(payload) + }, + clearLatestProjectsCache () { + return cache.removeLatestProjects() + }, + getProjectPreferencesFromCache () { + return cache.getProjectPreferences() + }, + clearProjectPreferences (projectTitle: string) { + return cache.removeProjectPreferences(projectTitle) + }, + clearAllProjectPreferences () { + return cache.removeAllProjectPreferences() + }, + insertProjectPreferencesToCache (projectTitle: string, preferences: Preferences) { + cache.insertProjectPreferences(projectTitle, preferences) + }, + removeProjectFromCache (path: string) { + return cache.removeProject(path) + }, + closeActiveProject () { + return openProject.closeActiveProject() + }, + error (type: string, ...args: any) { + throw errors.throw(type, ...args) + }, + } }, }) } diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index 80a166d5a214..57c44dc73bc4 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -34,7 +34,6 @@ import { SpecsStore } from './specs-store' import { checkSupportFile, getDefaultConfigFilePath } from './project_utils' import type { FoundBrowser, OpenProjectLaunchOptions } from '@packages/types' import { DataContextShell } from '@packages/data-context/src/DataContextShell' -import { getProjectConfig } from './cache' // Cannot just use RuntimeConfigOptions as is because some types are not complete. // Instead, this is an interface of values that have been manually validated to exist @@ -706,7 +705,7 @@ export class ProjectBase extends EE { this.options.configFile = await getDefaultConfigFilePath(this.projectRoot) } - let theCfg: Cfg = await config.get(this.projectRoot, this.options) + let theCfg: Cfg = await config.get(this.projectRoot, this.options, this.ctx) if (!theCfg.browsers || theCfg.browsers.length === 0) { // @ts-ignore - we don't know if the browser is headed or headless at this point. @@ -861,10 +860,10 @@ export class ProjectBase extends EE { async getProjectId () { await this.verifyExistence() - const config = await getProjectConfig(this.projectRoot) + const config = this.ctx.coreData.activeProjectConfig[this.projectRoot] - if (config?.projectId) { - return config.projectId + if (config?.settings.projectId) { + return config.settings.projectId } const readSettings = await settings.read(this.projectRoot, this.options) diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index ff50e69f4ab5..188458287560 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -6,7 +6,6 @@ import { fs } from '../util/fs' import { requireAsync } from './require_async' import Debug from 'debug' import type { SettingsOptions } from '@packages/types' -import { getProjectConfig } from '../cache' const debug = Debug('cypress:server:settings') @@ -131,13 +130,7 @@ export function configFile (options: SettingsOptions = {}) { } export function id (projectRoot, options = {}) { - return getProjectConfig(projectRoot).then((config) => { - if (config) { - return Promise.resolve(config) - } - - return read(projectRoot, options) - }) + return read(projectRoot, options) .then((config) => config.projectId) .catch(() => { return null From 3048ac605802974c7b2ede07d74b0c5ac5fd08cd Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Fri, 29 Oct 2021 16:43:43 -0400 Subject: [PATCH 47/57] Revert "Do not save confi in file cache" This reverts commit 0702fbbf974683971e7f6fa82ed23c083ec50e26. --- packages/data-context/src/DataContext.ts | 16 +++- packages/data-context/src/DataContextShell.ts | 14 +-- .../src/actions/ProjectActions.ts | 1 + .../data-context/src/data/coreDataShape.ts | 9 -- .../src/sources/ProjectDataSource.ts | 7 ++ packages/server/lib/cache.js | 13 +++ packages/server/lib/config.ts | 46 +++------- packages/server/lib/makeDataContext.ts | 91 ++++++++++--------- packages/server/lib/project-base.ts | 9 +- packages/server/lib/util/settings.ts | 9 +- 10 files changed, 110 insertions(+), 105 deletions(-) diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index 5559b7290890..da4946542ed7 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -5,6 +5,7 @@ import type { NexusGenAbstractTypeMembers } from '@packages/graphql/src/gen/nxs. import type { AuthApiShape } from './actions/AuthActions' import debugLib from 'debug' import fsExtra from 'fs-extra' +import { CoreDataShape, makeCoreData } from './data/coreDataShape' import { DataActions } from './DataActions' import { AppDataSource, @@ -26,15 +27,21 @@ export interface DataContextConfig extends DataContextShellConfig { os: PlatformName launchArgs: LaunchArgs launchOptions: OpenProjectLaunchOptions + /** + * Default is to + */ + coreData?: CoreDataShape /** * Injected from the server */ appApi: AppApiShape authApi: AuthApiShape - projectApi: (ctx: DataContext) => ProjectApiShape + projectApi: ProjectApiShape } export class DataContext extends DataContextShell { + private _coreData: CoreDataShape + @cached get fs () { return fsExtra @@ -47,6 +54,7 @@ export class DataContext extends DataContextShell { constructor (private config: DataContextConfig) { super(config) + this._coreData = config.coreData ?? makeCoreData() } async initializeData () { @@ -90,6 +98,10 @@ export class DataContext extends DataContextShell { return this.config.launchOptions } + get coreData () { + return this._coreData + } + get user () { return this.coreData.user } @@ -176,7 +188,7 @@ export class DataContext extends DataContextShell { return { appApi: this.config.appApi, authApi: this.config.authApi, - projectApi: this.config.projectApi(this), + projectApi: this.config.projectApi, busApi: this.config.rootBus, } } diff --git a/packages/data-context/src/DataContextShell.ts b/packages/data-context/src/DataContextShell.ts index d399437b8391..97692c675c3d 100644 --- a/packages/data-context/src/DataContextShell.ts +++ b/packages/data-context/src/DataContextShell.ts @@ -3,14 +3,9 @@ import type { Server } from 'http' import type { AddressInfo } from 'net' import { DataEmitterActions } from './actions/DataEmitterActions' import { cached } from './util/cached' -import { CoreDataShape, makeCoreData } from './data/coreDataShape' export interface DataContextShellConfig { rootBus: EventEmitter - /** - * Default is to - */ - coreData?: CoreDataShape } // Used in places where we have to create a "shell" data context, @@ -19,11 +14,8 @@ export class DataContextShell { private _gqlServer?: Server private _appServerPort: number | undefined private _gqlServerPort: number | undefined - private _coreData: CoreDataShape - constructor (private shellConfig: DataContextShellConfig = { rootBus: new EventEmitter }) { - this._coreData = shellConfig.coreData ?? makeCoreData() - } + constructor (private shellConfig: DataContextShellConfig = { rootBus: new EventEmitter }) {} setAppServerPort (port: number | undefined) { this._appServerPort = port @@ -53,10 +45,6 @@ export class DataContextShell { } } - get coreData () { - return this._coreData - } - destroy () { this._gqlServer?.close() } diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index bc9c6a85017d..7decce03884b 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -25,6 +25,7 @@ export interface ProjectApiShape { clearProjectPreferences(projectTitle: string): Promise clearAllProjectPreferences(): Promise closeActiveProject(): Promise + getProjectConfig (projectRoot: string): Promise error(type: string, ...args: any): Error } diff --git a/packages/data-context/src/data/coreDataShape.ts b/packages/data-context/src/data/coreDataShape.ts index d8fa97a6bd0d..eab9bd288308 100644 --- a/packages/data-context/src/data/coreDataShape.ts +++ b/packages/data-context/src/data/coreDataShape.ts @@ -63,11 +63,6 @@ export interface BaseErrorDataShape { stack?: string } -export interface ActiveProjectConfig { - settings: Cypress.ConfigOptions - envFile: Cypress.ObjectLike -} - export interface CoreDataShape { baseError: BaseErrorDataShape | null dev: DevStateShape @@ -75,9 +70,6 @@ export interface CoreDataShape { wizard: WizardDataShape user: AuthenticatedUserShape | null electron: ElectronShape - activeProjectConfig: { - [key: string]: ActiveProjectConfig | null - } } /** @@ -85,7 +77,6 @@ export interface CoreDataShape { */ export function makeCoreData (): CoreDataShape { return { - activeProjectConfig: {}, baseError: null, dev: { refreshState: null, diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index bfc0f74f4037..c6180417a7df 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -88,6 +88,13 @@ export class ProjectDataSource { // Check first the config files, to be sure there are no 2 config files const configFile = await this.getDefaultConfigFilePath(projectRoot) + // Check if we have already cached the config + const config = await this.api.getProjectConfig(projectRoot) + + if (config) { + return config + } + return this.configLoader({ configFile, }).load(projectRoot) diff --git a/packages/server/lib/cache.js b/packages/server/lib/cache.js index adba40cbb4d0..2c483ceea820 100644 --- a/packages/server/lib/cache.js +++ b/packages/server/lib/cache.js @@ -145,6 +145,19 @@ module.exports = { return fileUtil.set({ USER: {} }) }, + // We may need to set this value every time the config file is read, or updated + // having it on the cache, will help us preventing to read the file on a cp + // to get the projectId + setProjectConfig (projectRoot, config) { + return fileUtil.set({ PROJECTS_CONFIG: { [projectRoot]: config } }) + }, + + getProjectConfig (projectRoot) { + return fileUtil.get('PROJECTS_CONFIG').then((projects) => { + return projects && projects[projectRoot] ? projects[projectRoot] : null + }) + }, + removeLatestProjects () { return fileUtil.set({ PROJECTS: [] }) }, diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index f7e879e827d3..b1c7a930b8bb 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -14,6 +14,7 @@ import * as settings from './util/settings' import Debug from 'debug' import pathHelpers from './util/path_helpers' import findSystemNode from './util/find_system_node' +import { setProjectConfig } from './cache' export interface ConfigSettingsConfig { testingType: TestingType @@ -24,7 +25,6 @@ const debug = Debug('cypress:server:config') import { options, breakingOptions } from './config_options' import { getProcessEnvVars } from './util/config' -import type { DataContextShell } from '@packages/data-context/src/DataContextShell' export const CYPRESS_ENV_PREFIX = 'CYPRESS_' @@ -204,29 +204,12 @@ export type FullConfig = resolved: ResolvedConfigurationOptions } -export function get (projectRoot, options: {configFile?: string | false } = { configFile: undefined }, ctx?: DataContextShell): Promise { - return Promise.resolve(ctx?.coreData.activeProjectConfig[projectRoot]) - .then((config) => { - if (config) { - return Promise.resolve([config.settings, config.envFile]) - } - - return Promise.all([ - settings.read(projectRoot, options).then(validateFile(options.configFile ?? 'cypress.config.{ts|js}')), - settings.readEnv(projectRoot).then(validateFile('cypress.env.json')), - ]) - }) +export function get (projectRoot, options: {configFile?: string | false } = { configFile: undefined }): Promise { + return Promise.all([ + settings.read(projectRoot, options).then(validateFile(options.configFile ?? 'cypress.config.{ts|js}')), + settings.readEnv(projectRoot).then(validateFile('cypress.env.json')), + ]) .spread((settings, envFile) => { - if (ctx) { - ctx.coreData.activeProjectConfig = { - ...ctx.coreData.activeProjectConfig, - [projectRoot]: { - settings, - envFile, - }, - } - } - return set({ projectName: getNameFromRoot(projectRoot), projectRoot, @@ -235,16 +218,17 @@ export function get (projectRoot, options: {configFile?: string | false } = { co options, }) }) + .then((fullConfig) => { + return setProjectConfig(projectRoot, fullConfig).then(() => { + return fullConfig + }) + }) .catch((e) => { // Cleanup the cache if there's an error to prevent showing stale data - if (ctx?.coreData.activeProjectConfig) { - ctx.coreData.activeProjectConfig = { - ...ctx.coreData.activeProjectConfig, - [projectRoot]: null, - } - } - - throw e + return setProjectConfig(projectRoot, null) + .then(() => { + throw e + }) }) } diff --git a/packages/server/lib/makeDataContext.ts b/packages/server/lib/makeDataContext.ts index 605152e4e8b3..0a4c9c2ed7a4 100644 --- a/packages/server/lib/makeDataContext.ts +++ b/packages/server/lib/makeDataContext.ts @@ -38,51 +38,52 @@ export function makeDataContext (options: MakeDataContextOptions) { return user.logOut() }, }, - projectApi (ctx: DataContext) { - return { - getConfig (projectRoot: string, options?: SettingsOptions) { - return config.get(projectRoot, options, ctx) - }, - launchProject (browser: FoundBrowser, spec: Cypress.Spec, options?: LaunchOpts) { - return openProject.launch({ ...browser }, spec, options) - }, - initializeProject (args: LaunchArgs, options: OpenProjectLaunchOptions, browsers: FoundBrowser[]) { - return openProject.create(args.projectRoot, args, options, browsers) - }, - insertProjectToCache (projectRoot: string) { - cache.insertProject(projectRoot) - }, - getProjectRootsFromCache () { - return cache.getProjectRoots() - }, - findSpecs (payload: FindSpecs) { - return specsUtil.findSpecs(payload) - }, - clearLatestProjectsCache () { - return cache.removeLatestProjects() - }, - getProjectPreferencesFromCache () { - return cache.getProjectPreferences() - }, - clearProjectPreferences (projectTitle: string) { - return cache.removeProjectPreferences(projectTitle) - }, - clearAllProjectPreferences () { - return cache.removeAllProjectPreferences() - }, - insertProjectPreferencesToCache (projectTitle: string, preferences: Preferences) { - cache.insertProjectPreferences(projectTitle, preferences) - }, - removeProjectFromCache (path: string) { - return cache.removeProject(path) - }, - closeActiveProject () { - return openProject.closeActiveProject() - }, - error (type: string, ...args: any) { - throw errors.throw(type, ...args) - }, - } + projectApi: { + getConfig (projectRoot: string, options?: SettingsOptions) { + return config.get(projectRoot, options) + }, + launchProject (browser: FoundBrowser, spec: Cypress.Spec, options?: LaunchOpts) { + return openProject.launch({ ...browser }, spec, options) + }, + initializeProject (args: LaunchArgs, options: OpenProjectLaunchOptions, browsers: FoundBrowser[]) { + return openProject.create(args.projectRoot, args, options, browsers) + }, + insertProjectToCache (projectRoot: string) { + cache.insertProject(projectRoot) + }, + getProjectRootsFromCache () { + return cache.getProjectRoots() + }, + findSpecs (payload: FindSpecs) { + return specsUtil.findSpecs(payload) + }, + getProjectConfig (projectRoot: string) { + return cache.getProjectConfig(projectRoot) + }, + clearLatestProjectsCache () { + return cache.removeLatestProjects() + }, + getProjectPreferencesFromCache () { + return cache.getProjectPreferences() + }, + clearProjectPreferences (projectTitle: string) { + return cache.removeProjectPreferences(projectTitle) + }, + clearAllProjectPreferences () { + return cache.removeAllProjectPreferences() + }, + insertProjectPreferencesToCache (projectTitle: string, preferences: Preferences) { + cache.insertProjectPreferences(projectTitle, preferences) + }, + removeProjectFromCache (path: string) { + return cache.removeProject(path) + }, + closeActiveProject () { + return openProject.closeActiveProject() + }, + error (type: string, ...args: any) { + throw errors.throw(type, ...args) + }, }, }) } diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index 57c44dc73bc4..80a166d5a214 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -34,6 +34,7 @@ import { SpecsStore } from './specs-store' import { checkSupportFile, getDefaultConfigFilePath } from './project_utils' import type { FoundBrowser, OpenProjectLaunchOptions } from '@packages/types' import { DataContextShell } from '@packages/data-context/src/DataContextShell' +import { getProjectConfig } from './cache' // Cannot just use RuntimeConfigOptions as is because some types are not complete. // Instead, this is an interface of values that have been manually validated to exist @@ -705,7 +706,7 @@ export class ProjectBase extends EE { this.options.configFile = await getDefaultConfigFilePath(this.projectRoot) } - let theCfg: Cfg = await config.get(this.projectRoot, this.options, this.ctx) + let theCfg: Cfg = await config.get(this.projectRoot, this.options) if (!theCfg.browsers || theCfg.browsers.length === 0) { // @ts-ignore - we don't know if the browser is headed or headless at this point. @@ -860,10 +861,10 @@ export class ProjectBase extends EE { async getProjectId () { await this.verifyExistence() - const config = this.ctx.coreData.activeProjectConfig[this.projectRoot] + const config = await getProjectConfig(this.projectRoot) - if (config?.settings.projectId) { - return config.settings.projectId + if (config?.projectId) { + return config.projectId } const readSettings = await settings.read(this.projectRoot, this.options) diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index 188458287560..ff50e69f4ab5 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -6,6 +6,7 @@ import { fs } from '../util/fs' import { requireAsync } from './require_async' import Debug from 'debug' import type { SettingsOptions } from '@packages/types' +import { getProjectConfig } from '../cache' const debug = Debug('cypress:server:settings') @@ -130,7 +131,13 @@ export function configFile (options: SettingsOptions = {}) { } export function id (projectRoot, options = {}) { - return read(projectRoot, options) + return getProjectConfig(projectRoot).then((config) => { + if (config) { + return Promise.resolve(config) + } + + return read(projectRoot, options) + }) .then((config) => config.projectId) .catch(() => { return null From cee98b333108ada00b8a5dc53131d0eda693285d Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Fri, 29 Oct 2021 17:38:43 -0400 Subject: [PATCH 48/57] Pairing w/ alejandro --- packages/data-context/src/DataContext.ts | 34 ++++++----- .../src/actions/ProjectActions.ts | 6 +- .../data-context/src/data/coreDataShape.ts | 11 +++- packages/data-context/src/gen/index.ts | 4 ++ .../src/sources/ConfigDataSource.ts | 52 +++++++++++++++++ .../src/sources/ProjectDataSource.ts | 58 ++----------------- packages/server/lib/cache.js | 13 ----- packages/server/lib/configFiles.ts | 4 -- packages/server/lib/makeDataContext.ts | 28 +++++++-- packages/server/lib/modes/index.ts | 6 ++ packages/server/lib/project-base.ts | 7 ++- packages/server/lib/project_utils.ts | 32 +--------- 12 files changed, 130 insertions(+), 125 deletions(-) create mode 100644 packages/data-context/src/gen/index.ts create mode 100644 packages/data-context/src/sources/ConfigDataSource.ts delete mode 100644 packages/server/lib/configFiles.ts diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index da4946542ed7..056f9e0b95c7 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -20,6 +20,7 @@ import { } from './sources/' import { cached } from './util/cached' import { DataContextShell, DataContextShellConfig } from './DataContextShell' +import { ConfigDataSource } from './sources/ConfigDataSource' const IS_DEV_ENV = process.env.CYPRESS_INTERNAL_ENV !== 'production' @@ -52,9 +53,9 @@ export class DataContext extends DataContextShell { return path } - constructor (private config: DataContextConfig) { - super(config) - this._coreData = config.coreData ?? makeCoreData() + constructor (private _config: DataContextConfig) { + super(_config) + this._coreData = _config.coreData ?? makeCoreData() } async initializeData () { @@ -68,14 +69,14 @@ export class DataContext extends DataContextShell { this.actions.auth.getUser(), ] - if (this.config.launchArgs.projectRoot) { - toAwait.push(this.actions.project.setActiveProject(this.config.launchArgs.projectRoot)) + if (this._config.launchArgs.projectRoot) { + toAwait.push(this.actions.project.setActiveProject(this._config.launchArgs.projectRoot)) } - if (this.config.launchArgs.testingType) { + if (this._config.launchArgs.testingType) { // It should be possible to skip the first step in the wizard, if the // user already told us the testing type via command line argument - this.actions.wizard.setTestingType(this.config.launchArgs.testingType) + this.actions.wizard.setTestingType(this._config.launchArgs.testingType) this.actions.wizard.navigate('forward') } @@ -87,15 +88,15 @@ export class DataContext extends DataContextShell { } get os () { - return this.config.os + return this._config.os } get launchArgs () { - return this.config.launchArgs + return this._config.launchArgs } get launchOptions () { - return this.config.launchOptions + return this._config.launchOptions } get coreData () { @@ -157,6 +158,11 @@ export class DataContext extends DataContextShell { return new WizardDataSource(this) } + @cached + get config () { + return new ConfigDataSource(this) + } + @cached get storybook () { return new StorybookDataSource(this) @@ -186,10 +192,10 @@ export class DataContext extends DataContextShell { get _apis () { return { - appApi: this.config.appApi, - authApi: this.config.authApi, - projectApi: this.config.projectApi, - busApi: this.config.rootBus, + appApi: this._config.appApi, + authApi: this._config.authApi, + projectApi: this._config.projectApi, + busApi: this._config.rootBus, } } diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 7decce03884b..16710e804aad 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -25,7 +25,6 @@ export interface ProjectApiShape { clearProjectPreferences(projectTitle: string): Promise clearAllProjectPreferences(): Promise closeActiveProject(): Promise - getProjectConfig (projectRoot: string): Promise error(type: string, ...args: any): Error } @@ -66,9 +65,9 @@ export class ProjectActions { e2ePluginsInitialized: false, isCTConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'component'), isE2EConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'e2e'), - config: await this.ctx.project.getResolvedConfigFields(projectRoot), preferences: await this.ctx.project.getProjectPreferences(title), generatedSpec: null, + config: null, } return this @@ -250,7 +249,8 @@ export class ProjectActions { } const parsed = path.parse(codeGenCandidate) - const config = await this.ctx.project.getConfig(project.projectRoot) + const config = await this.ctx.config.getConfigForProject(project.projectRoot) + const getFileExtension = () => { if (codeGenType === 'integration') { const possibleExtensions = ['.spec', '.test', '-spec', '-test'] diff --git a/packages/data-context/src/data/coreDataShape.ts b/packages/data-context/src/data/coreDataShape.ts index eab9bd288308..028284cd6cbd 100644 --- a/packages/data-context/src/data/coreDataShape.ts +++ b/packages/data-context/src/data/coreDataShape.ts @@ -1,6 +1,7 @@ -import { BUNDLERS, FoundBrowser, FoundSpec, GeneratedSpec, Preferences, ResolvedFromConfig } from '@packages/types' +import { BUNDLERS, FoundBrowser, FoundSpec, FullConfig, GeneratedSpec, Preferences } from '@packages/types' import type { NexusGenEnums, TestingTypeEnum } from '@packages/graphql/src/gen/nxs.gen' import type { BrowserWindow } from 'electron' +import type { ChildProcess } from 'child_process' export type Maybe = T | null | undefined @@ -18,6 +19,11 @@ export interface DevStateShape { refreshState: null | string } +export interface ConfigChildProcessShape { + process: ChildProcess + executedPlugins: null | 'e2e' | 'ct' +} + export interface ActiveProjectShape extends ProjectShape { title: string ctPluginsInitialized: Maybe @@ -26,7 +32,8 @@ export interface ActiveProjectShape extends ProjectShape { isE2EConfigured: Maybe currentSpecId?: Maybe specs?: FoundSpec[] - config: ResolvedFromConfig[] + config: Promise | null + configChildProcess: ConfigChildProcessShape | null preferences?: Preferences| null generatedSpec: GeneratedSpec | null } diff --git a/packages/data-context/src/gen/index.ts b/packages/data-context/src/gen/index.ts new file mode 100644 index 000000000000..eb90cbc93476 --- /dev/null +++ b/packages/data-context/src/gen/index.ts @@ -0,0 +1,4 @@ +/* eslint-disable padding-line-between-statements */ +// created by autobarrel, do not modify directly + +export * from './all-operations.gen' diff --git a/packages/data-context/src/sources/ConfigDataSource.ts b/packages/data-context/src/sources/ConfigDataSource.ts new file mode 100644 index 000000000000..879bfd01b467 --- /dev/null +++ b/packages/data-context/src/sources/ConfigDataSource.ts @@ -0,0 +1,52 @@ +import type { FullConfig } from '@packages/types' +import type { DataContext } from '..' + +export class ConfigDataSource { + constructor (private ctx: DataContext) {} + + async getConfigForProject (projectRoot: string): Promise { + if (!this.ctx.coreData.app.activeProject) { + throw new Error(`Cannot access config without activeProject`) + } + + if (!this.ctx.coreData.app.activeProject.config) { + this.ctx.coreData.app.activeProject.config = Promise.resolve().then(async () => { + const configFile = await this.ctx.config.getDefaultConfigBasename(projectRoot) + + return this.ctx._apis.projectApi.getConfig(projectRoot, { configFile }) + }) + } + + return this.ctx.coreData.app.activeProject.config + } + + async getDefaultConfigBasename (projectRoot: string) { + const cypressConfigFiles = ['cypress.config.js', 'cypress.config.ts'] + const filesInProjectDir = await this.ctx.fs.readdir(projectRoot) + + const foundConfigFiles = cypressConfigFiles.filter((file) => filesInProjectDir.includes(file)) + + if (foundConfigFiles.length === 1) { + const configFile = foundConfigFiles[0] + + if (configFile === 'cypress.json') { + throw this.ctx._apis.projectApi.error('CONFIG_FILE_MIGRATION_NEEDED', projectRoot, configFile) + } + + return configFile + } + + // if we found more than one, throw a language conflict + if (foundConfigFiles.length > 1) { + if (foundConfigFiles.includes('cypress.json')) { + const foundFiles = foundConfigFiles.filter((f) => f !== 'cypress.json') + + throw this.ctx._apis.projectApi.error('LEGACY_CONFIG_FILE', projectRoot, ...foundFiles) + } + + throw this.ctx._apis.projectApi.error('CONFIG_FILES_LANGUAGE_CONFLICT', projectRoot, ...foundConfigFiles) + } + + throw this.ctx._apis.projectApi.error('NO_DEFAULT_CONFIG_FILE_FOUND', projectRoot) + } +} diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index c6180417a7df..6579e396297a 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -1,5 +1,5 @@ import type { CodeGenType, SpecType } from '@packages/graphql/src/gen/nxs.gen' -import { FrontendFramework, FRONTEND_FRAMEWORKS, FullConfig, ResolvedFromConfig, RESOLVED_FROM, SettingsOptions, SpecFile, STORYBOOK_GLOB } from '@packages/types' +import { FrontendFramework, FRONTEND_FRAMEWORKS, ResolvedFromConfig, RESOLVED_FROM, SpecFile, STORYBOOK_GLOB } from '@packages/types' import { scanFSForAvailableDependency } from 'create-cypress-tests/src/findPackageJson' import path from 'path' @@ -23,6 +23,10 @@ export class ProjectDataSource { return path.basename(projectRoot) } + getConfig (projectRoot: string) { + return this.ctx.config.getConfigForProject(projectRoot) + } + async findSpecs (projectRoot: string, specType: Maybe) { const config = await this.getConfig(projectRoot) const specs = await this.api.findSpecs({ @@ -54,52 +58,6 @@ export class ProjectDataSource { return specs.find((x) => x.absolute === currentSpecAbs) ?? null } - private async getDefaultConfigFilePath (projectRoot: string) { - const cypressConfigFiles = ['cypress.config.js', 'cypress.config.ts'] - const filesInProjectDir = await this.ctx.fs.readdir(projectRoot) - - const foundConfigFiles = cypressConfigFiles.filter((file) => filesInProjectDir.includes(file)) - - if (foundConfigFiles.length === 1) { - const configFile = foundConfigFiles[0] - - if (configFile === 'cypress.json') { - throw this.ctx._apis.projectApi.error('CONFIG_FILE_MIGRATION_NEEDED', projectRoot, configFile) - } - - return configFile - } - - // if we found more than one, throw a language conflict - if (foundConfigFiles.length > 1) { - if (foundConfigFiles.includes('cypress.json')) { - const foundFiles = foundConfigFiles.filter((f) => f !== 'cypress.json') - - throw this.ctx._apis.projectApi.error('LEGACY_CONFIG_FILE', projectRoot, ...foundFiles) - } - - throw this.ctx._apis.projectApi.error('CONFIG_FILES_LANGUAGE_CONFLICT', projectRoot, ...foundConfigFiles) - } - - throw this.ctx._apis.projectApi.error('NO_DEFAULT_CONFIG_FILE_FOUND', projectRoot) - } - - async getConfig (projectRoot: string) { - // Check first the config files, to be sure there are no 2 config files - const configFile = await this.getDefaultConfigFilePath(projectRoot) - - // Check if we have already cached the config - const config = await this.api.getProjectConfig(projectRoot) - - if (config) { - return config - } - - return this.configLoader({ - configFile, - }).load(projectRoot) - } - async getResolvedConfigFields (projectRoot: string): Promise { const config = await this.getConfig(projectRoot) @@ -129,12 +87,6 @@ export class ProjectDataSource { }) as ResolvedFromConfig[] } - private configLoader (options?: SettingsOptions) { - return this.ctx.loader((projectRoots) => { - return Promise.all(projectRoots.map((root) => this.ctx._apis.projectApi.getConfig(root, options))) - }) - } - async isTestingTypeConfigured (projectRoot: string, testingType: 'e2e' | 'component') { const config = await this.getConfig(projectRoot) diff --git a/packages/server/lib/cache.js b/packages/server/lib/cache.js index 2c483ceea820..adba40cbb4d0 100644 --- a/packages/server/lib/cache.js +++ b/packages/server/lib/cache.js @@ -145,19 +145,6 @@ module.exports = { return fileUtil.set({ USER: {} }) }, - // We may need to set this value every time the config file is read, or updated - // having it on the cache, will help us preventing to read the file on a cp - // to get the projectId - setProjectConfig (projectRoot, config) { - return fileUtil.set({ PROJECTS_CONFIG: { [projectRoot]: config } }) - }, - - getProjectConfig (projectRoot) { - return fileUtil.get('PROJECTS_CONFIG').then((projects) => { - return projects && projects[projectRoot] ? projects[projectRoot] : null - }) - }, - removeLatestProjects () { return fileUtil.set({ PROJECTS: [] }) }, diff --git a/packages/server/lib/configFiles.ts b/packages/server/lib/configFiles.ts deleted file mode 100644 index de1b7c53351d..000000000000 --- a/packages/server/lib/configFiles.ts +++ /dev/null @@ -1,4 +0,0 @@ -// the first file is the default created file -export const CYPRESS_CONFIG_FILES = ['cypress.config.js', 'cypress.config.ts'] - -export const LEGACY_CONFIG_FILE = 'cypress.json' diff --git a/packages/server/lib/makeDataContext.ts b/packages/server/lib/makeDataContext.ts index 0a4c9c2ed7a4..19813137fbfd 100644 --- a/packages/server/lib/makeDataContext.ts +++ b/packages/server/lib/makeDataContext.ts @@ -1,11 +1,13 @@ import { DataContext } from '@packages/data-context' +import os from 'os' + import specsUtil from './util/specs' import type { FindSpecs, FoundBrowser, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, PlatformName, Preferences, SettingsOptions } from '@packages/types' import browserUtils from './browsers/utils' import auth from './gui/auth' import user from './user' import * as config from './config' -import type { EventEmitter } from 'events' +import { EventEmitter } from 'events' import { openProject } from './open_project' import cache from './cache' import errors from './errors' @@ -18,6 +20,27 @@ interface MakeDataContextOptions { launchArgs: LaunchArgs } +let legacyDataContext: DataContext | undefined + +// For testing +export function clearLegacyDataContext () { + legacyDataContext = undefined +} + +export function makeLegacyDataContext (launchArgs: LaunchArgs = {} as LaunchArgs): DataContext { + if (legacyDataContext && process.env.LAUNCHPAD) { + throw new Error(`Expected ctx to be passed as an arg, but used legacy data context`) + } else if (!legacyDataContext) { + legacyDataContext = makeDataContext({ + rootBus: new EventEmitter, + launchArgs, + os: os.platform() as PlatformName, + }) + } + + return legacyDataContext +} + export function makeDataContext (options: MakeDataContextOptions) { return new DataContext({ ...options, @@ -57,9 +80,6 @@ export function makeDataContext (options: MakeDataContextOptions) { findSpecs (payload: FindSpecs) { return specsUtil.findSpecs(payload) }, - getProjectConfig (projectRoot: string) { - return cache.getProjectConfig(projectRoot) - }, clearLatestProjectsCache () { return cache.removeLatestProjects() }, diff --git a/packages/server/lib/modes/index.ts b/packages/server/lib/modes/index.ts index 22304c1bdeec..c9ad2c6d762f 100644 --- a/packages/server/lib/modes/index.ts +++ b/packages/server/lib/modes/index.ts @@ -1,4 +1,10 @@ +import { makeLegacyDataContext } from '../makeDataContext' + export = (mode, options) => { + if (!process.env.LAUNCHPAD) { + makeLegacyDataContext(options) + } + if (mode === 'record') { return require('./record').run(options) } diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index 80a166d5a214..ac14b052085b 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -33,8 +33,9 @@ import preprocessor from './plugins/preprocessor' import { SpecsStore } from './specs-store' import { checkSupportFile, getDefaultConfigFilePath } from './project_utils' import type { FoundBrowser, OpenProjectLaunchOptions } from '@packages/types' -import { DataContextShell } from '@packages/data-context/src/DataContextShell' import { getProjectConfig } from './cache' +import { makeLegacyDataContext } from './makeDataContext' +import type { DataContext } from '@packages/data-context' // Cannot just use RuntimeConfigOptions as is because some types are not complete. // Instead, this is an interface of values that have been manually validated to exist @@ -68,7 +69,7 @@ export class ProjectBase extends EE { public id: string protected watchers: Watchers - protected ctx: DataContextShell + protected ctx: DataContext protected _cfg?: Cfg protected _server?: TServer protected _automation?: Automation @@ -108,7 +109,7 @@ export class ProjectBase extends EE { this.spec = null this.browser = null this.id = createHmac('sha256', 'secret-key').update(projectRoot).digest('hex') - this.ctx = options.ctx ?? new DataContextShell() + this.ctx = options.ctx ?? makeLegacyDataContext() debug('Project created %o', { testingType: this.testingType, diff --git a/packages/server/lib/project_utils.ts b/packages/server/lib/project_utils.ts index f4de7a4238b3..8b40172dc365 100644 --- a/packages/server/lib/project_utils.ts +++ b/packages/server/lib/project_utils.ts @@ -5,7 +5,7 @@ import * as settings from './util/settings' import errors from './errors' import { fs } from './util/fs' import { escapeFilenameInUrl } from './util/escape_filename' -import { CYPRESS_CONFIG_FILES, LEGACY_CONFIG_FILE } from './configFiles' +import { makeLegacyDataContext } from './makeDataContext' const debug = Debug('cypress:server:project_utils') @@ -133,32 +133,6 @@ export const checkSupportFile = async ({ return } -export async function getDefaultConfigFilePath (projectRoot: string): Promise { - const filesInProjectDir = await fs.readdir(projectRoot) - - const foundConfigFiles = [...CYPRESS_CONFIG_FILES, LEGACY_CONFIG_FILE].filter((file) => filesInProjectDir.includes(file)) - - // if we only found one default file, it is the one - if (foundConfigFiles.length === 1) { - const configFile = foundConfigFiles[0] - - if (configFile === LEGACY_CONFIG_FILE) { - throw errors.throw('CONFIG_FILE_MIGRATION_NEEDED', projectRoot, configFile) - } - - return configFile - } - - // if we found more than one, throw a language conflict - if (foundConfigFiles.length > 1) { - if (foundConfigFiles.includes(LEGACY_CONFIG_FILE)) { - const foundFiles = foundConfigFiles.filter((f) => f !== LEGACY_CONFIG_FILE) - - throw errors.throw('LEGACY_CONFIG_FILE', projectRoot, ...foundFiles) - } - - throw errors.throw('CONFIG_FILES_LANGUAGE_CONFLICT', projectRoot, ...foundConfigFiles) - } - - throw errors.get('NO_DEFAULT_CONFIG_FILE_FOUND', projectRoot) +export async function getDefaultConfigFilePath (projectRoot: string, ctx = makeLegacyDataContext()): Promise { + return ctx.config.getDefaultConfigBasename(projectRoot) } From a861f355e76194427de1a08890c73cd573fd2519 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 29 Oct 2021 17:28:16 -0500 Subject: [PATCH 49/57] Fix tests --- circle.yml | 6 ++--- cli/test/lib/exec/open_spec.js | 2 +- cli/test/lib/exec/run_spec.js | 2 +- .../src/actions/ProjectActions.ts | 23 +++++++++++++++---- packages/data-context/src/gen/index.ts | 4 ---- packages/data-context/src/sources/index.ts | 1 + packages/driver/cypress.config.ts | 6 +++-- packages/server/lib/config.ts | 13 ----------- packages/server/lib/project-base.ts | 2 +- 9 files changed, 29 insertions(+), 30 deletions(-) delete mode 100644 packages/data-context/src/gen/index.ts diff --git a/circle.yml b/circle.yml index 05941114e508..8b1ad3053de7 100644 --- a/circle.yml +++ b/circle.yml @@ -737,7 +737,7 @@ commands: command: | if [[ -f cypress.json ]]; then rm -rf cypress.json - echo 'module.exports = {}' > cypress.config.js + echo 'export default {}' > cypress.config.js fi - run: name: Print Cypress version @@ -1869,7 +1869,7 @@ jobs: environment: CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" command: | - echo 'module.exports = {}' > cypress.config.js + echo 'export default {}' > cypress.config.js npx cypress run test-full-typescript-project: @@ -2097,7 +2097,7 @@ jobs: CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" command: | rm -rf cypress.json - echo 'module.exports = {}' > cypress.config.js + echo 'export default {}' > cypress.config.js - run: name: Verify Cypress binary working_directory: test-binary diff --git a/cli/test/lib/exec/open_spec.js b/cli/test/lib/exec/open_spec.js index 33c4d2d9e640..fcb975f8dd9c 100644 --- a/cli/test/lib/exec/open_spec.js +++ b/cli/test/lib/exec/open_spec.js @@ -66,7 +66,7 @@ describe('exec open', function () { }) it('spawns with --config-file set', function () { - return open.start() + return open.start({ configFile: 'special-cypress.config.js' }) .then(() => { expect(spawn.start).to.be.calledWith( ['--config-file', 'special-cypress.config.js'], diff --git a/cli/test/lib/exec/run_spec.js b/cli/test/lib/exec/run_spec.js index d01fa4cdbdf7..0f23ef74c234 100644 --- a/cli/test/lib/exec/run_spec.js +++ b/cli/test/lib/exec/run_spec.js @@ -150,7 +150,7 @@ describe('exec run', function () { }) it('spawns with --config-file set', function () { - return run.start() + return run.start({ configFile: 'special-cypress.config.js' }) .then(() => { expect(spawn.start).to.be.calledWith( ['--run-project', process.cwd(), '--config-file', 'special-cypress.config.js'], diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 16710e804aad..dfcb35a7c956 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -1,7 +1,7 @@ import type { CodeGenType, MutationAddProjectArgs, MutationAppCreateConfigFileArgs, MutationSetProjectPreferencesArgs, TestingTypeEnum } from '@packages/graphql/src/gen/nxs.gen' import type { FindSpecs, FoundBrowser, FoundSpec, FullConfig, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, Preferences, SettingsOptions } from '@packages/types' import path from 'path' -import type { ProjectShape } from '../data/coreDataShape' +import type { ActiveProjectShape, ProjectShape } from '../data/coreDataShape' import type { DataContext } from '..' import { SpecGenerator } from '../codegen' @@ -58,21 +58,34 @@ export class ProjectActions { await this.clearActiveProject() - this.ctx.coreData.app.activeProject = { + // TODO: (Alejandro) - Refactor this + // Set initial properties, so we can set on it the config on the next update + this.setActiveProjectProperties({ projectRoot, title, ctPluginsInitialized: false, e2ePluginsInitialized: false, + generatedSpec: null, + config: null, + configChildProcess: null, + }) + + this.setActiveProjectProperties({ isCTConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'component'), isE2EConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'e2e'), preferences: await this.ctx.project.getProjectPreferences(title), - generatedSpec: null, - config: null, - } + }) return this } + private setActiveProjectProperties (activeProjectProperties: Partial) { + this.ctx.coreData.app.activeProject = { + ...this.ctx.coreData.app.activeProject, + ...activeProjectProperties, + } as ActiveProjectShape + } + async loadProjects () { const projectRoots = await this.api.getProjectRootsFromCache() diff --git a/packages/data-context/src/gen/index.ts b/packages/data-context/src/gen/index.ts deleted file mode 100644 index eb90cbc93476..000000000000 --- a/packages/data-context/src/gen/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -/* eslint-disable padding-line-between-statements */ -// created by autobarrel, do not modify directly - -export * from './all-operations.gen' diff --git a/packages/data-context/src/sources/index.ts b/packages/data-context/src/sources/index.ts index a8c337594074..5da47488e24f 100644 --- a/packages/data-context/src/sources/index.ts +++ b/packages/data-context/src/sources/index.ts @@ -4,6 +4,7 @@ export * from './AppDataSource' export * from './BrowserDataSource' export * from './CloudDataSource' +export * from './ConfigDataSource' export * from './FileDataSource' export * from './GitDataSource' export * from './ProjectDataSource' diff --git a/packages/driver/cypress.config.ts b/packages/driver/cypress.config.ts index 91d140ee4609..6422035de5bb 100644 --- a/packages/driver/cypress.config.ts +++ b/packages/driver/cypress.config.ts @@ -1,4 +1,6 @@ -export default { +import { defineConfig } from 'cypress' + +export default defineConfig({ 'projectId': 'ypt4pf', 'baseUrl': 'http://localhost:3500', 'testFiles': '**/*', @@ -9,4 +11,4 @@ export default { 'reporterOptions': { 'configFile': '../../mocha-reporter-config.json', }, -} +}) diff --git a/packages/server/lib/config.ts b/packages/server/lib/config.ts index b1c7a930b8bb..7aec4f32b509 100644 --- a/packages/server/lib/config.ts +++ b/packages/server/lib/config.ts @@ -14,7 +14,6 @@ import * as settings from './util/settings' import Debug from 'debug' import pathHelpers from './util/path_helpers' import findSystemNode from './util/find_system_node' -import { setProjectConfig } from './cache' export interface ConfigSettingsConfig { testingType: TestingType @@ -218,18 +217,6 @@ export function get (projectRoot, options: {configFile?: string | false } = { co options, }) }) - .then((fullConfig) => { - return setProjectConfig(projectRoot, fullConfig).then(() => { - return fullConfig - }) - }) - .catch((e) => { - // Cleanup the cache if there's an error to prevent showing stale data - return setProjectConfig(projectRoot, null) - .then(() => { - throw e - }) - }) } export function set (obj: Record = {}) { diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index ac14b052085b..bce78044cd9b 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -704,7 +704,7 @@ export class ProjectBase extends EE { async initializeConfig (browsers: FoundBrowser[] = []): Promise { // set default for "configFile" if undefined if (this.options.configFile === undefined || this.options.configFile === null) { - this.options.configFile = await getDefaultConfigFilePath(this.projectRoot) + this.options.configFile = await getDefaultConfigFilePath(this.projectRoot, this.ctx) } let theCfg: Cfg = await config.get(this.projectRoot, this.options) From 345c840b94b5ae979f4e56163ffd8c701b3e2b9e Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 29 Oct 2021 23:26:26 -0500 Subject: [PATCH 50/57] Fix tests --- packages/server/lib/project-base.ts | 7 ------- packages/server/lib/util/settings.ts | 9 +-------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index bce78044cd9b..bc015681c7e3 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -33,7 +33,6 @@ import preprocessor from './plugins/preprocessor' import { SpecsStore } from './specs-store' import { checkSupportFile, getDefaultConfigFilePath } from './project_utils' import type { FoundBrowser, OpenProjectLaunchOptions } from '@packages/types' -import { getProjectConfig } from './cache' import { makeLegacyDataContext } from './makeDataContext' import type { DataContext } from '@packages/data-context' @@ -862,12 +861,6 @@ export class ProjectBase extends EE { async getProjectId () { await this.verifyExistence() - const config = await getProjectConfig(this.projectRoot) - - if (config?.projectId) { - return config.projectId - } - const readSettings = await settings.read(this.projectRoot, this.options) if (readSettings && readSettings.projectId) { diff --git a/packages/server/lib/util/settings.ts b/packages/server/lib/util/settings.ts index ff50e69f4ab5..188458287560 100644 --- a/packages/server/lib/util/settings.ts +++ b/packages/server/lib/util/settings.ts @@ -6,7 +6,6 @@ import { fs } from '../util/fs' import { requireAsync } from './require_async' import Debug from 'debug' import type { SettingsOptions } from '@packages/types' -import { getProjectConfig } from '../cache' const debug = Debug('cypress:server:settings') @@ -131,13 +130,7 @@ export function configFile (options: SettingsOptions = {}) { } export function id (projectRoot, options = {}) { - return getProjectConfig(projectRoot).then((config) => { - if (config) { - return Promise.resolve(config) - } - - return read(projectRoot, options) - }) + return read(projectRoot, options) .then((config) => config.projectId) .catch(() => { return null From 4ae2b5d9053650b20383a9df8a813f54d8367858 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 29 Oct 2021 23:46:37 -0500 Subject: [PATCH 51/57] Attempt to fix tests --- circle.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index 8b1ad3053de7..05941114e508 100644 --- a/circle.yml +++ b/circle.yml @@ -737,7 +737,7 @@ commands: command: | if [[ -f cypress.json ]]; then rm -rf cypress.json - echo 'export default {}' > cypress.config.js + echo 'module.exports = {}' > cypress.config.js fi - run: name: Print Cypress version @@ -1869,7 +1869,7 @@ jobs: environment: CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" command: | - echo 'export default {}' > cypress.config.js + echo 'module.exports = {}' > cypress.config.js npx cypress run test-full-typescript-project: @@ -2097,7 +2097,7 @@ jobs: CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1" command: | rm -rf cypress.json - echo 'export default {}' > cypress.config.js + echo 'module.exports = {}' > cypress.config.js - run: name: Verify Cypress binary working_directory: test-binary From 2b0be873e7b0d86d901de1b8a46cf983d68c0dd7 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Sat, 30 Oct 2021 10:43:11 -0500 Subject: [PATCH 52/57] Fix tests --- system-tests/lib/support/helpers/electron_stub.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 system-tests/lib/support/helpers/electron_stub.js diff --git a/system-tests/lib/support/helpers/electron_stub.js b/system-tests/lib/support/helpers/electron_stub.js new file mode 100644 index 000000000000..e4eb860155bb --- /dev/null +++ b/system-tests/lib/support/helpers/electron_stub.js @@ -0,0 +1,11 @@ +// a stubbed out version of electron +// for using in all of our tests :-) +module.exports = { + shell: {}, + app: { + dock: { + show () {}, + hide () {}, + }, + }, +} From edd41e3c84e7e02f05782c35ee407ff500ed5bef Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Sat, 30 Oct 2021 17:33:11 -0500 Subject: [PATCH 53/57] Fix some tests --- .../data-context/src/actions/FileActions.ts | 21 +++++++++- .../src/sources/ConfigDataSource.ts | 10 +++-- .../config-files-error-handling.spec.ts | 39 +++++++++++++++++- .../cypress/e2e/integration/open-mode.spec.ts | 10 +++-- packages/server/test/unit/config_spec.js | 2 +- packages/server/test/unit/project_spec.js | 4 +- .../lib/support/helpers/electron_stub.js | 40 +++++++++++++++++++ system-tests/projects/todos/cypress.config.js | 3 ++ .../unify-plugin-errors/cypress.config.js | 6 ++- 9 files changed, 120 insertions(+), 15 deletions(-) diff --git a/packages/data-context/src/actions/FileActions.ts b/packages/data-context/src/actions/FileActions.ts index b6501957c353..f9686bfda602 100644 --- a/packages/data-context/src/actions/FileActions.ts +++ b/packages/data-context/src/actions/FileActions.ts @@ -3,17 +3,34 @@ import path from 'path' import type { DataContext } from '..' export class FileActions { - constructor (private ctx: DataContext) {} + protected createdFiles: string[] + constructor (private ctx: DataContext) { + this.createdFiles = [] + } + + // Useful, if there's an error and the file needs to be deleted to be a valid test + // this method would cleanup those created files for the retry + async cleanupCreatedFilesInProject () { + if (!this.ctx.activeProject) { + return + } + + await Promise.all(this.createdFiles.map((f) => this.ctx.fs.remove(f))) + } async writeFileInProject (relativePath: string, data: any) { if (!this.ctx.activeProject) { throw new Error(`Cannot write file in project without active project`) } + const filePath = path.join(this.ctx.activeProject?.projectRoot, relativePath) + await this.ctx.fs.writeFile( - path.join(this.ctx.activeProject?.projectRoot, relativePath), + filePath, data, ) + + this.createdFiles.push(filePath) } async removeFileInProject (relativePath: string) { diff --git a/packages/data-context/src/sources/ConfigDataSource.ts b/packages/data-context/src/sources/ConfigDataSource.ts index 879bfd01b467..b8a88fbf805f 100644 --- a/packages/data-context/src/sources/ConfigDataSource.ts +++ b/packages/data-context/src/sources/ConfigDataSource.ts @@ -22,14 +22,16 @@ export class ConfigDataSource { async getDefaultConfigBasename (projectRoot: string) { const cypressConfigFiles = ['cypress.config.js', 'cypress.config.ts'] + const legacyConfigFile = 'cypress.json' + const filesInProjectDir = await this.ctx.fs.readdir(projectRoot) - const foundConfigFiles = cypressConfigFiles.filter((file) => filesInProjectDir.includes(file)) + const foundConfigFiles = [...cypressConfigFiles, legacyConfigFile].filter((file) => filesInProjectDir.includes(file)) if (foundConfigFiles.length === 1) { const configFile = foundConfigFiles[0] - if (configFile === 'cypress.json') { + if (configFile === legacyConfigFile) { throw this.ctx._apis.projectApi.error('CONFIG_FILE_MIGRATION_NEEDED', projectRoot, configFile) } @@ -38,8 +40,8 @@ export class ConfigDataSource { // if we found more than one, throw a language conflict if (foundConfigFiles.length > 1) { - if (foundConfigFiles.includes('cypress.json')) { - const foundFiles = foundConfigFiles.filter((f) => f !== 'cypress.json') + if (foundConfigFiles.includes(legacyConfigFile)) { + const foundFiles = foundConfigFiles.filter((f) => f !== legacyConfigFile) throw this.ctx._apis.projectApi.error('LEGACY_CONFIG_FILE', projectRoot, ...foundFiles) } diff --git a/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts b/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts index 739a7b2f58ee..aa866cff9554 100644 --- a/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts +++ b/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts @@ -1,4 +1,10 @@ describe('Config files error handling', () => { + afterEach(() => { + cy.withCtx(async (ctx) => { + await ctx.actions.file.cleanupCreatedFilesInProject() + }) + }) + it('it handles multiples config files', () => { cy.setupE2E('pristine-with-config-file') cy.visitLaunchpad() @@ -8,6 +14,10 @@ describe('Config files error handling', () => { }) cy.get('[data-cy-testingType=e2e]').click() + + cy.get('body').should('contain.text', 'Configuration Files') + + cy.get('button').contains('Continue').click() cy.wait(2000) cy.get('body') @@ -31,14 +41,20 @@ describe('Config files error handling', () => { cy.withCtx(async (ctx) => { await ctx.actions.file.writeFileInProject('cypress.json', '{}') + await ctx.actions.file.removeFileInProject('cypress.config.js') }) cy.get('[data-cy-testingType=e2e]').click() + + cy.get('body').should('contain.text', 'Configuration Files') + + cy.get('button').contains('Continue').click() + cy.wait(2000) cy.get('body') .should('contain.text', 'Cypress Configuration Error') - .and('contain.text', 'There is both a `cypress.config.js` and a cypress.json file at the location below') + .and('contain.text', 'There is a cypress.json file at the location below:') cy.withCtx(async (ctx) => { await ctx.actions.file.removeFileInProject('cypress.json') @@ -47,16 +63,35 @@ describe('Config files error handling', () => { cy.get('[data-testid=error-retry-button]').click() cy.wait(2000) + cy.get('body') + .should('contain.text', 'Cypress Configuration Error') + .and('contain.text', 'Could not find a Cypress configuration file, exiting.') + + cy.withCtx(async (ctx) => { + await ctx.actions.file.writeFileInProject('cypress.config.js', 'module.exports = {}') + }) + + cy.get('[data-testid=error-retry-button]').click() + cy.wait(2000) + cy.get('body') .should('not.contain.text', 'Cypress Configuration Error') }) it('it handles config files with legacy config file in same project', () => { - cy.setupE2E('multiples-config-files-with-json') + cy.setupE2E('pristine-with-config-file') cy.visitLaunchpad() + cy.withCtx(async (ctx) => { + await ctx.actions.file.writeFileInProject('cypress.json', '{}') + }) + cy.get('[data-cy-testingType=e2e]').click() + cy.get('body').should('contain.text', 'Configuration Files') + + cy.get('button').contains('Continue').click() + cy.wait(2000) cy.get('body') diff --git a/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts b/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts index a6848d294a70..6b39d8549562 100644 --- a/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts +++ b/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts @@ -1,10 +1,12 @@ import defaultMessages from '../../../../frontend-shared/src/locales/en-US.json' describe('Launchpad: Open Mode', () => { - it('shows the open page when testingType is not specified', () => { + beforeEach(() => { cy.setupE2E() cy.visitLaunchpad() + }) + it('shows the open page when testingType is not specified', () => { cy.get('h1').should('contain', defaultMessages.globalPage.empty.title) }) @@ -44,8 +46,10 @@ describe('Launchpad: Open Mode', () => { describe('when there is a list of projects', () => { it('goes to an active project if one is added', () => { - cy.setupE2E('todos') - cy.visitLaunchpad() + cy.withCtx(async (ctx, o) => { + await ctx.actions.project.setActiveProject(o.projectDir('todos')) + ctx.emitter.toLaunchpad() + }) cy.get('h1').should('contain', 'Welcome to Cypress!') }) diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index 1c5733059da8..4dfa915fb107 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -147,7 +147,7 @@ describe('lib/config', () => { it('validates cypress.config.js', function () { this.setup({ reporter: 5 }) - return this.expectValidationFails('cypress.config.js') + return this.expectValidationFails('cypress.config.{ts|js}') }) it('validates cypress.env.json', function () { diff --git a/packages/server/test/unit/project_spec.js b/packages/server/test/unit/project_spec.js index 82540674e8bb..39ce06fba903 100644 --- a/packages/server/test/unit/project_spec.js +++ b/packages/server/test/unit/project_spec.js @@ -968,7 +968,7 @@ This option will not have an effect in Some-other-name. Tests that rely on web s }) it('inserts path into cache', function () { - return add(this.pristinePath) + return add(this.pristinePath, {}) .then(() => cache.read()).then((json) => { expect(json.PROJECTS).to.deep.eq([this.pristinePath]) }) @@ -991,7 +991,7 @@ This option will not have an effect in Some-other-name. Tests that rely on web s it('returns object containing just the path', function () { sinon.stub(settings, 'read').rejects() - return add(this.pristinePath) + return add(this.pristinePath, {}) .then((project) => { expect(project.id).to.be.undefined diff --git a/system-tests/lib/support/helpers/electron_stub.js b/system-tests/lib/support/helpers/electron_stub.js index e4eb860155bb..40a4a7394d41 100644 --- a/system-tests/lib/support/helpers/electron_stub.js +++ b/system-tests/lib/support/helpers/electron_stub.js @@ -2,10 +2,50 @@ // for using in all of our tests :-) module.exports = { shell: {}, + dialog: {}, + ipcMain: { + on () {}, + removeAllListeners () {}, + }, + nativeImage: { + createFromPath () { + return {} + }, + }, app: { + on () {}, + exit () {}, + commandLine: { + appendSwitch () {}, + appendArgument () {}, + }, + disableHardwareAcceleration () {}, + async whenReady () {}, dock: { show () {}, hide () {}, }, }, + systemPreferences: { + isDarkMode () {}, + subscribeNotification () {}, + }, + BrowserWindow: { + fromWebContents () {}, + getExtensions () {}, + removeExtension () {}, + addExtension () {}, + }, + Menu: { + buildFromTemplate () {}, + setApplicationMenu () {}, + }, + Tray () { + return { + on () {}, + setToolTip () {}, + setImage () {}, + setPressedImage () {}, + } + }, } diff --git a/system-tests/projects/todos/cypress.config.js b/system-tests/projects/todos/cypress.config.js index 98b8373d51d2..c60f6b7c09d8 100644 --- a/system-tests/projects/todos/cypress.config.js +++ b/system-tests/projects/todos/cypress.config.js @@ -5,4 +5,7 @@ module.exports = { 'port': 8888, 'projectId': 'abc123', 'pluginsFile': false, + component: { + specFilePattern: 'src/**/*.spec.cy.js', + }, } diff --git a/system-tests/projects/unify-plugin-errors/cypress.config.js b/system-tests/projects/unify-plugin-errors/cypress.config.js index 4ba52ba2c8df..821d12808891 100644 --- a/system-tests/projects/unify-plugin-errors/cypress.config.js +++ b/system-tests/projects/unify-plugin-errors/cypress.config.js @@ -1 +1,5 @@ -module.exports = {} +module.exports = { + e2e: { + baseUrl: 'https://cypress.com', + }, +} From 118402b7a3db1b3015420f7da17d5117f811e230 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Sun, 31 Oct 2021 22:49:29 -0500 Subject: [PATCH 54/57] Fix build, fix tests --- packages/data-context/src/DataContext.ts | 1 + packages/data-context/src/sources/ProjectDataSource.ts | 3 ++- packages/launchpad/cypress/e2e/integration/open-mode.spec.ts | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index c7fe8486255c..b3c67e827572 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -14,6 +14,7 @@ import { BrowserDataSource, StorybookDataSource, CloudDataSource, + ConfigDataSource, } from './sources/' import { cached } from './util/cached' import { DataContextShell, DataContextShellConfig } from './DataContextShell' diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index 6579e396297a..df2c548ab123 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -1,6 +1,5 @@ import type { CodeGenType, SpecType } from '@packages/graphql/src/gen/nxs.gen' import { FrontendFramework, FRONTEND_FRAMEWORKS, ResolvedFromConfig, RESOLVED_FROM, SpecFile, STORYBOOK_GLOB } from '@packages/types' -import { scanFSForAvailableDependency } from 'create-cypress-tests/src/findPackageJson' import path from 'path' import type { DataContext } from '..' @@ -116,6 +115,8 @@ export class ProjectDataSource { }) private guessFramework (projectRoot: string) { + const { scanFSForAvailableDependency } = require('create-cypress-tests/src/findPackageJson') + const guess = FRONTEND_FRAMEWORKS.find((framework) => { const lookingForDeps = (framework.deps as readonly string[]).reduce( (acc, dep) => ({ ...acc, [dep]: '*' }), diff --git a/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts b/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts index 6b39d8549562..251a6e4647a1 100644 --- a/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts +++ b/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts @@ -24,7 +24,7 @@ describe('Launchpad: Open Mode', () => { }) // e2e testing is configured for the todo project, so we don't expect an error. - cy.get('h1').should('contain', 'Initializing Config...') + cy.get('h1').should('contain', 'Configuration Files') }) it('goes directly to component tests when launched with --component', () => { @@ -41,7 +41,7 @@ describe('Launchpad: Open Mode', () => { }) // Component testing is not configured for the todo project - cy.get('h1').should('contain', 'Cypress Configuration Error') + cy.get('h1').should('contain', 'Project Setup') }) describe('when there is a list of projects', () => { From 3c83d813799fab74741fda0f5299cde0ffb58766 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 1 Nov 2021 10:19:21 -0500 Subject: [PATCH 55/57] Fix tests --- packages/app/cypress/e2e/integration/runs.spec.ts | 3 ++- packages/data-context/src/actions/ProjectActions.ts | 3 +-- packages/data-context/src/sources/ConfigDataSource.ts | 8 ++++++++ .../data-context/src/sources/ProjectDataSource.ts | 3 +-- .../cypress/e2e/integration/open-mode.spec.ts | 11 +++++++---- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/app/cypress/e2e/integration/runs.spec.ts b/packages/app/cypress/e2e/integration/runs.spec.ts index 13244a6aa305..7a6732ae6375 100644 --- a/packages/app/cypress/e2e/integration/runs.spec.ts +++ b/packages/app/cypress/e2e/integration/runs.spec.ts @@ -58,7 +58,8 @@ describe('App', () => { cy.loginUser() cy.visitApp() cy.withCtx(async (ctx) => { - await ctx.actions.file.writeFileInProject('cypress.json', '{}') + ctx.config.cleanupCachedConfigForActiveProject() + await ctx.actions.file.writeFileInProject('cypress.config.js', 'module.exports = {}') }) cy.get('[href="#/runs"]').click() diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 468664bb0e6a..e890ea1e904d 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -58,8 +58,7 @@ export class ProjectActions { await this.clearActiveProject() - // TODO: (Alejandro) - Refactor this - // Set initial properties, so we can set on it the config on the next update + // Set initial properties, so we can set the config object on the active project this.setActiveProjectProperties({ projectRoot, title, diff --git a/packages/data-context/src/sources/ConfigDataSource.ts b/packages/data-context/src/sources/ConfigDataSource.ts index b8a88fbf805f..33b2869c4efd 100644 --- a/packages/data-context/src/sources/ConfigDataSource.ts +++ b/packages/data-context/src/sources/ConfigDataSource.ts @@ -51,4 +51,12 @@ export class ConfigDataSource { throw this.ctx._apis.projectApi.error('NO_DEFAULT_CONFIG_FILE_FOUND', projectRoot) } + + async cleanupCachedConfigForActiveProject () { + if (!this.ctx.coreData.app.activeProject?.config) { + return + } + + this.ctx.coreData.app.activeProject.config = null + } } diff --git a/packages/data-context/src/sources/ProjectDataSource.ts b/packages/data-context/src/sources/ProjectDataSource.ts index df2c548ab123..6579e396297a 100644 --- a/packages/data-context/src/sources/ProjectDataSource.ts +++ b/packages/data-context/src/sources/ProjectDataSource.ts @@ -1,5 +1,6 @@ import type { CodeGenType, SpecType } from '@packages/graphql/src/gen/nxs.gen' import { FrontendFramework, FRONTEND_FRAMEWORKS, ResolvedFromConfig, RESOLVED_FROM, SpecFile, STORYBOOK_GLOB } from '@packages/types' +import { scanFSForAvailableDependency } from 'create-cypress-tests/src/findPackageJson' import path from 'path' import type { DataContext } from '..' @@ -115,8 +116,6 @@ export class ProjectDataSource { }) private guessFramework (projectRoot: string) { - const { scanFSForAvailableDependency } = require('create-cypress-tests/src/findPackageJson') - const guess = FRONTEND_FRAMEWORKS.find((framework) => { const lookingForDeps = (framework.deps as readonly string[]).reduce( (acc, dep) => ({ ...acc, [dep]: '*' }), diff --git a/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts b/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts index 251a6e4647a1..204c76f3168f 100644 --- a/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts +++ b/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts @@ -11,6 +11,8 @@ describe('Launchpad: Open Mode', () => { }) it('goes directly to e2e tests when launched with --e2e', () => { + cy.setupE2E('todos') + cy.withCtx(async (ctx) => { // Though the data context is previously initialized, // we re-initialize it here so that it reflects the new launchArg @@ -19,7 +21,6 @@ describe('Launchpad: Open Mode', () => { }) cy.withCtx(async (ctx, o) => { - await ctx.actions.project.setActiveProject(o.projectDir('todos')) ctx.emitter.toLaunchpad() }) @@ -28,6 +29,8 @@ describe('Launchpad: Open Mode', () => { }) it('goes directly to component tests when launched with --component', () => { + cy.setupE2E('todos') + cy.withCtx(async (ctx) => { // Though the data context is previously initialized, // we re-initialize it here so that it reflects the new launchArg @@ -36,18 +39,18 @@ describe('Launchpad: Open Mode', () => { }) cy.withCtx(async (ctx, o) => { - await ctx.actions.project.setActiveProject(o.projectDir('todos')) ctx.emitter.toLaunchpad() }) // Component testing is not configured for the todo project - cy.get('h1').should('contain', 'Project Setup') + cy.get('h1').should('contain', 'Cypress Configuration Error') }) describe('when there is a list of projects', () => { it('goes to an active project if one is added', () => { + cy.setupE2E('todos') + cy.withCtx(async (ctx, o) => { - await ctx.actions.project.setActiveProject(o.projectDir('todos')) ctx.emitter.toLaunchpad() }) From 287c706438b2875fca40fabd90bd44e69fc020e0 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Mon, 1 Nov 2021 13:48:04 -0400 Subject: [PATCH 56/57] scaffold cypress-example-kitchensink tests from branch feat/use-config-file --- packages/example/package.json | 2 +- yarn.lock | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/example/package.json b/packages/example/package.json index 2275117c0e3b..d6e427a5aab4 100644 --- a/packages/example/package.json +++ b/packages/example/package.json @@ -28,7 +28,7 @@ "devDependencies": { "chai": "3.5.0", "cross-env": "6.0.3", - "cypress-example-kitchensink": "1.15.2", + "cypress-example-kitchensink": "cypress-io/cypress-example-kitchensink#feat/use-config-file", "gulp": "4.0.2", "gulp-clean": "0.4.0", "gulp-gh-pages": "0.6.0-6", diff --git a/yarn.lock b/yarn.lock index ad7c45c1159d..d557ba0b9eb9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16946,10 +16946,9 @@ cyclist@^1.0.1: resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk= -cypress-example-kitchensink@1.15.2: - version "1.15.2" - resolved "https://registry.yarnpkg.com/cypress-example-kitchensink/-/cypress-example-kitchensink-1.15.2.tgz#325015726291a5e1e0d0cf89177eb9dec1c13e19" - integrity sha512-Ni/xbpMEllrNBrDVxh9juu7W4sbyBGpENuWvFdiojjBxzyvCCHaYCJIdF5kgGNzE5aP4AkoGW/jEk1KiKQzALA== +cypress-example-kitchensink@cypress-io/cypress-example-kitchensink#feat/use-config-file: + version "0.0.0-development" + resolved "https://codeload.github.com/cypress-io/cypress-example-kitchensink/tar.gz/9de74fdcfa724324001b82a4a9d0582a38533db0" dependencies: npm-run-all "^4.1.2" serve "11.3.0" From 2d6c33895bba449c9e7220fe66d374d3995741ec Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Mon, 1 Nov 2021 13:58:02 -0400 Subject: [PATCH 57/57] Remove need for cleanupCreatedFilesInProject --- .../data-context/src/actions/FileActions.ts | 17 +---------- .../cypress/e2e/support/e2eProjectDirs.ts | 3 +- .../config-files-error-handling.spec.ts | 30 ++----------------- system-tests/lib/fixtures.js | 4 +++ 4 files changed, 10 insertions(+), 44 deletions(-) diff --git a/packages/data-context/src/actions/FileActions.ts b/packages/data-context/src/actions/FileActions.ts index f9686bfda602..bef4c85d0759 100644 --- a/packages/data-context/src/actions/FileActions.ts +++ b/packages/data-context/src/actions/FileActions.ts @@ -3,20 +3,7 @@ import path from 'path' import type { DataContext } from '..' export class FileActions { - protected createdFiles: string[] - constructor (private ctx: DataContext) { - this.createdFiles = [] - } - - // Useful, if there's an error and the file needs to be deleted to be a valid test - // this method would cleanup those created files for the retry - async cleanupCreatedFilesInProject () { - if (!this.ctx.activeProject) { - return - } - - await Promise.all(this.createdFiles.map((f) => this.ctx.fs.remove(f))) - } + constructor (private ctx: DataContext) {} async writeFileInProject (relativePath: string, data: any) { if (!this.ctx.activeProject) { @@ -29,8 +16,6 @@ export class FileActions { filePath, data, ) - - this.createdFiles.push(filePath) } async removeFileInProject (relativePath: string) { diff --git a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts index 449a9a82ec80..19a2d62fbb21 100644 --- a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts +++ b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts @@ -26,8 +26,8 @@ export const e2eProjectDirs = [ 'integration-outside-project-root', 'issue-8111-iframe-input', 'max-listeners', - 'multiples-config-files-with-json', 'multiple-task-registrations', + 'multiples-config-files-with-json', 'no-scaffolding', 'no-server', 'non-existent-spec', @@ -71,6 +71,7 @@ export const e2eProjectDirs = [ 'todos', 'ts-installed', 'ts-proj', + 'ts-proj-compiler', 'ts-proj-custom-names', 'ts-proj-esmoduleinterop-true', 'ts-proj-tsconfig-in-plugins', diff --git a/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts b/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts index aa866cff9554..6232d796b563 100644 --- a/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts +++ b/packages/launchpad/cypress/e2e/integration/config-files-error-handling.spec.ts @@ -1,14 +1,10 @@ describe('Config files error handling', () => { - afterEach(() => { - cy.withCtx(async (ctx) => { - await ctx.actions.file.cleanupCreatedFilesInProject() - }) - }) - - it('it handles multiples config files', () => { + beforeEach(() => { cy.setupE2E('pristine-with-config-file') cy.visitLaunchpad() + }) + it('it handles multiples config files', () => { cy.withCtx(async (ctx) => { await ctx.actions.file.writeFileInProject('cypress.config.ts', 'export default {}') }) @@ -18,8 +14,6 @@ describe('Config files error handling', () => { cy.get('body').should('contain.text', 'Configuration Files') cy.get('button').contains('Continue').click() - cy.wait(2000) - cy.get('body') .should('contain.text', 'Cypress Configuration Error') .and('contain.text', 'There is both a `cypress.config.js` and a `cypress.config.ts` at the location below') @@ -29,16 +23,11 @@ describe('Config files error handling', () => { }) cy.get('[data-testid=error-retry-button]').click() - cy.wait(2000) - cy.get('body') .should('not.contain.text', 'Cypress Configuration Error') }) it('it handles legacy config file', () => { - cy.setupE2E('pristine-with-config-file') - cy.visitLaunchpad() - cy.withCtx(async (ctx) => { await ctx.actions.file.writeFileInProject('cypress.json', '{}') await ctx.actions.file.removeFileInProject('cypress.config.js') @@ -50,8 +39,6 @@ describe('Config files error handling', () => { cy.get('button').contains('Continue').click() - cy.wait(2000) - cy.get('body') .should('contain.text', 'Cypress Configuration Error') .and('contain.text', 'There is a cypress.json file at the location below:') @@ -61,8 +48,6 @@ describe('Config files error handling', () => { }) cy.get('[data-testid=error-retry-button]').click() - cy.wait(2000) - cy.get('body') .should('contain.text', 'Cypress Configuration Error') .and('contain.text', 'Could not find a Cypress configuration file, exiting.') @@ -72,16 +57,11 @@ describe('Config files error handling', () => { }) cy.get('[data-testid=error-retry-button]').click() - cy.wait(2000) - cy.get('body') .should('not.contain.text', 'Cypress Configuration Error') }) it('it handles config files with legacy config file in same project', () => { - cy.setupE2E('pristine-with-config-file') - cy.visitLaunchpad() - cy.withCtx(async (ctx) => { await ctx.actions.file.writeFileInProject('cypress.json', '{}') }) @@ -92,8 +72,6 @@ describe('Config files error handling', () => { cy.get('button').contains('Continue').click() - cy.wait(2000) - cy.get('body') .should('contain.text', 'Cypress Configuration Error') .and('contain.text', 'There is both a `cypress.config.js` and a cypress.json file at the location below') @@ -103,8 +81,6 @@ describe('Config files error handling', () => { }) cy.get('[data-testid=error-retry-button]').click() - cy.wait(2000) - cy.get('body') .should('not.contain.text', 'Cypress Configuration Error') }) diff --git a/system-tests/lib/fixtures.js b/system-tests/lib/fixtures.js index e92233577d5c..d3e1e0f19b23 100644 --- a/system-tests/lib/fixtures.js +++ b/system-tests/lib/fixtures.js @@ -32,6 +32,10 @@ module.exports = { const from = path.join(projects, project) const to = path.join(tmpDir, project) + if (fs.existsSync(to)) { + fs.removeSync(to) + } + fs.copySync(from, to) },