Skip to content

Commit

Permalink
Update Cypress to version 10 (rancher#6146)
Browse files Browse the repository at this point in the history
* Run Cypress migration scripts; Update failing parts

* Move env var assignments to Cypress configuration; Correct env patterns

* Correct imports within the Cypress tests

* Correct TS linting configuration errors after update

* Return directly spec path in cypress configuration
  • Loading branch information
cnotv authored and bisht-richa committed Aug 12, 2022
1 parent 39866fa commit b6be5ca
Show file tree
Hide file tree
Showing 32 changed files with 882 additions and 173 deletions.
44 changes: 44 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { defineConfig } from 'cypress';
require('dotenv').config();

/**
* Filter test spec paths based on env var configuration
* @returns
*/
const getSpecPattern = (): string[] => {
const optionalPaths = [
{
path: 'cypress/e2e/tests/setup/**/*.spec.ts',
active: process.env.TEST_SKIP_SETUP !== 'true'
}
];
const activePaths = optionalPaths.filter(({ active }) => Boolean(active)).map(({ path }) => path);

return [
...activePaths,
'cypress/e2e/tests/pages/**/*.spec.ts',
'cypress/e2e/tests/navigation/**/*.spec.ts'
];
};
const baseUrl = (process.env.TEST_BASE_URL || 'https://localhost:8005').replace(/\/$/, '');

export default defineConfig({
defaultCommandTimeout: 60000,
trashAssetsBeforeRuns: true,
env: {
baseUrl,
username: process.env.TEST_USERNAME,
password: process.env.TEST_PASSWORD,
bootstrapPassword: process.env.CATTLE_BOOTSTRAP_PASSWORD,
},
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.ts')(on, config);
},
experimentalSessionAndOrigin: true,
specPattern: getSpecPattern(),
baseUrl
},
});
10 changes: 0 additions & 10 deletions cypress.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class AsyncButtonPo extends ComponentPo {
click(): Cypress.Chainable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class CheckboxInputPo extends ComponentPo {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CypressChainable } from '@/cypress/integration/po/po.types';
import { CypressChainable } from '@/cypress/e2e/po/po.types';

export default class ComponentPo {
public self: () => CypressChainable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class FormPo extends ComponentPo {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class LabeledInputPo extends ComponentPo {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class PasswordPo extends ComponentPo {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class RadioGroupInputPo extends ComponentPo {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class RadioInputPo extends ComponentPo {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PagePo from '@/cypress/integration/po/pages/page.po';
import PagePo from '@/cypress/e2e/po/pages/page.po';

export default class HomePagePo extends PagePo {
static url: string = '/home'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PagePo from '@/cypress/integration/po/pages/page.po';
import LabeledInputPo from '@/cypress/integration/po/components/labeled-input.po';
import AsyncButtonPo from '@/cypress/integration/po/components/async-button.po';
import PasswordPo from '~/cypress/integration/po/components/password.po';
import PagePo from '@/cypress/e2e/po/pages/page.po';
import LabeledInputPo from '@/cypress/e2e/po/components/labeled-input.po';
import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po';
import PasswordPo from '@/cypress/e2e/po/components/password.po';

export class LoginPagePo extends PagePo {
static url: string = '/auth/login'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class PagePo extends ComponentPo {
constructor(private path: string, selector: string = '.dashboard-root') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import PagePo from '@/cypress/integration/po/pages/page.po';
import LabeledInputPo from '@/cypress/integration/po/components/labeled-input.po';
import CheckboxInputPo from '@/cypress/integration/po/components/checkbox-input.po';
import RadioGroupInputPo from '@/cypress/integration/po/components/radio-group-input.po';
import AsyncButtonPo from '@/cypress/integration/po/components/async-button.po';
import PasswordPo from '~/cypress/integration/po/components/password.po';
import PagePo from '@/cypress/e2e/po/pages/page.po';
import LabeledInputPo from '@/cypress/e2e/po/components/labeled-input.po';
import CheckboxInputPo from '@/cypress/e2e/po/components/checkbox-input.po';
import RadioGroupInputPo from '@/cypress/e2e/po/components/radio-group-input.po';
import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po';
import PasswordPo from '@/cypress/e2e/po/components/password.po';

export class RancherSetupAuthVerifyPage extends PagePo {
static url: string = '/auth/login'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PagePo from '@/cypress/integration/po/pages/page.po';
import AsyncButtonPo from '@/cypress/integration/po/components/async-button.po';
import FormPo from '@/cypress/integration/po/components/form.po';
import PasswordPo from '~/cypress/integration/po/components/password.po';
import PagePo from '@/cypress/e2e/po/pages/page.po';
import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po';
import FormPo from '@/cypress/e2e/po/components/form.po';
import PasswordPo from '@/cypress/e2e/po/components/password.po';

export class RancherSetupPagePo extends PagePo {
static url: string = '/auth/login'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class BurgerMenuPo extends ComponentPo {
constructor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class PageActionsPo extends ComponentPo {
constructor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentPo from '@/cypress/integration/po/components/component.po';
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class ProductNavPo extends ComponentPo {
constructor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PageActions from '@/cypress/integration/po/side-bars/page-actions.po';
import HomePagePo from '@/cypress/integration/po/pages/home.po';
import PageActions from '@/cypress/e2e/po/side-bars/page-actions.po';
import HomePagePo from '@/cypress/e2e/po/pages/home.po';

describe('Page Actions', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HomePagePo from '@/cypress/integration/po/pages/home.po';
import BurgerMenuPo from '@/cypress/integration/po/side-bars/burger-side-menu.po';
import HomePagePo from '@/cypress/e2e/po/pages/home.po';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';

Cypress.config();
describe('Side Menu: main', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import HomePagePo from '@/cypress/integration/po/pages/home.po';
import BurgerMenuPo from '@/cypress/integration/po/side-bars/burger-side-menu.po';
import ProductNavPo from '@/cypress/integration/po/side-bars/product-side-nav.po';
import HomePagePo from '@/cypress/e2e/po/pages/home.po';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
import ProductNavPo from '@/cypress/e2e/po/side-bars/product-side-nav.po';

Cypress.config();
describe('Side navigation: Cluster ', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import HomePagePo from '@/cypress/integration/po/pages/home.po';
import BurgerMenuPo from '@/cypress/integration/po/side-bars/burger-side-menu.po';
import PageActions from '@/cypress/integration/po/side-bars/page-actions.po';
import HomePagePo from '@/cypress/e2e/po/pages/home.po';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
import PageActions from '@/cypress/e2e/po/side-bars/page-actions.po';

describe('Home Page', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoginPagePo } from '@/cypress/integration/po/pages/login-page.po';
import { LoginPagePo } from '@/cypress/e2e/po/pages/login-page.po';

describe('Local authentication', () => {
it('Log in with valid credentials', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RancherSetupPagePo } from '@/cypress/integration/po/pages/rancher-setup.po';
import { RancherSetupAuthVerifyPage } from '@/cypress/integration/po/pages/rancher-setup-auth-verify.po';
import { RancherSetupPagePo } from '@/cypress/e2e/po/pages/rancher-setup.po';
import { RancherSetupAuthVerifyPage } from '@/cypress/e2e/po/pages/rancher-setup-auth-verify.po';

describe('Rancher setup', () => {
it('Requires initial setup', () => {
Expand Down
30 changes: 0 additions & 30 deletions cypress/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,9 @@ module.exports = (
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions
) => {
// Disabled due freezing issues related to the CI machine resources
// deletePassedVideos(on);

// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
const url = process.env.TEST_BASE_URL || 'https://localhost:8005';

config.baseUrl = url.replace(/\/$/, '');

config.env.username = process.env.TEST_USERNAME;
config.env.password = process.env.TEST_PASSWORD;
config.env.bootstrapPassword = process.env.CATTLE_BOOTSTRAP_PASSWORD;
config.env.skip_setup = process.env.TEST_SKIP_SETUP;
config.testFiles = skipSetup(config);

return config;
};

/**
* Remove setup files from the Cypress config
* @param config Cypress config file
* @returns
*/
const skipSetup = (config: Cypress.PluginConfigOptions) => {
if (config.env.skip_setup === 'true') {
return (config.testFiles as string[]).filter(
path => !path.includes('tests/setup/')
);
} else {
return config.testFiles;
}
};

/**
* Only upload videos for specs with failing
* Run this function after every spec to delete passed tests video
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoginPagePo } from '@/cypress/integration/po/pages/login-page.po';
import { LoginPagePo } from '@/cypress/e2e/po/pages/login-page.po';

/**
* Login local authentication, including first login and bootstrap if not cached
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions docusaurus/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const config = {
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
navbar: {
title: "DevKit",
title: 'DevKit',
logo: {
alt: 'Rancher Logo',
src: 'img/rancher-logo.svg',
Expand Down Expand Up @@ -79,7 +79,7 @@ const config = {
},
{
label: 'Github',
href: 'https://github.com/rancher/',
href: 'https://github.com/rancher/',
},
],
copyright: `Copyright © ${ new Date().getFullYear() } Rancher. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks.`,
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
"@babel/plugin-proposal-optional-chaining": "^7.14.5",
"@babel/plugin-proposal-private-property-in-object": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
"@cypress/vue": "^3.1.1",
"@cypress/webpack-dev-server": "^1.8.4",
"@cypress/vue": "^4.0.0",
"@cypress/webpack-dev-server": "^2.0.0",
"@nuxt/types": "2.14.6",
"@nuxt/typescript-build": "^2.1.0",
"@nuxtjs/eslint-config-typescript": "^6.0.1",
Expand All @@ -156,7 +156,7 @@
"core-js": "^3.20.3",
"css-loader": "4.3.0",
"csv-loader": "^3.0.3",
"cypress": "^9.6.0",
"cypress": "^10.3.1",
"eslint": "^7.32.0",
"eslint-config-standard": ">=12.0.0",
"eslint-import-resolver-node": "0.3.4",
Expand Down
11 changes: 10 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
"compilerOptions": {
"types": ["@types/node", "@types/jest", "@nuxt/types"]
},
"exclude": ["node_modules", ".nuxt", "dist", "dist-pkg", "cypress", "shell/creators", "docusaurus"]
"exclude": [
"node_modules",
".nuxt",
"dist",
"dist-pkg",
"cypress",
"shell/creators",
"cypress",
"./cypress.config.ts"
]
}
Loading

0 comments on commit b6be5ca

Please sign in to comment.