Skip to content

Commit 2ce4997

Browse files
committed
build: migrated from Jest to Vitest
1 parent 1cd3702 commit 2ce4997

File tree

17 files changed

+545
-1826
lines changed

17 files changed

+545
-1826
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ jobs:
7575
- name: Install dependencies
7676
run: pnpm install
7777

78-
- name: Run Jest tests
78+
- name: Run Vitest tests
7979
run: pnpm test

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ tests/content/core/config/ldap.php
8989
tests/content/upgrades
9090
tests/fixtures/path-to-delete/foo.bar.baz
9191

92-
# Jest related stuff
92+
# Vitest related stuff
9393
coverage/*
9494

9595
# PHPMD

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This is a log of major user-visible changes in each phpMyFAQ release.
99
### phpMyFAQ v4.1.0-dev - unreleased
1010

1111
- removed Webpack, now using Vite (Thorsten)
12+
- migrated from Jest to vitest (Thorsten)
1213

1314
### phpMyFAQ v4.0.0-RC.4 - 2024-11-09
1415

jest.config.mjs

Lines changed: 0 additions & 13 deletions
This file was deleted.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"lint:fix": "prettier --write .",
2727
"prepare": "husky install",
2828
"pretty-quick": "pretty-quick",
29-
"test": "jest"
29+
"test": "vitest --run",
30+
"test:watch": "vitest",
31+
"coverage": "vitest run --coverage"
3032
},
3133
"dependencies": {
3234
"@popperjs/core": "^2.11.8",
@@ -47,16 +49,12 @@
4749
"@babel/preset-env": "^7.26.0",
4850
"@commitlint/cli": "^19.5.0",
4951
"@commitlint/config-conventional": "^19.5.0",
50-
"@testing-library/jest-dom": "^6.6.3",
5152
"@types/node": "^20.16.5",
53+
"@vitest/coverage-v8": "2.1.5",
5254
"autoprefixer": "^10.4.20",
53-
"babel-jest": "^29.7.0",
5455
"babel-preset-env": "^1.7.0",
55-
"extend-expect": "link:@testing-library/jest-dom/extend-expect",
5656
"husky": "^9.1.6",
57-
"jest": "^29.7.0",
58-
"jest-environment-jsdom": "^29.7.0",
59-
"jest-fetch-mock": "^3.0.3",
57+
"jsdom": "^25.0.1",
6058
"postcss": "^8.4.47",
6159
"prettier": "^3.3.3",
6260
"pretty-quick": "^4.0.0",
@@ -66,7 +64,9 @@
6664
"vite-plugin-compression": "^0.5.1",
6765
"vite-plugin-html": "^3.2.2",
6866
"vite-plugin-minify": "^2.0.1",
69-
"vite-plugin-static-copy": "^2.1.0"
67+
"vite-plugin-static-copy": "^2.1.0",
68+
"vitest": "^2.1.5",
69+
"vitest-fetch-mock": "^0.4.2"
7070
},
7171
"husky": {
7272
"hooks": {

phpmyfaq/.htaccess

Lines changed: 30 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,22 @@
1212
# @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
1313
# @link https://www.phpmyfaq.de
1414
# @since 2004-11-13
15-
1615
DirectoryIndex index.php
17-
1816
# always follow the symlinks
1917
<IfModule mod_negotiation.c>
2018
Options +FollowSymlinks -MultiViews -Indexes
2119
</IfModule>
22-
2320
# X-Frame-Options to prevent clickjacking
2421
Header always append X-Frame-Options SAMEORIGIN
25-
2622
# CORS
2723
Header set Access-Control-Allow-Origin "*"
2824
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE"
2925
Header set Access-Control-Allow-Headers "Content-Type, Authorization"
30-
3126
# Set cache control
3227
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
3328
Header set Cache-Control "max-age=84600, no-store"
3429
Header set Pragma "no-cache"
3530
</filesMatch>
36-
3731
# Set Gzip compression
3832
<IfModule mod_deflate.c>
3933
AddOutputFilterByType DEFLATE application/javascript
@@ -59,130 +53,98 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
5953
AddOutputFilterByType DEFLATE text/plain
6054
AddOutputFilterByType DEFLATE text/xml
6155
</IfModule>
62-
6356
# Enable Expires headers to set expiration dates for various file types
6457
<IfModule mod_expires.c>
65-
ExpiresActive On
66-
67-
# Set expiration for image files to 1 year
68-
ExpiresByType image/jpeg "access plus 1 year"
69-
ExpiresByType image/gif "access plus 1 year"
70-
ExpiresByType image/png "access plus 1 year"
71-
ExpiresByType image/webp "access plus 1 year"
72-
ExpiresByType image/svg+xml "access plus 1 year"
73-
ExpiresByType image/x-icon "access plus 1 year"
74-
75-
# Set expiration for video files to 1 year
76-
ExpiresByType video/webm "access plus 1 year"
77-
ExpiresByType video/mp4 "access plus 1 year"
78-
ExpiresByType video/mpeg "access plus 1 year"
79-
80-
# Set expiration for font files to 1 year
81-
ExpiresByType font/ttf "access plus 1 year"
82-
ExpiresByType font/otf "access plus 1 year"
83-
ExpiresByType font/woff "access plus 1 year"
84-
ExpiresByType font/woff2 "access plus 1 year"
85-
ExpiresByType application/font-woff "access plus 1 year"
86-
ExpiresByType application/font-woff2 "access plus 1 year"
87-
88-
# Set expiration for CSS and JavaScript files to 1 year
89-
ExpiresByType text/css "access plus 1 year"
90-
ExpiresByType text/javascript "access plus 1 year"
91-
ExpiresByType application/javascript "access plus 1 year"
92-
93-
# Set expiration for other file types to 1 year
94-
ExpiresByType application/pdf "access plus 1 year"
95-
ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
58+
ExpiresActive On
59+
# Set expiration for image files to 1 year
60+
ExpiresByType image/jpeg "access plus 1 year"
61+
ExpiresByType image/gif "access plus 1 year"
62+
ExpiresByType image/png "access plus 1 year"
63+
ExpiresByType image/webp "access plus 1 year"
64+
ExpiresByType image/svg+xml "access plus 1 year"
65+
ExpiresByType image/x-icon "access plus 1 year"
66+
# Set expiration for video files to 1 year
67+
ExpiresByType video/webm "access plus 1 year"
68+
ExpiresByType video/mp4 "access plus 1 year"
69+
ExpiresByType video/mpeg "access plus 1 year"
70+
# Set expiration for font files to 1 year
71+
ExpiresByType font/ttf "access plus 1 year"
72+
ExpiresByType font/otf "access plus 1 year"
73+
ExpiresByType font/woff "access plus 1 year"
74+
ExpiresByType font/woff2 "access plus 1 year"
75+
ExpiresByType application/font-woff "access plus 1 year"
76+
ExpiresByType application/font-woff2 "access plus 1 year"
77+
# Set expiration for CSS and JavaScript files to 1 year
78+
ExpiresByType text/css "access plus 1 year"
79+
ExpiresByType text/javascript "access plus 1 year"
80+
ExpiresByType application/javascript "access plus 1 year"
81+
# Set expiration for other file types to 1 year
82+
ExpiresByType application/pdf "access plus 1 year"
83+
ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
9684
</IfModule>
97-
9885
# Enable Cache-Control headers to set caching policies for various file types
9986
<IfModule mod_headers.c>
100-
<FilesMatch "\.(flv|gif|ico|jpg|jpeg|mp4|mpeg|png|svg|swf|webp|webm|js|pdf|css|woff|woff2)$">
101-
Header set Cache-Control "max-age=31536000, public"
102-
</FilesMatch>
87+
<FilesMatch "\.(flv|gif|ico|jpg|jpeg|mp4|mpeg|png|svg|swf|webp|webm|js|pdf|css|woff|woff2)$">
88+
Header set Cache-Control "max-age=31536000, public"
89+
</FilesMatch>
10390
</IfModule>
104-
105-
10691
# Set mod_rewrite
10792
<IfModule mod_rewrite.c>
10893
# This has to be 'On'
10994
RewriteEngine On
110-
11195
<IfModule mod_fcgid.c>
11296
RewriteCond %{HTTP:Authorization} .
11397
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
11498
</IfModule>
115-
11699
# the path to your phpMyFAQ installation
117-
RewriteBase /
118-
100+
RewriteBase //localhost/phpmyfaq-test/./phpmyfaq/src/libs/bin/phpunit/
119101
# Error pages
120102
ErrorDocument 404 /index.php?action=404
121-
122103
# General pages
123104
RewriteRule add-faq.html$ index.php?action=add [L,QSA]
124105
RewriteRule add-question.html$ index.php?action=ask [L,QSA]
125106
RewriteRule show-categories.html$ index.php?action=show [L,QSA]
126107
RewriteRule ^(search|open-questions|contact|glossary|overview|login|privacy)\.html$ index.php?action=$1 [L,QSA]
127108
RewriteRule ^(login) index.php?action=login [L,QSA]
128-
129109
# start page
130110
RewriteRule ^index.html$ index.php [PT]
131-
132111
# a solution ID page
133112
RewriteCond %{REQUEST_URI} solution_id_([0-9]+)\.html$ [NC]
134113
RewriteRule ^solution_id_(.*)\.html$ index.php?solution_id=$1 [L,QSA]
135-
136114
# the bookmarks page
137115
RewriteRule ^bookmarks\.html$ index.php?action=bookmarks [L,QSA]
138-
139116
# phpMyFAQ faq record page
140117
RewriteRule ^content/([0-9]+)/([0-9]+)/([a-z\-]+)/(.+)\.htm(l?)$ index.php?action=faq&cat=$1&id=$2&artlang=$3 [L,QSA]
141-
142118
# phpMyFAQ category page with page count
143119
RewriteRule ^category/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$ index.php?action=show&cat=$1&seite=$2 [L,QSA]
144-
145120
# phpMyFAQ category page
146121
RewriteRule ^category/([0-9]+)/(.+)\.htm(l?)$ index.php?action=show&cat=$1 [L,QSA]
147-
148122
# phpMyFAQ news page
149123
RewriteRule ^news/([0-9]+)/([a-z\-]+)/(.+)\.htm(l?)$ index.php?action=news&newsid=$1&newslang=$2 [L,QSA]
150-
151124
# phpMyFAQ sitemap
152125
RewriteRule ^sitemap/([^\/]+)/([a-z\-]+)\.htm(l?)$ index.php?action=sitemap&letter=$1&lang=$2 [L,QSA]
153-
154126
# phpMyFAQ Google sitemap
155127
RewriteRule ^sitemap.xml$ sitemap.xml.php [L]
156128
RewriteRule ^sitemap.gz$ sitemap.xml.php?gz=1 [L]
157129
RewriteRule ^sitemap.xml.gz$ sitemap.xml.php?gz=1 [L]
158-
159130
# phpMyFAQ tags page with page count
160131
RewriteRule ^tags/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$ index.php?action=search&tagging_id=$1&seite=$2 [L,QSA]
161-
162132
# phpMyFAQ tags page
163133
RewriteRule ^tags/([0-9]+)/([^\/]+)\.htm(l?)$ index.php?action=search&tagging_id=$1 [L,QSA]
164-
165134
# Authentication services
166135
RewriteRule ^services/webauthn(.*) services/webauthn/index.php [L,QSA]
167-
168136
# User pages
169137
RewriteRule ^user/(ucp|bookmarks|request-removal|logout|register) index.php?action=$1 [L,QSA]
170-
171138
# Setup and update pages
172139
RewriteRule ^setup/(.*) setup/index.php [L,QSA]
173140
RewriteRule ^update/(.*) update/index.php [L,QSA]
174-
175141
# Administration API
176142
RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
177-
178143
# Private APIs
179144
RewriteRule ^api/(autocomplete|bookmark/delete|bookmark/create|user/data/update|user/password/update|user/request-removal|user/remove-twofactor|contact|voting|register|captcha|share|comment/create|faq/create|question/create|webauthn/prepare|webauthn/register|webauthn/prepare-login|webauthn/login) api/index.php [L,QSA]
180-
181145
# Setup APIs
182146
RewriteRule ^api/setup/(check|backup|update-database) api/index.php [L,QSA]
183-
184147
# REST API v3.0 and v3.1
185148
# * http://[...]/api/v3.x/<ACTION>
186149
RewriteRule ^api/v3\.[01]/(.*) api/index.php [L,QSA]
187-
188150
</IfModule>

phpmyfaq/assets/src/api/autocomplete.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { fetchAutoCompleteData } from './autocomplete';
2-
import fetchMock from 'jest-fetch-mock';
2+
import createFetchMock from 'vitest-fetch-mock';
33

4-
fetchMock.enableMocks();
4+
const fetchMocker = createFetchMock(vi);
5+
6+
fetchMocker.enableMocks();
57

68
describe('fetchAutoCompleteData', () => {
79
beforeEach(() => {
8-
fetch.resetMocks();
10+
fetchMocker.resetMocks();
911
});
1012

1113
it('should return autocomplete data when the response is successful', async () => {

phpmyfaq/assets/src/api/captcha.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ describe('fetchCaptchaImage function', () => {
66

77
beforeEach(() => {
88
// Mocking fetch function
9-
fetchMock = jest.fn();
9+
fetchMock = vi.fn();
1010
global.fetch = fetchMock;
1111

1212
// Mocking console.error
13-
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {});
13+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
1414
});
1515

1616
afterEach(() => {

phpmyfaq/assets/src/api/comment.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { serialize } from '../utils';
44
describe('createComment function', () => {
55
it('creates a comment successfully', async () => {
66
// Mocking fetch function
7-
global.fetch = jest.fn().mockResolvedValue({
7+
global.fetch = vi.fn().mockResolvedValue({
88
status: 200,
99
json: () => Promise.resolve({ message: 'Comment created successfully' }),
1010
});
@@ -31,7 +31,7 @@ describe('createComment function', () => {
3131

3232
it('throws an error if network response is not ok', async () => {
3333
// Mocking fetch function
34-
global.fetch = jest.fn().mockResolvedValue({
34+
global.fetch = vi.fn().mockResolvedValue({
3535
status: 400,
3636
json: () => Promise.resolve({ error: 'Something went wrong' }),
3737
});

phpmyfaq/assets/src/api/contact.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { serialize } from '../utils';
44
describe('send function', () => {
55
it('sends a message successfully', async () => {
66
// Mocking fetch function
7-
global.fetch = jest.fn().mockResolvedValue({
7+
global.fetch = vi.fn().mockResolvedValue({
88
status: 200,
99
json: () => Promise.resolve({ success: 'Contact message sent successfully' }),
1010
});
@@ -31,7 +31,7 @@ describe('send function', () => {
3131

3232
it('throws an error if network response is not ok', async () => {
3333
// Mocking fetch function
34-
global.fetch = jest.fn().mockResolvedValue({
34+
global.fetch = vi.fn().mockResolvedValue({
3535
status: 400,
3636
json: () => Promise.resolve({ error: 'Something went wrong' }),
3737
});

0 commit comments

Comments
 (0)