Skip to content

Commit

Permalink
Merge pull request #20 from bloodyowl/rescript-11
Browse files Browse the repository at this point in the history
Rescript 11
  • Loading branch information
bloodyowl authored Apr 21, 2024
2 parents 2fa32f8 + 1867bc0 commit 84dd417
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 75 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ Outputs:
### Tests

- `test(name, body)`
- `testWith(~setup: unit => 'a, ~teardown: 'a => unit=?, name, body: 'a => unit)`
- `createTestWith(~setup: unit => 'a, ~teardown: 'a => unit=?` -> `test`
- `testAsync(name, body)`
- `testAsyncWith(~setup: unit => 'a, ~teardown: 'a => unit=?, name, body: ('a, cb) => unit)`
- `createTestAsyncWith(~setup: unit => 'a, ~teardown: 'a => unit=?, name, body: ('a, cb) => unit)` -> `testAsync`

### Operators

Expand Down Expand Up @@ -160,7 +160,7 @@ assertion(~message?, ~operator="deepEqual", (a, b) => a == b, a, b)
The `setup` function returns a clean context for the test, the `teardown` function resets it.

```rescript
let testWithRef = testWith(~setup=() => ref(0), ~teardown=someRef => someRef := 0)
let testWithRef = createTestWith(~setup=() => ref(0), ~teardown=someRef => someRef := 0)
testWithRef("Setup & teardown", someRef => {
incr(someRef)
Expand All @@ -185,8 +185,8 @@ let cleanupContainer = container => {
remove(container)
}
let testWithReact = testWith(~setup=createContainer, ~teardown=cleanupContainer)
let testAsyncWithReact = testAsyncWith(~setup=createContainer, ~teardown=cleanupContainer)
let testWithReact = createTestWith(~setup=createContainer, ~teardown=cleanupContainer)
let testAsyncWithReact = createTestAsyncWith(~setup=createContainer, ~teardown=cleanupContainer)
```

And then use it:
Expand Down
13 changes: 1 addition & 12 deletions bin/retest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,7 @@ let globsOrNames = args.filter((item) => !options[item]);

if (globsOrNames.some((item) => item.includes("*"))) {
globsOrNames = await Promise.all(
globsOrNames.map(
(globOrName) =>
new Promise((resolve, reject) => {
glob(globOrName, (err, files) => {
if (err) {
reject(err);
} else {
resolve(files);
}
});
})
)
globsOrNames.map((globOrName) => glob(globOrName))
).then((arrays) => [...new Set([].concat(...arrays))]);
}

Expand Down
24 changes: 13 additions & 11 deletions docs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The `test` function identifies a test suite. You give it a name to easily find i
```js title="Add_test.res"
test("Add", () => {
// Your assertions
})
});
```

:::note
Expand All @@ -29,13 +29,13 @@ Nesting `test` suites is not allowed.

### testAsync

`testAsync` works the same way, but gives the function an extra parameter, a `done` function to call when your test is done.
`testAsync` works the same way, but gives the function an extra parameter, a `done` function to call when your test is done.

```js title="AsyncWorkflow_test.res"
testAsync("Async workflow", (done) => {
// Your async assertions
done()
})
done();
});
```

#### Timeout
Expand Down Expand Up @@ -70,7 +70,7 @@ The API we provide is pretty similar to `test` & `testAsync`, they're nearly the
- A `teardown` function that takes the `value` and lets you act on it
- `value` that's passed to your test function body

### testWith
### createTestWith

```js title="SetupAndTeardown_test.res"
let setup = () => {
Expand All @@ -83,7 +83,9 @@ let teardown = element => {
element["remove"](. )
}

testWith(~setup, ~teardown, "Setup & teardown", (element) => {
const testWithElement = createTestWith(~setup, ~teardown)

testWithElement("Setup & teardown", (element) => {
// Your assertions that use `element`
})
```
Expand All @@ -109,10 +111,10 @@ And reuse it across your tests!
```js title="SomeDOMTests_test.res"
testWithElement("Some DOM logic", (element) => {
// Your assertions that use `element`
})
});
```

### testAsyncWith
### createTestAsyncWith

Pretty much the same story there, expect we have the extra `done` argument

Expand All @@ -127,14 +129,14 @@ let teardown = element => {
element["remove"](. )
}

