Skip to content

Commit 0f812d6

Browse files
committed
fix: js bin and add tests
1 parent 4a62cc0 commit 0f812d6

File tree

5 files changed

+82
-6
lines changed

5 files changed

+82
-6
lines changed

.github/workflows/pull_request.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,18 @@ jobs:
170170
- name: Run tests
171171
run: cargo test --workspace
172172

173-
test-js-bindings:
173+
test-js-packages:
174174
name:
175-
Test JS Bindings
175+
Test JS Packages
176176
# use the same image we use for compiling
177-
runs-on: ubuntu-22.04
177+
runs-on: ${{ matrix.os }}
178+
strategy:
179+
matrix:
180+
include:
181+
# use the same images we use for compiling
182+
- os: windows-2022
183+
- os: ubuntu-22.04
184+
- os: macos-14
178185
services:
179186
postgres:
180187
image: postgres:latest
@@ -201,12 +208,15 @@ jobs:
201208
uses: oven-sh/setup-bun@v2
202209
- name: Install JS dependencies
203210
run: bun install
204-
- name: Build TypeScript code
211+
- name: Build backend-jsonrpc
205212
working-directory: packages/@postgrestools/backend-jsonrpc
206213
run: bun run build
207-
- name: Run JS tests
214+
- name: Run backend-jsonrpc test
208215
working-directory: packages/@postgrestools/backend-jsonrpc
209216
run: bun run test
217+
- name: Run cli test
218+
working-directory: packages/@postgrestools/postgrestools
219+
run: bun run test
210220

211221
codegen:
212222
name: Check Codegen

packages/@postgrestools/postgrestools/bin/postgrestools

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function isMusl() {
3333
} catch (err) {
3434
stderr = err.stderr;
3535
}
36-
if (stderr.indexOf("musl") > -1) {
36+
if (stderr?.indexOf("musl") > -1) {
3737
return true;
3838
}
3939
return false;

packages/@postgrestools/postgrestools/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@
4040
"@postgrestools/cli-x86_64-linux-gnu": "<placeholder>",
4141
"@postgrestools/cli-aarch64-linux-gnu": "<placeholder>",
4242
"@postgrestools/cli-x86_64-linux-musl": "<placeholder>"
43+
},
44+
"scripts": {
45+
"test": "bun test"
4346
}
4447
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { describe, it, expect } from "bun:test";
2+
import { spawn } from "child_process";
3+
import { join, dirname } from "path";
4+
import { fileURLToPath } from "url";
5+
6+
const __dirname = dirname(fileURLToPath(import.meta.url));
7+
const binPath = join(__dirname, "../bin/postgrestools");
8+
const testSqlPath = join(__dirname, "test.sql");
9+
10+
describe("postgrestools bin", () => {
11+
12+
it("should check a SQL file successfully", async () => {
13+
const result = await new Promise((resolve) => {
14+
const proc = spawn("node", [binPath, "check", testSqlPath], {
15+
env: { ...process.env },
16+
});
17+
18+
let stdout = "";
19+
let stderr = "";
20+
21+
proc.stdout.on("data", (data) => {
22+
stdout += data.toString();
23+
});
24+
25+
proc.stderr.on("data", (data) => {
26+
stderr += data.toString();
27+
});
28+
29+
proc.on("close", (code) => {
30+
resolve({ code, stdout, stderr });
31+
});
32+
});
33+
34+
expect(result.code).toBe(0);
35+
expect(result.stderr).toBe("");
36+
});
37+
38+
it("should fail when file doesn't exist", async () => {
39+
const result = await new Promise((resolve) => {
40+
const proc = spawn("node", [binPath, "check", "nonexistent.sql"], {
41+
env: { ...process.env },
42+
});
43+
44+
let stdout = "";
45+
let stderr = "";
46+
47+
proc.stdout.on("data", (data) => {
48+
stdout += data.toString();
49+
});
50+
51+
proc.stderr.on("data", (data) => {
52+
stderr += data.toString();
53+
});
54+
55+
proc.on("close", (code) => {
56+
resolve({ code, stdout, stderr });
57+
});
58+
});
59+
60+
expect(result.code).not.toBe(0);
61+
});
62+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select 1;

0 commit comments

Comments
 (0)