From c0a0290380d4306ca3a82180dc81d2555fde5e36 Mon Sep 17 00:00:00 2001 From: Damien Daspit Date: Thu, 31 May 2018 15:41:09 +0700 Subject: [PATCH] Fix TS unit tests --- gulpfile.js | 94 ++++- karma.conf.js | 50 +++ package-lock.json | 336 ++++++------------ package.json | 3 +- src/angular-app/bellows/core/filters.spec.ts | 1 - src/angular-app/bellows/main.common.specs.ts | 8 + src/angular-app/languageforge/main.specs.ts | 7 + src/angular-app/scriptureforge/main.specs.ts | 7 + .../sfchecks/js/sorting.spec.ts | 2 - test/app/karma.conf.js | 57 --- webpack.config.js | 60 ++-- 11 files changed, 300 insertions(+), 325 deletions(-) create mode 100644 karma.conf.js create mode 100644 src/angular-app/bellows/main.common.specs.ts create mode 100644 src/angular-app/languageforge/main.specs.ts create mode 100644 src/angular-app/scriptureforge/main.specs.ts delete mode 100644 test/app/karma.conf.js diff --git a/gulpfile.js b/gulpfile.js index 866005d333..c8ab7dfd33 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -323,25 +323,91 @@ gulp.task('test-php-debug:watch', function () { gulp.watch(phpPatterns, ['test-php-debug']); }); +function runKarmaTests(applicationName, cb, type) { + var config = { + configFile: __dirname + '/karma.conf.js', + applicationName: applicationName + }; + + switch (type) { + case 'ci': + config.reporters = 'teamcity'; + break; + + case 'watch': + config.autoWatch = true; + config.singleRun = false; + break; + + case 'debug': + config.autoWatch = true; + config.singleRun = false; + config.browsers = []; + break; + } + + new Server(config, function(err) { + if (err === 0) { + cb(); + } else { + cb(new gutil.PluginError('karma', { message: 'Karma Tests failed' })); + } + }).start(); +} + +// ------------------------------------- +// Task: test-ts +// ------------------------------------- +gulp.task('test-ts', function (cb) { + var params = require('yargs') + .option('applicationName', { + demand: true, + type: 'string' }) + .fail(yargFailure) + .argv; + runKarmaTests(params.applicationName, cb, 'ci'); +}); + +// ------------------------------------- +// Task: test-ts-lf +// ------------------------------------- +gulp.task('test-ts-lf', function (cb) { + runKarmaTests('languageforge', cb); +}); + +// ------------------------------------- +// Task: test-ts-lf:watch +// ------------------------------------- +gulp.task('test-ts-lf:watch', function (cb) { + runKarmaTests('languageforge', cb, 'watch'); +}); + +// ------------------------------------- +// Task: test-ts-lf:debug +// ------------------------------------- +gulp.task('test-ts-lf:debug', function (cb) { + runKarmaTests('languageforge', cb, 'debug'); +}); + +// ------------------------------------- +// Task: test-ts-sf +// ------------------------------------- +gulp.task('test-ts-sf', function (cb) { + runKarmaTests('scriptureforge', cb); +}); + // ------------------------------------- -// Task: test-js +// Task: test-ts-sf:watch // ------------------------------------- -gulp.task('test-js', function (cb) { - new Server({ - configFile: __dirname + '/test/app/karma.conf.js', - reporters: 'teamcity' - }, cb).start(); +gulp.task('test-ts-sf:watch', function (cb) { + runKarmaTests('scriptureforge', cb, 'watch'); }); // ------------------------------------- -// Task: test-js:watch +// Task: test-ts-sf:debug // ------------------------------------- -gulp.task('test-js:watch', function (cb) { - new Server({ - configFile: __dirname + '/test/app/karma.conf.js', - autoWatch: true, - singleRun: false - }, cb).start(); +gulp.task('test-ts-sf:debug', function (cb) { + runKarmaTests('scriptureforge', cb, 'debug'); }); // ------------------------------------- @@ -1396,7 +1462,7 @@ gulp.task('build-and-test', 'build', 'test-php', - // 'test-js', + 'test-ts', 'test-dotnet', 'test-restart-webserver', 'local-restart-xforge-web-api', diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000000..e5c40a0713 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,50 @@ +'use strict'; +var getWebpackConfig = require('./webpack.config.js'); + +// Karma configuration +module.exports = function (config) { + if (config.applicationName == null) { + config.applicationName = 'languageforge'; + } + var webpackConfig = getWebpackConfig({ applicationName: config.applicationName, isTest: true }); + var main = webpackConfig.entry.main; + delete webpackConfig.entry; + + config.set({ + basePath: '.', + frameworks: ['jasmine'], + + // list of files / patterns to load in the browser + files: [main], + + // list of files to exclude + exclude: [], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + [main]: ['webpack', 'sourcemap'] + }, + + webpack: webpackConfig, + + // test results reporter to use + // possible values: dots || progress || growl + reporters: ['progress'], + + // web server port + port: 8080, + + // cli runner port + runnerPort: 9100, + + colors: true, + logLevel: config.LOG_WARN, + browsers: ['ChromiumHeadless'], + captureTimeout: 8000, + singleRun: true, + mime: { + 'text/x-typescript': ['ts','tsx'] + } + }); +}; diff --git a/package-lock.json b/package-lock.json index c4ad2095a9..0caa5a4143 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7965,168 +7965,33 @@ "integrity": "sha1-b+hA51oRYAydkehLM8RY4cRqNSk=", "dev": true }, + "karma-sourcemap-loader": { + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/karma-sourcemap-loader/-/karma-sourcemap-loader-0.3.7.tgz", + "integrity": "sha1-kTIsd/jxPUb+0GKwQuEAnUxFBdg=", + "dev": true, + "requires": { + "graceful-fs": "4.1.11" + } + }, "karma-teamcity-reporter": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/karma-teamcity-reporter/-/karma-teamcity-reporter-1.1.0.tgz", "integrity": "sha512-Ca1uhHGtNqUuzsnW3I+QykNuS/jF9vdxnIrkbLCVJRunCc6yWJq+ai1UobQT13j0e3JVUOf0mKo3QHZ6A6mG9Q==", "dev": true }, - "karma-typescript": { - "version": "3.0.12", - "resolved": "https://registry.npmjs.org/karma-typescript/-/karma-typescript-3.0.12.tgz", - "integrity": "sha1-qiy90RFEKgnG28uq6vSEmWVMaRM=", + "karma-webpack": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/karma-webpack/-/karma-webpack-3.0.0.tgz", + "integrity": "sha512-Ja1o9LLoqWaJyUNhTKaXjWiEH9y7a9H3mzP8pYB30SBsgoF5KBS/65NeHFd+QPuT9ITrym8xFt8BZeGbcOfujA==", "dev": true, "requires": { - "acorn": "4.0.13", - "assert": "1.4.1", "async": "2.6.0", - "browser-resolve": "1.11.2", - "browserify-zlib": "0.2.0", - "buffer": "5.1.0", - "combine-source-map": "0.8.0", - "console-browserify": "1.1.0", - "constants-browserify": "1.0.0", - "convert-source-map": "1.5.1", - "crypto-browserify": "3.12.0", - "diff": "3.5.0", - "domain-browser": "1.2.0", - "events": "1.1.1", - "glob": "7.1.2", - "https-browserify": "1.0.0", - "istanbul": "0.4.5", - "json-stringify-safe": "5.0.1", - "karma-coverage": "1.1.1", + "babel-runtime": "6.26.0", + "loader-utils": "1.1.0", "lodash": "4.17.5", - "log4js": "1.1.1", - "minimatch": "3.0.4", - "os-browserify": "0.3.0", - "pad": "2.0.3", - "path-browserify": "0.0.0", - "process": "0.11.10", - "punycode": "1.4.1", - "querystring-es3": "0.2.1", - "readable-stream": "2.3.5", - "remap-istanbul": "0.10.1", - "source-map": "0.6.1", - "stream-browserify": "2.0.1", - "stream-http": "2.8.0", - "string_decoder": "1.0.3", - "timers-browserify": "2.0.6", - "tmp": "0.0.29", - "tty-browserify": "0.0.0", - "url": "0.11.0", - "util": "0.10.3", - "vm-browserify": "0.0.4" - }, - "dependencies": { - "date-format": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/date-format/-/date-format-0.0.0.tgz", - "integrity": "sha1-CSBoY6sHDrRZrOpVQsvYVrEZZrM=", - "dev": true - }, - "log4js": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/log4js/-/log4js-1.1.1.tgz", - "integrity": "sha1-wh0px2BAieTyVYM+f5SzRh3h/0M=", - "dev": true, - "requires": { - "debug": "2.6.9", - "semver": "5.5.0", - "streamroller": "0.4.1" - } - }, - "readable-stream": { - "version": "2.3.5", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.5.tgz", - "integrity": "sha512-tK0yDhrkygt/knjowCUiWP9YdV7c5R+8cR0r/kt9ZhBU906Fs6RpQJCEilamRJj1Nx2rWI6LkW9gKqjTkshhEw==", - "dev": true, - "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "2.0.0", - "safe-buffer": "5.1.1", - "string_decoder": "1.0.3", - "util-deprecate": "1.0.2" - }, - "dependencies": { - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true - } - } - }, - "semver": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", - "dev": true - }, - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - }, - "streamroller": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-0.4.1.tgz", - "integrity": "sha1-1DW9WXQ3Or2b2QaDWVEwhRBswF8=", - "dev": true, - "requires": { - "date-format": "0.0.0", - "debug": "0.7.4", - "mkdirp": "0.5.1", - "readable-stream": "1.1.14" - }, - "dependencies": { - "debug": { - "version": "0.7.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-0.7.4.tgz", - "integrity": "sha1-BuHqgILCyxTjmAbiLi9vdX+Srzk=", - "dev": true - }, - "readable-stream": { - "version": "1.1.14", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", - "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", - "dev": true, - "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "0.0.1", - "string_decoder": "0.10.31" - } - }, - "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", - "dev": true - } - } - }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, - "tmp": { - "version": "0.0.29", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.29.tgz", - "integrity": "sha1-8lEl/w3Z2jzLDC3Tce4SiLuRKMA=", - "dev": true, - "requires": { - "os-tmpdir": "1.0.2" - } - } + "source-map": "0.5.7", + "webpack-dev-middleware": "2.0.6" } }, "kind-of": { @@ -8816,6 +8681,16 @@ } } }, + "loglevelnext": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/loglevelnext/-/loglevelnext-1.0.5.tgz", + "integrity": "sha512-V/73qkPuJmx4BcBF19xPBr+0ZRVBhc4POxvZTZdMeXpJ4NItXSJ/MSwuFT0kQJlCbXvdlZoQQ/418bS1y9Jh6A==", + "dev": true, + "requires": { + "es6-symbol": "3.1.1", + "object.assign": "4.1.0" + } + }, "longest": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", @@ -10598,15 +10473,6 @@ } } }, - "pad": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/pad/-/pad-2.0.3.tgz", - "integrity": "sha512-YVlBmpDQilhUl69RY/0Ku9Il0sNPLgVOVePhCJUfN8qDZKrq1zIY+ZwtCLtaWFtJzuJswwAcZHxf4a5RliV2pQ==", - "dev": true, - "requires": { - "wcwidth": "1.0.1" - } - }, "pako": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.6.tgz", @@ -12358,64 +12224,6 @@ } } }, - "remap-istanbul": { - "version": "0.10.1", - "resolved": "https://registry.npmjs.org/remap-istanbul/-/remap-istanbul-0.10.1.tgz", - "integrity": "sha512-gsNQXs5kJLhErICSyYhzVZ++C8LBW8dgwr874Y2QvzAUS75zBlD/juZgXs39nbYJ09fZDlX2AVLVJAY2jbFJoQ==", - "dev": true, - "requires": { - "amdefine": "1.0.1", - "istanbul": "0.4.5", - "minimatch": "3.0.4", - "plugin-error": "0.1.2", - "source-map": "0.6.1", - "through2": "2.0.1" - }, - "dependencies": { - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true - }, - "process-nextick-args": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=", - "dev": true - }, - "readable-stream": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz", - "integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44=", - "dev": true, - "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "string_decoder": "0.10.31", - "util-deprecate": "1.0.2" - } - }, - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - }, - "through2": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.1.tgz", - "integrity": "sha1-OE51MU1J8y3hLuu4E2uOtrXVnak=", - "dev": true, - "requires": { - "readable-stream": "2.0.6", - "xtend": "4.0.1" - } - } - } - }, "remove-bom-buffer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/remove-bom-buffer/-/remove-bom-buffer-3.0.0.tgz", @@ -14786,6 +14594,12 @@ } } }, + "url-join": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz", + "integrity": "sha1-WvIvGMBSoACkjXuCxenC4v7tpyg=", + "dev": true + }, "url-loader": { "version": "0.5.9", "resolved": "https://registry.npmjs.org/url-loader/-/url-loader-0.5.9.tgz", @@ -15238,15 +15052,6 @@ } } }, - "wcwidth": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz", - "integrity": "sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g=", - "dev": true, - "requires": { - "defaults": "1.0.3" - } - }, "webdriver-js-extender": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/webdriver-js-extender/-/webdriver-js-extender-1.0.0.tgz", @@ -15514,6 +15319,29 @@ } } }, + "webpack-dev-middleware": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-2.0.6.tgz", + "integrity": "sha512-tj5LLD9r4tDuRIDa5Mu9lnY2qBBehAITv6A9irqXhw/HQquZgTx3BCd57zYbU2gMDnncA49ufK2qVQSbaKJwOw==", + "dev": true, + "requires": { + "loud-rejection": "1.6.0", + "memory-fs": "0.4.1", + "mime": "2.3.1", + "path-is-absolute": "1.0.1", + "range-parser": "1.2.0", + "url-join": "2.0.5", + "webpack-log": "1.2.0" + }, + "dependencies": { + "mime": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.3.1.tgz", + "integrity": "sha512-OEUllcVoydBHGN1z84yfQDimn58pZNNNXgZlHXSboxMlFvgI6MXSWpWKpFRra7H1HxpVhHTkrghfRW49k6yjeg==", + "dev": true + } + } + }, "webpack-livereload-plugin": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/webpack-livereload-plugin/-/webpack-livereload-plugin-0.11.0.tgz", @@ -15523,6 +15351,58 @@ "tiny-lr": "0.2.1" } }, + "webpack-log": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/webpack-log/-/webpack-log-1.2.0.tgz", + "integrity": "sha512-U9AnICnu50HXtiqiDxuli5gLB5PGBo7VvcHx36jRZHwK4vzOYLbImqT4lwWwoMHdQWwEKw736fCHEekokTEKHA==", + "dev": true, + "requires": { + "chalk": "2.4.1", + "log-symbols": "2.2.0", + "loglevelnext": "1.0.5", + "uuid": "3.2.1" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "1.9.1" + } + }, + "chalk": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", + "dev": true, + "requires": { + "ansi-styles": "3.2.1", + "escape-string-regexp": "1.0.5", + "supports-color": "5.4.0" + } + }, + "log-symbols": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", + "integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==", + "dev": true, + "requires": { + "chalk": "2.4.1" + } + }, + "supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", + "dev": true, + "requires": { + "has-flag": "3.0.0" + } + } + } + }, "webpack-merge": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-4.1.2.tgz", diff --git a/package.json b/package.json index 07fae5b68e..2793637ca3 100644 --- a/package.json +++ b/package.json @@ -98,8 +98,9 @@ "karma-chrome-launcher": "^2.2.0", "karma-coverage": "^1.1.1", "karma-jasmine": "^1.0.2", + "karma-sourcemap-loader": "^0.3.7", "karma-teamcity-reporter": "^1.0.0", - "karma-typescript": "^3.0.5", + "karma-webpack": "^3.0.0", "lodash.template": "^4.4.0", "merge-stream": "^1.0.1", "node-sass": "git+https://github.com/sillsdev/node-sass.git#v4.9.0/css-build-fix", diff --git a/src/angular-app/bellows/core/filters.spec.ts b/src/angular-app/bellows/core/filters.spec.ts index 5660b3a4b3..db66bbc935 100644 --- a/src/angular-app/bellows/core/filters.spec.ts +++ b/src/angular-app/bellows/core/filters.spec.ts @@ -1,5 +1,4 @@ import * as angular from 'angular'; -import 'angular-mocks'; import { BytesFilterFunction, EncodeURIFilterFunction, RelativeTimeFilterFunction diff --git a/src/angular-app/bellows/main.common.specs.ts b/src/angular-app/bellows/main.common.specs.ts new file mode 100644 index 0000000000..638a519fef --- /dev/null +++ b/src/angular-app/bellows/main.common.specs.ts @@ -0,0 +1,8 @@ +import './main.common'; + +import 'angular-mocks'; +import 'angular-sanitize'; + +const webpackRequire = require as any; +const testsContext = webpackRequire.context('.', true, /\.spec$/); +testsContext.keys().forEach(testsContext); diff --git a/src/angular-app/languageforge/main.specs.ts b/src/angular-app/languageforge/main.specs.ts new file mode 100644 index 0000000000..a110e648e2 --- /dev/null +++ b/src/angular-app/languageforge/main.specs.ts @@ -0,0 +1,7 @@ +import './main'; + +import '../bellows/main.common.specs'; + +const webpackRequire = require as any; +const testsContext = webpackRequire.context('.', true, /\.spec$/); +testsContext.keys().forEach(testsContext); diff --git a/src/angular-app/scriptureforge/main.specs.ts b/src/angular-app/scriptureforge/main.specs.ts new file mode 100644 index 0000000000..a110e648e2 --- /dev/null +++ b/src/angular-app/scriptureforge/main.specs.ts @@ -0,0 +1,7 @@ +import './main'; + +import '../bellows/main.common.specs'; + +const webpackRequire = require as any; +const testsContext = webpackRequire.context('.', true, /\.spec$/); +testsContext.keys().forEach(testsContext); diff --git a/src/angular-app/scriptureforge/sfchecks/js/sorting.spec.ts b/src/angular-app/scriptureforge/sfchecks/js/sorting.spec.ts index cf64775645..8cecd06ea9 100644 --- a/src/angular-app/scriptureforge/sfchecks/js/sorting.spec.ts +++ b/src/angular-app/scriptureforge/sfchecks/js/sorting.spec.ts @@ -1,6 +1,4 @@ import * as angular from 'angular'; -import 'angular-mocks'; -import 'angular-sanitize'; import '../../../bellows/core/core.module'; import '../../../bellows/core/error.service'; diff --git a/test/app/karma.conf.js b/test/app/karma.conf.js deleted file mode 100644 index 6b47b0f43e..0000000000 --- a/test/app/karma.conf.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict'; - -// Karma configuration -module.exports = function (config) { - config.set({ - basePath: '../..', - frameworks: ['jasmine', 'karma-typescript'], - - // list of files / patterns to load in the browser - files: [ - 'src/angular-app/**/*.ts' - - // exclude sfchecks tests for now since they aren't working - IJH 2017-08 - // 'node_modules/angular/angular.js', - // 'node_modules/angular-route/angular-route.js', - // 'node_modules/angular-sanitize/angular-sanitize.js', - // 'node_modules/angular-mocks/angular-mocks.js', - // 'node_modules/ng-file-upload/dist/ng-file-upload.js', - // 'node_modules/jquery/dist/jquery.js', - // 'node_modules/angular-ui-bootstrap/dist/*ui-bootstrap*.js', - // 'src/angular-app/**/*.js', - // 'test/app/**/unit/*.spec.js' - ], - - // list of files to exclude - exclude: [], - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: { - '**/*.ts': ['karma-typescript'] - }, - - karmaTypescriptConfig: { - tsconfig: './tsconfig.json', - reports: { - html: 'test/CodeCoverage/typescript/' - } - }, - - // test results reporter to use - // possible values: dots || progress || growl - reporters: ['progress', 'karma-typescript'], - - // web server port - port: 8080, - - // cli runner port - runnerPort: 9100, - - colors: true, - logLevel: config.LOG_WARN, - browsers: ['ChromiumHeadless'], - captureTimeout: 8000, - singleRun: true - }); -}; diff --git a/webpack.config.js b/webpack.config.js index 95b8cb0a3f..fae0cafd6a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -34,25 +34,6 @@ var webpackConfig = { // your Angular Async Route paths relative to this root directory {} ), - new webpack.optimize.CommonsChunkPlugin({ - name: 'vendor', - minChunks: function (module) { - // this assumes your vendor imports exist in the node_modules or js/assets directories - return module.context && ( - module.context.indexOf('node_modules') !== -1 || - module.context.indexOf('js/assets') !== -1 || - module.context.indexOf('js/vendor') !== -1 || - module.context.indexOf('core/input-systems') !== -1 - ); - } - }), - - // CommonChunksPlugin will now extract all the common modules from vendor and main bundles - new webpack.optimize.CommonsChunkPlugin({ - name: 'manifest' - }), - new LiveReloadPlugin(), - new webpack.DefinePlugin({ 'process.env.XFORGE_BUGSNAG_API_KEY': JSON.stringify(process.env.XFORGE_BUGSNAG_API_KEY || 'missing-bugsnag-api-key'), @@ -130,11 +111,46 @@ var defaultConfig = { }; module.exports = function (env) { - var mainPath = './src/angular-app/languageforge/main.ts'; - if (env && env.applicationName) { - mainPath = './src/angular-app/' + env.applicationName + '/main.ts'; + if (env == null) { + env = { + applicationName: 'languageforge', + isTest: false + }; } + var mainPath = './src/angular-app/' + env.applicationName + '/main' + (env.isTest ? '.specs' : '') + '.ts'; webpackConfig.entry.main = mainPath; + + if (env.isTest) { + webpackConfig.devtool = false; + var plugins = [ + new webpack.SourceMapDevToolPlugin({ + filename: null, // if no value is provided the sourcemap is inlined + test: /\.(ts|js)($|\?)/i // process .js and .ts files only + }) + ]; + webpackConfig.plugins = webpackConfig.plugins.concat(plugins); + } else { + var plugins = [ + new webpack.optimize.CommonsChunkPlugin({ + name: 'vendor', + minChunks: function (module) { + // this assumes your vendor imports exist in the node_modules or js/assets directories + return module.context && ( + module.context.indexOf('node_modules') !== -1 || + module.context.indexOf('js/assets') !== -1 || + module.context.indexOf('js/vendor') !== -1 || + module.context.indexOf('core/input-systems') !== -1 + ); + } + }), + // CommonChunksPlugin will now extract all the common modules from vendor and main bundles + new webpack.optimize.CommonsChunkPlugin({ + name: 'manifest' + }), + new LiveReloadPlugin() + ]; + webpackConfig.plugins = webpackConfig.plugins.concat(plugins); + } return webpackMerge(defaultConfig, webpackConfig); };