diff --git a/.chronus/changes/deprecate-old-testing-framework-2026-6-11.md b/.chronus/changes/deprecate-old-testing-framework-2026-6-11.md new file mode 100644 index 00000000000..fc5007c42a9 --- /dev/null +++ b/.chronus/changes/deprecate-old-testing-framework-2026-6-11.md @@ -0,0 +1,17 @@ +--- +changeKind: deprecation +packages: + - "@typespec/compiler" + - "@typespec/http" + - "@typespec/rest" + - "@typespec/versioning" + - "@typespec/json-schema" + - "@typespec/xml" + - "@typespec/events" + - "@typespec/sse" + - "@typespec/streams" + - "@typespec/html-program-viewer" + - "@typespec/library-linter" +--- + +Deprecate old testing framework (`createTestHost`, `createTestRunner`, `createTestWrapper`, `createTestLibrary`, `BasicTestRunner`, `TypeSpecTestLibrary`, etc.). Use `createTester` from `@typespec/compiler/testing` instead. diff --git a/packages/compiler/src/testing/test-host.ts b/packages/compiler/src/testing/test-host.ts index 68ec16f523a..7eac654bd30 100644 --- a/packages/compiler/src/testing/test-host.ts +++ b/packages/compiler/src/testing/test-host.ts @@ -11,7 +11,7 @@ import { addTestLib, StandardTestLibrary } from "./test-compiler-host.js"; import { createTestWrapper, resolveVirtualPath } from "./test-utils.js"; import { BasicTestRunner, TestHost, TestHostConfig, TypeSpecTestLibrary } from "./types.js"; -/** Use {@link createTester} */ +/** @deprecated Use {@link createTester} */ export async function createTestHost(config: TestHostConfig = {}): Promise { const testHost = await createTestHostInternal(); await testHost.addTypeSpecLibrary(StandardTestLibrary); @@ -23,7 +23,7 @@ export async function createTestHost(config: TestHostConfig = {}): Promise { const testHost = host ?? (await createTestHost()); return createTestWrapper(testHost); diff --git a/packages/compiler/src/testing/test-utils.ts b/packages/compiler/src/testing/test-utils.ts index 6b34d559b97..b6c10566147 100644 --- a/packages/compiler/src/testing/test-utils.ts +++ b/packages/compiler/src/testing/test-utils.ts @@ -21,7 +21,9 @@ export function resolveVirtualPath(path: string, ...paths: string[]) { return resolvePath(rootDir, path, ...paths); } -/** Find the package root from the provided file */ +/** Find the package root from the provided file + * @deprecated Use {@link createTester} instead + */ export function findTestPackageRoot(fileUrl: string): Promise { return findProjectRoot(NodeHost.stat, fileURLToPath(fileUrl)) as Promise; } @@ -29,6 +31,7 @@ export function findTestPackageRoot(fileUrl: string): Promise { * Define a test library defaulting to the most common library structure. * @param init Library configuration. * @returns TypeSpec Test library. + * @deprecated Use {@link createTester} instead */ export function createTestLibrary(init: TypeSpecTestLibraryInit): TypeSpecTestLibrary { const { name } = init; @@ -53,6 +56,7 @@ export function createTestLibrary(init: TypeSpecTestLibraryInit): TypeSpecTestLi }; } +/** @deprecated Use {@link Tester} instead */ export interface TestWrapperOptions { wrapper?: (code: string) => string; @@ -68,6 +72,7 @@ export interface TestWrapperOptions { compilerOptions?: CompilerOptions; } +/** @deprecated Use {@link createTester} instead */ export function createTestWrapper( host: TestHost, testWrapperOptions: TestWrapperOptions = {}, diff --git a/packages/compiler/src/testing/types.ts b/packages/compiler/src/testing/types.ts index 19e47db94f4..72bb9b7f5ce 100644 --- a/packages/compiler/src/testing/types.ts +++ b/packages/compiler/src/testing/types.ts @@ -220,6 +220,7 @@ export interface PositionedMarkerInFile extends PositionedMarker { // #endregion // #region Legacy Test host +/** @deprecated Use {@link Tester} */ export interface TestHost extends Pick< TestFileSystem, | "addTypeSpecFile" @@ -243,12 +244,14 @@ export interface TestHost extends Pick< ): Promise<[Record, readonly Diagnostic[]]>; } +/** @deprecated Use {@link Tester} */ export interface TestFiles { realDir: string; pattern: string; virtualPath: string; } +/** @deprecated Use {@link Tester} */ export interface TypeSpecTestLibraryInit { name: string; packageRoot: string; @@ -263,16 +266,19 @@ export interface TypeSpecTestLibraryInit { jsFileFolder?: string; } +/** @deprecated Use {@link Tester} */ export interface TypeSpecTestLibrary { name: string; packageRoot: string; files: TestFiles[]; } +/** @deprecated Use {@link Tester} */ export interface TestHostConfig { libraries?: TypeSpecTestLibrary[]; } +/** @deprecated Use {@link Tester} */ export class TestHostError extends Error { constructor( message: string, @@ -282,6 +288,7 @@ export class TestHostError extends Error { } } +/** @deprecated Use {@link TesterInstance} */ export interface BasicTestRunner { readonly program: Program; readonly fs: Map; diff --git a/packages/compiler/templates/__snapshots__/emitter-ts/src/testing/index.ts b/packages/compiler/templates/__snapshots__/emitter-ts/src/testing/index.ts deleted file mode 100644 index 2232aeb74fc..00000000000 --- a/packages/compiler/templates/__snapshots__/emitter-ts/src/testing/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { resolvePath } from "@typespec/compiler"; -import { createTestLibrary, TypeSpecTestLibrary } from "@typespec/compiler/testing"; -import { fileURLToPath } from "url"; - -export const EmitterTsTestLibrary: TypeSpecTestLibrary = createTestLibrary({ - name: "emitter-ts", - packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"), -}); diff --git a/packages/compiler/templates/__snapshots__/library-ts/src/testing/index.ts b/packages/compiler/templates/__snapshots__/library-ts/src/testing/index.ts deleted file mode 100644 index 98f124f62a8..00000000000 --- a/packages/compiler/templates/__snapshots__/library-ts/src/testing/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { resolvePath } from "@typespec/compiler"; -import { createTestLibrary, TypeSpecTestLibrary } from "@typespec/compiler/testing"; -import { fileURLToPath } from "url"; - -export const LibraryTsTestLibrary: TypeSpecTestLibrary = createTestLibrary({ - name: "library-ts", - packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"), -}); diff --git a/packages/compiler/templates/emitter-ts/src/testing/index.ts.mu b/packages/compiler/templates/emitter-ts/src/testing/index.ts.mu deleted file mode 100644 index cd1a7daa546..00000000000 --- a/packages/compiler/templates/emitter-ts/src/testing/index.ts.mu +++ /dev/null @@ -1,8 +0,0 @@ -import { resolvePath } from "@typespec/compiler"; -import { createTestLibrary, TypeSpecTestLibrary } from "@typespec/compiler/testing"; -import { fileURLToPath } from "url"; - -export const {{#casing.pascalCase}}{{name}}{{/casing.pascalCase}}TestLibrary: TypeSpecTestLibrary = createTestLibrary({ - name: "{{name}}", - packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"), -}); diff --git a/packages/compiler/templates/library-ts/src/testing/index.ts.mu b/packages/compiler/templates/library-ts/src/testing/index.ts.mu deleted file mode 100644 index cd1a7daa546..00000000000 --- a/packages/compiler/templates/library-ts/src/testing/index.ts.mu +++ /dev/null @@ -1,8 +0,0 @@ -import { resolvePath } from "@typespec/compiler"; -import { createTestLibrary, TypeSpecTestLibrary } from "@typespec/compiler/testing"; -import { fileURLToPath } from "url"; - -export const {{#casing.pascalCase}}{{name}}{{/casing.pascalCase}}TestLibrary: TypeSpecTestLibrary = createTestLibrary({ - name: "{{name}}", - packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"), -}); diff --git a/packages/compiler/templates/scaffolding.json b/packages/compiler/templates/scaffolding.json index 152f071f8f6..08823490a52 100644 --- a/packages/compiler/templates/scaffolding.json +++ b/packages/compiler/templates/scaffolding.json @@ -124,10 +124,6 @@ "path": "library-ts/src/rules/no-interfaces.rule.ts", "destination": "src/rules/no-interfaces.rule.ts" }, - { - "path": "library-ts/src/testing/index.ts.mu", - "destination": "src/testing/index.ts" - }, { "path": "library-ts/test/decorators.test.ts.mu", "destination": "test/decorators.test.ts" @@ -185,10 +181,6 @@ "path": "emitter-ts/src/lib.ts", "destination": "src/lib.ts" }, - { - "path": "emitter-ts/src/testing/index.ts.mu", - "destination": "src/testing/index.ts" - }, { "path": "emitter-ts/test/hello.test.ts", "destination": "test/hello.test.ts" diff --git a/packages/emitter-framework/src/testing/index.ts b/packages/emitter-framework/src/testing/index.ts index 36a7e71dff4..43822ba4096 100644 --- a/packages/emitter-framework/src/testing/index.ts +++ b/packages/emitter-framework/src/testing/index.ts @@ -2,6 +2,7 @@ import { resolvePath } from "@typespec/compiler"; import { createTestLibrary, type TypeSpecTestLibrary } from "@typespec/compiler/testing"; import { fileURLToPath } from "url"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const EmitterFrameworkTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/emitter-framework", packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../"), diff --git a/packages/events/src/testing/index.ts b/packages/events/src/testing/index.ts index 66ba1a1bc01..aaa31876d46 100644 --- a/packages/events/src/testing/index.ts +++ b/packages/events/src/testing/index.ts @@ -1,5 +1,6 @@ import { createTestLibrary, findTestPackageRoot } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const EventsTestLibrary = createTestLibrary({ name: "@typespec/events", packageRoot: await findTestPackageRoot(import.meta.url), diff --git a/packages/html-program-viewer/src/testing/index.ts b/packages/html-program-viewer/src/testing/index.ts index 3054fa4f14e..9e1d12d8a22 100644 --- a/packages/html-program-viewer/src/testing/index.ts +++ b/packages/html-program-viewer/src/testing/index.ts @@ -4,6 +4,7 @@ import { type TypeSpecTestLibrary, } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const ProgramViewerTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/html-program-viewer", jsFileFolder: "dist/emitter", diff --git a/packages/http-client-js/src/testing/index.ts b/packages/http-client-js/src/testing/index.ts index 5148a1bba17..a9a1fc2dcc9 100644 --- a/packages/http-client-js/src/testing/index.ts +++ b/packages/http-client-js/src/testing/index.ts @@ -2,6 +2,7 @@ import { resolvePath } from "@typespec/compiler"; import { createTestLibrary, TypeSpecTestLibrary } from "@typespec/compiler/testing"; import { fileURLToPath } from "url"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const HttpClientJavascriptEmitterTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/http-client-js", packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../"), diff --git a/packages/http-client/src/testing/index.ts b/packages/http-client/src/testing/index.ts index fca24204afe..8cdea7d5c7a 100644 --- a/packages/http-client/src/testing/index.ts +++ b/packages/http-client/src/testing/index.ts @@ -2,6 +2,7 @@ import { resolvePath } from "@typespec/compiler"; import { createTestLibrary, TypeSpecTestLibrary } from "@typespec/compiler/testing"; import { fileURLToPath } from "url"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const HttpClientTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/http-client", packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"), diff --git a/packages/http-server-js/src/testing/index.ts b/packages/http-server-js/src/testing/index.ts index 94286cbfc2d..72b647b9710 100644 --- a/packages/http-server-js/src/testing/index.ts +++ b/packages/http-server-js/src/testing/index.ts @@ -4,6 +4,7 @@ import { findTestPackageRoot, } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const HttpServerJavaScriptTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/http-server-js", packageRoot: await findTestPackageRoot(import.meta.url), diff --git a/packages/http/src/testing/index.ts b/packages/http/src/testing/index.ts index 9c1a1d327c7..75581119a16 100644 --- a/packages/http/src/testing/index.ts +++ b/packages/http/src/testing/index.ts @@ -4,6 +4,7 @@ import { TypeSpecTestLibrary, } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const HttpTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/http", packageRoot: await findTestPackageRoot(import.meta.url), diff --git a/packages/json-schema/src/testing/index.ts b/packages/json-schema/src/testing/index.ts index 78267d60957..ae5d09a50a2 100644 --- a/packages/json-schema/src/testing/index.ts +++ b/packages/json-schema/src/testing/index.ts @@ -4,6 +4,7 @@ import { type TypeSpecTestLibrary, } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const JsonSchemaTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/json-schema", packageRoot: await findTestPackageRoot(import.meta.url), diff --git a/packages/library-linter/src/testing/index.ts b/packages/library-linter/src/testing/index.ts index 15db03ddbda..a8f40118510 100644 --- a/packages/library-linter/src/testing/index.ts +++ b/packages/library-linter/src/testing/index.ts @@ -4,6 +4,7 @@ import { TypeSpecTestLibrary, } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const LibraryLinterTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/library-linter", packageRoot: await findTestPackageRoot(import.meta.url), diff --git a/packages/rest/src/testing/index.ts b/packages/rest/src/testing/index.ts index 07fc1e57e28..967c5bf782f 100644 --- a/packages/rest/src/testing/index.ts +++ b/packages/rest/src/testing/index.ts @@ -4,6 +4,7 @@ import { TypeSpecTestLibrary, } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const RestTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/rest", packageRoot: await findTestPackageRoot(import.meta.url), diff --git a/packages/sse/src/testing/index.ts b/packages/sse/src/testing/index.ts index aaced1410b3..4548bdc1fab 100644 --- a/packages/sse/src/testing/index.ts +++ b/packages/sse/src/testing/index.ts @@ -1,5 +1,6 @@ import { createTestLibrary, findTestPackageRoot } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const SSETestLibrary = createTestLibrary({ name: "@typespec/sse", packageRoot: await findTestPackageRoot(import.meta.url), diff --git a/packages/streams/src/testing/index.ts b/packages/streams/src/testing/index.ts index 1308ba5390f..21eab67545a 100644 --- a/packages/streams/src/testing/index.ts +++ b/packages/streams/src/testing/index.ts @@ -1,5 +1,6 @@ import { createTestLibrary, findTestPackageRoot } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const StreamsTestLibrary = createTestLibrary({ name: "@typespec/streams", packageRoot: await findTestPackageRoot(import.meta.url), diff --git a/packages/versioning/src/testing/index.ts b/packages/versioning/src/testing/index.ts index 75fe32643a6..7f598c91102 100644 --- a/packages/versioning/src/testing/index.ts +++ b/packages/versioning/src/testing/index.ts @@ -4,6 +4,7 @@ import { type TypeSpecTestLibrary, } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const VersioningTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/versioning", packageRoot: await findTestPackageRoot(import.meta.url), diff --git a/packages/xml/src/testing/index.ts b/packages/xml/src/testing/index.ts index 6f4e37bebb8..b96de17aacb 100644 --- a/packages/xml/src/testing/index.ts +++ b/packages/xml/src/testing/index.ts @@ -4,6 +4,7 @@ import { type TypeSpecTestLibrary, } from "@typespec/compiler/testing"; +/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */ export const XmlTestLibrary: TypeSpecTestLibrary = createTestLibrary({ name: "@typespec/xml", packageRoot: await findTestPackageRoot(import.meta.url),