diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b1f60178f..ca8831c44 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,3 +44,26 @@ jobs: # Ensure the repository is clean after build - run: yarn clean-build - run: git --no-pager diff --compact-summary --exit-code + + coverage: # run coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + cache: yarn + - run: yarn install --frozen-lockfile + - run: GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} GITHUB_OUTPUT="" yarn coverage + + - name: Upload coverage Coveralls + uses: coverallsapp/github-action@95b1a2355bd0e526ad2fd62da9fd386ad4c98474 # 2.2.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./action-src/coverage/lcov.info + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3 + with: + directory: "./action-src" + files: ./coverage/lcov.info diff --git a/action-src/package.json b/action-src/package.json index 199993a6f..947e61d1b 100644 --- a/action-src/package.json +++ b/action-src/package.json @@ -11,7 +11,8 @@ "prepublishOnly": "yarn build", "smoke-test-push": "env-cmd -f ./fixtures/push.json node ./action/lib/main_root.js", "smoke-test": "env-cmd -f ./fixtures/pull_request.json node ./action/lib/main_root.js", - "test": "vitest run" + "test": "vitest run", + "coverage": "vitest run --coverage" }, "bin": { "build": "./build.mjs" diff --git a/action-src/src/index.ts b/action-src/src/index.ts deleted file mode 100644 index aad1ca831..000000000 --- a/action-src/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './main'; diff --git a/action-src/src/main_root.test.ts b/action-src/src/main_root.test.ts new file mode 100644 index 000000000..f56f7ed05 --- /dev/null +++ b/action-src/src/main_root.test.ts @@ -0,0 +1,14 @@ +import { describe, test, expect, vi } from 'vitest'; +import { run } from './main'; + +vi.mock('./main'); + +import './main_root'; + +const runMocked = vi.mocked(run); + +describe('main_root', () => { + test('run called', () => { + expect(runMocked).toHaveBeenCalled(); + }); +}); diff --git a/action-src/src/main_root.ts b/action-src/src/main_root.ts index 08110d18d..2ca87c9d5 100644 --- a/action-src/src/main_root.ts +++ b/action-src/src/main_root.ts @@ -1,3 +1,3 @@ -import { run } from '.'; +import { run } from './main'; run(); diff --git a/action-src/src/spell.test.ts b/action-src/src/spell.test.ts index a0c7b425e..344778fb7 100644 --- a/action-src/src/spell.test.ts +++ b/action-src/src/spell.test.ts @@ -53,7 +53,7 @@ describe('Validate Spell Checking', () => { test.each` glob | checkDotFiles | expected - ${'fixtures/sampleDotFiles/**'} | ${undefined} | ${[sc('ts/sample.ts')]} + ${'fixtures/sampleDotFiles/**'} | ${undefined} | ${[sc('.dot_dir/sample_nested.ts'), sc('.dot_sample.ts'), sc('ts/sample.ts')]} ${'fixtures/sampleDotFiles/**'} | ${true} | ${[sc('.dot_dir/sample_nested.ts'), sc('.dot_sample.ts'), sc('ts/sample.ts')]} ${'fixtures/sampleDotFiles/**'} | ${false} | ${[sc('ts/sample.ts')]} ${'fixtures/sampleDotFiles/**/.*.ts'} | ${undefined} | ${[sc('.dot_sample.ts')]} diff --git a/action-src/src/test/helper.ts b/action-src/src/test/helper.ts index 049072a36..75dd92af8 100644 --- a/action-src/src/test/helper.ts +++ b/action-src/src/test/helper.ts @@ -11,6 +11,7 @@ Polly.register(FSPersister); const tsconfig = require('../../tsconfig.json'); export const sourceDir = path.resolve(path.join(__dirname, '..', '..')); +/** Repo Root */ export const root = path.resolve(path.join(sourceDir, '..')); export const fixturesLocation = path.join(sourceDir, 'fixtures'); diff --git a/action-src/vitest.config.ts b/action-src/vitest.config.ts index 2bc55d92b..1be4f441b 100644 --- a/action-src/vitest.config.ts +++ b/action-src/vitest.config.ts @@ -15,6 +15,8 @@ export default defineConfig({ 'bin.mjs', 'bin.js', 'bin.cjs', + 'build.mjs', + 'fixtures/**', '.coverage/**', 'coverage', '_snapshots_', diff --git a/cspell.json b/cspell.json index 6f0bc8974..8b87bd323 100644 --- a/cspell.json +++ b/cspell.json @@ -1,10 +1,14 @@ { "version": "0.2", "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", + "enableGlobDot": true, "words": [ - "EDITMSG", "camelcase", + "codecov", "cosmiconfig", + "coverallsapp", + "EDITMSG", + "lcov", "octokit", "openapi", "pollyjs", diff --git a/package.json b/package.json index 1c0d79da1..2a1585fd4 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "clean-build": "yarn workspace action-src clean-build", "smoke-test-push": "env-cmd -f ./fixtures/push.json node ./action/lib/main_root.js", "smoke-test": "env-cmd -f ./fixtures/pull_request.json node ./action/lib/main_root.js", - "watch": "tsc -p . --watch", "test": "yarn workspace action-src test", + "coverage": "yarn workspace action-src coverage", "update-packages": "yarn upgrade && npx package-json-dependency-updater -u && yarn" }, "workspaces": {