garbles / kitimat Goto Github PK
View Code? Open in Web Editor NEWA library for generative, property-based testing in TypeScript and Jest.
License: MIT License
A library for generative, property-based testing in TypeScript and Jest.
License: MIT License
Make it possible to use React propTypes to generate props for your component.
import { fromPropTypes } from 'kitimat-prop-types';
jest.mock('prop-types', () => require('kitimat-prop-types/mock'));
import { App } from './app';
const propsGen = fromPropTypes(App);
// ...
Already squating on kitimat-prop-types
in packages.
Inspired by mockServer
in GraphQL tools, create GraphQL bindings for Kitimat. Given a schema.json
and a query, I should create a generator.
import { fromGraphQL } from 'kitimat-graphql';
improt schema from './schema.json';
const server = fromGraphQL(schema);
const queryGen = server(`query {
me {
id
name
}
}`);
check('my component renders', queryGen, result => {
// ...
});
I'm already squating kitimat-graphql
in packages.
While experimenting with this library, I found an issue that seemingly makes it very difficult to work with. It could be that I'm doing something wrong, or that there have been changes in jest since this library was last updated.
Demonstration code:
https://github.com/chrismilleruk/testapp/tree/kitimat-jest
Given a simple generative test which fails:
check('Always starts with a letter',
[string(), string()],
(generatedPrefix, generatedName) => {
const module = new Greeting(generatedPrefix);
const result = module.sayHello(generatedName);
// Always starts with a letter
expect(result[0]).toMatch(/[A-Za-z]/);
});
The reporter output doesn't provide
...
✕ Always starts with a letter (seed: undefined, source: undefined) (26ms)
✓ Has four basic formats (33ms)
● Greeting Class › Always starts with a letter (seed: undefined, source: undefined)
expect(received).toMatch(expected)
Expected pattern: /[A-Za-z]/
Received string: " "
37 |
38 | // Always starts with a letter
> 39 | expect(result[0]).toMatch(/[A-Za-z]/);
| ^
40 | });
...
TS exposes custom transformers through the public API, so it should be possible to create generates purely from a type alias. I've done something like before with babel as Flow.
import { fromType } from 'kitimat-type-to-gen';
const person = fromType<Person>();
// would expand to something like...
const kitimat = require('kitimat-jest');
const person = kitimat.object<Person>({
name: kitimat.string(),
age: kitimat.posInt(),
// ... etc
});
Like this talk but probably using Chromeless. For more information, see https://en.wikipedia.org/wiki/Model-based_testing.
This function would be the "snapshot testing" of property-based tests - don't want to use much effort and just have something that does a general sanity check that the function won't throw.
import { integer } from 'kitimat-jest';
fuzz('my func doesn\'t throw', [integer()], int => myFunc(int));
Maybe this should also try to throw garbage and see that there is an exception if the wrong type is passed.
Seems like this would involve allowing a property to accept a runner as an argument. Create a new runner that would complete as soon as a single test case proves the property. In kitimat-jest it would look the same as check
import { integer, exists } from 'kitimat-jest';
exists("a thing", integer(), a => expect(a).toEqual(0));
import { string, integer } from 'kitimat-jest';
const fuzz = string().or(integer());
I'd be interested in an integration with the ava test runner, since it's what I use. (I'm open to contributing myself, but I have a lot of other projects. Hopefully it's not too hard, and so I'll give it a try since I know ava stuff 😅)
We should be able to specify what options are defaults and which can simply be an extension so that we don't have to continuously add options for things that we don't care about, e.g. kitimat-jest
is the only thing that cares about the timeout
option.
Also, the options.ts
module is the only thing that relies on path
and cosmiconfig
which makes it annoying to use Kitimat directly in the browser. (something I want to do)
Q: is there a tool that transforms .d.ts
into .js.flow
?
Seems more natural for someone to use number
instead of integer
or float
.
import { number } from 'kitimat-jest';
const fuzz = number();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.