|
1 | 1 | import { build } from "esbuild"; |
| 2 | +import { mkdtemp, rm, writeFile } from "node:fs/promises"; |
2 | 3 | import { createRequire } from "node:module"; |
3 | | -import { dirname, resolve } from "node:path"; |
4 | | -import { fileURLToPath } from "node:url"; |
| 4 | +import { tmpdir } from "node:os"; |
| 5 | +import { dirname, join, resolve } from "node:path"; |
| 6 | +import { fileURLToPath, pathToFileURL } from "node:url"; |
5 | 7 | import { describe, expect, it } from "vitest"; |
6 | 8 |
|
7 | 9 | const require = createRequire(import.meta.url); |
@@ -80,16 +82,21 @@ describe("schema composition compatibility", () => { |
80 | 82 | ], |
81 | 83 | }); |
82 | 84 |
|
83 | | - const bundledModule = await import( |
84 | | - `data:text/javascript;base64,${Buffer.from(result.outputFiles[0]!.text).toString("base64")}` |
85 | | - ); |
| 85 | + const tempDir = await mkdtemp(join(tmpdir(), "schema-composition-")); |
| 86 | + try { |
| 87 | + const bundlePath = join(tempDir, "bundle.mjs"); |
| 88 | + await writeFile(bundlePath, result.outputFiles[0]!.text); |
| 89 | + const bundledModule = await import(pathToFileURL(bundlePath).href); |
86 | 90 |
|
87 | | - expect(bundledModule.parsed).toMatchObject({ |
88 | | - retry: { resetFormat: "unix_timestamp" }, |
89 | | - schedule: { window: "10%" }, |
90 | | - metadata: { id: "my-webhook" }, |
91 | | - resource: { id: "my-webhook" }, |
92 | | - }); |
| 91 | + expect(bundledModule.parsed).toMatchObject({ |
| 92 | + retry: { resetFormat: "unix_timestamp" }, |
| 93 | + schedule: { window: "10%" }, |
| 94 | + metadata: { id: "my-webhook" }, |
| 95 | + resource: { id: "my-webhook" }, |
| 96 | + }); |
| 97 | + } finally { |
| 98 | + await rm(tempDir, { recursive: true, force: true }); |
| 99 | + } |
93 | 100 | }); |
94 | 101 |
|
95 | 102 | it.each([ |
@@ -161,13 +168,18 @@ describe("schema composition compatibility", () => { |
161 | 168 | ], |
162 | 169 | }); |
163 | 170 |
|
164 | | - const bundledModule = await import( |
165 | | - `data:text/javascript;base64,${Buffer.from(result.outputFiles[0]!.text).toString("base64")}` |
166 | | - ); |
| 171 | + const tempDir = await mkdtemp(join(tmpdir(), "schema-composition-")); |
| 172 | + try { |
| 173 | + const bundlePath = join(tempDir, "bundle.mjs"); |
| 174 | + await writeFile(bundlePath, result.outputFiles[0]!.text); |
| 175 | + const bundledModule = await import(pathToFileURL(bundlePath).href); |
167 | 176 |
|
168 | | - expect(bundledModule.parsed).toMatchObject({ |
169 | | - dequeued: { run: { id: "run_1" }, snapshotRoute: { residency: "postgres" } }, |
170 | | - attemptStart: { isWarmStart: true, snapshotRoute: { residency: "postgres" } }, |
171 | | - }); |
| 177 | + expect(bundledModule.parsed).toMatchObject({ |
| 178 | + dequeued: { run: { id: "run_1" }, snapshotRoute: { residency: "postgres" } }, |
| 179 | + attemptStart: { isWarmStart: true, snapshotRoute: { residency: "postgres" } }, |
| 180 | + }); |
| 181 | + } finally { |
| 182 | + await rm(tempDir, { recursive: true, force: true }); |
| 183 | + } |
172 | 184 | }); |
173 | 185 | }); |
0 commit comments