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): update cypress version #21961

Merged
merged 2 commits into from Feb 23, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/cypress/migrations.json
Expand Up @@ -47,6 +47,12 @@
"version": "16.8.0-beta.4",
"description": "Update to Cypress v13. Most noteable change is video recording is off by default. This migration will only update if the workspace is already on Cypress v12. https://docs.cypress.io/guides/references/migration-guide#Migrating-to-Cypress-130",
"implementation": "./src/migrations/update-16-8-0/cypress-13"
},
"update-cypress-version-13-6-6": {
"cli": "nx",
"version": "18.1.0-beta.3",
"description": "Update to Cypress ^13.6.6 if the workspace is using Cypress v13 to ensure workspaces don't use v13.6.5 which has an issue when verifying Cypress.",
"implementation": "./src/migrations/update-18-1-0/update-cypress-version-13-6-6"
}
},
"packageJsonUpdates": {
Expand Down
@@ -0,0 +1,42 @@
import { readJson, updateJson, type Tree } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import * as cypressVersionUtils from '../../utils/cypress-version';
import migration from './update-cypress-version-13-6-6';

describe('update-cypress-version migration', () => {
let tree: Tree;

function setCypressVersion(version: string) {
updateJson(tree, 'package.json', (json) => {
json.devDependencies ??= {};
json.devDependencies.cypress = version;
return json;
});
const major = parseInt(version.split('.')[0].replace('^', ''), 10);
jest
.spyOn(cypressVersionUtils, 'installedCypressVersion')
.mockReturnValue(major);
}

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});

it('should bump cypress version to ^13.6.6', async () => {
setCypressVersion('^13.0.0');

await migration(tree);

const { devDependencies } = readJson(tree, 'package.json');
expect(devDependencies.cypress).toBe('^13.6.6');
});

it('should not update cypress version if it is not >= 13', async () => {
setCypressVersion('^12.0.0');

await migration(tree);

const { devDependencies } = readJson(tree, 'package.json');
expect(devDependencies.cypress).toBe('^12.0.0');
});
});
@@ -0,0 +1,16 @@
import {
addDependenciesToPackageJson,
formatFiles,
type Tree,
} from '@nx/devkit';
import { installedCypressVersion } from '../../utils/cypress-version';

export default async function (tree: Tree) {
if (installedCypressVersion() < 13) {
return;
}

addDependenciesToPackageJson(tree, {}, { cypress: '^13.6.6' });

await formatFiles(tree);
}
2 changes: 1 addition & 1 deletion packages/cypress/src/utils/versions.ts
Expand Up @@ -2,7 +2,7 @@ export const nxVersion = require('../../package.json').version;
export const eslintPluginCypressVersion = '^2.13.4';
export const typesNodeVersion = '18.16.9';
export const cypressViteDevServerVersion = '^2.2.1';
export const cypressVersion = '13.6.4';
export const cypressVersion = '^13.6.6';
export const cypressWebpackVersion = '^2.0.0';
export const webpackHttpPluginVersion = '^5.5.0';
export const viteVersion = '~5.0.0';
Expand Down