From 0b6782f72d2aa47bf5e02409232d2f64cf26a902 Mon Sep 17 00:00:00 2001 From: dblock Date: Thu, 6 Jun 2024 13:43:26 -0400 Subject: [PATCH] Added code coverage. Signed-off-by: dblock --- .../{test-tools.yml => test-tools-integ.yml} | 15 ++-- .github/workflows/test-tools-unit.yml | 48 +++++++++++ .gitignore | 6 +- CHANGELOG.md | 1 + DEVELOPER_GUIDE.md | 79 ++++++++++--------- README.md | 6 ++ 6 files changed, 112 insertions(+), 43 deletions(-) rename .github/workflows/{test-tools.yml => test-tools-integ.yml} (74%) create mode 100644 .github/workflows/test-tools-unit.yml diff --git a/.github/workflows/test-tools.yml b/.github/workflows/test-tools-integ.yml similarity index 74% rename from .github/workflows/test-tools.yml rename to .github/workflows/test-tools-integ.yml index eed811e1d..9c98aa6c3 100644 --- a/.github/workflows/test-tools.yml +++ b/.github/workflows/test-tools-integ.yml @@ -1,4 +1,4 @@ -name: Test Tools +name: Test Tools (Integration) on: push: @@ -9,6 +9,7 @@ on: - 'jest.config.js' - 'tsconfig.json' - 'tools/**' + - '.github/workflows/test-tools*.yml' pull_request: branches: ['**'] paths: @@ -17,6 +18,7 @@ on: - 'jest.config.js' - 'tsconfig.json' - 'tools/**' + - '.github/workflows/test-tools*.yml' jobs: test: @@ -43,8 +45,11 @@ jobs: - name: Install Dependencies run: npm install - - name: Lint - run: npm run lint - - name: Tests - run: npm run test + run: | + npm run test:integ -- --coverage + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test-tools-unit.yml b/.github/workflows/test-tools-unit.yml new file mode 100644 index 000000000..baf009678 --- /dev/null +++ b/.github/workflows/test-tools-unit.yml @@ -0,0 +1,48 @@ +name: Test Tools (Unit) + +on: + push: + branches: ['**'] + paths: + - 'package*.json' + - 'eslint.config.mjs' + - 'jest.config.js' + - 'tsconfig.json' + - 'tools/**' + - '.github/workflows/test-tools*.yml' + pull_request: + branches: ['**'] + paths: + - 'package*.json' + - 'eslint.config.mjs' + - 'jest.config.js' + - 'tsconfig.json' + - 'tools/**' + - '.github/workflows/test-tools*.yml' + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install Dependencies + run: npm install + + - name: Lint + run: npm run lint + + - name: Tests + run: | + npm run test:unit -- --coverage + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index c16dd7893..a4d81cb31 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,8 @@ node_modules _site/ # build output -build/ \ No newline at end of file +build/ + +# coverage output +coverage/ + diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aeadb5bd..b62bde306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added license headers to TypeScript code ([#311](https://github.com/opensearch-project/opensearch-api-specification/pull/311)) - Added `npm run test:spec -- --dry-run --verbose` ([#303](https://github.com/opensearch-project/opensearch-api-specification/pull/303)) - Added `npm run test:unit` and `test:integ` ([#320](https://github.com/opensearch-project/opensearch-api-specification/pull/320)) +- Added code coverage to tools' tests ([#323](https://github.com/opensearch-project/opensearch-api-specification/pull/323)) ### Changed diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index d8efe265a..a6044dcb2 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -1,39 +1,40 @@ -* [Developer Guide](#developer-guide) - * [Getting Started](#getting-started) - * [Specification](#specification) - * [File Structure](#file-structure) - * [Grouping Operations](#grouping-operations) - * [Grouping Schemas](#grouping-schemas) - * [Superseded Operations](#superseded-operations) - * [Global Parameters](#global-parameters) - * [OpenAPI Extensions](#openapi-extensions) - * [Writing Spec Tests](#writing-spec-tests) - * [Running Spec Tests Locally](#running-spec-tests-locally) - * [Tools](#tools) - * [Setup](#setup) - * [Spec Merger](#spec-merger) - * [Arguments](#arguments) - * [Example](#example) - * [Spec Linter](#spec-linter) - * [Arguments](#arguments-1) - * [Example](#example-1) - * [Dump Cluster Spec](#dump-cluster-spec) - * [Arguments](#arguments-2) - * [Example](#example-2) - * [Coverage](#coverage) - * [Arguments](#arguments-3) - * [Example](#example-3) - * [Testing](#testing) - * [Tests](#tests) - * [Lints](#lints) - * [Workflows](#workflows) - * [Analyze PR Changes](#analyze-pr-changes) - * [Build](#build) - * [Deploy GitHub Pages](#deploy-github-pages) - * [Comment on PR](#comment-on-pr) - * [Test Tools](#test-tools) - * [Validate Spec](#validate-spec) +- [Developer Guide](#developer-guide) + - [Getting Started](#getting-started) + - [Specification](#specification) + - [File Structure](#file-structure) + - [Grouping Operations](#grouping-operations) + - [Grouping Schemas](#grouping-schemas) + - [Superseded Operations](#superseded-operations) + - [Global Parameters](#global-parameters) + - [OpenAPI Extensions](#openapi-extensions) + - [Writing Spec Tests](#writing-spec-tests) + - [Running Spec Tests Locally](#running-spec-tests-locally) + - [Tools](#tools) + - [Setup](#setup) + - [Spec Merger](#spec-merger) + - [Arguments](#arguments) + - [Example](#example) + - [Spec Linter](#spec-linter) + - [Arguments](#arguments-1) + - [Example](#example-1) + - [Dump Cluster Spec](#dump-cluster-spec) + - [Arguments](#arguments-2) + - [Example](#example-2) + - [Coverage](#coverage) + - [Arguments](#arguments-3) + - [Example](#example-3) + - [Testing](#testing) + - [Tests](#tests) + - [Lints](#lints) + - [Workflows](#workflows) + - [Analyze PR Changes](#analyze-pr-changes) + - [Build](#build) + - [Deploy GitHub Pages](#deploy-github-pages) + - [Comment on PR](#comment-on-pr) + - [Test Tools (Unit)](#test-tools-unit) + - [Test Tools (Integration)](#test-tools-integration) + - [Validate Spec](#validate-spec) # Developer Guide @@ -417,9 +418,13 @@ This workflow performs a [Jekyll](https://jekyllrb.com/) build of the `main` bra This workflow is triggered by the completion of the workflows such as [Analyze PR Changes](#analyze-pr-changes) and downloading a JSON payload artifact which it uses to invoke a template from [.github/pr-comment-templates](.github/pr-comment-templates) to render a comment which is placed on the original triggering PR. -### [Test Tools](.github/workflows/test-tools.yml) +### [Test Tools (Unit)](.github/workflows/test-tools-unit.yml) -This workflow runs on PRs to invoke the [tools' tests](tools/tests) and [TypeScript linting](#lints) to ensure there are no breakages in behavior or departures from the desired code style and cleanliness. +This workflow runs on PRs to invoke the [tools' unit tests](tools/tests), upload test coverage to CodeCov, and run [TypeScript linting](#lints) to ensure there are no breakages in behavior or departures from the desired code style and cleanliness. + +### [Test Tools (Integration)](.github/workflows/test-tools-integ.yml) + +This workflow runs on PRs to invoke the [tools' integration tests](tools/tests) that require a running instance of OpenSearch to ensure there are no breakages in behavior. ### [Validate Spec](.github/workflows/validate-spec.yml) diff --git a/README.md b/README.md index e8ebe70ae..f971a979d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ ## OpenSearch API Specification +[![Code Covergage](https://codecov.io/github/opensearch-project/opensearch-api-specification/graph/badge.svg?token=TO9YMAKSHH)](https://codecov.io/github/opensearch-project/opensearch-api-specification) +[![Test Tools (Unit)](https://github.com/opensearch-project/opensearch-api-specification/actions/workflows/test-tools-unit.yml/badge.svg)](https://github.com/opensearch-project/opensearch-api-specification/actions/workflows/test-tools-unit.yml) +[![Test Tools (Integration)](https://github.com/opensearch-project/opensearch-api-specification/actions/workflows/test-tools-integ.yml/badge.svg)](https://github.com/opensearch-project/opensearch-api-specification/actions/workflows/test-tools-integ.yml) +[![Test Spec](https://github.com/opensearch-project/opensearch-api-specification/actions/workflows/test.yml/badge.svg)](https://github.com/opensearch-project/opensearch-api-specification/actions/workflows/test.yml) +[![Validate Spec](https://github.com/opensearch-project/opensearch-api-specification/actions/workflows/validate-spec.yml/badge.svg)](https://github.com/opensearch-project/opensearch-api-specification/actions/workflows/validate-spec.yml) + - [OpenSearch API Specification](#opensearch-api-specification) - [Welcome!](#welcome) - [Project Resources](#project-resources)