Skip to content

Commit

Permalink
Separate unit and integration tests. (#320)
Browse files Browse the repository at this point in the history
Separate unit and integration tests.

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Jun 6, 2024
1 parent 698266e commit 3ad078c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/test-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
25 changes: 25 additions & 0 deletions tools/tests/tester/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
22 changes: 0 additions & 22 deletions tools/tests/tester/overall_result.test.ts

This file was deleted.

0 comments on commit 3ad078c

Please sign in to comment.