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

Commit 1be698c

Browse files
authored
chore(testing): karma config files support multiple builtPaths (#2917)
* karma.config + karma-test-shim can handle multiple spec source paths; see quickstart issue: angular/quickstart#294 * cosmetic `karma.config.js` changes
1 parent d9c1054 commit 1be698c

File tree

3 files changed

+40
-33
lines changed

3 files changed

+40
-33
lines changed

public/docs/_examples/testing/ts/karma-test-shim.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.
77

88
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
99

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

1215
__karma__.loaded = function () { };
1316

@@ -19,8 +22,12 @@ function isSpecFile(path) {
1922
return /\.spec\.(.*\.)?js$/.test(path);
2023
}
2124

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

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

public/docs/_examples/testing/ts/karma.conf.js

+26-31
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
// #docregion
22
module.exports = function(config) {
33

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

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

1111
config.set({
1212
basePath: '',
1313
frameworks: ['jasmine'],
14+
1415
plugins: [
1516
require('karma-jasmine'),
1617
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
18+
require('karma-jasmine-html-reporter')
1919
],
2020

21+
client: {
22+
builtPaths: [appSrcBase, testingBase], // add more spec base paths as needed
23+
clearContext: false // leave Jasmine Spec Runner output visible in browser
24+
},
25+
2126
customLaunchers: {
2227
// From the CLI. Not used here but interesting
2328
// chrome setup for travis CI using chromium
@@ -26,6 +31,7 @@ module.exports = function(config) {
2631
flags: ['--no-sandbox']
2732
}
2833
},
34+
2935
files: [
3036
// System.js for module loading
3137
'node_modules/systemjs/dist/system.src.js',
@@ -49,28 +55,28 @@ module.exports = function(config) {
4955

5056
// Paths loaded via module imports:
5157
// Angular itself
52-
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
53-
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},
58+
{ pattern: 'node_modules/@angular/**/*.js', included: false, watched: false },
59+
{ pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false },
5460

55-
{pattern: 'systemjs.config.js', included: false, watched: false},
56-
{pattern: 'systemjs.config.extras.js', included: false, watched: false},
57-
'karma-test-shim.js',
61+
{ pattern: 'systemjs.config.js', included: false, watched: false },
62+
{ pattern: 'systemjs.config.extras.js', included: false, watched: false },
63+
'karma-test-shim.js', // optionally extend SystemJS mapping e.g., with barrels
5864

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

6369

6470
// Asset (HTML & CSS) paths loaded via Angular's component compiler
6571
// (these paths need to be rewritten, see proxies section)
66-
{pattern: appBase + '**/*.html', included: false, watched: true},
67-
{pattern: appBase + '**/*.css', included: false, watched: true},
72+
{ pattern: appBase + '**/*.html', included: false, watched: true },
73+
{ pattern: appBase + '**/*.css', included: false, watched: true },
6874

6975
// Paths for debugging with source maps in dev tools
70-
{pattern: appSrcBase + '**/*.ts', included: false, watched: false},
71-
{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}
76+
{ pattern: appSrcBase + '**/*.ts', included: false, watched: false },
77+
{ pattern: appBase + '**/*.js.map', included: false, watched: false },
78+
{ pattern: testingSrcBase + '**/*.ts', included: false, watched: false },
79+
{ pattern: testingBase + '**/*.js.map', included: false, watched: false}
7480
],
7581

7682
// Proxied base paths for loading assets
@@ -81,18 +87,7 @@ module.exports = function(config) {
8187

8288
exclude: [],
8389
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-
},
90+
reporters: ['progress', 'kjhtml'],
9691

9792
port: 9876,
9893
colors: true,

public/docs/ts/latest/guide/change-log.jade

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ block includes
55
The Angular documentation is a living document with continuous improvements.
66
This log calls attention to recent significant changes.
77

8+
## Testing: karma file updates (2016-11-30)
9+
* karma.config + karma-test-shim can handle multiple spec source paths;
10+
see quickstart issue: [angular/quickstart#294](https://github.com/angular/quickstart/issues/294)
11+
* Displays Jasmine Runner output in the karma-launched browser
12+
813
## QuickStart Rewrite (2016-11-18)
914
The QuickStart is completely rewritten so that it actually is quick.
1015
It references a minimal "Hello Angular" app running in Plunker.

0 commit comments

Comments
 (0)