karma-ava v0.0.1
karma-ava 
Run AVA tests with karma
WARNING: Alpha level software - for evaluation use only
Install
Note: this currently requires a custom build of AVA
$ npm install --save-dev jamestalmage/ava#karma-ava karma karma-ava karma-chrome-launcherUsage
Create a karma.conf.js, like so:
module.exports = function(config) {
config.set({
frameworks: ['ava'],
files: [
'test/*.js'
],
browsers: ['Chrome']
});
};Then run karma start:
$ node_modules/.bin/karma startNotes
- Be careful not to include test helpers in the
filespattern (future improvements will automatically filter helpers out).
How it works
The
avapreprocessor (lib/preprocessor.js) bundles up a single test. Instead of returning the bundle result. It stores it atnode_modules/.cache/karma-ava/<UNIQUE-HASH>.js. Karma sees a one-liner function call as the result:window.__AVA__.addFile(AVA_HASH, TEST_HASH, TEST_PREFIX);
AVA_HASHis the cache key for the external bundle of AVA common to all tests. It just contains AVA and it's dependencies.TEST_HASHis the cache key for the individual test bundle.TEST_PREFIXis a string prefix to put before the test title, something like:"dirname > filename > ".
- The
avamiddleware provides two routes:
/karma-ava/<CACHE_KEY>.js- returns the the bundle stored for that cache key (could be individual test bundles or the common AVA bundle)./karma-ava/child/:avaHash/:testHash- returns anhtmlpage that simply loads two bundles (the common bundle, and the individual test bundle). These pages will be loaded intoiframesby the main process.
lib/main.js
- This is loaded in the main window by the framework. It provides the
window.__AVA__.addFile()method discussed above, and acts as a test runner for individual iFrames. It also communicates test results back to the Karma server in a format it understands.
TODO's
Create opinionated, configuration-free defaults that follow AVA's current style.
Give the user greater control over what goes in the external/common bundle.
Automatically ignore test helpers
Create a custom karma reporter that uses AVA's own loggers
Honor
avaconfig params frompackage.jsonAllow for custom
babelconfigsUse
watchifyfor faster rebuilds and smart, dependency-based rerun behavior.
License
MIT © James Talmage
9 years ago