mercredi 14 septembre 2016

Unit testing with Webpack, Jasmine (-core), typescript

I have a project that is using webpack to bundle all code into a single file. The project is using Typescript and it is working fine at the moment.

I've gone to add unit testing and jasmine seems to be the way (one of the many ways) forward. Its actually jasmine-core that is included in the package.json - not sure how much of a difference that makes.

So running a very simple test such as

it('true is true', function(){ expect(true).toEqual(true); });

works fine. But when I add tests that require the use of an import - eg

import MyService = require('./MyServices');

then when I run the tests it complains as it doesn't know what 'require' is. Uncaught ReferenceError: require is not defined

Now I'm guessing this is because I need to package up the test module in a similar way that I package up the main project.

So what is the best way to do this? Should I have multiple entry points in the webpack.config.js file - one for each *.spec.ts file? Or is there a way to have say accept an unknown number of spec files

entry:[ *.spec.ts ] and have it output a js file for each one - *.spec.js

Aucun commentaire:

Enregistrer un commentaire