Skip to content

Commit 9770599

Browse files
committed
🧪 test: add e2e tests with Cypress
1 parent ae1bdf3 commit 9770599

17 files changed

+1330
-92
lines changed

‎.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ pnpm-debug.log*
1212

1313
# environment variables
1414
.env.production
15+
src/env.d.ts
1516

1617
# macOS-specific files
1718
.DS_Store
1819

1920
# localhost mobile preview
2021
ngrok.exe
22+
23+
# Cypress files
24+
tests/cypress/videos
25+
tests/cypress/downloads
26+
tests/cypress/screenshots

‎astro.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default defineConfig({
1010
assets: 'assets',
1111
},
1212
server: {
13-
open: true,
1413
port: 3000,
1514
host: '127.0.0.1',
1615
},

‎cypress.config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { resolve } from 'node:path';
2+
import { defineConfig } from 'cypress';
3+
import vitePreprocessor from 'cypress-vite';
4+
import { URL, fileURLToPath } from 'node:url';
5+
6+
export default defineConfig({
7+
viewportWidth: 1024,
8+
scrollBehavior: 'center',
9+
e2e: {
10+
supportFile: false,
11+
experimentalStudio: true,
12+
baseUrl: 'http://127.0.0.1:3000/image-editor',
13+
specPattern: 'tests/cypress/e2e/**/*.cy.ts',
14+
videosFolder: 'tests/cypress/videos',
15+
fixturesFolder: 'tests/cypress/fixtures',
16+
downloadsFolder: 'tests/cypress/downloads',
17+
screenshotsFolder: 'tests/cypress/screenshots',
18+
setupNodeEvents(on) {
19+
on('file:preprocessor', vitePreprocessor({
20+
resolve: {
21+
alias: {
22+
'@ts': resolve(fileURLToPath(new URL('./src/assets/ts', import.meta.url))),
23+
'@types': resolve(fileURLToPath(new URL('./src/types.d.ts', import.meta.url))),
24+
},
25+
},
26+
}));
27+
},
28+
},
29+
});

‎eslint.config.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import eslintJS from '@eslint/js';
22
import eslintAntfuConfig from '@antfu/eslint-config';
33
import eslintPluginVitest from 'eslint-plugin-vitest';
44
import eslintPluginStylistic from '@stylistic/eslint-plugin';
5+
import eslintPluginCypress from 'eslint-plugin-cypress/flat';
56

67
/* eslint-disable no-magic-numbers -- Improve SNR */
78
const jsRules = {
@@ -183,6 +184,13 @@ const vitestRules = {
183184
'vitest/max-nested-describe': ['error', { max: 1 }],
184185
};
185186

187+
const cypressRules = {
188+
'cypress/no-pause': 'error',
189+
'cypress/no-force': 'error',
190+
'cypress/no-async-tests': 'off',
191+
'cypress/assertion-before-screenshot': 'error',
192+
};
193+
186194
const stylisticRules = {
187195
...eslintPluginStylistic.configs['recommended-flat'].rules,
188196

@@ -289,12 +297,11 @@ const generalRules = {
289297

290298
export default eslintAntfuConfig(
291299
{
292-
files: ['**/*.js', '**/*.ts'],
300+
files: ['**/*.{js,ts}'],
293301
vue: false,
294302
typescript: {
295303
tsconfigPath: 'tsconfig.json',
296304
},
297-
// @ts-ignore: TypeScript can't properly infer the types.
298305
rules: { ...jsRules, ...tsRules, ...stylisticRules },
299306
},
300307
{
@@ -317,6 +324,11 @@ export default eslintAntfuConfig(
317324
'ts/no-unsafe-member-access': 'off',
318325
},
319326
},
327+
{
328+
files: ['tests/cypress/**/*.ts'],
329+
...eslintPluginCypress.configs.recommended,
330+
rules: { ...cypressRules, 'no-magic-numbers': 'off' },
331+
},
320332
{ rules: generalRules },
321333
{ ignores: ['**/*.json', 'src/env.d.ts'] },
322334
);

‎package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
},
2121
"scripts": {
2222
"dev": "astro dev",
23-
"format": "npx prettier --write '**/*.{json,css,astro}' --config=prettier.config.js --cache",
24-
"lint": "eslint --fix --ignore-pattern='.vscode/*.json' --config=eslint.config.js --cache-location='/node_modules/.eslintcache/",
25-
"test:unit": "vitest --config=vitest.config.ts",
2623
"build": "astro build",
27-
"removeEnvTypesFile": "node scripts/removeEnvTypesFile.js",
2824
"preview": "astro preview",
29-
"all": "pnpm format && pnpm lint && pnpm test:unit --run && pnpm build && pnpm removeEnvTypesFile"
25+
"format": "prettier --write '**/*.{json,css,astro}' --config=prettier.config.js --cache",
26+
"lint": "eslint --fix --ignore-pattern='.vscode/*.json' --config=eslint.config.js --cache-location='/node_modules/.eslintcache/",
27+
"test:unit": "vitest --config=vitest.config.ts",
28+
"test:e2e": "concurrently \"pnpm dev\" \"cypress open\" --kill-others",
29+
"test:e2e:ci": "concurrently \"pnpm preview\" \"cypress run --headed\" --kill-others",
30+
"all": "pnpm format && pnpm lint && pnpm test:unit --run && pnpm build && pnpm test:e2e:ci"
3031
},
3132
"dependencies": {
3233
"@formkit/auto-animate": "^0.8.1",
@@ -39,7 +40,11 @@
3940
"@types/eslint__js": "^8.42.3",
4041
"astro": "^4.4.15",
4142
"browserslist": "^4.23.0",
43+
"concurrently": "^8.2.2",
44+
"cypress": "^13.13.2",
45+
"cypress-vite": "^1.5.0",
4246
"eslint": "^9.8.0",
47+
"eslint-plugin-cypress": "^3.4.0",
4348
"eslint-plugin-vitest": "^0.5.4",
4449
"lightningcss": "^1.24.0",
4550
"prettier": "^3.2.5",

0 commit comments

Comments
 (0)