Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ jobs:

test-js-bindings:
name:
Test JS Bindings
Test JS Packages
# use the same image we use for compiling
runs-on: ubuntu-22.04
services:
Expand Down Expand Up @@ -201,12 +201,15 @@ jobs:
uses: oven-sh/setup-bun@v2
- name: Install JS dependencies
run: bun install
- name: Build TypeScript code
- name: Build backend-jsonrpc
working-directory: packages/@postgrestools/backend-jsonrpc
run: bun run build
- name: Run JS tests
- name: Run backend-jsonrpc test
working-directory: packages/@postgrestools/backend-jsonrpc
run: bun run test
- name: Run cli test
working-directory: packages/@postgrestools/postgrestools
run: bun run test

codegen:
name: Check Codegen
Expand Down
8 changes: 4 additions & 4 deletions packages/@postgrestools/postgrestools/bin/postgrestools
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ const PLATFORMS = {
};

function isMusl() {
let stderr;
let stdout;
try {
stderr = execSync("ldd --version", {
stdout = execSync("ldd --version", {
stdio: [
"ignore", // stdin
"pipe", // stdout – glibc systems print here
"pipe", // stderr – musl systems print here
],
});
} catch (err) {
stderr = err.stderr;
stdout = err.stderr;
}
if (stderr.indexOf("musl") > -1) {
if (typeof stdout === 'string' && stdout.indexOf("musl") > -1) {
return true;
}
return false;
Expand Down
3 changes: 3 additions & 0 deletions packages/@postgrestools/postgrestools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
"@postgrestools/cli-x86_64-linux-gnu": "<placeholder>",
"@postgrestools/cli-aarch64-linux-gnu": "<placeholder>",
"@postgrestools/cli-x86_64-linux-musl": "<placeholder>"
},
"scripts": {
"test": "bun test"
}
}
62 changes: 62 additions & 0 deletions packages/@postgrestools/postgrestools/test/bin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { describe, it, expect } from "bun:test";
import { spawn } from "child_process";
import { join, dirname } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const binPath = join(__dirname, "../bin/postgrestools");
const testSqlPath = join(__dirname, "test.sql");

describe("postgrestools bin", () => {

it("should check a SQL file successfully", async () => {
const result = await new Promise((resolve) => {
const proc = spawn("node", [binPath, "check", testSqlPath], {
env: { ...process.env },
});

let stdout = "";
let stderr = "";

proc.stdout.on("data", (data) => {
stdout += data.toString();
});

proc.stderr.on("data", (data) => {
stderr += data.toString();
});

proc.on("close", (code) => {
resolve({ code, stdout, stderr });
});
});

expect(result.code).toBe(0);
expect(result.stderr).toBe("");
});

it("should fail when file doesn't exist", async () => {
const result = await new Promise((resolve) => {
const proc = spawn("node", [binPath, "check", "nonexistent.sql"], {
env: { ...process.env },
});

let stdout = "";
let stderr = "";

proc.stdout.on("data", (data) => {
stdout += data.toString();
});

proc.stderr.on("data", (data) => {
stderr += data.toString();
});

proc.on("close", (code) => {
resolve({ code, stdout, stderr });
});
});

expect(result.code).not.toBe(0);
});
});
1 change: 1 addition & 0 deletions packages/@postgrestools/postgrestools/test/test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1;