Skip to content

Commit dd2c7d2

Browse files
authored
feat(testing): update cypress version (#21961)
1 parent 776367e commit dd2c7d2

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

packages/cypress/migrations.json

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
"version": "16.8.0-beta.4",
4848
"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",
4949
"implementation": "./src/migrations/update-16-8-0/cypress-13"
50+
},
51+
"update-cypress-version-13-6-6": {
52+
"cli": "nx",
53+
"version": "18.1.0-beta.3",
54+
"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.",
55+
"implementation": "./src/migrations/update-18-1-0/update-cypress-version-13-6-6"
5056
}
5157
},
5258
"packageJsonUpdates": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { readJson, updateJson, type Tree } from '@nx/devkit';
2+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
3+
import * as cypressVersionUtils from '../../utils/cypress-version';
4+
import migration from './update-cypress-version-13-6-6';
5+
6+
describe('update-cypress-version migration', () => {
7+
let tree: Tree;
8+
9+
function setCypressVersion(version: string) {
10+
updateJson(tree, 'package.json', (json) => {
11+
json.devDependencies ??= {};
12+
json.devDependencies.cypress = version;
13+
return json;
14+
});
15+
const major = parseInt(version.split('.')[0].replace('^', ''), 10);
16+
jest
17+
.spyOn(cypressVersionUtils, 'installedCypressVersion')
18+
.mockReturnValue(major);
19+
}
20+
21+
beforeEach(() => {
22+
tree = createTreeWithEmptyWorkspace();
23+
});
24+
25+
it('should bump cypress version to ^13.6.6', async () => {
26+
setCypressVersion('^13.0.0');
27+
28+
await migration(tree);
29+
30+
const { devDependencies } = readJson(tree, 'package.json');
31+
expect(devDependencies.cypress).toBe('^13.6.6');
32+
});
33+
34+
it('should not update cypress version if it is not >= 13', async () => {
35+
setCypressVersion('^12.0.0');
36+
37+
await migration(tree);
38+
39+
const { devDependencies } = readJson(tree, 'package.json');
40+
expect(devDependencies.cypress).toBe('^12.0.0');
41+
});
42+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {
2+
addDependenciesToPackageJson,
3+
formatFiles,
4+
type Tree,
5+
} from '@nx/devkit';
6+
import { installedCypressVersion } from '../../utils/cypress-version';
7+
8+
export default async function (tree: Tree) {
9+
if (installedCypressVersion() < 13) {
10+
return;
11+
}
12+
13+
addDependenciesToPackageJson(tree, {}, { cypress: '^13.6.6' });
14+
15+
await formatFiles(tree);
16+
}

packages/cypress/src/utils/versions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const nxVersion = require('../../package.json').version;
22
export const eslintPluginCypressVersion = '^2.13.4';
33
export const typesNodeVersion = '18.16.9';
44
export const cypressViteDevServerVersion = '^2.2.1';
5-
export const cypressVersion = '13.6.4';
5+
export const cypressVersion = '^13.6.6';
66
export const cypressWebpackVersion = '^2.0.0';
77
export const webpackHttpPluginVersion = '^5.5.0';
88
export const viteVersion = '~5.0.0';

0 commit comments

Comments
 (0)