fix(testing): do not update component configuration in cypress set-inject-document-domain migration (#31614)
## Current Behavior The `set-inject-document-domain` migration updates the component configuration. This is incorrect since the `inject-document-domain` is not a property supported by the component configuration. ## Expected Behavior The `set-inject-document-domain` migration should not update the component configuration. ## Related Issue(s) Fixes #31610
This commit is contained in:
parent
6b2175bfcb
commit
617b8d49cb
@ -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', {
|
addProjectConfiguration(tree, 'app1-e2e', {
|
||||||
root: 'apps/app1-e2e',
|
root: 'apps/app1-e2e',
|
||||||
projectType: 'application',
|
projectType: 'application',
|
||||||
@ -521,120 +521,6 @@ export default defineConfig({
|
|||||||
|
|
||||||
await migration(tree);
|
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'))
|
expect(tree.read('apps/app1-e2e/cypress.config.ts', 'utf-8'))
|
||||||
.toMatchInlineSnapshot(`
|
.toMatchInlineSnapshot(`
|
||||||
"import { nxComponentTestingPreset } from '@nx/react/plugins/component-testing';
|
"import { nxComponentTestingPreset } from '@nx/react/plugins/component-testing';
|
||||||
|
|||||||
@ -49,7 +49,12 @@ function setInjectDocumentDomain(cypressConfig: string): string {
|
|||||||
|
|
||||||
const sourceFile = tsquery.ast(cypressConfig);
|
const sourceFile = tsquery.ast(cypressConfig);
|
||||||
let e2eProperty = getObjectProperty(config, 'e2e');
|
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;
|
let updatedConfig = config;
|
||||||
|
|
||||||
const topLevelExperimentalSkipDomainInjectionProperty = getObjectProperty(
|
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 (
|
if (
|
||||||
topLevelSkipDomainState === 'not-set' &&
|
topLevelSkipDomainState === 'not-set' &&
|
||||||
!e2eProperty &&
|
!e2eProperty &&
|
||||||
!componentProperty
|
hasOtherTopLevelProperties
|
||||||
) {
|
) {
|
||||||
updatedConfig = setInjectDocumentDomainInObject(updatedConfig);
|
updatedConfig = setInjectDocumentDomainInObject(updatedConfig);
|
||||||
} else if (topLevelSkipDomainState === 'not-skipping') {
|
} else if (topLevelSkipDomainState === 'not-skipping') {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user