diff --git a/static/karma.conf.js b/static/karma.conf.js new file mode 100644 index 0000000..d46e1e3 --- /dev/null +++ b/static/karma.conf.js @@ -0,0 +1,44 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/0.13/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular/cli'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-remap-istanbul'), + require('karma-spec-reporter'), + require('@angular/cli/plugins/karma') + ], + files: [ + { pattern: './src/test.ts', watched: false } + ], + preprocessors: { + './src/test.ts': ['@angular/cli'] + }, + mime: { + 'text/x-typescript': ['ts','tsx'] + }, + remapIstanbulReporter: { + reports: { + html: 'coverage', + lcovonly: './coverage/coverage.lcov' + } + }, + angularCli: { + config: './.angular-cli.json', + environment: 'dev' + }, + reporters: config.angularCli && config.angularCli.codeCoverage + ? ['spec', 'karma-remap-istanbul'] + : ['spec'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false + }); +}; diff --git a/static/package.json b/static/package.json index abd362e..5720c65 100644 --- a/static/package.json +++ b/static/package.json @@ -11,7 +11,9 @@ }, "dependencies": { "@angular/common": "^4.1.1", + "@angular/cli": "1.0.2", "@angular/compiler": "^4.1.1", + "@angular/compiler-cli": "^4.1.1", "@angular/core": "^4.1.1", "@angular/forms": "^4.1.1", "@angular/http": "^4.1.1", @@ -25,19 +27,30 @@ "jquery-ui-bundle": "^1.11.4", "ngx-clipboard": "^8.0.2", "rxjs": "^5.2.0", - "socket.io-client": "^1.4.8", "ts-helpers": "^1.1.1", "typescript": "^2.3.2", "zone.js": "^0.8.5" }, "devDependencies": { "@angular/cli": "1.0.2", - "@angular/compiler-cli": "^4.1.1", + "@angular/compiler-cli": "^2.4.3", "@types/jasmine": "2.5.38", - "@types/node": "~6.0.60", + "@types/node": "^6.0.42", "@types/socket.io-client": "^1.4.26", "codelyzer": "~2.0.0-beta.1", + "concurrently": "^2.0.0", + "jasmine-core": "2.5.2", + "jasmine-spec-reporter": "2.5.0", + "karma": "1.2.0", + "karma-chrome-launcher": "^2.0.0", + "karma-cli": "^1.0.1", + "karma-jasmine": "^1.0.2", + "karma-remap-istanbul": "^0.2.1", + "karma-spec-reporter": "0.0.26", + "protractor": "~4.0.13", + "protractor-jasmine2-screenshot-reporter": "^0.3.2", "ts-node": "1.2.1", - "tslint": "^4.3.0" + "tslint": "^4.3.0", + "typescript": "^2.3.2" } } diff --git a/static/protractor-html-reporter.conf.js b/static/protractor-html-reporter.conf.js new file mode 100644 index 0000000..b9360f8 --- /dev/null +++ b/static/protractor-html-reporter.conf.js @@ -0,0 +1,52 @@ +// Protractor configuration file, see link for more information +// https://github.com/angular/protractor/blob/master/docs/referenceConf.js + +/*global jasmine */ +var SpecReporter = require('jasmine-spec-reporter'); +//var ScreenshotProcessor = require('./e2e/helpers/screen_shot_reporter.ts'); +var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter'); + +var reporter = new HtmlScreenshotReporter({ + dest: 'tmp/screenshots', + filename: 'test-report.html', + cleanDestination: true, + ignoreSkippedSpecs: true, + captureOnlyFailedSpecs: false +}); + + +exports.config = { + allScriptsTimeout: 11000, + specs: [ + './e2e/**/*.e2e-spec.ts' + ], + capabilities: { + 'browserName': 'firefox' + }, + directConnect: true, + baseUrl: 'http://localhost:4200/', + framework: 'jasmine', + jasmineNodeOpts: { + showColors: true, + defaultTimeoutInterval: 30000, + print: function() {} + }, + useAllAngular2AppRoots: true, + beforeLaunch: function() { + require('ts-node').register({ + project: 'e2e' + }); + return new Promise(function(resolve){ + reporter.beforeLaunch(resolve); + }); + }, + afterLaunch: function(exitCode) { + return new Promise(function(resolve){ + reporter.afterLaunch(resolve.bind(this, exitCode)); + }); + }, + onPrepare: function() { + jasmine.getEnv().addReporter(reporter); + jasmine.getEnv().addReporter(new SpecReporter()); + }, +}; \ No newline at end of file diff --git a/static/protractor.conf.js b/static/protractor.conf.js new file mode 100644 index 0000000..00cf700 --- /dev/null +++ b/static/protractor.conf.js @@ -0,0 +1,32 @@ +// Protractor configuration file, see link for more information +// https://github.com/angular/protractor/blob/master/lib/config.ts + +/*global jasmine */ +var SpecReporter = require('jasmine-spec-reporter'); + +exports.config = { + allScriptsTimeout: 11000, + specs: [ + './e2e/**/*.e2e-spec.ts' + ], + capabilities: { + 'browserName': 'chrome' + }, + directConnect: true, + baseUrl: 'http://localhost:8091/', + framework: 'jasmine', + jasmineNodeOpts: { + showColors: true, + defaultTimeoutInterval: 30000, + print: function() {} + }, + useAllAngular2AppRoots: true, + beforeLaunch: function() { + require('ts-node').register({ + project: 'e2e' + }); + }, + onPrepare: function() { + jasmine.getEnv().addReporter(new SpecReporter()); + } +}; diff --git a/static/src/test.ts b/static/src/test.ts new file mode 100644 index 0000000..6d46bc6 --- /dev/null +++ b/static/src/test.ts @@ -0,0 +1,35 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js/dist/long-stack-trace-zone'; +import 'zone.js/dist/proxy.js'; +import 'zone.js/dist/sync-test'; +import 'zone.js/dist/jasmine-patch'; +import 'zone.js/dist/async-test'; +import 'zone.js/dist/fake-async-test'; + +import 'rxjs/Rx'; + +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. +declare var __karma__: any; +declare var require: any; + +// Prevent Karma from running prematurely. +__karma__.loaded = function () {}; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting() +); +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); +// Finally, start Karma to run the tests. +__karma__.start();