experiment: Cucumber/Gherkin + Cypress (#24)

* chore: point de départ pour l'expérimentation Cucumber/Gherkin + Cypress

Repart de zéro (pas de reprise du travail précédent sur
feat/cypress-cucumber, fermée/supprimée) — voir la discussion sur la
PR pour le contexte : bug amont dans
@badeball/cypress-cucumber-preprocessor@26.0.0 (require() synchrone de
dépendances @cucumber/* désormais ESM pur, plusieurs incompatibilités
de schéma trouvées en épinglant d'anciennes versions).

* feat(web): installe cypress-cucumber-preprocessor@22.2.0, versions figées

Étape 1 de l'expérimentation. Versions exactes (pas de ^), comme
demandé, pour éviter que le prochain `pnpm install` fasse dériver la
résolution vers des patchs plus récents :

- @badeball/cypress-cucumber-preprocessor@22.2.0
- @bahmutov/cypress-esbuild-preprocessor@2.2.8
- cypress@13.17.0
- esbuild@0.21.5

Contrairement à v26.0.0 (utilisé dans la tentative précédente,
fermée), cette version charge sans ERR_REQUIRE_ESM — aucun
pnpm.overrides nécessaire cette fois. Vérifié :
- `import { addCucumberPreprocessorPlugin }` : OK
- `addCucumberPreprocessorPlugin(on, config)` avec un contexte Cypress
  minimal : résout sans erreur, enregistre tous ses event handlers
  (before:run, after:run, before:spec, after:spec, after:screenshot,
  task)

À vérifier ensuite : cypress.config.ts + un vrai fichier .feature.

* test(web): feature Gherkin jetable pour valider le pipeline preprocessor

Étape 2 de l'expérimentation — un seul scénario minimal (remplir
email/password sur l'écran de connexion) pour vérifier que
addCucumberPreprocessorPlugin@22.2.0 + l'esbuild plugin fonctionnent
de bout en bout, pas juste au chargement. Steps volontairement
autonomes dans login-smoke.steps.ts (pas de fichier partagé) — tout
ce fichier est prévu pour être supprimé une fois validé.

cypress.config.ts : specPattern couvre maintenant *.cy.ts ET *.feature
en parallèle (le reste de la suite reste en .cy.ts classique pour
l'instant).

Testé en local jusqu'au mur GPU/Electron habituel de cet
environnement (chargement de la config + bundling esbuild passent,
pas d'ERR_REQUIRE_ESM) — la vraie exécution du scénario reste à
vérifier via la CI.

* fix(web): renomme login-smoke.steps.ts en login-smoke.ts

Le vrai (et seul) problème du run précédent : "Step implementation
missing for 'I am not signed in'" — pas un souci ESM/CJS cette fois,
juste une convention de nommage. Le pattern stepDefinitions par défaut
du preprocessor cherche, pour cypress/e2e/login-smoke.feature :

  - cypress/e2e/login-smoke/**/*.{js,mjs,ts,tsx}
  - cypress/e2e/login-smoke.{js,mjs,ts,tsx}   <- même basename, SANS ".steps"
  - cypress/support/step_definitions/**/*.{js,mjs,ts,tsx}

`login-smoke.steps.ts` ne correspond à aucun des trois. Confirmé par
le message d'erreur lui-même (Cypress liste les 3 patterns essayés).
This commit is contained in:
kyuno053 2026-08-19 13:04:21 +02:00 committed by GitHub
parent ffb1e06130
commit fc886a79cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 2399 additions and 5 deletions

View file

@ -1,9 +1,18 @@
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
import { createEsbuildPlugin } from "@badeball/cypress-cucumber-preprocessor/esbuild";
import createBundler from "@bahmutov/cypress-esbuild-preprocessor";
import { defineConfig } from "cypress";
export default defineConfig({
e2e: {
baseUrl: "http://localhost:5173",
setupNodeEvents(on) {
// Experimental — testing whether real Gherkin .feature files work with
// this preprocessor version (see experiment/cucumber-cypress). Only one
// throwaway feature exists right now (login.feature); the rest of the
// suite is still plain .cy.ts, matched by the default `**/*.cy.ts`
// pattern alongside `**/*.feature`.
specPattern: ["cypress/e2e/**/*.cy.ts", "cypress/e2e/**/*.feature"],
async setupNodeEvents(on, config) {
// Disable GPU for headless/sandboxed environments (e.g. CI containers)
// where no GPU device is available.
on("before:browser:launch", (browser, launchOptions) => {
@ -12,6 +21,16 @@ export default defineConfig({
}
return launchOptions;
});
await addCucumberPreprocessorPlugin(on, config);
on(
"file:preprocessor",
createBundler({
plugins: [createEsbuildPlugin(config)],
}),
);
return config;
},
},
});

View file

@ -0,0 +1,12 @@
Feature: Login screen (throwaway smoke test)
Just checking that Gherkin + Cypress actually work end to end with the
currently installed preprocessor version not meant to stay in the
suite long-term.
Scenario: A visitor can type their credentials into the login screen
Given I am not signed in
When I visit "/login"
And I fill in the "email" field with "alice@example.com"
And I fill in the "password" field with "correct-horse-battery-staple"
Then the "email" field should have the value "alice@example.com"
And the "password" field should have the value "correct-horse-battery-staple"

View file

@ -0,0 +1,21 @@
import { Given, Then, When } from "@badeball/cypress-cucumber-preprocessor";
// Throwaway smoke test — see login-smoke.feature. Steps are deliberately
// minimal/self-contained here rather than shared, since this whole file is
// meant to be deleted once it's proven the preprocessor works.
Given("I am not signed in", () => {
cy.intercept("GET", "**/auth/me", { statusCode: 401 });
});
When("I visit {string}", (path: string) => {
cy.visit(path);
});
When("I fill in the {string} field with {string}", (fieldId: string, value: string) => {
cy.get(`#${fieldId}`).type(value);
});
Then("the {string} field should have the value {string}", (fieldId: string, value: string) => {
cy.get(`#${fieldId}`).should("have.value", value);
});

View file

@ -24,11 +24,14 @@
"zod": "^3.25.76"
},
"devDependencies": {
"@badeball/cypress-cucumber-preprocessor": "22.2.0",
"@bahmutov/cypress-esbuild-preprocessor": "2.2.8",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"cypress": "^13.15.2",
"cypress": "13.17.0",
"esbuild": "0.21.5",
"sass": "^1.102.0",
"start-server-and-test": "^2.0.8",
"typescript": "^5.7.2",

File diff suppressed because it is too large Load diff