Skip to content

Commit

Permalink
Make evaluation a method on snippets.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke committed Dec 31, 2019
1 parent cfcb869 commit 7ff820a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
21 changes: 12 additions & 9 deletions lib/Snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ function Snippets(snippets) {
this.items = snippets;
}

Snippets.prototype.evaluate = function(options, cb) {
evaluateSnippets(
this.items,
options,
passError(cb, () => {
cb(null, this);
})
);
};

Snippets.prototype.get = function(index) {
return this.items[index];
};
Expand Down Expand Up @@ -38,14 +48,7 @@ Snippets.prototype.getTests = function() {
};

module.exports = {
fromMarkdown: function(markdown, options, cb) {
var snippets = extractSnippets(markdown);
evaluateSnippets(
snippets,
options,
passError(cb, function() {
cb(null, new Snippets(snippets));
})
);
fromMarkdown: function(markdown) {
return new Snippets(extractSnippets(markdown));
}
};
5 changes: 4 additions & 1 deletion lib/UnexpectedMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ UnexpectedMarkdown.prototype.getSnippets = function(options, cb) {
cb(null, this.snippets);
} else {
// eslint-disable-next-line handle-callback-err
Snippets.fromMarkdown(this.content, options, function(err, snippets) {
Snippets.fromMarkdown(this.content).evaluate(options, function(
err,
snippets
) {
that.snippets = snippets;
cb(null, snippets);
});
Expand Down
6 changes: 3 additions & 3 deletions lib/convertMarkdownToMocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var pathModule = require('path');
var esprima = require('esprima');
var escodegen = require('escodegen');
var extractSnippets = require('./extractSnippets');
var Snippets = require('./Snippets');
var locateBabelrc = require('./locateBabelrc');
var fs = require('fs');
var cleanStackTrace = require('./cleanStackTrace');
Expand Down Expand Up @@ -133,8 +133,8 @@ function countLinesUntilIndex(text, untilIndex) {

function findCodeBlocks(mdSrc) {
var codeBlocks = [];
const snippets = extractSnippets(mdSrc);
for (const codeBlock of snippets) {
const snippets = Snippets.fromMarkdown(mdSrc);
for (const codeBlock of snippets.items) {
codeBlock.lineNumber = 1 + countLinesUntilIndex(mdSrc, codeBlock.index);
if (codeBlock.lang === 'output') {
var lastJavaScriptBlock = codeBlocks[codeBlocks.length - 1];
Expand Down

0 comments on commit 7ff820a

Please sign in to comment.