Jasmine having better modularity

113 Views Asked by At

I am a newbie to jasmine, please correct me if I am asking a wrong question.

I am working on a legacy system which has a lot java script code. I would like to write some tests for the same. Initially I thought of using buster since it's in beta I didn't explored much about it. Meantime while searching I came across jasmine. Writing tests in jasmine was simple, maven plugin makes jasmine to be integrated with CI also we can get coverage report. So I felt to use jasmine.

In our current legacy systems there are several js, which need's a lot of refactoring . But to start off writing some test.I need some help. Let me narrate the problem I am facing

We have a lot of scripts having conflicting function names, and global variable's and so on. So specifying the jsSource in pom or jstestconf file is cumbersome, as I need to exclude few files, sometimes scripts which needs tests might have a conflicting function name. Also some scripts may be dependent on other's and so on.

Is there a way in jasmine the below mentioned scenario could be achieved.

Test1.js

  • Include specific library, excluding common once
  • Include the java script(Source1.js) source which needs to tested
  • Then write the tests

Test2.js

  • Include specific library, excluding common once
  • Include the javascript source(Source2.js) which needs to be tested to tested
  • Then write the tests

Something similar to junit's where we say include class which needs to be tested.

Doing some initial search I got to know by using requirejs I can achieve this. But I couldn't find any concrete example's.

I would need your opinion before proceeding further. Also is there any other testing framework which I use which have good integration with maven & eclipse and better modularity of tests.

1

There are 1 best solutions below

0
On

I've been using Karma to run jasmine tests, and you can specify the files Karma includes via the karma.conf.js files property. So you could set up 2 different configurations for Test1.js and Test2.js. For example (assuming you have node_modules and your other files are under my-application-root:

for config 1:

module.exports = function(config){
  config.set({
  basePath : './',

  //files to load in the browser
  files : [
    'my-application-root/specific-library-1.js',
    'my-application-root/Source1.js',
    'my-application-root/test/Test1.js',
    'my-application-root/node_modules/**/*.js'
  ],

  exclude : [
    'my-application-root/common-lib.js',
    'my-application-root/specific-library-2.js',
  ],

.......

and for config 2:

module.exports = function(config){
  config.set({
  basePath : './',

  //files to load in the browser
  files : [
    'my-application-root/specific-library-2.js',
    'my-application-root/Source2.js',
    'my-application-root/test/Test2.js',
    'my-application-root/node_modules/**/*.js'
  ],

  exclude : [
    'my-application-root/common-lib.js',
    'my-application-root/specific-library-1.js',
  ],

.......