Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-7879

Set up a test harness package in Compass monorepo

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Testing
    • None
    • Developer Tools

      To be able to unit test application code while more and more context dependant hooks are being used throughout the application, we set up some test environments defaults and fallbacks for various React contexts and hooks by checking process.env.NODE_ENV global variable and adjusting behavior of providers / setting up default context values based on that. We don't want to follow that pattern in the monorepo, so instead we will set up a new package that will provide all the utilities to be able to write unit tests for UI without the need to write excessive amounts of the same bootstrap code over and over again. The goal of the package would be mainly to provide the pre-configured providers that would wrap every "render" method for the testing frameworks we are using. To make sure that the usage is consistent, we will also move all the third party testing library imports to one place. So the rough plan for this ticket is:

      • Set up new compass-testing-library package in the monorepo
      • Add imports and re-export all required testing libraries from one place: @testing-library/react, @testiong-library/react-hooks, @testing-library/dom, @testing-library/user-event, enzyme
        • Export enzyme under its own named export namespace and mark it as @deprecated with JSDoc annotations so that it shows up in IDEs as such on import
      • Create a testing provider component that will include all the providers required by the application and currently using NODE_ENV checks internally
        • In some cases this might require refactoring the hooks also to pick the actual implementations from context so that we can easier provide fallbacks in test environment
      • Wrap default testing library rendering methods (render, renderHook for RTL, mount for enzyme) in a way that always wraps the render in default providers
      • Wrap default testing library cleanup methods (cleanup for RTL, wrapper.unmount for enzyme) in a way that resets all the testing stores and services state if needed (will be required for useTabState, probably for other places that re-export hooks that access redux stores internally)
      • Change all the import from testing-library and enzyme to use new package
      • To make sure we don't regress, introduce new eslint rules
        • Prohibit imports of testing-library and enzyme directly. Point to the new package
        • Prohibit usage of process.env.NODE_ENV in any code in the application

            Assignee:
            Unassigned Unassigned
            Reporter:
            sergey.petushkov@mongodb.com Sergey Petushkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: