Skip to content

Commit 72b67cc

Browse files
test(*): Switch karma from SystemJS to webpack
1 parent 10fb103 commit 72b67cc

25 files changed

+123
-97
lines changed

.travis.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ node_js:
55
before_script:
66
- export DISPLAY=:99.0
77
- sh -e /etc/init.d/xvfb start
8-
- npm install -g karma
9-
- npm install -g typescript
10-
- npm install -g yarn
8+
- npm install -g yarn karma typescript
119
- ./nodeserver.sh > /dev/null &
1210

1311
matrix:
@@ -26,6 +24,7 @@ env:
2624

2725
script:
2826
- echo "CORE_BRANCH = x${CORE_BRANCH}x";
27+
# Fetch and build the ui-router-core branch from github, then install it
2928
- >
3029
if [ "x${CORE_BRANCH}x" != "xx" ] ; then
3130
git clone --depth=10 --branch="${CORE_BRANCH}" https://github.com/ui-router/core.git ui-router-core && pushd ui-router-core && yarn && popd && npm install ./ui-router-core ;
@@ -35,7 +34,7 @@ script:
3534
sudo: false
3635

3736
git:
38-
depth: 10
37+
depth: 3
3938

4039
notifications:
4140
slack: angularbuddies:b6leQM9gkBCW0S7MNDsELpqU

karma.conf.js

+15-25
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,20 @@ function karmaServedFiles(ngVersion) {
1919
'test/angular/' + version + '/angular.js',
2020
'test/angular/' + version + '/angular-mocks.js',
2121
'test/angular/' + version + '/angular-animate.js',
22-
'test/util/ng1.systemjs.adapter.js'
2322
];
2423
}
2524

2625
var angularFiles = angular(ngVersion).map(function (pattern) {
2726
return { watched: false, included: true, nocache: true, pattern: pattern };
2827
});
2928

30-
var srcFiles = [
31-
{ watched: true, included: false, nocache: true, pattern: 'src/**/*.ts' },
32-
];
33-
34-
var testFiles = [
35-
{ watched: true, included: false, nocache: true, pattern: 'test/**/*.ts' },
36-
{ watched: true, included: false, nocache: true, pattern: 'test/**/*.js' }
37-
];
38-
39-
return [].concat(angularFiles).concat(srcFiles).concat(testFiles);
29+
return angularFiles.concat('test/index.js');
4030
}
4131

32+
var webpackConfig = require('./webpack.config.js');
33+
webpackConfig.entry = {};
34+
webpackConfig.plugins = [];
35+
4236
module.exports = function(config) {
4337
var ngVersion = config.ngversion || "1.5.0";
4438

@@ -63,29 +57,25 @@ module.exports = function(config) {
6357
// Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
6458
browsers: ['PhantomJS'],
6559

66-
frameworks: ['systemjs', 'jasmine'],
60+
frameworks: ['jasmine'],
6761

6862
plugins: [
69-
require('karma-systemjs'),
63+
require('karma-webpack'),
64+
require('karma-sourcemap-loader'),
7065
require('karma-jasmine'),
7166
require('karma-phantomjs-launcher'),
7267
require('karma-chrome-launcher')
7368
],
7469

70+
webpack: webpackConfig,
71+
7572
/* Files *available to be served* by karma, i.e., anything that will be require()'d */
7673
files: karmaServedFiles(ngVersion),
77-
exclude: [],
78-
systemjs: {
79-
// Set up systemjs paths
80-
configFile: 'karma.system.config.js',
81-
82-
files: [
83-
'src/**/*.ts',
84-
'node_modules/ui-router-core/lib/**/*'
85-
],
86-
87-
// karma-systemjs kludge: This is turned into a regexp and is the actual specs that are loaded
88-
testFileSuffix: "/test/\\S+Spec.[tj]s"
74+
75+
preprocessors: {
76+
'test/index.js': ['webpack', 'sourcemap'],
77+
'../src/ng1': ['webpack', 'sourcemap'],
8978
},
79+
9080
});
9181
};

karma.system.config.js

