I'm new on using AVA for JS unit tests and I immediately hit a rock:
My situation is that I want to run a gulp task to run the AVA tests and watch the test files, and in the test file I wrote I need to include the js file that contains the code to test.
The problem is that the file with the code to test is an old js file with all global functions, so needs to be shimmed somehow into an AMD module, but how I can do this without changing the original file?
gulpfile.js
var gulp = require("gulp");
var ava = require("gulp-ava");
var srcUnitTestFiles = ["**/*.tests.js", "!node_modules/*.js"];
gulp.task("unit-tests-exec", () =>
gulp.src(srcUnitTestFiles)
// gulp-ava needs filepaths so you can't have any plugins before it
.pipe(ava({ verbose: true }))
);
gulp.task("unit-tests-watch", () =>
gulp.watch(srcUnitTestFiles, ["unit-tests-exec"])
);
package.json
{
"name": "name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "ava"
},
"author": "",
"license": "ISC",
"devDependencies": {
"ava": "^0.16.0",
"gulp": "^3.9.1",
"gulp-ava": "^0.14.0",
"jsdom": "^9.4.2"
},
"ava": {
"require": [
"./test/helpers/setup-browser-env.js"
]
}
}
firstTest.tests.js
import test from "ava";
// I need to import the js file to test
test.before(t => {
});
test("foo", t => {
t.pass();
});
test('bar', async t => {
const bar = Promise.resolve('bar');
t.is(await bar, 'bar');
});
Thanks!