Skip to content

Commit

Permalink
tests passed. converted to curried callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
dsiu committed Dec 1, 2023
1 parent fae413c commit 87cbdb1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 57 deletions.
8 changes: 4 additions & 4 deletions __tests__/globals_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let () = {
describe("beforeAll", () => {
let x = ref(0)

beforeAll(() => x := x.contents + 4)
beforeAll((. ()) => x := x.contents + 4)

test("x is 4", () =>
if x.contents === 4 {
Expand Down Expand Up @@ -232,7 +232,7 @@ let () = {
describe("beforeEach", () => {
let x = ref(0)

beforeEach(() => x := x.contents + 4)
beforeEach((. ()) => x := x.contents + 4)

test("x is 4", () =>
if x.contents === 4 {
Expand Down Expand Up @@ -390,7 +390,7 @@ let () = {
let x = ref(0)

describe("phase 1", () => {
afterAll(() => x := x.contents + 4)
afterAll((. ()) => x := x.contents + 4)

test(
"x is 0",
Expand Down Expand Up @@ -640,7 +640,7 @@ let () = {
describe("afterEach", () => {
let x = ref(0)

afterEach(() => x := x.contents + 4)
afterEach((. ()) => x := x.contents + 4)

test("x is 0", () =>
if x.contents === 0 {
Expand Down
10 changes: 5 additions & 5 deletions __tests__/runner_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Promise = Js.Promise2

include Jest.Runner({
type t<_> = bool
let affirm = ok => assert ok
let affirm = ok => assert(ok)
})

let () = {
Expand Down Expand Up @@ -50,7 +50,7 @@ let () = {
describe("beforeAll", () => {
let x = ref(0)

beforeAll(() => x := x.contents + 4)
beforeAll((. ()) => x := x.contents + 4)

test("x is 4", () => x.contents === 4)
test("x is still 4", () => x.contents === 4)
Expand Down Expand Up @@ -133,7 +133,7 @@ let () = {
describe("beforeEach", () => {
let x = ref(0)

beforeEach(() => x := x.contents + 4)
beforeEach((. ()) => x := x.contents + 4)

test("x is 4", () => x.contents === 4)
test("x is suddenly 8", () => x.contents === 8)
Expand Down Expand Up @@ -217,7 +217,7 @@ let () = {
let x = ref(0)

describe("phase 1", () => {
afterAll(() => x := x.contents + 4)
afterAll((. ()) => x := x.contents + 4)

test("x is 0", () => x.contents === 0)
test("x is still 0", () => x.contents === 0)
Expand Down Expand Up @@ -329,7 +329,7 @@ let () = {
describe("afterEach", () => {
let x = ref(0)

afterEach(() => x := x.contents + 4)
afterEach((. ()) => x := x.contents + 4)

test("x is 0", () => x.contents === 0)
test("x is suddenly 4", () => x.contents === 4)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@babel/core": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"babel-jest": "^27.3.1",
"rescript": "^11.0.0-rc.4"
"rescript": "^11.0.0-rc.6"
},
"dependencies": {
"jest": "^27.3.1"
Expand Down
73 changes: 34 additions & 39 deletions src/jest.res
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,26 @@ module LLExpect: {

module Runner = (A: Asserter) => {
let affirm = A.affirm
@val external _test: (string, @uncurry (unit => Js.undefined<unit>)) => unit = "test"
@val external _test: (string, (. unit) => Js.undefined<unit>) => unit = "test"
@val
external _testAsync: (
string,
((. unit) => unit) => Js.undefined<unit>,
(. (. unit) => unit) => Js.undefined<unit>,
Js.Undefined.t<int>,
) => unit = "test"
@val
external _testPromise: (string, @uncurry (unit => promise<'a>), Js.Undefined.t<int>) => unit =
"test"
external _testPromise: (string, (. unit) => promise<'a>, Js.Undefined.t<int>) => unit = "test"

let test = (name, callback) =>
_test(name, () => {
_test(name, (. ()) => {
affirm(callback())
Js.undefined
})

let testAsync = (name, ~timeout=?, callback) =>
_testAsync(
name,
finish => {
(. finish) => {
callback(case => {
affirm(case)
finish(.)
Expand All @@ -168,13 +167,13 @@ module Runner = (A: Asserter) => {
let testPromise = (name, ~timeout=?, callback) =>
_testPromise(
name,
() => Promise.then(callback(), a => a->A.affirm->Promise.resolve),
(. ()) => Promise.then(callback(), a => a->A.affirm->Promise.resolve),
Js.Undefined.fromOption(timeout),
)

let testAll = (name, inputs, callback) => List.iter(input => {
let name = `${name} - ${input->Js.String.make}`
_test(name, () => {
_test(name, (. ()) => {
affirm(callback(input))
Js.undefined
})
Expand All @@ -184,19 +183,19 @@ module Runner = (A: Asserter) => {
let name = `${name} - ${input->Js.String.make}`
_testPromise(
name,
() => Promise.then(callback(input), a => a->A.affirm->Promise.resolve),
(. ()) => Promise.then(callback(input), a => a->A.affirm->Promise.resolve),
Js.Undefined.fromOption(timeout),
)
}, inputs)

@val external describe: (string, @uncurry (unit => Js.undefined<unit>)) => unit = "describe"
@val external describe: (string, (. unit) => Js.undefined<unit>) => unit = "describe"
let describe = (label, f) =>
describe(label, () => {
describe(label, (. ()) => {
f()
Js.undefined
})

@val external beforeAll: (@uncurry (unit => unit)) => unit = "beforeAll"
@val external beforeAll: ((. unit) => unit) => unit = "beforeAll"
@val
external beforeAllAsync: (((. unit) => unit) => Js.undefined<unit>, Js.Undefined.t<int>) => unit =
"beforeAll"
Expand All @@ -205,12 +204,11 @@ module Runner = (A: Asserter) => {
Js.undefined
}, Js.Undefined.fromOption(timeout))
@val
external beforeAllPromise: (@uncurry (unit => promise<'a>), Js.Undefined.t<int>) => unit =
"beforeAll"
external beforeAllPromise: (. (. unit) => promise<'a>, Js.Undefined.t<int>) => unit = "beforeAll"
let beforeAllPromise = (~timeout=?, callback) =>
beforeAllPromise(() => Promise.resolve(callback()), Js.Undefined.fromOption(timeout))
beforeAllPromise((. ()) => Promise.resolve(callback()), Js.Undefined.fromOption(timeout))

@val external beforeEach: (@uncurry (unit => unit)) => unit = "beforeEach"
@val external beforeEach: ((. unit) => unit) => unit = "beforeEach"
@val
external beforeEachAsync: (
((. unit) => unit) => Js.undefined<unit>,
Expand All @@ -221,12 +219,11 @@ module Runner = (A: Asserter) => {
Js.undefined
}, Js.Undefined.fromOption(timeout))
@val
external beforeEachPromise: (@uncurry (unit => promise<'a>), Js.Undefined.t<int>) => unit =
"beforeEach"
external beforeEachPromise: ((. unit) => promise<'a>, Js.Undefined.t<int>) => unit = "beforeEach"
let beforeEachPromise = (~timeout=?, callback) =>
beforeEachPromise(() => Promise.resolve(callback()), Js.Undefined.fromOption(timeout))
beforeEachPromise((. ()) => Promise.resolve(callback()), Js.Undefined.fromOption(timeout))

@val external afterAll: (@uncurry (unit => unit)) => unit = "afterAll"
@val external afterAll: ((. unit) => unit) => unit = "afterAll"
@val
external afterAllAsync: (((. unit) => unit) => Js.undefined<unit>, Js.Undefined.t<int>) => unit =
"afterAll"
Expand All @@ -235,12 +232,11 @@ module Runner = (A: Asserter) => {
Js.undefined
}, Js.Undefined.fromOption(timeout))
@val
external afterAllPromise: (@uncurry (unit => promise<'a>), Js.Undefined.t<int>) => unit =
"afterAll"
external afterAllPromise: ((. unit) => promise<'a>, Js.Undefined.t<int>) => unit = "afterAll"
let afterAllPromise = (~timeout=?, callback) =>
afterAllPromise(() => Promise.resolve(callback()), Js.Undefined.fromOption(timeout))
afterAllPromise((. ()) => Promise.resolve(callback()), Js.Undefined.fromOption(timeout))

@val external afterEach: (@uncurry (unit => unit)) => unit = "afterEach"
@val external afterEach: ((. unit) => unit) => unit = "afterEach"
@val
external afterEachAsync: (((. unit) => unit) => Js.undefined<unit>, Js.Undefined.t<int>) => unit =
"afterEach"
Expand All @@ -249,25 +245,24 @@ module Runner = (A: Asserter) => {
Js.undefined
}, Js.Undefined.fromOption(timeout))
@val
external afterEachPromise: (@uncurry (unit => promise<'a>), Js.Undefined.t<int>) => unit =
"afterEach"
external afterEachPromise: ((. unit) => promise<'a>, Js.Undefined.t<int>) => unit = "afterEach"
let afterEachPromise = (~timeout=?, callback) =>
afterEachPromise(() => Promise.resolve(callback()), Js.Undefined.fromOption(timeout))
afterEachPromise((. ()) => Promise.resolve(callback()), Js.Undefined.fromOption(timeout))

module Only = {
@val external _test: (string, @uncurry (unit => Js.undefined<unit>)) => unit = "it.only"
@val external _test: (string, (. unit) => Js.undefined<unit>) => unit = "it.only"
@val
external _testAsync: (
string,
((. unit) => unit) => Js.undefined<unit>,
Js.Undefined.t<int>,
) => unit = "it.only"
@val
external _testPromise: (string, @uncurry (unit => promise<'a>), Js.Undefined.t<int>) => unit =
external _testPromise: (string, (. unit) => promise<'a>, Js.Undefined.t<int>) => unit =
"it.only"

let test = (name, callback) =>
_test(name, () => {
_test(name, (. ()) => {
affirm(callback())
Js.undefined
})
Expand All @@ -288,13 +283,13 @@ module Runner = (A: Asserter) => {
let testPromise = (name, ~timeout=?, callback) =>
_testPromise(
name,
() => Promise.then(callback(), a => a->affirm->Promise.resolve),
(. ()) => Promise.then(callback(), a => a->affirm->Promise.resolve),
Js.Undefined.fromOption(timeout),
)

let testAll = (name, inputs, callback) => List.iter(input => {
let name = `${name} - ${input->Js.String.make}`
_test(name, () => {
_test(name, (. ()) => {
affirm(callback(input))
Js.undefined
})
Expand All @@ -304,26 +299,26 @@ module Runner = (A: Asserter) => {
let name = `${name} - ${input->Js.String.make}`
_testPromise(
name,
() => Promise.then(callback(input), a => a->A.affirm->Promise.resolve),
(. ()) => Promise.then(callback(input), a => a->A.affirm->Promise.resolve),
Js.Undefined.fromOption(timeout),
)
}, inputs)

@val
external describe: (string, @uncurry (unit => Js.undefined<unit>)) => unit = "describe.only"
external describe: (string, (. unit) => Js.undefined<unit>) => unit = "describe.only"
let describe = (label, f) =>
describe(label, () => {
describe(label, (. ()) => {
f()
Js.undefined
})
}

module Skip = {
@val external test: (string, @uncurry (unit => A.t<'a>)) => unit = "it.skip"
@val external test: (string, unit => A.t<'a>) => unit = "it.skip"
@val external testAsync: (string, (A.t<'a> => unit) => unit) => unit = "it.skip"
let testAsync = (name, ~timeout as _=?, callback) => testAsync(name, callback)
@val
external testPromise: (string, @uncurry (unit => promise<A.t<'a>>)) => unit = "it.skip"
external testPromise: (string, unit => promise<A.t<'a>>) => unit = "it.skip"
let testPromise = (name, ~timeout as _=?, callback) => testPromise(name, callback)
let testAll = (name, inputs, callback) => List.iter(input => {
let name = `${name} - ${input->Js.String.make}`
Expand All @@ -334,9 +329,9 @@ module Runner = (A: Asserter) => {
testPromise(name, () => callback(input))
}, inputs)
@val
external describe: (string, @uncurry (unit => Js.undefined<unit>)) => unit = "describe.skip"
external describe: (string, (. unit) => Js.undefined<unit>) => unit = "describe.skip"
let describe = (label, f) =>
describe(label, () => {
describe(label, (. ()) => {
f()
Js.undefined
})
Expand Down
16 changes: 8 additions & 8 deletions src/jest.resi
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ module Runner: (A: Asserter) =>

let describe: (string, unit => unit) => unit

@val external beforeAll: (@uncurry (unit => unit)) => unit = "beforeAll"
@val external beforeAll: ((. unit) => unit) => unit = "beforeAll"
let beforeAllAsync: (~timeout: int=?, (unit => unit) => unit) => unit
let beforeAllPromise: (~timeout: int=?, unit => promise<'a>) => unit
@val external beforeEach: (@uncurry (unit => unit)) => unit = "beforeEach"
@val external beforeEach: ((. unit) => unit) => unit = "beforeEach"
let beforeEachAsync: (~timeout: int=?, (unit => unit) => unit) => unit
let beforeEachPromise: (~timeout: int=?, unit => promise<'a>) => unit
@val external afterAll: (@uncurry (unit => unit)) => unit = "afterAll"
@val external afterAll: ((. unit) => unit) => unit = "afterAll"
let afterAllAsync: (~timeout: int=?, (unit => unit) => unit) => unit
let afterAllPromise: (~timeout: int=?, unit => promise<'a>) => unit
@val external afterEach: (@uncurry (unit => unit)) => unit = "afterEach"
@val external afterEach: ((. unit) => unit) => unit = "afterEach"
let afterEachAsync: (~timeout: int=?, (unit => unit) => unit) => unit
let afterEachPromise: (~timeout: int=?, unit => promise<'a>) => unit

Expand Down Expand Up @@ -55,16 +55,16 @@ let testAllPromise: (string, list<'a>, ~timeout: int=?, 'a => promise<assertion>

let describe: (string, unit => unit) => unit

@val external beforeAll: (@uncurry (unit => unit)) => unit = "beforeAll"
@val external beforeAll: ((. unit) => unit) => unit = "beforeAll"
let beforeAllAsync: (~timeout: int=?, (unit => unit) => unit) => unit
let beforeAllPromise: (~timeout: int=?, unit => promise<'a>) => unit
@val external beforeEach: (@uncurry (unit => unit)) => unit = "beforeEach"
@val external beforeEach: ((. unit) => unit) => unit = "beforeEach"
let beforeEachAsync: (~timeout: int=?, (unit => unit) => unit) => unit
let beforeEachPromise: (~timeout: int=?, unit => promise<'a>) => unit
@val external afterAll: (@uncurry (unit => unit)) => unit = "afterAll"
@val external afterAll: ((. unit) => unit) => unit = "afterAll"
let afterAllAsync: (~timeout: int=?, (unit => unit) => unit) => unit
let afterAllPromise: (~timeout: int=?, unit => promise<'a>) => unit
@val external afterEach: (@uncurry (unit => unit)) => unit = "afterEach"
@val external afterEach: ((. unit) => unit) => unit = "afterEach"
let afterEachAsync: (~timeout: int=?, (unit => unit) => unit) => unit
let afterEachPromise: (~timeout: int=?, unit => promise<'a>) => unit

Expand Down

0 comments on commit 87cbdb1

Please sign in to comment.