Merge branch '10-add-unit-tests' into 'develop'

Added a first simple test.

Closes #10

See merge request !16
This commit is contained in:
Manuel Friedli 2017-03-15 02:33:12 +01:00
commit 718f693b75
7 changed files with 139 additions and 2 deletions

View file

@ -9,6 +9,7 @@ build_job:
script:
- npm install
- npm run build
- npm run test
tags:
- javascript
except:

21
config/karma-test-shim.js Normal file
View file

@ -0,0 +1,21 @@
Error.stackTraceLimit = Infinity;
require('core-js/es6');
require('core-js/es7/reflect');
require('zone.js/dist/zone');
require('zone.js/dist/long-stack-trace-zone');
require('zone.js/dist/proxy');
require('zone.js/dist/sync-test');
require('zone.js/dist/jasmine-patch');
require('zone.js/dist/async-test');
require('zone.js/dist/fake-async-test');
var appContext = require.context('../src', true, /\.spec\.ts/);
appContext.keys().forEach(appContext);
var testing = require('@angular/core/testing');
var browser = require('@angular/platform-browser-dynamic/testing');
testing.TestBed.initTestEnvironment(browser.BrowserDynamicTestingModule, browser.platformBrowserDynamicTesting());

44
config/karma.conf.js Normal file
View file

@ -0,0 +1,44 @@
var webpackConfig = require('./webpack.test');
module.exports = function (config) {
var _config = {
basePath: '',
frameworks: ['jasmine'],
files: [
{
pattern: './config/karma-test-shim.js',
watched: false
}
],
preprocessors: {
'./config/karma-test-shim.js': ['webpack', 'sourcemap']
},
webpack: webpackConfig,
webpackMiddleware: {
stats: 'errors-only'
},
webpackServer: {
noInfo: true
},
reporters: ['kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['PhantomJS'],
singleRun: true,
phantomjsLauncher: {
// Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
exitOnResourceError: true
}
};
config.set(_config);
};

52
config/webpack.test.js Normal file
View file

@ -0,0 +1,52 @@
var webpack = require('webpack');
var helpers = require('./helpers');
module.exports = {
devtool: 'inline-source-map',
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
loaders: [
{
loader: 'awesome-typescript-loader',
options: {configFileName: helpers.root('src', 'tsconfig.json')}
}, 'angular2-template-loader'
]
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'null-loader'
},
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: 'null-loader'
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
loader: 'raw-loader'
}
]
},
plugins: [
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('./src'), // location of your src
{} // a map of your routes
)
]
};

View file

@ -35,8 +35,8 @@
"punycode": "^1.4.0"
},
"devDependencies": {
"@types/node": "^6.0.45",
"@types/jasmine": "2.5.36",
"@types/node": "^6.0.45",
"angular2-template-loader": "^0.6.0",
"awesome-typescript-loader": "^3.0.4",
"css-loader": "^0.26.1",
@ -47,10 +47,14 @@
"jasmine-core": "^2.4.1",
"karma": "^1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-firefox-launcher": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.1",
"null-loader": "^0.1.1",
"phantomjs-prebuilt": "^2.1.14",
"raw-loader": "^0.5.1",
"rimraf": "^2.5.2",
"style-loader": "^0.13.1",

View file

@ -0,0 +1,16 @@
import {TestBed} from "@angular/core/testing";
import {AppComponent} from "./app.component";
import {FormsModule} from "@angular/forms";
describe('App', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
imports: [FormsModule]
});
});
it('should work', () => {
let fixture = TestBed.createComponent(AppComponent);
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
});
});

View file

@ -4,7 +4,6 @@ import {InputComponentManagerService} from "./inputcomponentmanager.service";
import {Converter} from "./converter/converter";
import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service";
import {Step} from "./step";
import "../assets/css/style.css";
@Component({