Skip to content

Commit

Permalink
Add a few tests for invalid values
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongwartz committed Mar 2, 2024
1 parent 7ac0b2a commit df7855f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
File renamed without changes.
3 changes: 3 additions & 0 deletions e2e/only_primitives/missingRequired.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
amends "schema.pkl"

addr = "localhost"
4 changes: 4 additions & 0 deletions e2e/only_primitives/outOfBounds.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
amends "schema.pkl"

addr = "localhost"
port = 3000000000000
21 changes: 19 additions & 2 deletions e2e/only_primitives/primitives.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@ import pklGenTypescript from "../../pkl-gen-typescript/main";
import { join } from "path";

describe("E2E of config with only primitive values", () => {
it("can generate the TypeScript sources", async () => {
it("can generate TypeScript sources and load valid values", async () => {
await pklGenTypescript([join(__dirname, "schema.pkl")]);
const configPkl = await import(join(__dirname, "../../.out/schema.pkl.ts"));
const config = await configPkl.loadFromPath(join(__dirname, "values.pkl"));
const config = await configPkl.loadFromPath(join(__dirname, "correct.pkl"));
expect(config).toStrictEqual({
addr: "localhost",
port: 3000,
});
});

it.each([
["missing a required property", "missingRequired.pkl"],
["property is of the wrong type", "wrongType.pkl"],
["property fails validation constraint", "outOfBounds.pkl"],
])(
"can generate TypeScript sources but error on evaluating invalid values: %s",
async (_, fileBase) => {
await pklGenTypescript([join(__dirname, "schema.pkl")]);
const configPkl = await import(
join(__dirname, "../../.out/schema.pkl.ts")
);
await expect(
configPkl.loadFromPath(join(__dirname, `${fileBase}.pkl`))
).rejects.toThrowError();
}
);
});
4 changes: 4 additions & 0 deletions e2e/only_primitives/wrongType.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
amends "schema.pkl"

addr = "localhost"
port = "3000"

0 comments on commit df7855f

Please sign in to comment.