Reputation: 689
I'm trying to unit test a home-made NPM module of aurelia components. Note that this is not an aurelia application, it's just a repository of components and classes!
For this, I tried to replicate the setup of aurelia-dialog but I still have a few problems that really prevent me from passing a single test in a useful way...
Thanks a lot!
Upvotes: 1
Views: 546
Reputation: 8047
Replicating the aurelia-dialog
setup is probably not going to help because it no longer has any html files. They inlined html in the typescript sources, to make it easier for consumers to bundle (and possibly easier to test as well..)
Karma is only as fast as the bundler/transpiler you integrated it with, and of course depends on how many files you are loading. Double check that you're not including/serving files you don't need:
src
and test
foldernode_modules
and other deps, but not watch themThere's always a module loader handling these requests for files coming from inside your app. They live in "virtual" paths. When you directly request the file from the browser, you're bypassing this and requesting something that likely doesn't exist (or isn't served), even though your app can access it.
Loading dependencies like jQuery (or Bluebird for that matter) is done similarly to how you'd normally do it in your app. Have a direct reference to the path in your node_modules folder from your bundle config. Then make sure it's either prepended to your bundle, or served standalone. In the latter case, simply import "jquery"
in your setup.ts
. Or look at how Bluebird
is included in my suggestion below.
If speed is a concern, I would recommend to try using karma in combination with webpack. That's typically very fast (especially since webpack 4) and it greatly simplifies serving additional assets.
This plugin skeleton should give you a good idea of how these various things all work together.
Here's an example of how to configure karma with webpack
Then to add html assets for testing, simply add the html-loader
below ts-loader
like so (as you can see here):
{
test: /\.html$/,
use: [{ loader: "html-loader" }]
},
Upvotes: 1