Setup a sample test [CI SKIP]

Clément FRÉVILLE 2 years ago
parent a8bd40b10b
commit 8d3db4fb67

@ -3,6 +3,9 @@ module.exports = {
ecmaVersion: 2021, ecmaVersion: 2021,
sourceType: 'module' sourceType: 'module'
}, },
env: {
browser: true,
},
plugins: [ plugins: [
'react', 'react',
'react-hooks' 'react-hooks'
@ -13,6 +16,9 @@ module.exports = {
'plugin:react/jsx-runtime', 'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended' 'plugin:react-hooks/recommended'
], ],
rules: {
'react/no-unescaped-entities': 0
},
settings: { settings: {
react: { react: {
version: 'detect' version: 'detect'

@ -15,6 +15,7 @@ Une fois le dépôt cloné :
npm install # Installe les dépendances npm install # Installe les dépendances
npm run build # Construit l'application npm run build # Construit l'application
npm run dev # Démarre le serveur de développement npm run dev # Démarre le serveur de développement
npm run test # Lance les tests
``` ```
## Contribuer ## Contribuer

@ -28,5 +28,8 @@
"test": "vitest", "test": "vitest",
"dev": "vite", "dev": "vite",
"lint": "eslint src/**/*.{js,jsx}" "lint": "eslint src/**/*.{js,jsx}"
},
"devDependencies": {
"jsdom": "^21.1.0"
} }
} }

@ -1,8 +0,0 @@
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

@ -1,4 +1,3 @@
import React from 'react'
import '../../css/login.css' import '../../css/login.css'
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";

@ -1,4 +1,3 @@
import React from 'react'
import '../../css/main.css' import '../../css/main.css'
export function MainPage() { export function MainPage() {

@ -1,4 +1,3 @@
import React from 'react'
import '../../css/login.css' import '../../css/login.css'
import { library } from '@fortawesome/fontawesome-svg-core'; import { library } from '@fortawesome/fontawesome-svg-core';

@ -0,0 +1,12 @@
import { render } from '@testing-library/react';
import { describe, test, expect } from 'vitest';
const App = () => <div>learn react</div>
describe('Application', function () {
test('renders learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
});

@ -0,0 +1 @@
import '@testing-library/jest-dom'

@ -6,7 +6,7 @@ import fs from 'fs/promises';
export default defineConfig({ export default defineConfig({
esbuild: { esbuild: {
loader: "jsx", loader: "jsx",
include: /src\/.*\.jsx?$/, include: /(src|test)\/.*\.jsx?$/,
exclude: [], exclude: [],
}, },
build: { build: {
@ -15,19 +15,18 @@ export default defineConfig({
test: { test: {
globals: true, globals: true,
environment: 'jsdom', environment: 'jsdom',
setupFiles: './test/setupTests.js'
}, },
plugins: [react({ plugins: [react()],
loader: { '.js': 'jsx' },
})],
optimizeDeps: { optimizeDeps: {
esbuildOptions: { esbuildOptions: {
plugins: [ plugins: [
{ {
name: "load-js-files-as-jsx", name: 'load-js-files-as-jsx',
setup(build) { setup(build) {
build.onLoad({ filter: /src\/.*\.js$/ }, async (args) => ({ build.onLoad({ filter: /(src|test)\/.*\.js$/ }, async (args) => ({
loader: "jsx", loader: 'jsx',
contents: await fs.readFile(args.path, "utf8"), contents: await fs.readFile(args.path, 'utf8'),
})); }));
}, },
}, },

Loading…
Cancel
Save