Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add basic unit-testing infrastructure with Karma
- Loading branch information
1 parent
127d11b
commit 780714d
Showing
7 changed files
with
105 additions
and
6 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
npm-debug.log | ||
node_modules | ||
dist |
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
- testing infrastructure | ||
- | ||
* testing infrastructure | ||
* finish first version of the pre-processor | ||
* calculate module path name | ||
* push options to the karma config configuration | ||
* how can I start all JS tests from System.register modules |
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,37 @@ | ||
var ts = require('typescript'); | ||
var path = require('path'); | ||
|
||
var createTypeScriptPreprocessor = function (args, config, logger) { | ||
|
||
var log = logger.create('preprocessor.typescript'); | ||
var projectBasePath = path.resolve(__dirname, '../..'); //TODO: OS-specific, path specific | ||
|
||
return function (content, file, done) { | ||
|
||
var baseRelativePath = path.relative(projectBasePath, file.originalPath); | ||
baseRelativePath = path.join('base', baseRelativePath); | ||
|
||
log.debug('Processing "%s".', file.originalPath); | ||
|
||
//TODO: pass those options from "outside" | ||
var compilerOptions = { | ||
module: ts.ModuleKind.System, | ||
experimentalDecorators: true | ||
}; | ||
|
||
var compileResult = ts.transpileModule(content, { | ||
compilerOptions: compilerOptions, | ||
moduleName: baseRelativePath.slice(0, -path.extname(baseRelativePath).length) | ||
}); | ||
|
||
//TODO: what happens if there is transpilation error? | ||
done(compileResult.outputText); //keys: [ 'outputText', 'diagnostics', 'sourceMapText' ] | ||
}; | ||
}; | ||
|
||
// PUBLISH DI MODULE | ||
module.exports = { | ||
'preprocessor:TypeScript': ['factory', createTypeScriptPreprocessor] | ||
}; | ||
|
||
//TODO: source-map support |
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,20 @@ | ||
// Cancel Karma's synchronous start, | ||
// we will call `__karma__.start()` later, once all the specs are loaded. | ||
__karma__.loaded = function() {}; | ||
|
||
// Import all the specs, execute their `main()` method and kick off Karma (Jasmine). | ||
Promise | ||
.all(Object.keys(window.__karma__.files) // All files served by Karma. | ||
.filter(onlySpecFiles) | ||
.map(function(path) { | ||
return System.import(path.slice(0, -3)); //TODO: hard-coded extension length | ||
})) | ||
.then(function() { | ||
__karma__.start(); | ||
}, function(error) { | ||
__karma__.error(error.stack || error); | ||
}); | ||
|
||
function onlySpecFiles(path) { | ||
return /spec\.ts$/.test(path); //TODO: hard-coded extension | ||
} |
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
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,14 @@ | ||
import {BsProgress} from '../../src/progress/progress'; | ||
|
||
describe('progress', () => { | ||
var progress; | ||
|
||
beforeEach(() => { | ||
progress = new BsProgress(); | ||
}); | ||
|
||
it('should calculate progress percent for default min = 0 / max = 100', () => { | ||
progress.value = 60; | ||
expect(progress.getPercentValue()).toBe(60); | ||
}); | ||
}); |