diff --git a/cdn/.gitignore b/cdn/.gitignore index f2e69ff6..14dd53b5 100644 --- a/cdn/.gitignore +++ b/cdn/.gitignore @@ -3,4 +3,5 @@ node_modules/ .DS_Store .env dist/ -files/ \ No newline at end of file +files/ +coverage/ \ No newline at end of file diff --git a/cdn/CONTRIBUTE.md b/cdn/CONTRIBUTE.md new file mode 100644 index 00000000..ceca896c --- /dev/null +++ b/cdn/CONTRIBUTE.md @@ -0,0 +1,14 @@ +# CONTRIBUTE + +### Setup: + +``` +npm i +npm start +``` + +### Run tests: + +``` +npm test +``` diff --git a/cdn/jest/setup.js b/cdn/jest/setup.js new file mode 100644 index 00000000..32c60181 --- /dev/null +++ b/cdn/jest/setup.js @@ -0,0 +1 @@ +jest.spyOn(global.console, "log").mockImplementation(() => jest.fn()); diff --git a/cdn/package-lock.json b/cdn/package-lock.json index 11ce8935..673395a5 100644 Binary files a/cdn/package-lock.json and b/cdn/package-lock.json differ diff --git a/cdn/package.json b/cdn/package.json index 083fbf5b..7e69b65d 100644 --- a/cdn/package.json +++ b/cdn/package.json @@ -5,7 +5,7 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "test": "npm run build && jest --coverage ./tests", "build": "npx tsc -b .", "start": "npm run build && node dist/start.js" }, @@ -48,12 +48,19 @@ "file-type": "^16.5.0", "fs-extra": "^10.0.0", "image-size": "^1.0.0", + "jest": "^27.0.6", "lambert-db": "^1.2.3", "lambert-server": "^1.2.8", "missing-native-js-functions": "^1.2.10", "multer": "^1.4.2", "node-fetch": "^2.6.1", + "supertest": "^6.1.6", "typescript": "^4.1.2", "uuid": "^8.3.2" + }, + "jest": { + "setupFilesAfterEnv": [ + "/jest/setup.js" + ] } } diff --git a/cdn/src/start.ts b/cdn/src/start.ts index 57c9f704..35a68265 100644 --- a/cdn/src/start.ts +++ b/cdn/src/start.ts @@ -25,3 +25,5 @@ server console.log("[Server] started on :" + server.options.port); }) .catch((e) => console.error("[Server] Error starting: ", e)); + +module.exports = server; diff --git a/cdn/tests/start.test.js b/cdn/tests/start.test.js new file mode 100644 index 00000000..348405de --- /dev/null +++ b/cdn/tests/start.test.js @@ -0,0 +1,22 @@ +const { CDNServer } = require("../dist/Server"); +const { db } = require("@fosscord/util"); +const supertest = require("supertest"); +const request = supertest("http://localhost:3003"); +const server = new CDNServer({ port: Number(process.env.PORT) || 3003 }); + +beforeAll(async () => { + await server.start(); + db.close(); + return server; +}); + +afterAll(() => { + return server.stop(); +}); + +describe("GET /ping", () => { + test("should return pong", async () => { + const response = await request.get("/ping"); + expect(response.text).toBe("pong"); + }); +});