let testWithElement = testAsyncWith(~setup, ~teardown)
let testWithElement = createTestAsyncWith(~setup, ~teardown)
```

And there we go:

```js title="SomeDOMTests_test.res"
testAsyncWithElement("Some DOM logic", (element, done) => {
// Your async assertions that use `element`
done()
})
done();
});
```
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
"author": "bloodyowl <[email protected]>",
"license": "MIT",
"devDependencies": {
"rescript": "^10.0.0",
"rescript-js": "1.0.0-beta.2"
"rescript": "^11.0.0"
},
"peerDependencies": {
"rescript": "^9.0.0 || ^10.0.0"
"rescript": "^11.0.0"
},
"dependencies": {
"glob": "^10.3.0",
"@rescript/core": "^1.3.0",
"glob": "^10.3.12",
"jsdom": "^23.1.0"
}
}
4 changes: 2 additions & 2 deletions bsconfig.json → rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"type": "dev"
}
],
"bs-dev-dependencies": ["rescript-js"],
"bs-dev-dependencies": ["@rescript/core"],
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"suffix": ".mjs",
Expand Down
6 changes: 6 additions & 0 deletions src/Test.res
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ let testAsyncWith = (~setup, ~teardown=?, name, ~timeout=?, func) => {
})
}

let createTestAsyncWith = (~setup, ~teardown=?) => (name, ~timeout=?, func) =>
testAsyncWith(~setup, ~teardown?, name, ~timeout?, func)

let test = (name, func) => {
if running.contents {
Js.Console.error(
Expand Down Expand Up @@ -236,6 +239,9 @@ let testWith = (~setup, ~teardown=?, name, func) => {
})
}

let createTestWith = (~setup, ~teardown=?) => (name, func) =>
testWith(~setup, ~teardown?, name, func)

let autoBoot = ref(true)

let runTests = () => {
Expand Down
7 changes: 7 additions & 0 deletions src/Test.resi
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ let testAsyncWith: (
('a, (~planned: int=?, unit) => unit) => unit,
) => unit

let createTestAsyncWith: (
~setup: unit => 'a,
~teardown: 'a => unit=?,
) => (string, ~timeout: int=?, ('a, (~planned: int=?, unit) => unit) => unit) => unit

let testWith: (~setup: unit => 'a, ~teardown: 'a => unit=?, string, 'a => unit) => unit

let createTestWith: (~setup: unit => 'a, ~teardown: 'a => unit=?) => (string, 'a => unit) => unit

let autoBoot: ref<bool>

let runTests: unit => unit
2 changes: 1 addition & 1 deletion test/BasicExample.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open ReScriptJs.Js
open RescriptCore
open Test

let intEqual = (~message=?, a: int, b: int) =>
Expand Down
2 changes: 1 addition & 1 deletion test/TestAllFail.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open ReScriptJs.Js
open RescriptCore
open Test

let equal = (~message=?, a, b) => assertion(~message?, ~operator="equal", (a, b) => a === b, a, b)
Expand Down
11 changes: 7 additions & 4 deletions test/TestAllPass.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open ReScriptJs.Js
open RescriptCore
open Test

let equal = (~message=?, a, b) => assertion(~message?, ~operator="equal", (a, b) => a === b, a, b)
Expand Down Expand Up @@ -38,7 +38,7 @@ test("DeepEquals", () => {
deepEqual(a, b)
})

let testWithSetup = testWith(~setup=() => ref(0))
let testWithSetup = createTestWith(~setup=() => ref(0))

testWithSetup("Setup", someRef => {
incr(someRef)
Expand All @@ -52,7 +52,10 @@ testWithSetup("Setup", someRef => {
equal(someRef.contents, 2)
})

let testWithSetupAndTeardown = testWith(~setup=() => ref(0), ~teardown=someRef => someRef := 0)
let testWithSetupAndTeardown = createTestWith(
~setup=() => ref(0),
~teardown=someRef => someRef := 0,
)

testWithSetupAndTeardown("Setup & teardown", someRef => {
incr(someRef)
Expand All @@ -66,7 +69,7 @@ testWithSetupAndTeardown("Setup & teardown 2", someRef => {
equal(someRef.contents, 2)
})

let testAsyncWithSetupAndTeardown = testAsyncWith(
let testAsyncWithSetupAndTeardown = createTestAsyncWith(
~setup=() => ref(0),
~teardown=someRef => someRef := 0,
)
Expand Down
4 changes: 2 additions & 2 deletions test/TestVarious.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open ReScriptJs.Js
open RescriptCore
open Belt
open Test

Expand Down Expand Up @@ -58,7 +58,7 @@ test("DeepEquals", () => {
let b = {username: "user", id: "a"}
equal(a.username, b.username)
equal(a.username, b.id)
equal(Undefined.make(1), Undefined.empty)
equal(Nullable.make(1), Nullable.undefined)
deepEqual(a, b)
todo("Check that user is ok")
})
Expand Down
61 changes: 28 additions & 33 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==

"@ryyppy/rescript-promise@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@ryyppy/rescript-promise/-/rescript-promise-2.1.0.tgz#a33861274c41360cfbe872cf489f3dcb8dd526e6"
integrity sha512-+dW6msBrj2Lr2hbEMX+HoWCvN89qVjl94RwbYWJgHQuj8jm/izdPC0YzxgpGoEFdeAEW2sOozoLcYHxT6o5WXQ==
"@rescript/core@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@rescript/core/-/core-1.3.0.tgz#e7ebc6814772ccabac23c980d5bb0851ad8338d1"
integrity sha512-wNZOZ63sYcaIYZCmTZeIPCeLa3HCGgPbIOR8zjyNkoBYUlxNV8Nb2ZyqlXR5Mb9ttvv8fTV56JbKhyVEZEYo8g==

agent-base@^7.0.2, agent-base@^7.1.0:
version "7.1.0"
Expand Down Expand Up @@ -167,16 +167,16 @@ form-data@^4.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

glob@^10.3.0:
version "10.3.10"
resolved "https://registry.yarnpkg.com/glob/-/glob-10.3.10.tgz#0351ebb809fd187fe421ab96af83d3a70715df4b"
integrity sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==
glob@^10.3.12:
version "10.3.12"
resolved "https://registry.yarnpkg.com/glob/-/glob-10.3.12.tgz#3a65c363c2e9998d220338e88a5f6ac97302960b"
integrity sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg==
dependencies:
foreground-child "^3.1.0"
jackspeak "^2.3.5"
jackspeak "^2.3.6"
minimatch "^9.0.1"
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"
path-scurry "^1.10.1"
minipass "^7.0.4"
path-scurry "^1.10.2"

html-encoding-sniffer@^4.0.0:
version "4.0.0"
Expand Down Expand Up @@ -223,7 +223,7 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==

jackspeak@^2.3.5:
jackspeak@^2.3.6:
version "2.3.6"
resolved "https://registry.yarnpkg.com/jackspeak/-/jackspeak-2.3.6.tgz#647ecc472238aee4b06ac0e461acc21a8c505ca8"
integrity sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==
Expand Down Expand Up @@ -259,10 +259,10 @@ jsdom@^23.1.0:
ws "^8.16.0"
xml-name-validator "^5.0.0"

"lru-cache@^9.1.1 || ^10.0.0":
version "10.1.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.1.0.tgz#2098d41c2dc56500e6c88584aa656c84de7d0484"
integrity sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag==
lru-cache@^10.2.0:
version "10.2.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3"
integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==

[email protected]:
version "1.52.0"
Expand All @@ -283,7 +283,7 @@ minimatch@^9.0.1:
dependencies:
brace-expansion "^2.0.1"

"minipass@^5.0.0 || ^6.0.2 || ^7.0.0":
"minipass@^5.0.0 || ^6.0.2 || ^7.0.0", minipass@^7.0.4:
version "7.0.4"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.0.4.tgz#dbce03740f50a4786ba994c1fb908844d27b038c"
integrity sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==
Expand All @@ -310,12 +310,12 @@ path-key@^3.1.0:
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==

path-scurry@^1.10.1:
version "1.10.1"
resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-1.10.1.tgz#9ba6bf5aa8500fe9fd67df4f0d9483b2b0bfc698"
integrity sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==
path-scurry@^1.10.2:
version "1.10.2"
resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-1.10.2.tgz#8f6357eb1239d5fa1da8b9f70e9c080675458ba7"
integrity sha512-7xTavNy5RQXnsjANvVvMkEjvloOinkAjv/Z6Ildz9v2RinZ4SBKTWFOVRbaF8p0vpHnyjV/UwNDdKuUv6M5qcA==
dependencies:
lru-cache "^9.1.1 || ^10.0.0"
lru-cache "^10.2.0"
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"

psl@^1.1.33:
Expand All @@ -338,17 +338,10 @@ requires-port@^1.0.0:
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
integrity sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==

[email protected]:
version "1.0.0-beta.2"
resolved "https://registry.yarnpkg.com/rescript-js/-/rescript-js-1.0.0-beta.2.tgz#f04a259396dde22178b43cebd1b3dbd3a4f94a60"
integrity sha512-eWq9ga4tnzXpED1IkDtmmkMBoUN2Vy4FPeZ9ge5ur0vHSolf7QhpnpGoPY0hkTXfwXQuFlPw5g2g5nWCEmIkVQ==
dependencies:
"@ryyppy/rescript-promise" "^2.1.0"

rescript@^10.0.0:
version "10.1.4"
resolved "https://registry.yarnpkg.com/rescript/-/rescript-10.1.4.tgz#0f37710d371f32a704f17b4e804f66ce3c79a305"
integrity sha512-FFKlS9AG/XrLepWsyw7B+A9DtQBPWEPDPDKghV831Y2KGbie+eeFBOS0xtRHp0xbt7S0N2Dm6hhX+kTZQ/3Ybg==
rescript@^11.0.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/rescript/-/rescript-11.1.0.tgz#68dec0b3cbc456c1f9c8e4f10bda6fae49bf7f92"
integrity sha512-9la2Dv+ACylQ77I8s4spPu1JnLZXbH5WgxcLHLLUBWgFFSiv0wXqgzWztrBIZqwFgVX5BYcwldUqUVcEzdCyHg==

rrweb-cssom@^0.6.0:
version "0.6.0"
Expand Down Expand Up @@ -385,6 +378,7 @@ signal-exit@^4.0.1:
integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
name string-width-cjs
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand All @@ -403,6 +397,7 @@ string-width@^5.0.1, string-width@^5.1.2:
strip-ansi "^7.0.1"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
name strip-ansi-cjs
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down

0 comments on commit 84dd417

Please sign in to comment.