Skip to content

Commit

Permalink
test(*): split tests into core, ng1, ng2
Browse files Browse the repository at this point in the history
chore(*): use npm scripts for karma, not grunt
  • Loading branch information
christopherthielen committed May 7, 2016
1 parent 95ae0cf commit b3d3b56
Show file tree
Hide file tree
Showing 42 changed files with 929 additions and 975 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ before_script:
- ./nodeserver.sh > /dev/null &

script:
- grunt integrate
- npm run test:integrate

sudo: false

Expand Down
45 changes: 45 additions & 0 deletions config/_karma.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Karma configuration file

var karma = require("karma");
var files = require('../files').files;

var config = {

singleRun: true,
autoWatch: false,
autoWatchInterval: 0,

// level of logging
// possible values: LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
logLevel: "warn",
// possible values: 'dots', 'progress'
reporters: 'dots',
colors: true,

port: 8080,

// base path, that will be used to resolve files and exclude
basePath: '..',

// Start these browsers, currently available:
// Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
browsers: ['PhantomJS'],

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

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

systemjs: {
// Set up systemjs paths
configFile: 'config/system.config.js',
files: ['src/**/*.ts']
},
exclude: []
};

module.exports = config;
18 changes: 18 additions & 0 deletions config/_karma.ng1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

// Karma configuration file
var clone = require("clone");
var baseconfig = require("./_karma.base");
var files = require('../files').files;

module.exports = function (ngVersion, testFileSuffix) {
var config = clone(baseconfig);

/* Files available to be served by karma, i.e., anything that will be require()'d */
config.files = files.karmaServedFiles(ngVersion);

// karma-systemjs kludge: This is turned into a regexp and is the actual specs that are loaded
config.systemjs.testFileSuffix = testFileSuffix;

return config;
};

16 changes: 16 additions & 0 deletions config/karma.core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Karma configuration file
var clone = require("clone");
var baseconfig = require("./_karma.base");
var files = require('../files').files;

module.exports = function (karma) {
var config = clone(baseconfig);

/* Files available to be served, so anything that will be require()'d */
config.files = files.karmaServedFiles();

// karma-systemjs kludge: This is turned into a regexp and is the actual specs that are loaded
config.systemjs.testFileSuffix = "/test/core/\\S+.[tj]s";

karma.set(config);
};
54 changes: 0 additions & 54 deletions config/karma.js

This file was deleted.

