Skip to content

Commit 0948309

Browse files
chore(tests): switch to karma-webpack
chore(tests): clean up typescript code
1 parent bde9c0f commit 0948309

19 files changed

+118
-97
lines changed

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ build_packages
44
site
55

66
# common
7+
**/.*
8+
*~
79
node_modules
810
bower_components
9-
.DS_Store
10-
*~
11-
.tscache
12-
.baseDir.ts
1311
lib
1412
lib-esm
1513

karma.conf.js

+26-14
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,42 @@ module.exports = function (karma) {
2323
// Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
2424
browsers: ['PhantomJS'],
2525

26-
frameworks: ['systemjs', 'jasmine'],
26+
frameworks: ['jasmine'],
2727

2828
plugins: [
29-
require('karma-systemjs'),
29+
require('karma-webpack'),
30+
require('karma-sourcemap-loader'),
3031
require('karma-jasmine'),
3132
require('karma-phantomjs-launcher'),
3233
require('karma-chrome-launcher')
3334
],
3435

36+
webpack: {
37+
devtool: 'source-map',
3538

36-
/* Files available to be served, so anything that will be require()'d */
37-
files: [
38-
{ watched: true, included: false, nocache: true, pattern: 'src/**/*.ts' },
39-
{ watched: true, included: false, nocache: true, pattern: 'test/**/*.[tj]s' },
40-
],
39+
resolve: {
40+
modulesDirectories: ['node_modules'],
41+
extensions: ['', '.js', '.ts']
42+
},
43+
44+
module: {
45+
loaders: [
46+
{ test: /\.ts$/, loader: "awesome-typescript-loader?declaration=false&tsconfig=test/tsconfig.json" }
47+
]
48+
},
49+
50+
},
4151

42-
systemjs: {
43-
// Set up systemjs paths
44-
configFile: 'karma.system.config.js',
45-
files: ['src/**/*.ts'],
46-
// karma-systemjs kludge: This is turned into a regexp and is the actual specs that are loaded
47-
testFileSuffix: "/test/\\S+.[tj]s"
52+
webpackMiddleware: {
53+
stats: { chunks: false },
4854
},
49-
exclude: []
55+
56+
files: ['test/index.js'],
57+
58+
preprocessors: {
59+
'test/index.js': ['webpack', 'sourcemap'],
60+
},
61+
5062
};
5163

5264
karma.set(config);

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,26 @@
5555
"devDependencies": {
5656
"@types/jasmine": "^2.2.34",
5757
"@types/jquery": "^1.10.31",
58+
"awesome-typescript-loader": "^2.2.4",
5859
"conventional-changelog": "^1.1.0",
5960
"conventional-changelog-cli": "^1.1.1",
6061
"conventional-changelog-ui-router-core": "^1.3.0",
62+
"core-js": "^2.4.1",
6163
"jasmine-core": "^2.4.1",
6264
"karma": "^1.2.0",
6365
"karma-chrome-launcher": "~0.1.0",
6466
"karma-coverage": "^0.5.3",
6567
"karma-jasmine": "^1.0.2",
6668
"karma-phantomjs-launcher": "^1.0.2",
6769
"karma-script-launcher": "~0.1.0",
68-
"karma-systemjs": "^0.7.2",
70+
"karma-sourcemap-loader": "^0.3.7",
71+
"karma-webpack": "^1.8.0",
6972
"npm-run-all": "^3.1.1",
7073
"readline-sync": "^1.4.4",
7174
"shelljs": "^0.7.0",
7275
"shx": "^0.1.4",
73-
"systemjs": "^0.18.4",
7476
"tslint": "=2.5.0",
75-
"typescript": "~2.0.2"
77+
"typescript": "~2.0.2",
78+
"webpack": "^1.13.3"
7679
}
7780
}

test/_matchers.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
declare namespace jasmine {
3+
interface Matchers {
4+
toEqualData(x: any): boolean;
5+
toEqualValues(x: any): boolean;
6+
}
7+
}

test/_matchers.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1+
/// <reference path="./_matchers.d.ts" />
2+
13
import {equals} from "../src/common/common";
24
declare var testablePromise;
35

