Fix the upload tests

The current approach wasn't working. Not sure what caused it to stop working,
but anyway that was an hacky import, as evidenced by the ungainly warning
webpack would print on `yarn dev`. So instead of taking the path, we just take
the JSON contents directly, sidestepping all that.

**Tested by**

Rerunning the upload tests
This commit is contained in:
Manav Rathi 2024-03-13 14:25:07 +05:30
parent ccb6a4a283
commit 2faef37f4b
No known key found for this signature in database
2 changed files with 12 additions and 7 deletions

View file

@ -68,7 +68,12 @@
#
# NEXT_PUBLIC_ENTE_FAMILY_PORTAL_ENDPOINT = http://localhost:3003
# The path of the JSON file which contains the expected results of our
# integration tests. See `upload.test.ts` for more details.
# The JSON which describes the expected results of our integration tests. See
# `upload.test.ts` for more details of the expected format.
#
# NEXT_PUBLIC_ENTE_TEST_EXPECTED_JSON_PATH = /path/to/dataset/expected.json
# This is perhaps easier to specify as an environment variable, since then we
# can directly read from the source file when running `yarn dev`. For example,
#
# NEXT_PUBLIC_ENTE_TEST_EXPECTED_JSON=`cat path/to/expected.json` yarn dev
#
# NEXT_PUBLIC_ENTE_TEST_EXPECTED_JSON = {}

View file

@ -100,13 +100,13 @@ const FILE_NAME_TO_JSON_NAME = [
];
export async function testUpload() {
const jsonPath = process.env.NEXT_PUBLIC_ENTE_TEST_EXPECTED_JSON_PATH;
if (!jsonPath) {
const jsonString = process.env.NEXT_PUBLIC_ENTE_TEST_EXPECTED_JSON;
if (!jsonString) {
throw Error(
"Please specify the NEXT_PUBLIC_ENTE_TEST_EXPECTED_JSON_PATH to run the upload tests",
"Please specify the NEXT_PUBLIC_ENTE_TEST_EXPECTED_JSON to run the upload tests",
);
}
const expectedState = await import(jsonPath);
const expectedState = JSON.parse(jsonString);
if (!expectedState) {
throw Error("upload test failed expectedState missing");
}