improve unit testing

currently the only problem is that phantomjs is unable to parse the js files

fix test exec on travis env
This commit is contained in:
Yeiniel Suárez Sosa 2020-11-27 23:19:47 -05:00 committed by Yeiniel Suarez Sosa
parent 75b9cc60df
commit d3901cc286
No known key found for this signature in database
GPG Key ID: E2CFACE611B42B6C
11 changed files with 112 additions and 52 deletions

27
package-lock.json generated
View File

@ -1514,6 +1514,12 @@
"resolved": "https://registry.npmjs.org/angular/-/angular-1.8.2.tgz", "resolved": "https://registry.npmjs.org/angular/-/angular-1.8.2.tgz",
"integrity": "sha512-IauMOej2xEe7/7Ennahkbb5qd/HFADiNuLSESz9Q27inmi32zB0lnAsFeLEWcox3Gd1F6YhNd1CP7/9IukJ0Gw==" "integrity": "sha512-IauMOej2xEe7/7Ennahkbb5qd/HFADiNuLSESz9Q27inmi32zB0lnAsFeLEWcox3Gd1F6YhNd1CP7/9IukJ0Gw=="
}, },
"angular-mocks": {
"version": "1.8.2",
"resolved": "https://registry.npmjs.org/angular-mocks/-/angular-mocks-1.8.2.tgz",
"integrity": "sha512-I5L3P0l21HPdVsP4A4qWmENt4ePjjbkDFdAzOaM7QiibFySbt14DptPbt2IjeG4vFBr4vSLbhIz8Fk03DISl8Q==",
"dev": true
},
"angular-route": { "angular-route": {
"version": "1.8.2", "version": "1.8.2",
"resolved": "https://registry.npmjs.org/angular-route/-/angular-route-1.8.2.tgz", "resolved": "https://registry.npmjs.org/angular-route/-/angular-route-1.8.2.tgz",
@ -5272,6 +5278,11 @@
} }
} }
}, },
"jquery-linkify": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/jquery-linkify/-/jquery-linkify-2.2.1.tgz",
"integrity": "sha1-yXMApcqmaHeHfg05y5Jdg4XaZEs="
},
"js-tokens": { "js-tokens": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@ -5564,6 +5575,17 @@
"phantomjs-prebuilt": "^2.1.7" "phantomjs-prebuilt": "^2.1.7"
} }
}, },
"karma-webpack": {
"version": "5.0.0-alpha.3.0",
"resolved": "https://registry.npmjs.org/karma-webpack/-/karma-webpack-5.0.0-alpha.3.0.tgz",
"integrity": "sha512-ID2xYs8CnvPPbOCdj/ridr0w9l0vmuZem7hJP7yEXVQ94KhFG++IrTH1qj+EUO4ymll3ECLCw6N+nQIY/Nvj1w==",
"dev": true,
"requires": {
"glob": "^7.1.3",
"minimatch": "^3.0.4",
"webpack-merge": "^4.1.5"
}
},
"kew": { "kew": {
"version": "0.7.0", "version": "0.7.0",
"resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz", "resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz",
@ -8595,6 +8617,11 @@
"integrity": "sha512-8lBMSkFZuAK7gGF8LswsXmir8eX8d2AAMOnxSDWjKBx/fBR6MypQjs78m6ML9zQVp1/hD4TBdfeMZMC7nW1TAA==", "integrity": "sha512-8lBMSkFZuAK7gGF8LswsXmir8eX8d2AAMOnxSDWjKBx/fBR6MypQjs78m6ML9zQVp1/hD4TBdfeMZMC7nW1TAA==",
"dev": true "dev": true
}, },
"underscore": {
"version": "1.10.2",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.10.2.tgz",
"integrity": "sha512-N4P+Q/BuyuEKFJ43B9gYuOj4TQUHXX+j2FqguVOpjkssLUUrnJofCcBccJSCoeturDoZU6GorDTHSvUDlSQbTg=="
},
"unicode-canonical-property-names-ecmascript": { "unicode-canonical-property-names-ecmascript": {
"version": "1.0.4", "version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",

View File

@ -9,6 +9,7 @@
"devDependencies": { "devDependencies": {
"@babel/core": "^7.12.9", "@babel/core": "^7.12.9",
"@babel/preset-env": "^7.12.7", "@babel/preset-env": "^7.12.7",
"angular-mocks": "^1.8.2",
"babel-loader": "^8.2.2", "babel-loader": "^8.2.2",
"bower": "^1.8.8", "bower": "^1.8.8",
"copy-webpack-plugin": "^6.3.2", "copy-webpack-plugin": "^6.3.2",
@ -21,6 +22,7 @@
"karma-jasmine": "~3.1", "karma-jasmine": "~3.1",
"karma-junit-reporter": "~2.0", "karma-junit-reporter": "~2.0",
"karma-phantomjs-launcher": "^1.0.4", "karma-phantomjs-launcher": "^1.0.4",
"karma-webpack": "^5.0.0-alpha.3.0",
"linkifyjs": "^2.1.9", "linkifyjs": "^2.1.9",
"protractor": "^7.0.0", "protractor": "^7.0.0",
"shelljs": "^0.8.4", "shelljs": "^0.8.4",
@ -31,11 +33,9 @@
}, },
"scripts": { "scripts": {
"build": "webpack", "build": "webpack",
"postinstall": "bower install -p", "lint": "jshint src/js/*.js test/unit/*.js",
"minify": " uglifyjs js/localstorage.js js/weechat.js js/irc-utils.js js/glowingbear.js js/settings.js js/utils.js js/notifications.js js/filters.js js/handlers.js js/connection.js js/file-change.js js/imgur-drop-directive.js js/whenscrolled-directive.js js/inputbar.js js/plugin-directive.js js/websockets.js js/models.js js/bufferResume.js js/plugins.js js/imgur.js -c -m -o min.js --source-map url='min.js.map'",
"prestart": "npm install", "prestart": "npm install",
"start": "webpack serve", "start": "webpack serve",
"pretest": "npm install",
"test": "karma start test/karma.conf.js", "test": "karma start test/karma.conf.js",
"test-single-run": "karma start test/karma.conf.js --single-run", "test-single-run": "karma start test/karma.conf.js --single-run",
"preupdate-webdriver": "npm install", "preupdate-webdriver": "npm install",
@ -55,6 +55,8 @@
"angular-sanitize": "^1.8.2", "angular-sanitize": "^1.8.2",
"angular-touch": "^1.8.2", "angular-touch": "^1.8.2",
"favico.js": "^0.3.10", "favico.js": "^0.3.10",
"jquery-linkify": "^2.2.1",
"underscore": "^1.10.2",
"zlibjs": "^0.3.1" "zlibjs": "^0.3.1"
} }
} }

