browserify - Jest and Bower Module loading in jest tests -


lets have project uses bower, grunt, bowerify(with shim) , since love jest want test that. how in world jest see browserify shim modules when runs tests. use grunt, kick off npm test command. here package.json file.

"browser": {     "jquery": "./bower_components/jquery/dist/jquery.js",     "foundation": "./bower_components/foundation/js/foundation/foundation.js",     "fastclick": "./bower_components/fastclick/lib/fastclick.js",     "greensock-tm": "./bower_components/gsap/src/uncompressed/tweenmax.js",     "greensock-css": "./bower_components/gsap/src/uncompressed/plugins/cssplugin.js",     "greensock-time": "./bower_components/gsap/src/uncompressed/timelinemax.js",     "scrollmagic": "./bower_components/scrollmagic/js/jquery.scrollmagic.js",     "handlebars": "./bower_components/handlebars/handlebars.runtime.js"   },   "browserify-shim": {     "jquery": "$",     "greensock-css": "cssplugin",     "fastclick": "fastclick",     "greensock-tm": "tweenmax",     "greensock-time": "timelinemax",     "scrollmagic": "scrollmagic",     "foundation": "foundation",     "handlebars": "handlebars"   },   "browserify": {     "transform": [       "browserify-shim"     ]   }, 

right have worked out doing in grunt file before run test.

grunt.registertask("shimbowerfortests",function(){     var readjson = require('read-package-json');     var fs = require('fs');     var remapify = require('remapify');     readjson('./package.json', console.error, false, function (er, data) {       if (er) {         throw "there error reading file";       }       var packages = data.browser;       var browserify = require('browserify');       (var key in packages){         var b = browserify();         var wstream = fs.createwritestream("devjs/test/modules/"+key+'.js');         b.add(packages[key]);         b.bundle().pipe(wstream);       }     });   }); 

and.

exec: {       jesttest: {         command: 'cp -r devjs/modules devjs/test/modules && npm test'       }     } 

the problem using browserify combine browser works great setup , can require shimmed modules this. require('jquery') //example in jest cli test fail because can find module unless somehow prefix ./, require('./jquery')

i'm guessing problem you've installed shimmed modules bower. if want them work in node/jest, you'll have install them npm well. make sure jest isn't mocking in node_modules directory, , should find required modules in there long names match up.

your jest config in package.json should like:

"jest": {   "unmockedmodulepathpatterns": [     "./node_modules"   ] } 

and download dependencies.

npm install jquery --save-dev 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -