Skip to content
Open
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
13 changes: 13 additions & 0 deletions .commands/test-eslint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

ARGUMENTS="$@"

# scripts
eslint --quiet $ARGUMENTS scripts/
# tests
eslint --quiet $ARGUMENTS tests/
eslint --quiet $ARGUMENTS integration/
# documentation
eslint --quiet $ARGUMENTS docs/
21 changes: 21 additions & 0 deletions .commands/test-types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

# core
tsc -p tests/core/tsconfig.json
# client
tsc -p tests/client/tsconfig.json
# interfaces
tsc -p tests/interfaces/node/tsconfig.json
tsc -p tests/interfaces/bun/tsconfig.json
tsc -p tests/interfaces/deno/tsconfig.json
# plugins
tsc -p tests/plugins/codeGenerator/tsconfig.json
tsc -p tests/plugins/openApiGenerator/tsconfig.json
tsc -p tests/plugins/cacheController/tsconfig.json
tsc -p tests/plugins/static/tsconfig.json
# integration
npm -w integration run test:types
# documentation
npm -w docs run test:types
6 changes: 6 additions & 0 deletions docs/.commands/test-types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -e

tsc -p tsconfig.app.json
tsc -p tsconfig.v0.json
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview",
"test:types": "tsc -p tsconfig.app.json && tsc -p tsconfig.v0.json"
"test:types": "./.commands/test-types.sh"
},
"devDependencies": {
"@shikijs/vitepress-twoslash": "^3.21.0",
Expand Down
11 changes: 11 additions & 0 deletions integration/.commands/test-types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e

tsc -p codeGenerator/tsconfig.json
tsc -p openApiGenerator/tsconfig.json
tsc -p core/tsconfig.json
tsc -p node/tsconfig.json
tsc -p client/tsconfig.json
tsc -p static/tsconfig.json
tsc -p cacheController/tsconfig.json
File renamed without changes.
57 changes: 57 additions & 0 deletions integration/cacheController/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { createCacheControllerHook } from "@duplojs/http/cacheController";
import { createHub, ResponseContract, useRouteBuilder } from "@duplojs/http";
import { createHttpServer } from "@duplojs/http/node";
import { DP } from "@duplojs/utils";

describe("cacheController", () => {
it("route is good", async() => {
const route = useRouteBuilder("GET", "/", {
hooks: [
createCacheControllerHook({
response: {
private: ["authorization", "cookie"],
noCache: ["set-cookie"],
maxAge: 200,
},
}),
],
})
.handler(
ResponseContract.ok("test", DP.boolean()),
(__, { response, request }) => response(
"test",
request.getCacheControlDirective("noStore"),
),
);

const hub = createHub({ environment: "DEV" }).register(route);
const server = await createHttpServer(hub, {
host: "0.0.0.0",
port: 8947,
});

await expect(
fetch("http://localhost:8947/", {
method: "GET",
})
.then(async(response) => ({
body: await response.text(),
headers: [...response.headers.entries()],
})),
).resolves.toStrictEqual({
body: "false",
headers: expect.arrayContaining([
[
"information",
"test",
],
[
"cache-control",
"max-age=200,private=\"authorization,cookie\",no-cache=\"set-cookie\"",
],
]),
});

server.close();
});
});
11 changes: 11 additions & 0 deletions integration/cacheController/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.test.json",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@core": ["../core/index.ts"]
},
"types": ["vitest/globals", "node"]
},
"include": ["**/*.ts", "../core/**/*.ts"],
}
2 changes: 1 addition & 1 deletion integration/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"baseUrl": "./",
"paths": {
"@core": ["../core/index.ts"],
"@utils": ["../utils/index.ts"],
"@utils": ["../_utils/index.ts"],
},
"types": ["vitest/globals", "node", "web"]
},
Expand Down
32 changes: 32 additions & 0 deletions integration/codeGenerator/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,37 @@ export type Routes = {
information: "close";
body?: undefined;
};
} | {
method: "GET";
path: "/static-file";
responses: {
code: "200";
information: "resource.found";
body: File;
} | {
code: "404";
information: "resource.notfound";
body?: undefined;
} | {
code: "304";
information: "resource.notModified";
body?: undefined;
};
} | {
method: "GET";
path: \`/static-folder/\${string}\`;
responses: {
code: "200";
information: "resource.found";
body: File;
} | {
code: "404";
information: "resource.notfound";
body?: undefined;
} | {
code: "304";
information: "resource.notModified";
body?: undefined;
};
};"
`;
21 changes: 19 additions & 2 deletions integration/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import "./routes";
import { setCurrentWorkingDirectory, SF } from "@duplojs/server-utils";
import { createHub, routeStore } from "@duplojs/http";
import { staticPlugin } from "@duplojs/http/static";
import { asserts, E, Path } from "@duplojs/utils";
import "./routes";

const sourceFile = SF.createFileInterface("files/fakeFiles/superTextFile.txt");
const sourceFolder = SF.createFolderInterface("files/fakeFiles");

asserts(
setCurrentWorkingDirectory(Path.resolveRelative([import.meta.dirname, "../"])),
E.isRight,
);

export const hub = createHub({ environment: "DEV" })
.register(routeStore.getAll());
.register(routeStore.getAll())
.plug(
staticPlugin(sourceFile, { path: "/static-file" }),
)
.plug(
staticPlugin(sourceFolder, { prefix: "/static-folder" }),
);
1 change: 1 addition & 0 deletions integration/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.app.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["**/*.ts"],
}
2 changes: 0 additions & 2 deletions integration/node/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ describe("file", async() => {
uploadFolder: resolve(import.meta.dirname, "../files/upload"),
});

