Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testing): Cypress 12 Support #14058

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/cypress/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
"version": "15.1.0-beta.0",
"description": "Update to Cypress v11. This migration will only update if the workspace is already on v10. https://www.cypress.io/blog/2022/11/04/upcoming-changes-to-component-testing/",
"factory": "./src/migrations/update-15-1-0/cypress-11"
},
"update-to-cypress-12": {
"cli": "nx",
"version": "15.5.0-beta.0",
"description": "Update to Cypress v12. Cypress 12 contains a handful of breaking changes that might causes tests to start failing that nx cannot directly fix. Read more Cypress 12 changes: https://docs.cypress.io/guides/references/migration-guide#Migrating-to-Cypress-12-0.This migration will only run if you are already using Cypress v11.",
"factory": "./src/migrations/update-15-5-0/update-to-cypress-12"
}
},
"packageJsonUpdates": {}
Expand Down
2 changes: 1 addition & 1 deletion packages/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"semver": "7.3.4"
},
"peerDependencies": {
"cypress": ">= 3 < 12"
"cypress": ">= 3 < 13"
},
"peerDependenciesMeta": {
"cypress": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ https://nx.dev/cypress/v10-migration-guide
);

updateJson(tree, 'package.json', (json) => {
json.devDependencies['cypress'] = cypressVersion;
json.devDependencies['cypress'] = '^11.2.0';
return json;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Cypress 12 Migration should migrate to cy 12 1`] = `
"describe('something', () => {
it('should do the thing', () => {
// TODO(@nrwl/cypress): this command has been removed, use cy.session instead. https://docs.cypress.io/guides/references/migration-guide#Command-Cypress-API-Changes
Cypress.Cookies.defaults()
// TODO(@nrwl/cypress): this command has been removed, use cy.session instead. https://docs.cypress.io/guides/references/migration-guide#Command-Cypress-API-Changes
Cypress.Cookies.preserveOnce('seesion_id', 'remember-token');
Cypress.blah.abc()
// TODO(@nrwl/cypress): this command has been removed, use cy.intercept instead. https://docs.cypress.io/guides/references/migration-guide#cy-server-cy-route-and-Cypress-Server-defaults
Cypress.Server.defaults({
delay: 500,
method: 'GET',
})
// TODO(@nrwl/cypress): this command has been removed, use cy.intercept instead. https://docs.cypress.io/guides/references/migration-guide#cy-server-cy-route-and-Cypress-Server-defaults
cy.server()
// TODO(@nrwl/cypress): this command has been removed, use cy.intercept instead. https://docs.cypress.io/guides/references/migration-guide#cy-server-cy-route-and-Cypress-Server-defaults
cy.route(/api/, () => {
return {
'test': 'We’ll',
}
}).as('getApi')
cy.visit('/index.html')
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest
xhr.open('GET', '/api/v1/foo/bar?a=42')
xhr.send()
})
cy.wait('@getApi')
.its('url').should('include', 'api/v1')
/**
* TODO(@nrwl/cypress): Nesting Cypress commands in a should assertion now throws.
* You should use .then() to chain commands instead.
* More Info: https://docs.cypress.io/guides/references/migration-guide#-should
**/
cy.should(($s) => {
cy.get('@table').find('tr').should('have.length', 3)
})
})
})"
`;

exports[`Cypress 12 Migration should migrate to cy 12 2`] = `
"describe('something', () => {
it('should do the thing', () => {
// TODO(@nrwl/cypress): this command has been removed, use cy.session instead. https://docs.cypress.io/guides/references/migration-guide#Command-Cypress-API-Changes
Cypress.Cookies.defaults()
// TODO(@nrwl/cypress): this command has been removed, use cy.session instead. https://docs.cypress.io/guides/references/migration-guide#Command-Cypress-API-Changes
Cypress.Cookies.preserveOnce('seesion_id', 'remember-token');
Cypress.blah.abc()
// TODO(@nrwl/cypress): this command has been removed, use cy.intercept instead. https://docs.cypress.io/guides/references/migration-guide#cy-server-cy-route-and-Cypress-Server-defaults
Cypress.Server.defaults({
delay: 500,
method: 'GET',
})
// TODO(@nrwl/cypress): this command has been removed, use cy.intercept instead. https://docs.cypress.io/guides/references/migration-guide#cy-server-cy-route-and-Cypress-Server-defaults
cy.server()
// TODO(@nrwl/cypress): this command has been removed, use cy.intercept instead. https://docs.cypress.io/guides/references/migration-guide#cy-server-cy-route-and-Cypress-Server-defaults
cy.route(/api/, () => {
return {
'test': 'We’ll',
}
}).as('getApi')
cy.visit('/index.html')
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest
xhr.open('GET', '/api/v1/foo/bar?a=42')
xhr.send()
})
cy.wait('@getApi')
.its('url').should('include', 'api/v1')
/**
* TODO(@nrwl/cypress): Nesting Cypress commands in a should assertion now throws.
* You should use .then() to chain commands instead.
* More Info: https://docs.cypress.io/guides/references/migration-guide#-should
**/
cy.should(($s) => {
cy.get('@table').find('tr').should('have.length', 3)
})
})
})"
`;
38 changes: 38 additions & 0 deletions packages/cypress/src/migrations/update-15-5-0/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Node } from 'typescript';

export function isAlreadyCommented(node: Node) {
return node.getFullText().includes('TODO(@nrwl/cypress)');
}

export const BANNED_COMMANDS = [
'as',
'children',
'closest',
'contains',
'debug',
'document',
'eq',
'filter',
'find',
'first',
'focused',
'get',
'hash',
'its',
'last',
'location',
'next',
'nextAll',
'not',
'parent',
'parents',
'parentsUntil',
'prev',
'prevUntil',
'root',
'shadow',
'siblings',
'title',
'url',
'window',
];
Loading