View File

@ -1,2 +1,2 @@
./node_modules/.bin/jshint js/*.js test/unit/*.js npm run lint
npm test npm test

View File

@ -19,7 +19,7 @@
<link rel="shortcut icon" type="image/png" href="assets/img/favicon.png" > <link rel="shortcut icon" type="image/png" href="assets/img/favicon.png" >
<link href="css/glowingbear.css" rel="stylesheet" media="screen"> <link href="css/glowingbear.css" rel="stylesheet" media="screen">
<link href="css/themes/dark.css" rel="stylesheet" media="screen" id="themeCSS" /> <link href="css/themes/dark.css" rel="stylesheet" media="screen" id="themeCSS" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.10.2/underscore-min.js" integrity="sha512-HKvDCFVKg8ZPGjecy6on7UECEpE76Y86h3GaE4JMCz+deFWdjcW/tWnh0hCfaBvURvlOa9f5CNVzt7EFkulYbw==" crossorigin="anonymous"></script> <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.10.2/underscore-min.js" integrity="sha512-HKvDCFVKg8ZPGjecy6on7UECEpE76Y86h3GaE4JMCz+deFWdjcW/tWnh0hCfaBvURvlOa9f5CNVzt7EFkulYbw==" crossorigin="anonymous"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.7/lib/js/emojione.min.js" integrity="sha256-9cBkVeU53NiJ9/BdcJta3HbERAmf5X9DE2WvL8V+gDs=" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.7/lib/js/emojione.min.js" integrity="sha256-9cBkVeU53NiJ9/BdcJta3HbERAmf5X9DE2WvL8V+gDs=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery-linkify/2.1.9/linkify.min.js" integrity="sha512-kxj7VjlzsQgiku2vbRcZI0FJ0dXmPsiRLugiRxJrCROusKHaFfX/hGDD1/L/R0Y+xI8zlA2B5nm6USapz7nQbg==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery-linkify/2.1.9/linkify.min.js" integrity="sha512-kxj7VjlzsQgiku2vbRcZI0FJ0dXmPsiRLugiRxJrCROusKHaFfX/hGDD1/L/R0Y+xI8zlA2B5nm6USapz7nQbg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery-linkify/2.1.9/linkify-string.min.js" integrity="sha512-CMBjJdVIcw7zafkE+uedZCnw6r4ABU1Fev5xA7db0D097/NzhO6Ajo2kdZFOQ+y0kg9sE/t44bPAwuuNhUVIcQ==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery-linkify/2.1.9/linkify-string.min.js" integrity="sha512-CMBjJdVIcw7zafkE+uedZCnw6r4ABU1Fev5xA7db0D097/NzhO6Ajo2kdZFOQ+y0kg9sE/t44bPAwuuNhUVIcQ==" crossorigin="anonymous"></script>

View File

@ -1,4 +1,3 @@
(function() {
'use strict'; 'use strict';
var weechat = angular.module('weechat'); var weechat = angular.module('weechat');
@ -235,6 +234,4 @@ weechat.filter('codify', function() {
return rr; return rr;
}); });
}; };
}); });
})();

View File

@ -2,9 +2,10 @@
* This file contains the plugin definitions * This file contains the plugin definitions
*/ */
(function() {
'use strict'; 'use strict';
import * as _ from "underscore";
var plugins = angular.module('plugins', []); var plugins = angular.module('plugins', []);
/* /*
@ -594,4 +595,3 @@ plugins.factory('userPlugins', function() {
}); });
})();

View File

@ -8,7 +8,10 @@ import "angular-touch";
import "./js/localstorage.js"; import "./js/localstorage.js";
import "./js/irc-utils.js"; import "./js/irc-utils.js";
import "./js/bufferResume.js";
import "./js/models.js";
import "./js/plugins.js"; import "./js/plugins.js";
import "./js/websockets.js";
import "./js/glowingbear.js"; import "./js/glowingbear.js";
import "./js/settings.js"; import "./js/settings.js";
import "./js/utils.js"; import "./js/utils.js";
@ -20,8 +23,5 @@ import "./js/imgur-drop-directive.js";
import "./js/whenscrolled-directive.js"; import "./js/whenscrolled-directive.js";
import "./js/inputbar.js"; import "./js/inputbar.js";
import "./js/plugin-directive.js"; import "./js/plugin-directive.js";
import "./js/websockets.js";
import "./js/bufferResume.js";
import "./js/models.js";
import "./js/imgur.js"; import "./js/imgur.js";

View File

@ -1,53 +1,72 @@
module.exports = function(config){ const webpackConfig = require('../webpack.config');
module.exports = function (config) {
config.set({ config.set({
basePath : '../', basePath: '../',
files : [ files: [
'bower_components/angular/angular.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-touch/angular-touch.js',
'bower_components/underscore/underscore.js',
'node_modules/linkifyjs/dist/linkify.js', 'node_modules/linkifyjs/dist/linkify.js',
'node_modules/linkifyjs/dist/linkify-string.js', 'node_modules/linkifyjs/dist/linkify-string.js',
'src/js/localstorage.js', 'test/unit/main.test.js'
'src/js/weechat.js',
'src/js/irc-utils.js',
'src/js/glowingbear.js',
'src/js/utils.js',
'src/js/notifications.js',
'src/js/filters.js',
'src/js/handlers.js',
'src/js/connection.js',
'src/js/inputbar.js',
'src/js/plugin-directive.js',
'src/js/websockets.js',
'src/js/models.js',
'src/js/bufferResume.js',
'src/js/plugins.js',
'test/unit/**/*.js'
], ],
autoWatch : true, autoWatch: true,
frameworks: ['jasmine'], frameworks: ['jasmine'],
browsers : ['PhantomJS'], browsers: ['Chrome', 'ChromeHeadless', 'ChromeHeadlessNoSandbox'],
singleRun: true, singleRun: true,
plugins : [ plugins: [
'karma-phantomjs-launcher', 'karma-phantomjs-launcher',
'karma-jasmine', 'karma-jasmine',
'karma-junit-reporter' 'karma-junit-reporter',
], 'karma-webpack'
],
junitReporter : { customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--disable-setuid-sandbox']
}
},
junitReporter: {
outputFile: 'test_out/unit.xml', outputFile: 'test_out/unit.xml',
suite: 'unit' suite: 'unit'
} },
/* karma-webpack config
pass your webpack configuration for karma
add `babel-loader` to the webpack configuration to make
the ES6+ code in the test files readable to the browser
eg. import, export keywords */
webpack: {
devtool: webpackConfig.devtool,
module: webpackConfig.module,
optimization: {
runtimeChunk: false,
splitChunks: false
},
},
preprocessors: {
//add webpack as preprocessor to support require() in test-suits .js files
'./test/unit/*.js': ['webpack'],
'./src/**/*.js': ['webpack']
},
// webpackMiddleware: {
// //turn off webpack bash output when run the tests
// noInfo: true,
// stats: 'errors-only'
// }
}); });
if(process.env.TRAVIS){
config.browsers = ['ChromeHeadlessNoSandbox'];
}
}; };

