webex / webex-js-sdk

JavaScript SDK for Webex
https://webex.github.io/webex-js-sdk/
Other
170 stars 336 forks source link

fix(legacy-tooling): use the 'targets' argument to override usual test file path #3563

Closed sreenara closed 2 months ago

sreenara commented 2 months ago

COMPLETES # NA

This pull request addresses

The inability to run test files separately. Currently, the test:unit or test:integration command collects all test files for a package and runs them even though we try mentioning the test file names using commands such as this: yarn workspace @webex/internal-plugin-dss test:unit -- test/unit/spec/dss.ts

Due to this, it is difficult to add .only() to tests and run them separately to troubleshoot problems.

by making the following changes

The run-tests script takes an argument targets which overrides the traditional test file collection. In this PR, I've enhanced the Package class to consider the targets argument and collect only the file that has been mentioned as a target. This ensures that the tooling runs only the tests we want them to.

Change Type

The following scenarios where tested

  1. Ran the command yarn workspace @webex/internal-plugin-dss test:unit --targets dss.ts
$ yarn workspace @webex/internal-plugin-dss test:unit --targets dss.ts
 PASS  test/unit/spec/dss.ts
  plugin-dss
    DSS
      #register()
        βœ“ registers correctly (6 ms)
        βœ“ rejects when it cannot authorize (4 ms)
      #unregister()
        βœ“ unregisters correctly (3 ms)
        βœ“ handles unregister when it is not registered (2 ms)
      #lookupDetail
        βœ“ calls _request correctly (2 ms)
        βœ“ works correctly (4 ms)
        βœ“ fails correctly if lookup fails (3 ms)
        βœ“ fails with default timeout when mercury does not respond (4 ms)
        βœ“ does not fail with timeout when mercury response in time (5 ms)
      #lookup
        βœ“ calls _request correctly (2 ms)
        βœ“ calls _request correctly with entityProviderType (2 ms)
        βœ“ works correctly (3 ms)
        βœ“ fails correctly if lookup fails (2 ms)
        βœ“ calls _batchedLookup correctly (2 ms)
        βœ“ calls _batchedLookup correctly with entityProviderType (2 ms)
        βœ“ Single batched lookup is made after 50 ms and works (3 ms)
        βœ“ Single batched lookup fails correctly if lookup fails (3 ms)
        βœ“ Batch of 2 lookups is made after 50 ms and works (5 ms)
        βœ“ Batch of 2 lookups is made after 50 ms and one fails correctly (3 ms)
        βœ“ Two unrelated lookups are made after 50 ms and work (3 ms)
        βœ“ Two unrelated lookups are made after 50 ms and one fails correctly (3 ms)
        βœ“ fails with default timeout when mercury does not respond (2 ms)
        βœ“ does not fail with timeout when mercury response in time (3 ms)
      #lookupByEmail
        βœ“ calls _request correctly (2 ms)
        βœ“ works correctly (2 ms)
        βœ“ fails correctly if lookup fails (2 ms)
        βœ“ fails with default timeout when mercury does not respond (3 ms)
        βœ“ does not fail with timeout when mercury response in time (2 ms)
      #search
        βœ“ calls _request correctly (2 ms)
        βœ“ works correctly (3 ms)
        βœ“ fails with default timeout when mercury does not respond (2 ms)
        βœ“ does not fail with timeout when mercury response in time (3 ms)
        βœ“ fails with timeout when request only partially resolved (3 ms)
      #_request
        βœ“ handles a request correctly (2 ms)
        βœ“ handles a request with foundPath correctly (3 ms)
        βœ“ handles a request with foundPath and notFoundPath correctly (2 ms)
      #_batchedLookup
        βœ“ calls batcher.request on new batcher for first lookup (3 ms)
        βœ“ calls batcher.request on new batcher for lookup with new resource (4 ms)
        βœ“ calls batcher.request on existing batcher for lookup with existing reource (3 ms)
        β—‹ skipped fails fails when mercury does not respond, later batches can still pass ok
      #searchPlaces
        βœ“ calls _request correctly (3 ms)
        βœ“ works correctly (2 ms)

Test Suites: 1 passed, 1 total
Tests:       1 skipped, 41 passed, 42 total
Snapshots:   0 total
Time:        1.024 s
  1. Tested the same with integration tests and observed the same behavior.

I certified that


Make sure to have followed the contributing guidelines before submitting.

sreenara commented 2 months ago

Looks good. Can we update the CONTRIBUTING also to mention how to use it?

@mkesavan13 If we add the --help argument to the command we will get the options anyway. Is it necessary to update the CONTRIBUTING as well?

$ yarn workspace @webex/internal-plugin-dss test:unit --help
Usage: index test [options]

Test a legacy package

Options:
  --automation                         Run automation-scoped tests.
  --documentation                      Run documentation-scoped tests.
  --integration                        Run integration-scoped tests.
  -browsers, --karma-browsers <array>  Browsers to use when running Karma tests. (default: ["chrome","firefox"])
  -debug, --karma-debug                Run Karma in debug mode
  -port, --karma-port <string>         Port to run the Karma server on
  --runner <array>                     Test runner to use.
  --targets <string>                   Override the default test target for reading files.
  --unit                               Run unit-scoped tests.
  -h, --help