UNPKG

fd-gulp-jsconcat

Version:

concat js files according to those rules listed on this page(http://wd.alibaba-inc.com/doc/page/work/cbu-regulations/merge)

85 lines (73 loc) 2.9 kB
require('chai').should(); require('mocha'); var constants = require('../assets/constants'); var helper = require('../assets/helper'); var gutil = require('gulp-util'); var PluginError = gutil.PluginError; describe('regular expression testing', function() { it('a ImportJavscript.url()-like str exists', function() { var str = 'ImportJavscript.url("./a")'; constants.JS_IMPORT_RE.test(str).should.be.true; }) it('a ImportJavscript.url()-like str not exists', function() { var str = 'ImportJavscript.url("./a");something else'; constants.JS_IMPORT_RE.test(str).should.be.false; }) it('a merge comment str exists', function() { var str = 'something ahead \n' + '/*merge start*/ \n' + '(function(){ \n' + 'ImportJavscript = { \n' + ' url:function(url){ \n' + ' document.write("<script type=\"text/javascript\" src=\""+url+"\"></scr"+"ipt>"); \n' + ' } \n' + ' } \n' + '})(); \n' + '/*!!cmd:compress=true*/ \n' + '/*!!cmd:jsCompressOpt=["--disable-optimizations"]*/ \n' + '/*merge end*/ \n' + 'something trailing'; constants.JS_MERGE_COMMENT_RE.test(str).should.be.true; }) }) describe('helper testing', function() { it('test getFileName func - url', function() { var fileName = helper.getFileName('d:/workspace/style_search', 'http://style.c.aliimg.com/app/search/js/test.js', { path: 'd:/workspace/style_search/filter/merge.min.js' }, 'http://style.c.aliimg.com/'); fileName.should.equal('d:/workspace/style_search/js/test.js'); }) it('test getFileName func - fdevlib/sys files', function() { var fileName = helper.getFileName('d:/workspace/style_search', 'http://style.c.aliimg.com/fdevlib/js/test.js', { path: 'd:/workspace/style_search/filter/merge.min.js' }, 'http://style.c.aliimg.com/', 'd:/workspace'); fileName.should.equal('d:/workspace/fdevlib/js/test.js'); }) it('test getFileName func - local file', function() { var fileName = helper.getFileName('d:/workspace/style_search', './test.js', { path: 'd:/workspace/style_search/filter/merge.min.js' }, 'http://style.c.aliimg.com/') fileName.should.equal('d:/workspace/style_search/filter/test.js'); }) it('test getDomain func - no domain specified', function() { var domain = helper.getDomain({}); domain.should.equal('http://style.c.aliimg.com/'); }) it('test getDomain func - domain specified with trailing slash', function() { var domain = helper.getDomain({ domain: 'http://static.c.aliimg.com/' }) domain.should.equal('http://static.c.aliimg.com/'); }) it('test getDomain func - domain specified without trailing slash', function() { var domain = helper.getDomain({ domain: 'http://static.c.aliimg.com' }) domain.should.equal('http://static.c.aliimg.com/'); }) }) describe('error testing', function() { it('srcDir must not be missing', function() { require('../index').should.throw(Error); }) })