Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 3adfdf7

Browse files
committed
chore: test framework improvements, remove tsconfig exclude clause
* remove `exclude` clause from `tsconfig.json`; it was just confusing people * karma.config + karma-test-shim can handle multiple spec source paths (issue #294) * cosmetic `app.component.spec.ts` changes * cosmetic `karma.config.js` changes
1 parent ce8fcdc commit 3adfdf7

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ Upgraders: for a fresh start, consider running these commands
33
* `git clean -xdf`
44
* `npm install`
55

6+
<a name="0.2.18"></a>
7+
# 0.2.18 (2016-11-30)
8+
* remove `exclude` clause from `tsconfig.json`; it was just confusing people
9+
* karma.config + karma-test-shim can handle multiple spec source paths (issue #294)
10+
* cosmetic `app.component.spec.ts` changes
11+
* cosmetic `karma.config.js` changes
12+
613
<a name="0.2.17"></a>
714
# 0.2.17 (2016-11-16)
815
* Conform to updated QuickStart advice

app/app.component.spec.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
/* tslint:disable:no-unused-variable */
21
import { AppComponent } from './app.component';
32

43
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
54
import { By } from '@angular/platform-browser';
65
import { DebugElement } from '@angular/core';
76

8-
//////// SPECS /////////////
97
describe('AppComponent', function () {
108
let de: DebugElement;
119
let comp: AppComponent;
1210
let fixture: ComponentFixture<AppComponent>;
1311

1412
beforeEach(async(() => {
15-
TestBed.configureTestingModule({
13+
TestBed.configureTestingModule({
1614
declarations: [ AppComponent ]
1715
})
1816
.compileComponents();

karma-test-shim.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// #docregion
21
// /*global jasmine, __karma__, window*/
32
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.
43

@@ -7,7 +6,10 @@ Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.
76

87
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
98

10-
var builtPath = '/base/app/';
9+
// builtPaths: root paths for output ("built") files
10+
// get from karma.config.js, then prefix with '/base/' (default is 'app/')
11+
var builtPaths = (__karma__.config.builtPaths || ['app/'])
12+
.map(function(p) { return '/base/'+p;});
1113

1214
__karma__.loaded = function () { };
1315

@@ -19,8 +21,12 @@ function isSpecFile(path) {
1921
return /\.spec\.(.*\.)?js$/.test(path);
2022
}
2123

24+
// Is a "built" file if is JavaScript file in one of the "built" folders
2225
function isBuiltFile(path) {
23-
return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
26+
return isJsFile(path) &&
27+
builtPaths.reduce(function(keep, bp) {
28+
return keep || (path.substr(0, bp.length) === bp);
29+
}, false);
2430
}
2531

2632
var allSpecFiles = Object.keys(window.__karma__.files)

karma.conf.js

+17-23
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
// #docregion
21
module.exports = function(config) {
32

4-
var appBase = 'app/'; // transpiled app JS and map files
5-
var appSrcBase = 'app/'; // app source TS files
3+
var appBase = 'app/'; // transpiled app JS and map files
4+
var appSrcBase = 'app/'; // app source TS files
65
var appAssets = 'base/app/'; // component assets fetched by Angular's compiler
76

8-
var testBase = 'testing/'; // transpiled test JS and map files
9-
var testSrcBase = 'testing/'; // test source TS files
7+
var testingBase = 'testing/'; // transpiled test JS and map files
8+
var testingSrcBase = 'testing/'; // test source TS files
109

1110
config.set({
1211
basePath: '',
1312
frameworks: ['jasmine'],
13+
1414
plugins: [
1515
require('karma-jasmine'),
1616
require('karma-chrome-launcher'),
17-
require('karma-jasmine-html-reporter'), // click "Debug" in browser to see it
18-
require('karma-htmlfile-reporter') // crashing w/ strange socket error
17+
require('karma-jasmine-html-reporter') // click "Debug" in browser to see it
1918
],
2019

20+
client: {
21+
builtPaths: [appSrcBase, testingBase], // add more spec base paths as needed
22+
clearContext: false // leave Jasmine Spec Runner output visible in browser
23+
},
24+
2125
customLaunchers: {
2226
// From the CLI. Not used here but interesting
2327
// chrome setup for travis CI using chromium
@@ -26,6 +30,7 @@ module.exports = function(config) {
2630
flags: ['--no-sandbox']
2731
}
2832
},
33+
2934
files: [
3035
// System.js for module loading
3136
'node_modules/systemjs/dist/system.src.js',
@@ -54,11 +59,11 @@ module.exports = function(config) {
5459

5560
{ pattern: 'systemjs.config.js', included: false, watched: false },
5661
{ pattern: 'systemjs.config.extras.js', included: false, watched: false },
57-
'karma-test-shim.js',
62+
'karma-test-shim.js', // optionally extend SystemJS mapping e.g., with barrels
5863

5964
// transpiled application & spec code paths loaded via module imports
6065
{ pattern: appBase + '**/*.js', included: false, watched: true },
61-
{ pattern: testBase + '**/*.js', included: false, watched: true },
66+
{ pattern: testingBase + '**/*.js', included: false, watched: true },
6267

6368

6469
// Asset (HTML & CSS) paths loaded via Angular's component compiler
@@ -69,8 +74,8 @@ module.exports = function(config) {
6974
// Paths for debugging with source maps in dev tools
7075
{ pattern: appSrcBase + '**/*.ts', included: false, watched: false },
7176
{ pattern: appBase + '**/*.js.map', included: false, watched: false },
72-
{ pattern: testSrcBase + '**/*.ts', included: false, watched: false },
73-
{ pattern: testBase + '**/*.js.map', included: false, watched: false }
77+
{ pattern: testingSrcBase + '**/*.ts', included: false, watched: false },
78+
{ pattern: testingBase + '**/*.js.map', included: false, watched: false}
7479
],
7580

7681
// Proxied base paths for loading assets
@@ -81,18 +86,7 @@ module.exports = function(config) {
8186

8287
exclude: [],
8388
preprocessors: {},
84-
// disabled HtmlReporter; suddenly crashing w/ strange socket error
85-
reporters: ['progress', 'kjhtml'],//'html'],
86-
87-
// HtmlReporter configuration
88-
htmlReporter: {
89-
// Open this file to see results in browser
90-
outputFile: '_test-output/tests.html',
91-
92-
// Optional
93-
pageTitle: 'Unit Tests',
94-
subPageTitle: __dirname
95-
},
89+
reporters: ['progress', 'kjhtml'],
9690

9791
port: 9876,
9892
colors: true,

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"karma": "^1.3.0",
4747
"karma-chrome-launcher": "^2.0.0",
4848
"karma-cli": "^1.0.1",
49-
"karma-htmlfile-reporter": "^0.3.4",
5049
"karma-jasmine": "^1.0.2",
5150
"karma-jasmine-html-reporter": "^0.2.2",
5251
"protractor": "4.0.9",

tsconfig.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,5 @@
99
"lib": [ "es2015", "dom" ],
1010
"noImplicitAny": true,
1111
"suppressImplicitAnyIndexErrors": true
12-
},
13-
"exclude": [
14-
"node_modules/*",
15-
"**/*-aot.ts"
16-
]
12+
}
1713
}

0 commit comments

Comments
 (0)