Skip to content

Commit c1c8621

Browse files
committed
fix(karma): update karma test setup
closes TrilonIO#38 Still need to implement real tests
1 parent e6d5a2e commit c1c8621

File tree

3 files changed

+58
-109
lines changed

3 files changed

+58
-109
lines changed

Client/karma-tests.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Load required polyfills and testing libraries
2+
import 'angular2-universal-polyfills';
3+
import 'zone.js/dist/long-stack-trace-zone';
4+
import 'zone.js/dist/proxy.js';
5+
import 'zone.js/dist/sync-test';
6+
import 'zone.js/dist/jasmine-patch';
7+
import 'zone.js/dist/async-test';
8+
import 'zone.js/dist/fake-async-test';
9+
import * as testing from '@angular/core/testing';
10+
import * as testingBrowser from '@angular/platform-browser-dynamic/testing';
11+
12+
// There's no typing for the `__karma__` variable. Just declare it as any
13+
declare var __karma__: any;
14+
declare var require: any;
15+
16+
// Prevent Karma from running prematurely
17+
__karma__.loaded = function () {};
18+
19+
// First, initialize the Angular testing environment
20+
testing.getTestBed().initTestEnvironment(
21+
testingBrowser.BrowserDynamicTestingModule,
22+
testingBrowser.platformBrowserDynamicTesting()
23+
);
24+
25+
// Then we find all the tests
26+
const context = require.context('./', true, /\.spec\.ts$/);
27+
28+
// And load the modules
29+
context.keys().map(context);
30+
31+
// Finally, start Karma to run the tests
32+
__karma__.start();

karma.conf.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/0.13/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '.',
7+
frameworks: ['jasmine'],
8+
files: [
9+
'./wwwroot/dist/vendor.js',
10+
'./Client/karma-tests.ts'
11+
],
12+
preprocessors: {
13+
'./Client/karma-tests.ts': ['webpack']
14+
},
15+
reporters: ['progress'],
16+
port: 9876,
17+
colors: true,
18+
logLevel: config.LOG_INFO,
19+
autoWatch: true,
20+
browsers: ['Chrome'],
21+
mime: { 'application/javascript': ['ts','tsx'] },
22+
singleRun: false,
23+
webpack: require('./webpack.config.js'),// .filter(config => config.target !== 'node'), // Test against client bundle, because tests run in a browser
24+
webpackMiddleware: { stats: 'errors-only' }
25+
});
26+
};

karma.config.js

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)