Skip to content

Commit 678f0a1

Browse files
committed
Cypress test works
1 parent 3cfc20a commit 678f0a1

File tree

10 files changed

+1144
-19
lines changed

10 files changed

+1144
-19
lines changed

cypress.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "cypress";
2+
3+
export default defineConfig({
4+
component: {
5+
devServer: {
6+
framework: "next",
7+
bundler: "webpack",
8+
},
9+
},
10+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import TreeVisualizer from "@components/TreeVisualizer";
2+
import failOnConsoleError from "cypress-fail-on-console-error";
3+
import randomPostorders from "src/data/randomPostorders";
4+
5+
describe("TreeVisualizer.cy.tsx", () => {
6+
randomPostorders.forEach((postorder) => {
7+
it("Running postorder: " + postorder, () => {
8+
cy.mount(<TreeVisualizer initialExpression={postorder} />);
9+
cy.get("div.swal2-container").should("not.exist");
10+
});
11+
});
12+
});

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/support/commands.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>Components App</title>
8+
<!-- Used by Next.js to inject CSS. -->
9+
<div id="__next_css__DO_NOT_USE__"></div>
10+
</head>
11+
<body>
12+
<div data-cy-root></div>
13+
</body>
14+
</html>

cypress/support/component.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// ***********************************************************
2+
// This example support/component.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')
21+
22+
import { mount } from 'cypress/react'
23+
24+
// Augment the Cypress namespace to include type definitions for
25+
// your custom command.
26+
// Alternatively, can be defined in cypress/support/component.d.ts
27+
// with a <reference path="./component" /> at the top of your spec.
28+
declare global {
29+
namespace Cypress {
30+
interface Chainable {
31+
mount: typeof mount
32+
}
33+
}
34+
}
35+
36+
Cypress.Commands.add('mount', mount)
37+
38+
// Example use:
39+
// cy.mount(<MyComponent />)

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "next build",
88
"start": "next start",
99
"export": "next build && next export",
10-
"test": "jest"
10+
"cypress": "cypress open"
1111
},
1212
"dependencies": {
1313
"classnames": "^2.3.1",
@@ -30,6 +30,8 @@
3030
"@types/uuid": "^8.3.4",
3131
"autoprefixer": "^10.4.7",
3232
"css-loader": "^6.7.1",
33+
"cypress": "^10.3.1",
34+
"cypress-fail-on-console-error": "^3.2.1",
3335
"postcss": "^8.4.14",
3436
"sass": "^1.54.0",
3537
"tailwindcss": "^3.1.6",

src/__tests__/randomPostorders.test.tsx

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/data/randomPostorders.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
const randomPostorders: string[] = ["3 7 * 9 + 2 /", "3 16 8 / 2 * +"];
1+
const randomPostorders: string[] = [
2+
"3 7 * 9 + 2 /",
3+
"3 16 8 / 2 * +",
4+
"7 1 2 + 3 - *",
5+
];
26
export default randomPostorders;

0 commit comments

Comments
 (0)