4-
module "jasmine" {
5-
interface Matchers {
6-
toEqualData(expected: any): boolean;
7-
toEqualValues(expected: any): boolean;
8-
}
9-
}
10-
116
beforeEach(function() {
127
jasmine.addMatchers(<any> {
138
toEqualData: function() {

test/_testUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {pick, extend, forEach, omit} from "../src/index";
1+
import {pick, forEach, omit} from "../src/index";
22
import {map} from "../src/common/common";
33

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

2929
export function PromiseResult(promise?) {
30-
var self = this, _promise: Promise;
30+
var self = this, _promise: Promise<any>;
3131
var resolve, reject, complete;
3232

3333
this.setPromise = function(promise) {

test/commonSpec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
Glob, defaults, filter, is, eq, not, pattern, val, isInjectable
2+
defaults, filter, is, eq, not, pattern, val, isInjectable
33
} from "../src/index";
44

55
describe('common', function() {
@@ -53,7 +53,7 @@ describe('common', function() {
5353
it('should allow double-negatives', function() {
5454
function T() { return true; }
5555
function F() { return false; }
56-
function empty() { return ""; }
56+
function empty(): boolean { return <any> ""; }
5757

5858
expect(not(not(T))()).toBe(true);
5959
expect(not(not(F))()).toBe(false);
@@ -102,7 +102,7 @@ describe('common', function() {
102102
});
103103

104104
it('should accept ng1 annotated functions', function() {
105-
fn.$inject = ['foo', 'bar'];
105+
fn['$inject'] = ['foo', 'bar'];
106106
function fn (foo, bar) {}
107107
expect(isInjectable(fn)).toBeTruthy();
108108
});

test/hookBuilderSpec.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import {
2-
UIRouter, TransitionService, StateService, State, PathNode, tail, PathFactory
3-
} from "../src/index";
4-
5-
import {tree2Array} from "./_testUtils.ts";
1+
import { UIRouter, TransitionService, StateService, State, PathNode } from "../src/index";
2+
import { tree2Array } from "./_testUtils";
63
import "../src/justjs";
74

85
describe('HookBuilder:', function() {
@@ -51,7 +48,7 @@ describe('HookBuilder:', function() {
5148
expect(hb.getOnBeforeHooks().length).toBe(0);
5249

5350
// Transition from 'A.B.C' to 'A'
54-
let A = $state.target('A', null).$state();
51+
A = $state.target('A', null).$state();
5552
let B = $state.target('A.B', null).$state();
5653
let C = $state.target('A.B.C', null).$state();
5754
let fromPath = [new PathNode(root), new PathNode(A), new PathNode(B), new PathNode(C)];

test/hooksSpec.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
2-
import {UIRouter} from "../src/router";
3-
import {tree2Array} from "./_testUtils.ts";
4-
import {find} from "../src/common/common";
1+
import { UIRouter } from "../src/router";
2+
import { tree2Array } from "./_testUtils";
3+
import { find } from "../src/common/common";
4+
import { StateService } from "../src/state/stateService";
5+
import { StateDeclaration } from "../src/state/interface";
56

67

78
let statetree = {
@@ -15,7 +16,7 @@ let statetree = {
1516
};
1617

1718
describe("hooks", () => {
18-
let router, $state, states, init;
19+
let router, $state: StateService, states: StateDeclaration[], init;
1920
beforeEach(() => {
2021
router = new UIRouter();
2122
$state = router.stateService;

test/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// require all source files ending in "Spec" from the
2+
// current directory and all subdirectories
3+
4+
require('core-js');
5+
require('../src/index');
6+
require('./_matchers');
7+
8+
var testsContext = require.context(".", true, /Spec$/);
9+
testsContext.keys().forEach(testsContext);

test/lazyLoadSpec.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import { trace, UIRouter TransitionService, StateService } from "../src/index";
1+
import { UIRouter, TransitionService, StateService } from "../src/index";
22
import "../src/justjs";
3-
import {StateRegistry} from "../src/state/stateRegistry";
4-
import {services} from "../src/common/coreservices";
5-
import {UrlRouter} from "../src/url/urlRouter";
6-
7-
8-
declare module "jasmine" {
9-
interface Matchers {
10-
toEqualValues(val: any): boolean;
11-
}
12-
}
13-
3+
import { StateRegistry } from "../src/state/stateRegistry";
4+
import { services } from "../src/common/coreservices";
5+
import { UrlRouter } from "../src/url/urlRouter";
146

157
describe('a Future State', function () {
168
let router: UIRouter;

test/paramSpec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ParamTypes} from "../src/index";
1+
import { ParamTypes } from "../src/index";
22

33
describe('parameters', () => {
44
let types;

test/resolveSpec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { ResolveContext, State, PathNode, Resolvable } from "../src/index";
2-
import { copy } from "../src/index";
1+
import { ResolveContext, State, PathNode, Resolvable, copy } from "../src/index";
2+
import { services } from "../src/common/coreservices";
3+
import { tree2Array } from "./_testUtils";
4+
import { UIRouter } from "../src/router";
35

46
import Spy = jasmine.Spy;
5-
import {services} from "../src/common/coreservices";
6-
import {tree2Array} from "./_testUtils.ts";
7-
import {UIRouter} from "../src/router";
87

98
///////////////////////////////////////////////
109

test/stateHelperSpec.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import {StateMatcher, StateBuilder, UrlMatcher, TargetState, extend} from "../src/index";
1+
import { StateMatcher, StateBuilder, UrlMatcher, TargetState, extend } from "../src/index";
2+
import { ParamTypes } from "../src/params/paramTypes";
23

4+
var paramTypes = new ParamTypes();
35
describe('state helpers', function() {
46

57
var states;
@@ -127,7 +129,7 @@ describe('state helpers', function() {
127129
});
128130

129131
it('should compile a UrlMatcher for ^ URLs', function() {
130-
var url = new UrlMatcher('/', {});
132+
var url = new UrlMatcher('/', paramTypes);
131133
spyOn(urlMatcherFactoryProvider, 'compile').and.returnValue(url);
132134
spyOn(urlMatcherFactoryProvider, 'isMatcher').and.returnValue(true);
133135

@@ -155,7 +157,7 @@ describe('state helpers', function() {
155157

156158
it('should pass through custom UrlMatchers', function() {
157159
var root = states[''] = { url: { append: function() {} } };
158-
var url = new UrlMatcher("/", {});
160+
var url = new UrlMatcher("/", paramTypes);
159161
spyOn(urlMatcherFactoryProvider, 'isMatcher').and.returnValue(true);
160162
spyOn(root.url, 'append').and.returnValue(url);
161163
expect(builder.builder('url')({ url: url })).toBe(url);

test/stateRegistrySpec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {UIRouter} from "../src/router";
2-
import {tree2Array} from "./_testUtils.ts";
3-
import {StateRegistry} from "../src/state/stateRegistry";
4-
import {services} from "../src/common/coreservices";
1+
import { UIRouter } from "../src/router";
2+
import { tree2Array } from "./_testUtils";
3+
import { StateRegistry } from "../src/state/stateRegistry";
4+
import { services } from "../src/common/coreservices";
55

66
let router: UIRouter = null;
77
let registry: StateRegistry = null;

test/stateServiceSpec.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { UIRouter
2-
TransitionService,
3-
StateService,
4-
} from "../src/index";
1+
import { UIRouter, TransitionService, StateService } from "../src/index";
52
import "../src/justjs";
6-
import {tree2Array} from "./_testUtils.ts";
7-
import {TransitionOptions} from "../src/transition/interface";
8-
import {LocationServices, services} from "../src/common/coreservices";
3+
import { tree2Array } from "./_testUtils";
4+
import { TransitionOptions } from "../src/transition/interface";
5+
import { LocationServices, services } from "../src/common/coreservices";
96

107
describe('stateService', function () {
118
let router: UIRouter;
@@ -79,12 +76,12 @@ describe('stateService', function () {
7976

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

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

9794
$loc.setUrl('/a/b/c');
98-
spyOn($loc, 'setUrl').and.callThrough();
95+
var setUrl = spyOn($loc, 'setUrl').and.callThrough();
9996
router.urlRouter.sync();
10097

10198
wait().then(() => {
10299
expect($state.current.name).toBe('D');
103-
let pushedUrls = $loc.setUrl.calls.all().map(x => x.args[0]).filter(x => x !== undefined);
100+
let pushedUrls = setUrl.calls.all().map(x => x.args[0]).filter(x => x !== undefined);
104101
expect(pushedUrls).toEqual(['/a/b/c/d']);
105102
expect($loc.path()).toBe('/a/b/c/d');
106103
done();

test/transitionSpec.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
import {PathNode} from "../src/path/node";
2-
3-
import { UIRouter
4-
RejectType, Rejection,
5-
pluck,
6-
services,
7-
TransitionService,
8-
StateService,
9-
Rejection,
10-
Resolvable,
11-
Transition,
1+
import { PathNode } from "../src/path/node";
2+
import {
3+
UIRouter, RejectType, Rejection, pluck, services, TransitionService, StateService, Resolvable, Transition
124
} from "../src/index";
135
import "../src/justjs";
14-
import {tree2Array, PromiseResult} from "./_testUtils.ts";
6+
import { tree2Array, PromiseResult } from "./_testUtils";
157

168
describe('transition', function () {
179

test/tsconfig.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"emitDecoratorMetadata": true,
4+
"experimentalDecorators": true,
5+
"moduleResolution": "node",
6+
"module": "commonjs",
7+
"target": "es5",
8+
"lib": [ "es6", "dom" ],
9+
"allowSyntheticDefaultImports": true,
10+
"outDir": "../.testlib",
11+
"declaration": false,
12+
"sourceMap": false
13+
},
14+
"include": [
15+
"*.ts"
16+
]
17+
}

test/viewServiceSpec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {UIRouter} from "../src/router";
2-
import {tree2Array} from "./_testUtils.ts";
3-
import {StateRegistry} from "../src/state/stateRegistry";
4-
import {ViewService} from "../src/view/view";
5-
import {ActiveUIView} from "../src/view/interface";
1+
import { UIRouter } from "../src/router";
2+
import { tree2Array } from "./_testUtils";
3+
import { StateRegistry } from "../src/state/stateRegistry";
4+
import { ViewService } from "../src/view/view";
5+
import { ActiveUIView } from "../src/view/interface";
66

77
let router: UIRouter = null;
88
let registry: StateRegistry = null;

0 commit comments

Comments
 (0)