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
|
build: node_modules
|
||||||
yarn tsc
|
yarn tsc
|
||||||
|
|
||||||
bundle: build
|
|
||||||
node config/esbuild/browser.mjs
|
|
||||||
cp -rv src/index.html out/
|
|
||||||
|
|
||||||
ci: build cover
|
ci: build cover
|
||||||
|
|
||||||
clean: clean-target
|
clean: clean-modules clean-target
|
||||||
|
|
||||||
|
clean-modules:
|
||||||
rm -rf node_modules/
|
rm -rf node_modules/
|
||||||
|
|
||||||
clean-target:
|
clean-target:
|
||||||
|
@ -27,14 +25,6 @@ docs:
|
||||||
yarn api-extractor run -c config/api-extractor.json
|
yarn api-extractor run -c config/api-extractor.json
|
||||||
yarn api-documenter markdown -i out/temp -o out/docs
|
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:
|
install:
|
||||||
yarn
|
yarn
|
||||||
|
|
||||||
|
@ -46,9 +36,6 @@ node_modules: install
|
||||||
|
|
||||||
out: build
|
out: build
|
||||||
|
|
||||||
pages: bundle
|
|
||||||
cp out/bundle/browser.js bundle/browser.js
|
|
||||||
|
|
||||||
push: ## push to both github and gitlab
|
push: ## push to both github and gitlab
|
||||||
git push $(GIT_ARGS) github $(GIT_HEAD_BRANCH)
|
git push $(GIT_ARGS) github $(GIT_HEAD_BRANCH)
|
||||||
git push $(GIT_ARGS) gitlab $(GIT_HEAD_BRANCH)
|
git push $(GIT_ARGS) gitlab $(GIT_HEAD_BRANCH)
|
||||||
|
@ -63,26 +50,6 @@ release: node_modules
|
||||||
yarn standard-version $(RELEASE_ARGS)
|
yarn standard-version $(RELEASE_ARGS)
|
||||||
GIT_ARGS=--follow-tags $(MAKE) push
|
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 \
|
MOCHA_ARGS := --async-only \
|
||||||
--check-leaks \
|
--check-leaks \
|
||||||
--forbid-only \
|
--forbid-only \
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
"esm": "^3.2.25",
|
"esm": "^3.2.25",
|
||||||
"fast-check": "^2.17.0",
|
"fast-check": "^2.17.0",
|
||||||
"mocha": "<9.0.0",
|
"mocha": "<9.0.0",
|
||||||
|
"nyc": "^15.1.0",
|
||||||
"sinon": "^11.1.1",
|
"sinon": "^11.1.1",
|
||||||
"sinon-chai": "^3.7.0",
|
"sinon-chai": "^3.7.0",
|
||||||
"source-map-support": "^0.5.19",
|
"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 TestDone = () => Promise<void>;
|
||||||
export type Test<T> = (this: Mocha.Context, args: T) => 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 type Suite<T> = (it: WrappedIt<T>) => void;
|
||||||
|
|
||||||
export function over<T>(name: string, strategy: Arbitrary<T>, suite: Suite<T>): void {
|
export function over<T>(name: string, strategy: Arbitrary<T>, suite: Suite<T>): void {
|
||||||
describe(name, () => {
|
describe(name, () => {
|
||||||
suite((name, test) => {
|
suite((name, test) => {
|
||||||
console.log('registered over suite');
|
it(name, function (this: Mocha.Context): Promise<void> {
|
||||||
it(name, function (this: Mocha.Context) {
|
const ctx = this;
|
||||||
console.log('calling over test');
|
|
||||||
// return test.call(this, 0 as any);
|
|
||||||
|
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
const result = check(property(strategy, (t) => {
|
const result = check(property(strategy, (t) => test.call(ctx, t)));
|
||||||
test.call(this, t);
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (result.failed) {
|
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 { integer } from 'fast-check';
|
||||||
|
|
||||||
import { over } from '../src/index';
|
import { over } from '../src/index';
|
||||||
|
|
||||||
describe('some foo', () => {
|
describe('some foo', () => {
|
||||||
over('the bars', integer(), (oit) => {
|
over('the bars', integer(), (it) => {
|
||||||
console.log('oit outer');
|
it('should be a small number', (bar: number) => {
|
||||||
oit('should be greater than 0', async (bar: number) => {
|
return bar < 1_000;
|
||||||
console.log('oit inner');
|
|
||||||
expect(bar).to.be.greaterThan(0);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue