|
1 | | -import { listServices } from "@typespec/compiler"; |
2 | 1 | import { expectDiagnostics, t } from "@typespec/compiler/testing"; |
3 | | -import { it } from "vitest"; |
4 | | -import { reportDiagnostic } from "../src/lib.js"; |
5 | | -import { Tester } from "./test-host.js"; |
| 2 | +import { expect } from "vitest"; |
| 3 | +import { EmitterTester } from "./test-host.js"; |
6 | 4 |
|
7 | 5 | it("targets the service namespace when no SDK clients are found", async () => { |
8 | | - const { program } = await Tester.compile(t.code` |
| 6 | + const [, diagnostics] = await EmitterTester.compileAndDiagnose(t.code` |
9 | 7 | #suppress "@typespec/http-client-python/no-sdk-clients" "This service intentionally has no client." |
10 | 8 | @service namespace ${t.namespace("Service")} {} |
11 | 9 | `); |
12 | 10 |
|
13 | | - reportDiagnostic(program, { |
14 | | - code: "no-sdk-clients", |
15 | | - target: listServices(program)[0]?.type ?? program.getGlobalNamespaceType(), |
16 | | - }); |
17 | | - expectDiagnostics(program.diagnostics, []); |
| 11 | + expectDiagnostics(diagnostics, []); |
18 | 12 | }); |
19 | 13 |
|
20 | | -it("allows suppressing the warning when no service exists", async () => { |
21 | | - const { program } = await Tester.compile(` |
| 14 | +it("generates models when no service exists", async () => { |
| 15 | + const [result, diagnostics] = await EmitterTester.compileAndDiagnose(` |
22 | 16 | #suppress "@typespec/http-client-python/no-sdk-clients" "This model-only package intentionally has no client." |
23 | | - model Widget {} |
| 17 | + namespace Models { |
| 18 | + model Widget {} |
| 19 | + } |
24 | 20 | `); |
25 | 21 |
|
26 | | - reportDiagnostic(program, { |
27 | | - code: "no-sdk-clients", |
28 | | - target: listServices(program)[0]?.type ?? program.getGlobalNamespaceType(), |
29 | | - }); |
30 | | - expectDiagnostics(program.diagnostics, []); |
| 22 | + expectDiagnostics(diagnostics, []); |
| 23 | + expect( |
| 24 | + Object.entries(result.outputs).some( |
| 25 | + ([path, content]) => path.endsWith("models/_models.py") && content.includes("class Widget"), |
| 26 | + ), |
| 27 | + ).toBe(true); |
31 | 28 | }); |
0 commit comments