Skip to content

Commit

Permalink
Adds running the puzzmo codebase inside the tests in order to figure …
Browse files Browse the repository at this point in the history
…out whats slow
  • Loading branch information
orta committed Sep 15, 2024
1 parent ae85283 commit 8cf50da
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
15 changes: 6 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export * from "./types.js"

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

import { makeStep } from "./utils.js"

export interface SDLCodeGenReturn {
// Optional way to start up a watcher mode for the codegen
createWatcher: () => { fileChanged: (path: string) => Promise<void> }
Expand All @@ -22,7 +24,10 @@ export interface SDLCodeGenReturn {
}

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

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

Expand Down Expand Up @@ -149,11 +154,3 @@ const isRedwoodServiceFile = (file: string) => {
if (file.endsWith("scenarios.ts") || file.endsWith("scenarios.js")) return false
return file.endsWith(".ts") || file.endsWith(".tsx") || file.endsWith(".js")
}

const makeStep = (verbose: boolean) => async (msg: string, fn: () => Promise<unknown> | Promise<void> | void) => {
if (!verbose) return fn()
console.log("[sdl-codegen] " + msg)
console.time("[sdl-codegen] " + msg)
await fn()
console.timeEnd("[sdl-codegen] " + msg)
}
8 changes: 6 additions & 2 deletions src/sharedSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import * as tsMorph from "ts-morph"
import { AppContext } from "./context.js"
import { formatDTS } from "./formatDTS.js"
import { typeMapper } from "./typeMap.js"
import { makeStep } from "./utils.js"

export const createSharedSchemaFiles = async (context: AppContext) => {
await createSharedExternalSchemaFile(context)
await createSharedReturnPositionSchemaFile(context)
const verbose = !!(context as { verbose?: true }).verbose
const step = makeStep(verbose)

await step("Creating shared schema files", () => createSharedExternalSchemaFile(context))
await step("Creating shared return position schema files", () => createSharedReturnPositionSchemaFile(context))

return [
context.join(context.pathSettings.typesFolderRoot, context.pathSettings.sharedFilename),
Expand Down
45 changes: 45 additions & 0 deletions src/tests/integration.puzzmo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { existsSync } from "node:fs"
import { join, resolve } from "node:path"

import { createSystem } from "@typescript/vfs"
import { describe, expect, it } from "vitest"

import { runFullCodegen } from "../index"

it("Passes", () => expect(true).toBe(true))

const hasAccessToPuzzmo = existsSync("../app/package.json")
const desc = hasAccessToPuzzmo ? describe : describe.skip

desc("Puzzmo", () => {
it("Runs the entire puzzmo codebase fast", async () => {
const puzzmoAPIWD = resolve(process.cwd() + "/..../../../app/apps/api.puzzmo.com")
const vfsMap = new Map<string, string>()
const vfs = createSystem(vfsMap)

// Replicates a Redwood project config object
const paths = {
base: puzzmoAPIWD,
api: {
base: puzzmoAPIWD,
config: "-",
dbSchema: join(puzzmoAPIWD, "prisma", "schema.prisma"),
directives: join(puzzmoAPIWD, "src", "directives"),
graphql: join(puzzmoAPIWD, "src", "functions", "graphql.ts"),
lib: join(puzzmoAPIWD, "src", "lib"),
models: "-",
services: join(puzzmoAPIWD, "src", "services"),
src: join(puzzmoAPIWD, "src"),
types: join(puzzmoAPIWD, "types"),
},
generated: {
schema: join(puzzmoAPIWD, "..", "..", "api-schema.graphql"),
},
web: {},
scripts: "-",
}

const results = await runFullCodegen("redwood", { paths, verbose: true, sys: vfs })
console.log(results)
})
})
8 changes: 8 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ export const createAndReferOrInlineArgsForField = (

return `${config.name}Args`
}

export const makeStep = (verbose: boolean) => async (msg: string, fn: () => Promise<unknown> | Promise<void> | void) => {

Check warning on line 60 in src/utils.ts

View workflow job for this annotation

GitHub Actions / lint

void is not valid as a constituent in a union type
if (!verbose) return fn()
console.log("[sdl-codegen] " + msg)
console.time("[sdl-codegen] " + msg)
await fn()
console.timeEnd("[sdl-codegen] " + msg)
}

0 comments on commit 8cf50da

Please sign in to comment.