Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Commit

Permalink
fix(test): update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
kyxyes committed Jun 15, 2018
1 parent d38ea1a commit 47d0ef0
Show file tree
Hide file tree
Showing 14 changed files with 714 additions and 97 deletions.
78 changes: 37 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,65 @@
"build": "webpack",
"build:watch": "webpack --watch",
"watch:build": "webpack --watch",
"test": "karma start ./test/ui/karma.conf.js",
"coverage": "karma start ./test/ui/karma.conf.js --singleRun=true",
"test": "karma start ./test/karma.conf.js",
"coverage": "karma start ./test/karma.conf.js --singleRun=true",
"commitmsg": "commitlint -e $GIT_PARAMS",
"travis-deploy-once": "travis-deploy-once --pro",
"semantic-release": "semantic-release"
},
"dependencies": {
"@angular/animations": "^4.4.4",
"@angular/common": "^4.4.4",
"@angular/compiler": "^4.4.4",
"@angular/core": "^4.4.4",
"@angular/forms": "^4.4.4",
"@angular/http": "^4.4.4",
"@angular/platform-browser": "^4.4.4",
"@angular/platform-browser-dynamic": "^4.4.4",
"@angular/animations": "4.4.4",
"@angular/common": "4.4.4",
"@angular/compiler": "4.4.4",
"@angular/core": "4.4.4",
"@angular/forms": "4.4.4",
"@angular/http": "4.4.4",
"@angular/platform-browser": "4.4.4",
"@angular/platform-browser-dynamic": "4.4.4",
"@angular/router": "^4.4.4",
"bootstrap": "^4.0.0",
"core-js": "^2.5.4",
"core-js": "^2.4.1",
"ngx-chips": "^1.9.1",
"ngx-quill": "^3.1.0",
"quill": "^1.3.4",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.1.0",
"zone.js": "^0.8.26"
"rxjs": "5.5.6",
"zone.js": "^0.8.18"
},
"devDependencies": {
"@angular/cli": "^1.5.0",
"@angular/compiler": "4.4.4",
"@angular/router": "^4.4.4",
"@types/es6-promise": "3.3.0",
"@types/jasmine": "^2.8.6",
"@types/node": "^10.0.6",
"css-loader": "0.28.11",
"file-loader": "1.1.11",
"@angular/compiler-cli": "4.4.4",
"@angular/platform-browser": "4.4.4",
"@angular/platform-browser-dynamic": "4.4.4",
"@commitlint/cli": "^6.2.0",
"@commitlint/config-conventional": "^6.1.3",
"@storybook/addon-actions": "3.4.6",
"@storybook/addon-links": "3.4.6",
"@storybook/addon-notes": "3.4.6",
"@storybook/addons": "3.4.6",
"@storybook/angular": "3.4.6",
"@types/jasmine": "^2.5.54",
"@types/node": "^10.3.0",
"coveralls": "^3.0.1",
"html-loader": "0.5.5",
"html-webpack-plugin": "3.2.0",
"husky": "^0.14.3",
"jasmine-core": "3.1.0",
"karma": "2.0.2",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "1.1.2",
"karma-jasmine": "1.1.2",
"istanbul-instrumenter-loader": "^3.0.1",
"karma-phantomjs-launcher": "1.0.4",
"karma-safari-launcher": "1.0.0",
"jasmine-core": "^3.1.0",
"karma": "^2.0.2",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-coverage-istanbul-reporter": "^2.0.0",
"karma-sourcemap-loader": "0.3.7",
"karma-jasmine": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-typescript": "^3.0.8",
"karma-webpack": "3.0.0",
"loader-utils": "^1.1.0",
"node-sass": "4.9.0",
"karma-webpack": "^4.0.0-beta.0",
"null-loader": "^0.1.1",
"sass-loader": "7.0.1",
"style-loader": "0.21.0",
"ts-loader": "^4.3.0",
"typescript": "^2.5.3",
"url-loader": "1.0.1",
"webpack": "4.8.1",
"webpack-cli": "^2.1.3",
"webpack-node-externals": "^1.6.0",
"@commitlint/cli": "^6.2.0",
"@commitlint/config-conventional": "^6.1.3",
"coveralls": "^3.0.1",
"tslint-angular": "^1.1.0",
"typescript": "^2.7.2",
"webpack": "4.10.1",
"@labshare/semantic-release-config": "^1.0.0",
"travis-deploy-once": "^5.0.0",
"semantic-release": "^15.5.0"
Expand Down
35 changes: 35 additions & 0 deletions src/app/components/form-radio/form-radio.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormRadioComponent } from './form-radio.component';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { APP_BASE_HREF } from '@angular/common';


