Skip to content

Commit

Permalink
test(website): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-0acf4 committed Jan 22, 2024
1 parent a6fe331 commit b3086e8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
22 changes: 11 additions & 11 deletions typegate/tests/e2e/website/website_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// SPDX-License-Identifier: Elastic-2.0

import { expandGlob } from "std/fs/expand_glob.ts";
import { dirname, fromFileUrl } from "std/path/mod.ts";
import { dirname, fromFileUrl, join } from "std/path/mod.ts";
import { existsSync } from "std/fs/exists.ts";
import { copySync } from "std/fs/copy.ts";
import { Meta } from "../../utils/mod.ts";
import { MetaTest } from "../../utils/test.ts";
import { assertEquals } from "std/assert/assert_equals.ts";
Expand All @@ -12,8 +13,9 @@ import config from "../../../src/config.ts";
export const thisDir = dirname(fromFileUrl(import.meta.url));

async function testSerializeAllPairs(t: MetaTest, path: string) {
let success = 0;
let count = 0;
const tempDir = Deno.makeTempDirSync({
dir: config.tmp_dir,
});

for await (
const file of expandGlob(path, {
Expand All @@ -25,9 +27,12 @@ async function testSerializeAllPairs(t: MetaTest, path: string) {
const name = file.name.replace(/\.py$/, "");
const pyPath = file.path;
const tsPath = pyPath.replace(/\.py$/, ".ts");
const scriptDir = join(dirname(tsPath), "scripts");
if (!existsSync(scriptDir)) {
copySync(scriptDir, tempDir);
}

if (existsSync(tsPath)) {
count += 1;
const { stdout: pyVersion } = await Meta.cli(
"serialize",
"--pretty",
Expand All @@ -41,10 +46,8 @@ async function testSerializeAllPairs(t: MetaTest, path: string) {
/\(\s*g\s*\)/,
"(g: any)",
);
const tsTempPath = Deno.makeTempFileSync({
dir: config.tmp_dir,
suffix: ".ts",
});

const tsTempPath = join(tempDir, `${name}.ts`);
Deno.writeTextFileSync(tsTempPath, data);
const { stdout: tsVersion } = await Meta.cli(
"serialize",
Expand All @@ -57,13 +60,10 @@ async function testSerializeAllPairs(t: MetaTest, path: string) {
`serialize and compare python and typescript version of ${name})}`,
() => {
assertEquals(pyVersion, tsVersion);
success += 1;
},
);
}
}

console.log(`Comparison success ${success}/${count}`);
}

Meta.test("typegraphs creation", async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion website/typegraphs/backend-for-frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typegraph({
stargazers: github.get(
t.struct({}),
t.list(stargazer),
{ path: "/repos/metatypedev/metatype/stargazers?per_page:2" },
{ path: "/repos/metatypedev/metatype/stargazers?per_page=2" },
).withPolicy(pub),
});
});
2 changes: 1 addition & 1 deletion website/typegraphs/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typegraph({
maxAgeSec: 60,
},
}, (g) => {
const random = new RandomRuntime({ seed: 0 });
const random = new RandomRuntime({});
const pub = Policy.public();

g.expose({
Expand Down
3 changes: 2 additions & 1 deletion website/typegraphs/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ typegraph({
"body": t.string(),
},
// highlight-next-line
).rename("message");
{ name: "message" },
);

g.expose({
// highlight-next-line
Expand Down
2 changes: 1 addition & 1 deletion website/typegraphs/graphql-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typegraph({
stargazers: github.get(
t.struct({}),
t.list(stargazer),
{ path: "/repos/metatypedev/metatype/stargazers?per_page:2" },
{ path: "/repos/metatypedev/metatype/stargazers?per_page=2" },
),
}, pub);
});
2 changes: 1 addition & 1 deletion website/typegraphs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typegraph({
stargazers: github.get(
t.struct({}),
t.list(stargazer),
{ path: "/repos/metatypedev/metatype/stargazers?per_page:2" },
{ path: "/repos/metatypedev/metatype/stargazers?per_page=2" },
),
// automatically generate crud operations
send_feedback: db.create(feedback),
Expand Down

0 comments on commit b3086e8

Please sign in to comment.