rsocket-js icon indicating copy to clipboard operation
rsocket-js copied to clipboard

add browser tck test suite

Open viglucci opened this issue 3 years ago • 2 comments

Adds a test suite that exercises various @rsocket packages and patterns to ensure compatibility with Browser environments. This is done by compiling the actual test files into a browser-compatible version, and executing the test suite from within a browser context using Karma.

The suite is intended to run on all pushes and PR's, though you'll notice there are browser compatibility issues with various RSocket APIs, so the suite currently fails. In addition to the initial tests added in this PR, there are likely other APIs with browser compatibility issues (really anywhere Buffer is used) that will need to ultimately be covered as well.

Example test output:

23 01 2022 00:00:00.936:INFO [compiler.karma-typescript]: Compiling project using Typescript 4.5.4
23 01 2022 00:00:06.766:INFO [compiler.karma-typescript]: Compiled 1 files in 5816 ms.
23 01 2022 00:00:07.674:INFO [bundler.karma-typescript]: Bundled imports for 1 file(s) in 408 ms.
23 01 2022 00:00:07.677:INFO [karma-server]: Karma v6.3.11 server started at http://localhost:9876/
23 01 2022 00:00:07.677:INFO [launcher]: Launching browsers ChromeHeadlessCI with concurrency unlimited
23 01 2022 00:00:07.692:INFO [launcher]: Starting browser ChromeHeadless
23 01 2022 00:00:07.986:INFO [Chrome Headless 98.0.4758.0 (Linux x86_64)]: Connected on socket QAqP7-lVctYze3jsAAAB with id 94968735
  CompositeMetadata
    ✖ encodeRoute
    ✖ encodeCompositeMetadata

Finished in 0.002 secs / 0.001 secs @ 00:00:08 GMT+0000 (Coordinated Universal Time)

SUMMARY:
✔ 0 tests completed
✖ 2 tests failed

FAILED TESTS:
  CompositeMetadata
    ✖ encodeRoute
      Chrome Headless 98.0.4758.0 (Linux x86_64)
    ReferenceError: Buffer is not defined
        at encodeRoute (/tmp/karma-typescript-bundle--778-pAzoKp0HW4d1-.js:452:24)
        at Context.<anonymous> (src/CompositeMetadata.spec.ts:15:37 <- src/CompositeMetadata.spec.js:8:65)

    ✖ encodeCompositeMetadata
      Chrome Headless 98.0.4758.0 (Linux x86_64)
    ReferenceError: Buffer is not defined
        at encodeCompositeMetadata (/tmp/karma-typescript-bundle--778-pAzoKp0HW4d1-.js:7689:36)
        at Context.<anonymous> (src/CompositeMetadata.spec.ts:21:52 <- src/CompositeMetadata.spec.js:13:80)

viglucci avatar Jan 23 '22 17:01 viglucci

I expect that for browser env folks will be importing any buffer polyfill. Thus, should we add from the browser test dependency?

OlegDokuka avatar Jan 24 '22 09:01 OlegDokuka

My hope has been that we can support supplying a polyfill through the public API, via optional constructor dependency injection, or other DI pattern (like how we support WebSocket factory on the WS client transport).

Most front-end build tools support polyfilling an API globally, but it varies by tool, and is often confusing for new users. So my goal would be to offer browser support directly, rather than require global polyfill.

viglucci avatar Jan 24 '22 12:01 viglucci