Draft test shell with karma and jasmine - adding missing files

This commit is contained in:
knsv
2014-11-04 07:50:58 +01:00
parent 2a92168a0d
commit f35e43c512
4 changed files with 136 additions and 0 deletions

66
conf/karma.conf.js Normal file
View File

@@ -0,0 +1,66 @@
// Karma configuration
// Generated on Mon Nov 03 2014 07:53:38 GMT+0100 (CET)
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
browserify: {
watch: true
},
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'vendor/requirejs/require.js',
'vendor/jasmine/lib/jasmine-core/jasmine.js',
'src/**/*.spec.js',
'test/test-main.js'
],
// list of files to exclude
exclude: [],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};

View File

@@ -0,0 +1,28 @@
/**
* Created by knut on 14-11-03.
*/
define('parser/mermaid.spec',['parser/scope','parser/mermaid.js'],function(scope, p){
console.log('here:'+p);
describe('when parsing ',function(){
beforeEach(function(){
console.log('here');
p.yy = scope;
});
it('should',function(){
var res = p.parse('A-->B;');
expect(p.yy.getLinks()).toBe('apa');
})
});
describe('just checking', function() {
it('works for app', function () {
expect(2).toBe(2);
});
});
});

18
src/parser/scope.js Normal file
View File

@@ -0,0 +1,18 @@
/**
* Created by knut on 14-11-03.
*/
define('parser/scope',function() {
var scope = {
addVertex: function (id, text, type, style) {
console.log('Got node ' + id + ' ' + type + ' ' + text + ' styles: ' + JSON.stringify(style));
},
addLink: function (start, end, type, linktext) {
console.log('Got link from ' + start + ' to ' + end + ' type:' + type.type + ' linktext:' + linktext);
},
getLinks: function () {
return 'apa';
}
};
return scope;
});

24
test/test-main.js Normal file
View File

@@ -0,0 +1,24 @@
/**
* Created by knut on 14-11-03.
*/
var tests = [];
for (var file in window.__karma__.files) {
if (window.__karma__.files.hasOwnProperty(file)) {
if (/spec\.js$/.test(file)) {
var file2 = file.substr(10,file.length-13);
console.log(file2);
tests.push(file2);
}
}
}
require.config({
// Karma serves files from '/base'
baseUrl: '/base/src',
// ask Require.js to load these files (all our tests)
deps: tests,
// start test run, once Require.js is done
callback: window.__karma__.start
});