Skip to content

Commit b3d3b56

Browse files
test(*): split tests into core, ng1, ng2
chore(*): use npm scripts for karma, not grunt
1 parent 95ae0cf commit b3d3b56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+929
-975
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ before_script:
1010
- ./nodeserver.sh > /dev/null &
1111

1212
script:
13-
- grunt integrate
13+
- npm run test:integrate
1414

1515
sudo: false
1616

config/_karma.base.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Karma configuration file
2+
3+
var karma = require("karma");
4+
var files = require('../files').files;
5+
6+
var config = {
7+
8+
singleRun: true,
9+
autoWatch: false,
10+
autoWatchInterval: 0,
11+
12+
// level of logging
13+
// possible values: LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
14+
logLevel: "warn",
15+
// possible values: 'dots', 'progress'
16+
reporters: 'dots',
17+
colors: true,
18+
19+
port: 8080,
20+
21+
// base path, that will be used to resolve files and exclude
22+
basePath: '..',
23+
24+
// Start these browsers, currently available:
25+
// Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
26+
browsers: ['PhantomJS'],
27+
28+
frameworks: ['systemjs', 'jasmine'],
29+
30+
plugins: [
31+
require('karma-systemjs'),
32+
require('karma-jasmine'),
33+
require('karma-phantomjs-launcher'),
34+
require('karma-chrome-launcher')
35+
],
36+
37+
systemjs: {
38+
// Set up systemjs paths
39+
configFile: 'config/system.config.js',
40+
files: ['src/**/*.ts']
41+
},
42+
exclude: []
43+
};
44+
45+
module.exports = config;

config/_karma.ng1.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
// Karma configuration file
3+
var clone = require("clone");
4+
var baseconfig = require("./_karma.base");
5+
var files = require('../files').files;
6+
7+
module.exports = function (ngVersion, testFileSuffix) {
8+
var config = clone(baseconfig);
9+
10+
/* Files available to be served by karma, i.e., anything that will be require()'d */
11+
config.files = files.karmaServedFiles(ngVersion);
12+
13+
// karma-systemjs kludge: This is turned into a regexp and is the actual specs that are loaded
14+
config.systemjs.testFileSuffix = testFileSuffix;
15+
16+
return config;
17+
};
18+

config/karma.core.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Karma configuration file
2+
var clone = require("clone");
3+
var baseconfig = require("./_karma.base");
4+
var files = require('../files').files;
5+
6+
module.exports = function (karma) {
7+
var config = clone(baseconfig);
8+
9+
/* Files available to be served, so anything that will be require()'d */
10+
config.files = files.karmaServedFiles();
11+
12+
// karma-systemjs kludge: This is turned into a regexp and is the actual specs that are loaded
13+
config.systemjs.testFileSuffix = "/test/core/\\S+.[tj]s";
14+
15+
karma.set(config);
16+
};

config/karma.js

-54
This file was deleted.

config/karma.ng12.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var ng1ConfigFactory = require("./_karma.ng1");
2+
module.exports = function (karma) {
3+
karma.set(ng1ConfigFactory("1.2.28", "/test/ng1/\\S+.[tj]s"));
4+
};

config/karma.ng13.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var ng1ConfigFactory = require("./_karma.ng1");
2+
module.exports = function (karma) {
3+
karma.set(ng1ConfigFactory("1.3.16", "/test/ng1/\\S+.[tj]s"));
4+
};

config/karma.ng14.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var ng1ConfigFactory = require("./_karma.ng1");
2+
module.exports = function (karma) {
3+
karma.set(ng1ConfigFactory("1.4.9", "/test/ng1/\\S+.[tj]s"));
4+
};

config/karma.ng15.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var ng1ConfigFactory = require("./_karma.ng1");
2+
module.exports = function (karma) {
3+
karma.set(ng1ConfigFactory("1.5.0", "/test/ng1/\\S+.[tj]s"));
4+
};

