diff --git a/package-lock.json b/package-lock.json index 81a3206..1cdff5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1514,6 +1514,12 @@ "resolved": "https://registry.npmjs.org/angular/-/angular-1.8.2.tgz", "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": { "version": "1.8.2", "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": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -5564,6 +5575,17 @@ "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": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz", @@ -8595,6 +8617,11 @@ "integrity": "sha512-8lBMSkFZuAK7gGF8LswsXmir8eX8d2AAMOnxSDWjKBx/fBR6MypQjs78m6ML9zQVp1/hD4TBdfeMZMC7nW1TAA==", "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": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", diff --git a/package.json b/package.json index 0158f4a..e3eb1ca 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "devDependencies": { "@babel/core": "^7.12.9", "@babel/preset-env": "^7.12.7", + "angular-mocks": "^1.8.2", "babel-loader": "^8.2.2", "bower": "^1.8.8", "copy-webpack-plugin": "^6.3.2", @@ -21,6 +22,7 @@ "karma-jasmine": "~3.1", "karma-junit-reporter": "~2.0", "karma-phantomjs-launcher": "^1.0.4", + "karma-webpack": "^5.0.0-alpha.3.0", "linkifyjs": "^2.1.9", "protractor": "^7.0.0", "shelljs": "^0.8.4", @@ -31,11 +33,9 @@ }, "scripts": { "build": "webpack", - "postinstall": "bower install -p", - "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'", + "lint": "jshint src/js/*.js test/unit/*.js", "prestart": "npm install", "start": "webpack serve", - "pretest": "npm install", "test": "karma start test/karma.conf.js", "test-single-run": "karma start test/karma.conf.js --single-run", "preupdate-webdriver": "npm install", @@ -55,6 +55,8 @@ "angular-sanitize": "^1.8.2", "angular-touch": "^1.8.2", "favico.js": "^0.3.10", + "jquery-linkify": "^2.2.1", + "underscore": "^1.10.2", "zlibjs": "^0.3.1" } } diff --git a/run_tests.sh b/run_tests.sh index 7ae7475..a84cc5a 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,2 +1,2 @@ -./node_modules/.bin/jshint js/*.js test/unit/*.js +npm run lint npm test diff --git a/src/index.html b/src/index.html index 54e5fe4..d9d0a60 100644 --- a/src/index.html +++ b/src/index.html @@ -19,7 +19,7 @@ - + diff --git a/src/js/filters.js b/src/js/filters.js index 8887678..8568b01 100644 --- a/src/js/filters.js +++ b/src/js/filters.js @@ -1,4 +1,3 @@ -(function() { 'use strict'; var weechat = angular.module('weechat'); @@ -235,6 +234,4 @@ weechat.filter('codify', function() { return rr; }); }; -}); - -})(); +}); \ No newline at end of file diff --git a/src/js/plugins.js b/src/js/plugins.js index bbdfccf..7e8a15a 100644 --- a/src/js/plugins.js +++ b/src/js/plugins.js @@ -2,9 +2,10 @@ * This file contains the plugin definitions */ -(function() { 'use strict'; +import * as _ from "underscore"; + var plugins = angular.module('plugins', []); /* @@ -594,4 +595,3 @@ plugins.factory('userPlugins', function() { }); -})(); diff --git a/src/main.js b/src/main.js index b9c996d..af5abb1 100644 --- a/src/main.js +++ b/src/main.js @@ -8,7 +8,10 @@ import "angular-touch"; import "./js/localstorage.js"; import "./js/irc-utils.js"; +import "./js/bufferResume.js"; +import "./js/models.js"; import "./js/plugins.js"; +import "./js/websockets.js"; import "./js/glowingbear.js"; import "./js/settings.js"; import "./js/utils.js"; @@ -20,8 +23,5 @@ import "./js/imgur-drop-directive.js"; import "./js/whenscrolled-directive.js"; import "./js/inputbar.js"; import "./js/plugin-directive.js"; -import "./js/websockets.js"; -import "./js/bufferResume.js"; -import "./js/models.js"; import "./js/imgur.js"; \ No newline at end of file diff --git a/test/karma.conf.js b/test/karma.conf.js index 18385cb..41431f4 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -1,53 +1,72 @@ -module.exports = function(config){ +const webpackConfig = require('../webpack.config'); + +module.exports = function (config) { config.set({ - basePath : '../', + basePath: '../', - 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', + files: [ 'node_modules/linkifyjs/dist/linkify.js', 'node_modules/linkifyjs/dist/linkify-string.js', - 'src/js/localstorage.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' + 'test/unit/main.test.js' ], - autoWatch : true, + autoWatch: true, frameworks: ['jasmine'], - browsers : ['PhantomJS'], + browsers: ['Chrome', 'ChromeHeadless', 'ChromeHeadlessNoSandbox'], singleRun: true, - plugins : [ - 'karma-phantomjs-launcher', - 'karma-jasmine', - 'karma-junit-reporter' - ], + plugins: [ + 'karma-phantomjs-launcher', + 'karma-jasmine', + 'karma-junit-reporter', + 'karma-webpack' + ], - junitReporter : { + customLaunchers: { + ChromeHeadlessNoSandbox: { + base: 'ChromeHeadless', + flags: ['--no-sandbox', '--disable-setuid-sandbox'] + } + + }, + + junitReporter: { outputFile: 'test_out/unit.xml', 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']; + } }; diff --git a/test/unit/filters.js b/test/unit/filters.js index 4f0e189..661fc5d 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -1,7 +1,13 @@ -var weechat = angular.module('weechat'); +"use strict"; + +import angular from "angular"; + +import "angular-mocks"; + +import "../../src/main"; describe('Filters', function() { - beforeEach(module('weechat')); + beforeEach(angular.mock.module('weechat')); /*beforeEach(module(function($provide) { $provide.value('version', 'TEST_VER'); }));*/ diff --git a/test/unit/main.test.js b/test/unit/main.test.js new file mode 100644 index 0000000..b244b23 --- /dev/null +++ b/test/unit/main.test.js @@ -0,0 +1,3 @@ + +import "./filters"; +import "./plugins"; \ No newline at end of file diff --git a/test/unit/plugins.js b/test/unit/plugins.js index 9d646ab..0a74e80 100644 --- a/test/unit/plugins.js +++ b/test/unit/plugins.js @@ -1,5 +1,11 @@ /* plugins go here */ +import angular from "angular"; + +import "angular-mocks"; + +import "../../src/main"; + var msg = function(msg) { return {'text': msg }; }; @@ -22,10 +28,10 @@ var expectTheseMessagesToContain = function(urls, pluginType, plugins) { }; describe('filter', function() { - beforeEach(module('plugins')); + beforeEach(angular.mock.module('plugins')); describe('Plugins', function() { - beforeEach(module(function($provide) { + beforeEach(angular.mock.module(function($provide) { $provide.value('version', 'TEST_VER'); }));