diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..00f4c25 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +* text=auto eol=lf +dist/** -diff linguist-generated=true diff --git a/.github/workflows/build-push-release.yml b/.github/workflows/build-push-release.yml index 79f8ac3..dd94e68 100644 --- a/.github/workflows/build-push-release.yml +++ b/.github/workflows/build-push-release.yml @@ -37,7 +37,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: "16" + node-version: "18.x" # Install dependencies - name: Install dependencies @@ -60,7 +60,13 @@ jobs: git config --global user.name 'GitHub Action' git config --global user.email 'action@github.com' git add package.json dist - git diff --quiet && git diff --staged --quiet || (git commit -m "Automated build: Update version to ${{ steps.gitversion.outputs.semVer }} and rebuild dist" && git push) + git diff --quiet && git diff --staged --quiet || ( + BRANCH_NAME="update-version-${{ steps.gitversion.outputs.semVer }}" + git checkout -b $BRANCH_NAME + git commit -m "Automated build: Update version to ${{ steps.gitversion.outputs.semVer }} and rebuild dist" + git push origin $BRANCH_NAME + gh pr create --title "Automated build: Update version to ${{ steps.gitversion.outputs.semVer }}" --body "This PR updates the version to ${{ steps.gitversion.outputs.semVer }} and rebuilds the dist folder." --base main --head $BRANCH_NAME + ) # Create a release if on a release branch - name: Create Release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0f1a0af..c371854 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,6 +49,19 @@ jobs: env: CODECOV_TOKEN: ${{ vars.CODECOV_TOKEN }} + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + with: + files: ./testResults/junit.xml + flags: unittests + name: relabeler-tests-results + verbose: true + fail_ci_if_error: true + #token: ${{ env.CODECOV_TOKEN }} + env: + CODECOV_TOKEN: ${{ vars.CODECOV_TOKEN }} + - name: Create artifact run: | mkdir artifact diff --git a/.gitignore b/.gitignore index ba2a97b..d5cd775 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules coverage +testResults diff --git a/__tests__/api.test.ts b/__tests__/api.test.ts index 0f04b01..cee8ee8 100644 --- a/__tests__/api.test.ts +++ b/__tests__/api.test.ts @@ -7,11 +7,14 @@ jest.mock('axios'); const mockedAxios = axios as jest.Mocked; -it('fetches successfully data from an API', async () => { - const data = { data: { userId: 1, id: 1, title: 'mock title' } }; - mockedAxios.get.mockResolvedValue(data); +describe('api', () => { + it('fetches successfully data from an API', async () => { + const data = { data: { userId: 1, id: 1, title: 'mock title' } }; + mockedAxios.get.mockResolvedValue(data); - const result = await fetchData('https://jsonplaceholder.typicode.com/todos/1'); - expect(result).toEqual(data.data); - expect(mockedAxios.get).toHaveBeenCalledTimes(1); + const result = await fetchData('https://jsonplaceholder.typicode.com/todos/1'); + expect(result).toEqual(data.data); + expect(mockedAxios.get).toHaveBeenCalledTimes(1); + }); }); + diff --git a/__tests__/sum.test.ts b/__tests__/sum.test.ts index 8be66bf..2a295d5 100644 --- a/__tests__/sum.test.ts +++ b/__tests__/sum.test.ts @@ -1,6 +1,8 @@ import { test, expect } from '@jest/globals'; import { sum } from '../src/sum'; -test('adds 1 + 2 to equal 3', () => { - expect(sum(1, 2)).toBe(3); +describe('sum', () => { + test('adds 1 + 2 to equal 3', () => { + expect(sum(1, 2)).toBe(3); + }); }); diff --git a/codecov.yml b/codecov.yml index 8c96964..1df185f 100644 --- a/codecov.yml +++ b/codecov.yml @@ -3,13 +3,13 @@ coverage: project: default: # Thresholds for overall project coverage - target: 80% # Set your desired coverage target - threshold: 1% # Allowable drop in coverage + target: 80% # Set your desired coverage target + threshold: 1% # Allowable drop in coverage patch: default: # Thresholds for coverage of new changes - target: 80% # Set your desired coverage target for new changes - threshold: 5% # Allowable drop in coverage for new changes + target: 80% # Set your desired coverage target for new changes + threshold: 5% # Allowable drop in coverage for new changes comment: layout: "reach, diff, flags, files" diff --git a/jest.config.mjs b/jest.config.mjs index f6097fa..23c0475 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -5,6 +5,10 @@ export default { transform: { '^.+\\.tsx?$': ['ts-jest', {}], }, + reporters: [ + "default", + "jest-junit" + ], collectCoverage: true, coverageDirectory: 'coverage', coverageReporters: ['lcov', 'text', 'cobertura'], // Generates both LCOV and Cobertura reports diff --git a/package-lock.json b/package-lock.json index a670486..e385947 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "eslint": "^8.55.0", "globals": "^13.24.0", "jest": "^29.7.0", + "jest-junit": "^16.0.0", "license-checker": "^25.0.1", "ts-jest": "^29.1.1", "typescript": "5.3.3", @@ -3934,6 +3935,35 @@ "fsevents": "^2.3.2" } }, + "node_modules/jest-junit": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/jest-junit/-/jest-junit-16.0.0.tgz", + "integrity": "sha512-A94mmw6NfJab4Fg/BlvVOUXzXgF0XIH6EmTgJ5NDPp4xoKq0Kr7sErb+4Xs9nZvu58pJojz5RFGpqnZYJTrRfQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "mkdirp": "^1.0.4", + "strip-ansi": "^6.0.1", + "uuid": "^8.3.2", + "xml": "^1.0.1" + }, + "engines": { + "node": ">=10.12.0" + } + }, + "node_modules/jest-junit/node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "dev": true, + "license": "MIT", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/jest-leak-detector": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-29.7.0.tgz", @@ -6238,6 +6268,13 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==", + "dev": true, + "license": "MIT" + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index 7014ba0..35c4f25 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "main": "dist/index.js", "scripts": { "clean": "rm -rf dist", - "clean:coverage": "rm -rf coverage", + "clean:coverage": "rm -rf coverage testResults", "build": "npm run clean && npx ncc build src/index.ts -o dist --source-map --license licenses.txt", "test": "npm run clean:coverage && jest --coverage --verbose --detectOpenHandles && npm run lint", "lint": "eslint 'src/**/*.{ts,js}'", @@ -23,6 +23,7 @@ "devDependencies": { "typescript": "5.3.3", "jest": "^29.7.0", + "jest-junit": "^16.0.0", "ts-jest": "^29.1.1", "@types/jest": "^29.5.11", "@types/axios": "^0.14.0", @@ -37,5 +38,13 @@ "@types/js-yaml": "^4.0.5", "license-checker": "^25.0.1", "@vercel/ncc": "^0.38.1" + }, + "jest-junit": { + "suiteName": "Relabeler Tests", + "outputDirectory": "testResults", + "outputName": "junit.xml", + "reportTestSuiteErrors": "true", + "includeConsoleOutput": "true", + "ancestorSeparator": " :: " } }