Dixture is a Deno module that helps you create random data for your tests.
Dixture
Dixture helps you create random data for your tests, with zero external dependencies!
🚥 Current Status
Master status
Project status: Under development
Latest stable version: v0.2.2
🏆 Acknowledgements
Dixture is loosely based on the great AutoFixture library that exists on the .NET environment.
I've used this library for so long for my Unit and Integration tests that I needed to, somehow, get some of its functionality when working on my Deno's tests.
Thus I began working on this project.
⚡ Getting Started
Simply import us by deno.land/x/ and use your favorite flavor of test data generation!
As of v0.2.2 you can pick from two "flavors":
Functions that create and/or assign fields for your classes and instances
A Factory API that allows you to write down rules for your classes
Some background on myself: My fulltime job, right now, is as a fullstack engineer for c#. That means that I get to enjoy all of its perks and all the awesome NuGet packages that the .NET community created.
Some of these packages are soo helpful that they're must-haves for my daily workflow. These NuGets help me be productive while writing my tests and, to be honest, actually make me enjoy writing tests! To name a few:
AutoFixture and either AutoFixture.nUnit or AutoFixture.xUnit
FluentAssertions
Moq
So when I'm working with Deno on my free time I must admit... I miss those libraries 😅.
Wello Horld, this is Dixture
So, out of my frustration due to a lack of Test Data Generators for Deno I began to work on something, now called Dixture. I had to, somehow, make my workflow faster and since no one was writing one... might as well give it a shot, right?
Dixture is, basically, a module that simplifies your Test Data Generation. It has zero external dependencies and allows you some room for customization.
My goal is to keep Dixture as less intrusive as possible. I don't think it's fair to ask anyone to clutter their code with ClassAttributes or bother with metadata generation just for some data generation. However, given the not-on-par-with-csharp support for Reflection on Typescript, we still need some input from you, the developer, in order to give us a "blueprint" (called RuleSet inside Dixture) of how to build your class.
import{dixtureFns,RuleSet,DixtureFactory,}from"https://deno.land/x/dixture@v0.2.0/mod.ts";classPerson{name:string="";age:number=0;bankBalance:bigint=1n;isAlive:boolean=true;}// 1. Creating our factoryconstfactory=newDixtureFactory(// 2. Writing in-line Rule Sets (blueprints) for our classesnewRuleSet(Person,// 3. For each field we pick a resolution function{field:"name",resolve:dixtureFns.String,},{field:"age",resolve:dixtureFns.Int,},// 4. We can even define our own resolution functions, as far as they return the expected type{field:"bankBalance",resolve:()=>{if(dixtureFns.Bool()){return10000000n;}return0n;},},// 5. We can also omit rules, the field might not be important after all),);
What about x/y/z Feature!?
Well, currently, the roadmap is to try and allow generation for interfaces (so no need to wrap those up into classes anymore 😅), allow a Fluent/Builder api for RuleSets / Blueprints and further enhance how data is generated.
However all suggestions are welcome! Feel free to drop by our GitHub repo and create issues, fork us and send us your pull request!
Acknowledgements
Kudos to the great community behind AutoFixture for getting me into Testing and to Rhum for creating an improved test "framework" for Deno (Rhum is used for testing Dixture!)