diff --git a/packages/cypress/src/migrations/update-20-8-0/set-inject-document-domain.spec.ts b/packages/cypress/src/migrations/update-20-8-0/set-inject-document-domain.spec.ts index 1003b56d56..49249b7d7b 100644 --- a/packages/cypress/src/migrations/update-20-8-0/set-inject-document-domain.spec.ts +++ b/packages/cypress/src/migrations/update-20-8-0/set-inject-document-domain.spec.ts @@ -500,7 +500,7 @@ export default defineConfig({ `); }); - it('should set the injectDocumentDomain property to true in the component config when defined and experimentalSkipDomainInjection is not set', async () => { + it('should not set the injectDocumentDomain property in the component config', async () => { addProjectConfiguration(tree, 'app1-e2e', { root: 'apps/app1-e2e', projectType: 'application', @@ -521,120 +521,6 @@ export default defineConfig({ await migration(tree); - expect(tree.read('apps/app1-e2e/cypress.config.ts', 'utf-8')) - .toMatchInlineSnapshot(` - "import { nxComponentTestingPreset } from '@nx/react/plugins/component-testing'; - import { defineConfig } from 'cypress'; - - export default defineConfig({ - component: { - ...nxComponentTestingPreset(__filename, { bundler: 'vite' }), - // Please ensure you use \`cy.origin()\` when navigating between domains and remove this option. - // See https://docs.cypress.io/app/references/migration-guide#Changes-to-cyorigin - injectDocumentDomain: true, - }, - }); - " - `); - }); - - it('should set the injectDocumentDomain property to true in the component config when it is not an object literal', async () => { - addProjectConfiguration(tree, 'app1-e2e', { - root: 'apps/app1-e2e', - projectType: 'application', - targets: {}, - }); - tree.write( - 'apps/app1-e2e/cypress.config.ts', - `import { nxComponentTestingPreset } from '@nx/react/plugins/component-testing'; -import { defineConfig } from 'cypress'; - -export default defineConfig({ - component: nxComponentTestingPreset(__filename, { bundler: 'vite' }), -}); -` - ); - - await migration(tree); - - expect(tree.read('apps/app1-e2e/cypress.config.ts', 'utf-8')) - .toMatchInlineSnapshot(` - "import { nxComponentTestingPreset } from '@nx/react/plugins/component-testing'; - import { defineConfig } from 'cypress'; - - export default defineConfig({ - component: { - ...nxComponentTestingPreset(__filename, { bundler: 'vite' }), - // Please ensure you use \`cy.origin()\` when navigating between domains and remove this option. - // See https://docs.cypress.io/app/references/migration-guide#Changes-to-cyorigin - injectDocumentDomain: true, - }, - }); - " - `); - }); - - it('should replace the experimentalSkipDomainInjection property in the component config with injectDocumentDomain when it is set to an empty array', async () => { - addProjectConfiguration(tree, 'app1-e2e', { - root: 'apps/app1-e2e', - projectType: 'application', - targets: {}, - }); - tree.write( - 'apps/app1-e2e/cypress.config.ts', - `import { nxComponentTestingPreset } from '@nx/react/plugins/component-testing'; -import { defineConfig } from 'cypress'; - -export default defineConfig({ - component: { - ...nxComponentTestingPreset(__filename, { bundler: 'vite' }), - experimentalSkipDomainInjection: [], - }, -}); -` - ); - - await migration(tree); - - expect(tree.read('apps/app1-e2e/cypress.config.ts', 'utf-8')) - .toMatchInlineSnapshot(` - "import { nxComponentTestingPreset } from '@nx/react/plugins/component-testing'; - import { defineConfig } from 'cypress'; - - export default defineConfig({ - component: { - ...nxComponentTestingPreset(__filename, { bundler: 'vite' }), - // Please ensure you use \`cy.origin()\` when navigating between domains and remove this option. - // See https://docs.cypress.io/app/references/migration-guide#Changes-to-cyorigin - injectDocumentDomain: true, - }, - }); - " - `); - }); - - it('should remove the experimentalSkipDomainInjection property in the component config when it is set to a non-empty array', async () => { - addProjectConfiguration(tree, 'app1-e2e', { - root: 'apps/app1-e2e', - projectType: 'application', - targets: {}, - }); - tree.write( - 'apps/app1-e2e/cypress.config.ts', - `import { nxComponentTestingPreset } from '@nx/react/plugins/component-testing'; -import { defineConfig } from 'cypress'; - -export default defineConfig({ - component: { - ...nxComponentTestingPreset(__filename, { bundler: 'vite' }), - experimentalSkipDomainInjection: ['https://example.com'], - }, -}); -` - ); - - await migration(tree); - expect(tree.read('apps/app1-e2e/cypress.config.ts', 'utf-8')) .toMatchInlineSnapshot(` "import { nxComponentTestingPreset } from '@nx/react/plugins/component-testing'; diff --git a/packages/cypress/src/migrations/update-20-8-0/set-inject-document-domain.ts b/packages/cypress/src/migrations/update-20-8-0/set-inject-document-domain.ts index 9010f1e02a..339f1a1060 100644 --- a/packages/cypress/src/migrations/update-20-8-0/set-inject-document-domain.ts +++ b/packages/cypress/src/migrations/update-20-8-0/set-inject-document-domain.ts @@ -49,7 +49,12 @@ function setInjectDocumentDomain(cypressConfig: string): string { const sourceFile = tsquery.ast(cypressConfig); let e2eProperty = getObjectProperty(config, 'e2e'); - let componentProperty = getObjectProperty(config, 'component'); + let hasOtherTopLevelProperties = config.properties.some( + (p): p is PropertyAssignment => + ts.isPropertyAssignment(p) && + p.name.getText() !== 'e2e' && + p.name.getText() !== 'component' + ); let updatedConfig = config; const topLevelExperimentalSkipDomainInjectionProperty = getObjectProperty( @@ -116,62 +121,10 @@ function setInjectDocumentDomain(cypressConfig: string): string { } } - let componentSkipDomainState: 'not-set' | 'skipping' | 'not-skipping' = - 'not-set'; - if (componentProperty) { - let experimentalSkipDomainInjectionProperty: PropertyAssignment | undefined; - let isObjectLiteral = false; - if (ts.isObjectLiteralExpression(componentProperty.initializer)) { - experimentalSkipDomainInjectionProperty = getObjectProperty( - componentProperty.initializer, - 'experimentalSkipDomainInjection' - ); - isObjectLiteral = true; - } - - if (experimentalSkipDomainInjectionProperty) { - componentSkipDomainState = - !ts.isArrayLiteralExpression( - experimentalSkipDomainInjectionProperty.initializer - ) || - experimentalSkipDomainInjectionProperty.initializer.elements.length > 0 - ? 'skipping' - : 'not-skipping'; - } - - if ( - componentSkipDomainState === 'not-set' && - topLevelSkipDomainState === 'not-set' - ) { - updatedConfig = updateObjectProperty(updatedConfig, componentProperty, { - newValue: setInjectDocumentDomainInObject( - componentProperty.initializer - ), - }); - } else if (componentSkipDomainState === 'not-skipping') { - updatedConfig = updateObjectProperty(updatedConfig, componentProperty, { - newValue: replaceExperimentalSkipDomainInjectionInObject( - componentProperty.initializer - ), - }); - } else if (componentSkipDomainState === 'skipping') { - updatedConfig = updateObjectProperty(updatedConfig, componentProperty, { - newValue: removeObjectProperty( - // we only determine that it's skipping if it's an object literal - componentProperty.initializer as ObjectLiteralExpression, - getObjectProperty( - componentProperty.initializer as ObjectLiteralExpression, - 'experimentalSkipDomainInjection' - ) - ), - }); - } - } - if ( topLevelSkipDomainState === 'not-set' && !e2eProperty && - !componentProperty + hasOtherTopLevelProperties ) { updatedConfig = setInjectDocumentDomainInObject(updatedConfig); } else if (topLevelSkipDomainState === 'not-skipping') {