Make Vitest helpers global

This commit is contained in:
Steve Kinney
2024-10-01 16:49:45 -05:00
parent 45f8282a05
commit 7f6b9ad691
19 changed files with 48 additions and 32 deletions

View File

@@ -6,4 +6,8 @@ import { css } from 'css-configuration';
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
css, css,
test: {
environment: 'happy-dom',
globals: true,
},
}); });

View File

@@ -1,8 +0,0 @@
import { mergeConfig } from 'vitest/config';
import config from './vite.config';
export default mergeConfig(config, {
test: {
environment: 'happy-dom',
},
});

View File

@@ -1,4 +1,3 @@
import { it, expect, describe } from 'vitest';
import { createButton } from './button.js'; import { createButton } from './button.js';
describe('createButton', () => { describe('createButton', () => {

View File

@@ -1,5 +1,3 @@
import { it, expect } from 'vitest';
it('should properly assign to localStorage', () => { it('should properly assign to localStorage', () => {
const key = 'secret'; const key = 'secret';
const message = "It's a secret to everybody."; const message = "It's a secret to everybody.";

View File

@@ -1,4 +1,3 @@
import { describe, expect, it, beforeEach, vi, afterEach } from 'vitest';
import { screen } from '@testing-library/dom'; import { screen } from '@testing-library/dom';
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import { createSecretInput } from './secret-input.js'; import { createSecretInput } from './secret-input.js';

View File

@@ -3,5 +3,6 @@ import { defineConfig } from 'vitest/config';
export default defineConfig({ export default defineConfig({
test: { test: {
environment: 'happy-dom', environment: 'happy-dom',
globals: true,
}, },
}); });

View File

@@ -4,4 +4,8 @@ import { css } from 'css-configuration';
export default defineConfig({ export default defineConfig({
assetsInclude: ['**/*.html'], assetsInclude: ['**/*.html'],
css, css,
test: {
environment: 'happy-dom',
globals: true,
},
}); });

View File

@@ -1,8 +0,0 @@
import { mergeConfig } from 'vitest/config';
import config from './vite.config';
export default mergeConfig(config, {
test: {
environment: 'happy-dom',
},
});

View File

@@ -1,5 +1,6 @@
export default { export default {
test: { test: {
environment: 'node', environment: 'node',
globals: true,
}, },
}; };

View File

@@ -1,5 +1,6 @@
export default { export default {
test: { test: {
environment: 'node', environment: 'node',
globals: true,
}, },
}; };

View File

@@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node',
globals: true,
},
});

View File

@@ -0,0 +1,11 @@
import { setTasks } from './actions';
describe('setTasks', () => {
it('creates a set-tasks action', () => {
const tasks = [{ id: '1', text: 'Task 1', completed: false }];
expect(setTasks(tasks)).toEqual({
type: 'set-tasks',
payload: tasks,
});
});
});

View File

@@ -15,7 +15,7 @@ export const CreateTask = ({ onSubmit }) => {
> >
<div> <div>
<label htmlFor="new-task-title" className="sr-only"> <label htmlFor="new-task-title" className="sr-only">
Title Create Task
</label> </label>
<div className="flex flex-row"> <div className="flex flex-row">
<input <input

View File

@@ -1,5 +1,4 @@
import { memo } from 'react'; import { memo } from 'react';
import { ChevronRightCircle } from 'lucide-react';
import { DateTime } from './date-time'; import { DateTime } from './date-time';
export const Task = memo(({ task, updateTask, removeTask }) => { export const Task = memo(({ task, updateTask, removeTask }) => {
@@ -7,7 +6,7 @@ export const Task = memo(({ task, updateTask, removeTask }) => {
<li className="block space-y-2 border-x border-t border-slate-300 bg-white p-4 first:rounded-t-md last:rounded-b-md last:border-b dark:border-slate-700"> <li className="block space-y-2 border-x border-t border-slate-300 bg-white p-4 first:rounded-t-md last:rounded-b-md last:border-b dark:border-slate-700">
<header className="flex flex-row items-center gap-4"> <header className="flex flex-row items-center gap-4">
<label htmlFor={`toggle-${task.id}`} className="sr-only"> <label htmlFor={`toggle-${task.id}`} className="sr-only">
Mark Task as {task.completed ? 'Incomplete' : 'Complete'} Completed?
</label> </label>
<input <input
id={`toggle-${task.id}`} id={`toggle-${task.id}`}
@@ -20,6 +19,7 @@ export const Task = memo(({ task, updateTask, removeTask }) => {
<button <button
className="button-small button-destructive button-ghost" className="button-small button-destructive button-ghost"
onClick={() => removeTask(task.id)} onClick={() => removeTask(task.id)}
aria-label='Remove Task'
> >
</button> </button>

View File

@@ -16,4 +16,9 @@ export default defineConfig({
}, },
}, },
}, },
test: {
environment: 'happy-dom',
globals: true,
setupFiles: ['@testing-library/jest-dom/vitest'],
},
}); });

View File

@@ -1,8 +0,0 @@
import { mergeConfig } from 'vite';
import config from './vite.config';
export default mergeConfig(config, {
test: {
environment: 'happy-dom',
},
});

View File

@@ -0,0 +1 @@
export * from './string-to-number';

View File

@@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node',
globals: true,
},
});

View File

@@ -11,6 +11,6 @@
"./*.html?raw": ["./*"] "./*.html?raw": ["./*"]
} }
}, },
"include": ["examples/**/*.js", "examples/accident-counter/src/reducer.ts"], "include": ["examples/**/*.js"],
"exclude": ["node_modules", "dist"] "exclude": ["node_modules", "dist"]
} }