Skip to content

Commit

Permalink
test: add code coverage report (#1336)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Aug 16, 2023
1 parent 0ece0f5 commit 2761a13
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 6 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion action-src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion action-src/src/index.ts

This file was deleted.

14 changes: 14 additions & 0 deletions action-src/src/main_root.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
2 changes: 1 addition & 1 deletion action-src/src/main_root.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { run } from '.';
import { run } from './main';

run();
2 changes: 1 addition & 1 deletion action-src/src/spell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')]}
Expand Down
1 change: 1 addition & 0 deletions action-src/src/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 2 additions & 0 deletions action-src/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default defineConfig({
'bin.mjs',
'bin.js',
'bin.cjs',
'build.mjs',
'fixtures/**',
'.coverage/**',
'coverage',
'_snapshots_',
Expand Down
6 changes: 5 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"version": "0.2",
"$schema": "https://github.com/streetsidesoftware/cspell/main/cspell.schema.json",
"enableGlobDot": true,
"words": [
"EDITMSG",
"camelcase",
"codecov",
"cosmiconfig",
"coverallsapp",
"EDITMSG",
"lcov",
"octokit",
"openapi",
"pollyjs",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 2761a13

Please sign in to comment.