From d8be18e2b1afa36432b9536c3b3fc7fc6598403e Mon Sep 17 00:00:00 2001 From: bcoll Date: Fri, 16 Feb 2024 16:44:51 +0000 Subject: [PATCH] Format with monorepo's `prettier` version --- .prettierignore | 5 ++++- packages/vitest-pool-workers/src/pool/config.ts | 2 +- packages/vitest-pool-workers/src/pool/index.ts | 8 ++++---- .../src/worker/durable-objects.ts | 2 +- .../vitest-pool-workers/src/worker/fetch-mock.ts | 2 +- .../src/worker/lib/cloudflare/test-runner.ts | 2 +- .../src/worker/lib/node/tty.ts | 2 +- .../test/basic/fake-timer.test.ts | 2 +- .../vitest-pool-workers/test/basic/maths.test.ts | 2 +- .../test/basic/mocking.test.ts | 2 +- .../test/basic/strings.test.ts | 2 +- .../vitest-pool-workers/test/kv/store.test.ts | 15 +++++++++------ packages/vitest-pool-workers/test/kv/worker.ts | 7 +++++-- .../test/stacked/stacked.test.ts | 2 +- 14 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.prettierignore b/.prettierignore index defbb49eb2bc..32dedb2fedaf 100644 --- a/.prettierignore +++ b/.prettierignore @@ -37,7 +37,10 @@ fixtures/**/dist/** # Miniflare shouldn't be formatted with the root `prettier` version packages/miniflare -packages/vitest-pool-workers + +# Generated Cap'n Proto files shouldn't be formatted +*.capnp.js +*.capnp.d.ts # In the C3 templates, in particular framework templates, we want to be able to # use any format that the framework authors prefer/use in their own templates, diff --git a/packages/vitest-pool-workers/src/pool/config.ts b/packages/vitest-pool-workers/src/pool/config.ts index 95fba4a9dcec..7bf8bd3fc097 100644 --- a/packages/vitest-pool-workers/src/pool/config.ts +++ b/packages/vitest-pool-workers/src/pool/config.ts @@ -6,11 +6,11 @@ import { PLUGINS, } from "miniflare"; import { z } from "zod"; +import { getProjectPath, getRelativeProjectPath } from "./helpers"; import type { WorkerOptions } from "miniflare"; import type { ProvidedContext } from "vitest"; import type { WorkspaceProject } from "vitest/node"; import type { ParseParams, ZodError } from "zod"; -import { getProjectPath, getRelativeProjectPath } from "./helpers"; const PLUGIN_VALUES = Object.values(PLUGINS); diff --git a/packages/vitest-pool-workers/src/pool/index.ts b/packages/vitest-pool-workers/src/pool/index.ts index 327c5635553f..84821286ac85 100644 --- a/packages/vitest-pool-workers/src/pool/index.ts +++ b/packages/vitest-pool-workers/src/pool/index.ts @@ -8,14 +8,14 @@ import util from "node:util"; import { createBirpc } from "birpc"; import * as devalue from "devalue"; import { + kCurrentWorker, + kUnsafeEphemeralUniqueKey, Log, LogLevel, Miniflare, structuredSerializableReducers, structuredSerializableRevivers, WebSocket, - kCurrentWorker, - kUnsafeEphemeralUniqueKey, } from "miniflare"; import { createMethodsRPC } from "vitest/node"; import { OPTIONS_PATH, parseProjectOptions } from "./config"; @@ -35,10 +35,10 @@ import { ensurePosixLikePath, handleModuleFallbackRequest, } from "./module-fallback"; -import type { WorkersPoolOptions, SourcelessWorkerOptions } from "./config"; +import type { SourcelessWorkerOptions, WorkersPoolOptions } from "./config"; import type { CloseEvent, MiniflareOptions, WorkerOptions } from "miniflare"; -import type { MessagePort } from "node:worker_threads"; import type { Readable } from "node:stream"; +import type { MessagePort } from "node:worker_threads"; import type { ResolvedConfig, RunnerRPC, diff --git a/packages/vitest-pool-workers/src/worker/durable-objects.ts b/packages/vitest-pool-workers/src/worker/durable-objects.ts index 80ea7804ddf0..100780f0b3f7 100644 --- a/packages/vitest-pool-workers/src/worker/durable-objects.ts +++ b/packages/vitest-pool-workers/src/worker/durable-objects.ts @@ -1,5 +1,5 @@ import assert from "node:assert"; -import { internalEnv, getSerializedOptions } from "./env"; +import { getSerializedOptions, internalEnv } from "./env"; import { importModule, mustGetResolvedMainPath } from "./import"; const CF_KEY_ACTION = "vitestPoolWorkersDurableObjectAction"; diff --git a/packages/vitest-pool-workers/src/worker/fetch-mock.ts b/packages/vitest-pool-workers/src/worker/fetch-mock.ts index 7b4d38b275b6..68a7bcd14c81 100644 --- a/packages/vitest-pool-workers/src/worker/fetch-mock.ts +++ b/packages/vitest-pool-workers/src/worker/fetch-mock.ts @@ -1,6 +1,6 @@ import assert from "node:assert"; import { Buffer } from "node:buffer"; -import { MockAgent, setDispatcher, isMockActive } from "cloudflare:mock-agent"; +import { isMockActive, MockAgent, setDispatcher } from "cloudflare:mock-agent"; import type { Dispatcher } from "undici"; // See public facing `cloudflare:test` types for docs diff --git a/packages/vitest-pool-workers/src/worker/lib/cloudflare/test-runner.ts b/packages/vitest-pool-workers/src/worker/lib/cloudflare/test-runner.ts index 64de32def0a9..ba6aa4784889 100644 --- a/packages/vitest-pool-workers/src/worker/lib/cloudflare/test-runner.ts +++ b/packages/vitest-pool-workers/src/worker/lib/cloudflare/test-runner.ts @@ -2,9 +2,9 @@ import assert from "node:assert"; import { NodeSnapshotEnvironment } from "@vitest/snapshot/environment"; import { resetMockAgent } from "cloudflare:mock-agent"; import { - internalEnv, fetchMock, getSerializedOptions, + internalEnv, } from "cloudflare:test-internal"; import { VitestTestRunner } from "vitest/runners"; import workerdUnsafe from "workerd:unsafe"; diff --git a/packages/vitest-pool-workers/src/worker/lib/node/tty.ts b/packages/vitest-pool-workers/src/worker/lib/node/tty.ts index aa04dff32977..abcbff3f7843 100644 --- a/packages/vitest-pool-workers/src/worker/lib/node/tty.ts +++ b/packages/vitest-pool-workers/src/worker/lib/node/tty.ts @@ -1,3 +1,3 @@ export function isatty() { - return false; + return false; } diff --git a/packages/vitest-pool-workers/test/basic/fake-timer.test.ts b/packages/vitest-pool-workers/test/basic/fake-timer.test.ts index 27d877e808c8..7d8c04246858 100644 --- a/packages/vitest-pool-workers/test/basic/fake-timer.test.ts +++ b/packages/vitest-pool-workers/test/basic/fake-timer.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; describe("fake timers", () => { beforeEach(() => { diff --git a/packages/vitest-pool-workers/test/basic/maths.test.ts b/packages/vitest-pool-workers/test/basic/maths.test.ts index a192638d880f..07e95c28b3d0 100644 --- a/packages/vitest-pool-workers/test/basic/maths.test.ts +++ b/packages/vitest-pool-workers/test/basic/maths.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, inject } from "vitest"; +import { describe, expect, inject, it } from "vitest"; describe("maths", () => { it("adds", () => { diff --git a/packages/vitest-pool-workers/test/basic/mocking.test.ts b/packages/vitest-pool-workers/test/basic/mocking.test.ts index 891c941b5376..d542ca0a6994 100644 --- a/packages/vitest-pool-workers/test/basic/mocking.test.ts +++ b/packages/vitest-pool-workers/test/basic/mocking.test.ts @@ -1,5 +1,5 @@ // import { fetch as undiciFetch } from "undici"; -import { describe, it, expect, afterEach, vi } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; afterEach(() => { vi.restoreAllMocks(); diff --git a/packages/vitest-pool-workers/test/basic/strings.test.ts b/packages/vitest-pool-workers/test/basic/strings.test.ts index 647a6ea9353c..36c825ba0914 100644 --- a/packages/vitest-pool-workers/test/basic/strings.test.ts +++ b/packages/vitest-pool-workers/test/basic/strings.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, expect, it } from "vitest"; describe("strings", () => { it("concatenates", () => { diff --git a/packages/vitest-pool-workers/test/kv/store.test.ts b/packages/vitest-pool-workers/test/kv/store.test.ts index 37a5152232ac..eb2fd2017ac8 100644 --- a/packages/vitest-pool-workers/test/kv/store.test.ts +++ b/packages/vitest-pool-workers/test/kv/store.test.ts @@ -1,15 +1,15 @@ import { + createExecutionContext, env, - SELF, fetchMock, - runInDurableObject, - runDurableObjectAlarm, listDurableObjectIds, - createExecutionContext, + runDurableObjectAlarm, + runInDurableObject, + SELF, waitOnExecutionContext, } from "cloudflare:test"; -import { describe, it, expect, afterAll, beforeAll } from "vitest"; -import worker, { transformResponse, Counter } from "./worker"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import worker, { Counter, transformResponse } from "./worker"; beforeAll(() => { fetchMock.activate(); @@ -112,6 +112,9 @@ describe("kv", () => { "http://localhost" ); const ctx = createExecutionContext(); + // @ts-expect-error `fetch()` is defined, but optional on `ExportedHandler`. + // The solution is to use `satisfies ExportedHandler` here instead, but + // we're stuck on an old TypeScript version until we bump to Prettier 3. const response = await worker.fetch(request, env, ctx); await waitOnExecutionContext(ctx); expect(await response.text()).toBe("body:http://localhost"); diff --git a/packages/vitest-pool-workers/test/kv/worker.ts b/packages/vitest-pool-workers/test/kv/worker.ts index a8844c00c03c..07f61bf1e45b 100644 --- a/packages/vitest-pool-workers/test/kv/worker.ts +++ b/packages/vitest-pool-workers/test/kv/worker.ts @@ -42,8 +42,11 @@ export function transformResponse(response: Response): Response { .transform(response); } -export default { +// TODO(soon): once we upgrade to TypeScript 5/Prettier 3, replace this with +// `satisfies ExportedHandler` so we don't need non-null assertions on +// the `fetch()` method +export default >{ async fetch(request, _env, _ctx) { return new Response(`body:${request.url}`); }, -} satisfies ExportedHandler; +}; diff --git a/packages/vitest-pool-workers/test/stacked/stacked.test.ts b/packages/vitest-pool-workers/test/stacked/stacked.test.ts index ab197f513ab5..88c031c9ddcc 100644 --- a/packages/vitest-pool-workers/test/stacked/stacked.test.ts +++ b/packages/vitest-pool-workers/test/stacked/stacked.test.ts @@ -1,5 +1,5 @@ import { env } from "cloudflare:test"; -import { describe, beforeAll, beforeEach, expect, test } from "vitest"; +import { beforeAll, beforeEach, describe, expect, test } from "vitest"; async function get() { return await env.TEST_NAMESPACE.get("thing");