js.spec
js.spec copied to clipboard
Function specification idea
I can think of an AST transform that could instrument functions. Here's some ideas:
- Define specs in separate files/modules (with
.specextension, similar to.d.tsin TypeScript) - Find a way to map spec modules to JS modules
/* @spec path/to/spec.spec */in JS files?import from "path/to/spec.spec";
- Match specs with function by name?
- Use Webpack loader and Babel AST transform to load specs and instrument JS code
I'd be careful prescribing an extension for this, since a lot of people uses *spec* to match test files, but I'm sure there will be a way to have whatever test-runner or bootstrapping script you use to specify where to find the right files.
Wow, that's an interesting suggestion. I don't understand how this would work yet, but worth looking into 👍
You might want to consider ES Decorators to do this instead of magic places and names. Decorator would create the instrumented code you would need to spec the function params before calling the actual function. See https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841#.khz5wclld