Skip to content

Commit

Permalink
test(*): Switch karma from SystemJS to webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Oct 23, 2016
1 parent 10fb103 commit 72b67cc
Show file tree
Hide file tree
Showing 25 changed files with 123 additions and 97 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ node_js:
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- npm install -g karma
- npm install -g typescript
- npm install -g yarn
- npm install -g yarn karma typescript
- ./nodeserver.sh > /dev/null &

matrix:
Expand All @@ -26,6 +24,7 @@ env:

script:
- echo "CORE_BRANCH = x${CORE_BRANCH}x";
# Fetch and build the ui-router-core branch from github, then install it
- >
if [ "x${CORE_BRANCH}x" != "xx" ] ; then
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 ;
Expand All @@ -35,7 +34,7 @@ script:
sudo: false

git:
depth: 10
depth: 3

notifications:
slack: angularbuddies:b6leQM9gkBCW0S7MNDsELpqU
40 changes: 15 additions & 25 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,20 @@ function karmaServedFiles(ngVersion) {
'test/angular/' + version + '/angular.js',
'test/angular/' + version + '/angular-mocks.js',
'test/angular/' + version + '/angular-animate.js',
'test/util/ng1.systemjs.adapter.js'
];
}

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

var srcFiles = [
{ watched: true, included: false, nocache: true, pattern: 'src/**/*.ts' },
];

var testFiles = [
{ watched: true, included: false, nocache: true, pattern: 'test/**/*.ts' },
{ watched: true, included: false, nocache: true, pattern: 'test/**/*.js' }
];

return [].concat(angularFiles).concat(srcFiles).concat(testFiles);
return angularFiles.concat('test/index.js');
}

var webpackConfig = require('./webpack.config.js');
webpackConfig.entry = {};
webpackConfig.plugins = [];

module.exports = function(config) {
var ngVersion = config.ngversion || "1.5.0";

Expand All @@ -63,29 +57,25 @@ module.exports = function(config) {
// 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: webpackConfig,

/* Files *available to be served* by karma, i.e., anything that will be require()'d */
files: karmaServedFiles(ngVersion),
exclude: [],
systemjs: {
// Set up systemjs paths
configFile: 'karma.system.config.js',

files: [
'src/**/*.ts',
'node_modules/ui-router-core/lib/**/*'
],

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

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

});
};
19 changes: 0 additions & 19 deletions karma.system.config.js

This file was deleted.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.2",
"karma-script-launcher": "~0.1.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-systemjs": "^0.7.2",
"karma-webpack": "^1.8.0",
"lodash": "^4.5.1",
"remap-istanbul": "^0.6.3",
"shelljs": "^0.7.0",
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('./util');

require('../src/ng1');

var testsContext = require.context(".", true, /Spec$/);
testsContext.keys().forEach(testsContext);
5 changes: 5 additions & 0 deletions test/ng1StateBuilderSpec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/// <reference path='../node_modules/@types/angular/index.d.ts' />
/// <reference path='../node_modules/@types/angular-mocks/index.d.ts' />
/// <reference path='../node_modules/@types/jasmine/index.d.ts' />

import {StateBuilder, StateMatcher, ng1ViewsBuilder} from "../src/ng1";
import {Resolvable} from "ui-router-core";
declare var inject;

