Set global values via grunt+karma karma.conf accessible in the JS context from the test (in browser)?

38 views
Skip to first unread message

brian.m...@gmail.com

unread,
Sep 29, 2016, 11:29:32 AM9/29/16
to karma-users

I have a large js webapp, and I am integration testing with protractor and unit testing with karma through grunt plugins.

I realized at one point that I wanted to share certain things across both tests, for example certain mockServices could be reused.

So I split my structure to be:
/testRoot
  /sharedMocks
  /tests
    /unit
    /integration

In the protractor conf's onPrepare function, I wrote a little script to load all files in /shareMocks, example fooMock.js that is a node module, gets imported, and put on global integration.mocks.foo available in any test ran from /integration.
The problem comes when I want to do the same thing symmetrically now in my unit tests. Karma doesn't have an onPrepare function, and seems to have a unique global context. There's no access to node framework, or globals from the grunt plugin, or karma conf.
Anyone have any idea how I can load node modules into a global context for my unit tests?


Cheers!

Reply all
Reply to author
Forward
0 new messages