Skip to content

Commit c86daa4

Browse files
committed
Add test options support to For.* API
1 parent 271a329 commit c86daa4

1 file changed

Lines changed: 212 additions & 57 deletions

File tree

src/Vitest.res

Lines changed: 212 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -851,113 +851,268 @@ module Each: EachType = {
851851
}
852852

853853
module type ForType = {
854+
let describe: (array<'a>, string, ~timeout: int=?, ('a, testCtx) => unit) => unit
855+
let describeAsync: (array<'a>, string, ~timeout: int=?, ('a, testCtx) => promise<unit>) => unit
856+
854857
let test: (array<'a>, string, ~timeout: int=?, ('a, testCtx) => unit) => unit
855858
let testAsync: (array<'a>, string, ~timeout: int=?, ('a, testCtx) => promise<unit>) => unit
856859

857860
let it: (array<'a>, string, ~timeout: int=?, ('a, testCtx) => unit) => unit
858861
let itAsync: (array<'a>, string, ~timeout: int=?, ('a, testCtx) => promise<unit>) => unit
859-
860-
let describe: (array<'a>, string, ~timeout: int=?, ('a, testCtx) => unit) => unit
861-
let describeAsync: (array<'a>, string, ~timeout: int=?, ('a, testCtx) => promise<unit>) => unit
862862
}
863863

