Skip to content

Commit

Permalink
Add tests for --module esm
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed Apr 1, 2019
1 parent 7490cea commit 440668b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
7 changes: 7 additions & 0 deletions test/esm/incorrect.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Convert degrees Celsius to degrees Fahrenheit.
//
// > toFahrenheit(0)
// 32
export function toFahrenheit(degreesCelsius) {
return String (degreesCelsius) + '°F';
}
7 changes: 7 additions & 0 deletions test/esm/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Convert degrees Celsius to degrees Fahrenheit.
//
// > toFahrenheit(0)
// 32
export function toFahrenheit(degreesCelsius) {
return degreesCelsius * 9 / 5 + 32;
}
27 changes: 25 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ 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 @@ -57,10 +60,9 @@ function testCommand(command, expected) {
var status = 0;
var stdout;
var stderr = '';
var noWarnings = Number (process.versions.node.split ('.')[0]) >= 9;
try {
stdout = execSync (
command + (noWarnings ? ' --nodejs --no-warnings' : ''),
command + (esmSupported ? ' --nodejs --no-warnings' : ''),
{encoding: 'utf8', stdio: 'pipe'}
);
} catch (err) {
Expand Down Expand Up @@ -209,6 +211,27 @@ 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/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,
stdout: unlines ([
Expand Down

0 comments on commit 440668b

Please sign in to comment.