Skip to content

Commit

Permalink
test: 🔧 add configuration for cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
Carolinedanslesnuages committed Dec 12, 2024
1 parent 0ec3be5 commit 523f857
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 2 deletions.
30 changes: 30 additions & 0 deletions client/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:5173', // Remplacez par l'URL de votre application
setupNodeEvents(on, config) {
// Implémentez ici les écouteurs d'événements Node
// Exemple : utiliser un plugin
// require('cypress-plugin-snapshots/plugin')(on, config);
return config;
},
specPattern: "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}",
supportFile: "cypress/support/e2e.ts",
},

component: {
devServer: {
framework: "vue",
bundler: "vite",
},
specPattern: "cypress/component/**/*.cy.{js,jsx,ts,tsx,vue}",
supportFile: "cypress/support/component.ts",
},

// Autres configurations globales si nécessaire
retries: {
runMode: 2,
openMode: 0,
},
});
5 changes: 5 additions & 0 deletions client/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
51 changes: 51 additions & 0 deletions client/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/// <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
// ***********************************************
//
//
Cypress.Commands.add('login', (username: string, password: string) => {
// Naviguer vers la page de connexion
cy.get('.fr-btn').contains('Se connecter').click();
cy.wait(2000);

// Interagir avec l'origine différente pour se connecter
cy.origin('http://localhost:8082', { args: { username, password } }, ({ username, password }) => {
cy.get('#username').type(username); // Saisir le nom d'utilisateur
cy.get('#password').type(password); // Saisir le mot de passe
cy.get('#rememberMe').check(); // Cocher "Remember me" (facultatif)
cy.get('#kc-login').click(); // Soumettre le formulaire
});

// Attendre la redirection vers l'URL principale après connexion
cy.url().should('include', 'http://localhost:5173');
});
//
//
// -- 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>
// }
// }
// }
12 changes: 12 additions & 0 deletions client/cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!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>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
40 changes: 40 additions & 0 deletions client/cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ***********************************************************
// 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/vue'

// 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
login(username: string, password: string): Chainable<void>;
}
}
}

Cypress.Commands.add('mount', mount)

// Example use:
// cy.mount(MyComponent)
20 changes: 20 additions & 0 deletions client/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.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')
16 changes: 16 additions & 0 deletions client/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["../src/*"]
},
"types": ["cypress", "node"],
"noEmit": true
},
"include": [
"./**/*.ts",
"vite.config.ts"
],
"exclude": []
}
9 changes: 9 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test:unit": "vitest run",
"test:watch": "vitest",
"test:e2e": "cypress open",
"test:e2e-run": "cypress run",
"type-check": "vue-tsc --build --force"
},
"dependencies": {
Expand All @@ -30,13 +31,21 @@
"vue": "^3.4.38",
"vue-router": "^4.4.3"
},

"optionalDependencies": {
"@cypress/vue": "^6.0.1",
"cypress": "^13.12.0",
"cypress-vite": "^1.5.0"
},

"devDependencies": {
"@antfu/eslint-config": "^3.0.0",
"@playwright/test": "^1.46.1",
"@rushstack/eslint-patch": "^1.10.4",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/vue": "^8.1.0",
"@tsconfig/node20": "^20.1.4",
"@types/cypress": "^1.1.6",
"@types/jsdom": "^21.1.7",
"@types/node": "^20.16.2",
"@vitejs/plugin-vue": "^5.1.3",
Expand Down
2 changes: 1 addition & 1 deletion client/tsconfig.vitest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.vitest.tsbuildinfo",

"lib": [],
"types": ["node", "jsdom", "@testing-library/jest-dom"]
"types": ["node", "cypress", "jsdom", "@testing-library/jest-dom"]
},
"exclude": []
}
2 changes: 1 addition & 1 deletion client/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export default mergeConfig(
setupFiles: [fileURLToPath(new URL("./vitest-setup.ts", import.meta.url))],
},
}),
);
);

0 comments on commit 523f857

Please sign in to comment.