Skip to content

Commit

Permalink
jest test
Browse files Browse the repository at this point in the history
  • Loading branch information
cyri113 committed May 20, 2023
1 parent 69fce75 commit c707cb6
Show file tree
Hide file tree
Showing 8 changed files with 5,284 additions and 1,771 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COPY . .
RUN npm ci

FROM base AS test
RUN jest
CMD [ "npx", "jest", "--coverage" ]

FROM base AS build
RUN npm run build
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@ The CI Pipeline uses [super-linter](https://github.com/super-linter/super-linter
docker run -e RUN_LOCAL=true -e TYPESCRIPT_DEFAULT_STYLE=prettier -e VALIDATE_DOCKERFILE_HADOLINT=false -v $(pwd):/tmp/lint github/super-linter:slim-latest
```

Note: We have disabled HADOLINT for now as we are getting an error: `qemu: uncaught target signal 11 (Segmentation fault) - core dumped`.
Note: We have disabled HADOLINT for now as we are getting an error: `qemu: uncaught target signal 11 (Segmentation fault) - core dumped`.


### Tests

The CI Pipeline uses the `test` target from the Dockerfile to run the tests. You can run it locally with the following command:

```bash
docker compose -f docker-compose.test.yml up
```

Note: This will create a /coverage folder where you can review the coverage details.
10 changes: 10 additions & 0 deletions __test__/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import request from "supertest";
import app from "../src/app";

describe("GET /", () => {
it("should respond with 'Express + TypeScript Server'", async () => {
const response = await request(app).get("/");
expect(response.status).toBe(200);
expect(response.text).toBe("Express + TypeScript Server");
});
});
32 changes: 32 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.9'

services:
app:
build:
context: .
target: test
dockerfile: Dockerfile
environment:
- PORT=3000
- MONGODB_HOST=mongo
- MONGODB_PORT=27017
- MONGODB_USER=root
- MONGODB_PASS=pass
- REDIS_QUEUE_HOST=localhost
- REDIS_QUEUE_PORT=6379
volumes:
- ./coverage:/project/coverage
depends_on:
- redis
- mongo
redis:
image: 'redis:alpine'
ports:
- 6379:6379
mongo:
image: 'mongo'
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=pass
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
};
Loading

0 comments on commit c707cb6

Please sign in to comment.