Skip to content

Commit

Permalink
Enabling vitest globals (#2027)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Sep 8, 2024
1 parent 975e379 commit 4245839
Show file tree
Hide file tree
Showing 48 changed files with 10 additions and 63 deletions.
2 changes: 1 addition & 1 deletion tests/bench/documentation.bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, describe, expect } from "vitest";
import { bench } from "vitest";
import { config } from "../../example/config";
import { routing } from "../../example/routing";
import { Documentation } from "../../src";
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/endpoint.bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, describe, expect } from "vitest";
import { bench } from "vitest";
import { retrieveUserEndpoint } from "../../example/endpoints/retrieve-user";
import { testEndpoint } from "../../src";

Expand Down
2 changes: 1 addition & 1 deletion tests/bench/experiment.bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, describe } from "vitest";
import { bench } from "vitest";
import { z } from "zod";
import { depictExamples } from "../../src/documentation-helpers";
import "../../src/zod-plugin";
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/integration.bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, describe, expect } from "vitest";
import { bench } from "vitest";
import { routing } from "../../example/routing";
import { Integration } from "../../src";

Expand Down
1 change: 0 additions & 1 deletion tests/cjs/quick-start.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { spawn } from "node:child_process";
import { afterAll, afterEach, describe, expect, test } from "vitest";

