From 3ad078c5cb645afaed78590439eeb613b5f9e644 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Thu, 6 Jun 2024 12:07:54 -0400 Subject: [PATCH] Separate unit and integration tests. (#320) Separate unit and integration tests. Signed-off-by: dblock --- .github/workflows/test-tools.yml | 10 ++------ CHANGELOG.md | 1 + DEVELOPER_GUIDE.md | 2 ++ package.json | 4 ++- tools/tests/tester/helpers.test.ts | 25 +++++++++++++++++++ .../tester/{ => integ}/StoryEvaluator.test.ts | 2 +- .../tester/{ => integ}/TestRunner.test.ts | 4 +-- tools/tests/tester/overall_result.test.ts | 22 ---------------- 8 files changed, 36 insertions(+), 34 deletions(-) create mode 100644 tools/tests/tester/helpers.test.ts rename tools/tests/tester/{ => integ}/StoryEvaluator.test.ts (97%) rename tools/tests/tester/{ => integ}/TestRunner.test.ts (92%) delete mode 100644 tools/tests/tester/overall_result.test.ts diff --git a/.github/workflows/test-tools.yml b/.github/workflows/test-tools.yml index cdd7897f3..eed811e1d 100644 --- a/.github/workflows/test-tools.yml +++ b/.github/workflows/test-tools.yml @@ -46,11 +46,5 @@ jobs: - name: Lint run: npm run lint - - name: Test Spec Merger - run: npm run test -- tools/tests/merger - - - name: Test Spec Linter - run: npm run test -- tools/tests/linter - - - name: Test Spec Tester - run: npm run test -- tools/tests/tester --runInBand + - name: Tests + run: npm run test diff --git a/CHANGELOG.md b/CHANGELOG.md index ef2cbacbe..0aeadb5bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added API coverage ([#210](https://github.com/opensearch-project/opensearch-api-specification/pull/210)) - 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)) ### Changed diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 65229fae4..d8efe265a 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -383,6 +383,8 @@ Specify the test path to run tests for one of the tools: npm run test -- tools/tests/tester/ ``` +The test suite contains unit tests and integration tests. Integration tests, such as [these](tools/tests/tester/integ/), require a local instance of OpenSearch and are placed into a folder named `integ`. Unit tests are run in parallel and integration tests are run sequentially using `--runInBand`. You can run unit tests with `npm run test:unit` separately from integration tests with `npm run test:integ`. + #### Lints All code is linted using [ESLint](https://eslint.org/) in combination with [typescript-eslint](https://typescript-eslint.io/). Linting can be run via: diff --git a/package.json b/package.json index 6e953726a..032861043 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,9 @@ "lint": "eslint .", "lint--fix": "eslint . --fix", "merge": "ts-node tools/src/merger/merge.ts", - "test": "jest", + "test": "npm run test:unit && npm run test:integ", + "test:unit": "jest --testMatch='**/*.test.ts' --testPathIgnorePatterns=/integ/", + "test:integ": "jest --testMatch='**/integ/*.test.ts' --runInBand", "test:spec": "ts-node tools/src/tester/start.ts" }, "dependencies": { diff --git a/tools/tests/tester/helpers.test.ts b/tools/tests/tester/helpers.test.ts new file mode 100644 index 000000000..8383edb42 --- /dev/null +++ b/tools/tests/tester/helpers.test.ts @@ -0,0 +1,25 @@ +/* +* Copyright OpenSearch Contributors +* SPDX-License-Identifier: Apache-2.0 +* +* The OpenSearch Contributors require contributions made to +* this file be licensed under the Apache-2.0 license or a +* compatible open source license. +*/ + +import { overall_result } from '../../src/tester/helpers' +import { type Evaluation, Result } from '../../src/tester/types/eval.types' + +describe('helpers', () => { + function e (...results: Result[]): Evaluation[] { + return results.map(result => ({ result })) + } + + test('overall_result', () => { + expect(overall_result(e(Result.PASSED, Result.SKIPPED, Result.FAILED, Result.ERROR))).toBe(Result.ERROR) + expect(overall_result(e(Result.PASSED, Result.SKIPPED, Result.FAILED))).toBe(Result.FAILED) + expect(overall_result(e(Result.PASSED, Result.SKIPPED))).toBe(Result.SKIPPED) + expect(overall_result(e(Result.PASSED))).toBe(Result.PASSED) + expect(overall_result(e())).toBe(Result.PASSED) + }) +}) diff --git a/tools/tests/tester/StoryEvaluator.test.ts b/tools/tests/tester/integ/StoryEvaluator.test.ts similarity index 97% rename from tools/tests/tester/StoryEvaluator.test.ts rename to tools/tests/tester/integ/StoryEvaluator.test.ts index 3edae05ea..bcb8959f4 100644 --- a/tools/tests/tester/StoryEvaluator.test.ts +++ b/tools/tests/tester/integ/StoryEvaluator.test.ts @@ -7,7 +7,7 @@ * compatible open source license. */ -import { construct_tester_components, load_actual_evaluation, load_expected_evaluation } from './helpers' +import { construct_tester_components, load_actual_evaluation, load_expected_evaluation } from '../helpers' const { story_evaluator } = construct_tester_components('tools/tests/tester/fixtures/specs/indices_excerpt.yaml') diff --git a/tools/tests/tester/TestRunner.test.ts b/tools/tests/tester/integ/TestRunner.test.ts similarity index 92% rename from tools/tests/tester/TestRunner.test.ts rename to tools/tests/tester/integ/TestRunner.test.ts index 00f3c47c3..b6c8c99f9 100644 --- a/tools/tests/tester/TestRunner.test.ts +++ b/tools/tests/tester/integ/TestRunner.test.ts @@ -7,8 +7,8 @@ * compatible open source license. */ -import { construct_tester_components, flatten_errors, load_expected_evaluation } from './helpers' -import { type StoryEvaluation } from '../../src/tester/types/eval.types' +import { construct_tester_components, flatten_errors, load_expected_evaluation } from '../helpers' +import { type StoryEvaluation } from '../../../src/tester/types/eval.types' test('stories folder', async () => { const { test_runner } = construct_tester_components('tools/tests/tester/fixtures/specs/indices_excerpt.yaml') diff --git a/tools/tests/tester/overall_result.test.ts b/tools/tests/tester/overall_result.test.ts deleted file mode 100644 index 7e2bb2427..000000000 --- a/tools/tests/tester/overall_result.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* -* Copyright OpenSearch Contributors -* SPDX-License-Identifier: Apache-2.0 -* -* The OpenSearch Contributors require contributions made to -* this file be licensed under the Apache-2.0 license or a -* compatible open source license. -*/ - -import { overall_result } from '../../src/tester/helpers' -import { type Evaluation, Result } from '../../src/tester/types/eval.types' - -function e (...results: Result[]): Evaluation[] { - return results.map(result => ({ result })) -} -test('overall_result', () => { - expect(overall_result(e(Result.PASSED, Result.SKIPPED, Result.FAILED, Result.ERROR))).toBe(Result.ERROR) - expect(overall_result(e(Result.PASSED, Result.SKIPPED, Result.FAILED))).toBe(Result.FAILED) - expect(overall_result(e(Result.PASSED, Result.SKIPPED))).toBe(Result.SKIPPED) - expect(overall_result(e(Result.PASSED))).toBe(Result.PASSED) - expect(overall_result(e())).toBe(Result.PASSED) -})