|
| 1 | +import { test } from "node:test"; |
| 2 | +import assert from "node:assert"; |
| 3 | +import { readFile } from "node:fs/promises"; |
| 4 | +import { fileURLToPath } from "node:url"; |
| 5 | +import { dirname, join } from "node:path"; |
| 6 | + |
| 7 | +const __filename = fileURLToPath(import.meta.url); |
| 8 | +const __dirname = dirname(__filename); |
| 9 | + |
| 10 | +// Mock fetch for Node.js to load local wasm file |
| 11 | +globalThis.fetch = async (url) => { |
| 12 | + const filePath = join(__dirname, url); |
| 13 | + const buffer = await readFile(filePath); |
| 14 | + return { |
| 15 | + arrayBuffer: async () => buffer.buffer, |
| 16 | + }; |
| 17 | +}; |
| 18 | + |
| 19 | +// Now import the modules |
| 20 | +const { sqldef } = await import("./sqldef.mjs"); |
| 21 | +const { schemaExamples } = await import("./schema_examples.mjs"); |
| 22 | + |
| 23 | +for (const [dbType, example] of Object.entries(schemaExamples)) { |
| 24 | + test(`sqldef returns non-empty string for ${dbType} (enableDrop=false)`, async () => { |
| 25 | + const result = await sqldef(dbType, example.desired, example.current, false); |
| 26 | + assert.strictEqual(typeof result, "string"); |
| 27 | + assert.ok(result.length > 0, `Result should be non-empty for ${dbType}`); |
| 28 | + }); |
| 29 | + |
| 30 | + test(`sqldef returns non-empty string for ${dbType} (enableDrop=true)`, async () => { |
| 31 | + const result = await sqldef(dbType, example.desired, example.current, true); |
| 32 | + assert.strictEqual(typeof result, "string"); |
| 33 | + assert.ok(result.length > 0, `Result should be non-empty for ${dbType}`); |
| 34 | + }); |
| 35 | +} |
0 commit comments