describe("CJS Test", async () => {
const { givePort, waitFor } = await import("../helpers.js");
Expand Down
1 change: 0 additions & 1 deletion tests/compat/migration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { describe, expect, test } from "vitest";
import { readFile } from "node:fs/promises";

describe("Migration", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/esm/quick-start.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { spawn } from "node:child_process";
import { givePort, waitFor } from "../helpers";
import { afterAll, afterEach, describe, expect, test } from "vitest";

describe("ESM Test", async () => {
let out = "";
Expand Down
3 changes: 1 addition & 2 deletions tests/express-mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @see https://github.com/swc-project/vi/issues/14#issuecomment-970189585
import { Mock, vi } from "vitest";
import type { Mock } from "vitest";

const expressJsonMock = vi.fn();
const expressRawMock = vi.fn();
Expand Down
2 changes: 1 addition & 1 deletion tests/http-mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import http from "node:http";
import https from "node:https";
import { MockInstance, vi } from "vitest";
import type { MockInstance } from "vitest";
import type { Application } from "express";

const realHttpCreator = http.createServer;
Expand Down
8 changes: 0 additions & 8 deletions tests/system/example.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ import {
import { givePort, waitFor } from "../helpers";
import { createHash } from "node:crypto";
import { readFile } from "node:fs/promises";
import {
afterAll,
afterEach,
describe,
expect,
expectTypeOf,
test,
} from "vitest";

describe("Example", async () => {
let out = "";
Expand Down
1 change: 0 additions & 1 deletion tests/system/system.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
ResultHandler,
} from "../../src";
import { givePort, waitFor } from "../helpers";
import { afterAll, describe, expect, test, vi } from "vitest";

describe("App", async () => {
const port = givePort();
Expand Down
9 changes: 0 additions & 9 deletions tests/unit/builtin-logger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import MockDate from "mockdate";
import { EventEmitter } from "node:events";
import {
afterAll,
beforeAll,
beforeEach,
describe,
expect,
test,
vi,
} from "vitest";
import { performance } from "node:perf_hooks";
import { BuiltinLogger, BuiltinLoggerConfig } from "../../src/builtin-logger";

Expand Down
1 change: 0 additions & 1 deletion tests/unit/checks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { UploadedFile } from "express-fileupload";
import { describe, expect, test, vi } from "vitest";
import { z } from "zod";
import { ez } from "../../src";
import { hasNestedSchema } from "../../src/deep-checks";
Expand Down
1 change: 0 additions & 1 deletion tests/unit/common-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from "../../src/common-helpers";
import { InputValidationError } from "../../src";
import { z } from "zod";
import { describe, expect, expectTypeOf, test } from "vitest";
import { makeRequestMock } from "../../src/testing";

describe("Common Helpers", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/config-type.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Express, IRouter } from "express";
import { createConfig } from "../../src";
import { describe, expect, test, vi } from "vitest";

describe("ConfigType", () => {
describe("createConfig()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/content-type.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { contentTypes } from "../../src/content-type";
import { describe, expect, test } from "vitest";

describe("contentTypes", () => {
test("should has predefined properties", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/date-in-schema.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { z } from "zod";
import { ezDateInBrand } from "../../src/date-in-schema";
import { ez } from "../../src";
import { describe, expect, test } from "vitest";
import { metaSymbol } from "../../src/metadata";

describe("ez.dateIn()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/date-out-schema.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { z } from "zod";
import { ezDateOutBrand } from "../../src/date-out-schema";
import { ez } from "../../src";
import { describe, expect, test } from "vitest";
import { metaSymbol } from "../../src/metadata";

describe("ez.dateOut()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/depends-on-method.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
EndpointsFactory,
defaultResultHandler,
} from "../../src";
import { describe, expect, test } from "vitest";
import { AbstractEndpoint } from "../../src/endpoint";

describe("DependsOnMethod", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/documentation-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import {
} from "../../src/documentation-helpers";
import { walkSchema } from "../../src/schema-walker";
import { serializeSchemaForTest } from "../helpers";
import { beforeEach, describe, expect, test, vi } from "vitest";

describe("Documentation helpers", () => {
const getRefMock = vi.fn();
Expand Down
1 change: 0 additions & 1 deletion tests/unit/documentation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { contentTypes } from "../../src/content-type";
import { z } from "zod";
import { givePort } from "../helpers";
import { describe, expect, expectTypeOf, test, vi } from "vitest";

describe("Documentation", () => {
const sampleConfig = createConfig({
Expand Down
1 change: 0 additions & 1 deletion tests/unit/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from "../../src";
import { AbstractEndpoint, Endpoint } from "../../src/endpoint";
import { serializeSchemaForTest } from "../helpers";
import { describe, expect, test, vi } from "vitest";

describe("Endpoint", () => {
describe(".getMethods()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/endpoints-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Endpoint } from "../../src/endpoint";
import { testMiddleware } from "../../src/testing";
import { serializeSchemaForTest } from "../helpers";
import { z } from "zod";
import { describe, expect, expectTypeOf, test, vi } from "vitest";

describe("EndpointsFactory", () => {
const resultHandlerMock = new ResultHandler({
Expand Down
1 change: 0 additions & 1 deletion tests/unit/errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
OutputValidationError,
ResultHandlerError,
} from "../../src/errors";
import { describe, expect, test } from "vitest";

describe("Errors", () => {
describe("RoutingError", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/file-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { z } from "zod";
import { ezFileBrand } from "../../src/file-schema";
import { ez } from "../../src";
import { readFile } from "node:fs/promises";
import { describe, expect, expectTypeOf, test } from "vitest";
import { metaSymbol } from "../../src/metadata";

describe("ez.file()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
Routing,
ServerConfig,
} from "../../src";
import { describe, expect, test, expectTypeOf } from "vitest";

describe("Index Entrypoint", () => {
describe("exports", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
defaultEndpointsFactory,
ResultHandler,
} from "../../src";
import { describe, expect, test, vi } from "vitest";

describe("Integration", () => {
test.each(["client", "types"] as const)(
Expand Down
1 change: 0 additions & 1 deletion tests/unit/io-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getFinalEndpointInputSchema } from "../../src/io-schema";
import { metaSymbol } from "../../src/metadata";
import { AbstractMiddleware } from "../../src/middleware";
import { serializeSchemaForTest } from "../helpers";
import { describe, expect, expectTypeOf, test, vi } from "vitest";

describe("I/O Schema and related helpers", () => {
describe("IOSchema", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/last-resort.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { describe, expect, test } from "vitest";
import { lastResortHandler } from "../../src/last-resort";
import { makeLoggerMock, makeResponseMock } from "../../src/testing";

Expand Down
1 change: 0 additions & 1 deletion tests/unit/logger-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
formatDuration,
isLoggerInstance,
} from "../../src/logger-helpers";
import { describe, expect, test } from "vitest";

describe("Logger helpers", () => {
describe("isLoggerInstance()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/logical-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
combineContainers,
mapLogicalContainer,
} from "../../src/logical-container";
import { describe, expect, test } from "vitest";

describe("LogicalContainer", () => {
describe("mapLogicalContainer()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/metadata.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "../../src/zod-plugin"; // required for this test
import { z } from "zod";
import { copyMeta, metaSymbol } from "../../src/metadata";
import { describe, expect, test } from "vitest";

describe("Metadata", () => {
describe("copyMeta()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/middleware.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { z } from "zod";
import { InputValidationError, Middleware } from "../../src";
import { describe, expect, test, vi } from "vitest";
import { AbstractMiddleware } from "../../src/middleware";
import {
makeLoggerMock,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/migration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { RuleTester } from "@typescript-eslint/rule-tester";
import migration from "../../src/migration";
import { describe, test, expect, afterAll, it } from "vitest";
import parser from "@typescript-eslint/parser";

RuleTester.afterAll = afterAll;
Expand Down
1 change: 0 additions & 1 deletion tests/unit/peer-helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MissingPeerError } from "../../src";
import { loadPeer } from "../../src/peer-helpers";
import { describe, expect, test } from "vitest";

describe("Peer loading helpers", () => {
describe("loadPeer()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/result-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from "../../src";
import { ResultHandlerError } from "../../src/errors";
import { metaSymbol } from "../../src/metadata";
import { describe, expect, expectTypeOf, test, vi } from "vitest";
import { AbstractResultHandler, Result } from "../../src/result-handler";
import {
makeLoggerMock,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/routing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
} from "../../src/testing";
import { initRouting } from "../../src/routing";
import type { IRouter, RequestHandler } from "express";
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";

describe("Routing", () => {
describe("initRouting()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/schema-helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { describe, expect, test } from "vitest";
import { isValidDate } from "../../src/schema-helpers";

describe("Schema helpers", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/serve-static.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ServeStatic } from "../../src";
import { describe, expect, test } from "vitest";

describe("ServeStatic", () => {
describe("constructor()", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/server-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
makeChildLoggerExtractor,
moveRaw,
} from "../../src/server-helpers";
import { describe, expect, test, vi } from "vitest";
import { defaultResultHandler, ResultHandler } from "../../src";
import { Request } from "express";
import assert from "node:assert/strict";
Expand Down
1 change: 0 additions & 1 deletion tests/unit/server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
ez,
} from "../../src";
import express from "express";
import { afterAll, describe, expect, test, vi } from "vitest";

describe("Server", () => {
afterAll(() => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/startup-logo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getStartupLogo } from "../../src/startup-logo";
import { describe, expect, test } from "vitest";

describe("Startup logo", () => {
describe("getStartupLogo()", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/testing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { defaultEndpointsFactory, Middleware, testEndpoint } from "../../src";
import { Mock, describe, expect, expectTypeOf, test, vi } from "vitest";
import type { Mock } from "vitest";
import { testMiddleware } from "../../src/testing";

describe("Testing", () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/upload-schema.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { z } from "zod";
import { ez } from "../../src";
import { describe, expect, test, vi } from "vitest";
import { metaSymbol } from "../../src/metadata";
import { ezUploadBrand } from "../../src/upload-schema";

Expand Down
1 change: 0 additions & 1 deletion tests/unit/zod-plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "../../src/zod-plugin"; // required for this test
import camelize from "camelize-ts";
import { describe, expect, test } from "vitest";
import { z } from "zod";
import { metaSymbol } from "../../src/metadata";

Expand Down
1 change: 0 additions & 1 deletion tests/unit/zts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { f } from "../../src/integration-helpers";
import { defaultSerializer } from "../../src/common-helpers";
import { zodToTs } from "../../src/zts";
import { ZTSContext, createTypeAlias, printNode } from "../../src/zts-helpers";
import { describe, expect, test, vi } from "vitest";

describe("zod-to-ts", () => {
const printNodeTest = (node: ts.Node) =>
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"noImplicitAny": true,
"noImplicitOverride": true,
"strictNullChecks": true
"strictNullChecks": true,
"types": ["vitest/globals"]
}
}
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineConfig({
env: {
FORCE_COLOR: "1",
},
globals: true,
pool: "threads",
testTimeout: 10000,
reporters: "basic",
Expand Down

0 comments on commit 4245839

Please sign in to comment.