Skip to content

Commit

Permalink
feat(testing): update cypress version (#21961)
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez authored Feb 23, 2024
1 parent 776367e commit dd2c7d2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/cypress/migrations.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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');
});
});
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit dd2c7d2

Please sign in to comment.