Wallaby.js is one of the most amazing additions you can make to your testing workflow. I have been a happily paid user for a couple of years now and if you are looking to up your testing game, I highly recommend it.
Chances are if you are reading this post, you already use Wallaby and you are looking to get it working in your Aurelia applications with Jest and TypeScript. It’s a combination that is not all too uncommon these days, TypeScript is the future.
The Wallaby.js configuration itself requires very little code to work out-of-the-box with Aurelia and Jest.
module.exports = function (wallaby) { return { files: [ '!**/*.css', 'src/**/*.ts', 'src/**/*.html', 'test/unit/helpers.ts', 'test/unit/mock-data/**/*.ts', 'test/unit/stubs/**/*.ts', 'aurelia_project/environments/**/*.ts', 'test/jest.setup.ts', 'tsconfig.json' ], tests: [ 'test/unit/**/*.spec.ts' ], compilers: { '**/*.ts': wallaby.compilers.typeScript({ module: 'commonjs' }) }, env: { runner: 'node', type: 'node' }, testFramework: 'jest', debug: true }; };
The above configuration assumes your files live in src
and in my case, inside of my test/unit
directory I have a helpers.ts
file which has some functions making testing easier, a mock-data
directory for mock data to import, a stubs
directory for stubbing out certain mocks as well as my main Jest configuration file jest.setup.ts
.
Do not copy the above file line-for-line. Make sure it reflects your project and the files inside of it.
In the compilers
section we have to tell Wallaby to compile our TypeScript to commonjs
format. In my case, I was originally targeting esnext
as my module format and Wallaby does not work with modern JS syntax just yet. the rest is fairly explanatory.
Here is what Wallaby looks like running in an application I am currently working on.