diff --git a/.dockerignore b/.dockerignore index 40b878d..fe6a8e4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +node_modules/ +report.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 029c0af..b4f1429 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,18 @@ jobs: - uses: actions/checkout@v4 - name: Start containers - run: docker compose up -d + run: docker compose -f docker-compose.ci.yml up -d + + # install any dependencies since this is a fresh checkout + - name: Install dependencies + run: docker compose -f docker-compose.ci.yml run -v ${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE} --workdir ${GITHUB_WORKSPACE} tests yarn install - name: Run tests - run: docker compose run tests jest --coverage + run: docker compose -f docker-compose.ci.yml run -v ${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE} --workdir ${GITHUB_WORKSPACE} tests jest --coverage --ci --json --testLocationInResults --outputFile=report.json + + - name: Collect test coverage + uses: ArtiomTr/jest-coverage-report-action@v2 + if: always() # we should still try to run this even if there are test failures + with: + coverage-file: ./report.json + base-coverage-file: ./report.json diff --git a/.gitignore b/.gitignore index 40b878d..fe6a8e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +node_modules/ +report.json diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml new file mode 100644 index 0000000..026bc95 --- /dev/null +++ b/docker-compose.ci.yml @@ -0,0 +1,7 @@ +services: + tests: + extends: + file: "docker-compose.yml" + service: tests + build: + target: base # do not install dependencies because we will mount a fresh checkout diff --git a/sum.js b/sum.js index 6fb269a..021908b 100644 --- a/sum.js +++ b/sum.js @@ -1,4 +1,9 @@ function sum(a, b) { return a + b; } -module.exports = sum; \ No newline at end of file + +function multiply(a, b) { + return a * b; +} + +module.exports = sum; diff --git a/sum.test.js b/sum.test.js index df0dd09..6a05bdb 100644 --- a/sum.test.js +++ b/sum.test.js @@ -2,4 +2,8 @@ const sum = require('./sum'); test('adds 1 + 2 to equal 3', () => { expect(sum(1, 2)).toBe(3); -}); \ No newline at end of file +}); + +test('adds 1 + 2 to equal 4', () => { + expect(sum(1, 2)).toBe(4); +});