-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): karma integration and unit test sample
Closes #10
- Loading branch information
Showing
5 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Error.stackTraceLimit = Infinity; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; | ||
|
||
__karma__.loaded = function() {}; | ||
|
||
System.config({ | ||
packages: { | ||
'base/dist/app': { | ||
defaultExtension: false, | ||
format: 'register', | ||
map: Object.keys(window.__karma__.files) | ||
.filter(onlyAppFiles) | ||
.reduce(function(pathsMapping, appPath) { | ||
var moduleName = appPath.replace(/^\/base\/dist\/app\//, './').replace(/\.js$/, ''); | ||
pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath] | ||
return pathsMapping; | ||
}, {}) | ||
} | ||
} | ||
}); | ||
|
||
System.import('angular2/src/core/dom/browser_adapter').then(function(browser_adapter) { | ||
// TODO: once beta is out we should change this code to use a "test platform" | ||
browser_adapter.BrowserDomAdapter.makeCurrent(); | ||
}).then(function() { | ||
return Promise.all( | ||
Object.keys(window.__karma__.files) | ||
.filter(onlySpecFiles) | ||
.map(function(moduleName) { | ||
return System.import(moduleName); | ||
})); | ||
}).then(function() { | ||
__karma__.start(); | ||
}, function(error) { | ||
__karma__.error(error.stack || error); | ||
}); | ||
|
||
function onlyAppFiles(filePath) { | ||
return /^\/base\/dist\/app\/(?!spec)([a-z0-9]+)\.js$/.test(filePath); | ||
} | ||
|
||
function onlySpecFiles(path) { | ||
return /\.spec\.js$/.test(path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module.exports = function(config) { | ||
config.set({ | ||
basePath: '', | ||
frameworks: ['jasmine'], | ||
files: [ | ||
{pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true}, | ||
{pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true}, | ||
{pattern: 'node_modules/angular2/bundles/testing.js', included: true, watched: true}, | ||
|
||
{pattern: 'karma-test-shim.js', included: true, watched: true}, | ||
|
||
// paths loaded via module imports | ||
{pattern: 'dist/**/*.js', included: false, watched: true}, | ||
|
||
// paths loaded via Angular's component compiler | ||
// (these paths need to be rewritten, see proxies section) | ||
{pattern: 'dist/**/*.html', included: false, watched: true}, | ||
{pattern: 'dist/**/*.css', included: false, watched: true}, | ||
|
||
// paths to support debugging with source maps in dev tools | ||
{pattern: 'dist/**/*.ts', included: false, watched: false}, | ||
{pattern: 'dist/**/*.js.map', included: false, watched: false} | ||
], | ||
proxies: { | ||
// required for component assests fetched by Angular's compiler | ||
"/app/": "/base/dist/app/" | ||
}, | ||
exclude: [], | ||
preprocessors: {}, | ||
reporters: ['progress'], | ||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: true, | ||
browsers: ['Chrome'], | ||
singleRun: false | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {describe, it, expect, beforeEachProviders, inject} from 'angular2/testing'; | ||
import {<%= jsComponentName %>App} from '../app/<%= htmlComponentName %>'; | ||
|
||
beforeEachProviders(() => [<%= jsComponentName %>App]); | ||
|
||
describe('App: <%= jsComponentName %>', () => { | ||
it('should have the `defaultMeaning` as 42', inject([<%= jsComponentName %>App], (app) => { | ||
expect(app.defaultMeaning).toBe(42); | ||
})); | ||
|
||
describe('#meaningOfLife', () => { | ||
it('should get the meaning of life', inject([<%= jsComponentName %>App], (app) => { | ||
expect(app.meaningOfLife()).toBe('The meaning of life is 42'); | ||
expect(app.meaningOfLife(22)).toBe('The meaning of life is 22'); | ||
})); | ||
}); | ||
|
||
it('should be almost passing', function() { | ||
expect(1 + 1).toBe(1); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters