mirror of
https://github.com/rajnandan1/kener.git
synced 2026-08-07 07:14:56 +00:00
test: use extends: true for Vitest projects, guard clipboard spy target
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { render } from "vitest-browser-svelte";
|
import { render } from "vitest-browser-svelte";
|
||||||
import CopyButton from "./CopyButton.svelte";
|
import CopyButton from "./CopyButton.svelte";
|
||||||
|
|
||||||
@@ -6,6 +6,17 @@ import CopyButton from "./CopyButton.svelte";
|
|||||||
// grant clipboard-read permission, and the component's contract is "calls
|
// grant clipboard-read permission, and the component's contract is "calls
|
||||||
// navigator.clipboard.writeText and flips to the copied state".
|
// navigator.clipboard.writeText and flips to the copied state".
|
||||||
describe("CopyButton", () => {
|
describe("CopyButton", () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
// navigator.clipboard only exists in secure contexts; provide a minimal
|
||||||
|
// stand-in when absent so the spies below always have a target.
|
||||||
|
if (!("clipboard" in navigator)) {
|
||||||
|
Object.defineProperty(navigator, "clipboard", {
|
||||||
|
value: { writeText: async () => {} },
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-2
@@ -62,7 +62,7 @@ export default defineConfig(({ mode }) => {
|
|||||||
test: {
|
test: {
|
||||||
projects: [
|
projects: [
|
||||||
{
|
{
|
||||||
extends: "./vite.config.ts",
|
extends: true,
|
||||||
test: {
|
test: {
|
||||||
name: "server",
|
name: "server",
|
||||||
environment: "node",
|
environment: "node",
|
||||||
@@ -71,7 +71,7 @@ export default defineConfig(({ mode }) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
extends: "./vite.config.ts",
|
extends: true,
|
||||||
// Pre-bundle the component-test dependency graph: on a cold Vite cache
|
// Pre-bundle the component-test dependency graph: on a cold Vite cache
|
||||||
// (every CI runner) a mid-run dep-optimization reload can flake the suite.
|
// (every CI runner) a mid-run dep-optimization reload can flake the suite.
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
|
|||||||
Reference in New Issue
Block a user