Skip to content

Commit

Permalink
Merge pull request #124 from davidchambers/disharmony
Browse files Browse the repository at this point in the history
drop support for unmaintained versions of Node.js
  • Loading branch information
davidchambers authored Jun 17, 2020
2 parents a2c1573 + bb457e0 commit 67bde9e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repo-owner = davidchambers
repo-name = doctest
author-name = David Chambers <[email protected]>
source-files = lib/*.js
source-files = lib/*.js lib/*.mjs
version-tag-prefix =
9 changes: 2 additions & 7 deletions bin/doctest
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@

var path = require ('path');

var esmSupported = Number ((process.versions.node.split ('.'))[0]) >= 9;
var args = process.argv.slice (2);
var idx = args.indexOf ('--nodejs');
var flags = idx >= 0 && idx < args.length - 1;

require ('child_process')
.spawn (
process.execPath,
[].concat (esmSupported ? ['--experimental-modules'] : [])
[].concat (['--experimental-modules'])
.concat (flags ? args[idx + 1].split (/\s+/) : [])
.concat (['--',
path.resolve (__dirname,
'..',
'lib',
'command' + (esmSupported ? '.mjs' : '.js'))])
.concat (['--', path.resolve (__dirname, '..', 'lib', 'command.mjs')])
.concat (flags ? (args.slice (0, idx)).concat (args.slice (idx + 2))
: args),
{cwd: process.cwd (), env: process.env, stdio: [0, 1, 2]}
Expand Down
19 changes: 0 additions & 19 deletions lib/command.js

This file was deleted.

25 changes: 23 additions & 2 deletions lib/command.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import common from './common.js';
import doctest from './doctest.mjs';
import program from './program.js';

common.runDoctests (doctest, program);

// formatErrors :: Array String -> String
function formatErrors(errors) {
return (errors.map (function(s) { return 'error: ' + s + '\n'; })).join ('');
}

if (program.args.length === 0) {
process.stderr.write (formatErrors (['No files for doctesting provided']));
process.exit (1);
}

Promise.all (program.args.map (function(path) {
return (doctest (path, program)).then (function(results) {
return results.reduce (function(status, tuple) {
return tuple[0] ? status : 1;
}, 0);
});
})).then (function(statuses) {
process.exit (statuses.every (function(s) { return s === 0; }) ? 0 : 1);
}, function(err) {
process.stderr.write (formatErrors ([err.message]));
process.exit (1);
});
26 changes: 0 additions & 26 deletions lib/common.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
'use strict';


// formatErrors :: Array String -> String
exports.formatErrors = function(errors) {
return (errors.map (function(s) { return 'error: ' + s + '\n'; })).join ('');
};

// sanitizeFileContents :: String -> String
exports.sanitizeFileContents = function(contents) {
return contents.replace (/\r\n?/g, '\n').replace (/^#!.*/, '');
Expand All @@ -15,24 +10,3 @@ exports.sanitizeFileContents = function(contents) {
exports.unlines = function(lines) {
return lines.reduce (function(s, line) { return s + line + '\n'; }, '');
};

exports.runDoctests = function(doctest, program) {
if (program.args.length === 0) {
process.stderr.write (exports.formatErrors ([
'No files for doctesting provided'
]));
process.exit (1);
}
Promise.all (program.args.map (function(path) {
return (doctest (path, program)).then (function(results) {
return results.reduce (function(status, tuple) {
return tuple[0] ? status : 1;
}, 0);
});
})).then (function(statuses) {
process.exit (statuses.every (function(s) { return s === 0; }) ? 0 : 1);
}, function(err) {
process.stderr.write (exports.formatErrors ([err.message]));
process.exit (1);
});
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"type": "git",
"url": "git://github.com/davidchambers/doctest.git"
},
"engines": {
"node": ">=10.0.0"
},
"dependencies": {
"coffeescript": "1.12.x",
"commander": "2.20.x",
Expand Down
65 changes: 26 additions & 39 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ var Z = require ('sanctuary-type-classes');
var doctest = require ('..');


var esmSupported = Number ((process.versions.node.split ('.'))[0]) >= 9;


// unlines :: Array String -> String
function unlines(lines) {
return lines.reduce (function(s, line) { return s + line + '\n'; }, '');
Expand Down Expand Up @@ -62,7 +59,7 @@ function testCommand(command, expected) {
var stderr = '';
try {
stdout = execSync (
command + (esmSupported ? ' --nodejs --no-warnings' : ''),
command + ' --nodejs --no-warnings',
{encoding: 'utf8', stdio: 'pipe'}
);
} catch (err) {
Expand Down Expand Up @@ -211,43 +208,33 @@ testCommand ('bin/doctest --module commonjs lib/doctest.js', {
stderr: ''
});

if (esmSupported) {
testCommand ('bin/doctest --module esm test/esm/index.mjs', {
status: 0,
stdout: unlines ([
'running doctests in test/esm/index.mjs...',
'.'
]),
stderr: ''
});
testCommand ('bin/doctest --module esm test/esm/index.mjs', {
status: 0,
stdout: unlines ([
'running doctests in test/esm/index.mjs...',
'.'
]),
stderr: ''
});

testCommand ('bin/doctest --module esm test/esm/dependencies.mjs', {
status: 0,
stdout: unlines ([
'running doctests in test/esm/dependencies.mjs...',
'.'
]),
stderr: ''
});
testCommand ('bin/doctest --module esm test/esm/dependencies.mjs', {
status: 0,
stdout: unlines ([
'running doctests in test/esm/dependencies.mjs...',
'.'
]),
stderr: ''
});

testCommand ('bin/doctest --module esm test/esm/incorrect.mjs', {
status: 1,
stdout: unlines ([
'running doctests in test/esm/incorrect.mjs...',
'x',
'FAIL: expected 32 on line 4 (got "0°F")'
]),
stderr: ''
});
} else {
testCommand ('bin/doctest --module esm test/esm/index.mjs', {
status: 1,
stdout: '',
stderr: unlines ([
'error: Node.js v' + process.versions.node + ' does not support ECMAScript modules (supported since v9.0.0)'
])
});
}
testCommand ('bin/doctest --module esm test/esm/incorrect.mjs', {
status: 1,
stdout: unlines ([
'running doctests in test/esm/incorrect.mjs...',
'x',
'FAIL: expected 32 on line 4 (got "0°F")'
]),
stderr: ''
});

testCommand ('bin/doctest --print test/commonjs/exports/index.js', {
status: 0,
Expand Down

0 comments on commit 67bde9e

Please sign in to comment.