Closed dotnetCarpenter closed 2 years ago
I assume that your actual app includes the libraries via script tags. If that's the case you should be able to add them to the srcFiles list. For instance, if jQuery is public/libs/jQuery.js:
{
"srcDir": "public/js",
"srcFiles": [
"../libs/jQuery.js",
"**/*.?(m)js"
],
// [...]
I currently use jsDelivr CDN. https://cdn.jsdelivr.net/npm/...
.
Using Karma I can add external files like so:
// List of files/patterns to load in the browser.
files: [
'https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js',
'https://cdn.jsdelivr.net/npm/underscore@1.13.1/underscore-min.js',
{
pattern: 'public/js/*',
included: true,
served: true,
watched: false,
nocache: false,
type: 'js'
},{
pattern: 'spec/unit/*.js',
included: true,
served: true,
watched: false,
nocache: false,
type: 'js'
}],
jasmine-browser-runner looks interesting but I needed to get it working ASAP, so I switched to Karma.
Leaving this open, in case you want to implement something similar to Karma's solution, but feel free to close this.
Cheers, and thank you for the attention :)
That seems reasonable. (It's always surprised me that almost nobody in the long history of Jasmine's other runners has asked for it.) I think the easiset and likely best way to implement it would be to allow any of the file glob arrays (srcFiles, specFiles, and helpers) to contain URLs as well as file globs. I'd be happy to review a PR that added that functionality.
Just to clarify. I will not work on this issue, since I use Karma now (which has support for CDN).
But I'm interested and will keep an eye out for this space.
This is done in 027690a and will be in the next release.
I'm trying to add jasmine to a legacy project but I have not been able to find if it's possible or how to inject library code into the test runner page.
I see that each file in my
srcDir
is included on the page served onlocalhost:8888
. Our client codebase expects underscore.js and jQuery but where do I define them as globally available when we do not have a package system or use ESM?I would like to use jasmine for our nodejs express code as well so using the Standalone version would probably mean that we will have to maintain two versions of Jasmine until we have time to rewrite our project (which could benefit hugely from having unit-tests in that process).
The beginning of the test page:
jasmine-browser.json
nodejs: v14.17.3 jasmine: 3.8.0 jasmine-browser-runner: 0.7.0