describe('Ng1 StateBuilder', function() {
var builder, matcher, urlMatcherFactoryProvider: any = {
Expand Down
24 changes: 14 additions & 10 deletions test/resolveSpec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import "./util/testUtilsNg1.js";
declare var resolvedValue, resolvedError, caught;
/// <reference path='../node_modules/@types/angular/index.d.ts' />
/// <reference path='../node_modules/@types/angular-mocks/index.d.ts' />
/// <reference path='../node_modules/@types/jasmine/index.d.ts' />
/// <reference path='./util/matchers.types.d.ts' />

import "./util/matchers.ts";

import {
ResolveContext, State, PathNode, omit, pick, extend, forEach
} from "../src/ng1";
import * as angular from "angular";
import "./util/matchers";
import "./util/testUtilsNg1";

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

let module = angular.mock.module;
let module = angular['mock'].module;
///////////////////////////////////////////////

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

angular.forEach(copy, stateDef => {
angular.forEach(copy, (stateDef: StateDeclaration) => {
if (stateDef.name) $stateProvider.state(stateDef);
});
}));
Expand Down
3 changes: 2 additions & 1 deletion test/stateDirectivesSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var module = angular.mock.module;
var uiRouter = require("angular-ui-router");
var uiRouter = require("../src/ng1");
var obj = require('./util/testUtilsNg1').obj;

describe('uiStateRef', function() {

Expand Down
8 changes: 7 additions & 1 deletion test/stateEventsSpec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
var module = angular.mock.module;
var uiRouter = require("angular-ui-router");
var uiRouter = require("../src/ng1");
var stateEvents = require("../src/ng1/legacy/stateEvents.ts");
var decorateExceptionHandler = require("./util/testUtilsNg1").decorateExceptionHandler;
var obj = require('./util/testUtilsNg1').obj;

var resolvedValue = require('./util/testUtilsNg1').resolvedValue;
var resolvedError = require('./util/testUtilsNg1').resolvedError;
var caught = require('./util/testUtilsNg1').caught;

describe('UI-Router v0.2.x $state events', function () {
var $injector, stateProvider;
Expand Down
2 changes: 1 addition & 1 deletion test/stateFiltersSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var module = angular.mock.module;
var uiRouter = require("angular-ui-router");
var uiRouter = require("../src/ng1");

describe('isState filter', function() {
beforeEach(module('ui.router'));
Expand Down
7 changes: 5 additions & 2 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
var module = angular.mock.module;
var uiRouter = require("angular-ui-router");
var uiRouter = require("../src/ng1");
var extend = uiRouter.extend;
var forEach = uiRouter.forEach;
var services = uiRouter.services;
var UrlMatcher = uiRouter.UrlMatcher;

var obj = require('./util/testUtilsNg1').obj;
var resolvedError = require('./util/testUtilsNg1').resolvedError;
var resolvedValue = require('./util/testUtilsNg1').resolvedValue;
var html5Compat = require('./util/testUtilsNg1').html5Compat;

describe('state', function () {

Expand Down
2 changes: 1 addition & 1 deletion test/templateFactorySpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var module = angular.mock.module;
var uiRouter = require("angular-ui-router");
var uiRouter = require("../src/ng1");

describe('templateFactory', function () {

Expand Down
2 changes: 1 addition & 1 deletion test/urlMatcherFactorySpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var module = angular.mock.module;
var uiRouter = require("angular-ui-router");
var uiRouter = require("../src/ng1");
var Param = uiRouter.Param;
var ParamTypes = uiRouter.ParamTypes;
var UrlMatcher = uiRouter.UrlMatcher;
Expand Down
20 changes: 14 additions & 6 deletions test/urlRouterSpec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import ILocationService = angular.ILocationService;
declare var html5Compat;
/// <reference path='../node_modules/@types/angular/index.d.ts' />
/// <reference path='../node_modules/@types/angular-mocks/index.d.ts' />
/// <reference path='../node_modules/@types/jasmine/index.d.ts' />

import * as angular from "angular";
import {ILocationService, ILocationProvider} from "angular";
import "./util/matchers";
import { html5Compat } from './util/testUtilsNg1';
declare var inject;

import {UrlMatcher, UrlMatcherFactory, services, UrlRouterProvider, UrlRouter, StateService} from "../src/ng1";
import ILocationProvider = angular.ILocationProvider;

var module = angular.mock.module;
var module = angular['mock'].module;

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

$urp.rule(function ($injector, $location) {
log.push($location.path());
return null;
});

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

$urp.rule(function ($injector, $location) {
var path = $location.path();
if (!/baz/.test(path)) return false;
if (!/baz/.test(path)) return;
return path.replace('baz', 'b4z');
}).when('/foo/:param', function($match) {
match = ['/foo/:param', $match];
Expand Down Expand Up @@ -120,7 +128,7 @@ describe("UrlRouter", function () {
validates: function() {},
parameter: function() {},
parameters: function() {}
},
} as any as UrlMatcher,
handler: function() {}
};

Expand Down
5 changes: 5 additions & 0 deletions test/util/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path='./matchers.types.d.ts' />

export * from './matchers'
export * from './testUtils'
export * from './testUtilsNg1'
8 changes: 6 additions & 2 deletions test/util/matchers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/// <reference path='../typings/jasmine/jasmine.d.ts' />
/// <reference path='../../node_modules/@types/angular/index.d.ts' />
/// <reference path='../../node_modules/@types/angular-mocks/index.d.ts' />
/// <reference path='../../node_modules/@types/jasmine/index.d.ts' />
/// <reference path='./matchers.types.d.ts' />

import {equals} from "ui-router-core";
declare var testablePromise;
import {testablePromise} from "./testUtilsNg1";

beforeEach(function() {
jasmine.addMatchers(<any> {
Expand Down
7 changes: 7 additions & 0 deletions test/util/matchers.types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare namespace jasmine {
interface Matchers {
toEqualData(expected: any, expectationFailOutput?: any): boolean;
toEqualValues(expected: any, expectationFailOutput?: any): boolean;
toBeResolved(): boolean;
}
}
1 change: 0 additions & 1 deletion test/util/ng1.systemjs.adapter.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/util/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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
Loading

0 comments on commit 72b67cc

Please sign in to comment.