864864
module For: ForType = {
865865
module Ext = {
866+
type describe
866867
type test
867868
type it
868-
type describe
869869

870870
@module("vitest") @val
871-
external test: test = "test"
871+
external describe: describe = "describe"
872872

873873
@module("vitest") @val
874-
external it: it = "it"
874+
external test: test = "test"
875875

876876
@module("vitest") @val
877-
external describe: describe = "describe"
878-
879-
@send
880-
external testObj: (
881-
~test: test,
882-
~cases: array<'a>,
883-
) => (~name: string, ~f: @uncurry ('a, testCtx) => unit, ~timeout: Js.undefined<int>) => unit =
884-
"for"
885-
886-
@send
887-
external testObjAsync: (
888-
~test: test,
889-
~cases: array<'a>,
890-
) => (
891-
~name: string,
892-
~f: @uncurry ('a, testCtx) => promise<unit>,
893-
~timeout: Js.undefined<int>,
894-
) => unit = "for"
895-
896-
@send
897-
external itObj: (
898-
~it: it,
899-
~cases: array<'a>,
900-
) => (~name: string, ~f: @uncurry ('a, testCtx) => unit, ~timeout: Js.undefined<int>) => unit =
901-
"for"
877+
external it: it = "it"
902878

903879
@send
904-
external itObjAsync: (
905-
~it: it,
880+
external describeObj: (
881+
~describe: describe,
906882
~cases: array<'a>,
907883
) => (
908884
~name: string,
909-
~f: @uncurry ('a, testCtx) => promise<unit>,
910-
~timeout: Js.undefined<int>,
885+
~options: testCollectorOptions,
886+
~f: @uncurry ('a, testCtx) => unit,
911887
) => unit = "for"
912888

913-
@send
914-
external describeObj: (
915-
~describe: describe,
916-
~cases: array<'a>,
917-
) => (~name: string, ~f: @uncurry ('a, testCtx) => unit, ~timeout: Js.undefined<int>) => unit =
918-
"for"
919-
920889
@send
921890
external describeObjAsync: (
922891
~describe: describe,
923892
~cases: array<'a>,
924893
) => (
925894
~name: string,
895+
~options: testCollectorOptions,
926896
~f: @uncurry ('a, testCtx) => promise<unit>,
927-
~timeout: Js.undefined<int>,
928897
) => unit = "for"
929898
}
930899

900+
@send
901+
external testObj: (
902+
~test: test,
903+
~cases: array<'a>,
904+
) => (~name: string, ~options: testCollectorOptions, ~f: @uncurry ('a, testCtx) => unit) => unit =
905+
"for"
906+
907+
@send
908+
external testObjAsync: (
909+
~test: test,
910+
~cases: array<'a>,
911+
) => (
912+
~name: string,
913+
~options: testCollectorOptions,
914+
~f: @uncurry ('a, testCtx) => promise<unit>,
915+
) => unit = "for"
916+
917+
@send
918+
external itObj: (
919+
~it: it,
920+
~cases: array<'a>,
921+
) => (~name: string, ~options: testCollectorOptions, ~f: @uncurry ('a, testCtx) => unit) => unit =
922+
"for"
923+
924+
@send
925+
external itObjAsync: (
926+
~it: it,
927+
~cases: array<'a>,
928+
) => (
929+
~name: string,
930+
~options: testCollectorOptions,
931+
~f: @uncurry ('a, testCtx) => promise<unit>,
932+
) => unit = "for"
933+
931934
@inline
932-
let test = (cases, name, ~timeout=?, f) =>
933-
Ext.testObj(~test=Ext.test, ~cases)(~name, ~f, ~timeout=timeout->Js.Undefined.fromOption)
935+
let describe = (
936+
cases,
937+
name,
938+
~timeout=?,
939+
~retry=?,
940+
~repeats=?,
941+
~shuffle=?,
942+
~concurrent=?,
943+
~sequential=?,
944+
~skip=?,
945+
~only=?,
946+
~todo=?,
947+
~fails=?,
948+
f,
949+
) =>
950+
Ext.describeObj(~describe=Ext.describe, ~cases)(
951+
~name,
952+
~options={
953+
?retry,
954+
?repeats,
955+
?shuffle,
956+
?concurrent,
957+
?sequential,
958+
?skip,
959+
?only,
960+
?todo,
961+
?fails,
962+
},
963+
~f,
964+
)
934965

935966
@inline
936-
let testAsync = (cases, name, ~timeout=?, f) =>
937-
Ext.testObjAsync(~test=Ext.test, ~cases)(~name, ~f, ~timeout=timeout->Js.Undefined.fromOption)
967+
let describeAsync = (
968+
cases,
969+
name,
970+
~timeout=?,
971+
~retry=?,
972+
~repeats=?,
973+
~shuffle=?,
974+
~concurrent=?,
975+
~sequential=?,
976+
~skip=?,
977+
~only=?,
978+
~todo=?,
979+
~fails=?,
980+
f,
981+
) =>
982+
Ext.describeObjAsync(~describe=Ext.describe, ~cases)(
983+
~name,
984+
~options={
985+
?retry,
986+
?repeats,
987+
?shuffle,
988+
?concurrent,
989+
?sequential,
990+
?skip,
991+
?only,
992+
?todo,
993+
?fails,
994+
},
995+
~f,
996+
)
938997

939998
@inline
940-
let it = (cases, name, ~timeout=?, f) =>
941-
Ext.itObj(~it=Ext.it, ~cases)(~name, ~f, ~timeout=timeout->Js.Undefined.fromOption)
999+
let test = (
1000+
cases,
1001+
name,
1002+
~timeout=?,
1003+
~retry=?,
1004+
~repeats=?,
1005+
~concurrent=?,
1006+
~sequential=?,
1007+
~skip=?,
1008+
~only=?,
1009+
~todo=?,
1010+
~fails=?,
1011+
f,
1012+
) =>
1013+
Ext.testObj(~test=Ext.test, ~cases)(
1014+
~name,
1015+
~options={
1016+
?retry,
1017+
?repeats,
1018+
?concurrent,
1019+
?sequential,
1020+
?skip,
1021+
?only,
1022+
?todo,
1023+
?fails,
1024+
},
1025+
~f,
1026+
)
9421027

9431028
@inline
944-
let itAsync = (cases, name, ~timeout=?, f) =>
945-
Ext.itObjAsync(~it=Ext.it, ~cases)(~name, ~f, ~timeout=timeout->Js.Undefined.fromOption)
1029+
let testAsync = (
1030+
cases,
1031+
name,
1032+
~timeout=?,
1033+
~retry=?,
1034+
~repeats=?,
1035+
~concurrent=?,
1036+
~sequential=?,
1037+
~skip=?,
1038+
~only=?,
1039+
~todo=?,
1040+
~fails=?,
1041+
f,
1042+
) =>
1043+
Ext.testObjAsync(~test=Ext.test, ~cases)(
1044+
~name,
1045+
~options={
1046+
?retry,
1047+
?repeats,
1048+
?concurrent,
1049+
?sequential,
1050+
?skip,
1051+
?only,
1052+
?todo,
1053+
?fails,
1054+
},
1055+
~f,
1056+
)
9461057

9471058
@inline
948-
let describe = (cases, name, ~timeout=?, f) =>
949-
Ext.describeObj(~describe=Ext.describe, ~cases)(
1059+
let it = (
1060+
cases,
1061+
name,
1062+
~timeout=?,
1063+
~retry=?,
1064+
~repeats=?,
1065+
~concurrent=?,
1066+
~sequential=?,
1067+
~skip=?,
1068+
~only=?,
1069+
~todo=?,
1070+
~fails=?,
1071+
f,
1072+
) =>
1073+
Ext.itObj(~it=Ext.it, ~cases)(
9501074
~name,
1075+
~options={
1076+
?retry,
1077+
?repeats,
1078+
?concurrent,
1079+
?sequential,
1080+
?skip,
1081+
?only,
1082+
?todo,
1083+
?fails,
1084+
},
9511085
~f,
952-
~timeout=timeout->Js.Undefined.fromOption,
9531086
)
9541087

9551088
@inline
956-
let describeAsync = (cases, name, ~timeout=?, f) =>
957-
Ext.describeObjAsync(~describe=Ext.describe, ~cases)(
1089+
let itAsync = (
1090+
cases,
1091+
name,
1092+
~timeout=?,
1093+
~retry=?,
1094+
~repeats=?,
1095+
~concurrent=?,
1096+
~sequential=?,
1097+
~skip=?,
1098+
~only=?,
1099+
~todo=?,
1100+
~fails=?,
1101+
f,
1102+
) =>
1103+
Ext.itObjAsync(~it=Ext.it, ~cases)(
9581104
~name,
1105+
~options={
1106+
?retry,
1107+
?repeats,
1108+
?concurrent,
1109+
?sequential,
1110+
?skip,
1111+
?only,
1112+
?todo,
1113+
?fails,
1114+
},
9591115
~f,
960-
~timeout=timeout->Js.Undefined.fromOption,
9611116
)
9621117
}
9631118

0 commit comments

Comments
 (0)