diff --git a/.github/workflows/node-snapshot.yml b/.github/workflows/node-snapshot.yml new file mode 100644 index 00000000..606b1985 --- /dev/null +++ b/.github/workflows/node-snapshot.yml @@ -0,0 +1,28 @@ +name: Node Snapshot Test + +on: + pull_request: + push: + branches: [main] + +jobs: + node-snapshot: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Setup bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + - name: Install dependencies + run: bun install + - name: Build and install tsci + run: | + bun run build + npm install -g . + - name: Run Node snapshot smoke test + run: node scripts/node-snapshot-test.js diff --git a/scripts/node-snapshot-test.js b/scripts/node-snapshot-test.js new file mode 100644 index 00000000..22c59cff --- /dev/null +++ b/scripts/node-snapshot-test.js @@ -0,0 +1,38 @@ +import { mkdtempSync, writeFileSync, existsSync } from "fs" +import { tmpdir } from "os" +import { join } from "path" +import { spawnSync } from "child_process" + +const tmpDir = mkdtempSync(join(tmpdir(), "tsci-node-")) +writeFileSync( + join(tmpDir, "test.board.tsx"), + `export const TestBoard = () => ( + + + + )`, +) + +const result = spawnSync("tsci", ["snapshot", "--update", "--3d"], { + cwd: tmpDir, + encoding: "utf8", +}) +console.log(result.stdout) +console.error(result.stderr) + +if (result.status !== 0) { + console.error("tsci snapshot failed") + process.exit(result.status || 1) +} + +const snapDir = join(tmpDir, "__snapshots__") +const pcbExists = existsSync(join(snapDir, "test.board-pcb.snap.svg")) +const schExists = existsSync(join(snapDir, "test.board-schematic.snap.svg")) +const threeExists = existsSync(join(snapDir, "test.board-3d.snap.svg")) + +if (!pcbExists || !schExists || !threeExists) { + console.error("Snapshots were not created as expected") + process.exit(1) +} + +console.log("Node snapshot smoke test passed")