Skip to content

Commit

Permalink
Make sure to run all tests (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzyl committed Feb 8, 2024
1 parent bcc9be9 commit 6cf99ac
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 23 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dev:transpile": "tsup --watch",
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
"test": "vitest run",
"test:watch": "vitest",
"transpile": "tsup",
"transpileWatch": "tsup --watch",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const CONFIG_FILE_SCHEMA: JSONSchemaType<FoundryConfig> = {
oneOf: [
{
properties: {
"type": { enum: ["git-describe"], type: "string" },
"type": { const: "git-describe", type: "string" },
"tagPrefix": { type: "string", nullable: true },
},
},
Expand Down
22 changes: 14 additions & 8 deletions packages/cli/src/util/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,25 @@ describe("loadToken", () => {
validToken,
);
const token = await loadToken(undefined, "valid-token.txt");

expect(token).toBe(validToken);
});

it("should load a valid token from an environment variable", async () => {
it("should load a valid token from the FOUNDRY_TOKEN environment variable", async () => {
vi.stubEnv("FOUNDRY_TOKEN", validToken);
vi.stubEnv("FOUNDRY_SDK_AUTH_TOKEN", "");
expect(await loadToken()).toBe(validToken);
});

const token = await loadToken();
expect(token).toBe(validToken);
it("should load a valid token from the deprecated FOUNDRY_SDK_AUTH_TOKEN environment variable", async () => {
vi.stubEnv("FOUNDRY_TOKEN", "");
vi.stubEnv("FOUNDRY_SDK_AUTH_TOKEN", validToken);
expect(await loadToken()).toBe(validToken);
});

it("should throw an error if no token is found", async () => {
expect(() => loadToken()).rejects.toThrow("No token found.");
vi.stubEnv("FOUNDRY_TOKEN", "");
vi.stubEnv("FOUNDRY_SDK_AUTH_TOKEN", "");
await expect(() => loadToken()).rejects.toThrow("No token found.");
});

afterEach(() => {
Expand All @@ -56,9 +62,9 @@ describe("loadToken", () => {
});
});

describe("loadTokenFile", async () => {
it("should throw an error if the token file is not found", () => {
expect(() => loadTokenFile("doesnt-exist.txt"))
describe("loadTokenFile", () => {
it("should throw an error if the token file is not found", async () => {
await expect(() => loadTokenFile("doesnt-exist.txt"))
.rejects.toThrow(`Unable to read token file "doesnt-exist.txt"`);
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/gateway-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"dev:transpile": "tsup --watch",
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
"test": "vitest run",
"test:watch": "vitest",
"transpile": "tsup",
"transpileWatch": "tsup --watch",
"typecheck": "tsc-absolute --build"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { Project } from "ts-morph";
import { describe, expect, it } from "vitest";
import { generateComponent } from "../component";
import { generateComponent } from "./component";

describe("Components", () => {
it("generates a component", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { Project } from "ts-morph";
import { describe, expect, it } from "vitest";
import { generateError } from "../error";
import { generateError } from "./error";

describe("Errors", () => {
it("should generate an error interface", () => {
Expand Down Expand Up @@ -47,8 +47,8 @@ describe("Errors", () => {
const sourceFile = project.getSourceFile("errors/MyError.ts");
expect(sourceFile?.getFullText()).toMatchInlineSnapshot(`
"export interface MyError {
errorCode: \\"ERROR_TYPE\\";
errorName: \\"MyError\\";
errorCode: "ERROR_TYPE";
errorName: "MyError";
errorInstanceId: string;
parameters: {
param1: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import { Project } from "ts-morph";
import { describe, expect, it } from "vitest";
import type { Namespace } from "../../spec";
import { generateNamespace } from "../namespace";
import type { Namespace } from "../spec";
import { generateNamespace } from "./namespace";

describe("Namespace", () => {
it("Generates a resource static method on a namespace correctly", () => {
Expand Down Expand Up @@ -119,9 +119,9 @@ describe("Namespace", () => {
const sourceFiles = project.getSourceFiles();
const sourceFile = project.getSourceFile("namespaces/Datasets.ts");
expect(sourceFile?.getFullText()).toMatchInlineSnapshot(`
"import type { CreateDatasetRequest } from \\"../components/CreateDatasetRequest\\";
import type { Dataset } from \\"../components/Dataset\\";
import { OpenApiRequest } from \\"../request\\";
"import type { CreateDatasetRequest } from "../components/CreateDatasetRequest";
import type { Dataset } from "../components/Dataset";
import { OpenApiRequest } from "../request";
/**
* Creates a new Dataset. A default branch - \`master\` for most enrollments - will be created on the Dataset.
Expand All @@ -131,16 +131,16 @@ describe("Namespace", () => {
*/
export function createDataset<TResponse>(_request: OpenApiRequest<Dataset, TResponse>, request: CreateDatasetRequest): Promise<TResponse> {
return _request(
\\"POST\\",
"POST",
\`/v1/datasets\`,
request,
__undefined,
__undefined,
);
}
const __anyMediaType: string = \\"*/*\\";
const __applicationJson: string = \\"application/json\\";
const __anyMediaType: string = "*/*";
const __applicationJson: string = "application/json";
/** Constant reference to \`undefined\` that we expect to get minified and therefore reduce total code size */
const __undefined: undefined = undefined;
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import { beforeEach, describe, expect, it } from "vitest";
import type { DataType } from "../../spec";
import { generateType } from "../types";
import type { DataType } from "../spec";
import { generateType } from "./types";

describe("generateTypes", () => {
let referenceSet: Set<string>;
Expand Down

0 comments on commit 6cf99ac

Please sign in to comment.