Skip to content

Commit

Permalink
chore(cypress): add path aliases for Cypress tests to import React ap…
Browse files Browse the repository at this point in the history
…p modules
  • Loading branch information
hdinia committed Jan 27, 2025
1 parent bd97359 commit 9d4c4cf
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 16 deletions.
5 changes: 5 additions & 0 deletions webapp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Cypress
cypress/screenshots
cypress/videos
cypress/downloads
5 changes: 2 additions & 3 deletions webapp/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
*/

import { defineConfig } from "cypress";
import { resolve, dirname } from "path";
import { fileURLToPath } from "url";
import { resolve } from "path";

export default defineConfig({
e2e: {
Expand All @@ -31,7 +30,7 @@ export default defineConfig({
framework: "react",
bundler: "vite",
viteConfig: {
configFile: resolve(dirname(fileURLToPath(import.meta.url)), "vite.config.ts"),
configFile: resolve(import.meta.dirname, "vite.config.ts"),
},
},
},
Expand Down
3 changes: 0 additions & 3 deletions webapp/cypress/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion webapp/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This file is part of the Antares project.
*/

import { AppPages } from "constants";
import { AppPages } from "@cypress/constants";
import "@testing-library/cypress/add-commands";

Cypress.Commands.add(
Expand Down
11 changes: 8 additions & 3 deletions webapp/cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
"types": ["cypress", "@testing-library/cypress"],
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
"@app/*": ["../src/*"], // React app imports
"@cypress/*": ["./*"] // Cypress-specific imports
},
"skipLibCheck": false,
"moduleResolution": "node"
},
"include": [
"**/*.ts",
"**/*.ts",
"../src/**/*.ts",
"../src/**/*.tsx"
]
}
2 changes: 1 addition & 1 deletion webapp/cypress/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* This file is part of the Antares project.
*/

import { TAppPages } from "./index";
import { mount } from "cypress/react";
import type { TAppPages } from ".";

declare global {
namespace Cypress {
Expand Down
2 changes: 1 addition & 1 deletion webapp/cypress/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
* This file is part of the Antares project.
*/

import type { AppPages } from "constants";
import type { AppPages } from "@cypress/constants";

export type TAppPages = keyof typeof AppPages;
7 changes: 4 additions & 3 deletions webapp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"target": "es2022",
"useDefineForClassFields": true,
"lib": [
"ES2022",
"DOM",
"ES2022",
"DOM",
"DOM.Iterable",
],
"module": "ESNext",
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
"@/*": ["src/*"],
"@app/*": ["src/*"]
},

/* Bundler mode */
Expand Down
2 changes: 1 addition & 1 deletion webapp/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"allowSyntheticDefaultImports": true,
"types": [
"vitest/globals",
"vitest/jsdom",
"vitest/jsdom"
]
},
"include": ["vite.config.ts"]
Expand Down

0 comments on commit 9d4c4cf

Please sign in to comment.