process.chdir(resolve(import.meta.dirname, "../"));

afterAll(() => {
server.close();
});
Expand Down
4 changes: 2 additions & 2 deletions integration/node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"baseUrl": "./",
"paths": {
"@core": ["../core/index.ts"],
"@utils": ["../utils/index.ts"],
"@utils": ["../_utils/index.ts"],
},
"types": ["vitest/globals", "node"]
},
"include": ["**/*.ts", "../core/**/*.ts", "../utils/**/*.ts"],
"include": ["**/*.ts", "../core/**/*.ts", "../_utils/**/*.ts"],
}
108 changes: 107 additions & 1 deletion integration/openApiGenerator/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,100 @@ exports[`openApiGenerator > correct generate file 1`] = `
}
}
}
},
"/static-file": {
"get": {
"parameters": [],
"responses": {
"200": {
"headers": {
"information": {
"schema": {
"const": "resource.found",
"type": "string"
},
"description": "resource.found"
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotIdentified15"
}
}
}
},
"304": {
"headers": {
"information": {
"schema": {
"const": "resource.notModified",
"type": "string"
},
"description": "resource.notModified"
}
}
},
"404": {
"headers": {
"information": {
"schema": {
"const": "resource.notfound",
"type": "string"
},
"description": "resource.notfound"
}
}
}
}
}
},
"/static-folder/*": {
"get": {
"parameters": [],
"responses": {
"200": {
"headers": {
"information": {
"schema": {
"const": "resource.found",
"type": "string"
},
"description": "resource.found"
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotIdentified18"
}
}
}
},
"304": {
"headers": {
"information": {
"schema": {
"const": "resource.notModified",
"type": "string"
},
"description": "resource.notModified"
}
}
},
"404": {
"headers": {
"information": {
"schema": {
"const": "resource.notfound",
"type": "string"
},
"description": "resource.notfound"
}
}
}
}
}
}
},
"components": {
Expand Down Expand Up @@ -459,7 +553,19 @@ exports[`openApiGenerator > correct generate file 1`] = `
"data"
]
},
"NotIdentified14": {}
"NotIdentified14": {},
"NotIdentified15": {
"type": "string",
"format": "binary"
},
"NotIdentified16": {},
"NotIdentified17": {},
"NotIdentified18": {
"type": "string",
"format": "binary"
},
"NotIdentified19": {},
"NotIdentified20": {}
}
}
}"
Expand Down
2 changes: 1 addition & 1 deletion integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "integrations",
"license": "ISC",
"scripts": {
"test:types": "tsc -p codeGenerator/tsconfig.json && tsc -p openApiGenerator/tsconfig.json && tsc -p core/tsconfig.json && tsc -p node/tsconfig.json && tsc -p client/tsconfig.json"
"test:types": "./.commands/test-types.sh"
},
"dependencies": {
"@duplojs/http": "file:.."
Expand Down
Loading
Loading