Skip to content

Initial exploration into an async check #73

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
:source-paths ["src"]

:dependencies [
[org.clojure/clojure "1.8.0"]
[org.clojure/clojure "1.9.0-alpha14"]
[org.clojure/clojurescript "1.9.293"]
[org.clojure/test.check "0.9.0"]]
[org.clojure/test.check "0.9.0"]
[io.nervous/promesa-check "0.1.1"]]

:plugins [
[lein-cljsbuild "1.1.5"]]
Expand Down
25 changes: 24 additions & 1 deletion src/testcheck.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
'[clojure.test.check.generators :as gen]
'[clojure.test.check.properties :as prop]
'[clojure.set :refer [rename-keys]]
'[clojure.string :refer [split join]])
'[clojure.string :refer [split join]]
'[promesa-check.core :as pc]
'[promesa.core :as p])

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Internal Helpers
Expand Down Expand Up @@ -164,6 +166,27 @@
;; Usage API
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defexport checkAsync (fn
[property options]
(let [opt (or options (js-obj))
num-tests (or (aget opt "numTests") (aget opt "times") 100)
max-size (or (aget opt "maxSize") 200)
seed (aget opt "seed")
result (pc/quick-check num-tests property :max-size max-size :seed seed)]
(p/map (fn
[res]
(let [
resultRenamed (rename-keys res {:failing-size :failingSize :num-tests :numTests})
resultRenamedDeep (if (contains? resultRenamed :shrunk)
(update
resultRenamed
:shrunk
rename-keys
{:total-nodes-visited :totalNodesVisited})
resultRenamed)
]
(clj->js resultRenamedDeep))) result))))

(defexport check (fn
[property options]
(let [opt (or options (js-obj))
Expand Down
8 changes: 7 additions & 1 deletion test/check.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
/*:: declare function expect(val: any): any; */
/*:: declare var jasmine: any; */

const { check, property, gen } = require('../')
const { check, checkAsync, property, gen } = require('../')

describe('check', () => {

it('async', (done) => {
const promise = checkAsync(property(gen.int, (i) => Promise.resolve(i)))

promise.then((result) => console.log(result) || done())
})

it('checks true properties', () => {

const seedVal = 1234567890
Expand Down