Skip to content

Commit

Permalink
Fixed #9, test widgets weren't cleaned up on parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Azeirah committed Jun 30, 2015
1 parent 442490f commit 2936b34
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions editor/plugins/collectTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ var lineWidgets = [];
Moonchild.on('parse', function(ast) {
var tests = {};

_.invoke(lineWidgets, 'clear'); // Clear widgets from the last parse.
// Tell codemirror to clear all widgets, and remove all widget references.
// At every edit, all widgets are removed and then rerendered.
_.invoke(lineWidgets, 'clear');
lineWidgets = [];

if (!options.collectTests) return;

Expand All @@ -17,7 +20,7 @@ Moonchild.on('parse', function(ast) {

// Find functions that have tests, and run the tests.
ast.where({ 'type': 'FunctionDeclaration' }).each(function(node) {
if (node.id.name in tests) {
if (node.id.name in tests) {
var loc = esLocToCm(node.loc.start);
var el = createElement('div', { 'class': 'test-result' }, 'Tests');
var widget = codeMirror.addLineWidget(loc.line, el, { above: true });
Expand All @@ -31,6 +34,6 @@ Moonchild.on('parse', function(ast) {
result = true;
} catch(e) {}
el.classList.toggle('ok', !!result);
}
}
});
});

0 comments on commit 2936b34

Please sign in to comment.