├── .gitignore ├── .jshintrc ├── .travis.yml ├── LICENSE ├── README.md ├── bootstrap.js ├── context.html ├── debug.html ├── example ├── APP │ ├── build │ │ └── app.jsb3 │ ├── specs │ │ └── mixin │ │ │ └── Badge.spec.js │ ├── src │ │ └── mixin │ │ │ └── Badge.js │ ├── testapp.js │ └── testconfig.js ├── README.md ├── extjs │ └── README.md ├── gulpfile.js └── package.json ├── index.js ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | 27 | # Licenced software 28 | ext-all.js 29 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "eqeqeq": true, 8 | "immed": true, 9 | "indent": 4, 10 | "newcap": true, 11 | "noarg": true, 12 | "quotmark": "single", 13 | "regexp": true, 14 | "undef": true, 15 | "unused": true, 16 | "strict": true, 17 | "trailing": true, 18 | "smarttabs": true 19 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.10' 4 | notifications: 5 | slack: unit4open:kashdeuAVUCPIetTI2mwlmi5 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2015 Unit4 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [karma](http://karma-runner.github.io/)-extjs 2 | 3 | Use Karma to run tests for Ext JS applications. Run tests and measure coverage without any html-file facilitation. 4 | 5 | [![NPM Version][npm-image]][npm-url] 6 | [![Build Status][travis-image]][travis-url] 7 | [![Dependency Status][dependencies-image]][dependencies-url] 8 | 9 | ## Install 10 | 11 | ```bash 12 | $ npm install --save-dev karma-extjs 13 | ``` 14 | 15 | 16 | ## Usage 17 | 18 | ```js 19 | var karma = require('karma-extjs'); 20 | 21 | karma.run({ 22 | coverage: true, 23 | staticPort: 9877, 24 | jsb3: 'APP/build/packages.jsb3', 25 | beforeSource: [ 26 | 'extjs/ext-all.js', 27 | 'appconfig.js' 28 | ], 29 | afterSource: [ 30 | 'testapp.js' 31 | ], 32 | tests: [ 33 | 'APP/specs/**/*.spec.js' 34 | ] 35 | }); 36 | ``` 37 | 38 | The appconfig.js is typically a file that sets the Ext JS config. Something like: 39 | 40 | ```js 41 | Ext.Loader.setConfig({ 42 | enabled: true, 43 | paths: { 44 | 'APP': 'http://' + window.location.host + '/base/APP/src', 45 | 'APPTests': 'http://' + window.location.host + '/base/APP/specs' 46 | }, 47 | disableCaching: true 48 | }); 49 | ``` 50 | 51 | The testapp.js is typically a file that starts the Ext JS application. Somethig like: 52 | 53 | ```js 54 | Ext.Loader.loadScript({ 55 | url: '/base/APP/src/init.js', 56 | onLoad: function () { 57 | Ext.application({ 58 | inhibitLaunch: true 59 | }); 60 | } 61 | }); 62 | ``` 63 | 64 | ## API 65 | 66 | ### run(options) 67 | 68 | #### options 69 | 70 | ##### jsb3 71 | 72 | Type: `string` 73 | 74 | Path to the jsb3 file of your application/package. This is used to append source files to Karma config 75 | in the correct order. 76 | 77 | ##### coverage 78 | 79 | Type: `Boolean` 80 | Default: `false` 81 | 82 | Enable coverage. `true` will add 'coverage' preprocessors to source files and add the coverage reporter. 83 | 84 | ##### staticPort 85 | 86 | Type: `Number` 87 | Default `9877` 88 | 89 | Serve the root of the project. Karma will use this server as a proxy when files are layzy loaded. 90 | 91 | ##### beforeSource 92 | 93 | Type: `Array` of `strings` 94 | 95 | File(s) to append to Karma files before the source files are appended. 96 | 97 | ##### afterSource 98 | 99 | Type: `Array` of `strings` 100 | 101 | File(s) to append to Karma files after the source files are appended. 102 | 103 | ##### karma 104 | 105 | Type: `Object` 106 | 107 | Dictionary with [Karma](http://karma-runner.github.io/) config. 108 | 109 | Defaults: 110 | - **port**: `9876` 111 | - **singleRun**: `true` 112 | - **reporters**: `progress` 113 | - **browsers**: `Chrome` 114 | - **frameworks**: `jasmine` 115 | 116 | Note: **proxies** option is overridden and cannot be configured through the API. 117 | 118 | ## License 119 | 120 | [MIT](http://opensource.org/licenses/MIT) © [Unit4](http://www.unit4.com/) 121 | 122 | [travis-image]: https://travis-ci.org/Unit4/karma-extjs.svg?branch=master 123 | [travis-url]: https://travis-ci.org/Unit4/karma-extjs 124 | [npm-image]: http://img.shields.io/npm/v/karma-extjs.svg 125 | [npm-url]: https://www.npmjs.org/package/karma-extjs 126 | [dependencies-image]: https://david-dm.org/unit4/karma-extjs.svg 127 | [dependencies-url]: https://david-dm.org/unit4/karma-extjs 128 | -------------------------------------------------------------------------------- /bootstrap.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | var karmaLoadedFunction = window.__karma__.loaded, 3 | Ext4Ready = false, 4 | Ext6Ready = false; 5 | 6 | window.__karma__.loaded = function(){}; 7 | 8 | if(typeof Ext !== 'undefined'){ 9 | Ext.onReady(function () { 10 | Ext4Ready = true; 11 | }); 12 | } else { 13 | Ext4Ready = true; 14 | } 15 | 16 | if(typeof Ext6 !== 'undefined'){ 17 | Ext6.onReady(function () { 18 | Ext6Ready = true; 19 | }); 20 | } else { 21 | Ext6Ready = true; 22 | } 23 | 24 | function launchTests() { 25 | 26 | if(Ext4Ready && Ext6Ready){ 27 | window.__karma__.loaded = karmaLoadedFunction; 28 | window.__karma__.loaded(); 29 | } else { 30 | setTimeout(function () { 31 | launchTests(); 32 | }, 200); 33 | } 34 | } 35 | 36 | launchTests(); 37 | }()); -------------------------------------------------------------------------------- /context.html: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 26 | 27 | %SCRIPTS% 28 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /debug.html: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | %X_UA_COMPATIBLE% 10 | Karma DEBUG RUNNER 11 | 12 | 13 | 14 | 15 | 19 | 51 | 52 | %SCRIPTS% 53 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /example/APP/build/app.jsb3: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "Example", 3 | "licenseText": "", 4 | "packages": [ 5 | { 6 | "name": "APP", 7 | "target": "pkgs/app.js", 8 | "id": "app", 9 | "files": [ 10 | { 11 | "path": "../src/mixin/", 12 | "name": "Badge.js" 13 | } 14 | ] 15 | } 16 | ], 17 | "builds": [ 18 | { 19 | "name": "All Debug", 20 | "target": "all-debug.js", 21 | "packages": [ 22 | "app" 23 | ] 24 | } 25 | ], 26 | "resources": [ 27 | 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /example/APP/specs/mixin/Badge.spec.js: -------------------------------------------------------------------------------- 1 | /*global Ext, describe, it*/ 2 | 3 | Ext.require('APP.mixin.Badge'); 4 | 5 | describe('APP.mixin.Badge', function () { 6 | var badge; 7 | 8 | beforeEach(function () { 9 | badge = Ext.create('APP.mixin.Badge'); 10 | badge.on = function () { }; 11 | }); 12 | 13 | it('registers after render event', function () { 14 | spyOn(badge, 'on'); 15 | 16 | badge.init(); 17 | 18 | expect(badge.on).toHaveBeenCalledWith('afterrender', badge.renderBadge, badge); 19 | }); 20 | 21 | it('renders', function(){ 22 | badge.renderBadge(); 23 | 24 | expect(badge.rendered).toBeTruthy(); 25 | }) 26 | }); -------------------------------------------------------------------------------- /example/APP/src/mixin/Badge.js: -------------------------------------------------------------------------------- 1 | /*global Ext*/ 2 | 3 | /** 4 | * A badge mixin 5 | */ 6 | Ext.define('APP.mixin.Badge', { 7 | /** 8 | * 9 | */ 10 | init: function () { 11 | var me = this; 12 | 13 | me.on('afterrender', me.renderBadge, me); 14 | }, 15 | 16 | /** 17 | * @private 18 | **/ 19 | renderBadge: function () { 20 | var me = this; 21 | me.rendered = true; 22 | } 23 | }); 24 | -------------------------------------------------------------------------------- /example/APP/testapp.js: -------------------------------------------------------------------------------- 1 | Ext.Loader.loadScript({ 2 | onLoad: function () { 3 | Ext.application({ 4 | inhibitLaunch: true, 5 | bootDependencies: [ ], 6 | bootDependenciesThen: function () { 7 | 8 | } 9 | }); 10 | } 11 | }); -------------------------------------------------------------------------------- /example/APP/testconfig.js: -------------------------------------------------------------------------------- 1 | /*global window*/ 2 | 3 | Ext.Loader.setConfig({ 4 | enabled: true, 5 | paths: { 6 | 'APP': 'http://' + window.location.host + '/base/APP/src' 7 | }, 8 | disableCaching: true 9 | }); -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | 3 | Do the following to run tests with coverage 4 | 5 | ```bash 6 | $ npm install 7 | $ gulp coverage 8 | ``` 9 | 10 | -------------------------------------------------------------------------------- /example/extjs/README.md: -------------------------------------------------------------------------------- 1 | Put ext-all.js here -------------------------------------------------------------------------------- /example/gulpfile.js: -------------------------------------------------------------------------------- 1 | /*global require*/ 2 | 3 | var gulp = require('gulp'); 4 | var gutil = require('gulp-util'); 5 | var argv = require('yargs').argv; 6 | var karma = require('karma-extjs'); 7 | 8 | gulp.task('coverage', function () { 9 | return karma.run({ 10 | staticPort: 9877, 11 | coverage: true, 12 | jsb3: 'APP/build/app.jsb3', 13 | beforeSource: [ 14 | 'extjs/ext-all.js', 15 | 'APP/testconfig.js' 16 | ], 17 | afterSource: [ 18 | 'APP/testapp.js' 19 | ], 20 | tests: [ 21 | 'APP/specs/**/*.spec.js' 22 | ], 23 | karma: { 24 | browserNoActivityTimeout: 20000, 25 | coverageReporter: { 26 | type: 'html', 27 | dir: argv.o ? argv.o : 'coverage/' 28 | }, 29 | exclude: [ 30 | ] 31 | } 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Example", 3 | "description": "Example", 4 | "version": "0.0.1", 5 | "private": true, 6 | "dependencies": { 7 | "gulp": "*", 8 | "gulp-compass": "1.1.x", 9 | "gulp-concat": "2.2.x", 10 | "gulp-jshint": "1.5.x", 11 | "gulp-rename": "1.2.x", 12 | "gulp-uglify": "0.2.x", 13 | "gulp-util": "2.2.x", 14 | "yargs": "1.2.x", 15 | "karma-extjs": "0.1.8" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var Q = require('q'); 3 | var path = require('path'); 4 | var http = require('http'); 5 | var ecstatic = require('ecstatic'); 6 | var Server = require('karma').Server; 7 | var merge = require('merge'); 8 | var jsb3 = require('jsb3'); 9 | var path = require('path'); 10 | 11 | var bootstrapFile = { pattern: path.join(__dirname, '/bootstrap.js'), included: true, served: true, watched: false }; 12 | 13 | function applyFilter(list, filter) { 14 | if (typeof filter === 'string') { 15 | filter = [filter]; 16 | } 17 | 18 | filter = filter.map(escapeBars).map(createRegex); 19 | 20 | list = list.filter(function(file) { 21 | return filter.some(function(regex) { 22 | return regex.test(file); 23 | }); 24 | }); 25 | 26 | return list; 27 | } 28 | 29 | function escapeBars(regex) { 30 | return regex.replace(/\\/g, '\\\\').replace(/\//g, '\/'); 31 | } 32 | 33 | function createRegex(regex) { 34 | return new RegExp(regex); 35 | } 36 | 37 | module.exports = { 38 | run: function(options) { 39 | var me = this, 40 | sourcePromise; 41 | 42 | sourcePromise = options.jsb3 ? jsb3(options.jsb3) : Promise.resolve([]); 43 | 44 | return sourcePromise.then(function(source) { 45 | return me.startKarma(me.setOptions(options, source)); 46 | }); 47 | }, 48 | 49 | setOptions: function(options, source) { 50 | source = source || []; 51 | options = options || {}; 52 | options.karma = options.karma || []; 53 | 54 | // Default options 55 | options.coverage = options.coverage || false; 56 | options.staticPort = options.staticPort || 9877; 57 | options.beforeSource = options.beforeSource || []; 58 | options.afterSource = options.afterSource || []; 59 | 60 | // Karma options 61 | options.karma.port = options.karma.port || 9876; 62 | options.karma.singleRun = options.karma.singleRun !== false; 63 | options.karma.reporters = options.karma.reporters || ['progress']; 64 | options.karma.browsers = options.karma.browsers || ['Chrome']; 65 | options.karma.frameworks = options.karma.frameworks || ['jasmine']; 66 | options.karma.preprocessors = options.karma.preprocessors || {}; 67 | options.karma.proxies = { 68 | '/base': 'http://localhost:' + options.staticPort 69 | }; 70 | options.karma.client = { 71 | args: options.filter ? ['--grep=' + options.filter] : [] 72 | }; 73 | 74 | var sources = source.slice(0); 75 | 76 | if (options.filterSource) { 77 | sources = applyFilter(sources, options.filterSource); 78 | } 79 | 80 | options.karma.files = [] 81 | .concat(options.beforeSource) 82 | .concat([bootstrapFile]) 83 | .concat(sources) 84 | .concat(options.afterSource) 85 | .concat(options.tests); 86 | 87 | if (options.coverage && sources) { 88 | var filesToCover = sources.slice(0); 89 | 90 | if (options.filterCoverage) { 91 | filesToCover = applyFilter(filesToCover, options.filterCoverage); 92 | } 93 | 94 | options.karma.reporters.push('coverage'); 95 | options.karma.preprocessors = merge(options.karma.preprocessors, this.preprocessCoverage(filesToCover)); 96 | } 97 | 98 | options.karma.customContextFile = path.join(__dirname, '/context.html'); 99 | options.karma.customDebugFile = path.join(__dirname, '/debug.html'); 100 | 101 | return options; 102 | }, 103 | 104 | startKarma: function(options) { 105 | var deferred = Q.defer(); 106 | 107 | var staticServer = this.serveStatic(options.staticPort, options.staticLocation); 108 | 109 | var karma = new Server(options.karma, function(exitCode) { 110 | console.log('Karma has exited with ' + exitCode); 111 | deferred.resolve(exitCode); 112 | 113 | // Close the static server after karma exists 114 | staticServer.close(); 115 | }); 116 | 117 | karma.start(); 118 | 119 | return deferred.promise; 120 | }, 121 | 122 | preprocessCoverage: function(files) { 123 | var cover = {}; 124 | files.forEach(function(file) { 125 | cover[file] = 'coverage'; 126 | }); 127 | 128 | return cover; 129 | }, 130 | 131 | serveStatic: function(port, location) { 132 | var location = location || './'; 133 | 134 | var server = http.createServer( 135 | ecstatic({ 136 | root: location 137 | }) 138 | ).listen(port, function() { 139 | console.log('Serving ' + path.resolve(location) + ' on port ' + port); 140 | }).on('close', function() { 141 | console.log('Server closing ' + path.resolve(location) + ' on port ' + port); 142 | }); 143 | 144 | return server; 145 | } 146 | }; 147 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "karma-extjs", 3 | "version": "1.0.17", 4 | "description": "Use Karma to run tests for Ext JS applications", 5 | "license": "MIT", 6 | "author": "Bjørn Harald Olsen ", 7 | "homepage": "https://github.com/unit4/karma-extjs", 8 | "contributors": [ 9 | "Juan Gabriel Jiménez " 10 | ], 11 | "main": "index.js", 12 | "scripts": { 13 | "test": "mocha" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git://github.com/unit4/karma-extjs.git" 18 | }, 19 | "keywords": [ 20 | "karma", 21 | "jasmine", 22 | "coverage", 23 | "test", 24 | "sencha", 25 | "extjs", 26 | "jsb3" 27 | ], 28 | "bugs": { 29 | "url": "https://github.com/unit4/karma-extjs/issues" 30 | }, 31 | "dependencies": { 32 | "ecstatic": "2.1.x", 33 | "jasmine-core": "2.5.x", 34 | "jsb3": "1.0.x", 35 | "karma": "1.7.x", 36 | "karma-chrome-launcher": "2.1.x", 37 | "karma-coverage": "1.1.x", 38 | "karma-edge-launcher": "^0.4.1", 39 | "karma-firefox-launcher": "1.0.x", 40 | "karma-generic-preprocessor": "1.1.0", 41 | "karma-ie-launcher": "1.0.x", 42 | "karma-jasmine": "1.1.x", 43 | "karma-junit-reporter": "^1.0.0", 44 | "karma-mocha-reporter": "^2.0.0", 45 | "karma-phantomjs-launcher": "1.0.x", 46 | "karma-script-launcher": "1.0.x", 47 | "merge": "1.2.x", 48 | "phantomjs": "2.1.x", 49 | "q": "2.0.x" 50 | }, 51 | "devDependencies": { 52 | "mocha": "*" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var kextjs = require('./index'); 4 | var path = require('path'); 5 | 6 | it('should add coverage to preprocessor dictionary', function(cb) { 7 | var prep = kextjs.preprocessCoverage(['file1', 'file2']); 8 | 9 | assert.strictEqual('coverage', prep.file1); 10 | assert.strictEqual('coverage', prep.file2); 11 | 12 | cb(); 13 | }); 14 | 15 | it('should default module options', function(cb) { 16 | var options = kextjs.setOptions(); 17 | assert(options.beforeSource); 18 | assert(options.beforeSource.length === 0); 19 | assert(options.afterSource); 20 | assert(options.afterSource.length === 0); 21 | assert(options.coverage === false); 22 | assert.strictEqual(9877, options.staticPort); 23 | 24 | cb(); 25 | }); 26 | 27 | it('should default karma options', function(cb) { 28 | var options = kextjs.setOptions(); 29 | assert.strictEqual(9876, options.karma.port, 'Expects default port'); 30 | assert(options.karma.singleRun); 31 | assert('progress', options.karma.reporters.pop()); 32 | assert('Chrome', options.karma.browsers.pop()); 33 | assert('jasmine', options.karma.frameworks.pop()); 34 | assert(options.karma.preprocessors); 35 | 36 | cb(); 37 | }); 38 | 39 | it('should not override module options', function(cb) { 40 | var options = kextjs.setOptions({ 41 | beforeSource: ['before.js'], 42 | afterSource: ['after.js'], 43 | coverage: true, 44 | staticPort: 1111 45 | }); 46 | 47 | assert(options.beforeSource); 48 | assert.strictEqual('before.js', options.beforeSource[0]); 49 | assert(options.afterSource); 50 | assert.strictEqual('after.js', options.afterSource[0]); 51 | assert(options.coverage); 52 | assert.strictEqual(1111, options.staticPort); 53 | 54 | cb(); 55 | }); 56 | 57 | it('should not override karma options', function(cb) { 58 | var options = kextjs.setOptions({ 59 | karma: { 60 | port: 1111, 61 | singleRun: false, 62 | reporters: ['otherreporter'], 63 | browsers: ['otherbrowser'], 64 | frameworks: ['otherframework'], 65 | preprocessors: { 66 | myfile: 'process' 67 | } 68 | } 69 | }); 70 | 71 | assert.strictEqual(1111, options.karma.port, 'Expects default port'); 72 | assert(!options.karma.singleRun, 'Expect single run false'); 73 | assert('otherreporter', options.karma.reporters.pop(), 'Expects reporter set'); 74 | assert('otherbrowser', options.karma.browsers.pop(), 'Expects browser set'); 75 | assert('otherframework', options.karma.frameworks.pop(), 'Expects framework set'); 76 | assert.strictEqual('process', options.karma.preprocessors.myfile, 'Expects preprocessor set'); 77 | 78 | cb(); 79 | }); 80 | 81 | it('should add coverage preprocessors', function(cb) { 82 | var options = kextjs.setOptions({ 83 | coverage: true, 84 | karma: { 85 | reporters: ['junit'] 86 | } 87 | }, ['file1', 'file2']); 88 | 89 | assert.strictEqual('coverage', options.karma.reporters.pop(), 'Expects coverage reporter'); 90 | assert.strictEqual('coverage', options.karma.preprocessors.file1, 'Expects file 1 preprocessors set'); 91 | assert.strictEqual('coverage', options.karma.preprocessors.file2, 'Expects file 2 preprocessors set'); 92 | 93 | cb(); 94 | }); 95 | 96 | it('should concat before files, source files, after files and spec files', function(cb) { 97 | var options = kextjs.setOptions({ 98 | beforeSource: ['before.js'], 99 | afterSource: ['after.js'], 100 | tests: ['fixture1.js', 'fixture2.js'] 101 | }, ['src1.js', 'src2.js']), 102 | bootstrap; 103 | 104 | assert.strictEqual('fixture2.js', options.karma.files.pop()); 105 | assert.strictEqual('fixture1.js', options.karma.files.pop()); 106 | assert.strictEqual('after.js', options.karma.files.pop()); 107 | assert.strictEqual('src2.js', options.karma.files.pop()); 108 | assert.strictEqual('src1.js', options.karma.files.pop()); 109 | bootstrap = options.karma.files.pop().pattern; 110 | assert.equal(bootstrap.indexOf('bootstrap.js') !== -1, true); 111 | assert.strictEqual('before.js', options.karma.files.pop()); 112 | 113 | cb(); 114 | }); 115 | 116 | it('should filter source files by given expression in filterSources config', function(cb) { 117 | var options = kextjs.setOptions({ 118 | beforeSource: ['before.js'], 119 | afterSource: ['after.js'], 120 | tests: ['fixture1.js', 'fixture2.js'], 121 | filterSource: 'U4/src/some' 122 | }, ['U4/src/some/src1.js', 'U4/src/other/src2.js']), 123 | bootstrap; 124 | 125 | assert.strictEqual('fixture2.js', options.karma.files.pop()); 126 | assert.strictEqual('fixture1.js', options.karma.files.pop()); 127 | assert.strictEqual('after.js', options.karma.files.pop()); 128 | assert.strictEqual('U4/src/some/src1.js', options.karma.files.pop()); 129 | bootstrap = options.karma.files.pop().pattern; 130 | assert.equal(bootstrap.indexOf('bootstrap.js') !== -1, true); 131 | assert.strictEqual('before.js', options.karma.files.pop()); 132 | 133 | cb(); 134 | }); 135 | 136 | it('should filter source files by given list of expressions in filterSources config', function(cb) { 137 | var options = kextjs.setOptions({ 138 | beforeSource: ['before.js'], 139 | afterSource: ['after.js'], 140 | tests: ['fixture1.js', 'fixture2.js'], 141 | filterSource: ['U4/src/some/one', 'U4/src/some/two'] 142 | }, ['U4/src/some/one/src1.js', 'U4/src/some/two/src2.js', 'U4/src/some/three/src3.js']), 143 | bootstrap; 144 | 145 | assert.strictEqual('fixture2.js', options.karma.files.pop()); 146 | assert.strictEqual('fixture1.js', options.karma.files.pop()); 147 | assert.strictEqual('after.js', options.karma.files.pop()); 148 | assert.strictEqual('U4/src/some/two/src2.js', options.karma.files.pop()); 149 | assert.strictEqual('U4/src/some/one/src1.js', options.karma.files.pop()); 150 | bootstrap = options.karma.files.pop().pattern; 151 | assert.equal(bootstrap.indexOf('bootstrap.js') !== -1, true); 152 | assert.strictEqual('before.js', options.karma.files.pop()); 153 | 154 | cb(); 155 | }); 156 | 157 | it('should filter source files to cover by given expression in filterCoverage config', function(cb) { 158 | var options = kextjs.setOptions({ 159 | beforeSource: ['before.js'], 160 | afterSource: ['after.js'], 161 | tests: ['fixture1.js', 'fixture2.js'], 162 | filterCoverage: 'U4/src/some', 163 | coverage: true 164 | }, ['U4/src/some/src1.js', 'U4/src/other/src2.js']); 165 | 166 | assert.strictEqual(1, Object.keys(options.karma.preprocessors).length); 167 | assert.strictEqual('coverage', options.karma.preprocessors['U4/src/some/src1.js']); 168 | 169 | cb(); 170 | }); 171 | 172 | it('should filter source files to cover by given list of expressions in filterCoverage config', function(cb) { 173 | var options = kextjs.setOptions({ 174 | beforeSource: ['before.js'], 175 | afterSource: ['after.js'], 176 | tests: ['fixture1.js', 'fixture2.js'], 177 | filterCoverage: ['U4/src/some/one', 'U4/src/some/two'], 178 | coverage: true 179 | }, ['U4/src/some/one/src1.js', 'U4/src/some/two/src2.js', 'U4/src/some/three/src3.js']); 180 | 181 | assert.strictEqual(2, Object.keys(options.karma.preprocessors).length); 182 | assert.strictEqual('coverage', options.karma.preprocessors['U4/src/some/one/src1.js']); 183 | assert.strictEqual('coverage', options.karma.preprocessors['U4/src/some/two/src2.js']); 184 | 185 | cb(); 186 | }); 187 | 188 | it('should use a custom context file', function(cb){ 189 | var options = kextjs.setOptions({ 190 | tests: ['fixture1.js', 'fixture2.js'], 191 | }, ['src1.js']); 192 | 193 | assert.strictEqual(options.karma.customContextFile, path.join(__dirname, '/context.html')); 194 | 195 | cb(); 196 | }); 197 | 198 | it('should use a custom debug file', function(cb){ 199 | var options = kextjs.setOptions({ 200 | tests: ['fixture1.js', 'fixture2.js'], 201 | }, ['src1.js']); 202 | 203 | assert.strictEqual(options.karma.customDebugFile, path.join(__dirname, '/debug.html')); 204 | 205 | cb(); 206 | }); 207 | --------------------------------------------------------------------------------