|
| 1 | +import { join } from "path"; |
| 2 | +import { EmitAutorestRule } from "../src/rules/emit-autorest.js"; |
| 3 | +import { TsvTestHost } from "./tsv-test-host.js"; |
| 4 | +import { strict as assert } from "node:assert"; |
| 5 | + |
| 6 | +describe("emit-autorest", function () { |
| 7 | + it("should succeed if no main.tsp", async function () { |
| 8 | + let host = new TsvTestHost(); |
| 9 | + host.checkFileExists = async (file: string) => file != join(TsvTestHost.folder, "main.tsp"); |
| 10 | + |
| 11 | + const result = await new EmitAutorestRule().execute(host, TsvTestHost.folder); |
| 12 | + |
| 13 | + assert(result.success); |
| 14 | + }); |
| 15 | + |
| 16 | + it("should succeed if emits autorest", async function () { |
| 17 | + let host = new TsvTestHost(); |
| 18 | + host.readTspConfig = async (_folder: string) => ` |
| 19 | +emit: |
| 20 | + - "@azure-tools/typespec-autorest" |
| 21 | +`; |
| 22 | + |
| 23 | + const result = await new EmitAutorestRule().execute(host, TsvTestHost.folder); |
| 24 | + |
| 25 | + assert(result.success); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should fail if config is empty", async function () { |
| 29 | + let host = new TsvTestHost(); |
| 30 | + host.readTspConfig = async (_folder: string) => ""; |
| 31 | + |
| 32 | + const result = await new EmitAutorestRule().execute(host, TsvTestHost.folder); |
| 33 | + |
| 34 | + assert(!result.success); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should fail if no emit", async function () { |
| 38 | + let host = new TsvTestHost(); |
| 39 | + host.readTspConfig = async (_folder: string) => ` |
| 40 | +linter: |
| 41 | + extends: |
| 42 | + - "@azure-tools/typespec-azure-core/all" |
| 43 | +`; |
| 44 | + |
| 45 | + const result = await new EmitAutorestRule().execute(host, TsvTestHost.folder); |
| 46 | + |
| 47 | + assert(!result.success); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should fail if no emit autorest", async function () { |
| 51 | + let host = new TsvTestHost(); |
| 52 | + host.readTspConfig = async (_folder: string) => ` |
| 53 | +emit: |
| 54 | +- foo |
| 55 | +`; |
| 56 | + |
| 57 | + const result = await new EmitAutorestRule().execute(host, TsvTestHost.folder); |
| 58 | + |
| 59 | + assert(!result.success); |
| 60 | + }); |
| 61 | +}); |
0 commit comments