Skip to content

Commit

Permalink
refactored createStartFn
Browse files Browse the repository at this point in the history
  • Loading branch information
bySabi committed Jul 10, 2016
1 parent f3fa3a5 commit df256f9
Showing 1 changed file with 57 additions and 60 deletions.
117 changes: 57 additions & 60 deletions src/adapter.js
Expand Up @@ -3,78 +3,75 @@ var finished = tapParser.finished;
var parser = tapParser.parser;

function createStartFn(tc) {
var numResults = 0;
var done = false;
var res = [];
var suite = [];
var startTime = new Date().getTime();
var parse_stream = parser();
return function(config) {
var numResults = 0;
var done = false;
var res = [];
var suite = '';
var startTime = new Date().getTime();
var parse_stream = parser();
var skip = /^# SKIP\s/;

parse_stream.on('comment', function(comment) {
// handle skipped test
if (skip.test(comment)) {
res.push({
description: comment.replace(skip, ''),
skipped: true
});
return;
}

// TODO: validate if comment is a test 'name'
suite = comment;
});

parse_stream.on('comment', function(comment) {
// handle skipped test
var skip = /^# SKIP\s{1,}/;
if (skip.test(comment)) {
parse_stream.on('assert', function(assertion) {
numResults++;
res.push({
description: comment.replace(skip, ''),
skipped: true,
description: assertion.name,
success: assertion.ok,
log: [JSON.stringify(assertion.diag || assertion, null, 2)],
suite: [suite],
time: new Date().getTime() - startTime
});
return;
}

// TODO: validate if comment is a test 'name'
suite = comment;
});

parse_stream.on('assert', function(assertion) {
numResults++;
res.push({
description: assertion.name,
success: assertion.ok,
log: [JSON.stringify(assertion.diag || assertion, null, 2)],
suite: [suite],
time: new Date().getTime() - startTime
});
});

parse_stream.on('complete', function(results) {
tc.info({ total: numResults });
for (var i = 0, len = res.length; i < len; i++) {
tc.result(res[i]);
}
tc.complete({
coverage: window.__coverage__
parse_stream.on('complete', function(results) {
tc.info({ total: numResults });
for (var i = 0, len = res.length; i < len; i++) {
tc.result(res[i]);
}
tc.complete({
coverage: window.__coverage__
});
});
});

// this part lifted from zuul
// https://github.com/defunctzombie/zuul/blob/master/frameworks/tape/client.js
// this part lifted from zuul
// https://github.com/defunctzombie/zuul/blob/master/frameworks/tape/client.js
var finished_stream = finished(function() {
done = true;
parse_stream.end();
});

var finished_stream = finished(function() {
done = true;
parse_stream.end();
});
var originalLog = console.log;
console.log = function () {
var msg = arguments[0];

var originalLog = console.log;
console.log = function () {
var msg = arguments[0];
// do not write in a closed WriteStream
if (!done) {
parse_stream.write(msg + '\n');
finished_stream.write(msg + '\n');
}

// do not write in a closed WriteStream
if (!done) {
parse_stream.write(msg + '\n');
finished_stream.write(msg + '\n');
// transfer log to original console,
// this shows the tap output in console
// and also let the user add console logs
if (typeof originalLog === 'function') {
return originalLog.apply(this, arguments);
}
}

// transfer log to original console,
// this shows the tap output in console
// and also let the user add console logs
if (typeof originalLog === 'function') {
return originalLog.apply(this, arguments);
}
};

return function(config) {
};
}
};

window.__karma__.start = createStartFn(window.__karma__);

0 comments on commit df256f9

Please sign in to comment.