Page MenuHomePhabricator

[Cashtab] Create a standardized wrapper for test rendering
ClosedPublic

Authored by bytesofman on Feb 13 2024, 01:13.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABCc594e39242bb: [Cashtab] Create a standardized wrapper for test rendering
Summary

Depends on D15429

Create a standardized wrapper to make it easier to add and edit tests (and make sure they are all testing the same thing).

Test Plan

npm test

Diff Detail

Repository
rABC Bitcoin ABC
Branch
improve-cashtab-test-org
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 27127
Build 53820: Build Diffcashtab-tests
Build 53819: arc lint + arc unit

Event Timeline

Tail of the build log:

    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)

FAIL src/slpv1/__tests__/index.test.js
  ● Test suite failed to run

    ReferenceError: structuredClone is not defined

      13 |         this.global.Uint8Array = Uint8Array;
      14 |         this.global.ArrayBuffer = ArrayBuffer;
    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)

FAIL src/components/Etokens/__tests__/CreateTokenForm.test.js
  ● Test suite failed to run

    ReferenceError: structuredClone is not defined

      13 |         this.global.Uint8Array = Uint8Array;
      14 |         this.global.ArrayBuffer = ArrayBuffer;
    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)

FAIL src/components/Home/__tests__/Home.test.js
  ● Test suite failed to run

    ReferenceError: structuredClone is not defined

      13 |         this.global.Uint8Array = Uint8Array;
      14 |         this.global.ArrayBuffer = ArrayBuffer;
    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)


Test Suites: 31 failed, 31 total
Tests:       0 total
Snapshots:   0 total
Time:        5.655 s
Ran all test suites.
Build cashtab-tests failed with exit code 1

Tail of the build log:

    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)

FAIL src/components/Home/__tests__/Home.test.js
  ● Test suite failed to run

    ReferenceError: structuredClone is not defined

      13 |         this.global.Uint8Array = Uint8Array;
      14 |         this.global.ArrayBuffer = ArrayBuffer;
    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)

FAIL src/components/Common/__tests__/ScanQRCode.test.js
  ● Test suite failed to run

    ReferenceError: structuredClone is not defined

      13 |         this.global.Uint8Array = Uint8Array;
      14 |         this.global.ArrayBuffer = ArrayBuffer;
    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)

FAIL src/components/Home/__tests__/Tx.test.js
  ● Test suite failed to run

    ReferenceError: structuredClone is not defined

      13 |         this.global.Uint8Array = Uint8Array;
      14 |         this.global.ArrayBuffer = ArrayBuffer;
    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)


Test Suites: 31 failed, 31 total
Tests:       0 total
Snapshots:   0 total
Time:        5.402 s
Ran all test suites.
Build cashtab-tests failed with exit code 1

Tail of the build log:

    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)

FAIL src/slpv1/__tests__/index.test.js
  ● Test suite failed to run

    ReferenceError: structuredClone is not defined

      13 |         this.global.Uint8Array = Uint8Array;
      14 |         this.global.ArrayBuffer = ArrayBuffer;
    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)

FAIL src/components/Etokens/__tests__/CreateTokenForm.test.js
  ● Test suite failed to run

    ReferenceError: structuredClone is not defined

      13 |         this.global.Uint8Array = Uint8Array;
      14 |         this.global.ArrayBuffer = ArrayBuffer;
    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)

FAIL src/components/Home/__tests__/Home.test.js
  ● Test suite failed to run

    ReferenceError: structuredClone is not defined

      13 |         this.global.Uint8Array = Uint8Array;
      14 |         this.global.ArrayBuffer = ArrayBuffer;
    > 15 |     }
         |      ^
      16 |
      17 |     async teardown() {
      18 |         await super.teardown();

      at new CustomEnvironment (config/jest/custom-environment.js:15:35)


Test Suites: 31 failed, 31 total
Tests:       0 total
Snapshots:   0 total
Time:        5.431 s
Ran all test suites.
Build cashtab-tests failed with exit code 1
The build failed due to an unexpected infrastructure outage. The administrators have been notified to investigate. Sorry for the inconvenience.

the toStrictEqual to toEqual change is I think related to the jsdom change from previous diff -- probably some issue with the exact storage type of localforage vs the objects used as mocks here.

should be its own diff or better explained here

cashtab/src/components/__tests__/AppIntegrations.test.js
180 ↗(On Diff #45268)

weirdly, I can avoid the toStrictEqual -> toEqual changes if I include the App component in the scope of this test file.

i.e., if i include import App from 'components/App'; at the top of this file -- even though the linter notes that it is unused.

I am not able to determine what toStrictEqual starts missing when tests fail, i.e.

const storedContacts = await localforage.getItem('contactList');
        console.log(`storedContacts`, storedContacts);
        console.log(`initialContactList`, initialContactList);
        console.log(`typeof storedContacts`, typeof storedContacts);
        console.log(`typeof initialContactList`, typeof initialContactList);
        console.log(
            `storedContacts`,
            Object.getOwnPropertyDescriptors(storedContacts),
        );
        console.log(
            `Object.getPrototypeOf(storedContacts)`,
            Object.getPrototypeOf(storedContacts),
        );
        console.log(
            `initialContactList`,
            Object.getOwnPropertyDescriptors(initialContactList),
        );
        console.log(
            `Object.getPrototypeOf(initialContactList)`,
            Object.getPrototypeOf(initialContactList),
        );

everything is the same.

For the purposes of the test, toEqual is fine. It seems like this issue is being caused by yet another jest / library issue. I'm not able to find any info on it.

imo the advantage gained by this simplification -- which will be implemented throughout the app and probably result in additional "gotchas" like this -- is worth it. The aim is to standardize all of the test files and approaches to make sure we are testing the test and not the implementation.

will standardize tests with the chronik mock first -- then try this diff throughout the app and see if there is any other weird behavior

I'm able to repeat this strange phenomenon -- useStrictEqual fails bc data serializes to the same string when testing any element by routing the wrapped <App/> component without that element in scope. Same thing exhibited while refactoring the configure tests.

This is a weird behavior. However, the goal of this diff is to make all integration tests

  1. As close to the actual app as possible (which this does, by mimicking everything about index.js except we use a MemoryRouter, which is required for testing
  2. The same for all integration tests

There appears to be a JSDOM impact when we get to an out-of-scope component through routing through App vs importing it directly. Well, we could have this same impact in the prod app.

Since tests should be as close as possible to the prod app, and standardized, and toEqual is still an acceptable check for the prod app -- this improvement is still worth it.

PiRK added a subscriber: PiRK.

I don't really understand the issue with toStrictEqual, but it seems that toEqual is a good enough test for comparing these simple contact data structures.
Other than that, this diff adds test coverage and removes boilerplate code, which is all good.

This revision is now accepted and ready to land.Feb 16 2024, 09:12