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: tests for Jest 27 #10

Merged
merged 6 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@
(melange
(>= "2.0.0"))
(reason :with-test)
(melange-webapi :with-test)
(opam-check-npm-deps :with-test) ; todo: use with-dev-setup once opam 2.2 is out
(ocaml-lsp-server :with-test)))
(melange-webapi :with-test)))
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

src = ./.;
dontNpmBuild = true;
npmDepsHash = "sha256-FJEGqD2SwkGur+dSWtMW1Jr3Rmh68nQGUtEoprkXSfo=";
npmDepsHash = "sha256-ssHwcub4A3tHvpQ929o9qImgHjmHNEsP6waQIrT1jUE=";
installPhase = ''
runHook preInstall
mkdir -p "$out"
Expand Down
8 changes: 8 additions & 0 deletions jest-dom/__tests__/jest_dom_test.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[@@@mel.config { flags = [| "--preamble";
{|
/**
* @jest-environment jsdom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be added in jest.config.js? Or is it beneficial to keep it here for more accuracy?

*/
|}
|] }]

open Jest
open JestDom
open Webapi.Dom
Expand Down
6 changes: 4 additions & 2 deletions jest/__tests__/globals_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ let () =
);

describe "timeout should not fail suite" (fun () ->
afterAllAsync ~timeout:1 (fun _ ->());
(* In jest 27, they do. *)
(* afterAllAsync ~timeout:3 (fun _ ->()); *)

test "" (fun () -> pass); (* runner will crash if there's no tests *)
);
Expand Down Expand Up @@ -267,7 +268,8 @@ let () =
);

describe "timeout should not fail suite" (fun () ->
afterAllPromise ~timeout:1 (fun () -> Js.Promise.make (fun ~resolve:_ ~reject:_ -> ()));
(* In jest 27, they do. *)
(* afterAllPromise ~timeout:1 (fun () -> Js.Promise.make (fun ~resolve:_ ~reject:_ -> ())); *)

test "" (fun () -> pass); (* runner will crash if there's no tests *)
);
Expand Down
10 changes: 5 additions & 5 deletions jest/__tests__/jest_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe "Fake Timers" (fun () ->

test "runAllImmediates" (fun () ->
let flag = ref false in
Jest.useFakeTimers ();
Jest.useFakeTimers ~config:{legacyFakeTimers=true} ();
setImmediate (fun () -> flag := true);
let before = !flag in
Jest.runAllImmediates ();
Expand All @@ -44,10 +44,10 @@ describe "Fake Timers" (fun () ->
Jest.useFakeTimers ();
setTimeout (fun () -> flag := true) 1500;
let before = !flag in
Jest.runTimersToTime 1000;
Jest.advanceTimersByTime 1000;
let inbetween = !flag in
Jest.runTimersToTime 1000;
Jest.advanceTimersByTime 1000;

expect (before, inbetween, !flag) = (false, false, true)
);

Expand Down Expand Up @@ -90,6 +90,6 @@ describe "Fake Timers" (fun () ->
testAsync "clearAllTimers" (fun finish ->
Jest.useFakeTimers ();
Jest.useRealTimers ();
setImmediate (fun () -> finish pass);
nextTick (fun () -> finish pass);
);
);
6 changes: 4 additions & 2 deletions jest/__tests__/runner_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ let () =
);

describe "timeout should not fail suite" (fun () ->
afterAllAsync ~timeout:1 (fun _ ->());
(* In jest 27, they do. *)
(* afterAllAsync ~timeout:1 (fun _ ->()); *)

test "" (fun () -> true); (* runner will crash if there's no tests *)
);
Expand Down Expand Up @@ -262,7 +263,8 @@ let () =
);

describe "timeout should not fail suite" (fun () ->
afterAllPromise ~timeout:1 (fun () -> Js.Promise.make (fun ~resolve:_ ~reject:_ -> ()));
(* In jest 27, they do. *)
(* afterAllPromise ~timeout:1 (fun () -> Js.Promise.make (fun ~resolve:_ ~reject:_ -> ())); *)

test "" (fun () -> true); (* runner will crash if there's no tests *)
);
Expand Down
6 changes: 4 additions & 2 deletions jest/jest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,12 @@ module Jest = struct
external runAllTicks : unit -> unit = "jest.runAllTicks"
external runAllTimers : unit -> unit = "jest.runAllTimers"
external runAllImmediates : unit -> unit = "jest.runAllImmediates"
external runTimersToTime : int -> unit = "jest.runTimersToTime"
external advanceTimersByTime : int -> unit = "jest.advanceTimersByTime"
external runOnlyPendingTimers : unit -> unit = "jest.runOnlyPendingTimers"
external useFakeTimers : unit -> unit = "jest.useFakeTimers"
type fakeTimersConfig = {
legacyFakeTimers: bool
}
external useFakeTimers : ?config:fakeTimersConfig -> unit -> unit = "jest.useFakeTimers"
external useRealTimers : unit -> unit = "jest.useRealTimers"
end

Expand Down
6 changes: 4 additions & 2 deletions jest/jest.mli
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ module Jest : sig
external runAllTicks : unit -> unit = "jest.runAllTicks"
external runAllTimers : unit -> unit = "jest.runAllTimers"
external runAllImmediates : unit -> unit = "jest.runAllImmediates"
external runTimersToTime : int -> unit = "jest.runTimersToTime"
external advanceTimersByTime : int -> unit = "jest.advanceTimersByTime"
external runOnlyPendingTimers : unit -> unit = "jest.runOnlyPendingTimers"
external useFakeTimers : unit -> unit = "jest.useFakeTimers"
type fakeTimersConfig = {
legacyFakeTimers: bool
}
external useFakeTimers : ?config:fakeTimersConfig -> unit -> unit = "jest.useFakeTimers"
external useRealTimers : unit -> unit = "jest.useRealTimers"
end

Expand Down
3 changes: 2 additions & 1 deletion melange-jest.opam.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
depexts: [
["jest"] {npm-version = "^26.5.2"}
["jest"] {npm-version = "^27.0.0"}
["jest-environment-jsdom"] {npm-version = "^27.0.0"}
["@testing-library/jest-dom"] {npm-version = "^5.10.0"}
]

Loading
Loading