How to set source files in jasmine.jason

333 views
Skip to first unread message

Eduard Gut

unread,
Jan 9, 2020, 9:06:50 AM1/9/20
to Jasmine

At the moment I am using modules to connect the source and spec files in jasmine node like so:

source.js

"use strict"

let someFunction = function() {
some code here
};

module.exports = someFunction;

and I require it in the spec file like so:

let someFunction = require('pathToFile/source.js');

everything works fine but I really do not want to use modules just to connect source and spec files for jasmine.

The documentation says that it is possible to "customize spec/support/jasmine.json to enumerate the source files and spec files you would like the Jasmine runner to include."

But I did not found an example of how to do it so I have added the source file to helpers in jasmine.json like so:

"helpers": [
    "../path/source.js"
  ], 

but it did not work.

Any advice would be greatly appreciated.

Gregg Van Hove

unread,
Jan 14, 2020, 8:14:40 PM1/14/20
to jasmi...@googlegroups.com
Files in Node.js are expected to export something such they can be `require`d and have their functionality exposed to the world. Even if you don't want to use `module.exports` or similar, you'd then need to explicitly put all of the functionality on the `global` object somehow, but you would still have to `require` it to ensure that had already occurred by the time your tests start executing.

Effectively, this means that without that `module.exports` line (or something similar putting it on global) no other Node.js code is able to access any of the functions you declare in that file. You're not exporting it on `module` so that Jasmine can use it, but so that anything outside of that file can.

Hope this helps. Thanks for using Jasmine!

-Gregg

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jasmine-js/2f0bdb0c-fb3d-4b7f-a138-011ec140e329%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages