Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix occassional failure of javascript tests #5011

Merged
merged 1 commit into from
Sep 27, 2023
Merged

Conversation

jorg-vr
Copy link
Contributor

@jorg-vr jorg-vr commented Sep 26, 2023

This pull request fixes the occasional failure of javascript tests.

One test tends to fail on document.querySelector("meta[name=\"csrf-token\"]") being undefined. This probably depends on whether or not another test sets this value.

I do not think the code should fail on absence of this variable, so I fixed that instead of also setting the variable within the specific test.

For future reference, the test error log: (The second failure is caused by the first error)

FAIL test/javascript/code_listing.test.ts (92.957 s)
  ● empty form should close on click outside

    TypeError: Cannot read properties of null (reading 'content')

      127 | function fetch(url: URL | RequestInfo, options: RequestInit = {}): Promise<Response> {
      128 |     const headers = options.headers || {};
    > 129 |     headers["x-csrf-token"] = headers["x-csrf-token"] || (document.querySelector("meta[name=\"csrf-token\"]") as HTMLMetaElement).content;
          |                                                                                                                                  ^
      130 |     headers["x-requested-with"] = headers["x-requested-with"] || "XMLHttpRequest";
      131 |     options["headers"] = headers;
      132 |     return window.fetch(url, options);

      at fetch (app/assets/javascripts/utilities.ts:129:130)
      at EventTarget.<anonymous> (app/assets/javascripts/state/SavedAnnotations.ts:38:37)
      at app/assets/javascripts/state/SavedAnnotations.ts:3095:40
      at Object.<anonymous>.__awaiter (app/assets/javascripts/state/SavedAnnotations.ts:3044:10)
      at EventTarget.fetchList (app/assets/javascripts/state/SavedAnnotations.ts:3195:12)
      at app/assets/javascripts/state/SavedAnnotations.ts:72:22
      at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:516:19)

  ● form should not close when it has content

    expect(received).toBe(expected) // Object.is equality

    Expected: 1
    Received: 0

      387 |     const annotationButton: HTMLButtonElement = document.querySelector(".annotation-button .btn");
      388 |     await userEvent.click(annotationButton);
    > 389 |     expect(document.querySelectorAll("d-annotation-form").length).toBe(1);
          |                                                                   ^
      390 |     await userEvent.click(document.body);
      391 |     expect(document.querySelectorAll("d-annotation-form").length).toBe(0);
      392 | });

      at test/javascript/code_listing.test.ts:389:67
      at fulfilled (test/javascript/code_listing.test.ts:5:58)

@jorg-vr jorg-vr added the bug Something isn't working label Sep 26, 2023
@jorg-vr jorg-vr requested a review from a team as a code owner September 26, 2023 13:06
@jorg-vr jorg-vr self-assigned this Sep 26, 2023
@jorg-vr jorg-vr requested review from bmesuere and niknetniko and removed request for a team September 26, 2023 13:06
@bmesuere bmesuere added chore Repository/build/dependency maintenance and removed bug Something isn't working labels Sep 26, 2023
@jorg-vr jorg-vr merged commit 2b0338b into main Sep 27, 2023
17 checks passed
@jorg-vr jorg-vr deleted the fix/javascript-tests branch September 27, 2023 08:29
@jorg-vr jorg-vr temporarily deployed to naos September 27, 2023 08:29 — with GitHub Actions Inactive
@jorg-vr jorg-vr temporarily deployed to production September 27, 2023 08:33 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Repository/build/dependency maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants