Skip to content

[BUG] npm run test requires a docker instance of OpenSearch #313

@dblock

Description

@dblock

What is the bug?

Tests require a local OpenSearch running on 9200. This is unexpected for unit tests.

How can one reproduce the bug?

$ npm run test -- tools/tests/tester/TestsRunner.test.ts 

> opensearch_api_tools@1.0.0 test
> jest tools/tests/tester/TestsRunner.test.ts

 FAIL  tools/tests/tester/TestsRunner.test.ts
  ✕ stories folder (134 ms)

  ● stories folder

    connect ECONNREFUSED ::1:9200

      26 |     const response: Record<string, any> = {}
      27 |     const [url, params] = this.#parse_url(chapter.path, chapter.parameters ?? {})
    > 28 |     await axios.request({
         |     ^
      29 |       url,
      30 |       auth: {
      31 |         username: 'admin',

      at Function.Object.<anonymous>.AxiosError.from (node_modules/axios/lib/core/AxiosError.js:89:14)
      at RedirectableRequest.handleRequestError (node_modules/axios/lib/adapters/http.js:610:25)
      at ClientRequest.eventHandlers.<computed> (node_modules/follow-redirects/index.js:38:24)
      at Axios.request (node_modules/axios/lib/core/Axios.js:45:41)
      at ChapterReader.read (tools/src/tester/ChapterReader.ts:28:5)
      at ChapterEvaluator.evaluate (tools/src/tester/ChapterEvaluator.ts:35:22)
      at StoryEvaluator.#evaluate_chapters (tools/src/tester/StoryEvaluator.ts:71:28)
      at StoryEvaluator.evaluate (tools/src/tester/StoryEvaluator.ts:50:22)
      at TestsRunner.run (tools/src/tester/TestsRunner.ts:45:26)
      at Object.<anonymous> (tools/tests/tester/TestsRunner.test.ts:20:30)

    Cause:
    connect ECONNREFUSED ::1:9200



Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.42 s, estimated 2 s

What is the expected behavior?

Tests run by default should not require a server.

Do you have any additional context?

We can move some tests to integration tests, use mocks, or the new --dry-run option added in #303.

Running all tests fails with unhelpful errors.

node:internal/child_process/serialization:159
    const string = JSONStringify(message) + '\n';
                   ^

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property '_httpMessage' -> object with constructor 'Object'
    --- property 'socket' closes the circle
    at stringify (<anonymous>)
    at writeChannelMessage (node:internal/child_process/serialization:159:20)
    at process.target._send (node:internal/child_process:838:17)
    at process.target.send (node:internal/child_process:738:19)
    at reportSuccess (/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/node_modules/jest-worker/build/workers/processChild.js:82:11)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions