Generate fixture modules from folders
Generate a fixture from a folder on disk:
tacks /path/to/fixture/example > example.js
Create and destroy the fixture from your tests:
var Tacks =var Dir = TacksDirvar File = TacksFilevar Symlink = TacksSymlink// I like my fixture paths to match my test filename:var fixturepath = pathvar example =example…example
Or create your own fixture inline:
var example =example…example
This is very much a "release early" type release. Still very much in progress, but being used.
These are used in the generated code. It's totally legit to write them directly though.
var fixture =
Create a new fixture object based on a
Dir object, see below.
Create Fixture On Disk
Take the directory and files described by the fixture and create it in
Remove Fixture From Disk
Cleanup a fixture we installed in
var Dir = TacksDirvar mydir = Tacks
Creates a new
Dir object for consumption by
dirspec is a
object whose properties are the names of files in a directory and whose
values are either
Dir objects or
var File = TacksFilevar myfile = Tacks
Creates a new
File object for use in
filespec can be
Buffer or an
Object. In the last case, it
will be stringified with
JSON.stringify before writing it to disk
var Symlink = TacksSymlinkvar mysymlink = Tacks
Creates a new
Symlink object for use in
either be relative to where the symlink is being created, or absolute relative
to the root of the fixture. That is,
Tacks.Symlink('/') will create a symlink
pointing at the fixture root.
Generate Fixture Object From Directory
var loadFromDir =var onDisk =
The value returned is a
Tacks object that you can call
remove on. It's also handy for using in tests use compare an in
memory tacks fixture to whatever ended up on disk.
Assert Two Fixtures The Same With node-tap
var test = testvar tacksAreTheSame = areTheSame
tacks/tap submodule is the start of tap assertions for comparing fixtures.
areTheSame creates a subtest, and inside that subtest runs a bunch of
assertions comparing the contents of the two models. It's smart enough to
tacks equivalent things equal, eg strings & buffers with the same
Because it creates a subtest, it's async, it returns the subtest (which is also a promise) so you can either return it yourself and your test will complete when it does, or do something like:
var generateFromDir =var fixturestr = Tacks
WANT TO HAVES
These are things I'll do sooner or late myself.
- Include adding a
.mockFs('/tmp/fixture/path/')function which returns a patched version of
fsthat, for attempts to read from
/tmp/fixture/pathreturns data from the in memory fixture instead of looking at the filesystem. For injection into tested modules with something like
NICE TO HAVES
I'd love to see these, but I may never get time to do them myself. If someone else did them though…
- Having some way to control the formatting of the generated output would be
nice for folks who don't use
standard… eg, semicolons, indentation, default quoting. The right answer might be to generate AST objects for use by an existing formatter. Relatedly, it'd be nice to have some standard extension method for the generated sourcecode. Right now I make use of it just by concattenating source code.