describe('FormRadioComponent', () => {
let component: FormRadioComponent;
let fixture: ComponentFixture<FormRadioComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormsModule,
ReactiveFormsModule
],
declarations: [FormRadioComponent],
providers: [
{ provide: APP_BASE_HREF, useValue: '/' }
]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(FormRadioComponent);
component = fixture.componentInstance;
component.field = { "type": "text", "label": "Explain", "name": "testName", "hidden": true, "required": true };
fixture.detectChanges();
});

it('should be created', () => {
expect(component).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion src/app/components/form-radio/form-radio.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as _ from 'lodash';

@Component({
selector: 'form-radio',
templateUrl: './form-radio.component.html'
template: require('./form-radio.component.html')
})

export class FormRadioComponent implements Field{
Expand Down
36 changes: 20 additions & 16 deletions test/ui/karma.conf.js → test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
const {join} = require('path');

module.exports = function (config) {
'use strict';

let configuration = {
autoWatch: true,
basePath: '../../../',
basePath: '../',
frameworks: ['jasmine'],
files: [
'test/test-index.ts'
],
reporters: ['progress', 'coverage-istanbul'],
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
reporters: ['progress', 'coverage-istanbul'],
coverageIstanbulReporter: {
// reports can be any that are listed here: https://github.com/istanbuljs/istanbuljs/tree/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib
reports: ['html', 'lcovonly', 'text-summary'],
Expand All @@ -38,43 +37,47 @@ module.exports = function (config) {
verbose: false // output config used by istanbul for debugging
},
preprocessors: {
'test/test-index.ts': ['webpack']
},
webpackMiddleware: {
stats: 'errors-only'
},
exclude: [],
port: 8080,
browsers: ['ChromeHeadless'],
singleRun: true,
browserConsoleLogOptions: {
level: 'log',
format: '%b %T: %m',
terminal: true
},
exclude: [],
port: 8080,
browsers: [
'Chrome',
'Safari'
],
// Workaround for test timeout issue: https://github.com/jasmine/jasmine/issues/1327#issuecomment-332939551
browserNoActivityTimeout: 50000,
browserNoActivityTimeout: 150000,
mime: { // Chrome version 55+ has a bug with TS. See: https://stackoverflow.com/a/41054760
'text/x-typescript': ['ts', 'tsx']
},
singleRun: true,
colors: true,
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
webpack: {
mode: 'development',
resolve: {
extensions: ['.ts', '.tsx', '.js']
// Add '.ts' and '.tsx' as a resolvable extension.
extensions: [".ts", ".tsx", ".js"]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: ['ts-loader']
use: {
loader: 'ts-loader',
options: {}
},
exclude: '/node_modules'
},
{
test: /ui\/.+(\.ts|\.js)$/,
exclude: /(node_modules|_Spec\.ts$|\_Spec.js$)/,
exclude: /(node_modules|spec\.ts$|spec.js$)/,
loader: 'istanbul-instrumenter-loader',
enforce: 'post',
options: {
Expand All @@ -94,11 +97,12 @@ module.exports = function (config) {
use: ['null-loader']
},
{
test: /\.(jpe|jpg|woff|woff2|eot|ttf|svg|png)(\?.*$|$)/,
test: /\.(jpe|jpg|png|woff|woff2|eot|ttf|svg)(\?.*$|$)/,
loader: 'null-loader'
}
]
},
plugins: [],
cache: true,
devtool: 'inline-source-map'
}
Expand Down
52 changes: 52 additions & 0 deletions test/test-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Error.stackTraceLimit = 5;

import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';

import 'core-js/es6/reflect';
import 'core-js/es7/reflect';

import 'zone.js/dist/zone'

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 { 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 const __karma__: any;
declare const 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('../src', true, /spec$/i);
// And load the modules.
context.keys().map(context);
// Finally, start Karma to run the tests.
__karma__.start();
Loading

0 comments on commit 47d0ef0

Please sign in to comment.