@glennsl/rescript-jest
Version:
Rescript bindings to the Jest testing framework
991 lines (901 loc) • 22.8 kB
JavaScript
;
let Stdlib_List = require("@rescript/runtime/lib/js/Stdlib_List.js");
function mapMod(f, x) {
if (x.NAME === "Just") {
return {
NAME: "Just",
VAL: f(x.VAL)
};
} else {
return {
NAME: "Not",
VAL: f(x.VAL)
};
}
}
let objectContaining = (function (properties) {
var spec = {};
properties.forEach(function (property) {
spec[property] = expect.anything();
});
return spec;
});
function affirm(x) {
if (typeof x !== "object") {
return;
}
switch (x.TAG) {
case "Fail" :
fail(x._0);
return;
case "ArrayContains" :
let match = x._0;
if (match.NAME === "Just") {
let match$1 = match.VAL;
return expect(match$1[0]).toContain(match$1[1]);
}
let match$2 = match.VAL;
return expect(match$2[0]).not.toContain(match$2[1]);
case "ArrayContainsEqual" :
let match$3 = x._0;
if (match$3.NAME === "Just") {
let match$4 = match$3.VAL;
return expect(match$4[0]).toContainEqual(match$4[1]);
}
let match$5 = match$3.VAL;
return expect(match$5[0]).not.toContainEqual(match$5[1]);
case "ArrayLength" :
let match$6 = x._0;
if (match$6.NAME === "Just") {
let match$7 = match$6.VAL;
return expect(match$7[0]).toHaveLength(match$7[1]);
}
let match$8 = match$6.VAL;
return expect(match$8[0]).not.toHaveLength(match$8[1]);
case "ArraySuperset" :
let match$9 = x._0;
if (match$9.NAME === "Just") {
let match$10 = match$9.VAL;
return expect(match$10[0]).toEqual(expect.arrayContaining(match$10[1]));
}
let match$11 = match$9.VAL;
return expect(match$11[0]).not.toEqual(expect.arrayContaining(match$11[1]));
case "Be" :
let match$12 = x._0;
if (match$12.NAME === "Just") {
let match$13 = match$12.VAL;
return expect(match$13[0]).toBe(match$13[1]);
}
let match$14 = match$12.VAL;
return expect(match$14[0]).not.toBe(match$14[1]);
case "Equal" :
let match$15 = x._0;
if (match$15.NAME === "Just") {
let match$16 = match$15.VAL;
return expect(match$16[0]).toEqual(match$16[1]);
}
let match$17 = match$15.VAL;
return expect(match$17[0]).not.toEqual(match$17[1]);
case "FloatCloseTo" :
let match$18 = x._0;
if (match$18.NAME === "Just") {
let match$19 = match$18.VAL;
return expect(match$19[0]).toBeCloseTo(match$19[1]);
}
let match$20 = match$18.VAL;
return expect(match$20[0]).not.toBeCloseTo(match$20[1]);
case "FloatSoCloseTo" :
let match$21 = x._0;
if (match$21.NAME === "Just") {
let match$22 = match$21.VAL;
return expect(match$22[0]).toBeCloseTo(match$22[1], match$22[2]);
}
let match$23 = match$21.VAL;
return expect(match$23[0]).not.toBeCloseTo(match$23[1], match$23[2]);
case "GreaterThan" :
let match$24 = x._0;
if (match$24.NAME === "Just") {
let match$25 = match$24.VAL;
return expect(match$25[0]).toBeGreaterThan(match$25[1]);
}
let match$26 = match$24.VAL;
return expect(match$26[0]).not.toBeGreaterThan(match$26[1]);
case "GreaterThanOrEqual" :
let match$27 = x._0;
if (match$27.NAME === "Just") {
let match$28 = match$27.VAL;
return expect(match$28[0]).toBeGreaterThanOrEqual(match$28[1]);
}
let match$29 = match$27.VAL;
return expect(match$29[0]).not.toBeGreaterThanOrEqual(match$29[1]);
case "LessThan" :
let match$30 = x._0;
if (match$30.NAME === "Just") {
let match$31 = match$30.VAL;
return expect(match$31[0]).toBeLessThan(match$31[1]);
}
let match$32 = match$30.VAL;
return expect(match$32[0]).not.toBeLessThan(match$32[1]);
case "LessThanOrEqual" :
let match$33 = x._0;
if (match$33.NAME === "Just") {
let match$34 = match$33.VAL;
return expect(match$34[0]).toBeLessThanOrEqual(match$34[1]);
}
let match$35 = match$33.VAL;
return expect(match$35[0]).not.toBeLessThanOrEqual(match$35[1]);
case "StringContains" :
let match$36 = x._0;
if (match$36.NAME === "Just") {
let match$37 = match$36.VAL;
return expect(match$37[0]).toEqual(expect.stringContaining(match$37[1]));
}
let match$38 = match$36.VAL;
return expect(match$38[0]).not.toEqual(expect.stringContaining(match$38[1]));
case "StringMatch" :
let match$39 = x._0;
if (match$39.NAME === "Just") {
let match$40 = match$39.VAL;
return expect(match$40[0]).toMatch(match$40[1]);
}
let match$41 = match$39.VAL;
return expect(match$41[0]).not.toMatch(match$41[1]);
case "Throws" :
let match$42 = x._0;
if (match$42.NAME === "Just") {
return expect(match$42.VAL).toThrow();
} else {
return expect(match$42.VAL).not.toThrow();
}
case "MatchInlineSnapshot" :
return expect(x._0).toMatchInlineSnapshot(x._1);
case "MatchSnapshot" :
return expect(x._0).toMatchSnapshot();
case "MatchSnapshotName" :
return expect(x._0).toMatchSnapshot(x._1);
case "ThrowsMatchSnapshot" :
return expect(x._0).toThrowErrorMatchingSnapshot();
case "Defined" :
let match$43 = x._0;
if (match$43.NAME === "Just") {
return expect(match$43.VAL).toBeDefined();
} else {
return expect(match$43.VAL).not.toBeDefined();
}
case "Falsy" :
let match$44 = x._0;
if (match$44.NAME === "Just") {
return expect(match$44.VAL).toBeFalsy();
} else {
return expect(match$44.VAL).not.toBeFalsy();
}
case "Null" :
let match$45 = x._0;
if (match$45.NAME === "Just") {
return expect(match$45.VAL).toBeNull();
} else {
return expect(match$45.VAL).not.toBeNull();
}
case "Truthy" :
let match$46 = x._0;
if (match$46.NAME === "Just") {
return expect(match$46.VAL).toBeTruthy();
} else {
return expect(match$46.VAL).not.toBeTruthy();
}
case "Undefined" :
let match$47 = x._0;
if (match$47.NAME === "Just") {
return expect(match$47.VAL).toBeUndefined();
} else {
return expect(match$47.VAL).not.toBeUndefined();
}
case "ObjectContains" :
let match$48 = x._0;
if (match$48.NAME === "Just") {
let match$49 = match$48.VAL;
return expect(match$49[0]).toEqual(objectContaining(match$49[1]));
}
let match$50 = match$48.VAL;
return expect(match$50[0]).not.toEqual(objectContaining(match$50[1]));
case "ObjectMatch" :
let match$51 = x._0;
if (match$51.NAME === "Just") {
let match$52 = match$51.VAL;
return expect(match$52[0]).toMatchObject(match$52[1]);
}
let match$53 = match$51.VAL;
return expect(match$53[0]).not.toMatchObject(match$53[1]);
}
}
function test$1(name, callback) {
test(name, () => {
affirm(callback());
});
}
function testAsync(name, timeout, callback) {
test(name, finish => {
callback($$case => {
affirm($$case);
finish();
});
}, timeout);
}
function testPromise(name, timeout, callback) {
test(name, () => callback().then(a => Promise.resolve(affirm(a))), timeout);
}
function testAll(name, inputs, callback) {
Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
test(name$1, () => {
affirm(callback(input));
});
});
}
function testAllPromise(name, inputs, timeout, callback) {
Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
test(name$1, () => callback(input).then(a => Promise.resolve(affirm(a))), timeout);
});
}
function describe$1(label, f) {
describe(label, () => {
f();
});
}
function beforeAllAsync(timeout, callback) {
beforeAll(finish => {
callback(() => finish());
}, timeout);
}
function beforeAllPromise(timeout, callback) {
beforeAll(() => Promise.resolve(callback()), timeout);
}
function beforeEachAsync(timeout, callback) {
beforeEach(finish => {
callback(finish);
}, timeout);
}
function beforeEachPromise(timeout, callback) {
beforeEach(() => Promise.resolve(callback()), timeout);
}
function afterAllAsync(timeout, callback) {
afterAll(finish => {
callback(finish);
}, timeout);
}
function afterAllPromise(timeout, callback) {
afterAll(() => Promise.resolve(callback()), timeout);
}
function afterEachAsync(timeout, callback) {
afterEach(finish => {
callback(finish);
}, timeout);
}
function afterEachPromise(timeout, callback) {
afterEach(() => Promise.resolve(callback()), timeout);
}
function test$2(name, callback) {
it.only(name, () => {
affirm(callback());
});
}
function testAsync$1(name, timeout, callback) {
it.only(name, finish => {
callback(assertion => {
affirm(assertion);
finish();
});
}, timeout);
}
function testPromise$1(name, timeout, callback) {
it.only(name, () => callback().then(a => Promise.resolve(affirm(a))), timeout);
}
function testAll$1(name, inputs, callback) {
Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
it.only(name$1, () => {
affirm(callback(input));
});
});
}
function testAllPromise$1(name, inputs, timeout, callback) {
Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
it.only(name$1, () => callback(input).then(a => Promise.resolve(affirm(a))), timeout);
});
}
function describe$2(label, f) {
describe.only(label, () => {
f();
});
}
let Only = {
test: test$2,
testAsync: testAsync$1,
testPromise: testPromise$1,
testAll: testAll$1,
testAllPromise: testAllPromise$1,
describe: describe$2
};
function testAsync$2(name, param, callback) {
it.skip(name, callback);
}
function testPromise$2(name, param, callback) {
it.skip(name, callback);
}
function testAll$2(name, inputs, callback) {
Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
it.skip(name$1, () => callback(input));
});
}
function testAllPromise$2(name, inputs, param, callback) {
Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
it.skip(name$1, () => callback(input));
});
}
function describe$3(label, f) {
describe.skip(label, () => {
f();
});
}
function fail$1(message) {
return {
TAG: "Fail",
_0: message
};
}
function expect$1(a) {
return {
NAME: "Just",
VAL: a
};
}
function expectFn(f, a) {
return {
NAME: "Just",
VAL: () => f(a)
};
}
function toBe(b, p) {
return {
TAG: "Be",
_0: mapMod(a => [
a,
p
], b)
};
}
function toBeCloseTo(b, p) {
return {
TAG: "FloatCloseTo",
_0: mapMod(a => [
a,
p
], b)
};
}
function toBeSoCloseTo(b, digits, p) {
return {
TAG: "FloatSoCloseTo",
_0: mapMod(a => [
a,
p,
digits
], b)
};
}
function toBeGreaterThan(b, p) {
return {
TAG: "GreaterThan",
_0: mapMod(a => [
a,
p
], b)
};
}
function toBeGreaterThanOrEqual(b, p) {
return {
TAG: "GreaterThanOrEqual",
_0: mapMod(a => [
a,
p
], b)
};
}
function toBeLessThan(b, p) {
return {
TAG: "LessThan",
_0: mapMod(a => [
a,
p
], b)
};
}
function toBeLessThanOrEqual(b, p) {
return {
TAG: "LessThanOrEqual",
_0: mapMod(a => [
a,
p
], b)
};
}
function toBeSupersetOf(b, p) {
return {
TAG: "ArraySuperset",
_0: mapMod(a => [
a,
p
], b)
};
}
function toContain(b, p) {
return {
TAG: "ArrayContains",
_0: mapMod(a => [
a,
p
], b)
};
}
function toContainEqual(b, p) {
return {
TAG: "ArrayContainsEqual",
_0: mapMod(a => [
a,
p
], b)
};
}
function toContainString(b, p) {
return {
TAG: "StringContains",
_0: mapMod(a => [
a,
p
], b)
};
}
function toEqual(b, p) {
return {
TAG: "Equal",
_0: mapMod(a => [
a,
p
], b)
};
}
function toHaveLength(l, p) {
return {
TAG: "ArrayLength",
_0: mapMod(a => [
a,
p
], l)
};
}
function toMatch(p, s) {
return {
TAG: "StringMatch",
_0: mapMod(a => [
a,
new RegExp(s)
], p)
};
}
function toMatchInlineSnapshot(param, inlineSnapshot) {
return {
TAG: "MatchInlineSnapshot",
_0: param.VAL,
_1: inlineSnapshot
};
}
function toMatchRe(re, p) {
return {
TAG: "StringMatch",
_0: mapMod(a => [
a,
p
], re)
};
}
function toMatchSnapshot(param) {
return {
TAG: "MatchSnapshot",
_0: param.VAL
};
}
function toMatchSnapshotWithName(param, name) {
return {
TAG: "MatchSnapshotName",
_0: param.VAL,
_1: name
};
}
function toThrow(f) {
return {
TAG: "Throws",
_0: f
};
}
function toThrowErrorMatchingSnapshot(param) {
return {
TAG: "ThrowsMatchSnapshot",
_0: param.VAL
};
}
function not_(param) {
return {
NAME: "Not",
VAL: param.VAL
};
}
let $eq$eq = toEqual;
let $eq$eq$eq = toBe;
function $bang$eq(a, b) {
return toEqual(not_(a), b);
}
function $bang$eq$eq(a, b) {
return toBe(not_(a), b);
}
let $great = toBeGreaterThan;
let $great$eq = toBeGreaterThanOrEqual;
let $less = toBeLessThan;
let $less$eq = toBeLessThanOrEqual;
let Operators = {
$eq$eq: $eq$eq,
$eq$eq$eq: $eq$eq$eq,
$bang$eq: $bang$eq,
$bang$eq$eq: $bang$eq$eq,
$great: $great,
$great$eq: $great$eq,
$less: $less,
$less$eq: $less$eq
};
let Expect = {
expect: expect$1,
expectFn: expectFn,
toBe: toBe,
toBeCloseTo: toBeCloseTo,
toBeSoCloseTo: toBeSoCloseTo,
toBeGreaterThan: toBeGreaterThan,
toBeGreaterThanOrEqual: toBeGreaterThanOrEqual,
toBeLessThan: toBeLessThan,
toBeLessThanOrEqual: toBeLessThanOrEqual,
toBeSupersetOf: toBeSupersetOf,
toContain: toContain,
toContainEqual: toContainEqual,
toContainString: toContainString,
toEqual: toEqual,
toHaveLength: toHaveLength,
toMatch: toMatch,
toMatchInlineSnapshot: toMatchInlineSnapshot,
toMatchRe: toMatchRe,
toMatchSnapshot: toMatchSnapshot,
toMatchSnapshotWithName: toMatchSnapshotWithName,
toThrow: toThrow,
toThrowErrorMatchingSnapshot: toThrowErrorMatchingSnapshot,
not_: not_,
not__: not_,
Operators: Operators
};
function toBeDefined(a) {
return {
TAG: "Defined",
_0: a
};
}
function toBeFalsy(a) {
return {
TAG: "Falsy",
_0: a
};
}
function toBeNull(a) {
return {
TAG: "Null",
_0: a
};
}
function toBeTruthy(a) {
return {
TAG: "Truthy",
_0: a
};
}
function toBeUndefined(a) {
return {
TAG: "Undefined",
_0: a
};
}
function toContainProperties(props, p) {
return {
TAG: "ObjectContains",
_0: mapMod(a => [
a,
p
], props)
};
}
function toMatchObject(b, p) {
return {
TAG: "ObjectMatch",
_0: mapMod(a => [
a,
p
], b)
};
}
let ExpectJs = {
expect: expect$1,
expectFn: expectFn,
toBe: toBe,
toBeCloseTo: toBeCloseTo,
toBeSoCloseTo: toBeSoCloseTo,
toBeGreaterThan: toBeGreaterThan,
toBeGreaterThanOrEqual: toBeGreaterThanOrEqual,
toBeLessThan: toBeLessThan,
toBeLessThanOrEqual: toBeLessThanOrEqual,
toBeSupersetOf: toBeSupersetOf,
toContain: toContain,
toContainEqual: toContainEqual,
toContainString: toContainString,
toEqual: toEqual,
toHaveLength: toHaveLength,
toMatch: toMatch,
toMatchInlineSnapshot: toMatchInlineSnapshot,
toMatchRe: toMatchRe,
toMatchSnapshot: toMatchSnapshot,
toMatchSnapshotWithName: toMatchSnapshotWithName,
toThrow: toThrow,
toThrowErrorMatchingSnapshot: toThrowErrorMatchingSnapshot,
not_: not_,
not__: not_,
Operators: Operators,
toBeDefined: toBeDefined,
toBeFalsy: toBeFalsy,
toBeNull: toBeNull,
toBeTruthy: toBeTruthy,
toBeUndefined: toBeUndefined,
toContainProperties: toContainProperties,
toMatchObject: toMatchObject
};
function makeNewMock(self) {
return new (Function.prototype.bind.apply(self, arguments));
}
;
function new0(prim) {
return makeNewMock(prim);
}
function new1(self, a) {
return makeNewMock(self, a);
}
function new2(self, a, b) {
return makeNewMock(self, a, b);
}
function calls(self) {
return self.mock.calls.slice().map((function (args) { return args.length === 1 ? args[0] : args }));
}
function instances(self) {
return self.mock.instances.slice();
}
let MockJs = {
new0: new0,
new1: new1,
new2: new2,
calls: calls,
instances: instances
};
function useFakeTimers(implementation, param) {
if (implementation !== undefined) {
jest.useFakeTimers(implementation);
} else {
jest.useFakeTimers();
}
}
function setSystemTime(systemTime) {
jest.setSystemTime(systemTime.VAL);
}
let Jest = {
useFakeTimers: useFakeTimers,
setSystemTime: setSystemTime
};
let JestJs = {};
function Runner(funarg) {
let affirm = funarg.affirm;
let test$3 = (name, callback) => {
test(name, () => {
affirm(callback());
});
};
let testAsync = (name, timeout, callback) => {
test(name, finish => {
callback($$case => {
affirm($$case);
finish();
});
}, timeout);
};
let testPromise = (name, timeout, callback) => {
test(name, () => callback().then(a => Promise.resolve(funarg.affirm(a))), timeout);
};
let testAll = (name, inputs, callback) => Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
test(name$1, () => {
affirm(callback(input));
});
});
let testAllPromise = (name, inputs, timeout, callback) => Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
test(name$1, () => callback(input).then(a => Promise.resolve(funarg.affirm(a))), timeout);
});
let describe$4 = (label, f) => {
describe(label, () => {
f();
});
};
let beforeAllAsync = (timeout, callback) => {
beforeAll(finish => {
callback(() => finish());
}, timeout);
};
let beforeAllPromise = (timeout, callback) => {
beforeAll(() => Promise.resolve(callback()), timeout);
};
let beforeEachAsync = (timeout, callback) => {
beforeEach(finish => {
callback(finish);
}, timeout);
};
let beforeEachPromise = (timeout, callback) => {
beforeEach(() => Promise.resolve(callback()), timeout);
};
let afterAllAsync = (timeout, callback) => {
afterAll(finish => {
callback(finish);
}, timeout);
};
let afterAllPromise = (timeout, callback) => {
afterAll(() => Promise.resolve(callback()), timeout);
};
let afterEachAsync = (timeout, callback) => {
afterEach(finish => {
callback(finish);
}, timeout);
};
let afterEachPromise = (timeout, callback) => {
afterEach(() => Promise.resolve(callback()), timeout);
};
let test$4 = (name, callback) => {
it.only(name, () => {
affirm(callback());
});
};
let testAsync$1 = (name, timeout, callback) => {
it.only(name, finish => {
callback(assertion => {
affirm(assertion);
finish();
});
}, timeout);
};
let testPromise$1 = (name, timeout, callback) => {
it.only(name, () => callback().then(a => Promise.resolve(affirm(a))), timeout);
};
let testAll$1 = (name, inputs, callback) => Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
it.only(name$1, () => {
affirm(callback(input));
});
});
let testAllPromise$1 = (name, inputs, timeout, callback) => Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
it.only(name$1, () => callback(input).then(a => Promise.resolve(funarg.affirm(a))), timeout);
});
let describe$5 = (label, f) => {
describe.only(label, () => {
f();
});
};
let Only = {
test: test$4,
testAsync: testAsync$1,
testPromise: testPromise$1,
testAll: testAll$1,
testAllPromise: testAllPromise$1,
describe: describe$5
};
let testAsync$2 = (name, param, callback) => {
it.skip(name, callback);
};
let testPromise$2 = (name, param, callback) => {
it.skip(name, callback);
};
let testAll$2 = (name, inputs, callback) => Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
it.skip(name$1, () => callback(input));
});
let testAllPromise$2 = (name, inputs, param, callback) => Stdlib_List.forEach(inputs, input => {
let name$1 = name + ` - ` + String(input);
it.skip(name$1, () => callback(input));
});
let describe$6 = (label, f) => {
describe.skip(label, () => {
f();
});
};
return {
test: test$3,
testAsync: testAsync,
testPromise: testPromise,
testAll: testAll,
testAllPromise: testAllPromise,
describe: describe$4,
beforeAllAsync: beforeAllAsync,
beforeAllPromise: beforeAllPromise,
beforeEachAsync: beforeEachAsync,
beforeEachPromise: beforeEachPromise,
afterAllAsync: afterAllAsync,
afterAllPromise: afterAllPromise,
afterEachAsync: afterEachAsync,
afterEachPromise: afterEachPromise,
Only: Only,
Skip: {
test: (prim0, prim1) => {
it.skip(prim0, prim1);
},
testAsync: testAsync$2,
testPromise: testPromise$2,
testAll: testAll$2,
testAllPromise: testAllPromise$2,
describe: describe$6
}
};
}
function Skip_test(prim0, prim1) {
it.skip(prim0, prim1);
}
let Skip = {
test: Skip_test,
testAsync: testAsync$2,
testPromise: testPromise$2,
testAll: testAll$2,
testAllPromise: testAllPromise$2,
describe: describe$3
};
let Todo = {
test: prim => {
it.todo(prim);
}
};
let pass = "Ok";
exports.Runner = Runner;
exports.test = test$1;
exports.testAsync = testAsync;
exports.testPromise = testPromise;
exports.testAll = testAll;
exports.testAllPromise = testAllPromise;
exports.describe = describe$1;
exports.beforeAllAsync = beforeAllAsync;
exports.beforeAllPromise = beforeAllPromise;
exports.beforeEachAsync = beforeEachAsync;
exports.beforeEachPromise = beforeEachPromise;
exports.afterAllAsync = afterAllAsync;
exports.afterAllPromise = afterAllPromise;
exports.afterEachAsync = afterEachAsync;
exports.afterEachPromise = afterEachPromise;
exports.Only = Only;
exports.Skip = Skip;
exports.Todo = Todo;
exports.pass = pass;
exports.fail = fail$1;
exports.Expect = Expect;
exports.ExpectJs = ExpectJs;
exports.MockJs = MockJs;
exports.Jest = Jest;
exports.JestJs = JestJs;
/* Not a pure module */