View File

@ -1,7 +1,13 @@
var weechat = angular.module('weechat'); "use strict";
import angular from "angular";
import "angular-mocks";
import "../../src/main";
describe('Filters', function() { describe('Filters', function() {
beforeEach(module('weechat')); beforeEach(angular.mock.module('weechat'));
/*beforeEach(module(function($provide) { /*beforeEach(module(function($provide) {
$provide.value('version', 'TEST_VER'); $provide.value('version', 'TEST_VER');
}));*/ }));*/

3
test/unit/main.test.js Normal file
View File

@ -0,0 +1,3 @@
import "./filters";
import "./plugins";

View File

@ -1,5 +1,11 @@
/* plugins go here */ /* plugins go here */
import angular from "angular";
import "angular-mocks";
import "../../src/main";
var msg = function(msg) { var msg = function(msg) {
return {'text': msg }; return {'text': msg };
}; };
@ -22,10 +28,10 @@ var expectTheseMessagesToContain = function(urls, pluginType, plugins) {
}; };
describe('filter', function() { describe('filter', function() {
beforeEach(module('plugins')); beforeEach(angular.mock.module('plugins'));
describe('Plugins', function() { describe('Plugins', function() {
beforeEach(module(function($provide) { beforeEach(angular.mock.module(function($provide) {
$provide.value('version', 'TEST_VER'); $provide.value('version', 'TEST_VER');
})); }));