Skip to content

Commit 8cf50da

Browse files
committed
Adds running the puzzmo codebase inside the tests in order to figure out whats slow
1 parent ae85283 commit 8cf50da

File tree

4 files changed

+65
-11
lines changed

4 files changed

+65
-11
lines changed

src/index.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export * from "./types.js"
1414

1515
import { basename, join } from "node:path"
1616

17+
import { makeStep } from "./utils.js"
18+
1719
export interface SDLCodeGenReturn {
1820
// Optional way to start up a watcher mode for the codegen
1921
createWatcher: () => { fileChanged: (path: string) => Promise<void> }
@@ -22,7 +24,10 @@ export interface SDLCodeGenReturn {
2224
}
2325

2426
/** The API specifically for the Redwood preset */
25-
export async function runFullCodegen(preset: "redwood", config: { paths: RedwoodPaths; verbose?: true }): Promise<SDLCodeGenReturn>
27+
export async function runFullCodegen(
28+
preset: "redwood",
29+
config: { paths: RedwoodPaths; sys?: typescript.System; verbose?: true }
30+
): Promise<SDLCodeGenReturn>
2631

2732
export async function runFullCodegen(preset: string, config: unknown): Promise<SDLCodeGenReturn>
2833

@@ -149,11 +154,3 @@ const isRedwoodServiceFile = (file: string) => {
149154
if (file.endsWith("scenarios.ts") || file.endsWith("scenarios.js")) return false
150155
return file.endsWith(".ts") || file.endsWith(".tsx") || file.endsWith(".js")
151156
}
152-
153-
const makeStep = (verbose: boolean) => async (msg: string, fn: () => Promise<unknown> | Promise<void> | void) => {
154-
if (!verbose) return fn()
155-
console.log("[sdl-codegen] " + msg)
156-
console.time("[sdl-codegen] " + msg)
157-
await fn()
158-
console.timeEnd("[sdl-codegen] " + msg)
159-
}

src/sharedSchema.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import * as tsMorph from "ts-morph"
66
import { AppContext } from "./context.js"
77
import { formatDTS } from "./formatDTS.js"
88
import { typeMapper } from "./typeMap.js"
9+
import { makeStep } from "./utils.js"
910

1011
export const createSharedSchemaFiles = async (context: AppContext) => {
11-
await createSharedExternalSchemaFile(context)
12-
await createSharedReturnPositionSchemaFile(context)
12+
const verbose = !!(context as { verbose?: true }).verbose
13+
const step = makeStep(verbose)
14+
15+
await step("Creating shared schema files", () => createSharedExternalSchemaFile(context))
16+
await step("Creating shared return position schema files", () => createSharedReturnPositionSchemaFile(context))
1317

1418
return [
1519
context.join(context.pathSettings.typesFolderRoot, context.pathSettings.sharedFilename),

src/tests/integration.puzzmo.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { existsSync } from "node:fs"
2+
import { join, resolve } from "node:path"
3+
4+
import { createSystem } from "@typescript/vfs"
5+
import { describe, expect, it } from "vitest"
6+
7+
import { runFullCodegen } from "../index"
8+
9+
it("Passes", () => expect(true).toBe(true))
10+
11+
const hasAccessToPuzzmo = existsSync("../app/package.json")
12+
const desc = hasAccessToPuzzmo ? describe : describe.skip
13+
14+
desc("Puzzmo", () => {
15+
it("Runs the entire puzzmo codebase fast", async () => {
16+
const puzzmoAPIWD = resolve(process.cwd() + "/..../../../app/apps/api.puzzmo.com")
17+
const vfsMap = new Map<string, string>()
18+
const vfs = createSystem(vfsMap)
19+
20+
// Replicates a Redwood project config object
21+
const paths = {
22+
base: puzzmoAPIWD,
23+
api: {
24+
base: puzzmoAPIWD,
25+
config: "-",
26+
dbSchema: join(puzzmoAPIWD, "prisma", "schema.prisma"),
27+
directives: join(puzzmoAPIWD, "src", "directives"),
28+
graphql: join(puzzmoAPIWD, "src", "functions", "graphql.ts"),
29+
lib: join(puzzmoAPIWD, "src", "lib"),
30+
models: "-",
31+
services: join(puzzmoAPIWD, "src", "services"),
32+
src: join(puzzmoAPIWD, "src"),
33+
types: join(puzzmoAPIWD, "types"),
34+
},
35+
generated: {
36+
schema: join(puzzmoAPIWD, "..", "..", "api-schema.graphql"),
37+
},
38+
web: {},
39+
scripts: "-",
40+
}
41+
42+
const results = await runFullCodegen("redwood", { paths, verbose: true, sys: vfs })
43+
console.log(results)
44+
})
45+
})

src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@ export const createAndReferOrInlineArgsForField = (
5656

5757
return `${config.name}Args`
5858
}
59+
60+
export const makeStep = (verbose: boolean) => async (msg: string, fn: () => Promise<unknown> | Promise<void> | void) => {
61+
if (!verbose) return fn()
62+
console.log("[sdl-codegen] " + msg)
63+
console.time("[sdl-codegen] " + msg)
64+
await fn()
65+
console.timeEnd("[sdl-codegen] " + msg)
66+
}

0 commit comments

Comments
 (0)