4 changes: 4 additions & 0 deletions config/karma.ng12.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var ng1ConfigFactory = require("./_karma.ng1");
module.exports = function (karma) {
karma.set(ng1ConfigFactory("1.2.28", "/test/ng1/\\S+.[tj]s"));
};
4 changes: 4 additions & 0 deletions config/karma.ng13.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var ng1ConfigFactory = require("./_karma.ng1");
module.exports = function (karma) {
karma.set(ng1ConfigFactory("1.3.16", "/test/ng1/\\S+.[tj]s"));
};
4 changes: 4 additions & 0 deletions config/karma.ng14.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var ng1ConfigFactory = require("./_karma.ng1");
module.exports = function (karma) {
karma.set(ng1ConfigFactory("1.4.9", "/test/ng1/\\S+.[tj]s"));
};
4 changes: 4 additions & 0 deletions config/karma.ng15.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var ng1ConfigFactory = require("./_karma.ng1");
module.exports = function (karma) {
karma.set(ng1ConfigFactory("1.5.0", "/test/ng1/\\S+.[tj]s"));
};
23 changes: 16 additions & 7 deletions config/system.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ System.config({
'system-polyfills': 'node_modules/systemjs/dist/system-polyfills.js',
'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js',
'phantomjs-polyfill': 'node_modules/phantomjs-polyfill/bind-polyfill.js',
'angular-ui-router': 'src/ng1.ts'
'rxjs': 'node_modules/rxjs/bundles/Rx.js',
'@angular': 'node_modules/@angular',

'angular-ui-router': 'src/ng1.ts',
'ui-router-core': 'src/core.ts',
'ui-router-ng2': 'src/ng2.ts'
},
packages: {
'build/es6': {
defaultExtension: 'js'
},
'src': {
defaultExtension: 'ts'
}
'build/es6': { defaultExtension: 'js' },
'src': { defaultExtension: 'ts' },

'@angular/core': { main: 'index.js', defaultExtension: 'js' },
'@angular/compiler': { main: 'index.js', defaultExtension: 'js' },
'@angular/common': { main: 'index.js', defaultExtension: 'js' },
'@angular/http': { main: 'index.js', defaultExtension: 'js' },
'@angular/testing': { main: 'index.js', defaultExtension: 'js' },
'@angular/platform-browser': { main: 'index.js', defaultExtension: 'js' },
'@angular/platform-browser-dynamic': { main: 'index.js', defaultExtension: 'js' }
}
});
29 changes: 20 additions & 9 deletions files.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,28 @@ routerFiles = {

// Returns necessary files for a specific version of angular
angular: function(version) {
return [
'lib/angular-' + version + '/angular.js',
'lib/angular-' + version + '/angular-mocks.js',
'lib/angular-' + version + '/angular-animate.js'
];
if (version && version[0] === '1') {
return [
'lib/angular-' + version + '/angular.js',
'lib/angular-' + version + '/angular-mocks.js',
'lib/angular-' + version + '/angular-animate.js'
];
}

return [];
},

// This returns a Karma 'files configuration' for the files served by the Karma web server
// http://karma-runner.github.io/0.8/config/files.html
karmaServedFiles: function(version) {
return routerFiles.angular(version).map(function (pattern) {
/**
* This returns a Karma 'files configuration'.
* http://karma-runner.github.io/0.8/config/files.html
*
* Specifies which files can be served by the Karma web server
*
* included: true -- files that are always served to the browser (like <script> tag)
* included: false -- files *available to be served* by karma, for instance via require()
*/
karmaServedFiles: function(ngVersion) {
return routerFiles.angular(ngVersion).map(function (pattern) {
return { watched: false, included: true, nocache: true, pattern: pattern };
}).concat([
{ watched: true, included: false, nocache: true, pattern: 'src/**/*.ts' },
Expand Down
28 changes: 24 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@
"name": "ui-router",
"description": "State-based routing for Javascript",
"version": "1.0.0-alpha.5",
"scripts": {},
"scripts": {
"test": "npm run test:core && npm run test:ng1",
"test:watch": "node_modules/watch/cli.js 'npm run test' src test",

"test:core": "karma start config/karma.core.js",
"test:core:debug": "karma start config/karma.core.js --singleRun=false --browsers=Chrome --autoWatch=true --autoWatchInterval=1",

"test:ng1": "karma start config/karma.ng15.js",
"test:ng1:debug": "karma start config/karma.ng15.js --singleRun=false --browsers=Chrome --autoWatch=true --autoWatchInterval=1",

"test:ng12": "karma start config/karma.ng12.js",
"test:ng13": "karma start config/karma.ng13.js",
"test:ng14": "karma start config/karma.ng14.js",
"test:ng15": "karma start config/karma.ng15.js",
"test:integrate": "npm run test:core && npm run test:ng12 && npm run test:ng13 && npm run test:ng14 && npm run test:ng15"
},
"homepage": "http://angular-ui.github.com/ui-router",
"contributors": [
{
Expand Down Expand Up @@ -46,9 +61,8 @@
"@angular/core": "=2.0.0-rc.1",
"@angular/platform-browser": "=2.0.0-rc.1",
"@angular/platform-browser-dynamic": "=2.0.0-rc.1",
"rxjs": "=5.0.0-beta.6",
"zone.js": "=0.6.12",
"babel-core": "^5.8.14",
"clone": "^1.0.2",
"conventional-changelog": "^1.1.0",
"conventional-changelog-cli": "^1.1.1",
"es6-module-loader": "^0.17.3",
Expand All @@ -70,22 +84,28 @@
"jsdoc": "git://github.com/jsdoc3/jsdoc.git#v3.2.2",
"karma": "~0.12.0",
"karma-chrome-launcher": "~0.1.0",
"karma-coverage": "^0.5.3",
"karma-jasmine": "^0.3.8",
"karma-phantomjs-launcher": "~0.1.0",
"karma-script-launcher": "~0.1.0",
"karma-systemjs": "^0.7.2",
"load-grunt-tasks": "~0.4.0",
"lodash": "^4.5.1",
"parallelshell": "^2.0.0",
"phantomjs-polyfill": "0.0.1",
"reflect-metadata": "=0.1.2",
"remap-istanbul": "^0.6.3",
"rxjs": "=5.0.0-beta.6",
"shelljs": "~0.6.0",
"systemjs": "^0.18.4",
"ts-loader": "^0.8.1",
"tslint": "=2.5.0",
"typedoc": "git://github.com/christopherthielen/typedoc.git#v0.3-uirouter",
"typescript": "~1.8.0",
"watch": "^0.18.0",
"webpack": "1.x",
"webpack-dev-server": "1.x",
"yargs": "^4.2.0"
"yargs": "^4.2.0",
"zone.js": "=0.6.12"
}
}
2 changes: 1 addition & 1 deletion src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ export class UIRouterGlobals {

transitionService.onBefore({}, ['$transition$', beforeNewTransition]);
}
}
}
4 changes: 4 additions & 0 deletions src/state/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import {ParamDeclaration} from "../params/interface";
import {State} from "./stateObject";
import {ViewContext} from "../view/interface";
import {IInjectable} from "../common/common";
import {Transition} from "../transition/transition";

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

export interface TransitionPromise extends Promise<State> {
transition: Transition;
}

/**
* Base interface for [[Ng1ViewDeclaration]] and [[Ng2ViewDeclaration]]
Expand Down
8 changes: 4 additions & 4 deletions src/state/stateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {TransitionService, defaultTransOpts} from "../transition/transitionServi
import {Rejection} from "../transition/rejectFactory";
import {Transition} from "../transition/transition";

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

/** Factory method for creating a TargetState */
target(identifier: StateOrName, params: ParamsOrArray, options: TransitionOptions = {}): TargetState {
target(identifier: StateOrName, params?: ParamsOrArray, options: TransitionOptions = {}): TargetState {
// If we're reloading, find the state object to reload from
if (isObject(options.reload) && !(<any>options.reload).name)
throw new Error('Invalid reload state object');
Expand Down Expand Up @@ -268,7 +268,7 @@ export class StateService {
* @returns {promise} A promise representing the state of the new transition. See
* {@link ui.router.state.$state#methods_go $state.go}.
*/
transitionTo(to: StateOrName, toParams: RawParams = {}, options: TransitionOptions = {}): Promise<State> {
transitionTo(to: StateOrName, toParams: RawParams = {}, options: TransitionOptions = {}): TransitionPromise {
let transHistory = this.globals.transitionHistory;
options = defaults(options, defaultTransOpts);
options = extend(options, { current: transHistory.peekTail.bind(transHistory)});
Expand Down
37 changes: 0 additions & 37 deletions test/compat/matchers.ts

This file was deleted.

Loading

0 comments on commit b3d3b56

Please sign in to comment.