Make Vitest helpers global
This commit is contained in:
@@ -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,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
import { mergeConfig } from 'vitest/config';
|
|
||||||
import config from './vite.config';
|
|
||||||
|
|
||||||
export default mergeConfig(config, {
|
|
||||||
test: {
|
|
||||||
environment: 'happy-dom',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { it, expect, describe } from 'vitest';
|
|
||||||
import { createButton } from './button.js';
|
import { createButton } from './button.js';
|
||||||
|
|
||||||
describe('createButton', () => {
|
describe('createButton', () => {
|
||||||
|
|||||||
@@ -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.";
|
||||||
|
|||||||
@@ -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';
|
||||||
|
|||||||
@@ -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,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
import { mergeConfig } from 'vitest/config';
|
|
||||||
import config from './vite.config';
|
|
||||||
|
|
||||||
export default mergeConfig(config, {
|
|
||||||
test: {
|
|
||||||
environment: 'happy-dom',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
test: {
|
test: {
|
||||||
environment: 'node',
|
environment: 'node',
|
||||||
|
globals: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
test: {
|
test: {
|
||||||
environment: 'node',
|
environment: 'node',
|
||||||
|
globals: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
8
examples/logjam/vitest.config.js
Normal file
8
examples/logjam/vitest.config.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
environment: 'node',
|
||||||
|
globals: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
11
examples/task-list/src/actions.test.js
Normal file
11
examples/task-list/src/actions.test.js
Normal 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,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -16,4 +16,9 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
test: {
|
||||||
|
environment: 'happy-dom',
|
||||||
|
globals: true,
|
||||||
|
setupFiles: ['@testing-library/jest-dom/vitest'],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
import { mergeConfig } from 'vite';
|
|
||||||
import config from './vite.config';
|
|
||||||
|
|
||||||
export default mergeConfig(config, {
|
|
||||||
test: {
|
|
||||||
environment: 'happy-dom',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from './string-to-number';
|
||||||
|
|||||||
8
examples/utility-belt/vitest.config.js
Normal file
8
examples/utility-belt/vitest.config.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
environment: 'node',
|
||||||
|
globals: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -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"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user