config/system.config.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@ System.config({
77
'system-polyfills': 'node_modules/systemjs/dist/system-polyfills.js',
88
'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js',
99
'phantomjs-polyfill': 'node_modules/phantomjs-polyfill/bind-polyfill.js',
10-
'angular-ui-router': 'src/ng1.ts'
10+
'rxjs': 'node_modules/rxjs/bundles/Rx.js',
11+
'@angular': 'node_modules/@angular',
12+
13+
'angular-ui-router': 'src/ng1.ts',
14+
'ui-router-core': 'src/core.ts',
15+
'ui-router-ng2': 'src/ng2.ts'
1116
},
1217
packages: {
13-
'build/es6': {
14-
defaultExtension: 'js'
15-
},
16-
'src': {
17-
defaultExtension: 'ts'
18-
}
18+
'build/es6': { defaultExtension: 'js' },
19+
'src': { defaultExtension: 'ts' },
20+
21+
'@angular/core': { main: 'index.js', defaultExtension: 'js' },
22+
'@angular/compiler': { main: 'index.js', defaultExtension: 'js' },
23+
'@angular/common': { main: 'index.js', defaultExtension: 'js' },
24+
'@angular/http': { main: 'index.js', defaultExtension: 'js' },
25+
'@angular/testing': { main: 'index.js', defaultExtension: 'js' },
26+
'@angular/platform-browser': { main: 'index.js', defaultExtension: 'js' },
27+
'@angular/platform-browser-dynamic': { main: 'index.js', defaultExtension: 'js' }
1928
}
2029
});

