Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add code coverage report #1336

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://raw.githubusercontent.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