-19
This file was deleted.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@
8282
"karma-jasmine": "^1.0.2",
8383
"karma-phantomjs-launcher": "^1.0.2",
8484
"karma-script-launcher": "~0.1.0",
85+
"karma-sourcemap-loader": "^0.3.7",
8586
"karma-systemjs": "^0.7.2",
87+
"karma-webpack": "^1.8.0",
8688
"lodash": "^4.5.1",
8789
"remap-istanbul": "^0.6.3",
8890
"shelljs": "^0.7.0",

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('./util');
5+
6+
require('../src/ng1');
7+
8+
var testsContext = require.context(".", true, /Spec$/);
9+
testsContext.keys().forEach(testsContext);

test/ng1StateBuilderSpec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
/// <reference path='../node_modules/@types/angular/index.d.ts' />
2+
/// <reference path='../node_modules/@types/angular-mocks/index.d.ts' />
3+
/// <reference path='../node_modules/@types/jasmine/index.d.ts' />
4+
15
import {StateBuilder, StateMatcher, ng1ViewsBuilder} from "../src/ng1";
26
import {Resolvable} from "ui-router-core";
7+
declare var inject;
38

49
describe('Ng1 StateBuilder', function() {
510
var builder, matcher, urlMatcherFactoryProvider: any = {

test/resolveSpec.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import "./util/testUtilsNg1.js";
2-
declare var resolvedValue, resolvedError, caught;
1+
/// <reference path='../node_modules/@types/angular/index.d.ts' />
2+
/// <reference path='../node_modules/@types/angular-mocks/index.d.ts' />
3+
/// <reference path='../node_modules/@types/jasmine/index.d.ts' />
4+
/// <reference path='./util/matchers.types.d.ts' />
35

4-
import "./util/matchers.ts";
5-
6-
import {
7-
ResolveContext, State, PathNode, omit, pick, extend, forEach
8-
} from "../src/ng1";
6+
import * as angular from "angular";
7+
import "./util/matchers";
8+
import "./util/testUtilsNg1";
99

10+
declare var inject;
1011
import Spy = jasmine.Spy;
11-
import {Resolvable, services} from "ui-router-core";
12+
import "./util/matchers.ts";
13+
import { resolvedValue, resolvedError, caught } from './util/testUtilsNg1';
14+
import { ResolveContext, State, PathNode, omit, pick, extend, forEach } from "../src/ng1";
15+
import {Resolvable, services, StateDeclaration} from "ui-router-core";
1216

13-
let module = angular.mock.module;
17+
let module = angular['mock'].module;
1418
///////////////////////////////////////////////
1519

1620
var states, statesTree, statesMap: { [key:string]: State } = {};
@@ -433,7 +437,7 @@ describe("Integration: Resolvables system", () => {
433437
copy[name] = extend({}, stateDef);
434438
});
435439

436-
angular.forEach(copy, stateDef => {
440+
angular.forEach(copy, (stateDef: StateDeclaration) => {
437441
if (stateDef.name) $stateProvider.state(stateDef);
438442
});
439443
}));

test/stateDirectivesSpec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var module = angular.mock.module;
2-
var uiRouter = require("angular-ui-router");
2+
var uiRouter = require("../src/ng1");
3+
var obj = require('./util/testUtilsNg1').obj;
34

45
describe('uiStateRef', function() {
56

test/stateEventsSpec.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
var module = angular.mock.module;
2-
var uiRouter = require("angular-ui-router");
2+
var uiRouter = require("../src/ng1");
33
var stateEvents = require("../src/ng1/legacy/stateEvents.ts");
4+
var decorateExceptionHandler = require("./util/testUtilsNg1").decorateExceptionHandler;
5+
var obj = require('./util/testUtilsNg1').obj;
6+
7+
var resolvedValue = require('./util/testUtilsNg1').resolvedValue;
8+
var resolvedError = require('./util/testUtilsNg1').resolvedError;
9+
var caught = require('./util/testUtilsNg1').caught;
410

511
describe('UI-Router v0.2.x $state events', function () {
612
var $injector, stateProvider;

test/stateFiltersSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var module = angular.mock.module;
2-
var uiRouter = require("angular-ui-router");
2+
var uiRouter = require("../src/ng1");
33

44
describe('isState filter', function() {
55
beforeEach(module('ui.router'));

test/stateSpec.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
var module = angular.mock.module;
2-
var uiRouter = require("angular-ui-router");
2+
var uiRouter = require("../src/ng1");
33
var extend = uiRouter.extend;
44
var forEach = uiRouter.forEach;
55
var services = uiRouter.services;
66
var UrlMatcher = uiRouter.UrlMatcher;
7-
7+
var obj = require('./util/testUtilsNg1').obj;
8+
var resolvedError = require('./util/testUtilsNg1').resolvedError;
9+
var resolvedValue = require('./util/testUtilsNg1').resolvedValue;
10+
var html5Compat = require('./util/testUtilsNg1').html5Compat;
811

912
describe('state', function () {
1013

test/templateFactorySpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var module = angular.mock.module;
2-
var uiRouter = require("angular-ui-router");
2+
var uiRouter = require("../src/ng1");
33

44
describe('templateFactory', function () {
55

test/urlMatcherFactorySpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var module = angular.mock.module;
2-
var uiRouter = require("angular-ui-router");
2+
var uiRouter = require("../src/ng1");
33
var Param = uiRouter.Param;
44
var ParamTypes = uiRouter.ParamTypes;
55
var UrlMatcher = uiRouter.UrlMatcher;

test/urlRouterSpec.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import ILocationService = angular.ILocationService;
2-
declare var html5Compat;
1+
/// <reference path='../node_modules/@types/angular/index.d.ts' />
2+
/// <reference path='../node_modules/@types/angular-mocks/index.d.ts' />
3+
/// <reference path='../node_modules/@types/jasmine/index.d.ts' />
4+
5+
import * as angular from "angular";
6+
import {ILocationService, ILocationProvider} from "angular";
7+
import "./util/matchers";
8+
import { html5Compat } from './util/testUtilsNg1';
9+
declare var inject;
10+
311
import {UrlMatcher, UrlMatcherFactory, services, UrlRouterProvider, UrlRouter, StateService} from "../src/ng1";
4-
import ILocationProvider = angular.ILocationProvider;
512

6-
var module = angular.mock.module;
13+
var module = angular['mock'].module;
714

815
describe("UrlRouter", function () {
916
var $urp: UrlRouterProvider, $lp: ILocationProvider, $umf: UrlMatcherFactory,
@@ -41,6 +48,7 @@ describe("UrlRouter", function () {
4148

4249
$urp.rule(function ($injector, $location) {
4350
log.push($location.path());
51+
return null;
4452
});
4553

4654
$location.path("/foo");
@@ -64,7 +72,7 @@ describe("UrlRouter", function () {
6472

6573
$urp.rule(function ($injector, $location) {
6674
var path = $location.path();
67-
if (!/baz/.test(path)) return false;
75+
if (!/baz/.test(path)) return;
6876
return path.replace('baz', 'b4z');
6977
}).when('/foo/:param', function($match) {
7078
match = ['/foo/:param', $match];
@@ -120,7 +128,7 @@ describe("UrlRouter", function () {
120128
validates: function() {},
121129
parameter: function() {},
122130
parameters: function() {}
123-
},
131+
} as any as UrlMatcher,
124132
handler: function() {}
125133
};
126134

test/util/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference path='./matchers.types.d.ts' />
2+
3+
export * from './matchers'
4+
export * from './testUtils'
5+
export * from './testUtilsNg1'

test/util/matchers.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
/// <reference path='../typings/jasmine/jasmine.d.ts' />
1+
/// <reference path='../../node_modules/@types/angular/index.d.ts' />
2+
/// <reference path='../../node_modules/@types/angular-mocks/index.d.ts' />
3+
/// <reference path='../../node_modules/@types/jasmine/index.d.ts' />
4+
/// <reference path='./matchers.types.d.ts' />
5+
26
import {equals} from "ui-router-core";
3-
declare var testablePromise;
7+
import {testablePromise} from "./testUtilsNg1";
48

59
beforeEach(function() {
610
jasmine.addMatchers(<any> {

test/util/matchers.types.d.ts

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

test/util/ng1.systemjs.adapter.js

-1
This file was deleted.

test/util/testUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function tree2Array(tree, inheritName) {
2626
}
2727

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

3232
this.setPromise = function(promise) {

0 commit comments

Comments
 (0)