Skip to content

[Test] Clean and investigate console errors/warnings in unit tests #554

@ananzh

Description

@ananzh

Describe the bug

Currently, there are many console.errors in the unit test. To build a clean unit test, we want to investigate these console errors and clean up if possible. Some examples are:

 PASS  src/core/public/application/ui/app_container.test.tsx
  ● Console

    console.error
      [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry. Using default message as fallback.

      at defaultFormatMessage (node_modules/react-intl/lib/index.js:1533:13)
      at FormattedMessage.render (node_modules/react-intl/lib/index.js:1638:30)
      at finishClassComponent (node_modules/react-dom/cjs/react-dom.development.js:18470:31)
      at updateClassComponent (node_modules/react-dom/cjs/react-dom.development.js:18423:24)
      at beginWork$1 (node_modules/react-dom/cjs/react-dom.development.js:20186:16)
      at beginWork$$1 (node_modules/react-dom/cjs/react-dom.development.js:25756:14)
      at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:24698:12)
      at workLoopSync (node_modules/react-dom/cjs/react-dom.development.js:24671:22)
 FAIL  packages/osd-telemetry-tools/src/tools/manage_schema.test.ts (5.505 s)
  ● generateMapping › generates a mapping file

    : Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error:

      45 | 
      46 | describe('generateMapping', () => {
    > 47 |   it('generates a mapping file', async () => {
         |   ^
      48 |     const mockSchema = await parseJsonFile('mock_schema.json');
      49 |     const result = generateMapping([parsedWorkingCollector]);
      50 |     expect(result).toEqual(mockSchema);

      at new Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Suite.Object.<anonymous>.describe (packages/osd-telemetry-tools/src/tools/manage_schema.test.ts:47:3)
      at Object.<anonymous> (packages/osd-telemetry-tools/src/tools/manage_schema.test.ts:46:1)

To Reproduce
Run:
yarn test:jest --runInBand --detectOpenHandles --reporters=default

If see an error like this:

$ node scripts/jest --runInBand --detectOpenHandles
Error: An error occurred while adding the reporter at path "/home/anan/work/OpenSearch-Dashboards/src/dev/jest/junit_reporter.js".In database main: Invalid argument
    at renewReadTxn (/home/anan/work/OpenSearch-Dashboards/node_modules/lmdb-store/index.js:79:11)
    at LMDBStore.get (/home/anan/work/OpenSearch-Dashboards/node_modules/lmdb-store/index.js:205:39)
    at Cache.getMtime (/home/anan/work/OpenSearch-Dashboards/packages/osd-optimizer/src/node/cache.ts:112:24)
    at compile (/home/anan/work/OpenSearch-Dashboards/packages/osd-optimizer/src/node/node_auto_tranpilation.ts:98:15)
    at /home/anan/work/OpenSearch-Dashboards/packages/osd-optimizer/src/node/node_auto_tranpilation.ts:169:16
    at Module._compile (/home/anan/work/OpenSearch-Dashboards/node_modules/pirates/lib/index.js:93:29)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.newLoader [as .js] (/home/anan/work/OpenSearch-Dashboards/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)

then pass ab argument:
yarn test:jest --runInBand --detectOpenHandles --reporters=default

Expected behavior
explore each problem unit test and do the following step for each test suite

  1. create a sub issue for each test suite
  2. check the following questions:
  • what causes the console error or issues?

  • should this unit test log this error or warning message?

  • if answer to the above question is no, then can we fix it?

The final output is expected to be a cleaned unit test with un-necessary error/warnings been removed.

OpenSearch Version
OpenSearch 1.0.0

Dashboards Version
Dashboards 1.0.0

Sub issues

  • Investigate console error in telemetry_management_section.test.tsx
    issue: #555
  • Investigate console warnings in get_local_stats.test.ts
    issue: #556
  • Investigate console error in telemetry_service.test.ts
    issue: #557

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerstechnical debtIf not paid, jeapardizes long-term success and maintainability of the repository.test:unit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions