Skip to content

Commit

Permalink
chore(cypress): add component test cypress starter
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunan-k committed Dec 3, 2023
1 parent de83ba4 commit 92b48b5
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ export default defineConfig({
baseUrl: "http://localhost:3000",
setupNodeEvents(on, config) {
// implement node event listeners here
on("task", {
seedDatabase(fileName) {
// Run node js
// Edit files
console.log(`Cypress task running ${fileName}...`);
return fileName;
}
});
}
},

component: {
devServer: {
framework: "next",
bundler: "webpack"
}
}
});
3 changes: 3 additions & 0 deletions cypress/e2e/signUp.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ describe(
});
it("should be able to click Register here ! for signing up to the application", () => {
cy.visit("http://localhost:3000/");
cy.task("seedDatabase", "arjunank.json").then((returnValue) => {
console.log(returnValue);
});
// cy.get(".signin-signup p span").click({ force: true });
cy.get("[data-cy='registerHereButton']").then((el) => {
expect(el.text("Register Here !"));
Expand Down
14 changes: 14 additions & 0 deletions 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 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 />)
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^9.2.1",
"@semantic-release/release-notes-generator": "^12.0.0",
"@types/cypress": "^1.1.3",
"@types/node": "^20.8.0",
"@types/react": "^18.2.24",
"@types/react-dom": "^18.2.8",
Expand Down

0 comments on commit 92b48b5

Please sign in to comment.