monounity / karma-typescript

Simplifying running unit tests with coverage for Typescript projects.
313 stars 109 forks source link

[support] Loading test data / assets in bundle #493

Open thw0rted opened 3 years ago

thw0rted commented 3 years ago

I'm trying to convert tests from karma-webpack to karma-typescript. One of the outstanding issues I have is that some tests load test data via Webpack loaders, and I'm not sure how to replicate that behavior with Karma. I'm pretty sure that this isn't a general Karma issue, though, but specific to the way karma-ts bundling works.

I asked a detailed version of the question here on SO, but briefly, I'm serving the assets with

// Karma config
files: [
  { pattern: "src/app/**/*.xml", served: true, included: false, watched: false },
]

I can hard-code the path as e.g. fetch("/base/src/app/some/module/dir/test-data/test1.xml"), but I'd rather either a) bundle the data during the build process, or b) compute the fetch path at runtime based on module metadata.

If it helps clarify, I put together a simple repro here which includes commented-out code showing what I did in Webpack.