Skip to content

Commit

Permalink
validation tests for cypress 12 and 13 with the latest modification b…
Browse files Browse the repository at this point in the history
…ased on the results from cypress 12 without modification
  • Loading branch information
miguelangarano committed Sep 7, 2023
1 parent a3d70da commit bfd11fe
Show file tree
Hide file tree
Showing 39 changed files with 13,217 additions and 4 deletions.
13 changes: 13 additions & 0 deletions e2e/cypress-12-demo/currents.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
e2e: {
batchSize: 3, // how many specs to send in one batch
},
component: {
batchSize: 5, // how many specs to send in one batch
},
// eslint-disable-next-line turbo/no-undeclared-env-vars
projectId: !!(process.env.GITHUB_ACTION || process.env.CIRCLE_BRANCH)
? "Ij0RfK"
: "l4zuz8",
// cloudServiceUrl: "http://localhost:1234",
};
26 changes: 26 additions & 0 deletions e2e/cypress-12-demo/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { defineConfig } from "cypress";
import currents from "cypress-cloud/plugin";

module.exports = defineConfig({
e2e: {
baseUrl: "https://todomvc.com/examples/vanillajs",
supportFile: "cypress/support/e2e.ts",
specPattern: "cypress/*/**/*.spec.js",
setupNodeEvents(on, config) {
require("@cypress/grep/src/plugin")(config);
// require("cypress-terminal-report/src/installLogsPrinter")(on);
return currents(on, config);
},
},

component: {
specPattern: ["pages/__tests__/*.spec.tsx"],
setupNodeEvents(on, config) {
return currents(on, config);
},
devServer: {
framework: "next",
bundler: "webpack",
},
},
});
16 changes: 16 additions & 0 deletions e2e/cypress-12-demo/cypress/e2e/retries.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let i = 3;
describe("Retries", function () {
it(
"Runs a test with retries",
{
retries: 3,
},
function () {
throw new Error("x".repeat(1024));
// if (i > 1) {
// i--;
// }
// return;
}
);
});
43 changes: 43 additions & 0 deletions e2e/cypress-12-demo/cypress/e2e/xxx.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
let TODO_ITEM_ONE = "item A";
let TODO_ITEM_TWO = "item B";
let TODO_ITEM_THREE = "item C";

context("Clear completed button", function () {
beforeEach(function () {
cy.createDefaultTodos().as("todos");
});

it(
"should display the correct text",
{
tags: ["@tagA"],
},
function () {
cy.get("@todos").eq(0).find(".toggle").check();
cy.get(".clear-completed").contains("Clear completed X");
}
);

it(
"should remove completed items when clicked",
{
tags: ["@tagB"],
},
function () {
cy.get("@todos").eq(1).find(".toggle").check();

cy.get(".clear-completed").click();
cy.get("@todos").should("have.length", 2);
cy.get(".todo-list li").eq(0).should("contain", TODO_ITEM_ONE);
cy.get(".todo-list li").eq(1).should("contain", "XXXX");
}
);

it("should be hidden when there are no items that are completed", function () {
cy.get("@todos").eq(1).find(".toggle").check();

cy.get(".clear-completed").should("be.visible").click();

cy.get(".clear-completed").should("not.be.visible");
});
});
119 changes: 119 additions & 0 deletions e2e/cypress-12-demo/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }

// ***********************************************
// This example commands.js shows you how to
// create the custom commands: 'createDefaultTodos'
// and 'createTodo'.
//
// The commands.js file is a great place to
// modify existing commands and create custom
// commands for use throughout your tests.
//
// You can read more about custom commands here:
// https://on.cypress.io/commands
// ***********************************************

Cypress.Commands.add("createDefaultTodos", function () {
let TODO_ITEM_ONE = "buy some cheese";
let TODO_ITEM_TWO = "feed the cat";
let TODO_ITEM_THREE = "book a doctors appointment";

// begin the command here, which by will display
// as a 'spinning blue state' in the UI to indicate
// the command is running
let cmd = Cypress.log({
name: "create default todos",
message: [],
consoleProps() {
// we're creating our own custom message here
// which will print out to our browsers console
// whenever we click on this command
return {
"Inserted Todos": [TODO_ITEM_ONE, TODO_ITEM_TWO, TODO_ITEM_THREE],
};
},
});

// additionally we pass {log: false} to all of our
// sub-commands so none of them will output to
// our command log

cy.get(".new-todo", { log: false })
.type(`${TODO_ITEM_ONE}{enter}`, { log: false })
.type(`${TODO_ITEM_TWO}{enter}`, { log: false })
.type(`${TODO_ITEM_THREE}{enter}`, { log: false });

cy.get(".todo-list li", { log: false }).then(function ($listItems) {
// once we're done inserting each of the todos
// above we want to return the .todo-list li's
// to allow for further chaining and then
// we want to snapshot the state of the DOM
// and end the command so it goes from that
// 'spinning blue state' to the 'finished state'
cmd.set({ $el: $listItems }).snapshot().end();
});
});

Cypress.Commands.add("createTodo", function (todo) {
let cmd = Cypress.log({
name: "create todo",
message: todo,
consoleProps() {
return {
"Inserted Todo": todo,
};
},
});

// create the todo
cy.get(".new-todo", { log: false }).type(`${todo}{enter}`, { log: false });

// now go find the actual todo
// in the todo list so we can
// easily alias this in our tests
// and set the $el so its highlighted
cy.get(".todo-list", { log: false })
.contains("li", todo.trim(), { log: false })
.then(function ($li) {
// set the $el for the command so
// it highlights when we hover over
// our command
cmd.set({ $el: $li }).snapshot().end();
});
});
14 changes: 14 additions & 0 deletions e2e/cypress-12-demo/cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
<!-- Used by Next.js to inject CSS. -->
<div id="__next_css__DO_NOT_USE__"></div>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
39 changes: 39 additions & 0 deletions e2e/cypress-12-demo/cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ***********************************************************
// This example support/component.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')

import { mount } from "cypress/react18";

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount;
}
}
}

Cypress.Commands.add("mount", mount);

// Example use:
// cy.mount(<MyComponent />)
9 changes: 9 additions & 0 deletions e2e/cypress-12-demo/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import registerCypressGrep from "@cypress/grep/src/support";
require("cypress-terminal-report/src/installLogsCollector")();
require("cypress-cloud/support");
require("./commands");

registerCypressGrep();
beforeEach(() => {
cy.visit("/");
});
Loading

0 comments on commit bfd11fe

Please sign in to comment.