Skip to content

Commit

Permalink
improve test fail log
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed Apr 25, 2024
1 parent a2983bf commit be19fba
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 21 deletions.
5 changes: 3 additions & 2 deletions lib/SchemaWatch/SchemaWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { OnSchemaChangeCallback } from "../Prostgles";
import { PubSubManager, log } from "../PubSubManager/PubSubManager";
import { ValidatedWatchSchemaType, getValidatedWatchSchemaType } from "./getValidatedWatchSchemaType";
const COMMAND_FIRST_KEYWORDS = EVENT_TRIGGER_TAGS
.map(tag => tag.split(" ")[0]!).filter(tag => tag !== "SELECT")
.concat("SELECT INTO");
.map(tag => tag.split(" ")[0]!)
.filter(tag => tag !== "SELECT"); /** SELECT INTO is not easily detectable with pg-node (command = "SELECT") */

const DB_FALLBACK_COMMANDS = Array.from(new Set(COMMAND_FIRST_KEYWORDS));

export type VoidFunction = () => void;
Expand Down
6 changes: 3 additions & 3 deletions lib/SchemaWatch/getValidatedWatchSchemaType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type ValidatedWatchSchemaType =
| { watchType: "prostgles_queries"; onChange?: OnSchemaChangeCallback; isFallbackFromDDL: boolean; }

export const getValidatedWatchSchemaType = (dboBuilder: DboBuilder): ValidatedWatchSchemaType => {
const {watchSchema, watchSchemaType, tsGeneratedTypesDir} = dboBuilder.prostgles.opts;
const {watchSchema, watchSchemaType, tsGeneratedTypesDir, disableRealtime } = dboBuilder.prostgles.opts;
if(!watchSchema) return { watchType: "NONE" };

if (watchSchema === "hotReloadMode" && !tsGeneratedTypesDir) {
Expand All @@ -17,12 +17,12 @@ export const getValidatedWatchSchemaType = (dboBuilder: DboBuilder): ValidatedWa
const onChange = typeof watchSchema === "function"? watchSchema : undefined;

if(watchSchemaType === "DDL_trigger" || !watchSchemaType){
if(!dboBuilder.prostgles.isSuperUser){
if(!dboBuilder.prostgles.isSuperUser || disableRealtime){

if(watchSchemaType === "DDL_trigger"){
console.error(`watchSchemaType "DDL_trigger" cannot be used because db user is not a superuser. Will fallback to watchSchemaType "prostgles_queries" `)
} else {
console.warn(`watchSchema fallback to watchSchemaType "prostgles_queries" due to non-superuser`)
console.warn(`watchSchema fallback to watchSchemaType "prostgles_queries" due to ${disableRealtime? "disableRealtime setting" : "non-superuser"}`)
}
return {
watchType: "prostgles_queries",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.2.43",
"version": "4.2.44",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion tests/client/renderReactHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const renderReactHook = (rootArgs: RenderHookArgs): Promise<RenderResult>
});
setTimeout(() => {
if(!resolved){
reject(new Error(`Expected ${expectedRerenders} rerenders, got ${results.length}`));
reject(new Error(`Expected ${expectedRerenders} rerenders, got ${results.length}:\n${JSON.stringify(results)}`));
}
}, timeout);
});
Expand Down
6 changes: 5 additions & 1 deletion tests/client/useProstgles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { renderReactHook, renderReactHookManual } from "./renderReactHook";

export const newly_created_table = "newly_created_table";
export const useProstglesTest = async (db: DBHandlerClient, getSocketOptions: (watchSchema?: boolean) => AnyObject) => {
await db.sql(`DROP TABLE IF EXISTS ${newly_created_table};`);
await describe("useProstgles hook", async (t) => {
const socketOptions = getSocketOptions();
await test("useProstglesClient", async (t) => {
Expand All @@ -23,10 +24,13 @@ export const useProstglesTest = async (db: DBHandlerClient, getSocketOptions: (w
typeof (res2 as any)?.dbo.items4.useFind,
"function"
);
assert.equal(
typeof (res2 as any)?.dbo[newly_created_table],
"undefined"
);
});

await test("useProstglesClient with schema reload", async (t) => {
await db.sql(`DROP TABLE IF EXISTS ${newly_created_table}; DROP TABLE IF EXISTS will_delete;`);
await db.sql(`select pg_sleep(1)`);
let rerenders = 0
const { results: [res1, res2, res3], rerender } = await renderReactHook({
Expand Down
10 changes: 0 additions & 10 deletions tests/server/DBoGenerated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,6 @@ export type DBSchemaGenerated = {
id: string;
};
};
newly_created_table: {
is_view: false;
select: true;
insert: true;
update: true;
delete: true;
columns: {
id?: null | number;
};
};
obj_table: {
is_view: false;
select: true;
Expand Down
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be19fba

Please sign in to comment.