Skip to content

Commit 1bd423a

Browse files
test environments using docker compose
1 parent 4d1936b commit 1bd423a

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ RUN yarn install --frozen-lockfile
1212
COPY . .
1313
CMD [ "yarn", "start:dev" ]
1414

15+
FROM dev AS test
16+
ENV NODE_ENV=test
17+
CMD [ "yarn", "test" ]
18+
19+
FROM test AS test-cov
20+
CMD [ "yarn", "test:cov" ]
21+
22+
FROM test AS test-watch
23+
ENV GIT_WORK_TREE=/app GIT_DIR=/app/.git
24+
RUN apk add git
25+
CMD [ "yarn", "test:watch" ]
26+
1527
FROM base AS prod
1628
ENV NODE_ENV=production
1729
RUN yarn install --frozen-lockfile --production

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
"test:cov": "STAGE=dev jest --coverage",
2020
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
2121
"test:e2e": "jest --config ./test/jest-e2e.json",
22-
"docker-compose:dev": "docker-compose up --build"
22+
"docker-compose:dev": "docker-compose up --build",
23+
"docker-compose:test": "docker-compose -f docker-compose.yml -f test.yml up --build --exit-code-from app",
24+
"docker-compose:test:watch": "docker-compose -f docker-compose.yml -f test-watch.yml up --build",
25+
"docker-compose:test:cov": "docker-compose -f docker-compose.yml -f test-cov.yml up --build"
2326
},
2427
"dependencies": {
2528
"@nestjs/common": "^8.0.0",

test-cov.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
app:
3+
build:
4+
target: test-cov

test-watch.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
app:
3+
build:
4+
target: test-watch
5+
volumes:
6+
- .git:/app/.git/

test.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
app:
3+
build:
4+
target: test

0 commit comments

Comments
 (0)