Skip to content

Commit

Permalink
Merge pull request #29 from unexpectedjs/fix/unsupportOldNode
Browse files Browse the repository at this point in the history
Unsupport node versions < 6
  • Loading branch information
papandreou authored Jan 1, 2019
2 parents 794d28e + 798a3a6 commit 76e57c7
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 47 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ module.exports = {
],
env: {
es6: false
},
parserOptions: null
}
};
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
- "6"
- "8"
- "10"
Expand Down
5 changes: 3 additions & 2 deletions lib/UnexpectedMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ UnexpectedMarkdown.prototype.toHtml = function (options, cb) {
this.getSnippets(options, passError(cb, function (snippets) {
var index = 0;
var renderer = new marked.Renderer();
renderer.code = function (code, blockInfoString, escaped) {
renderer.code = function (code) {
var snippet = snippets.get(index);
var previousSnippet = snippets.get(index - 1);
index += 1;
Expand Down Expand Up @@ -94,6 +94,7 @@ UnexpectedMarkdown.prototype.getSnippets = function (options, cb) {
if (this.snippets) {
cb(null, this.snippets);
} else {
// eslint-disable-next-line handle-callback-err
Snippets.fromMarkdown(this.content, options, function (err, snippets) {
that.snippets = snippets;
cb(null, snippets);
Expand All @@ -105,7 +106,7 @@ UnexpectedMarkdown.prototype.withUpdatedExamples = function (options, cb) {
var content = this.content;
this.getSnippets(options, passError(cb, function (snippets) {
var index = 0;
var updateContent = content.replace(snippetRegexp, function ($0, lang, code) {
var updateContent = content.replace(snippetRegexp, function ($0, lang) {
var currentIndex = index;
index += 1;
var snippet = snippets.get(currentIndex);
Expand Down
4 changes: 2 additions & 2 deletions lib/convertMarkdownToMocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ module.exports = function (mdSrc, fileName) {
var separator = '\n//---------------------um-separator---------------------\n';
var transpiledCode = transpile(preambleSeparator + codeBlocks.map(function (codeBlock) {
return codeBlock.flags.async
? '(function unexpectedMarkdownScope() {' +
? '(function unexpectedMarkdownScope() {' +
codeBlock.code +
'})("unexpectedMarkdownScope");'
: codeBlock.code;
: codeBlock.code;
}).join(separator));

var transpiledBlocks = transpiledCode
Expand Down
8 changes: 4 additions & 4 deletions lib/evaluateSnippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ module.exports = function (snippets, options, cb) {
if (exampleSnippets.length) {
var codeForTranspilation = preambleSeparator + exampleSnippets.map(function (snippet) {
return snippet.flags.async
? '(function () {' + snippet.code + '})();'
: snippet.code;
? '(function () {' + snippet.code + '})();'
: snippet.code;
}).join(separator);

var transpiledCode = transpile(codeForTranspilation);
Expand All @@ -92,8 +92,8 @@ module.exports = function (snippets, options, cb) {
if (snippet.flags.async) {
var promise = vm.runInThisContext(
hasBabel
? snippet.code
: '(function () {' + snippet.code + '})();'
? snippet.code
: '(function () {' + snippet.code + '})();'
);
if (!isPromise(promise)) {
throw new Error('Async code block did not return a promise or throw\n' + snippet.code);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"source-map-support": "^0.5.9"
},
"devDependencies": {
"eslint": "^2.13.1",
"eslint-config-onelint": "^1.2.0",
"mocha": "^2.2.5",
"eslint": "^5.11.1",
"eslint-config-onelint": "^4.0.0",
"mocha": "^5.2.0",
"unexpected": "^10.40.0"
},
"author": "Sune Simonsen",
Expand Down
50 changes: 25 additions & 25 deletions test/UnexpectedMarkdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ describe('UnexpectedMarkdown', function () {
var markdown;
beforeEach(function () {
markdown = new UnexpectedMarkdown([
"Asserts deep equality.",
"",
"```javascript",
'Asserts deep equality.',
'',
'```javascript',
"expect({ a: 'b' }, 'to equal', { a: 'b' });",
"var now = new Date();",
'var now = new Date();',
"expect(now, 'to equal', now);",
"expect(now, 'to equal', new Date(now.getTime()));",
"expect({ now: now }, 'to equal', { now: now });",
"```",
"",
"For a lot of types a failing equality test results in a nice",
"diff. Below you can see an object diff.",
"",
"```javascript",
'```',
'',
'For a lot of types a failing equality test results in a nice',
'diff. Below you can see an object diff.',
'',
'```javascript',
"expect({ text: 'foo!' }, 'to equal', { text: 'f00!' });",
"```",
"",
"```output",
"Missing output",
"```"
'```',
'',
'```output',
'Missing output',
'```'
].join('\n'));
});

Expand All @@ -44,12 +44,12 @@ describe('UnexpectedMarkdown', function () {

it('syntax highlight examples', function () {
return expect(htmlPromise, 'when fulfilled',
'to contain', '<span style="color: #000000">expect</span>');
'to contain', '<span style="color: #000000">expect</span>');
});

it('outputs evaluated examples', function () {
return expect(htmlPromise, 'when fulfilled',
'to contain', '<span style="background-color: green; color: white">f00</span>');
'to contain', '<span style="background-color: green; color: white">f00</span>');
});
});

Expand All @@ -69,16 +69,16 @@ describe('UnexpectedMarkdown', function () {

it('produces a markdown where the examples has been updated', function () {
return expect(updatedMarkdownPromise, 'when fulfilled', 'to contain', [
"```output",
'```output',
"expected { text: 'foo!' } to equal { text: 'f00!' }",
"",
"{",
'',
'{',
" text: 'foo!' // should equal 'f00!'",
" //",
" // -foo!",
" // +f00!",
"}",
"```"
' //',
' // -foo!',
' // +f00!',
'}',
'```'
].join('\n'));
});
});
Expand Down
16 changes: 10 additions & 6 deletions test/convertMarkdownToMocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ var synchronousSuccessfulSnippet =
var returningSuccessfulSnippet =
"var blah = 'abc';\n" +
"if (blah === 'abc') {\n" +
" return expect.promise(function (resolve, reject) {\n" +
" setImmediate(resolve);\n" +
" });\n" +
"} else {\n" +
" return 456;\n" +
"}\n";
' return expect.promise(function (resolve, reject) {\n' +
' setImmediate(resolve);\n' +
' });\n' +
'} else {\n' +
' return 456;\n' +
'}\n';

var synchronousThrowingSnippet =
"var bar = 'abc';\n" +
Expand Down Expand Up @@ -211,6 +211,7 @@ describe('convertMarkdownToMocha', function () {
} else {
return endOfExample1();
}
// eslint-disable-next-line handle-callback-err
function endOfExample1(err) {
var __returnValue2;
example2: try {
Expand Down Expand Up @@ -373,6 +374,7 @@ describe('convertMarkdownToMocha', function () {
} else {
return endOfExample1();
}
// eslint-disable-next-line handle-callback-err
function endOfExample1(err) {
var __returnValue2;
example2: try {
Expand Down Expand Up @@ -449,6 +451,7 @@ describe('convertMarkdownToMocha', function () {
} else {
return endOfExample1();
}
// eslint-disable-next-line handle-callback-err
function endOfExample1(err) {
var __returnValue2;
example2: try {
Expand Down Expand Up @@ -525,6 +528,7 @@ describe('convertMarkdownToMocha', function () {
} else {
return endOfExample1();
}
// eslint-disable-next-line handle-callback-err
function endOfExample1(err) {
expect = unexpected.clone();
var __returnValue2;
Expand Down

0 comments on commit 76e57c7

Please sign in to comment.