invoke fc check and handle results
This commit is contained in:
parent
d543dde7be
commit
9aa8db5d11
39
Makefile
39
Makefile
|
@ -11,13 +11,11 @@ build: ## build the app
|
|||
build: node_modules
|
||||
yarn tsc
|
||||
|
||||
bundle: build
|
||||
node config/esbuild/browser.mjs
|
||||
cp -rv src/index.html out/
|
||||
|
||||
ci: build cover
|
||||
|
||||
clean: clean-target
|
||||
clean: clean-modules clean-target
|
||||
|
||||
clean-modules:
|
||||
rm -rf node_modules/
|
||||
|
||||
clean-target:
|
||||
|
@ -27,14 +25,6 @@ docs:
|
|||
yarn api-extractor run -c config/api-extractor.json
|
||||
yarn api-documenter markdown -i out/temp -o out/docs
|
||||
|
||||
GRAPH_LAYOUT ?= dot
|
||||
|
||||
graph: ## render any debug graphs
|
||||
cat out/debug-graph | $(GRAPH_LAYOUT) -Tpng -oout/debug-graph.png && sensible-browser out/debug-graph.png
|
||||
|
||||
image: ## build the docker image
|
||||
docker build $(DOCKER_ARGS) -f Dockerfile -t $(DOCKER_IMAGE) .
|
||||
|
||||
install:
|
||||
yarn
|
||||
|
||||
|
@ -46,9 +36,6 @@ node_modules: install
|
|||
|
||||
out: build
|
||||
|
||||
pages: bundle
|
||||
cp out/bundle/browser.js bundle/browser.js
|
||||
|
||||
push: ## push to both github and gitlab
|
||||
git push $(GIT_ARGS) github $(GIT_HEAD_BRANCH)
|
||||
git push $(GIT_ARGS) gitlab $(GIT_HEAD_BRANCH)
|
||||
|
@ -63,26 +50,6 @@ release: node_modules
|
|||
yarn standard-version $(RELEASE_ARGS)
|
||||
GIT_ARGS=--follow-tags $(MAKE) push
|
||||
|
||||
RUN_ARGS ?= --config data/config.yml \
|
||||
--data file://data/demo.yml \
|
||||
--input 'create a test with test and with 20' \
|
||||
--input help
|
||||
|
||||
run: ## run app with demo data
|
||||
run: build
|
||||
node $(NODE_ARGS) out/src/index.js $(RUN_ARGS)
|
||||
|
||||
run-debug: ## run app and wait for debugger
|
||||
NODE_ARGS=--inspect-brk $(MAKE) run
|
||||
|
||||
run-graph: build
|
||||
node $(NODE_ARGS) out/src/index.js $(RUN_ARGS) --depth 13
|
||||
$(MAKE) graph
|
||||
|
||||
run-image: ## run app from docker image
|
||||
run-image: image
|
||||
docker run --rm -it $(DOCKER_IMAGE):latest $(RUN_ARGS)
|
||||
|
||||
MOCHA_ARGS := --async-only \
|
||||
--check-leaks \
|
||||
--forbid-only \
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"esm": "^3.2.25",
|
||||
"fast-check": "^2.17.0",
|
||||
"mocha": "<9.0.0",
|
||||
"nyc": "^15.1.0",
|
||||
"sinon": "^11.1.1",
|
||||
"sinon-chai": "^3.7.0",
|
||||
"source-map-support": "^0.5.19",
|
||||
|
|
36
src/index.ts
36
src/index.ts
|
@ -2,39 +2,33 @@ import { Arbitrary, check, property } from 'fast-check';
|
|||
|
||||
export type TestDone = () => Promise<void>;
|
||||
export type Test<T> = (this: Mocha.Context, args: T) => Promise<void>;
|
||||
export type WrappedTest<T> = (done: TestDone) => Promise<void>;
|
||||
export type WrappedTest<T> = (this: Mocha.Context) => Promise<void>;
|
||||
|
||||
export type WrappedIt<T> = (name: string, test: Test<T>) => void;
|
||||
export type WrappedCheck<T> = (t: T) => boolean;
|
||||
export type WrappedIt<T> = (name: string, test: WrappedCheck<T>) => void;
|
||||
export type Suite<T> = (it: WrappedIt<T>) => void;
|
||||
|
||||
export function over<T>(name: string, strategy: Arbitrary<T>, suite: Suite<T>): void {
|
||||
describe(name, () => {
|
||||
suite((name, test) => {
|
||||
console.log('registered over suite');
|
||||
it(name, function (this: Mocha.Context) {
|
||||
console.log('calling over test');
|
||||
// return test.call(this, 0 as any);
|
||||
it(name, function (this: Mocha.Context): Promise<void> {
|
||||
const ctx = this;
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
const result = check(property(strategy, (t) => {
|
||||
test.call(this, t);
|
||||
}));
|
||||
|
||||
const result = check(property(strategy, (t) => test.call(ctx, t)));
|
||||
if (result.failed) {
|
||||
rej();
|
||||
if (result.counterexample !== null) {
|
||||
const examples = result.counterexample.join(',');
|
||||
const error = `failed after ${result.numRuns} runs and ${result.numShrinks} shrinks, failing on: ${examples}`;
|
||||
rej(new Error(error));
|
||||
} else {
|
||||
rej(new Error('failed without counterexample'));
|
||||
}
|
||||
} else {
|
||||
res();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
describe('some foo', () => {
|
||||
over('the bars', integer(), (oit) => {
|
||||
oit('should be greater than 0', async (bar: number) => {
|
||||
expect(bar).to.be.greaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
*/
|
|
@ -1,14 +1,11 @@
|
|||
import { expect } from 'chai';
|
||||
import { integer } from 'fast-check';
|
||||
|
||||
import { over } from '../src/index';
|
||||
|
||||
describe('some foo', () => {
|
||||
over('the bars', integer(), (oit) => {
|
||||
console.log('oit outer');
|
||||
oit('should be greater than 0', async (bar: number) => {
|
||||
console.log('oit inner');
|
||||
expect(bar).to.be.greaterThan(0);
|
||||
over('the bars', integer(), (it) => {
|
||||
it('should be a small number', (bar: number) => {
|
||||
return bar < 1_000;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue