PolicyEngine / policyengine-app

PolicyEngine's free web app for computing the impact of public policy.
GNU Affero General Public License v3.0
35 stars 89 forks source link

Add utility function in Jest setup that fetches US and UK metadata #1450

Closed anth-volk closed 2 weeks ago

anth-volk commented 2 months ago

This is used in various places in the tests, so it would be great to have just one fetch at the start, before all tests

czhou578 commented 3 weeks ago

@anth-volk, what do you mean by "start"?

anth-volk commented 3 weeks ago

@czhou578 At present, for any tests that require metadata, we use a beforeAll to fetch the metadata for the entire test file. While this means that we only need to fetch once for one file (e.g., PolicyRightSidebar.test.js), it has two disadvantages:

  1. It only works for that file; if 10 test files need metadata, 10 fetches are executed
  2. It is guaranteed to finish before all test declarations in the file, but not before all describe blocks - data declared inside the describe, for use within all tests inside of it, cannot access the fetched data

Ultimately, we're using the same metadata for every test file. It would be great to have an order of execution whereby the metadata is fetched, then given to all test files, meaning that every run of the test suite would result in just one metadata fetch.

czhou578 commented 3 weeks ago

@anth-volk, just to confirm, I'm seeing some test files that are fetching the metadata not in a beforeAll clause, but within the test clause, as shown in the image. Do you want me to leave that as it is? image

anth-volk commented 3 weeks ago

Shoot, actually, could you change that? That's not what this issue refers to, but it would be good to fix that, as well.

anth-volk commented 3 weeks ago

Out of curiosity, though, have you determined a way to fetch before all test files? Ideally, this would function in some sort of separate setup file, before the tests, the describe blocks, etc.

czhou578 commented 3 weeks ago

Ok. I guess I can change that. I believe I have found a way to run that fetch metadata function before all the test suites. I'm using the setupFilesAfterEnv property in the jest.config.js to run a new file I created that has the fetching logic included. I'll open a PR for you soon so you can check.