Skip to content

Commit

Permalink
chore(tests): switch to karma-webpack
Browse files Browse the repository at this point in the history
chore(tests): clean up typescript code
  • Loading branch information
christopherthielen committed Nov 2, 2016
1 parent bde9c0f commit 0948309
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 97 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ build_packages
site

# common
**/.*
*~
node_modules
bower_components
.DS_Store
*~
.tscache
.baseDir.ts
lib
lib-esm

Expand Down
40 changes: 26 additions & 14 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,42 @@ module.exports = function (karma) {
// Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
browsers: ['PhantomJS'],

frameworks: ['systemjs', 'jasmine'],
frameworks: ['jasmine'],

plugins: [
require('karma-systemjs'),
require('karma-webpack'),
require('karma-sourcemap-loader'),
require('karma-jasmine'),
require('karma-phantomjs-launcher'),
require('karma-chrome-launcher')
],

webpack: {
devtool: 'source-map',

/* Files available to be served, so anything that will be require()'d */
files: [
{ watched: true, included: false, nocache: true, pattern: 'src/**/*.ts' },
{ watched: true, included: false, nocache: true, pattern: 'test/**/*.[tj]s' },
],
resolve: {
modulesDirectories: ['node_modules'],
extensions: ['', '.js', '.ts']
},

module: {
loaders: [
{ test: /\.ts$/, loader: "awesome-typescript-loader?declaration=false&tsconfig=test/tsconfig.json" }
]
},

},

systemjs: {
// Set up systemjs paths
configFile: 'karma.system.config.js',
files: ['src/**/*.ts'],
// karma-systemjs kludge: This is turned into a regexp and is the actual specs that are loaded
testFileSuffix: "/test/\\S+.[tj]s"
webpackMiddleware: {
stats: { chunks: false },
},
exclude: []

files: ['test/index.js'],

preprocessors: {
'test/index.js': ['webpack', 'sourcemap'],
},

};

karma.set(config);
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,26 @@
"devDependencies": {
"@types/jasmine": "^2.2.34",
"@types/jquery": "^1.10.31",
"awesome-typescript-loader": "^2.2.4",
"conventional-changelog": "^1.1.0",
"conventional-changelog-cli": "^1.1.1",
"conventional-changelog-ui-router-core": "^1.3.0",
"core-js": "^2.4.1",
"jasmine-core": "^2.4.1",
"karma": "^1.2.0",
"karma-chrome-launcher": "~0.1.0",
"karma-coverage": "^0.5.3",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.2",
"karma-script-launcher": "~0.1.0",
"karma-systemjs": "^0.7.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"npm-run-all": "^3.1.1",
"readline-sync": "^1.4.4",
"shelljs": "^0.7.0",
"shx": "^0.1.4",
"systemjs": "^0.18.4",
"tslint": "=2.5.0",
"typescript": "~2.0.2"
"typescript": "~2.0.2",
"webpack": "^1.13.3"
}
}
7 changes: 7 additions & 0 deletions test/_matchers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

declare namespace jasmine {
interface Matchers {
toEqualData(x: any): boolean;
toEqualValues(x: any): boolean;
}
}
9 changes: 2 additions & 7 deletions test/_matchers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
/// <reference path="./_matchers.d.ts" />

import {equals} from "../src/common/common";
declare var testablePromise;

module "jasmine" {
interface Matchers {
toEqualData(expected: any): boolean;
toEqualValues(expected: any): boolean;
}
}