files.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,28 @@ routerFiles = {
2020

2121
// Returns necessary files for a specific version of angular
2222
angular: function(version) {
23-
return [
24-
'lib/angular-' + version + '/angular.js',
25-
'lib/angular-' + version + '/angular-mocks.js',
26-
'lib/angular-' + version + '/angular-animate.js'
27-
];
23+
if (version && version[0] === '1') {
24+
return [
25+
'lib/angular-' + version + '/angular.js',
26+
'lib/angular-' + version + '/angular-mocks.js',
27+
'lib/angular-' + version + '/angular-animate.js'
28+
];
29+
}
30+
31+
return [];
2832
},
2933

30-
// This returns a Karma 'files configuration' for the files served by the Karma web server
31-
// http://karma-runner.github.io/0.8/config/files.html
32-
karmaServedFiles: function(version) {
33-
return routerFiles.angular(version).map(function (pattern) {
34+
/**
35+
* This returns a Karma 'files configuration'.
36+
* http://karma-runner.github.io/0.8/config/files.html
37+
*
38+
* Specifies which files can be served by the Karma web server
39+
*
40+
* included: true -- files that are always served to the browser (like <script> tag)
41+
* included: false -- files *available to be served* by karma, for instance via require()
42+
*/
43+
karmaServedFiles: function(ngVersion) {
44+
return routerFiles.angular(ngVersion).map(function (pattern) {
3445
return { watched: false, included: true, nocache: true, pattern: pattern };
3546
}).concat([
3647
{ watched: true, included: false, nocache: true, pattern: 'src/**/*.ts' },

package.json

+24-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22
"name": "ui-router",
33
"description": "State-based routing for Javascript",
44
"version": "1.0.0-alpha.5",
5-
"scripts": {},
5+
"scripts": {
6+
"test": "npm run test:core && npm run test:ng1",
7+
"test:watch": "node_modules/watch/cli.js 'npm run test' src test",
8+
9+
"test:core": "karma start config/karma.core.js",
10+
"test:core:debug": "karma start config/karma.core.js --singleRun=false --browsers=Chrome --autoWatch=true --autoWatchInterval=1",
11+
12+
"test:ng1": "karma start config/karma.ng15.js",
13+
"test:ng1:debug": "karma start config/karma.ng15.js --singleRun=false --browsers=Chrome --autoWatch=true --autoWatchInterval=1",
14+
15+
"test:ng12": "karma start config/karma.ng12.js",
16+
"test:ng13": "karma start config/karma.ng13.js",
17+
"test:ng14": "karma start config/karma.ng14.js",
18+
"test:ng15": "karma start config/karma.ng15.js",
19+
"test:integrate": "npm run test:core && npm run test:ng12 && npm run test:ng13 && npm run test:ng14 && npm run test:ng15"
20+
},
621
"homepage": "http://angular-ui.github.com/ui-router",
722
"contributors": [
823
{
@@ -46,9 +61,8 @@
4661
"@angular/core": "=2.0.0-rc.1",
4762
"@angular/platform-browser": "=2.0.0-rc.1",
4863
"@angular/platform-browser-dynamic": "=2.0.0-rc.1",
49-
"rxjs": "=5.0.0-beta.6",
50-
"zone.js": "=0.6.12",
5164
"babel-core": "^5.8.14",
65+
"clone": "^1.0.2",
5266
"conventional-changelog": "^1.1.0",
5367
"conventional-changelog-cli": "^1.1.1",
5468
"es6-module-loader": "^0.17.3",
@@ -70,22 +84,28 @@
7084
"jsdoc": "git://github.com/jsdoc3/jsdoc.git#v3.2.2",
7185
"karma": "~0.12.0",
7286
"karma-chrome-launcher": "~0.1.0",
87+
"karma-coverage": "^0.5.3",
7388
"karma-jasmine": "^0.3.8",
7489
"karma-phantomjs-launcher": "~0.1.0",
7590
"karma-script-launcher": "~0.1.0",
7691
"karma-systemjs": "^0.7.2",
7792
"load-grunt-tasks": "~0.4.0",
7893
"lodash": "^4.5.1",
94+
"parallelshell": "^2.0.0",
7995
"phantomjs-polyfill": "0.0.1",
8096
"reflect-metadata": "=0.1.2",
97+
"remap-istanbul": "^0.6.3",
98+
"rxjs": "=5.0.0-beta.6",
8199
"shelljs": "~0.6.0",
82100
"systemjs": "^0.18.4",
83101
"ts-loader": "^0.8.1",
84102
"tslint": "=2.5.0",
85103
"typedoc": "git://github.com/christopherthielen/typedoc.git#v0.3-uirouter",
86104
"typescript": "~1.8.0",
105+
"watch": "^0.18.0",
87106
"webpack": "1.x",
88107
"webpack-dev-server": "1.x",
89-
"yargs": "^4.2.0"
108+
"yargs": "^4.2.0",
109+
"zone.js": "=0.6.12"
90110
}
91111
}

src/globals.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ export class UIRouterGlobals {
7272

7373
transitionService.onBefore({}, ['$transition$', beforeNewTransition]);
7474
}
75-
}
75+
}

src/state/interface.ts

+4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import {ParamDeclaration} from "../params/interface";
44
import {State} from "./stateObject";
55
import {ViewContext} from "../view/interface";
66
import {IInjectable} from "../common/common";
7+
import {Transition} from "../transition/transition";
78

89
export type StateOrName = (string|StateDeclaration|State);
910

11+
export interface TransitionPromise extends Promise<State> {
12+
transition: Transition;
13+
}
1014

1115
/**
1216
* Base interface for [[Ng1ViewDeclaration]] and [[Ng2ViewDeclaration]]

src/state/stateService.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {TransitionService, defaultTransOpts} from "../transition/transitionServi
1818
import {Rejection} from "../transition/rejectFactory";
1919
import {Transition} from "../transition/transition";
2020

21-
import {StateOrName, StateDeclaration} from "./interface";
21+
import {StateOrName, StateDeclaration, TransitionPromise} from "./interface";
2222
import {StateRegistry} from "./stateRegistry";
2323
import {State} from "./stateObject";
2424
import {TargetState} from "./targetState";
@@ -210,14 +210,14 @@ export class StateService {
210210
* - *resolve error* - when an error has occurred with a `resolve`
211211
*
212212
*/
213-
go(to: StateOrName, params: RawParams, options: TransitionOptions): Promise<State> {
213+
go(to: StateOrName, params?: RawParams, options?: TransitionOptions): TransitionPromise {
214214
let defautGoOpts = { relative: this.$current, inherit: true };
215215
let transOpts = defaults(options, defautGoOpts, defaultTransOpts);
216216
return this.transitionTo(to, params, transOpts);
217217
};
218218

219219
/** Factory method for creating a TargetState */
220-
target(identifier: StateOrName, params: ParamsOrArray, options: TransitionOptions = {}): TargetState {
220+
target(identifier: StateOrName, params?: ParamsOrArray, options: TransitionOptions = {}): TargetState {
221221
// If we're reloading, find the state object to reload from
222222
if (isObject(options.reload) && !(<any>options.reload).name)
223223
throw new Error('Invalid reload state object');
@@ -268,7 +268,7 @@ export class StateService {
268268
* @returns {promise} A promise representing the state of the new transition. See
269269
* {@link ui.router.state.$state#methods_go $state.go}.
270270
*/
271-
transitionTo(to: StateOrName, toParams: RawParams = {}, options: TransitionOptions = {}): Promise<State> {
271+
transitionTo(to: StateOrName, toParams: RawParams = {}, options: TransitionOptions = {}): TransitionPromise {
272272
let transHistory = this.globals.transitionHistory;
273273
options = defaults(options, defaultTransOpts);
274274
options = extend(options, { current: transHistory.peekTail.bind(transHistory)});

test/compat/matchers.ts

-37
This file was deleted.

0 commit comments

Comments
 (0)