This package has been developed to provide a lightweight spec runner to generate an environment to unit/integration test your ES[6||2015] code.
It uses Rollup to compile your code and adds it to a JSDOM environment. You can also precompile your code and pass that in if you prefer use your own.
This package has been developed due to difficulties in unit/integration testing ES[6||2015]. Most of this issues we encountered were around stubbing and spying on dependencies.
With the package bundling your scripts
const { bundleRunner } = require('es-spec-runner');
const runner = bundleRunner({
input: { file: 'this/is/the/file/location.js' },
output: { },
scriptDependencies: [ ]
});
runner({
polyfills: {},
fixture: '<div />'
}).then(({ dom }) => { /* run your assertions */ });
Providing your own custom bundle
const { bundleRunner } = require('es-spec-runner');
const runner = bundleRunner({
input: { custom: 'window.foo = "bar";' },
output: { },
scriptDependencies: [ ]
});
runner({
polyfills: {},
fixture: '<div />'
}).then(({ dom }) => { /* run your assertions */ });
options
[Object] required - Consists of the following:input
[Object] required - Can consist of Rollup input options. Passing this in will bundle you scripts for you.file
[String] required (when not providing acustom
value) - File path of the script to bundle.custom
[String] required (when not providing afile
value) - Pass in a pre-bundled script, and skip over the package automatically bundling for you.
output
[Object] optional - Can consist of Rollup output options. Passing this in will bundle you scripts for you.scriptDependencies
[Array] optional - Array of file locations that are required for your input to run e.g. lib/util files.
fixture
[String] optional - Markup to inject into the DOM.polyfills
[Object] optional - Map of polyfills to assign to the window scope. Can also be used for stubbing / spying external dependencies.