beforeEach(function() {
jasmine.addMatchers(<any> {
toEqualData: function() {
Expand Down
4 changes: 2 additions & 2 deletions test/_testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {pick, extend, forEach, omit} from "../src/index";
import {pick, forEach, omit} from "../src/index";
import {map} from "../src/common/common";

let stateProps = ["resolve", "resolvePolicy", "data", "template", "templateUrl", "url", "name", "params"];
Expand Down Expand Up @@ -27,7 +27,7 @@ export function tree2Array(tree, inheritName) {
}

export function PromiseResult(promise?) {
var self = this, _promise: Promise;
var self = this, _promise: Promise<any>;
var resolve, reject, complete;

this.setPromise = function(promise) {
Expand Down
6 changes: 3 additions & 3 deletions test/commonSpec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Glob, defaults, filter, is, eq, not, pattern, val, isInjectable
defaults, filter, is, eq, not, pattern, val, isInjectable
} from "../src/index";

describe('common', function() {
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('common', function() {
it('should allow double-negatives', function() {
function T() { return true; }
function F() { return false; }
function empty() { return ""; }
function empty(): boolean { return <any> ""; }

expect(not(not(T))()).toBe(true);
expect(not(not(F))()).toBe(false);
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('common', function() {
});

it('should accept ng1 annotated functions', function() {
fn.$inject = ['foo', 'bar'];
fn['$inject'] = ['foo', 'bar'];
function fn (foo, bar) {}
expect(isInjectable(fn)).toBeTruthy();
});
Expand Down
9 changes: 3 additions & 6 deletions test/hookBuilderSpec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
UIRouter, TransitionService, StateService, State, PathNode, tail, PathFactory
} from "../src/index";

import {tree2Array} from "./_testUtils.ts";
import { UIRouter, TransitionService, StateService, State, PathNode } from "../src/index";
import { tree2Array } from "./_testUtils";
import "../src/justjs";

describe('HookBuilder:', function() {
Expand Down Expand Up @@ -51,7 +48,7 @@ describe('HookBuilder:', function() {
expect(hb.getOnBeforeHooks().length).toBe(0);

// Transition from 'A.B.C' to 'A'
let A = $state.target('A', null).$state();
A = $state.target('A', null).$state();
let B = $state.target('A.B', null).$state();
let C = $state.target('A.B.C', null).$state();
let fromPath = [new PathNode(root), new PathNode(A), new PathNode(B), new PathNode(C)];
Expand Down
11 changes: 6 additions & 5 deletions test/hooksSpec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import {UIRouter} from "../src/router";
import {tree2Array} from "./_testUtils.ts";
import {find} from "../src/common/common";
import { UIRouter } from "../src/router";
import { tree2Array } from "./_testUtils";
import { find } from "../src/common/common";
import { StateService } from "../src/state/stateService";
import { StateDeclaration } from "../src/state/interface";


let statetree = {
Expand All @@ -15,7 +16,7 @@ let statetree = {
};

describe("hooks", () => {
let router, $state, states, init;
let router, $state: StateService, states: StateDeclaration[], init;
beforeEach(() => {
router = new UIRouter();
$state = router.stateService;
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// require all source files ending in "Spec" from the
// current directory and all subdirectories

require('core-js');
require('../src/index');
require('./_matchers');

var testsContext = require.context(".", true, /Spec$/);
testsContext.keys().forEach(testsContext);
16 changes: 4 additions & 12 deletions test/lazyLoadSpec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { trace, UIRouter TransitionService, StateService } from "../src/index";
import { UIRouter, TransitionService, StateService } from "../src/index";
import "../src/justjs";
import {StateRegistry} from "../src/state/stateRegistry";
import {services} from "../src/common/coreservices";
import {UrlRouter} from "../src/url/urlRouter";


declare module "jasmine" {
interface Matchers {
toEqualValues(val: any): boolean;
}
}

import { StateRegistry } from "../src/state/stateRegistry";
import { services } from "../src/common/coreservices";
import { UrlRouter } from "../src/url/urlRouter";

describe('a Future State', function () {
let router: UIRouter;
Expand Down
2 changes: 1 addition & 1 deletion test/paramSpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ParamTypes} from "../src/index";
import { ParamTypes } from "../src/index";

describe('parameters', () => {
let types;
Expand Down
9 changes: 4 additions & 5 deletions test/resolveSpec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ResolveContext, State, PathNode, Resolvable } from "../src/index";
import { copy } from "../src/index";
import { ResolveContext, State, PathNode, Resolvable, copy } from "../src/index";
import { services } from "../src/common/coreservices";
import { tree2Array } from "./_testUtils";
import { UIRouter } from "../src/router";

import Spy = jasmine.Spy;
import {services} from "../src/common/coreservices";
import {tree2Array} from "./_testUtils.ts";
import {UIRouter} from "../src/router";

///////////////////////////////////////////////

Expand Down
8 changes: 5 additions & 3 deletions test/stateHelperSpec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {StateMatcher, StateBuilder, UrlMatcher, TargetState, extend} from "../src/index";
import { StateMatcher, StateBuilder, UrlMatcher, TargetState, extend } from "../src/index";
import { ParamTypes } from "../src/params/paramTypes";

var paramTypes = new ParamTypes();
describe('state helpers', function() {

var states;
Expand Down Expand Up @@ -127,7 +129,7 @@ describe('state helpers', function() {
});

it('should compile a UrlMatcher for ^ URLs', function() {
var url = new UrlMatcher('/', {});
var url = new UrlMatcher('/', paramTypes);
spyOn(urlMatcherFactoryProvider, 'compile').and.returnValue(url);
spyOn(urlMatcherFactoryProvider, 'isMatcher').and.returnValue(true);

Expand Down Expand Up @@ -155,7 +157,7 @@ describe('state helpers', function() {

it('should pass through custom UrlMatchers', function() {
var root = states[''] = { url: { append: function() {} } };
var url = new UrlMatcher("/", {});
var url = new UrlMatcher("/", paramTypes);
spyOn(urlMatcherFactoryProvider, 'isMatcher').and.returnValue(true);
spyOn(root.url, 'append').and.returnValue(url);
expect(builder.builder('url')({ url: url })).toBe(url);
Expand Down
8 changes: 4 additions & 4 deletions test/stateRegistrySpec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {UIRouter} from "../src/router";
import {tree2Array} from "./_testUtils.ts";
import {StateRegistry} from "../src/state/stateRegistry";
import {services} from "../src/common/coreservices";
import { UIRouter } from "../src/router";
import { tree2Array } from "./_testUtils";
import { StateRegistry } from "../src/state/stateRegistry";
import { services } from "../src/common/coreservices";

let router: UIRouter = null;
let registry: StateRegistry = null;
Expand Down
19 changes: 8 additions & 11 deletions test/stateServiceSpec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { UIRouter
TransitionService,
StateService,
} from "../src/index";
import { UIRouter, TransitionService, StateService } from "../src/index";
import "../src/justjs";
import {tree2Array} from "./_testUtils.ts";
import {TransitionOptions} from "../src/transition/interface";
import {LocationServices, services} from "../src/common/coreservices";
import { tree2Array } from "./_testUtils";
import { TransitionOptions } from "../src/transition/interface";
import { LocationServices, services } from "../src/common/coreservices";

describe('stateService', function () {
let router: UIRouter;
Expand Down Expand Up @@ -79,12 +76,12 @@ describe('stateService', function () {

it("should not update the URL in response to synchronizing URL", ((done) => {
$loc.setUrl('/a/b/c');
spyOn($loc, 'setUrl').and.callThrough();
var setUrl = spyOn($loc, 'setUrl').and.callThrough();
router.urlRouter.sync();

wait().then(() => {
expect($state.current.name).toBe('C');
let pushedUrls = $loc.setUrl.calls.all().map(x => x.args[0]).filter(x => x !== undefined);
let pushedUrls = setUrl.calls.all().map(x => x.args[0]).filter(x => x !== undefined);
expect(pushedUrls).toEqual([]);
expect($loc.path()).toBe('/a/b/c');
done();
Expand All @@ -95,12 +92,12 @@ describe('stateService', function () {
$transitions.onStart({ to: 'C' }, () => $state.target('D'));

$loc.setUrl('/a/b/c');
spyOn($loc, 'setUrl').and.callThrough();
var setUrl = spyOn($loc, 'setUrl').and.callThrough();
router.urlRouter.sync();

wait().then(() => {
expect($state.current.name).toBe('D');
let pushedUrls = $loc.setUrl.calls.all().map(x => x.args[0]).filter(x => x !== undefined);
let pushedUrls = setUrl.calls.all().map(x => x.args[0]).filter(x => x !== undefined);
expect(pushedUrls).toEqual(['/a/b/c/d']);
expect($loc.path()).toBe('/a/b/c/d');
done();
Expand Down
16 changes: 4 additions & 12 deletions test/transitionSpec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import {PathNode} from "../src/path/node";

import { UIRouter
RejectType, Rejection,
pluck,
services,
TransitionService,
StateService,
Rejection,
Resolvable,
Transition,
import { PathNode } from "../src/path/node";
import {
UIRouter, RejectType, Rejection, pluck, services, TransitionService, StateService, Resolvable, Transition
} from "../src/index";
import "../src/justjs";
import {tree2Array, PromiseResult} from "./_testUtils.ts";
import { tree2Array, PromiseResult } from "./_testUtils";

describe('transition', function () {

Expand Down
17 changes: 17 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"module": "commonjs",
"target": "es5",
"lib": [ "es6", "dom" ],
"allowSyntheticDefaultImports": true,
"outDir": "../.testlib",
"declaration": false,
"sourceMap": false
},
"include": [
"*.ts"
]
}
10 changes: 5 additions & 5 deletions test/viewServiceSpec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {UIRouter} from "../src/router";
import {tree2Array} from "./_testUtils.ts";
import {StateRegistry} from "../src/state/stateRegistry";
import {ViewService} from "../src/view/view";
import {ActiveUIView} from "../src/view/interface";
import { UIRouter } from "../src/router";
import { tree2Array } from "./_testUtils";
import { StateRegistry } from "../src/state/stateRegistry";
import { ViewService } from "../src/view/view";
import { ActiveUIView } from "../src/view/interface";

let router: UIRouter = null;
let registry: StateRegistry = null;
Expand Down

0 comments on commit 0948309

Please sign in to comment.