1var fs = require('fs') 2var path = require('path') 3var chai = require('chai') 4var sinon = require('sinon') 5var sinonChai = require('sinon-chai') 6var expect = chai.expect 7chai.use(sinonChai) 8 9var md5 = require('md5') 10var getBundle = require('../lib/require-bundle').getBundle 11 12 13describe('bundle of 3rd party js', function () { 14 it('one entry file', function () { 15 var requiresObj = {} 16 var absolutePath = path.join(__dirname, 'bundle/a.js') 17 var md5Path = md5(absolutePath) 18 requiresObj[md5Path] = absolutePath 19 20 var outputBundleCode = getBundle(requiresObj) 21 var evalCode = outputBundleCode + '; var aModule = browserifyRequire("' + md5Path + '"); aModule.getA();' 22 expect(eval(evalCode)).eql('ab') 23 }) 24 25 it('multiple entry file', function () { 26 var requiresObj = {} 27 var absolutePathA = path.join(__dirname, 'bundle/a.js') 28 var md5PathA = md5(absolutePathA) 29 requiresObj[md5PathA] = absolutePathA 30 var absolutePathC = path.join(__dirname, 'bundle/c.js') 31 var md5PathC = md5(absolutePathC) 32 requiresObj[md5PathC] = absolutePathC 33 34 var outputBundleCode = getBundle(requiresObj) 35 var evalCodeA = outputBundleCode + '; var aModule = browserifyRequire("' + md5PathA + '"); aModule.getA();' 36 var evalCodeC = outputBundleCode + '; var cModule = browserifyRequire("' + md5PathC + '"); cModule.getC();' 37 expect(eval(evalCodeA)).eql('ab') 38 expect(eval(evalCodeC)).eql('c require') 39 }) 40}) 41