Skip to content

Commit

Permalink
Wip trying to migrate from jest to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
ChqThomas committed Oct 18, 2023
1 parent 46d0b68 commit e9e16eb
Show file tree
Hide file tree
Showing 12 changed files with 833 additions and 19 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
],
"scripts": {
"build": "node bin/build_javascript.js && node bin/build_styles.js",
"test": "yarn workspaces run jest",
"test": "vitest src --run",
"test:vitest": "yarn workspaces run vitest --run",
"test:jest": "yarn workspaces run jest",
"lint": "yarn workspaces run eslint src test",
"format": "prettier src/*/assets/src/*.ts src/*/assets/test/*.js {,src/*/}*.{json,md} --write",
"check-lint": "yarn lint --no-fix",
Expand All @@ -31,7 +33,8 @@
"prettier": "^2.2.1",
"rollup": "^3.7.0",
"tslib": "^2.3.1",
"typescript": "^4.4.4"
"typescript": "^4.4.4",
"vitest": "^0.34.6"
},
"eslintConfig": {
"root": true,
Expand Down
10 changes: 5 additions & 5 deletions src/Notify/assets/test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ describe('NotifyController', () => {
afterEach(() => {
clearDOM();
application.stop();
jest.clearAllMocks();
vi.clearAllMocks();
});

const addEventListenerMock = jest.fn();
const removeEventListenerMock = jest.fn();
const closeMock = jest.fn();
const addEventListenerMock = vi.fn();
const removeEventListenerMock = vi.fn();
const closeMock = vi.fn();

global.EventSource = jest.fn().mockImplementation(() => {
global.EventSource = vi.fn().mockImplementation(() => {
return {
addEventListener: addEventListenerMock,
removeEventListener: removeEventListenerMock,
Expand Down
11 changes: 11 additions & 0 deletions src/React/assets/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// vitest.config.ts
import { defineConfig, mergeConfig } from 'vitest/config';
import react from "@vitejs/plugin-react";
import configShared from '../../../vitest.config.js'

export default mergeConfig(
configShared,
defineConfig({
plugins: [react()],
})
);
2 changes: 2 additions & 0 deletions src/Svelte/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "dist/register_controller.js",
"version": "1.0.0",
"license": "MIT",
"type": "module",
"symfony": {
"controllers": {
"svelte": {
Expand All @@ -25,6 +26,7 @@
},
"devDependencies": {
"@hotwired/stimulus": "^3.0.0",
"@sveltejs/vite-plugin-svelte": "^2.4.6",
"@types/webpack-env": "^1.16",
"svelte": "^3.0",
"svelte-jester": "^2.3"
Expand Down
11 changes: 11 additions & 0 deletions src/Svelte/assets/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// vitest.config.ts
import { defineConfig, mergeConfig } from 'vitest/config';
import { svelte } from "@sveltejs/vite-plugin-svelte";
import configShared from '../../../vitest.config.js'

export default mergeConfig(
configShared,
defineConfig({
plugins: [svelte()],
})
);
8 changes: 4 additions & 4 deletions src/Turbo/assets/test/turbo_stream_controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ describe('TurboStreamController', () => {
let container;

beforeEach(() => {
global.EventSource = jest.fn(() => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
close: jest.fn(),
global.EventSource = vi.fn(() => ({
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
close: vi.fn(),
}));

container = mountDOM(
Expand Down
1 change: 1 addition & 0 deletions src/Vue/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"devDependencies": {
"@hotwired/stimulus": "^3.0.0",
"@types/webpack-env": "^1.16",
"@vitejs/plugin-vue": "^4.4.0",
"@vue/vue3-jest": "^27.0.0",
"ts-jest": "^27.1.5",
"vue": "^3.0"
Expand Down
11 changes: 11 additions & 0 deletions src/Vue/assets/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// vitest.config.ts
import { defineConfig, mergeConfig } from 'vitest/config';
import vue from "@vitejs/plugin-vue";
import configShared from '../../../vitest.config.js'

export default mergeConfig(
configShared,
defineConfig({
plugins: [vue()],
})
);
13 changes: 13 additions & 0 deletions test/setup-vitest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

'use strict';

import '@symfony/stimulus-testing/setup';
import '@testing-library/jest-dom';
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"jsx": "react"
},
"exclude": ["src/*/assets/dist"],
"include": ["src/*/assets/src", "src/*/assets/test"]
"include": ["src/*/assets/src", "src/*/assets/test"],
"types": ["vite/client", "vitest/globals"]
}
14 changes: 14 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// vitest.config.ts
import { defineConfig } from 'vitest/config';
import path from 'path';

export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
setupFiles: [path.join(__dirname, 'test', 'setup-vitest.js')],
coverage: {
reporter: ['text', 'html'],
},
}
});
Loading

0 comments on commit e9e16eb

Please sign in to comment.