diff --git a/.travis.yml b/.travis.yml index 339a38cc..77127208 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js node_js: + - 4.0 - 4 + - 5 sudo: false diff --git a/bin/_lab b/bin/_lab index 1400bf57..4a2e2734 100755 --- a/bin/_lab +++ b/bin/_lab @@ -1,14 +1,16 @@ #!/usr/bin/env node +'use strict'; + if (process.env.ROOT_SPAWN) { require('../test_runner/cli').run(); return; } -var Cpr = require('cpr'); -var Rimraf = require('rimraf'); +const Cpr = require('cpr'); +const Rimraf = require('rimraf'); -Cpr('./lib', './test_runner', { deleteFirst: true, confirm: true }, function (err) { +Cpr('./lib', './test_runner', { deleteFirst: true, confirm: true }, (err) => { if (err) { console.error(err); @@ -19,7 +21,7 @@ Cpr('./lib', './test_runner', { deleteFirst: true, confirm: true }, function (er require('../test_runner/cli').run(); }); -process.on('exit', function (code) { +process.on('exit', (code) => { Rimraf.sync('./test_runner'); }); diff --git a/bin/lab b/bin/lab index ace9f1bb..80f20fc3 100755 --- a/bin/lab +++ b/bin/lab @@ -1,3 +1,5 @@ #!/usr/bin/env node +'use strict'; + require('../lib/cli').run(); \ No newline at end of file diff --git a/lib/cli.js b/lib/cli.js index e0a1ecc1..94d56127 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,24 +1,26 @@ +'use strict'; + // Load modules -var Fs = require('fs'); -var Path = require('path'); -var Bossy = require('bossy'); -var Hoek = require('hoek'); -var Coverage = require('./coverage'); -var Pkg = require('../package.json'); -var Runner = require('./runner'); -var Transform = require('./transform'); -var Utils = require('./utils'); +const Fs = require('fs'); +const Path = require('path'); +const Bossy = require('bossy'); +const Hoek = require('hoek'); +const Coverage = require('./coverage'); +const Pkg = require('../package.json'); +const Runner = require('./runner'); +const Transform = require('./transform'); +const Utils = require('./utils'); // Declare internals -var internals = {}; +const internals = {}; exports.run = function () { - var settings = internals.options(); + const settings = internals.options(); settings.coveragePath = Path.join(process.cwd(), settings['coverage-path'] || ''); settings.coverageExclude = settings['coverage-exclude'] || ['test', 'node_modules']; settings.lintingPath = process.cwd(); @@ -35,7 +37,7 @@ exports.run = function () { } if (settings.sourcemaps) { - var sourceMapOptions = {}; + let sourceMapOptions = {}; if (settings.transform) { sourceMapOptions = { @@ -46,26 +48,26 @@ exports.run = function () { require('source-map-support').install(sourceMapOptions); } - var scripts = internals.traverse(settings.paths, settings); + const scripts = internals.traverse(settings.paths, settings); return Runner.report(scripts, settings); }; internals.traverse = function (paths, options) { - var traverse = function (path) { + const traverse = function (path) { - var files = []; + let files = []; - var pathStat = Fs.statSync(path); + const pathStat = Fs.statSync(path); if (pathStat.isFile()) { return path; } - Fs.readdirSync(path).forEach(function (filename) { + Fs.readdirSync(path).forEach((filename) => { - var file = Path.join(path, filename); - var stat = Fs.statSync(file); + let file = Path.join(path, filename); + const stat = Fs.statSync(file); if (stat.isDirectory() && !options.flat) { @@ -84,24 +86,24 @@ internals.traverse = function (paths, options) { return files; }; - var testFiles = []; - paths.forEach(function (path) { + let testFiles = []; + paths.forEach((path) => { testFiles = testFiles.concat(traverse(path)); }); - testFiles = testFiles.map(function (path) { + testFiles = testFiles.map((path) => { return Path.resolve(path); }); - var scripts = []; + const scripts = []; if (testFiles.length) { - testFiles.forEach(function (file) { + testFiles.forEach((file) => { global._labScriptRun = false; file = Path.resolve(file); - var pkg = require(file); + const pkg = require(file); if (pkg.lab && pkg.lab._root) { @@ -124,7 +126,7 @@ internals.traverse = function (paths, options) { internals.options = function () { - var definition = { + const definition = { assert: { alias: 'a', type: 'string', @@ -285,7 +287,7 @@ internals.options = function () { } }; - var argv = Bossy.parse(definition); + const argv = Bossy.parse(definition); if (argv instanceof Error) { console.error(Bossy.usage(definition, 'lab [options] [path]')); @@ -303,7 +305,7 @@ internals.options = function () { process.exit(0); } - var options = { + const options = { paths: argv._ ? [].concat(argv._) : ['test'] }; @@ -312,10 +314,10 @@ internals.options = function () { require('./').assertions = options.assert; } - var keys = ['coverage', 'coverage-path', 'coverage-exclude', 'colors', 'dry', 'debug', 'environment', 'flat', + const keys = ['coverage', 'coverage-path', 'coverage-exclude', 'colors', 'dry', 'debug', 'environment', 'flat', 'grep', 'globals', 'timeout', 'parallel', 'pattern', 'reporter', 'threshold', 'context-timeout', 'sourcemaps', 'lint', 'linter', 'transform', 'lint-options', 'lint-errors-threshold', 'lint-warnings-threshold']; - for (var i = 0, il = keys.length; i < il; ++i) { + for (let i = 0; i < keys.length; ++i) { if (argv.hasOwnProperty(keys[i]) && argv[keys[i]] !== undefined) { options[keys[i]] = argv[keys[i]]; } @@ -350,13 +352,13 @@ internals.options = function () { options.pattern = options.pattern ? '.*' + options.pattern + '.*?' : ''; if (options.transform) { - var transform = require(Path.resolve(options.transform)); + const transform = require(Path.resolve(options.transform)); Hoek.assert(Array.isArray(transform) && transform.length > 0, 'transform module must export an array of objects {ext: ".js", transform: null or function (content, filename)}'); options.transform = transform; - var includes = 'js|' + transform.map(internals.mapTransform).join('|'); - var regex = options.pattern + '\\.(' + includes + ')$'; + const includes = 'js|' + transform.map(internals.mapTransform).join('|'); + const regex = options.pattern + '\\.(' + includes + ')$'; options.pattern = new RegExp(regex); } else { diff --git a/lib/coverage.js b/lib/coverage.js index 6f5c7f79..272f68bd 100755 --- a/lib/coverage.js +++ b/lib/coverage.js @@ -1,3 +1,5 @@ +'use strict'; + // Adapted from: // Blanket https://github.com/alex-seville/blanket, copyright (c) 2013 Alex Seville, MIT licensed // Falafel https://github.com/substack/node-falafel, copyright (c) James Halliday, MIT licensed @@ -5,16 +7,16 @@ // Load modules -var Fs = require('fs'); -var Path = require('path'); -var Espree = require('espree'); -var SourceMapSupport = require('source-map-support'); -var Transform = require('./transform'); +const Fs = require('fs'); +const Path = require('path'); +const Espree = require('espree'); +const SourceMapSupport = require('source-map-support'); +const Transform = require('./transform'); // Declare internals -var internals = { +const internals = { patterns: [], sources: {} }; @@ -24,13 +26,13 @@ internals.prime = function (extension) { require.extensions[extension] = function (localModule, filename) { - for (var i = 0, il = internals.patterns.length; i < il; ++i) { + for (let i = 0; i < internals.patterns.length; ++i) { if (internals.patterns[i].test(filename.replace(/\\/g, '/'))) { return localModule._compile(internals.instrument(filename), filename); } } - var src = Fs.readFileSync(filename, 'utf8'); + const src = Fs.readFileSync(filename, 'utf8'); return localModule._compile(Transform.transform(filename, src), filename); }; }; @@ -46,9 +48,9 @@ exports.instrument = function (options) { internals.pattern = function (options) { - var base = internals.escape(options.coveragePath || ''); - var excludes = options.coverageExclude ? [].concat(options.coverageExclude).map(internals.escape).join('|') : ''; - var regex = '^' + base + (excludes ? (base[base.length - 1] === '/' ? '' : '\\/') + '(?!' + excludes + ')' : ''); + const base = internals.escape(options.coveragePath || ''); + const excludes = options.coverageExclude ? [].concat(options.coverageExclude).map(internals.escape).join('|') : ''; + const regex = '^' + base + (excludes ? (base[base.length - 1] === '/' ? '' : '\\/') + '(?!' + excludes + ')' : ''); return new RegExp(regex); }; @@ -63,17 +65,17 @@ internals.instrument = function (filename) { filename = filename.replace(/\\/g, '/'); - var file = Fs.readFileSync(filename, 'utf8'); - var content = file.replace(/^\#\!.*/, ''); + const file = Fs.readFileSync(filename, 'utf8'); + let content = file.replace(/^\#\!.*/, ''); content = Transform.transform(filename, content); - var tracking = []; - var statements = []; - var chunks = content.split(''); - var ids = 0; - var bypass = {}; + const tracking = []; + const statements = []; + const chunks = content.split(''); + let ids = 0; + const bypass = {}; - var annotate = function (node, parent) { + const annotate = function (node, parent) { // Decorate node @@ -87,7 +89,7 @@ internals.instrument = function (filename) { node.set = function (s) { chunks[node.range[0]] = s; - for (var i = node.range[0] + 1, il = node.range[1]; i < il; i++) { + for (let i = node.range[0] + 1; i < node.range[1]; i++) { chunks[i] = ''; } }; @@ -100,14 +102,14 @@ internals.instrument = function (filename) { // Recursively annotate the tree from the inner-most out - Object.keys(node).forEach(function (name) { + Object.keys(node).forEach((name) => { if (name === 'parent') { return; } - var children = [].concat(node[name]); - children.forEach(function (child) { + const children = [].concat(node[name]); + children.forEach((child) => { if (child && typeof child.type === 'string') { // Identify node types annotate(child, node); @@ -117,7 +119,7 @@ internals.instrument = function (filename) { // Annotate source code - var decoratedTypes = [ + const decoratedTypes = [ 'IfStatement', 'WhileStatement', 'DoWhileStatement', @@ -126,8 +128,8 @@ internals.instrument = function (filename) { 'WithStatement' ]; - var consequent; - var line; + let consequent; + let line; if (decoratedTypes.indexOf(node.type) !== -1) { if (node.alternate && @@ -142,7 +144,7 @@ internals.instrument = function (filename) { } } - var trackedTypes = [ + const trackedTypes = [ 'ExpressionStatement', 'BreakStatement', 'ContinueStatement', @@ -172,14 +174,14 @@ internals.instrument = function (filename) { else if (node.type === 'ConditionalExpression') { line = node.loc.start.line; consequent = addStatement(line, node.consequent, false); - var alternate = addStatement(line, node.alternate, false); + const alternate = addStatement(line, node.alternate, false); node.set('(' + node.test.source() + '? global.__$$labCov._statement(\'' + filename + '\',' + consequent + ',' + line + ',' + node.consequent.source() + ') : global.__$$labCov._statement(\'' + filename + '\',' + alternate + ',' + line + ',' + node.alternate.source() + '))'); } else if (node.type === 'LogicalExpression') { line = node.loc.start.line; - var left = addStatement(line, node.left, true); - var right = addStatement(line, node.right, node.parent.type === 'LogicalExpression'); + const left = addStatement(line, node.left, true); + const right = addStatement(line, node.right, node.parent.type === 'LogicalExpression'); node.set('(global.__$$labCov._statement(\'' + filename + '\',' + left + ',' + line + ',' + node.left.source() + ')' + node.operator + 'global.__$$labCov._statement(\'' + filename + '\',' + right + ',' + line + ',' + node.right.source() + '))'); } @@ -188,15 +190,15 @@ internals.instrument = function (filename) { node.parent.type !== 'SwitchCase') { line = node.loc.start.line; - var test = addStatement(line, node, true); + const test = addStatement(line, node, true); node.set('global.__$$labCov._statement(\'' + filename + '\',' + test + ',' + line + ',' + node.source() + ')'); } }; - var addStatement = function (line, node, bool) { + const addStatement = function (line, node, bool) { - var id = ++ids; + const id = ++ids; statements.push({ id: id, loc: node.loc, @@ -208,7 +210,7 @@ internals.instrument = function (filename) { // Parse tree - var tree = Espree.parse(content, { + const tree = Espree.parse(content, { loc: true, comment: true, range: true, @@ -228,21 +230,21 @@ internals.instrument = function (filename) { // Process comments - var skipStart = 0; - var segmentSkip = false; - tree.comments.forEach(function (comment) { + let skipStart = 0; + let segmentSkip = false; + tree.comments.forEach((comment) => { - var directive = comment.value.match(/^\s*\$lab\:coverage\:(off|on)\$\s*$/); + const directive = comment.value.match(/^\s*\$lab\:coverage\:(off|on)\$\s*$/); if (directive) { - var skip = directive[1] !== 'on'; + const skip = directive[1] !== 'on'; if (skip !== segmentSkip) { segmentSkip = skip; if (skip) { skipStart = comment.range[1]; } else { - for (var s = skipStart; s < comment.range[0]; ++s) { - bypass[s] = true; + for (let i = skipStart; i < comment.range[0]; ++i) { + bypass[i] = true; } } } @@ -255,7 +257,7 @@ internals.instrument = function (filename) { // Store original source - var transformedFile = content.replace(/\/\/\#(.*)$/, ''); + const transformedFile = content.replace(/\/\/\#(.*)$/, ''); internals.sources[filename] = transformedFile.replace(/(\r\n|\n|\r)/gm, '\n').split('\n'); // Setup global report container @@ -271,7 +273,7 @@ internals.instrument = function (filename) { _statement: function (name, id, line, source) { - var statement = global.__$$labCov.files[name].statements[line][id]; + const statement = global.__$$labCov.files[name].statements[line][id]; if (!statement.bool) { statement.hit[!source] = true; } @@ -287,13 +289,13 @@ internals.instrument = function (filename) { lines: {} }; - var record = global.__$$labCov.files[filename]; - tracking.forEach(function (item) { + const record = global.__$$labCov.files[filename]; + tracking.forEach((item) => { record.lines[item] = 0; }); - statements.forEach(function (item) { + statements.forEach((item) => { record.statements[item.line] = record.statements[item.line] || {}; record.statements[item.line][item.id] = { hit: {}, bool: item.bool, loc: item.loc }; @@ -307,10 +309,10 @@ exports.analyze = function (options) { // Process coverage (global.__$$labCov needed when labCov isn't defined) - /* $lab:coverage:off$ */ var report = global.__$$labCov || { files: {} }; /* $lab:coverage:on$ */ - var pattern = internals.pattern(options); + /* $lab:coverage:off$ */ const report = global.__$$labCov || { files: {} }; /* $lab:coverage:on$ */ + const pattern = internals.pattern(options); - var cov = { + const cov = { sloc: 0, hits: 0, misses: 0, @@ -320,12 +322,12 @@ exports.analyze = function (options) { // Filter files - var files = Object.keys(report.files); - for (var i = 0, il = files.length; i < il; ++i) { - var filename = files[i]; + const files = Object.keys(report.files); + for (let i = 0; i < files.length; ++i) { + const filename = files[i]; if (pattern.test(filename)) { report.files[filename].source = internals.sources[filename] || []; - var data = internals.file(filename, report.files[filename], options); + const data = internals.file(filename, report.files[filename], options); cov.files.push(data); cov.hits += data.hits; @@ -336,28 +338,28 @@ exports.analyze = function (options) { // Sort files based on directory structure - cov.files.sort(function (a, b) { + cov.files.sort((a, b) => { - var segmentsA = a.filename.split('/'); - var segmentsB = b.filename.split('/'); + const segmentsA = a.filename.split('/'); + const segmentsB = b.filename.split('/'); - var al = segmentsA.length; - var bl = segmentsB.length; + const al = segmentsA.length; + const bl = segmentsB.length; - for (var si = 0; si < al && si < bl; ++si) { + for (let i = 0; i < al && i < bl; ++i) { - if (segmentsA[si] === segmentsB[si]) { + if (segmentsA[i] === segmentsB[i]) { continue; } - var lastA = si + 1 === al; - var lastB = si + 1 === bl; + const lastA = i + 1 === al; + const lastB = i + 1 === bl; if (lastA !== lastB) { return lastA ? -1 : 1; } - return segmentsA[si] < segmentsB[si] ? -1 : 1; + return segmentsA[i] < segmentsB[i] ? -1 : 1; } return segmentsA.length < segmentsB.length ? -1 : 1; @@ -374,13 +376,13 @@ exports.analyze = function (options) { internals.addSourceMapsInformation = function (ret, num) { - var position = { + const position = { source: ret.filename, line: num, column: 0 }; - var originalPosition = SourceMapSupport.mapSourcePosition(position); - var source = ret.source[num]; + const originalPosition = SourceMapSupport.mapSourcePosition(position); + const source = ret.source[num]; if (position !== originalPosition) { source.originalFilename = originalPosition.source.replace(Path.join(process.cwd(), '/').replace(/\\/g, '/'), ''); @@ -399,7 +401,7 @@ internals.addSourceMapsInformation = function (ret, num) { internals.file = function (filename, data, options) { - var ret = { + const ret = { filename: filename.replace(Path.join(process.cwd(), '/').replace(/\\/g, '/'), ''), percent: 0, hits: 0, @@ -410,11 +412,11 @@ internals.file = function (filename, data, options) { // Process each line of code - data.source.forEach(function (line, num) { + data.source.forEach((line, num) => { num++; - var isMiss = false; + let isMiss = false; ret.source[num] = { source: line }; @@ -432,10 +434,10 @@ internals.file = function (filename, data, options) { ret.sloc++; if (data.statements[num]) { - var mask = new Array(line.length); - Object.keys(data.statements[num]).forEach(function (id) { + const mask = new Array(line.length); + Object.keys(data.statements[num]).forEach((id) => { - var statement = data.statements[num][id]; + const statement = data.statements[num][id]; if (statement.hit.true && statement.hit.false) { @@ -468,19 +470,19 @@ internals.file = function (filename, data, options) { } isMiss = true; - var issue = statement.hit.true ? 'true' : (statement.hit.false ? 'false' : 'never'); - for (var ci = statement.loc.start.column; ci < statement.loc.end.column; ++ci) { - mask[ci] = issue; + const issue = statement.hit.true ? 'true' : (statement.hit.false ? 'false' : 'never'); + for (let i = statement.loc.start.column; i < statement.loc.end.column; ++i) { + mask[i] = issue; } }); - var chunks = []; + const chunks = []; - var from = 0; - for (var a = 1, al = mask.length; a < al; ++a) { - if (mask[a] !== mask[a - 1]) { - chunks.push({ source: line.slice(from, a), miss: mask[a - 1] }); - from = a; + let from = 0; + for (let i = 1; i < mask.length; ++i) { + if (mask[i] !== mask[i - 1]) { + chunks.push({ source: line.slice(from, i), miss: mask[i - 1] }); + from = i; } } diff --git a/lib/index.js b/lib/index.js index 65f7be41..3ba928a7 100755 --- a/lib/index.js +++ b/lib/index.js @@ -1,15 +1,17 @@ +'use strict'; + // Load modules -var Hoek = require('hoek'); -var Coverage = require('./coverage'); -var Leaks = require('./leaks'); -var Runner = require('./runner'); -var Utils = require('./utils'); +const Hoek = require('hoek'); +const Coverage = require('./coverage'); +const Leaks = require('./leaks'); +const Runner = require('./runner'); +const Utils = require('./utils'); // Declare internals -var internals = {}; +const internals = {}; // Exports @@ -22,15 +24,15 @@ exports.assertions = null; // Set b /* - experiment('Utilities', function (){ + experiment('Utilities', () => { - experiment('#isEven()', function () { + experiment('#isEven()', () => { - test('returns true on even values', function (done) { + test('returns true on even values', (done) => { }); - test('returns false on odd values', function (done) { + test('returns false on odd values', (done) => { }); }); @@ -44,7 +46,7 @@ exports.script = function (options) { global._labScriptRun = true; // Compared by CLI to detect missing exports.lab - var script = { + const script = { _current: { experiments: [], tests: [], @@ -80,7 +82,7 @@ exports.script = function (options) { script.afterEach = internals.afterEach.bind(script); if (options.schedule !== false) { // Defaults to true - setImmediate(function () { + setImmediate(() => { if (!script._executed) { Runner.report(script, options); // Schedule automatic execution when used without the CLI @@ -94,16 +96,16 @@ exports.script = function (options) { internals.experiment = function (title /*, options, fn */) { - var options = arguments.length === 3 ? arguments[1] : {}; - var fn = arguments.length === 3 ? arguments[2] : arguments[1]; + const options = arguments.length === 3 ? arguments[1] : {}; + const fn = arguments.length === 3 ? arguments[2] : arguments[1]; - var settings = Utils.mergeOptions(this._current.options, options, ['only']); + const settings = Utils.mergeOptions(this._current.options, options, ['only']); if (settings.only) { Hoek.assert(!this._current.only.experiment, 'Cannot set multiple experiments at the same level as only'); this._current.only.experiment = true; - for (var i = 0, il = this._current.experiments.length; i < il; ++i) { + for (let i = 0; i < this._current.experiments.length; ++i) { this._current.experiments[i].options.skip = true; } } @@ -111,7 +113,7 @@ internals.experiment = function (title /*, options, fn */) { settings.skip = true; } - var child = { + const child = { title: title, parent: this._current, experiments: [], @@ -140,12 +142,12 @@ internals.experiment = function (title /*, options, fn */) { internals.before = function (/* options, */ fn) { - var options = arguments.length === 2 ? arguments[0] : {}; + const options = arguments.length === 2 ? arguments[0] : {}; fn = arguments.length === 2 ? arguments[1] : fn; Hoek.assert(fn && fn.length === 1, 'Function for before in "' + this._current.title + '" should take exactly one argument'); - var before = { + const before = { title: 'Before ' + this._titles.join(' '), fn: fn, options: options @@ -158,12 +160,12 @@ internals.before = function (/* options, */ fn) { internals.after = function (/* options, */ fn) { - var options = arguments.length === 2 ? arguments[0] : {}; + const options = arguments.length === 2 ? arguments[0] : {}; fn = arguments.length === 2 ? arguments[1] : fn; Hoek.assert(fn && fn.length === 1, 'Function for after in "' + this._current.title + '" should take exactly one argument'); - var after = { + const after = { title: 'After ' + this._titles.join(' '), fn: fn, options: options @@ -176,12 +178,12 @@ internals.after = function (/* options, */ fn) { internals.beforeEach = function (/* options, */ fn) { - var options = arguments.length === 2 ? arguments[0] : {}; + const options = arguments.length === 2 ? arguments[0] : {}; fn = arguments.length === 2 ? arguments[1] : fn; Hoek.assert(fn && fn.length === 1, 'Function for beforeEach in "' + this._current.title + '" should take exactly one argument'); - var beforeEach = { + const beforeEach = { title: 'Before each ' + this._titles.join(' '), fn: fn, options: options @@ -194,12 +196,12 @@ internals.beforeEach = function (/* options, */ fn) { internals.afterEach = function (/* options, */ fn) { - var options = arguments.length === 2 ? arguments[0] : {}; + const options = arguments.length === 2 ? arguments[0] : {}; fn = arguments.length === 2 ? arguments[1] : fn; Hoek.assert(fn && fn.length === 1, 'Function for afterEach in "' + this._current.title + '" should take exactly one argument'); - var afterEach = { + const afterEach = { title: 'After each ' + this._titles.join(' '), fn: fn, options: options @@ -212,20 +214,20 @@ internals.afterEach = function (/* options, */ fn) { internals.test = function (title /*, options, fn */) { - var options = arguments.length === 3 ? arguments[1] : {}; - var fn = arguments.length === 3 ? arguments[2] : arguments[1]; + const options = arguments.length === 3 ? arguments[1] : {}; + const fn = arguments.length === 3 ? arguments[2] : arguments[1]; if (fn) { Hoek.assert(fn.length === 1, 'Function for test "' + title + '" should take exactly one argument'); } - var settings = Utils.mergeOptions(this._current.options, options, ['only']); + const settings = Utils.mergeOptions(this._current.options, options, ['only']); if (settings.only) { Hoek.assert(!this._current.only.test, 'Cannot set multiple tests at the same level as only'); this._current.only.test = true; - for (var i = 0, il = this._current.tests.length; i < il; ++i) { + for (let i = 0; i < this._current.tests.length; ++i) { this._current.tests[i].options.skip = true; } } @@ -233,7 +235,7 @@ internals.test = function (title /*, options, fn */) { settings.skip = true; } - var test = { + const test = { path: this._path, title: this._titles.join(' ') + ' ' + title, relativeTitle: title, @@ -249,8 +251,8 @@ internals.skip = function (script, type) { return function (title /*, options, fn */) { - var options = arguments.length === 3 ? arguments[1] : {}; - var fn = arguments.length === 3 ? arguments[2] : arguments[1]; + const options = arguments.length === 3 ? arguments[1] : {}; + const fn = arguments.length === 3 ? arguments[2] : arguments[1]; script[type](title, Utils.mergeOptions({ skip: true }, options), fn); }; @@ -261,8 +263,8 @@ internals.only = function (script, type) { return function (title /*, options, fn */) { - var options = arguments.length === 3 ? arguments[1] : {}; - var fn = arguments.length === 3 ? arguments[2] : arguments[1]; + const options = arguments.length === 3 ? arguments[1] : {}; + const fn = arguments.length === 3 ? arguments[2] : arguments[1]; script[type](title, Utils.mergeOptions({ only: true }, options), fn); }; diff --git a/lib/leaks.js b/lib/leaks.js index 7095aa59..476da289 100755 --- a/lib/leaks.js +++ b/lib/leaks.js @@ -1,14 +1,16 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.detect = function (customGlobals) { - var whitelist = { + const whitelist = { _labScriptRun: true, // Lab global to detect script executions // Enumerable globals @@ -74,8 +76,8 @@ exports.detect = function (customGlobals) { }; if (customGlobals) { - for (var c = 0, cl = customGlobals.length; c < cl; ++c) { - whitelist[customGlobals[c]] = true; + for (let i = 0; i < customGlobals.length; ++i) { + whitelist[customGlobals[i]] = true; } } @@ -129,9 +131,9 @@ exports.detect = function (customGlobals) { whitelist.COUNTER_HTTP_CLIENT_RESPONSE = true; } - var leaks = []; - var globals = Object.getOwnPropertyNames(global); - for (var i = 0, il = globals.length; i < il; ++i) { + const leaks = []; + const globals = Object.getOwnPropertyNames(global); + for (let i = 0; i < globals.length; ++i) { if (!whitelist[globals[i]] && global[globals[i]] !== global) { diff --git a/lib/lint.js b/lib/lint.js old mode 100644 new mode 100755 index cf9cea9b..6c4cae03 --- a/lib/lint.js +++ b/lib/lint.js @@ -1,11 +1,13 @@ +'use strict'; + // Load modules -var ChildProcess = require('child_process'); +const ChildProcess = require('child_process'); // Declare internals -var internals = { +const internals = { linters: { eslint: __dirname + '/linters/eslint/index.js', jslint: __dirname + '/linters/jslint/index.js' @@ -15,23 +17,23 @@ var internals = { exports.lint = function (settings, callback) { - var child = ChildProcess.fork(internals.linters[settings.linter], + const child = ChildProcess.fork(internals.linters[settings.linter], settings['lint-options'] ? [settings['lint-options']] : [], { cwd: settings.lintingPath }); - child.once('message', function (message) { + child.once('message', (message) => { child.kill(); - var result = { lint: message, totalErrors: 0, totalWarnings: 0 }; + const result = { lint: message, totalErrors: 0, totalWarnings: 0 }; - result.lint.forEach(function (lint) { + result.lint.forEach((lint) => { - var errors = 0; - var warnings = 0; + let errors = 0; + let warnings = 0; - lint.errors.forEach(function (e) { + lint.errors.forEach((err) => { - if (e.severity === 'ERROR') { + if (err.severity === 'ERROR') { errors++; } else { diff --git a/lib/linters/eslint/index.js b/lib/linters/eslint/index.js old mode 100644 new mode 100755 index 16bf44a1..c2611e8a --- a/lib/linters/eslint/index.js +++ b/lib/linters/eslint/index.js @@ -1,21 +1,21 @@ -var Fs = require('fs'); -var Path = require('path'); -var Eslint = require('eslint'); -var Hoek = require('hoek'); +const Fs = require('fs'); +const Path = require('path'); +const Eslint = require('eslint'); +const Hoek = require('hoek'); // Declare internals -var internals = {}; +const internals = {}; exports.lint = function () { - var configuration = { + const configuration = { ignore: true, useEslintrc: true }; - var options = process.argv[2] ? JSON.parse(process.argv[2]) : undefined; + const options = process.argv[2] ? JSON.parse(process.argv[2]) : undefined; if (!Fs.existsSync('.eslintrc')) { configuration.configFile = Path.join(__dirname, '.eslintrc'); @@ -29,19 +29,19 @@ exports.lint = function () { Hoek.merge(configuration, options, true, false); } - var engine = new Eslint.CLIEngine(configuration); - var results = engine.executeOnFiles(['.']); + const engine = new Eslint.CLIEngine(configuration); + const results = engine.executeOnFiles(['.']); - return results.results.map(function (result) { + return results.results.map((result) => { return { filename: result.filePath, - errors: result.messages.map(function (error) { + errors: result.messages.map((err) => { return { - line: error.line, - severity: error.severity === 1 ? 'WARNING' : 'ERROR', - message: error.ruleId + ' - ' + error.message + line: err.line, + severity: err.severity === 1 ? 'WARNING' : 'ERROR', + message: err.ruleId + ' - ' + err.message }; }) }; diff --git a/lib/linters/jslint/index.js b/lib/linters/jslint/index.js old mode 100644 new mode 100755 index 9cbce988..c3e314e1 --- a/lib/linters/jslint/index.js +++ b/lib/linters/jslint/index.js @@ -1,14 +1,14 @@ // Load modules -var Hoek = require('hoek'); -var Nodejslint = require('jslint'); +const Hoek = require('hoek'); +const Nodejslint = require('jslint'); // Declare internals -var internals = {}; +const internals = {}; -var formatErrors = function (error) { +const formatErrors = function (error) { return { line: error.line, @@ -17,7 +17,7 @@ var formatErrors = function (error) { }; }; -var formatFile = function (file) { +const formatFile = function (file) { return { filename: file[0], @@ -27,7 +27,7 @@ var formatFile = function (file) { exports.lint = function () { - var configuration = { + const configuration = { edition: 'latest', argv: { remain: ['**/*.js'] @@ -35,16 +35,16 @@ exports.lint = function () { collector: true }; - var options = process.argv[2] ? JSON.parse(process.argv[2]) : undefined; + const options = process.argv[2] ? JSON.parse(process.argv[2]) : undefined; if (options) { Hoek.merge(configuration, options, true, false); } // synchronously lint - Nodejslint.runMain(configuration, function (err, report) { + Nodejslint.runMain(configuration, (err, report) => { - var formatted = report.map(formatFile); + const formatted = report.map(formatFile); process.send(formatted); }); }; diff --git a/lib/reporters/clover.js b/lib/reporters/clover.js index 95442953..ae3073c1 100755 --- a/lib/reporters/clover.js +++ b/lib/reporters/clover.js @@ -1,21 +1,23 @@ +'use strict'; + // Load modules -var Fs = require('fs'); -var Path = require('path'); -var Handlebars = require('handlebars'); +const Fs = require('fs'); +const Path = require('path'); +const Handlebars = require('handlebars'); // Declare internals -var internals = {}; +const internals = {}; exports = module.exports = internals.Reporter = function (options) { this.settings = options; - var filename = Path.join(__dirname, 'clover', 'report.xml'); - var template = Fs.readFileSync(filename, 'utf8'); + const filename = Path.join(__dirname, 'clover', 'report.xml'); + const template = Fs.readFileSync(filename, 'utf8'); if (this.settings.coveragePath) { this.settings.packageRoot = Path.basename(this.settings.coveragePath); @@ -24,7 +26,7 @@ exports = module.exports = internals.Reporter = function (options) { this.settings.packageRoot = 'root'; } - Handlebars.registerHelper('hits', function (hits) { + Handlebars.registerHelper('hits', (hits) => { return (hits === undefined ? '0' : hits); }); @@ -45,10 +47,10 @@ internals.Reporter.prototype.test = function (test) { internals.Reporter.prototype.end = function (notebook) { - var settings = this.settings; + const settings = this.settings; notebook.coverage = notebook.coverage || { files: [] }; - var context = { + const context = { cov: notebook.coverage, now: Date.now(), fileCount: notebook.coverage.files.length, @@ -56,7 +58,7 @@ internals.Reporter.prototype.end = function (notebook) { packages: {} }; - notebook.coverage.files.forEach(function (file) { + notebook.coverage.files.forEach((file) => { file.segments = file.filename.split('/'); file.basename = file.segments.pop(); @@ -82,7 +84,7 @@ internals.Reporter.prototype.end = function (notebook) { context.packageCount++; } - var curPackage = context.packages[file.package]; + const curPackage = context.packages[file.package]; curPackage.files.push(file); curPackage.hits += file.hits; diff --git a/lib/reporters/console.js b/lib/reporters/console.js index 2db99802..ea64adef 100755 --- a/lib/reporters/console.js +++ b/lib/reporters/console.js @@ -1,13 +1,15 @@ +'use strict'; + // Load modules -var Tty = require('tty'); -var Diff = require('diff'); -var StringifySafe = require('json-stringify-safe'); +const Tty = require('tty'); +const Diff = require('diff'); +const StringifySafe = require('json-stringify-safe'); // Declare internals -var internals = { +const internals = { width: 50 }; @@ -51,12 +53,12 @@ internals.Reporter.prototype.test = function (test) { } else { - var check = process.platform === 'win32' ? '\u221A' : '\u2714'; - var asterisk = process.platform === 'win32' ? '\u00D7' : '\u2716'; + const check = process.platform === 'win32' ? '\u221A' : '\u2714'; + const asterisk = process.platform === 'win32' ? '\u00D7' : '\u2716'; // Verbose (Spec reporter) - for (var i = 0, il = test.path.length; i < il; ++i) { + for (let i = 0; i < test.path.length; ++i) { if (test.path[i] !== this.last[i]) { this.report(internals.spacer(i * 2) + test.path[i] + '\n'); } @@ -64,12 +66,12 @@ internals.Reporter.prototype.test = function (test) { this.last = test.path; - var spacer = internals.spacer(test.path.length * 2); + const spacer = internals.spacer(test.path.length * 2); if (test.err) { this.report(spacer + this.colors.red(asterisk + test.id + ') ' + test.relativeTitle) + '\n'); } else { - var symbol = test.skipped || test.todo ? this.colors.magenta('-') : this.colors.green(check); + const symbol = test.skipped || test.todo ? this.colors.magenta('-') : this.colors.green(check); this.report(spacer + symbol + ' ' + this.colors.gray(test.id + ') ' + test.relativeTitle + ' (' + test.duration + ' ms)') + '\n'); } @@ -114,30 +116,30 @@ internals.Reporter.prototype.end = function (notebook) { // Colors - var red = this.colors.red; - var redBg = this.colors.redBg; - var green = this.colors.green; - var greenBg = this.colors.greenBg; - var gray = this.colors.gray; - var yellow = this.colors.yellow; + const red = this.colors.red; + const redBg = this.colors.redBg; + const green = this.colors.green; + const greenBg = this.colors.greenBg; + const gray = this.colors.gray; + const yellow = this.colors.yellow; // Tests - var failures = notebook.tests.filter(internals.filterFailures); + const failures = notebook.tests.filter(internals.filterFailures); - var skipped = notebook.tests.filter(internals.filterSkipped); + const skipped = notebook.tests.filter(internals.filterSkipped); - var output = ''; - var totalTests = notebook.tests.length - skipped.length; + let output = ''; + const totalTests = notebook.tests.length - skipped.length; - var errors = notebook.errors || []; + const errors = notebook.errors || []; if (errors.length) { output += 'Test script errors:\n\n'; - errors.forEach(function (error) { + errors.forEach((err) => { - output += red(error.message || error) + '\n'; - if (error.stack) { - var stack = error.stack.slice(error.stack.indexOf('\n') + 1) + output += red(err.message) + '\n'; + if (err.stack) { + const stack = err.stack.slice(err.stack.indexOf('\n') + 1) .replace(/^/gm, ' ') .split('\n') .filter(internals.filterNodeModules) // Remove node_modules files @@ -155,9 +157,9 @@ internals.Reporter.prototype.end = function (notebook) { if (failures.length) { output += 'Failed tests:\n\n'; - for (var i = 0, il = failures.length; i < il; ++i) { - var test = failures[i]; - var message = test.err.message || ''; + for (let i = 0; i < failures.length; ++i) { + const test = failures[i]; + const message = test.err.message || ''; output += ' ' + test.id + ') ' + test.title + ':\n\n'; @@ -166,26 +168,26 @@ internals.Reporter.prototype.end = function (notebook) { if (test.err.actual !== undefined && test.err.expected !== undefined) { - var actual = StringifySafe(test.err.actual, internals.stringifyReplacer, 2); - var expected = StringifySafe(test.err.expected, internals.stringifyReplacer, 2); + const actual = StringifySafe(test.err.actual, internals.stringifyReplacer, 2); + const expected = StringifySafe(test.err.expected, internals.stringifyReplacer, 2); output += ' ' + redBg('actual') + ' ' + greenBg('expected') + '\n\n '; - var comparison = Diff.diffWords(actual, expected); - for (var c = 0, cl = comparison.length; c < cl; ++c) { - var item = comparison[c]; - var value = item.value; - var lines = value.split('\n'); - for (var l = 0, ll = lines.length; l < ll; ++l) { - if (l) { + const comparison = Diff.diffWords(actual, expected); + for (let j = 0; j < comparison.length; ++j) { + const item = comparison[j]; + const value = item.value; + const lines = value.split('\n'); + for (let k = 0; k < lines.length; ++k) { + if (k) { output += '\n '; } if (item.added || item.removed) { - output += item.added ? greenBg(lines[l]) : redBg(lines[l]); + output += item.added ? greenBg(lines[k]) : redBg(lines[k]); } else { - output += lines[l]; + output += lines[k]; } } } @@ -207,8 +209,8 @@ internals.Reporter.prototype.end = function (notebook) { } if (test.err.data) { - var isObject = typeof test.err.data === 'object' && !Array.isArray(test.err.data); - var errorData = StringifySafe(test.err.data, null, isObject ? 4 : null); + const isObject = typeof test.err.data === 'object' && !Array.isArray(test.err.data); + let errorData = StringifySafe(test.err.data, null, isObject ? 4 : null); if (isObject) { errorData = errorData.replace(/(\n\s*)"(.*)"\:/g, '$1$2:').split('\n').slice(1, -1).join('\n'); } @@ -246,30 +248,30 @@ internals.Reporter.prototype.end = function (notebook) { // Coverage - var coverage = notebook.coverage; + const coverage = notebook.coverage; if (coverage) { - var status = 'Coverage: ' + coverage.percent.toFixed(2) + '%'; + const status = 'Coverage: ' + coverage.percent.toFixed(2) + '%'; output += coverage.percent === 100 ? green(status) : red(status + ' (' + (coverage.sloc - coverage.hits) + '/' + coverage.sloc + ')'); if (coverage.percent < 100) { - coverage.files.forEach(function (file) { + coverage.files.forEach((file) => { - var missingLines; + let missingLines; if (file.sourcemaps) { - var missingLinesByFile = {}; - Object.keys(file.source).forEach(function (lineNumber) { + const missingLinesByFile = {}; + Object.keys(file.source).forEach((lineNumber) => { - var line = file.source[lineNumber]; + const line = file.source[lineNumber]; if (line.miss) { missingLines = missingLinesByFile[line.originalFilename] = missingLinesByFile[line.originalFilename] || []; missingLines.push(line.originalLine); } }); - var files = Object.keys(missingLinesByFile); + const files = Object.keys(missingLinesByFile); if (files.length) { output += red('\n' + file.filename + ' missing coverage from file(s):'); - files.forEach(function (filename) { + files.forEach((filename) => { output += red('\n\t' + filename + ' on line(s): ' + missingLinesByFile[filename].join(', ')); }); @@ -277,9 +279,9 @@ internals.Reporter.prototype.end = function (notebook) { } else { missingLines = []; - Object.keys(file.source).forEach(function (lineNumber) { + Object.keys(file.source).forEach((lineNumber) => { - var line = file.source[lineNumber]; + const line = file.source[lineNumber]; if (line.miss) { missingLines.push(lineNumber); } @@ -299,12 +301,12 @@ internals.Reporter.prototype.end = function (notebook) { output += '\n'; } - var lint = notebook.lint; + const lint = notebook.lint; if (lint) { output += 'Linting results:'; - var hasErrors = false; - lint.lint.forEach(function (entry) { + let hasErrors = false; + lint.lint.forEach((entry) => { // Don't show anything if there aren't issues if (!entry.errors || !entry.errors.length) { @@ -313,9 +315,9 @@ internals.Reporter.prototype.end = function (notebook) { hasErrors = true; output += gray('\n\t' + entry.filename + ':'); - entry.errors.forEach(function (error) { + entry.errors.forEach((err) => { - output += (error.severity === 'ERROR' ? red : yellow)('\n\t\tLine ' + error.line + ': ' + error.message); + output += (err.severity === 'ERROR' ? red : yellow)('\n\t\tLine ' + err.line + ': ' + err.message); }); }); @@ -332,7 +334,7 @@ internals.Reporter.prototype.end = function (notebook) { internals.color = function (name, code, enabled) { if (enabled) { - var color = '\u001b[' + code + 'm'; + const color = '\u001b[' + code + 'm'; return function (text) { return color + text + '\u001b[0m'; @@ -352,7 +354,7 @@ internals.colors = function (enabled) { enabled = Tty.isatty(1) && Tty.isatty(2); } - var codes = { + const codes = { 'black': 0, 'gray': 90, 'red': 31, @@ -363,10 +365,10 @@ internals.colors = function (enabled) { 'greenBg': 42 }; - var colors = {}; - var names = Object.keys(codes); - for (var i = 0, il = names.length; i < il; ++i) { - var name = names[i]; + const colors = {}; + const names = Object.keys(codes); + for (let i = 0; i < names.length; ++i) { + const name = names[i]; colors[name] = internals.color(name, codes[name], enabled); } diff --git a/lib/reporters/html.js b/lib/reporters/html.js index 7fe76bd7..f4b2b06f 100755 --- a/lib/reporters/html.js +++ b/lib/reporters/html.js @@ -1,43 +1,45 @@ +'use strict'; + // Load modules -var Fs = require('fs'); -var Path = require('path'); -var Handlebars = require('handlebars'); -var Hoek = require('hoek'); +const Fs = require('fs'); +const Path = require('path'); +const Handlebars = require('handlebars'); +const Hoek = require('hoek'); // Declare internals -var internals = {}; +const internals = {}; exports = module.exports = internals.Reporter = function (options) { this.settings = options; - var filename = Path.join(__dirname, 'html', 'report.html'); - var template = Fs.readFileSync(filename, 'utf8'); + const filename = Path.join(__dirname, 'html', 'report.html'); + const template = Fs.readFileSync(filename, 'utf8'); - Handlebars.registerHelper('hits', function (hits) { + Handlebars.registerHelper('hits', (hits) => { return (hits === undefined ? '' : hits); }); - Handlebars.registerHelper('join', function (array, separator) { + Handlebars.registerHelper('join', (array, separator) => { return array.join(separator); }); - Handlebars.registerHelper('replace', function (str, from, to, flags) { + Handlebars.registerHelper('replace', (str, from, to, flags) => { return str.replace(new RegExp(from, flags), to); }); - Handlebars.registerHelper('lintJoin', function (array) { + Handlebars.registerHelper('lintJoin', (array) => { - var str = ''; + let str = ''; - for (var i = 0, il = array.length; i < il; ++i) { + for (let i = 0; i < array.length; ++i) { if (str) { str += ' '; // This is a line break } @@ -48,20 +50,20 @@ exports = module.exports = internals.Reporter = function (options) { return new Handlebars.SafeString(str); }); - Handlebars.registerHelper('errorMessage', function (error) { + Handlebars.registerHelper('errorMessage', (err) => { - return new Handlebars.SafeString(Hoek.escapeHtml('' + (error.message || error))); + return new Handlebars.SafeString(Hoek.escapeHtml('' + err.message)); }); - Handlebars.registerHelper('errorStack', function (error) { + Handlebars.registerHelper('errorStack', (err) => { - var stack = error.stack.slice(error.stack.indexOf('\n') + 1).replace(/^\s*/gm, ' '); + const stack = err.stack.slice(err.stack.indexOf('\n') + 1).replace(/^\s*/gm, ' '); return new Handlebars.SafeString(Hoek.escapeHtml(stack)); }); - var partialsPath = Path.join(__dirname, 'html', 'partials'); - var partials = Fs.readdirSync(partialsPath); - partials.forEach(function (partial) { + const partialsPath = Path.join(__dirname, 'html', 'partials'); + const partials = Fs.readdirSync(partialsPath); + partials.forEach((partial) => { Handlebars.registerPartial(Path.basename(partial, '.html'), Fs.readFileSync(Path.join(partialsPath, partial), 'utf8')); }); @@ -85,8 +87,8 @@ internals.Reporter.prototype.end = function (notebook) { notebook.coverage = notebook.coverage || { percent: 0, files: [] }; notebook.lint = notebook.lint || { lint: [], disabled: true }; - var percent = notebook.coverage.percent; - var context = { + const percent = notebook.coverage.percent; + const context = { coverage: { cov: notebook.coverage, percentClass: percent > 75 ? 'high' : (percent > 50 ? 'medium' : (percent > 25 ? 'low' : 'terrible')), @@ -98,22 +100,22 @@ internals.Reporter.prototype.end = function (notebook) { duration: notebook.ms }; - context.failures = context.tests.filter(function (test) { + context.failures = context.tests.filter((test) => { return !!test.err; }); - context.skipped = context.tests.filter(function (test) { + context.skipped = context.tests.filter((test) => { return test.skipped; }); // Populate path to be used for filtering context.paths = []; - context.tests.forEach(function (test) { + context.tests.forEach((test) => { - var paths = []; - test.path.forEach(function (path) { + const paths = []; + test.path.forEach((path) => { path = path.replace(/\ /gi, '_'); paths.push(path); @@ -125,7 +127,7 @@ internals.Reporter.prototype.end = function (notebook) { test.path = paths; }); - context.coverage.cov.files.forEach(function (file) { + context.coverage.cov.files.forEach((file) => { file.segments = file.filename.split('/'); file.basename = file.segments.pop(); @@ -137,9 +139,9 @@ internals.Reporter.prototype.end = function (notebook) { } if (context.lint.lint.length) { - var fileLint = internals.findLint(context.lint.lint, file); + const fileLint = internals.findLint(context.lint.lint, file); if (fileLint) { - Object.keys(file.source).forEach(function (line) { + Object.keys(file.source).forEach((line) => { file.source[line].lintErrors = internals.findLintErrors(fileLint, +line); }); @@ -151,15 +153,15 @@ internals.Reporter.prototype.end = function (notebook) { context.lint.errorClass = internals.lintClass(context.lint.totalErrors, this.settings['lint-errors-threshold']); context.lint.warningClass = internals.lintClass(context.lint.totalWarnings, this.settings['lint-warnings-threshold']); - context.lint.lint.forEach(function (entry) { + context.lint.lint.forEach((entry) => { entry.filename = Path.relative(process.cwd(), Path.resolve(entry.filename)); entry.errorClass = internals.lintClass(entry.totalErrors, this.settings['lint-errors-threshold']); entry.warningClass = internals.lintClass(entry.totalWarnings, this.settings['lint-warnings-threshold']); - entry.errors.forEach(function (error) { + entry.errors.forEach((err) => { - error.message = Hoek.escapeHtml(error.message); + err.message = Hoek.escapeHtml(err.message); }); }, this); } @@ -169,18 +171,18 @@ internals.Reporter.prototype.end = function (notebook) { internals.findLint = function (lint, file) { - for (var f = 0, fl = lint.length; f < fl; ++f) { - if (lint[f].filename.slice(-file.filename.length) === file.filename && lint[f].errors.length) { - return lint[f]; + for (let i = 0; i < lint.length; ++i) { + if (lint[i].filename.slice(-file.filename.length) === file.filename && lint[i].errors.length) { + return lint[i]; } } }; internals.findLintErrors = function (lint, line) { - var reports = { errors: [], warnings: [] }; - for (var i = 0, il = lint.errors.length; i < il; ++i) { - var report = lint.errors[i]; + const reports = { errors: [], warnings: [] }; + for (let i = 0; i < lint.errors.length; ++i) { + const report = lint.errors[i]; if (report.line === line) { if (report.severity === 'ERROR') { diff --git a/lib/reporters/html/partials/scripts.html b/lib/reporters/html/partials/scripts.html old mode 100644 new mode 100755 diff --git a/lib/reporters/index.js b/lib/reporters/index.js index fd677975..06a7f4d4 100755 --- a/lib/reporters/index.js +++ b/lib/reporters/index.js @@ -1,14 +1,16 @@ +'use strict'; + // Load modules -var Fs = require('fs'); -var Path = require('path'); -var Mkdirp = require('mkdirp'); +const Fs = require('fs'); +const Path = require('path'); +const Mkdirp = require('mkdirp'); // ('./multiple') loaded below // Declare internals -var internals = {}; +const internals = {}; internals.protos = { @@ -21,6 +23,7 @@ internals.protos = { tap: require('./tap') }; + internals.requireReporter = function (reporter) { if (Array.isArray(reporter)) { @@ -34,17 +37,18 @@ internals.requireReporter = function (reporter) { return require(reporter); }; + internals.isOverLintStatus = function (lint, threshold, status) { if (threshold >= 0) { - var lintResults = lint.lint; + const lintResults = lint.lint; - for (var l = 0, ll = lintResults.length; l < ll; ++l) { + for (let i = 0; i < lintResults.length; ++i) { - var errors = lintResults[l].errors; + const errors = lintResults[i].errors; - for (var e = 0, el = errors.length; e < el; ++e) { - if (errors[e].severity === status && --threshold <= 0) { + for (let j = 0; j < errors.length; ++j) { + if (errors[j].severity === status && --threshold <= 0) { return true; } } @@ -54,13 +58,14 @@ internals.isOverLintStatus = function (lint, threshold, status) { return false; }; + exports.generate = function (options) { - var Proto = internals.protos[options.reporter] || internals.requireReporter(options.reporter); - var reporter = new Proto(options); + const Proto = internals.protos[options.reporter] || internals.requireReporter(options.reporter); + const reporter = new Proto(options); if (!Array.isArray(options.reporter)) { - var dest; + let dest; if (typeof options.output === 'string') { Mkdirp.sync(Path.dirname(options.output)); dest = Fs.createWriteStream(options.output); @@ -69,7 +74,7 @@ exports.generate = function (options) { dest = options.output; } - var output = ''; + let output = ''; reporter.report = function (text) { @@ -83,9 +88,9 @@ exports.generate = function (options) { reporter.end(notebook); - var finalize = function () { + const finalize = function () { - var code = ((notebook.errors && notebook.errors.length) || // Before/after/exceptions + const code = ((notebook.errors && notebook.errors.length) || // Before/after/exceptions options.coverage && options.threshold && notebook.coverage.percent < options.threshold) || // Missing coverage notebook.failures || // Tests failed (notebook.leaks && notebook.leaks.length) || // Global leaked diff --git a/lib/reporters/json.js b/lib/reporters/json.js index 46ce6172..de6e9992 100755 --- a/lib/reporters/json.js +++ b/lib/reporters/json.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports = module.exports = internals.Reporter = function (options) { @@ -24,19 +26,19 @@ internals.Reporter.prototype.test = function (test) { internals.Reporter.prototype.end = function (notebook) { - var tests = {}; - notebook.tests.forEach(function (test) { + const tests = {}; + notebook.tests.forEach((test) => { - var path = test.path.join('/'); + const path = test.path.join('/'); tests[path] = tests[path] || []; tests[path].push({ title: test.relativeTitle, - err: (test.err ? test.err.message || true : false), + err: (test.err ? test.err.message : false), duration: test.duration }); }); - var report = { + const report = { tests: tests, duration: notebook.ms, leaks: notebook.leaks diff --git a/lib/reporters/junit.js b/lib/reporters/junit.js old mode 100644 new mode 100755 index 4ed8b1d3..7108177a --- a/lib/reporters/junit.js +++ b/lib/reporters/junit.js @@ -1,21 +1,23 @@ +'use strict'; + // Load modules -var Fs = require('fs'); -var Path = require('path'); -var Handlebars = require('handlebars'); +const Fs = require('fs'); +const Path = require('path'); +const Handlebars = require('handlebars'); // Declare internals -var internals = {}; +const internals = {}; exports = module.exports = internals.Reporter = function (options) { this.settings = options; - var filename = Path.join(__dirname, 'junit', 'report.xml'); - var template = Fs.readFileSync(filename, 'utf8'); + const filename = Path.join(__dirname, 'junit', 'report.xml'); + const template = Fs.readFileSync(filename, 'utf8'); this.view = Handlebars.compile(template); }; @@ -33,7 +35,7 @@ internals.Reporter.prototype.test = function (test) { internals.Reporter.prototype.end = function (notebook) { - var context = { + const context = { count: notebook.tests.length, failures: notebook.failures, errors: notebook.errors.length, @@ -41,11 +43,11 @@ internals.Reporter.prototype.end = function (notebook) { time: notebook.ms / 1000 }; - var tests = context.tests = []; + const tests = context.tests = []; - notebook.tests.forEach(function (nbtest) { + notebook.tests.forEach((nbtest) => { - var test = { + const test = { title: nbtest.title, path: nbtest.path.join(' '), relativeTitle: nbtest.relativeTitle, diff --git a/lib/reporters/lcov.js b/lib/reporters/lcov.js old mode 100644 new mode 100755 index 80572e2e..2eae5171 --- a/lib/reporters/lcov.js +++ b/lib/reporters/lcov.js @@ -1,11 +1,13 @@ +'use strict'; + // Load modules -var Path = require('path'); +const Path = require('path'); // Declare internals -var internals = {}; +const internals = {}; exports = module.exports = internals.Reporter = function (options) { @@ -32,24 +34,22 @@ internals.Reporter.prototype.test = function (test) { internals.Reporter.prototype.end = function (notebook) { - var self = this; - notebook.coverage = notebook.coverage || { files: [] }; - notebook.coverage.files.forEach(function (file) { + notebook.coverage.files.forEach((file) => { - self.reportln('TN:'); // Test Name - self.reportln('SF:' + Path.join(process.cwd(), '/', file.filename)); // Script File + this.reportln('TN:'); // Test Name + this.reportln('SF:' + Path.join(process.cwd(), '/', file.filename)); // Script File - var lineNums = Object.keys(file.source); - lineNums.forEach(function (lineNum) { + const lineNums = Object.keys(file.source); + lineNums.forEach((lineNum) => { - var line = file.source[lineNum]; - var hits = line.miss ? 0 : (line.hits || 1); - self.reportln('DA:' + lineNum + ',' + hits); // Line and total execution count + const line = file.source[lineNum]; + const hits = line.miss ? 0 : (line.hits || 1); + this.reportln('DA:' + lineNum + ',' + hits); // Line and total execution count }); - self.reportln('LF:' + file.sloc); - self.reportln('LH:' + file.hits); - self.reportln('end_of_record'); + this.reportln('LF:' + file.sloc); + this.reportln('LH:' + file.hits); + this.reportln('end_of_record'); }); }; diff --git a/lib/reporters/multiple.js b/lib/reporters/multiple.js old mode 100644 new mode 100755 index e791525f..43bbbb7c --- a/lib/reporters/multiple.js +++ b/lib/reporters/multiple.js @@ -1,22 +1,23 @@ +'use strict'; + // Load modules -var Hoek = require('hoek'); -var Reporters = require('./index'); +const Hoek = require('hoek'); +const Reporters = require('./index'); // Declare internals -var internals = {}; +const internals = {}; exports = module.exports = internals.Reporter = function (options) { - var self = this; - self._reporters = []; + this._reporters = []; - options.reporter.forEach(function (reporter, index) { + options.reporter.forEach((reporter, index) => { - var reporterOptions = Hoek.clone(options); + const reporterOptions = Hoek.clone(options); reporterOptions.reporter = reporter; if (options.output[index] === 'stdout') { @@ -25,14 +26,14 @@ exports = module.exports = internals.Reporter = function (options) { reporterOptions.output = options.output[index] || options.output; - var reporterKey = reporterOptions.reporter; - var reporterIndex = 2; - while (self._reporters.hasOwnProperty(reporterKey)) { + let reporterKey = reporterOptions.reporter; + let reporterIndex = 2; + while (this._reporters.hasOwnProperty(reporterKey)) { reporterKey = reporterOptions.reporter + reporterIndex; reporterIndex++; } - self._reporters[reporterKey] = Reporters.generate(reporterOptions); + this._reporters[reporterKey] = Reporters.generate(reporterOptions); }); this.settings = options; }; @@ -40,7 +41,7 @@ exports = module.exports = internals.Reporter = function (options) { internals.Reporter.prototype.start = function (notebook) { - for (var key in this._reporters) { + for (let key in this._reporters) { this._reporters[key].start(notebook); } }; @@ -48,7 +49,7 @@ internals.Reporter.prototype.start = function (notebook) { internals.Reporter.prototype.test = function (test) { - for (var key in this._reporters) { + for (let key in this._reporters) { this._reporters[key].test(test); } }; @@ -56,7 +57,7 @@ internals.Reporter.prototype.test = function (test) { internals.Reporter.prototype.end = function (notebook) { - for (var key in this._reporters) { + for (let key in this._reporters) { this._reporters[key].end(notebook); } }; @@ -64,7 +65,7 @@ internals.Reporter.prototype.end = function (notebook) { internals.Reporter.prototype.report = function (text) { - for (var key in this._reporters) { + for (let key in this._reporters) { this._reporters[key].report(text); } }; @@ -74,7 +75,7 @@ internals.Reporter.prototype.finalize = function (notebook, callback) { this._results = { err: false, code: [], output: [], count: 0 }; - for (var key in this._reporters) { + for (let key in this._reporters) { this._reporters[key].finalize(notebook, this.finalizeSingle(key, callback)); } }; @@ -82,22 +83,20 @@ internals.Reporter.prototype.finalize = function (notebook, callback) { internals.Reporter.prototype.finalizeSingle = function (key, callback) { - var self = this; - - return function (err, code, output) { + return (err, code, output) => { - self._results.count++; - self._results.err = self._results.err || err; - self._results.code[key] = code; - self._results.output[key] = output; - self._results.processCode = self._results.processCode || code; + this._results.count++; + this._results.err = this._results.err || err; + this._results.code[key] = code; + this._results.output[key] = output; + this._results.processCode = this._results.processCode || code; - if (self._results.count === Object.keys(self._reporters).length) { + if (this._results.count === Object.keys(this._reporters).length) { if (callback) { - return callback(self._results.err, self._results.code, self._results.output); + return callback(this._results.err, this._results.code, this._results.output); } - process.exit(self._results.processCode); + process.exit(this._results.processCode); } }; }; diff --git a/lib/reporters/tap.js b/lib/reporters/tap.js index 0c724b6e..dabd646c 100755 --- a/lib/reporters/tap.js +++ b/lib/reporters/tap.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports = module.exports = internals.Reporter = function (options) { @@ -38,8 +40,8 @@ internals.Reporter.prototype.start = function (notebook) { internals.Reporter.prototype.test = function (test) { - var title = '(' + test.id + ') ' + test.title.replace(/#/g, ''); - var id = ++this.counter; + const title = '(' + test.id + ') ' + test.title.replace(/#/g, ''); + const id = ++this.counter; if (test.err) { ++this.failures; diff --git a/lib/runner.js b/lib/runner.js index dcc8dd9a..4d996e23 100755 --- a/lib/runner.js +++ b/lib/runner.js @@ -1,24 +1,26 @@ +'use strict'; + // Load modules -var Domain = require('domain'); -var Items = require('items'); -var Reporters = require('./reporters'); -var Coverage = require('./coverage'); -var Linters = require('./lint'); -var Leaks = require('./leaks'); -var Utils = require('./utils'); +const Domain = require('domain'); +const Items = require('items'); +const Reporters = require('./reporters'); +const Coverage = require('./coverage'); +const Linters = require('./lint'); +const Leaks = require('./leaks'); +const Utils = require('./utils'); // prevent libraries like Sinon from clobbering global time functions -var Date = global.Date; -var setTimeout = global.setTimeout; -var clearTimeout = global.clearTimeout; -var setImmediate = global.setImmediate; +const Date = global.Date; +const setTimeout = global.setTimeout; +const clearTimeout = global.clearTimeout; +const setImmediate = global.setImmediate; // Declare internals -var internals = {}; +const internals = {}; Error.stackTraceLimit = Infinity; // Set Error stack size @@ -56,12 +58,12 @@ internals.defaults = { exports.report = function (scripts, options, callback) { - var settings = Utils.mergeOptions(internals.defaults, options); - var reporter = Reporters.generate(settings); + const settings = Utils.mergeOptions(internals.defaults, options); + const reporter = Reporters.generate(settings); - var executeScripts = function (next) { + const executeScripts = function (next) { - exports.execute(scripts, settings, reporter, function (err, result) { + exports.execute(scripts, settings, reporter, (err, result) => { if (settings.leaks) { result.leaks = Leaks.detect(settings.globals); @@ -75,7 +77,7 @@ exports.report = function (scripts, options, callback) { }); }; - var executeLint = function (next) { + const executeLint = function (next) { if (!settings.lint) { return next(); @@ -84,17 +86,17 @@ exports.report = function (scripts, options, callback) { Linters.lint(settings, next); }; - Items.parallel.execute({ notebook: executeScripts, lint: executeLint }, function (err, results) { + Items.parallel.execute({ notebook: executeScripts, lint: executeLint }, (err, results) => { - var notebook = results.notebook; + const notebook = results.notebook; notebook.lint = results.lint; if (options.assert) { notebook.assertions = options.assert.count && options.assert.count(); - var incompletes = options.assert.incomplete && options.assert.incomplete(); + const incompletes = options.assert.incomplete && options.assert.incomplete(); if (incompletes) { - for (var i = 0, il = incompletes.length; i < il; ++i) { - var error = new Error('Incomplete assertion at ' + incompletes[i]); + for (let i = 0; i < incompletes.length; ++i) { + const error = new Error('Incomplete assertion at ' + incompletes[i]); error.stack = undefined; notebook.errors.push(error); } @@ -109,29 +111,29 @@ exports.report = function (scripts, options, callback) { exports.execute = function (scripts, options, reporter, callback) { scripts = [].concat(scripts); - var experiments = scripts.map(function (script) { + const experiments = scripts.map((script) => { script._executed = true; return script._root; }); reporter = reporter || { test: function () { }, start: function () { } }; - var settings = Utils.mergeOptions(internals.defaults, options); + const settings = Utils.mergeOptions(internals.defaults, options); if (settings.environment) { process.env.NODE_ENV = settings.environment; } - var filters = { + const filters = { ids: settings.ids, grep: settings.grep ? new RegExp(settings.grep) : null }; - var count = internals.count(experiments, { filters: filters }); // Sets test.id + const count = internals.count(experiments, { filters: filters }); // Sets test.id reporter.start({ count: count }); - var startTime = Date.now(); - var state = { + const startTime = Date.now(); + const state = { report: { tests: [], failures: 0, @@ -142,9 +144,9 @@ exports.execute = function (scripts, options, reporter, callback) { options: settings }; - internals.executeExperiments(experiments, state, settings.dry, function () { + internals.executeExperiments(experiments, state, settings.dry, () => { - var notebook = { + const notebook = { ms: Date.now() - startTime, tests: state.report.tests, failures: state.report.failures, @@ -158,14 +160,14 @@ exports.execute = function (scripts, options, reporter, callback) { internals.executeExperiments = function (experiments, state, skip, callback) { - Items.serial(experiments, function (experiment, nextExperiment) { + Items.serial(experiments, (experiment, nextExperiment) => { // Create a new domains context for this level of experiments, keep the old ones to restore them when finishing - var previousDomains = state.domains; + const previousDomains = state.domains; state.domains = []; - var skipExperiment = skip || experiment.options.skip; - var steps = [ + const skipExperiment = skip || experiment.options.skip; + const steps = [ function (next) { // Before @@ -174,7 +176,7 @@ internals.executeExperiments = function (experiments, state, skip, callback) { return next(); } - internals.executeDeps(experiment.befores, state, function (err) { + internals.executeDeps(experiment.befores, state, (err) => { if (err) { internals.fail([experiment], state, skip, '\'before\' action failed'); @@ -207,7 +209,7 @@ internals.executeExperiments = function (experiments, state, skip, callback) { } ]; - Items.serial(steps, function (item, next) { + Items.serial(steps, (item, next) => { item(next); }, @@ -236,7 +238,7 @@ internals.executeDeps = function (deps, state, callback) { return callback(); } - Items.serial(deps, function (dep, next) { + Items.serial(deps, (dep, next) => { dep.options.timeout = dep.options.timeout || state.options['context-timeout']; internals.protect(dep, state, next); @@ -252,15 +254,15 @@ internals.executeTests = function (experiment, state, skip, callback) { // Collect beforeEach and afterEach from parents - var befores = skip ? [] : internals.collectDeps(experiment, 'beforeEaches'); - var afters = skip ? [] : internals.collectDeps(experiment, 'afterEaches'); + const befores = skip ? [] : internals.collectDeps(experiment, 'beforeEaches'); + const afters = skip ? [] : internals.collectDeps(experiment, 'afterEaches'); // Separate serial and parallel execution tests - var serial = []; - var parallel = []; + const serial = []; + const parallel = []; - experiment.tests.forEach(function (test) { + experiment.tests.forEach((test) => { if (test.options.parallel || (test.options.parallel === undefined && state.options.parallel)) { @@ -274,7 +276,7 @@ internals.executeTests = function (experiment, state, skip, callback) { // Execute tests - var execute = function (test, nextTest) { + const execute = function (test, nextTest) { if ((state.filters.ids.length && state.filters.ids.indexOf(test.id) === -1) || (state.filters.grep && !state.filters.grep.test(test.title))) { @@ -282,12 +284,12 @@ internals.executeTests = function (experiment, state, skip, callback) { return nextTest(); } - var steps = [ + const steps = [ function (next) { // Before each - internals.executeDeps(befores, state, function (err) { + internals.executeDeps(befores, state, (err) => { if (err) { internals.failTest(test, state, skip, '\'before each\' action failed'); @@ -311,8 +313,8 @@ internals.executeTests = function (experiment, state, skip, callback) { return setImmediate(next); } - var start = Date.now(); - internals.protect(test, state, function (err) { + const start = Date.now(); + internals.protect(test, state, (err) => { if (err) { state.report.failures++; @@ -335,7 +337,7 @@ internals.executeTests = function (experiment, state, skip, callback) { } ]; - Items.serial(steps, function (item, next) { + Items.serial(steps, (item, next) => { item(next); }, @@ -349,9 +351,9 @@ internals.executeTests = function (experiment, state, skip, callback) { }); }; - Items.serial(serial, execute, function (err) { + Items.serial(serial, execute, (err) => { - Items.parallel(parallel, execute, function () { + Items.parallel(parallel, execute, () => { return callback(err); }); @@ -361,10 +363,10 @@ internals.executeTests = function (experiment, state, skip, callback) { internals.collectDeps = function (experiment, key) { - var set = []; + const set = []; // if we are looking at afterEaches, we want to run our parent's blocks before ours (unshift onto front) - var arrayAddFn = key === 'afterEaches' ? Array.prototype.unshift : Array.prototype.push; + const arrayAddFn = key === 'afterEaches' ? Array.prototype.unshift : Array.prototype.push; if (experiment.parent) { arrayAddFn.apply(set, internals.collectDeps(experiment.parent, key)); @@ -377,18 +379,27 @@ internals.collectDeps = function (experiment, key) { internals.protect = function (item, state, callback) { - var isFirst = true; + let isFirst = true; + let timeoutId; - var activeDomain = Domain.active; + const activeDomain = Domain.active; // We need to keep a reference to the list of domains at the time of the call since those will change with nested // experiments. - var domains = state.domains; + const domains = state.domains; + + const finish = function (err, cause) { - var finish = function (err, cause) { + if (err && + err instanceof Error === false) { + + const data = err; + err = new Error('Non Error object received or caught'); + err.data = data; + } if (!isFirst) { - var message = 'Multiple callbacks or thrown errors received in test "' + item.title + '" (' + cause + ')'; + const message = 'Multiple callbacks or thrown errors received in test "' + item.title + '" (' + cause + ')'; if (err && !/^Multiple callbacks/.test(err.message)) { err.message = message + ': ' + err.message; @@ -404,7 +415,7 @@ internals.protect = function (item, state, callback) { isFirst = false; clearTimeout(timeoutId); - var immed = setImmediate(function () { + const immed = setImmediate(() => { return callback(err); }); @@ -419,17 +430,17 @@ internals.protect = function (item, state, callback) { /* $lab:coverage:on$ */ }; - var ms = item.options.timeout !== undefined ? item.options.timeout : state.options.timeout; + const ms = item.options.timeout !== undefined ? item.options.timeout : state.options.timeout; if (ms) { - var timeoutId = setTimeout(function () { + timeoutId = setTimeout(() => { - var error = new Error('Timed out (' + ms + 'ms) - ' + item.title); + const error = new Error('Timed out (' + ms + 'ms) - ' + item.title); error.timeout = true; finish(error, 'timeout'); }, ms); } - var onError = function (err, isForward) { + const onError = function (err, isForward) { // 1. Do not forward what's already a forward. // 2. Only errors that reach before*/after* are worth forwarding, otherwise we know where they came from. @@ -444,15 +455,15 @@ internals.protect = function (item, state, callback) { finish(err, 'error'); }; - var domain = Domain.createDomain(); + const domain = Domain.createDomain(); domain.title = item.title; domain.on('error', onError); domains.push(domain); - setImmediate(function () { + setImmediate(() => { domain.enter(); - item.fn.call(null, function (err) { + item.fn.call(null, (err) => { finish(err, 'done'); }); @@ -463,8 +474,8 @@ internals.protect = function (item, state, callback) { internals.forwardError = function (err, sourceDomain, targetDomains) { - for (var s = 0, sl = targetDomains.length; s < sl; ++s) { - var d = targetDomains[s]; + for (let i = 0; i < targetDomains.length; ++i) { + const d = targetDomains[i]; if (d !== sourceDomain) { d.emit('error', err, true); // Add true to mark this as a forward. } @@ -477,11 +488,11 @@ internals.count = function (experiments, state) { state.count = state.count || 0; state.seq = state.seq || 0; - for (var e = 0, el = experiments.length; e < el; ++e) { - var experiment = experiments[e]; + for (let i = 0; i < experiments.length; ++i) { + const experiment = experiments[i]; - for (var i = 0, il = experiment.tests.length; i < il; ++i) { - var test = experiment.tests[i]; + for (let j = 0; j < experiment.tests.length; ++j) { + const test = experiment.tests[j]; test.id = ++state.seq; state.count += (state.filters.ids.length && state.filters.ids.indexOf(test.id) === -1) || (state.filters.grep && !state.filters.grep.test(test.title)) ? 0 : 1; } @@ -495,11 +506,11 @@ internals.count = function (experiments, state) { internals.fail = function (experiments, state, skip, err) { - for (var e = 0, el = experiments.length; e < el; ++e) { - var experiment = experiments[e]; + for (let i = 0; i < experiments.length; ++i) { + const experiment = experiments[i]; - for (var i = 0, il = experiment.tests.length; i < il; ++i) { - internals.failTest(experiment.tests[i], state, skip, err); + for (let j = 0; j < experiment.tests.length; ++j) { + internals.failTest(experiment.tests[j], state, skip, err); } internals.fail(experiment.experiments, state, skip || experiment.options.skip); diff --git a/lib/transform.js b/lib/transform.js old mode 100644 new mode 100755 index 06d19d88..d9e1f2fd --- a/lib/transform.js +++ b/lib/transform.js @@ -1,10 +1,12 @@ +'use strict'; + // Load modules -var Fs = require('fs'); +const Fs = require('fs'); // Declare internals -var internals = { +const internals = { fileCache: {}, transforms: [{ ext: '.js', transform: null }] }; @@ -14,7 +16,7 @@ internals.prime = function (extension) { require.extensions[extension] = function (localModule, filename) { - var src = Fs.readFileSync(filename, 'utf8'); + const src = Fs.readFileSync(filename, 'utf8'); return localModule._compile(exports.transform(filename, src), filename); }; }; @@ -23,7 +25,7 @@ internals.prime = function (extension) { exports.install = function (settings, primeFn) { if (Array.isArray(settings.transform)) { - settings.transform.forEach(function (element) { + settings.transform.forEach((element) => { if (element.ext === '.js') { internals.transforms[0].transform = element.transform; @@ -38,7 +40,7 @@ exports.install = function (settings, primeFn) { primeFn = internals.prime; } - internals.transforms.forEach(function (transform) { + internals.transforms.forEach((transform) => { primeFn(transform.ext); }); @@ -47,10 +49,10 @@ exports.install = function (settings, primeFn) { exports.transform = function (filename, content) { - var ext = ''; - var transform = null; + let ext = ''; + let transform = null; - internals.transforms.forEach(function (element) { + internals.transforms.forEach((element) => { ext = element.ext; if (filename.indexOf(ext, filename.length - ext.length) !== -1) { @@ -58,7 +60,7 @@ exports.transform = function (filename, content) { } }); - var relativeFilename = filename.substr(process.cwd().length + 1); + const relativeFilename = filename.substr(process.cwd().length + 1); internals.fileCache[relativeFilename] = (typeof transform === 'function') ? transform(content, relativeFilename) : content; return internals.fileCache[relativeFilename]; }; @@ -66,13 +68,13 @@ exports.transform = function (filename, content) { exports.retrieveFile = function (path) { - var cwd = process.cwd(); - var cacheKey = path.indexOf(cwd) === 0 ? path.substr(cwd.length + 1) : path; + const cwd = process.cwd(); + const cacheKey = path.indexOf(cwd) === 0 ? path.substr(cwd.length + 1) : path; if (internals.fileCache[cacheKey]) { return internals.fileCache[cacheKey]; } - var contents = null; + let contents = null; try { contents = Fs.readFileSync(path, 'utf8'); } diff --git a/lib/utils.js b/lib/utils.js index b82b2924..7d363409 100755 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,24 +1,26 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.mergeOptions = function (parent, child, ignore) { ignore = ignore || []; - var options = {}; + const options = {}; - Object.keys(parent || {}).forEach(function (key) { + Object.keys(parent || {}).forEach((key) => { if (ignore.indexOf(key) === -1) { options[key] = parent[key]; } }); - Object.keys(child || {}).forEach(function (key) { + Object.keys(child || {}).forEach((key) => { options[key] = child[key]; }); @@ -29,7 +31,7 @@ exports.mergeOptions = function (parent, child, ignore) { exports.applyOptions = function (parent, child) { - Object.keys(child).forEach(function (key) { + Object.keys(child).forEach((key) => { parent[key] = child[key]; }); diff --git a/package.json b/package.json index 650255a2..b52d8f25 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "eslint-plugin-hapi": "1.x.x", "espree": "2.x.x", "handlebars": "4.x.x", - "hoek": "2.x.x", + "hoek": "3.x.x", "items": "1.x.x", "json-stringify-safe": "5.x.x", "mkdirp": "0.5.x", @@ -28,7 +28,7 @@ "jslint": "0.9.x" }, "devDependencies": { - "code": "1.x.x", + "code": "2.x.x", "cpr": "0.4.x", "lab-event-reporter": "1.x.x", "rimraf": "2.4.x" diff --git a/test/cli.js b/test/cli.js index 80ced7a5..52ca4fe7 100755 --- a/test/cli.js +++ b/test/cli.js @@ -1,47 +1,49 @@ +'use strict'; + // Load modules -var ChildProcess = require('child_process'); -var Fs = require('fs'); -var Path = require('path'); -var Code = require('code'); -var Lab = require('../'); -var Pkg = require('../package.json'); -var _Lab = require('../test_runner'); +const ChildProcess = require('child_process'); +const Fs = require('fs'); +const Path = require('path'); +const Code = require('code'); +const Lab = require('../'); +const Pkg = require('../package.json'); +const _Lab = require('../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('CLI', function () { +describe('CLI', () => { - var labPath = Path.join(__dirname, '..', 'bin', '_lab'); + const labPath = Path.join(__dirname, '..', 'bin', '_lab'); - it('runs a single test from the command line', function (done) { + it('runs a single test from the command line', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-m', '2000']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-m', '2000']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -50,22 +52,22 @@ describe('CLI', function () { }); }); - it('runs multiple tests from the command line', function (done) { + it('runs multiple tests from the command line', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', 'test/cli/simple2.js', '-m', '2000']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', 'test/cli/simple2.js', '-m', '2000']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -74,22 +76,22 @@ describe('CLI', function () { }); }); - it('runs a directory of tests from the command line', function (done) { + it('runs a directory of tests from the command line', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-m', '2000']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-m', '2000']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -98,63 +100,63 @@ describe('CLI', function () { }); }); - it('exits with code 1 when after function throws', function (done) { + it('exits with code 1 when after function throws', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_throws/throws.js']); - var outData = ''; - var errData = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_throws/throws.js']); + let outData = ''; + let errData = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { outData += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { errData += data; }); - cli.once('close', function (code) { + cli.once('close', (code, signal) => { expect(code).to.not.equal(0); done(); }); }); - it('exits with code 1 when function returns error with multiple reporters', function (done) { + it('exits with code 1 when function returns error with multiple reporters', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_failure/failure.js', '-r', 'console', '-r', 'lcov']); - var outData = ''; - var errData = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_failure/failure.js', '-r', 'console', '-r', 'lcov']); + let outData = ''; + let errData = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { outData += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { errData += data; }); - cli.once('close', function (code) { + cli.once('close', (code, signal) => { expect(code).to.not.equal(0); done(); }); }); - it('runs tests with multiple reporters', function (done) { + it('runs tests with multiple reporters', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-r', 'console', '-r', 'lcov']); - var outData = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-r', 'console', '-r', 'lcov']); + let outData = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { outData += data; }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -163,17 +165,17 @@ describe('CLI', function () { }); }); - it('runs tests with a custom reporter starting with .', function (done) { + it('runs tests with a custom reporter starting with .', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-r', './node_modules/lab-event-reporter/index.js']); - var outData = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-r', './node_modules/lab-event-reporter/index.js']); + let outData = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { outData += data; }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -182,17 +184,17 @@ describe('CLI', function () { }); }); - it('requires a custom reporter from node_modules', function (done) { + it('requires a custom reporter from node_modules', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-r', 'lab-event-reporter']); - var outData = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-r', 'lab-event-reporter']); + let outData = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { outData += data; }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -201,22 +203,22 @@ describe('CLI', function () { }); }); - it('displays error message when an unknown reporter is specified', function (done) { + it('displays error message when an unknown reporter is specified', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-r', 'unknown']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-r', 'unknown']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { output += data; }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.not.equal(0); expect(signal).to.not.exist(); @@ -225,40 +227,40 @@ describe('CLI', function () { }); }); - it('displays a domain\'s error stack (-D)', function (done) { + it('displays a domain\'s error stack (-D)', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_throws/debug.js', '--debug']); - var outData = ''; - var errData = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_throws/debug.js', '--debug']); + let outData = ''; + let errData = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { outData += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { errData += data; }); - cli.once('close', function (code) { + cli.once('close', (code, signal) => { expect(code).to.not.equal(0); done(); }); }); - it('shows the help (-h)', function (done) { + it('shows the help (-h)', (done) => { - var cli = ChildProcess.spawn('node', [labPath, '-h']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, '-h']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -267,17 +269,17 @@ describe('CLI', function () { }); }); - it('shows the version (-V)', function (done) { + it('shows the version (-V)', (done) => { - var cli = ChildProcess.spawn('node', [labPath, '-V']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, '-V']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -286,26 +288,26 @@ describe('CLI', function () { }); }); - it('ignores the list of predefined globals (-I)', function (done) { + it('ignores the list of predefined globals (-I)', (done) => { - var output = ''; - var scriptFile = 'global.foo = 1; global.bar = 2'; + let output = ''; + const scriptFile = 'global.foo = 1; global.bar = 2'; Fs.writeFileSync(Path.join(__dirname, 'cli', 'leaks.js'), scriptFile); - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/leaks.js', '-I', 'foo,bar']); + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/leaks.js', '-I', 'foo,bar']); - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -316,26 +318,26 @@ describe('CLI', function () { }); }); - it('ignores the list of predefined globals when using --ignore', function (done) { + it('ignores the list of predefined globals when using --ignore', (done) => { - var output = ''; - var scriptFile = 'global.foo = 1; global.bar = 2'; + let output = ''; + const scriptFile = 'global.foo = 1; global.bar = 2'; Fs.writeFileSync(Path.join(__dirname, 'cli', 'leaks.js'), scriptFile); - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/leaks.js', '--ignore', 'foo,bar']); + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/leaks.js', '--ignore', 'foo,bar']); - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -346,22 +348,22 @@ describe('CLI', function () { }); }); - it('silences output (-s)', function (done) { + it('silences output (-s)', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-s']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-s']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -370,22 +372,22 @@ describe('CLI', function () { }); }); - it('displays verbose output (-v)', function (done) { + it('displays verbose output (-v)', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-v']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-v']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -394,22 +396,22 @@ describe('CLI', function () { }); }); - it('runs a single test (-i 1)', function (done) { + it('runs a single test (-i 1)', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-i', '1']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-i', '1']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -418,23 +420,23 @@ describe('CLI', function () { }); }); - it('runs a range of tests (-i 3-4)', function (done) { + it('runs a range of tests (-i 3-4)', (done) => { // The range may need to adjust as new tests are added (if they are skipped for example) - var cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-i', '3-4']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli', '-i', '3-4']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -443,22 +445,22 @@ describe('CLI', function () { }); }); - it('runs in color mode with (-C)', function (done) { + it('runs in color mode with (-C)', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-C']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-C']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -467,22 +469,22 @@ describe('CLI', function () { }); }); - it('disables color output when tty doesn\'t support it', function (done) { + it('disables color output when tty doesn\'t support it', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -491,22 +493,22 @@ describe('CLI', function () { }); }); - it('defaults to color output when tty supports it', function (done) { + it('defaults to color output when tty supports it', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/simpleTty.js']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/simpleTty.js']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -515,22 +517,22 @@ describe('CLI', function () { }); }); - it('uses custom coverage path with the --coverage-path argument', function (done) { + it('uses custom coverage path with the --coverage-path argument', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_coverage', '-t', '100', '--coverage-path', 'test/cli_coverage/include', '-a', 'code']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_coverage', '-t', '100', '--coverage-path', 'test/cli_coverage/include', '-a', 'code']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -540,48 +542,48 @@ describe('CLI', function () { }); }); - it('uses custom coverage excludes with the --coverage-exclude argument', function (done) { + it('uses custom coverage excludes with the --coverage-exclude argument', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_coverage', '-t', '100', '--coverage-exclude', 'test/cli_coverage/exclude', '-a', 'code']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_coverage', '-t', '100', '--coverage-exclude', 'test/cli_coverage/exclude', '-a', 'code']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(1); expect(signal).to.not.exist(); expect(output).to.contain('1 tests complete'); - expect(output).to.contain('Coverage: 96.55% (1/29)'); + expect(output).to.contain('Coverage: 96.88% (1/32)'); expect(output).to.contain('test/cli_coverage/missing.js missing coverage on line(s)'); done(); }); }); - it('doesn\'t fail with coverage when no external file is being tested', function (done) { + it('doesn\'t fail with coverage when no external file is being tested', (done) => { - var cli = ChildProcess.spawn(labPath, ['test/cli/simple.js', '-t', '10']); - var output = ''; + const cli = ChildProcess.spawn(labPath, ['test/cli/simple.js', '-t', '10']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(1); expect(signal).to.not.exist(); @@ -591,22 +593,22 @@ describe('CLI', function () { }); }); - it('defaults NODE_ENV environment variable to test', function (done) { + it('defaults NODE_ENV environment variable to test', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/environment.js']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/environment.js']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -615,22 +617,22 @@ describe('CLI', function () { }); }); - it('changes the NODE_ENV based on -e param', function (done) { + it('changes the NODE_ENV based on -e param', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/environment.js', '-e', 'lab']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/environment.js', '-e', 'lab']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -639,22 +641,22 @@ describe('CLI', function () { }); }); - it('runs tests with "only" method when set and reports correct test count', function (done) { + it('runs tests with "only" method when set and reports correct test count', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/only.js']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/only.js']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -663,22 +665,22 @@ describe('CLI', function () { }); }); - it('overrides cli options using script', function (done) { + it('overrides cli options using script', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/override/cli.js']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/override/cli.js']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -687,22 +689,22 @@ describe('CLI', function () { }); }); - it('displays error message when a script is detected without an exports.lab', function (done) { + it('displays error message when a script is detected without an exports.lab', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_no_exports/missingExports.js']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_no_exports/missingExports.js']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(1); expect(signal).to.not.exist(); @@ -711,22 +713,22 @@ describe('CLI', function () { }); }); - it('displays error message when a script is missing exports and other scripts contain them', function (done) { + it('displays error message when a script is missing exports and other scripts contain them', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_no_exports/']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_no_exports/']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(1); expect(signal).to.not.exist(); @@ -735,23 +737,23 @@ describe('CLI', function () { }); }); - it('displays error message when an unknown argument is specified', function (done) { + it('displays error message when an unknown argument is specified', (done) => { - var cli = ChildProcess.spawn('node', [labPath, '-z']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, '-z']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { output += data; expect(data).to.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(1); expect(signal).to.not.exist(); @@ -760,22 +762,22 @@ describe('CLI', function () { }); }); - it('supports junit reporter', function (done) { + it('supports junit reporter', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/only.js', '-r', 'junit']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/only.js', '-r', 'junit']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -784,9 +786,9 @@ describe('CLI', function () { }); }); - it('outputs to file passed with -o argument', function (done) { + it('outputs to file passed with -o argument', (done) => { - var outputPath = __dirname + '/_no_exist'; + const outputPath = __dirname + '/_no_exist'; try { Fs.unlinkSync(outputPath); } @@ -795,47 +797,47 @@ describe('CLI', function () { // Error is ok here } - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-m', '2000', '-o', outputPath]); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-m', '2000', '-o', outputPath]); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); - var file = Fs.readFileSync(outputPath); + const file = Fs.readFileSync(outputPath); expect(file.toString()).to.contain('No global variable leaks detected'); Fs.unlinkSync(outputPath); done(); }); }); - it('loads assertions library', function (done) { + it('loads assertions library', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_assert/assert.js', '-m', '2000', '-a', 'code']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_assert/assert.js', '-m', '2000', '-a', 'code']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -844,22 +846,22 @@ describe('CLI', function () { }); }); - it('only loads files matching pattern (-P)', function (done) { + it('only loads files matching pattern (-P)', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_pattern', '-m', '2000', '-a', 'code', '-P', 'test']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_pattern', '-m', '2000', '-a', 'code', '-P', 'test']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -868,22 +870,22 @@ describe('CLI', function () { }); }); - it('only loads files matching pattern when pattern at beginning of name (-P)', function (done) { + it('only loads files matching pattern when pattern at beginning of name (-P)', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_pattern', '-m', '2000', '-a', 'code', '-P', 'file']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_pattern', '-m', '2000', '-a', 'code', '-P', 'file']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -892,22 +894,22 @@ describe('CLI', function () { }); }); - it('loads all files when pattern is empty (-P)', function (done) { + it('loads all files when pattern is empty (-P)', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli_pattern', '-m', '2000', '-a', 'code', '-P', '']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli_pattern', '-m', '2000', '-a', 'code', '-P', '']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -916,23 +918,23 @@ describe('CLI', function () { }); }); - it('errors out when unknown module is specified in transform option', function (done) { + it('errors out when unknown module is specified in transform option', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-T', 'not-a-transform-module']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-T', 'not-a-transform-module']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { output += data; expect(data).to.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.not.equal(0); expect(signal).to.not.exist(); @@ -940,23 +942,23 @@ describe('CLI', function () { }); }); - it('displays error message when transform module does not export', function (done) { + it('displays error message when transform module does not export', (done) => { - var cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-m', '2000', '-T', 'test/transform/exclude/lab-noexport']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, 'test/cli/simple.js', '-m', '2000', '-T', 'test/transform/exclude/lab-noexport']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { output += data; expect(data).to.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.not.equal(0); expect(signal).to.not.exist(); @@ -965,23 +967,23 @@ describe('CLI', function () { }); }); - it('uses transforms to run a test', function (done) { + it('uses transforms to run a test', (done) => { - var cli = ChildProcess.spawn('node', [labPath, '-T', 'test/transform/exclude/lab-transform', 'test/transform/exclude/transform-test.js']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, '-T', 'test/transform/exclude/lab-transform', 'test/transform/exclude/transform-test.js']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { output += data; expect(data).to.not.exist(); }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -990,22 +992,22 @@ describe('CLI', function () { }); }); - it('uses transforms to run a test file that has to be transformed', function (done) { + it('uses transforms to run a test file that has to be transformed', (done) => { - var cli = ChildProcess.spawn('node', [labPath, '-T', 'test/transform/exclude/lab-transform', 'test/transform/exclude/ext-test.new.js']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, '-T', 'test/transform/exclude/lab-transform', 'test/transform/exclude/ext-test.new.js']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { output += data; }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -1014,22 +1016,22 @@ describe('CLI', function () { }); }); - it('uses transforms to run a test file that has to be transformed with coverage support', function (done) { + it('uses transforms to run a test file that has to be transformed with coverage support', (done) => { - var cli = ChildProcess.spawn('node', [labPath, '-c', '-T', 'test/transform/exclude/lab-transform', 'test/transform/exclude/ext-test.new.js']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, '-c', '-T', 'test/transform/exclude/lab-transform', 'test/transform/exclude/ext-test.new.js']); + let output = ''; - cli.stdout.on('data', function (data) { + cli.stdout.on('data', (data) => { output += data; }); - cli.stderr.on('data', function (data) { + cli.stderr.on('data', (data) => { output += data; }); - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(0); expect(signal).to.not.exist(); @@ -1038,12 +1040,12 @@ describe('CLI', function () { }); }); - it('displays error message when multiple reporters with only one output are specified', function (done) { + it('displays error message when multiple reporters with only one output are specified', (done) => { - var cli = ChildProcess.spawn('node', [labPath, '-r', 'console', '-r', 'console', '-o', 'stdout']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, '-r', 'console', '-r', 'console', '-o', 'stdout']); + let output = ''; - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(1); expect(signal).to.not.exist(); @@ -1051,12 +1053,12 @@ describe('CLI', function () { }); }); - it('displays error message when multiple reporters with less outputs are specified', function (done) { + it('displays error message when multiple reporters with less outputs are specified', (done) => { - var cli = ChildProcess.spawn('node', [labPath, '-r', 'console', '-r', 'console', '-r', 'console', '-o', 'stdout', '-o', 'stdout']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, '-r', 'console', '-r', 'console', '-r', 'console', '-o', 'stdout', '-o', 'stdout']); + let output = ''; - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(1); expect(signal).to.not.exist(); @@ -1064,12 +1066,12 @@ describe('CLI', function () { }); }); - it('displays error message when multiple reporters with more outputs are specified', function (done) { + it('displays error message when multiple reporters with more outputs are specified', (done) => { - var cli = ChildProcess.spawn('node', [labPath, '-r', 'console', '-r', 'console', '-o', 'stdout', '-o', 'stdout', '-o', 'stdout']); - var output = ''; + const cli = ChildProcess.spawn('node', [labPath, '-r', 'console', '-r', 'console', '-o', 'stdout', '-o', 'stdout', '-o', 'stdout']); + let output = ''; - cli.once('close', function (code, signal) { + cli.once('close', (code, signal) => { expect(code).to.equal(1); expect(signal).to.not.exist(); diff --git a/test/cli/environment.js b/test/cli/environment.js index 2595b998..82611c83 100755 --- a/test/cli/environment.js +++ b/test/cli/environment.js @@ -1,21 +1,23 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../../test_runner'); +const Code = require('code'); +const _Lab = require('../../test_runner'); // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -var env = process.env.NODE_ENV; +const env = process.env.NODE_ENV; -describe('Test CLI', function () { +describe('Test CLI', () => { - it('Node Environment defaults to test', function (done) { + it('Node Environment defaults to test', (done) => { if (process.argv[3] && process.argv[3].indexOf('-e') >= 0) { expect(env).to.equal('lab'); diff --git a/test/cli/only.js b/test/cli/only.js index c5d22780..671d4c6f 100755 --- a/test/cli/only.js +++ b/test/cli/only.js @@ -1,34 +1,36 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../../test_runner'); +const Code = require('code'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Test CLI Not Only', function () { +describe('Test CLI Not Only', () => { - it('should not run', function (done) { + it('should not run', (done) => { throw new Error(); }); }); -describe.only('Test CLI Only', function () { +describe.only('Test CLI Only', () => { - it('should run', function (done) { + it('should run', (done) => { done(); }); diff --git a/test/cli/simple.js b/test/cli/simple.js index c5d1ea24..ecd63771 100755 --- a/test/cli/simple.js +++ b/test/cli/simple.js @@ -1,31 +1,33 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../../test_runner'); +const Code = require('code'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Test CLI', function () { +describe('Test CLI', () => { - it('adds two numbers together', function (done) { + it('adds two numbers together', (done) => { expect(1 + 1).to.equal(2); done(); }); - it('subtracts two numbers', function (done) { + it('subtracts two numbers', (done) => { expect(2 - 2).to.equal(0); done(); diff --git a/test/cli/simple2.js b/test/cli/simple2.js index 6b546d7b..0df2bf3a 100755 --- a/test/cli/simple2.js +++ b/test/cli/simple2.js @@ -1,31 +1,33 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../../test_runner'); +const Code = require('code'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Test CLI 2', function () { +describe('Test CLI 2', () => { - it('adds multiplies numbers together', function (done) { + it('adds multiplies numbers together', (done) => { expect(5 * 5).to.equal(25); done(); }); - it('divides two numbers', function (done) { + it('divides two numbers', (done) => { expect(25 / 5).to.equal(5); done(); diff --git a/test/cli/simpleTty.js b/test/cli/simpleTty.js index c773e74c..8fc984f1 100755 --- a/test/cli/simpleTty.js +++ b/test/cli/simpleTty.js @@ -1,21 +1,23 @@ +'use strict'; + // Load modules -var Tty = require('tty'); -var Code = require('code'); -var _Lab = require('../../test_runner'); +const Tty = require('tty'); +const Code = require('code'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; Tty.isatty = function () { @@ -24,15 +26,15 @@ Tty.isatty = function () { }; -describe('Test CLI', function () { +describe('Test CLI', () => { - it('adds two numbers together', function (done) { + it('adds two numbers together', (done) => { expect(1 + 1).to.equal(2); done(); }); - it('subtracts two numbers', function (done) { + it('subtracts two numbers', (done) => { expect(2 - 2).to.equal(0); done(); diff --git a/test/cli/test/simple.js b/test/cli/test/simple.js index 37fc65d1..a5d7274e 100755 --- a/test/cli/test/simple.js +++ b/test/cli/test/simple.js @@ -1,31 +1,33 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../../../test_runner'); +const Code = require('code'); +const _Lab = require('../../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Test CLI 3', function () { +describe('Test CLI 3', () => { - it('supports negative numbers', function (done) { + it('supports negative numbers', (done) => { expect(1 - 2).to.equal(-1); done(); }); - it('supports infinity', function (done) { + it('supports infinity', (done) => { expect(Infinity + 1).to.equal(Infinity); done(); diff --git a/test/cli_assert/assert.js b/test/cli_assert/assert.js index 984c8387..02087542 100755 --- a/test/cli_assert/assert.js +++ b/test/cli_assert/assert.js @@ -1,30 +1,32 @@ +'use strict'; + // Load modules -var _Lab = require('../../test_runner'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = _Lab.assertions.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = _Lab.assertions.expect; -describe('Test CLI', function () { +describe('Test CLI', () => { - it('adds two numbers together', function (done) { + it('adds two numbers together', (done) => { expect(1 + 1).to.equal(2); done(); }); - it('subtracts two numbers', function (done) { + it('subtracts two numbers', (done) => { expect(2 - 2).to.equal(0); done(); diff --git a/test/cli_coverage/exclude/exclude.js b/test/cli_coverage/exclude/exclude.js old mode 100644 new mode 100755 index 465b7d89..32594e8d --- a/test/cli_coverage/exclude/exclude.js +++ b/test/cli_coverage/exclude/exclude.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/cli_coverage/include/include.js b/test/cli_coverage/include/include.js old mode 100644 new mode 100755 index 465b7d89..32594e8d --- a/test/cli_coverage/include/include.js +++ b/test/cli_coverage/include/include.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/cli_coverage/missing.js b/test/cli_coverage/missing.js old mode 100644 new mode 100755 index 465b7d89..32594e8d --- a/test/cli_coverage/missing.js +++ b/test/cli_coverage/missing.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/cli_coverage/test/include.js b/test/cli_coverage/test/include.js old mode 100644 new mode 100755 index be77c7af..c8cb7dd6 --- a/test/cli_coverage/test/include.js +++ b/test/cli_coverage/test/include.js @@ -1,26 +1,28 @@ +'use strict'; + // Load modules -var _Lab = require('../../../test_runner'); -var Include = require('../include/include'); +const _Lab = require('../../../test_runner'); +const Include = require('../include/include'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = _Lab.assertions.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = _Lab.assertions.expect; -describe('Test CLI', function () { +describe('Test CLI', () => { - it('returns the specified value', function (done) { + it('returns the specified value', (done) => { - var result = Include.method('test'); + const result = Include.method('test'); expect(result).to.equal('test'); done(); }); diff --git a/test/cli_error/failure.js b/test/cli_error/failure.js old mode 100644 new mode 100755 index 9f91084c..5d05441f --- a/test/cli_error/failure.js +++ b/test/cli_error/failure.js @@ -1,25 +1,27 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../../test_runner'); +const Code = require('code'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Test CLI', function () { +describe('Test CLI', () => { - it('handles failure', function (done) { + it('handles failure', (done) => { done(new Error('fail')); }); diff --git a/test/cli_no_exports/hasExports.js b/test/cli_no_exports/hasExports.js index 8d8e0641..9f70bab2 100755 --- a/test/cli_no_exports/hasExports.js +++ b/test/cli_no_exports/hasExports.js @@ -1,25 +1,27 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../../test_runner'); +const Code = require('code'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Test CLI Exports', function () { +describe('Test CLI Exports', () => { - it('adds two numbers together', function (done) { + it('adds two numbers together', (done) => { expect(1 + 1).to.equal(2); done(); diff --git a/test/cli_no_exports/missingExports.js b/test/cli_no_exports/missingExports.js index dcd6f1b6..c254b65d 100755 --- a/test/cli_no_exports/missingExports.js +++ b/test/cli_no_exports/missingExports.js @@ -1,25 +1,27 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../../test_runner'); +const Code = require('code'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Test CLI', function () { +describe('Test CLI', () => { - it('adds two numbers together', function (done) { + it('adds two numbers together', (done) => { expect(1 + 1).to.equal(2); done(); diff --git a/test/cli_pattern/file-test-something.js b/test/cli_pattern/file-test-something.js old mode 100644 new mode 100755 index d98e1b75..3ca6503c --- a/test/cli_pattern/file-test-something.js +++ b/test/cli_pattern/file-test-something.js @@ -1,24 +1,26 @@ +'use strict'; + // Load modules -var _Lab = require('../../test_runner'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = _Lab.assertions.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = _Lab.assertions.expect; -describe('Test CLI', function () { +describe('Test CLI', () => { - it('adds two numbers together', function (done) { + it('adds two numbers together', (done) => { expect(1 + 1).to.equal(2); done(); diff --git a/test/cli_pattern/file-test.js b/test/cli_pattern/file-test.js old mode 100644 new mode 100755 index d98e1b75..3ca6503c --- a/test/cli_pattern/file-test.js +++ b/test/cli_pattern/file-test.js @@ -1,24 +1,26 @@ +'use strict'; + // Load modules -var _Lab = require('../../test_runner'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = _Lab.assertions.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = _Lab.assertions.expect; -describe('Test CLI', function () { +describe('Test CLI', () => { - it('adds two numbers together', function (done) { + it('adds two numbers together', (done) => { expect(1 + 1).to.equal(2); done(); diff --git a/test/cli_pattern/file.js b/test/cli_pattern/file.js old mode 100644 new mode 100755 index d98e1b75..3ca6503c --- a/test/cli_pattern/file.js +++ b/test/cli_pattern/file.js @@ -1,24 +1,26 @@ +'use strict'; + // Load modules -var _Lab = require('../../test_runner'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = _Lab.assertions.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = _Lab.assertions.expect; -describe('Test CLI', function () { +describe('Test CLI', () => { - it('adds two numbers together', function (done) { + it('adds two numbers together', (done) => { expect(1 + 1).to.equal(2); done(); diff --git a/test/cli_throws/debug.js b/test/cli_throws/debug.js old mode 100644 new mode 100755 index 39495e8b..8d00a2ee --- a/test/cli_throws/debug.js +++ b/test/cli_throws/debug.js @@ -1,31 +1,33 @@ +'use strict'; + // Load modules -var _Lab = require('../../test_runner'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var after = lab.after; -var describe = lab.describe; -var it = lab.it; +const lab = exports.lab = _Lab.script(); +const after = lab.after; +const describe = lab.describe; +const it = lab.it; -describe('Test CLI domain error debug', function () { +describe('Test CLI domain error debug', () => { - after(function (done) { + after((done) => { done(); }); - it('throws badly', function (done) { + it('throws badly', (done) => { - setTimeout(function () { + setTimeout(() => { throw new Error('throwing later'); }, 0); diff --git a/test/cli_throws/throws.js b/test/cli_throws/throws.js old mode 100644 new mode 100755 index 25150984..93eec5ec --- a/test/cli_throws/throws.js +++ b/test/cli_throws/throws.js @@ -1,29 +1,31 @@ +'use strict'; + // Load modules -var _Lab = require('../../test_runner'); +const _Lab = require('../../test_runner'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var after = lab.after; -var describe = lab.describe; -var it = lab.it; +const lab = exports.lab = _Lab.script(); +const after = lab.after; +const describe = lab.describe; +const it = lab.it; -describe('Test CLI throws', function () { +describe('Test CLI throws', () => { - after(function (done) { + after((done) => { throw new Error('throwing after'); }); - it('handles thrown error', function (done) { + it('handles thrown error', (done) => { done(); }); diff --git a/test/coverage.js b/test/coverage.js index 2019d27f..709f9cce 100755 --- a/test/coverage.js +++ b/test/coverage.js @@ -1,73 +1,75 @@ +'use strict'; + // Load modules -var Path = require('path'); -var Code = require('code'); -var _Lab = require('../test_runner'); -var Lab = require('../'); +const Path = require('path'); +const Code = require('code'); +const _Lab = require('../test_runner'); +const Lab = require('../'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Coverage', function () { +describe('Coverage', () => { Lab.coverage.instrument({ coveragePath: Path.join(__dirname, 'coverage'), coverageExclude: 'exclude' }); - it('instruments and measures coverage', function (done) { + it('instruments and measures coverage', (done) => { - var Test = require('./coverage/basic'); + const Test = require('./coverage/basic'); Test.method(1); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/basic') }); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/basic') }); expect(cov.percent).to.equal(100); done(); }); - it('measures coverage on an empty return statement', function (done) { + it('measures coverage on an empty return statement', (done) => { - var Test = require('./coverage/return'); + const Test = require('./coverage/return'); Test.method(); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/return') }); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/return') }); expect(cov.percent).to.equal(100); done(); }); - it('identifies lines with partial coverage', function (done) { + it('identifies lines with partial coverage', (done) => { - var Test = require('./coverage/partial'); + const Test = require('./coverage/partial'); Test.method(1, 2, 3); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/partial') }); - expect(Math.floor(cov.percent)).to.equal(62); - expect(cov.sloc).to.equal(51); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/partial') }); + expect(Math.floor(cov.percent)).to.equal(63); + expect(cov.sloc).to.equal(52); expect(cov.misses).to.equal(19); - expect(cov.hits).to.equal(32); + expect(cov.hits).to.equal(33); done(); }); - it('identifies lines with partial coverage when having external sourcemap', function (done) { + it('identifies lines with partial coverage when having external sourcemap', (done) => { - var Test = require('./coverage/sourcemaps-external'); + const Test = require('./coverage/sourcemaps-external'); Test.method(false); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/sourcemaps-external'), sourcemaps: true }); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/sourcemaps-external'), sourcemaps: true }); - var source = cov.files[0].source; - var missedLines = []; - Object.keys(source).forEach(function (lineNumber) { + const source = cov.files[0].source; + const missedLines = []; + Object.keys(source).forEach((lineNumber) => { - var line = source[lineNumber]; + const line = source[lineNumber]; if (line.miss) { missedLines.push({ filename: line.originalFilename, @@ -85,18 +87,18 @@ describe('Coverage', function () { done(); }); - it('identifies lines with partial coverage when having inline sourcemap', function (done) { + it('identifies lines with partial coverage when having inline sourcemap', (done) => { - var Test = require('./coverage/sourcemaps-inline'); + const Test = require('./coverage/sourcemaps-inline'); Test.method(false); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/sourcemaps-inline'), sourcemaps: true }); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/sourcemaps-inline'), sourcemaps: true }); - var source = cov.files[0].source; - var missedLines = []; - Object.keys(source).forEach(function (lineNumber) { + const source = cov.files[0].source; + const missedLines = []; + Object.keys(source).forEach((lineNumber) => { - var line = source[lineNumber]; + const line = source[lineNumber]; if (line.miss) { missedLines.push({ filename: line.originalFilename, @@ -114,44 +116,44 @@ describe('Coverage', function () { done(); }); - it('bypasses marked code', function (done) { + it('bypasses marked code', (done) => { - var Test = require('./coverage/bypass'); + const Test = require('./coverage/bypass'); Test.method(1, 2, 3); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/bypass') }); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/bypass') }); expect(Math.floor(cov.percent)).to.equal(100); - expect(cov.sloc).to.equal(15); + expect(cov.sloc).to.equal(16); expect(cov.misses).to.equal(0); - expect(cov.hits).to.equal(15); + expect(cov.hits).to.equal(16); done(); }); - it('ignores non-matching files', function (done) { + it('ignores non-matching files', (done) => { - var Test = require('./coverage/exclude/ignore'); + const Test = require('./coverage/exclude/ignore'); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/exclude/ignore') }); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/exclude/ignore') }); expect(Math.floor(cov.percent)).to.equal(0); expect(cov.files).to.have.length(0); done(); }); - it('measures missing while statement coverage', function (done) { + it('measures missing while statement coverage', (done) => { - var Test = require('./coverage/while'); + const Test = require('./coverage/while'); Test.method(false); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/while') }); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/while') }); expect(cov.percent).to.be.lessThan(100); done(); }); - it('measures when errors are thrown', function (done) { + it('measures when errors are thrown', (done) => { - var Test = require('./coverage/throws'); + const Test = require('./coverage/throws'); - var fn = function () { + const fn = function () { Test.method(true); Test.method(false); @@ -159,25 +161,25 @@ describe('Coverage', function () { expect(fn).to.throw(Error); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/throws') }); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/throws') }); expect(cov.percent).to.equal(100); done(); }); - it('retains original value of conditional result', function (done) { + it('retains original value of conditional result', (done) => { - var Test = require('./coverage/conditional'); - var value = { a: 1 }; + const Test = require('./coverage/conditional'); + const value = { a: 1 }; expect(Test.method(value)).to.equal(value); done(); }); - it('should not change use strict instructions', function (done) { + it('should not change use strict instructions', (done) => { - var Test = require('./coverage/use-strict.js'); + const Test = require('./coverage/use-strict.js'); expect(Test.method.toString()).to.not.contain('13'); // This is the line of the inner use strict - var testFile = Path.join(__dirname, 'coverage/use-strict.js'); + const testFile = Path.join(__dirname, 'coverage/use-strict.js'); expect(Test.singleLine.toString()).to.contain('"use strict"; global.__$$labCov._line(\'' + testFile + '\',19);return value;'); expect(Test.shouldFail).to.throw('unknownvar is not defined'); @@ -185,19 +187,19 @@ describe('Coverage', function () { done(); }); - it('should work with loop labels', function (done) { + it('should work with loop labels', (done) => { - var Test = require('./coverage/loop-labels.js'); + const Test = require('./coverage/loop-labels.js'); expect(Test.method()).to.deep.equal([1, 0]); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/loop-labels') }); - var source = cov.files[0].source; - var missedChunks = []; - Object.keys(source).forEach(function (lineNumber) { + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/loop-labels') }); + const source = cov.files[0].source; + const missedChunks = []; + Object.keys(source).forEach((lineNumber) => { - var line = source[lineNumber]; + const line = source[lineNumber]; if (line.miss) { - missedChunks.push.apply(missedChunks, line.chunks.filter(function (chunk) { + missedChunks.push.apply(missedChunks, line.chunks.filter((chunk) => { return !!chunk.miss; })); @@ -209,19 +211,19 @@ describe('Coverage', function () { done(); }); - describe('#analyze', function () { + describe('#analyze', () => { - it('sorts file paths in report', function (done) { + it('sorts file paths in report', (done) => { - var files = global.__$$labCov.files; - var paths = ['/a/b', '/a/b/c', '/a/c/b', '/a/c', '/a/b/c', '/a/b/a']; - paths.forEach(function (path) { + const files = global.__$$labCov.files; + const paths = ['/a/b', '/a/b/c', '/a/c/b', '/a/c', '/a/b/c', '/a/b/a']; + paths.forEach((path) => { files[path] = { source: [] }; }); - var cov = Lab.coverage.analyze({ coveragePath: '/a' }); - var sorted = cov.files.map(function (file) { + const cov = Lab.coverage.analyze({ coveragePath: '/a' }); + const sorted = cov.files.map((file) => { return file.filename; }); diff --git a/test/coverage/basic.js b/test/coverage/basic.js index 465b7d89..32594e8d 100755 --- a/test/coverage/basic.js +++ b/test/coverage/basic.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/coverage/bypass.js b/test/coverage/bypass.js index de3fb37b..2ea10026 100755 --- a/test/coverage/bypass.js +++ b/test/coverage/bypass.js @@ -1,15 +1,17 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (a, b, c) { // $lab:coverage:off$ - var d = 0; + let d = 0; if (a) { /* $lab:coverage:off$ */ d += 1; } diff --git a/test/coverage/clover.js b/test/coverage/clover.js index 7678508f..446d96ac 100755 --- a/test/coverage/clover.js +++ b/test/coverage/clover.js @@ -1,14 +1,16 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (a, b, c) { - var d = 0; + let d = 0; if (a) { d += 1; } diff --git a/test/coverage/conditional.js b/test/coverage/conditional.js index 64ab6882..6186041c 100755 --- a/test/coverage/conditional.js +++ b/test/coverage/conditional.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/coverage/console-full.js b/test/coverage/console-full.js index 465b7d89..32594e8d 100755 --- a/test/coverage/console-full.js +++ b/test/coverage/console-full.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/coverage/console.js b/test/coverage/console.js index 7678508f..446d96ac 100755 --- a/test/coverage/console.js +++ b/test/coverage/console.js @@ -1,14 +1,16 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (a, b, c) { - var d = 0; + let d = 0; if (a) { d += 1; } diff --git a/test/coverage/exclude/ignore.js b/test/coverage/exclude/ignore.js index 465b7d89..32594e8d 100755 --- a/test/coverage/exclude/ignore.js +++ b/test/coverage/exclude/ignore.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/coverage/html-lint/html-lint.1.js b/test/coverage/html-lint/html-lint.1.js index b96b24cb..532a8000 100755 --- a/test/coverage/html-lint/html-lint.1.js +++ b/test/coverage/html-lint/html-lint.1.js @@ -1,14 +1,16 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (a, b, c) { - var d = 0; + let d = 0; if (a) { d += 1; } diff --git a/test/coverage/html-lint/html-lint.2.js b/test/coverage/html-lint/html-lint.2.js index 59c7417a..7e55fe08 100755 --- a/test/coverage/html-lint/html-lint.2.js +++ b/test/coverage/html-lint/html-lint.2.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (a, b, c) { diff --git a/test/coverage/html.js b/test/coverage/html.js index 7678508f..446d96ac 100755 --- a/test/coverage/html.js +++ b/test/coverage/html.js @@ -1,14 +1,16 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (a, b, c) { - var d = 0; + let d = 0; if (a) { d += 1; } diff --git a/test/coverage/json.js b/test/coverage/json.js index 465b7d89..32594e8d 100755 --- a/test/coverage/json.js +++ b/test/coverage/json.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/coverage/loop-labels.js b/test/coverage/loop-labels.js old mode 100644 new mode 100755 index 87cfd229..ded1f5af --- a/test/coverage/loop-labels.js +++ b/test/coverage/loop-labels.js @@ -1,15 +1,19 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function () { + let i = 0; + let j = 0; - outer: for (var i = 0; i < 1; ++i) { - inner: for (var j = 0; j < 1; ++j) { + outer: for (; i < 1; ++i) { + inner: for (; j < 1; ++j) { continue outer; } } diff --git a/test/coverage/partial.js b/test/coverage/partial.js index 38786ba3..7372f590 100755 --- a/test/coverage/partial.js +++ b/test/coverage/partial.js @@ -1,14 +1,16 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (a, b, c) { - var d = 0; + let d = 0; if (a) { d += 1; } @@ -16,9 +18,9 @@ exports.method = function (a, b, c) { d += 1; } - var e = (a ? b : c); + const e = (a ? b : c); - var f; + let f; if (e) f = 0; else @@ -26,13 +28,13 @@ exports.method = function (a, b, c) { while (false)++f; - var g = 0; + let g = 0; label: while (g > 3) { ++g; } - var h = false || a; + const h = false || a; - for (var i = 0; + for (let i = 0; i < 3; ++i) { @@ -47,24 +49,24 @@ exports.method = function (a, b, c) { ++a; } - var n = false ? + const n = false ? a + b : 0; - var j = [1, 2, 3]; - var l = 0; - for (var k in j) { + const j = [1, 2, 3]; + let l = 0; + for (let k in j) { ++l; } - for (var o of j) { + for (let o of j) { ++l; } - var m = (a ? b : c) || (c ? d : e); + const m = (a ? b : c) || (c ? d : e); return d + (a || b || c); }; diff --git a/test/coverage/reset.js b/test/coverage/reset.js index 7678508f..446d96ac 100755 --- a/test/coverage/reset.js +++ b/test/coverage/reset.js @@ -1,14 +1,16 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (a, b, c) { - var d = 0; + let d = 0; if (a) { d += 1; } diff --git a/test/coverage/return.js b/test/coverage/return.js old mode 100644 new mode 100755 index 89caa6bf..d53831eb --- a/test/coverage/return.js +++ b/test/coverage/return.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function () { diff --git a/test/coverage/sourcemaps-covered.js b/test/coverage/sourcemaps-covered.js old mode 100644 new mode 100755 index 789123e5..59821a3d --- a/test/coverage/sourcemaps-covered.js +++ b/test/coverage/sourcemaps-covered.js @@ -1,6 +1,6 @@ -"use strict"; -var __moduleName = "basic"; -var internals = {}; +'use strict'; +const __moduleName = 'basic'; +const internals = {}; exports.method = function(value) { return value; }; diff --git a/test/coverage/sourcemaps-covered.map b/test/coverage/sourcemaps-covered.map old mode 100644 new mode 100755 index ef6dcbe0..3085e11b --- a/test/coverage/sourcemaps-covered.map +++ b/test/coverage/sourcemaps-covered.map @@ -1 +1 @@ -{"version":3,"file":"sourcemaps-covered.js","sources":["@traceur/generated/TemplateParser/1","basic"],"names":[],"mappings":";AAAA,AAAI,EAAA,CAAA,YAAW,UAAoB,CAAC;ACKpC,AAAI,EAAA,CAAA,SAAQ,EAAI,GAAC,CAAC;AAGlB,MAAM,OAAO,EAAI,UAAU,KAAI,CAAG;AAEjC,OAAO,MAAI,CAAC;AACb,CAAC","sourceRoot":"/home/ubuntu/workspace/test/coverage/","sourcesContent":["var __moduleName = $__placeholder__0;","// Load modules\n\n\n// Declare internals\n\nvar internals = {};\n\n\nexports.method = function (value) {\n\n\treturn value;\n};"]} \ No newline at end of file +{"version":3,"file":"sourcemaps-covered.js","sources":["@traceur/generated/TemplateParser/1","basic"],"names":[],"mappings":";AAAA,AAAI,EAAA,CAAA,YAAW,UAAoB,CAAC;ACKpC,AAAI,EAAA,CAAA,SAAQ,EAAI,GAAC,CAAC;AAGlB,MAAM,OAAO,EAAI,UAAU,KAAI,CAAG;AAEjC,OAAO,MAAI,CAAC;AACb,CAAC","sourceRoot":"/home/ubuntu/workspace/test/coverage/","sourcesContent":["const __moduleName = $__placeholder__0;","// Load modules\n\n\n// Declare internals\n\nvar internals = {};\n\n\nexports.method = function (value) {\n\n\treturn value;\n};"]} \ No newline at end of file diff --git a/test/coverage/sourcemaps-external.js b/test/coverage/sourcemaps-external.js old mode 100644 new mode 100755 index e52fa7d7..4d993eff --- a/test/coverage/sourcemaps-external.js +++ b/test/coverage/sourcemaps-external.js @@ -1,6 +1,6 @@ -"use strict"; -var __moduleName = "while"; -var internals = {}; +'use strict'; +const __moduleName = 'while'; +const internals = {}; exports.method = function(value) { while (value) { value = false; diff --git a/test/coverage/sourcemaps-external.map b/test/coverage/sourcemaps-external.map old mode 100644 new mode 100755 index a8ffb641..af80c229 --- a/test/coverage/sourcemaps-external.map +++ b/test/coverage/sourcemaps-external.map @@ -1 +1 @@ -{"version":3,"sources":["@traceur/generated/TemplateParser/1","./while.js"],"names":[],"mappings":";AAAA,AAAI,EAAA,CAAA,YAAW,UAAoB,CAAC;ACKpC,AAAI,EAAA,CAAA,SAAQ,EAAI,GAAC,CAAC;AAGlB,MAAM,OAAO,EAAI,UAAU,KAAI,CAAG;AAE9B,QAAM,KAAI,CAAG;AACT,QAAI,EAAI,MAAI,CAAC;EACjB;AAAA,AAEA,OAAO,MAAI,CAAC;AAChB,CAAC","sourcesContent":["var __moduleName = $__placeholder__0;","// Load modules\n\n\n// Declare internals\n\nvar internals = {};\n\n\nexports.method = function (value) {\n\n while(value) {\n value = false;\n }\n\n return value;\n};\n"]} \ No newline at end of file +{"version":3,"sources":["@traceur/generated/TemplateParser/1","./while.js"],"names":[],"mappings":";AAAA,AAAI,EAAA,CAAA,YAAW,UAAoB,CAAC;ACKpC,AAAI,EAAA,CAAA,SAAQ,EAAI,GAAC,CAAC;AAGlB,MAAM,OAAO,EAAI,UAAU,KAAI,CAAG;AAE9B,QAAM,KAAI,CAAG;AACT,QAAI,EAAI,MAAI,CAAC;EACjB;AAAA,AAEA,OAAO,MAAI,CAAC;AAChB,CAAC","sourcesContent":["const __moduleName = $__placeholder__0;","// Load modules\n\n\n// Declare internals\n\nvar internals = {};\n\n\nexports.method = function (value) {\n\n while(value) {\n value = false;\n }\n\n return value;\n};\n"]} \ No newline at end of file diff --git a/test/coverage/sourcemaps-inline.js b/test/coverage/sourcemaps-inline.js old mode 100644 new mode 100755 index 5e289dae..c2dd773f --- a/test/coverage/sourcemaps-inline.js +++ b/test/coverage/sourcemaps-inline.js @@ -1,6 +1,6 @@ -"use strict"; -var __moduleName = "while"; -var internals = {}; +'use strict'; +const __moduleName = 'while'; +const internals = {}; exports.method = function(value) { while (value) { value = false; diff --git a/test/coverage/throws.js b/test/coverage/throws.js old mode 100644 new mode 100755 index 6d454720..7b923319 --- a/test/coverage/throws.js +++ b/test/coverage/throws.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/coverage/use-strict.js b/test/coverage/use-strict.js old mode 100644 new mode 100755 index b9c7eed1..0fb25901 --- a/test/coverage/use-strict.js +++ b/test/coverage/use-strict.js @@ -1,11 +1,11 @@ -"use strict"; +'use strict'; // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/coverage/while.js b/test/coverage/while.js old mode 100644 new mode 100755 index 1b1143e6..25e054c5 --- a/test/coverage/while.js +++ b/test/coverage/while.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/index.js b/test/index.js index 0cb65ed2..ba4e6312 100755 --- a/test/index.js +++ b/test/index.js @@ -1,51 +1,53 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../test_runner'); -var Lab = require('../'); +const Code = require('code'); +const _Lab = require('../test_runner'); +const Lab = require('../'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Lab', function () { +describe('Lab', () => { - it('creates a script and executes', function (done) { + it('creates a script and executes', (done) => { - var a = 0; - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + let a = 0; + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.before(function (testDone) { + script.before((testDone) => { ++a; testDone(); }); - script.test('value of a', function (testDone) { + script.test('value of a', (testDone) => { expect(a).to.equal(1); testDone(); }); - script.after(function (testDone) { + script.after((testDone) => { ++a; testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(a).to.equal(2); expect(notebook.tests).to.have.length(1); @@ -55,32 +57,32 @@ describe('Lab', function () { }); }); - it('creates a script and executes (BDD)', function (done) { + it('creates a script and executes (BDD)', (done) => { - var a = 0; - var script = Lab.script({ schedule: false }); - script.describe('test', function () { + let a = 0; + const script = Lab.script({ schedule: false }); + script.describe('test', () => { - script.before(function (testDone) { + script.before((testDone) => { ++a; testDone(); }); - script.it('value of a', function (testDone) { + script.it('value of a', (testDone) => { expect(a).to.equal(1); testDone(); }); - script.after(function (testDone) { + script.after((testDone) => { ++a; testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(a).to.equal(2); expect(notebook.tests).to.have.length(1); @@ -89,32 +91,32 @@ describe('Lab', function () { }); }); - it('creates a script and executes (TDD)', function (done) { + it('creates a script and executes (TDD)', (done) => { - var a = 0; - var script = Lab.script({ schedule: false }); - script.suite('test', function () { + let a = 0; + const script = Lab.script({ schedule: false }); + script.suite('test', () => { - script.before(function (testDone) { + script.before((testDone) => { ++a; testDone(); }); - script.test('value of a', function (testDone) { + script.test('value of a', (testDone) => { expect(a).to.equal(1); testDone(); }); - script.after(function (testDone) { + script.after((testDone) => { ++a; testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(a).to.equal(2); expect(notebook.tests).to.have.length(1); @@ -123,53 +125,53 @@ describe('Lab', function () { }); }); - it('executes beforeEach and afterEach', function (done) { + it('executes beforeEach and afterEach', (done) => { - var a = 0; - var b = 0; - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + let a = 0; + let b = 0; + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.before(function (testDone) { + script.before((testDone) => { ++a; testDone(); }); - script.beforeEach(function (testDone) { + script.beforeEach((testDone) => { ++b; testDone(); }); - script.test('value of a', function (testDone) { + script.test('value of a', (testDone) => { expect(a).to.equal(1); expect(b).to.equal(1); testDone(); }); - script.test('value of b', function (testDone) { + script.test('value of b', (testDone) => { expect(a).to.equal(1); expect(b).to.equal(3); testDone(); }); - script.after(function (testDone) { + script.after((testDone) => { ++a; testDone(); }); - script.afterEach(function (testDone) { + script.afterEach((testDone) => { ++b; testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(a).to.equal(2); expect(b).to.equal(4); @@ -179,77 +181,77 @@ describe('Lab', function () { }); }); - it('executes multiple pre/post processors', function (done) { + it('executes multiple pre/post processors', (done) => { - var a = 0; - var b = 0; - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + let a = 0; + let b = 0; + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.before(function (testDone) { + script.before((testDone) => { ++a; testDone(); }); - script.before(function (testDone) { + script.before((testDone) => { ++a; testDone(); }); - script.beforeEach(function (testDone) { + script.beforeEach((testDone) => { ++b; testDone(); }); - script.beforeEach(function (testDone) { + script.beforeEach((testDone) => { ++b; testDone(); }); - script.test('value of a', function (testDone) { + script.test('value of a', (testDone) => { expect(a).to.equal(2); expect(b).to.equal(2); testDone(); }); - script.test('value of b', function (testDone) { + script.test('value of b', (testDone) => { expect(a).to.equal(2); expect(b).to.equal(6); testDone(); }); - script.after(function (testDone) { + script.after((testDone) => { ++a; testDone(); }); - script.after(function (testDone) { + script.after((testDone) => { ++a; testDone(); }); - script.afterEach(function (testDone) { + script.afterEach((testDone) => { ++b; testDone(); }); - script.afterEach(function (testDone) { + script.afterEach((testDone) => { ++b; testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(a).to.equal(4); expect(b).to.equal(8); @@ -259,19 +261,19 @@ describe('Lab', function () { }); }); - it('reports errors', function (done) { + it('reports errors', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { expect(0).to.equal(1); testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(1); expect(notebook.failures).to.equal(1); @@ -279,26 +281,26 @@ describe('Lab', function () { }); }); - it('multiple experiments', function (done) { + it('multiple experiments', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment('test2', function () { + script.experiment('test2', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].id).to.equal(1); @@ -308,44 +310,44 @@ describe('Lab', function () { }); }); - it('nested experiments', function (done) { + it('nested experiments', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('a', function (testDone) { + script.test('a', (testDone) => { testDone(); }); - script.experiment('test2', function () { + script.experiment('test2', () => { - script.test('b', function (testDone) { + script.test('b', (testDone) => { testDone(); }); }); - script.test('c', function (testDone) { + script.test('c', (testDone) => { testDone(); }); - script.experiment('test3', function () { + script.experiment('test3', () => { - script.test('d', function (testDone) { + script.test('d', (testDone) => { testDone(); }); }); - script.test('e', function (testDone) { + script.test('e', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(5); expect(notebook.tests[0].id).to.equal(1); @@ -355,26 +357,26 @@ describe('Lab', function () { }); }); - it('skips experiment', function (done) { + it('skips experiment', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment('test2', { skip: true }, function () { + script.experiment('test2', { skip: true }, () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.not.exist(); @@ -384,26 +386,26 @@ describe('Lab', function () { }); }); - it('skips experiment using helper (2 args)', function (done) { + it('skips experiment using helper (2 args)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment.skip('test2', function () { + script.experiment.skip('test2', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.not.exist(); @@ -413,26 +415,26 @@ describe('Lab', function () { }); }); - it('skips experiment using helper (3 args)', function (done) { + it('skips experiment using helper (3 args)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment.skip('test2', {}, function () { + script.experiment.skip('test2', {}, () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.not.exist(); @@ -442,26 +444,26 @@ describe('Lab', function () { }); }); - it('runs only one experiment (only first)', function (done) { + it('runs only one experiment (only first)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', { only: true }, function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', { only: true }, () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment('test2', function () { + script.experiment('test2', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.not.exist(); @@ -471,26 +473,26 @@ describe('Lab', function () { }); }); - it('runs only one experiment (only not first)', function (done) { + it('runs only one experiment (only not first)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment('test2', { only: true }, function () { + script.experiment('test2', { only: true }, () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.equal(true); @@ -500,26 +502,26 @@ describe('Lab', function () { }); }); - it('runs only one experiment using helper (2 args)', function (done) { + it('runs only one experiment using helper (2 args)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment.only('test2', function () { + script.experiment.only('test2', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.equal(true); @@ -529,26 +531,26 @@ describe('Lab', function () { }); }); - it('runs only one experiment using helper (3 args)', function (done) { + it('runs only one experiment using helper (3 args)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment.only('test2', {}, function () { + script.experiment.only('test2', {}, () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.equal(true); @@ -558,26 +560,26 @@ describe('Lab', function () { }); }); - it('skips test', function (done) { + it('skips test', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment('test2', function () { + script.experiment('test2', () => { - script.test('works', { skip: true }, function (testDone) { + script.test('works', { skip: true }, (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.not.exist(); @@ -587,26 +589,26 @@ describe('Lab', function () { }); }); - it('skips test using helper (2 args)', function (done) { + it('skips test using helper (2 args)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment('test2', function () { + script.experiment('test2', () => { - script.test.skip('works', function (testDone) { + script.test.skip('works', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.not.exist(); @@ -616,26 +618,26 @@ describe('Lab', function () { }); }); - it('skips test using helper (3 args)', function (done) { + it('skips test using helper (3 args)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - script.experiment('test2', function () { + script.experiment('test2', () => { - script.test.skip('works', {}, function (testDone) { + script.test.skip('works', {}, (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.not.exist(); @@ -645,23 +647,23 @@ describe('Lab', function () { }); }); - it('runs only one test (only first)', function (done) { + it('runs only one test (only first)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('a', { only: true }, function (testDone) { + script.test('a', { only: true }, (testDone) => { testDone(); }); - script.test('b', function (testDone) { + script.test('b', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.not.exist(); @@ -671,23 +673,23 @@ describe('Lab', function () { }); }); - it('runs only one test (only not first)', function (done) { + it('runs only one test (only not first)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('a', function (testDone) { + script.test('a', (testDone) => { testDone(); }); - script.test('b', { only: true }, function (testDone) { + script.test('b', { only: true }, (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.equal(true); @@ -697,23 +699,23 @@ describe('Lab', function () { }); }); - it('runs only one test using helper (2 args)', function (done) { + it('runs only one test using helper (2 args)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('a', function (testDone) { + script.test('a', (testDone) => { testDone(); }); - script.test.only('b', function (testDone) { + script.test.only('b', (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.equal(true); @@ -723,23 +725,23 @@ describe('Lab', function () { }); }); - it('runs only one test using helper (3 args)', function (done) { + it('runs only one test using helper (3 args)', (done) => { - var script = Lab.script({ schedule: false }); - script.experiment('test1', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test1', () => { - script.test('a', function (testDone) { + script.test('a', (testDone) => { testDone(); }); - script.test.only('b', {}, function (testDone) { + script.test.only('b', {}, (testDone) => { testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests).to.have.length(2); expect(notebook.tests[0].skipped).to.equal(true); @@ -749,18 +751,18 @@ describe('Lab', function () { }); }); - it('schedules automatic execution', { parallel: false }, function (done) { + it('schedules automatic execution', { parallel: false }, (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { testDone(); }); }); - var orig = process.exit; + const orig = process.exit; process.exit = function (code) { process.exit = orig; @@ -769,40 +771,40 @@ describe('Lab', function () { }; }); - it('throws on invalid functions', function (done) { + it('throws on invalid functions', (done) => { - var script = Lab.script(); + const script = Lab.script(); - expect(function () { + expect(() => { script.test('a'); }).not.to.throw(); - expect(function () { + expect(() => { - script.test('a', function () {}); + script.test('a', () => {}); }).to.throw('Function for test "a" should take exactly one argument'); - ['before', 'beforeEach', 'after', 'afterEach'].forEach(function (fn) { + ['before', 'beforeEach', 'after', 'afterEach'].forEach((fn) => { - expect(function () { + expect(() => { - script.experiment('exp', function () { + script.experiment('exp', () => { script[fn](); }); }).to.throw('Function for ' + fn + ' in "exp" should take exactly one argument'); - expect(function () { + expect(() => { - script.experiment('exp', function () { + script.experiment('exp', () => { - script[fn](function () {}); + script[fn](() => {}); }); }).to.throw('Function for ' + fn + ' in "exp" should take exactly one argument'); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { done(); }); diff --git a/test/leaks.js b/test/leaks.js index d93fc238..8e2823a2 100755 --- a/test/leaks.js +++ b/test/leaks.js @@ -1,66 +1,68 @@ +'use strict'; + // Load modules -var Path = require('path'); -var Code = require('code'); -var _Lab = require('../test_runner'); -var Lab = require('../'); +const Path = require('path'); +const Code = require('code'); +const _Lab = require('../test_runner'); +const Lab = require('../'); // Declare internals -var internals = { +const internals = { harmonyGlobals: ['Promise', 'Proxy', 'Symbol', 'Map', 'WeakMap', 'Set', 'WeakSet'] }; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Leaks', function () { +describe('Leaks', () => { - it('identifies global leaks', function (done) { + it('identifies global leaks', (done) => { global.abc = 1; - var leaks = Lab.leaks.detect(); + const leaks = Lab.leaks.detect(); delete global.abc; expect(leaks.length).to.equal(1); done(); }); - it('identifies global leaks for non-enumerable properties', function (done) { + it('identifies global leaks for non-enumerable properties', (done) => { Object.defineProperty(global, 'abc', { enumerable: false, configurable: true }); - var leaks = Lab.leaks.detect(); + const leaks = Lab.leaks.detect(); delete global.abc; expect(leaks.length).to.equal(1); done(); }); - it('verifies no leaks', function (done) { + it('verifies no leaks', (done) => { - var leaks = Lab.leaks.detect(); + const leaks = Lab.leaks.detect(); expect(leaks.length).to.equal(0); done(); }); - it('ignores DTrace globals', function (done) { + it('ignores DTrace globals', (done) => { - var currentGlobal = global.DTRACE_HTTP_SERVER_RESPONSE; + const currentGlobal = global.DTRACE_HTTP_SERVER_RESPONSE; global.DTRACE_HTTP_SERVER_RESPONSE = 1; - var leaks = Lab.leaks.detect(); + const leaks = Lab.leaks.detect(); expect(leaks.length).to.equal(0); global.DTRACE_HTTP_SERVER_RESPONSE = currentGlobal; done(); }); - it('works with missing DTrace globals', function (done) { + it('works with missing DTrace globals', (done) => { delete global.DTRACE_HTTP_SERVER_RESPONSE; delete global.DTRACE_HTTP_CLIENT_REQUEST; @@ -71,36 +73,36 @@ describe('Leaks', function () { delete global.DTRACE_NET_SOCKET_WRITE; delete global.DTRACE_NET_SERVER_CONNECTION; - var leaks = Lab.leaks.detect(); + const leaks = Lab.leaks.detect(); expect(leaks.length).to.equal(0); done(); }); - it('ignores Counter globals', function (done) { + it('ignores Counter globals', (done) => { global.COUNTER_NET_SERVER_CONNECTION = 1; - var leaks = Lab.leaks.detect(); + const leaks = Lab.leaks.detect(); delete global.COUNTER_NET_SERVER_CONNECTION; expect(leaks.length).to.equal(0); done(); }); - it('ignores Harmony globals', function (done) { + it('ignores Harmony globals', (done) => { - var harmonyGlobals = internals.harmonyGlobals; + const harmonyGlobals = internals.harmonyGlobals; - for (var i = 0; i < harmonyGlobals.length; ++i) { - var harmonyGlobal = harmonyGlobals[i]; + for (let i = 0; i < harmonyGlobals.length; ++i) { + const harmonyGlobal = harmonyGlobals[i]; global[harmonyGlobal] = global[harmonyGlobal] || 1; } - var leaks = Lab.leaks.detect(); + const leaks = Lab.leaks.detect(); expect(leaks.length).to.equal(0); - for (i = 0; i < harmonyGlobals.length; ++i) { - harmonyGlobal = harmonyGlobals[i]; + for (let i = 0; i < harmonyGlobals.length; ++i) { + const harmonyGlobal = harmonyGlobals[i]; if (global[harmonyGlobal] === 1) { delete global[harmonyGlobal]; @@ -110,23 +112,23 @@ describe('Leaks', function () { done(); }); - it('handles case where Harmony globals do not exist', function (done) { + it('handles case where Harmony globals do not exist', (done) => { - var harmonyGlobals = internals.harmonyGlobals; - var originalValues = {}; + const harmonyGlobals = internals.harmonyGlobals; + const originalValues = {}; - for (var i = 0; i < harmonyGlobals.length; ++i) { - var harmonyGlobal = harmonyGlobals[i]; + for (let i = 0; i < harmonyGlobals.length; ++i) { + const harmonyGlobal = harmonyGlobals[i]; originalValues[harmonyGlobal] = global[harmonyGlobal]; delete global[harmonyGlobal]; } - var leaks = Lab.leaks.detect(); + const leaks = Lab.leaks.detect(); expect(leaks.length).to.equal(0); - for (i = 0; i < harmonyGlobals.length; ++i) { - harmonyGlobal = harmonyGlobals[i]; + for (let i = 0; i < harmonyGlobals.length; ++i) { + const harmonyGlobal = harmonyGlobals[i]; if (originalValues[harmonyGlobal]) { global[harmonyGlobal] = originalValues[harmonyGlobal]; @@ -136,10 +138,10 @@ describe('Leaks', function () { done(); }); - it('identifies custom globals', function (done) { + it('identifies custom globals', (done) => { global.abc = 1; - var leaks = Lab.leaks.detect(['abc']); + const leaks = Lab.leaks.detect(['abc']); delete global.abc; expect(leaks.length).to.equal(0); done(); diff --git a/test/lint/eslint/basic/fail.js b/test/lint/eslint/basic/fail.js old mode 100644 new mode 100755 index b9e59288..426d259e --- a/test/lint/eslint/basic/fail.js +++ b/test/lint/eslint/basic/fail.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/lint/eslint/clean/success.js b/test/lint/eslint/clean/success.js old mode 100644 new mode 100755 index 3a80a8f0..feebadc7 --- a/test/lint/eslint/clean/success.js +++ b/test/lint/eslint/clean/success.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/lint/eslint/html/fail.js b/test/lint/eslint/html/fail.js old mode 100644 new mode 100755 index b9e59288..426d259e --- a/test/lint/eslint/html/fail.js +++ b/test/lint/eslint/html/fail.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/lint/eslint/shadow-res/fail.js b/test/lint/eslint/shadow-res/fail.js old mode 100644 new mode 100755 index 223ea698..d3dcd5f7 --- a/test/lint/eslint/shadow-res/fail.js +++ b/test/lint/eslint/shadow-res/fail.js @@ -1,16 +1,18 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { - var top = function (res) { + const top = function (res) { - var inner = function (res) { + const inner = function (res) { return value; }; diff --git a/test/lint/eslint/shadow/success.js b/test/lint/eslint/shadow/success.js old mode 100644 new mode 100755 index 8ef9c858..e5f4c1b1 --- a/test/lint/eslint/shadow/success.js +++ b/test/lint/eslint/shadow/success.js @@ -1,16 +1,18 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { - var top = function (err) { + const top = function (err) { - var inner = function (err) { + const inner = function (err) { return value; }; diff --git a/test/lint/eslint/with_config/fail.ignore.js b/test/lint/eslint/with_config/fail.ignore.js old mode 100644 new mode 100755 index e3371aac..0d382683 --- a/test/lint/eslint/with_config/fail.ignore.js +++ b/test/lint/eslint/with_config/fail.ignore.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/lint/eslint/with_config/fail.js b/test/lint/eslint/with_config/fail.js old mode 100644 new mode 100755 index e3371aac..29d0c62d --- a/test/lint/eslint/with_config/fail.js +++ b/test/lint/eslint/with_config/fail.js @@ -1,3 +1,5 @@ +'use strict'; + // Load modules diff --git a/test/lint/jslint/basic/fail.js b/test/lint/jslint/basic/fail.js old mode 100644 new mode 100755 index b9e59288..426d259e --- a/test/lint/jslint/basic/fail.js +++ b/test/lint/jslint/basic/fail.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/lint/jslint/clean/success.js b/test/lint/jslint/clean/success.js old mode 100644 new mode 100755 diff --git a/test/lint/jslint/with_config/fail.js b/test/lint/jslint/with_config/fail.js old mode 100644 new mode 100755 index b15eaff0..449729d4 --- a/test/lint/jslint/with_config/fail.js +++ b/test/lint/jslint/with_config/fail.js @@ -1,15 +1,17 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { - var myString = 'x'; - var myObject = { + const myString = 'x'; + const myObject = { x: 10 }; value = eval('myObject.' + myString); diff --git a/test/linters.js b/test/linters.js index b6bf4338..46a7a48a 100755 --- a/test/linters.js +++ b/test/linters.js @@ -1,121 +1,123 @@ +'use strict'; + // Load modules -var Path = require('path'); -var _Lab = require('../test_runner'); -var Code = require('code'); -var Linters = require('../lib/lint'); +const Path = require('path'); +const _Lab = require('../test_runner'); +const Code = require('code'); +const Linters = require('../lib/lint'); // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Linters - eslint', function () { +describe('Linters - eslint', () => { - it('should lint files in a folder', function (done) { + it('should lint files in a folder', (done) => { - var path = Path.join(__dirname, 'lint', 'eslint', 'basic'); - Linters.lint({ lintingPath: path, linter: 'eslint' }, function (err, result) { + const path = Path.join(__dirname, 'lint', 'eslint', 'basic'); + Linters.lint({ lintingPath: path, linter: 'eslint' }, (err, result) => { expect(result).to.include('lint'); - var eslintResults = result.lint; + const eslintResults = result.lint; expect(eslintResults).to.have.length(1); - var checkedFile = eslintResults[0]; + const checkedFile = eslintResults[0]; expect(checkedFile).to.include({ filename: Path.join(path, 'fail.js') }); expect(checkedFile.errors).to.deep.include([ - { line: 11, severity: 'ERROR', message: 'semi - Missing semicolon.' }, - { line: 12, severity: 'WARNING', message: 'eol-last - Newline required at end of file but not found.' } + { line: 13, severity: 'ERROR', message: 'semi - Missing semicolon.' }, + { line: 14, severity: 'WARNING', message: 'eol-last - Newline required at end of file but not found.' } ]); done(); }); }); - it('should use local configuration files', function (done) { + it('should use local configuration files', (done) => { - var path = Path.join(__dirname, 'lint', 'eslint', 'with_config'); - Linters.lint({ lintingPath: path, linter: 'eslint' }, function (err, result) { + const path = Path.join(__dirname, 'lint', 'eslint', 'with_config'); + Linters.lint({ lintingPath: path, linter: 'eslint' }, (err, result) => { expect(result).to.include('lint'); - var eslintResults = result.lint; + const eslintResults = result.lint; expect(eslintResults).to.have.length(1); - var checkedFile = eslintResults[0]; + const checkedFile = eslintResults[0]; expect(checkedFile).to.include({ filename: Path.join(path, 'fail.js') }); expect(checkedFile.errors).to.deep.include([ - { line: 12, severity: 'ERROR', message: 'eol-last - Newline required at end of file but not found.' }]); - expect(checkedFile.errors).to.not.deep.include({ line: 6, severity: 'ERROR', message: 'no-unused-vars - internals is defined but never used' }); + { line: 14, severity: 'ERROR', message: 'eol-last - Newline required at end of file but not found.' }]); + expect(checkedFile.errors).to.not.deep.include({ line: 8, severity: 'ERROR', message: 'no-unused-vars - internals is defined but never used' }); done(); }); }); - it('displays success message if no issues found', function (done) { + it('displays success message if no issues found', (done) => { - var path = Path.join(__dirname, 'lint', 'eslint', 'clean'); - Linters.lint({ lintingPath: path, linter: 'eslint' }, function (err, result) { + const path = Path.join(__dirname, 'lint', 'eslint', 'clean'); + Linters.lint({ lintingPath: path, linter: 'eslint' }, (err, result) => { expect(result.lint).to.exist(); - var eslintResults = result.lint; + const eslintResults = result.lint; expect(eslintResults).to.have.length(1); - var checkedFile = eslintResults[0]; + const checkedFile = eslintResults[0]; expect(checkedFile.errors.length).to.equal(0); done(); }); }); - it('allows err to be shadowed', function (done) { + it('allows err to be shadowed', (done) => { - var path = Path.join(__dirname, 'lint', 'eslint', 'shadow'); - Linters.lint({ lintingPath: path, linter: 'eslint' }, function (err, result) { + const path = Path.join(__dirname, 'lint', 'eslint', 'shadow'); + Linters.lint({ lintingPath: path, linter: 'eslint' }, (err, result) => { expect(result.lint).to.exist(); - var eslintResults = result.lint; + const eslintResults = result.lint; expect(eslintResults).to.have.length(1); - var checkedFile = eslintResults[0]; + const checkedFile = eslintResults[0]; expect(checkedFile.errors.length).to.equal(0); done(); }); }); - it('doesn\'t allow res to be shadowed', function (done) { + it('doesn\'t allow res to be shadowed', (done) => { - var path = Path.join(__dirname, 'lint', 'eslint', 'shadow-res'); - Linters.lint({ lintingPath: path, linter: 'eslint' }, function (err, result) { + const path = Path.join(__dirname, 'lint', 'eslint', 'shadow-res'); + Linters.lint({ lintingPath: path, linter: 'eslint' }, (err, result) => { expect(result.lint).to.exist(); - var eslintResults = result.lint; + const eslintResults = result.lint; expect(eslintResults).to.have.length(1); - var checkedFile = eslintResults[0]; + const checkedFile = eslintResults[0]; expect(checkedFile.errors.length).to.equal(1); done(); }); }); - it('should pass options and not find any files', function (done) { + it('should pass options and not find any files', (done) => { - var lintOptions = JSON.stringify({ extensions: ['.jsx'] }); - var path = Path.join(__dirname, 'lint', 'eslint', 'basic'); - Linters.lint({ lintingPath: path, linter: 'eslint', 'lint-options': lintOptions }, function (err, result) { + const lintOptions = JSON.stringify({ extensions: ['.jsx'] }); + const path = Path.join(__dirname, 'lint', 'eslint', 'basic'); + Linters.lint({ lintingPath: path, linter: 'eslint', 'lint-options': lintOptions }, (err, result) => { expect(result).to.include('lint'); - var eslintResults = result.lint; + const eslintResults = result.lint; expect(eslintResults).to.have.length(0); done(); @@ -123,83 +125,81 @@ describe('Linters - eslint', function () { }); }); -describe('Linters - jslint', function () { +describe('Linters - jslint', () => { - it('should lint files in a folder', function (done) { + it('should lint files in a folder', (done) => { - var path = Path.join(__dirname, 'lint', 'jslint', 'basic'); - Linters.lint({ lintingPath: path, linter: 'jslint' }, function (err, result) { + const path = Path.join(__dirname, 'lint', 'jslint', 'basic'); + Linters.lint({ lintingPath: path, linter: 'jslint' }, (err, result) => { expect(err).not.to.exist(); expect(result).to.include('lint'); - var jslintResults = result.lint; + const jslintResults = result.lint; expect(jslintResults).to.have.length(1); - var checkedFile = jslintResults[0]; + const checkedFile = jslintResults[0]; expect(checkedFile).to.include({ filename: 'fail.js' }); expect(checkedFile.errors).to.deep.include([ - { line: 10, severity: 'ERROR', message: 'Use spaces, not tabs.' }, - { line: 10, severity: 'ERROR', message: 'Expected \'use strict\' before \'return\'.' }, - { line: 11, severity: 'ERROR', message: 'Expected \';\' and instead saw \'}\'.' }, - { line: 11, severity: 'ERROR', message: 'Stopping.' } + { line: 12, severity: 'ERROR', message: 'Use spaces, not tabs.' }, + { line: 13, severity: 'ERROR', message: 'Expected \';\' and instead saw \'}\'.' }, + { line: 13, severity: 'ERROR', message: 'Stopping.' } ]); done(); }); }); - it('should use local configuration files', function (done) { + it('should use local configuration files', (done) => { - var path = Path.join(__dirname, 'lint', 'jslint', 'with_config'); - Linters.lint({ lintingPath: path, linter: 'jslint' }, function (err, result) { + const path = Path.join(__dirname, 'lint', 'jslint', 'with_config'); + Linters.lint({ lintingPath: path, linter: 'jslint' }, (err, result) => { expect(err).not.to.exist(); expect(result).to.include('lint'); - var jslintResults = result.lint; + const jslintResults = result.lint; expect(jslintResults).to.have.length(1); - var checkedFile = jslintResults[0]; + const checkedFile = jslintResults[0]; expect(checkedFile).to.include({ filename: 'fail.js' }); expect(checkedFile.errors).to.deep.include([ - { line: 5, severity: 'ERROR', message: 'Unused \'internals\'.' }, - { line: 10, severity: 'ERROR', message: 'Expected \'use strict\' before \'var\'.' }, - { line: 11, severity: 'ERROR', message: 'Unused \'myObject\'.' } + { line: 7, severity: 'ERROR', message: 'Unused \'internals\'.' }, + { line: 13, severity: 'ERROR', message: 'Unused \'myObject\'.' } ]); expect(checkedFile.errors).to.not.deep.include({ line: 14, severity: 'ERROR', message: 'Unexpected \'eval\'.' }); done(); }); }); - it('displays success message if no issues found', function (done) { + it('displays success message if no issues found', (done) => { - var path = Path.join(__dirname, 'lint', 'jslint', 'clean'); - Linters.lint({ lintingPath: path, linter: 'jslint' }, function (err, result) { + const path = Path.join(__dirname, 'lint', 'jslint', 'clean'); + Linters.lint({ lintingPath: path, linter: 'jslint' }, (err, result) => { expect(err).not.to.exist(); expect(result.lint).to.exist(); - var jslintResults = result.lint; + const jslintResults = result.lint; expect(jslintResults).to.have.length(1); - var checkedFile = jslintResults[0]; + const checkedFile = jslintResults[0]; expect(checkedFile.errors.length).to.equal(0); done(); }); }); - it('should pass options and not find any files', function (done) { + it('should pass options and not find any files', (done) => { - var lintOptions = JSON.stringify({ argv: { remain: ['**/*.jsx'] } }); - var path = Path.join(__dirname, 'lint', 'jslint', 'basic'); - Linters.lint({ lintingPath: path, linter: 'jslint', 'lint-options': lintOptions }, function (err, result) { + const lintOptions = JSON.stringify({ argv: { remain: ['**/*.jsx'] } }); + const path = Path.join(__dirname, 'lint', 'jslint', 'basic'); + Linters.lint({ lintingPath: path, linter: 'jslint', 'lint-options': lintOptions }, (err, result) => { expect(err).not.to.exist(); expect(result).to.include('lint'); - var jslintResults = result.lint; + const jslintResults = result.lint; expect(jslintResults).to.have.length(0); done(); diff --git a/test/override/cli.js b/test/override/cli.js index 03ed2cde..11d4b748 100755 --- a/test/override/cli.js +++ b/test/override/cli.js @@ -1,30 +1,32 @@ +'use strict'; + // Load modules -var _Lab = require('../../test_runner'); -var Code = require('code'); +const _Lab = require('../../test_runner'); +const Code = require('code'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script({ cli: { ids: [2] } }); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script({ cli: { ids: [2] } }); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Test CLI Not Only', function () { +describe('Test CLI Not Only', () => { - it('should not run', function (done) { + it('should not run', (done) => { throw new Error(); }); - it('should run', function (done) { + it('should run', (done) => { done(); }); diff --git a/test/reporters.js b/test/reporters.js index c79f5d32..db87b764 100755 --- a/test/reporters.js +++ b/test/reporters.js @@ -1,38 +1,40 @@ +'use strict'; + // Load modules -var Crypto = require('crypto'); -var Fs = require('fs'); -var Os = require('os'); -var Path = require('path'); -var Stream = require('stream'); -var Tty = require('tty'); -var Code = require('code'); -var Hoek = require('hoek'); -var _Lab = require('../test_runner'); -var Lab = require('../'); -var Reporters = require('../lib/reporters'); +const Crypto = require('crypto'); +const Fs = require('fs'); +const Os = require('os'); +const Path = require('path'); +const Stream = require('stream'); +const Tty = require('tty'); +const Code = require('code'); +const Hoek = require('hoek'); +const _Lab = require('../test_runner'); +const Lab = require('../'); +const Reporters = require('../lib/reporters'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Reporter', function () { +describe('Reporter', () => { Lab.coverage.instrument({ coveragePath: Path.join(__dirname, './coverage/'), coverageExclude: 'exclude' }); - it('outputs to a stream', function (done) { + it('outputs to a stream', (done) => { - var Recorder = function () { + const Recorder = function () { Stream.Writable.call(this); @@ -47,17 +49,17 @@ describe('Reporter', function () { next(); }; - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - var recorder = new Recorder(); - Lab.report(script, { output: recorder }, function (err, code, output) { + const recorder = new Recorder(); + Lab.report(script, { output: recorder }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(0); @@ -66,19 +68,19 @@ describe('Reporter', function () { }); }); - it('outputs to a file', function (done) { + it('outputs to a file', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - var filename = Path.join(Os.tmpDir(), [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-')); - Lab.report(script, { output: filename }, function (err, code, output) { + const filename = Path.join(Os.tmpDir(), [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-')); + Lab.report(script, { output: filename }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(0); @@ -88,21 +90,21 @@ describe('Reporter', function () { }); }); - it('outputs to a file in a directory', function (done) { + it('outputs to a file in a directory', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - var randomname = [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-'); - var folder = Path.join(Os.tmpDir(), randomname); - var filename = Path.join(folder, randomname); - Lab.report(script, { output: filename }, function (err, code, output) { + const randomname = [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-'); + const folder = Path.join(Os.tmpDir(), randomname); + const filename = Path.join(folder, randomname); + Lab.report(script, { output: filename }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(0); @@ -113,10 +115,10 @@ describe('Reporter', function () { }); }); - it('exits with error code when leak detected', function (done) { + it('exits with error code when leak detected', (done) => { - var reporter = Reporters.generate({ reporter: 'console' }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console' }); + const notebook = { tests: [], coverage: { percent: 30, @@ -125,7 +127,7 @@ describe('Reporter', function () { leaks: ['something'] }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -133,10 +135,10 @@ describe('Reporter', function () { }); }); - it('exits with error code when coverage threshold is not met', function (done) { + it('exits with error code when coverage threshold is not met', (done) => { - var reporter = Reporters.generate({ reporter: 'console', coverage: true, threshold: 50 }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', coverage: true, threshold: 50 }); + const notebook = { tests: [], coverage: { percent: 30, @@ -144,7 +146,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -152,10 +154,10 @@ describe('Reporter', function () { }); }); - it('exits with success code when coverage threshold is met', function (done) { + it('exits with success code when coverage threshold is met', (done) => { - var reporter = Reporters.generate({ reporter: 'console', coverage: true, threshold: 50 }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', coverage: true, threshold: 50 }); + const notebook = { tests: [], coverage: { percent: 60, @@ -163,7 +165,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(0); @@ -171,10 +173,10 @@ describe('Reporter', function () { }); }); - it('exits with error code when linting error threshold is met', function (done) { + it('exits with error code when linting error threshold is met', (done) => { - var reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-errors-threshold': 5 }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-errors-threshold': 5 }); + const notebook = { tests: [], lint: { lint: [ @@ -186,7 +188,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -194,10 +196,10 @@ describe('Reporter', function () { }); }); - it('exits with error code when linting error threshold is met and threshold is 0', function (done) { + it('exits with error code when linting error threshold is met and threshold is 0', (done) => { - var reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-errors-threshold': 0 }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-errors-threshold': 0 }); + const notebook = { tests: [], lint: { lint: [ @@ -206,7 +208,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -214,10 +216,10 @@ describe('Reporter', function () { }); }); - it('exits with success code when linting error threshold is not met', function (done) { + it('exits with success code when linting error threshold is not met', (done) => { - var reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-errors-threshold': 5 }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-errors-threshold': 5 }); + const notebook = { tests: [], lint: { lint: [ @@ -228,7 +230,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(0); @@ -236,10 +238,10 @@ describe('Reporter', function () { }); }); - it('exits with error code when linting warning threshold is met', function (done) { + it('exits with error code when linting warning threshold is met', (done) => { - var reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-warnings-threshold': 5 }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-warnings-threshold': 5 }); + const notebook = { tests: [], lint: { lint: [ @@ -251,7 +253,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -259,10 +261,10 @@ describe('Reporter', function () { }); }); - it('exits with error code when linting warning threshold is met and threshold is 0', function (done) { + it('exits with error code when linting warning threshold is met and threshold is 0', (done) => { - var reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-warnings-threshold': 0 }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-warnings-threshold': 0 }); + const notebook = { tests: [], lint: { lint: [ @@ -271,7 +273,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -279,10 +281,10 @@ describe('Reporter', function () { }); }); - it('exits with success code when linting warning threshold is not met', function (done) { + it('exits with success code when linting warning threshold is not met', (done) => { - var reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-warnings-threshold': 5 }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', lint: true, 'lint-warnings-threshold': 5 }); + const notebook = { tests: [], lint: { lint: [ @@ -293,7 +295,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(0); @@ -301,21 +303,21 @@ describe('Reporter', function () { }); }); - describe('console', function () { + describe('console', () => { - it('generates a report', function (done) { + it('generates a report', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { expect(true).to.equal(true); finished(); }); }); - Lab.report(script, { reporter: 'console' }, function (err, code, output) { + Lab.report(script, { reporter: 'console' }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(0); @@ -326,12 +328,12 @@ describe('Reporter', function () { }); }); - it('generates a report with errors', function (done) { + it('generates a report with errors', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { expect(true).to.equal(false); finished(); @@ -339,23 +341,23 @@ describe('Reporter', function () { }); global.x1 = true; - Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false }, (err, code, output) => { delete global.x1; expect(err).to.not.exist(); expect(code).to.equal(1); - var result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); + const result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test works:\n\n actual expected\n\n truefalse\n\n Expected true to equal specified value\n\n(?: at \n)+\n\n1 of 1 tests failed\nTest duration: \d+ ms\nThe following leaks were detected:x1\n\n$/); done(); }); }); - it('generates a report with multi-line diff', function (done) { + it('generates a report with multi-line diff', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { expect(['a', 'b']).to.deep.equal(['a', 'c']); finished(); @@ -363,25 +365,25 @@ describe('Reporter', function () { }); global.x1 = true; - Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false }, (err, code, output) => { delete global.x1; expect(err).to.not.exist(); expect(code).to.equal(1); - var result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); + const result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test works:\n\n actual expected\n\n \[\n \"a\",\n \"bc\"\n \]\n\n Expected \[ 'a', 'b' \] to equal specified value\n\n(?: at \n)+\n\n1 of 1 tests failed\nTest duration: \d+ ms\nThe following leaks were detected:x1\n\n$/); done(); }); }); - it('generates a report with caught error', function (done) { + it('generates a report with caught error', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { - expect(function () { + expect(() => { throw new Error('boom'); }).to.not.throw(); @@ -390,127 +392,127 @@ describe('Reporter', function () { }); }); - Lab.report(script, { reporter: 'console', colors: false, leaks: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false, leaks: false }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); - var result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); + const result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test works:\n\n Expected \[Function\] to not throw an error but got \[Error: boom\]\n\n(?: at \n)+\n\n1 of 1 tests failed\nTest duration: \d+ ms\n\n$/); done(); }); }); - it('generates a report with caught error (data plain)', function (done) { + it('generates a report with caught error (data plain)', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { - var error = new Error('boom'); + const error = new Error('boom'); error.data = 'abc'; throw error; }); }); - Lab.report(script, { reporter: 'console', colors: false, leaks: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false, leaks: false }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); - var result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); + const result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test works:\n\n boom\n\n at \n at \n at \n\n Additional error data:\n "abc"\n\n\n1 of 1 tests failed\nTest duration: \d+ ms\n\n$/); done(); }); }); - it('generates a report with caught error (data array)', function (done) { + it('generates a report with caught error (data array)', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { - var error = new Error('boom'); + const error = new Error('boom'); error.data = [1, 2, 3]; throw error; }); }); - Lab.report(script, { reporter: 'console', colors: false, leaks: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false, leaks: false }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); - var result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); + const result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test works:\n\n boom\n\n at \n at \n at \n\n Additional error data:\n \[1,2,3\]\n\n\n1 of 1 tests failed\nTest duration: \d+ ms\n\n$/); done(); }); }); - it('generates a report with caught error (data object)', function (done) { + it('generates a report with caught error (data object)', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { - var error = new Error('boom'); + const error = new Error('boom'); error.data = { a: 1 }; throw error; }); }); - Lab.report(script, { reporter: 'console', colors: false, leaks: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false, leaks: false }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); - var result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); + const result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test works:\n\n boom\n\n at \n at \n at \n\n Additional error data:\n a: 1\n\n\n1 of 1 tests failed\nTest duration: \d+ ms\n\n$/); done(); }); }); - it('generates a report with plain Error', function (done) { + it('generates a report with plain Error', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('fails', function (finished) { + script.test('fails', (finished) => { throw new Error('Error Message'); }); }); - Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); - var result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); + const result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test fails:\n\n Error Message\n\n(?: at \n)+(?: at \n)+(?: at \n)+\n\n1 of 1 tests failed\nTest duration: \d+ ms\nNo global variable leaks detected\n\n$/); done(); }); }); - describe('timeouts', function () { + describe('timeouts', () => { - it('generates a report with timeout', function (done) { + it('generates a report with timeout', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { }); + script.test('works', (finished) => { }); }); - Lab.report(script, { reporter: 'console', colors: false, timeout: 1 }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false, timeout: 1 }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); - var result = output.replace(/\/[\/\w]+\.js\:\d+\:\d+/g, ''); + const result = output.replace(/\/[\/\w]+\.js\:\d+\:\d+/g, ''); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test works:\n\n Timed out \(\d+ms\) - test works\n\n\n\n1 of 1 tests failed\nTest duration: \d+ ms\nNo global variable leaks detected\n\n$/); done(); }); }); - var tests = [ + const tests = [ { type: 'before', expect: 'Timed out (1ms) - Before test' @@ -529,21 +531,21 @@ describe('Reporter', function () { } ]; - tests.forEach(function (test) { + tests.forEach((test) => { - it('generates a report with timeout on ' + test.type, function (done) { + it('generates a report with timeout on ' + test.type, (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script[test.type](function (finished) { }); - script.test('works', function (finished) { + script[test.type]((finished) => { }); + script.test('works', (finished) => { finished(); }); }); - Lab.report(script, { reporter: 'console', colors: false, 'context-timeout': 1 }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false, 'context-timeout': 1 }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); @@ -552,23 +554,23 @@ describe('Reporter', function () { }); }); - it('doesn\'t generates a report with timeout on ' + test.type, function (done) { + it('doesn\'t generates a report with timeout on ' + test.type, (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script[test.type](function (finished) { + script[test.type]((finished) => { setTimeout(finished, 500); }); - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - Lab.report(script, { reporter: 'console', colors: false, 'context-timeout': 1000 }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false, 'context-timeout': 1000 }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(0); @@ -576,19 +578,19 @@ describe('Reporter', function () { }); }); - it('generates a report with inline timeout on ' + test.type, function (done) { + it('generates a report with inline timeout on ' + test.type, (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script[test.type]({ timeout: 1 }, function (finished) { }); - script.test('works', function (finished) { + script[test.type]({ timeout: 1 }, (finished) => { }); + script.test('works', (finished) => { finished(); }); }); - Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); @@ -599,18 +601,18 @@ describe('Reporter', function () { }); }); - it('generates a report without progress', function (done) { + it('generates a report without progress', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - Lab.report(script, { reporter: 'console', progress: 0 }, function (err, code, output) { + Lab.report(script, { reporter: 'console', progress: 0 }, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.match(/^\u001b\[32m1 tests complete\u001b\[0m\nTest duration: \d+ ms\n\u001b\[32mNo global variable leaks detected\u001b\[0m\n\n$/); @@ -618,18 +620,18 @@ describe('Reporter', function () { }); }); - it('generates a report with verbose progress', function (done) { + it('generates a report with verbose progress', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - Lab.report(script, { reporter: 'console', progress: 2 }, function (err, code, output) { + Lab.report(script, { reporter: 'console', progress: 2 }, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.match(/^test\n \u001b\[32m✔\u001b\[0m \u001b\[90m1\) works \(\d+ ms\)\u001b\[0m\n\n\n\u001b\[32m1 tests complete\u001b\[0m\nTest duration: \d+ ms\n\u001b\[32mNo global variable leaks detected\u001b\[0m\n\n$/); @@ -637,21 +639,21 @@ describe('Reporter', function () { }); }); - it('generates a report with verbose progress that displays well on windows', function (done) { + it('generates a report with verbose progress that displays well on windows', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - var oldPlatform = process.platform; + const oldPlatform = process.platform; Object.defineProperty(process, 'platform', { writable: true, value: 'win32' }); - Lab.report(script, { reporter: 'console', progress: 2 }, function (err, code, output) { + Lab.report(script, { reporter: 'console', progress: 2 }, (err, code, output) => { process.platform = oldPlatform; expect(err).not.to.exist(); @@ -661,42 +663,42 @@ describe('Reporter', function () { }); }); - it('generates a coverage report (verbose)', function (done) { + it('generates a coverage report (verbose)', (done) => { - var Test = require('./coverage/console'); - var Full = require('./coverage/console-full'); + const Test = require('./coverage/console'); + const Full = require('./coverage/console-full'); - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(1, 2, 3); Full.method(1); finished(); }); - script.test('diff', function (finished) { + script.test('diff', (finished) => { expect('abcd').to.equal('cdfg'); finished(); }); }); - Lab.report(script, { reporter: 'console', coverage: true, coveragePath: Path.join(__dirname, './coverage/console') }, function (err, code, output) { + Lab.report(script, { reporter: 'console', coverage: true, coveragePath: Path.join(__dirname, './coverage/console') }, (err, code, output) => { expect(err).not.to.exist(); - expect(output).to.contain('Coverage: 78.95% (4/19)'); - expect(output).to.contain('test/coverage/console.js missing coverage on line(s): 12, 15, 16, 19'); + expect(output).to.contain('Coverage: 80.95% (4/21)'); + expect(output).to.contain('test/coverage/console.js missing coverage on line(s): 14, 17, 18, 21'); expect(output).to.not.contain('console-full'); done(); }); }); - it('reports 100% coverage', function (done) { + it('reports 100% coverage', (done) => { - var reporter = Reporters.generate({ reporter: 'console', coverage: true }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', coverage: true }); + const notebook = { tests: [], coverage: { percent: 100, @@ -704,7 +706,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('Coverage: 100.00%'); @@ -712,21 +714,21 @@ describe('Reporter', function () { }); }); - it('reports correct lines with sourcemaps enabled', function (done) { + it('reports correct lines with sourcemaps enabled', (done) => { - var Test = require('./coverage/sourcemaps-external'); + const Test = require('./coverage/sourcemaps-external'); - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(false); finished(); }); }); - Lab.report(script, { reporter: 'console', coverage: true, coveragePath: Path.join(__dirname, './coverage/sourcemaps-external'), sourcemaps: true }, function (err, code, output) { + Lab.report(script, { reporter: 'console', coverage: true, coveragePath: Path.join(__dirname, './coverage/sourcemaps-external'), sourcemaps: true }, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('test/coverage/sourcemaps-external.js missing coverage from file(s):'); @@ -735,21 +737,21 @@ describe('Reporter', function () { }); }); - it('doesn\'t report lines on a fully covered file with sourcemaps enabled', function (done) { + it('doesn\'t report lines on a fully covered file with sourcemaps enabled', (done) => { - var Test = require('./coverage/sourcemaps-covered'); + const Test = require('./coverage/sourcemaps-covered'); - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(false); finished(); }); }); - Lab.report(script, { reporter: 'console', coverage: true, coveragePath: Path.join(__dirname, './coverage/'), sourcemaps: true }, function (err, code, output) { + Lab.report(script, { reporter: 'console', coverage: true, coveragePath: Path.join(__dirname, './coverage/'), sourcemaps: true }, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.not.contain('sourcemaps-covered'); @@ -757,36 +759,36 @@ describe('Reporter', function () { }); }); - it('generates a report with multi-line progress', function (done) { + it('generates a report with multi-line progress', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - var works = function (finished) { + const works = function (finished) { expect(true).to.equal(true); finished(); }; - var fails = function (finished) { + const fails = function (finished) { expect(true).to.equal(false); finished(); }; - var skips = function (finished) { + const skips = function (finished) { finished(); }; - for (var i = 0; i < 30; ++i) { + for (let i = 0; i < 30; ++i) { script.test('works', works); script.test('fails', fails); script.test('skips', { skip: true }, skips); } }); - Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); @@ -795,28 +797,28 @@ describe('Reporter', function () { }); }); - it('generates a report with verbose progress', function (done) { + it('generates a report with verbose progress', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); - script.test('fails', function (finished) { + script.test('fails', (finished) => { finished('boom'); }); - script.test('skips', { skip: true }, function (finished) { + script.test('skips', { skip: true }, (finished) => { finished(); }); }); - Lab.report(script, { reporter: 'console', colors: false, progress: 2 }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false, progress: 2 }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); @@ -825,26 +827,26 @@ describe('Reporter', function () { }); }); - it('excludes colors when terminal does not support', { parallel: false }, function (done) { + it('excludes colors when terminal does not support', { parallel: false }, (done) => { - var orig = Tty.isatty; + const orig = Tty.isatty; Tty.isatty = function () { Tty.isatty = orig; return false; }; - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { expect(true).to.equal(true); finished(); }); }); - Lab.report(script, { reporter: 'console' }, function (err, code, output) { + Lab.report(script, { reporter: 'console' }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(0); @@ -853,49 +855,49 @@ describe('Reporter', function () { }); }); - it('displays custom error messages in expect', function (done) { + it('displays custom error messages in expect', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { expect(true, 'Not working right').to.equal(false); finished(); }); }); - Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false }, (err, code, output) => { expect(err).not.to.exist(); - var result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); + const result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test works:\n\n actual expected\n\n truefalse\n\n Not working right: Expected true to equal specified value\n\n(?: at \n)+\n\n1 of 1 tests failed\nTest duration: \d+ ms\nNo global variable leaks detected\n\n$/); done(); }); }); - it('displays session errors if there in an error in "before"', function (done) { + it('displays session errors if there in an error in "before"', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.before(function (testDone) { + script.before((testDone) => { testDone(new Error('there was an error in the before function')); }); - script.test('works', function (testDone) { + script.test('works', (testDone) => { expect(true).to.equal(true); testDone(); }); }); - Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false }, (err, code, output) => { expect(err).not.to.exist(); - var result = output.replace(/\/[\/\w]+\.js\:\d+\:\d+/g, ''); + const result = output.replace(/\/[\/\w]+\.js\:\d+\:\d+/g, ''); expect(code).to.equal(1); expect(result).to.contain('There were 1 test script error(s).'); @@ -904,28 +906,28 @@ describe('Reporter', function () { }); }); - it('displays session errors if there in an error in "afterEach"', function (done) { + it('displays session errors if there in an error in "afterEach"', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.afterEach(function (testDone) { + script.afterEach((testDone) => { - testDone('there was an error in the afterEach function'); + testDone(new Error('there was an error in the afterEach function')); }); - script.test('works', function (testDone) { + script.test('works', (testDone) => { expect(true).to.equal(true); testDone(); }); }); - Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false }, (err, code, output) => { expect(err).not.to.exist(); - var result = output.replace(/\/[\/\w]+\.js\:\d+\:\d+/g, ''); + const result = output.replace(/\/[\/\w]+\.js\:\d+\:\d+/g, ''); expect(code).to.equal(1); expect(result).to.contain('There were 1 test script error(s).'); @@ -934,10 +936,10 @@ describe('Reporter', function () { }); }); - it('generates a report with linting enabled', function (done) { + it('generates a report with linting enabled', (done) => { - var reporter = Reporters.generate({ reporter: 'console', coverage: true }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', coverage: true }); + const notebook = { tests: [], lint: { 'lint': [ @@ -955,7 +957,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('missing ;'); @@ -963,10 +965,10 @@ describe('Reporter', function () { }); }); - it('displays a success message for lint when no issues found', function (done) { + it('displays a success message for lint when no issues found', (done) => { - var reporter = Reporters.generate({ reporter: 'console', coverage: true }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', coverage: true }); + const notebook = { tests: [], lint: { 'lint': [ @@ -978,7 +980,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('No issues'); @@ -986,10 +988,10 @@ describe('Reporter', function () { }); }); - it('displays a success message for lint when errors are null', function (done) { + it('displays a success message for lint when errors are null', (done) => { - var reporter = Reporters.generate({ reporter: 'console', coverage: true }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'console', coverage: true }); + const notebook = { tests: [], lint: { 'lint': [ @@ -1001,7 +1003,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('No issues'); @@ -1009,14 +1011,14 @@ describe('Reporter', function () { }); }); - it('reports with circular JSON', function (done) { + it('reports with circular JSON', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { - var err = new Error('Fail'); + const err = new Error('Fail'); err.actual = { a: 1 }; @@ -1029,23 +1031,23 @@ describe('Reporter', function () { }); }); - Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false }, (err, code, output) => { expect(err).not.to.exist(); - var result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); + const result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test works:\n\n actual expected\n\n {\n "a": 12,\n "b": "\[Circular ~\]"\n }\n\n Fail\n\n(?: at \n)+\n\n1 of 1 tests failed\nTest duration: \d+ ms\nNo global variable leaks detected\n\n$/); done(); }); }); - it('reports with undefined values', function (done) { + it('reports with undefined values', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { - var err = new Error('Fail'); + const err = new Error('Fail'); err.actual = { a: 1 }; err.expected = { a: 1, @@ -1061,45 +1063,45 @@ describe('Reporter', function () { }); }); - Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) { + Lab.report(script, { reporter: 'console', colors: false }, (err, code, output) => { expect(err).not.to.exist(); - var result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); + const result = output.replace(/at.*\.js\:\d+\:\d+\)?/g, 'at '); expect(result).to.match(/^\n \n x\n\nFailed tests:\n\n 1\) test works:\n\n actual expected\n\n {\n\s+"a": 1,\n\s+"b": "\[undefined\]",\n\s+"c": "\[function \(\) \{\\n\\n\s+return 'foo';\\n\s+\}\]",\n\s+"d": "\[Infinity\]",\n\s+"e": "\[-Infinity\]"\n\s+}\n\n Fail\n\n(?: at \n)+\n\n1 of 1 tests failed\nTest duration: \d+ ms\nNo global variable leaks detected\n\n$/); done(); }); }); }); - describe('json', function () { + describe('json', () => { - it('generates a report', function (done) { + it('generates a report', (done) => { - var script = Lab.script(); - script.experiment('group', function () { + const script = Lab.script(); + script.experiment('group', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { expect(true).to.equal(true); finished(); }); - script.test('fails', function (finished) { + script.test('fails', (finished) => { expect(true).to.equal(false); finished(); }); - script.test('fails with non-error', function (finished) { + script.test('fails with non-error', (finished) => { finished('boom'); finished('kaboom'); }); }); - Lab.report(script, { reporter: 'json', lint: true, linter: 'eslint' }, function (err, code, output) { + Lab.report(script, { reporter: 'json', lint: true, linter: 'eslint' }, (err, code, output) => { - var result = JSON.parse(output); + const result = JSON.parse(output); expect(err).to.not.exist(); expect(code).to.equal(1); expect(result.tests.group.length).to.equal(3); @@ -1108,7 +1110,7 @@ describe('Reporter', function () { expect(result.tests.group[1].title).to.equal('fails'); expect(result.tests.group[1].err).to.equal('Expected true to equal specified value'); expect(result.tests.group[2].title).to.equal('fails with non-error'); - expect(result.tests.group[2].err).to.equal(true); + expect(result.tests.group[2].err).to.equal('Non Error object received or caught'); expect(result.leaks.length).to.equal(0); expect(result.duration).to.exist(); expect(result.errors).to.have.length(1); @@ -1119,71 +1121,71 @@ describe('Reporter', function () { }); }); - it('generates a report with coverage', function (done) { + it('generates a report with coverage', (done) => { - var Test = require('./coverage/json'); + const Test = require('./coverage/json'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('value of a', function (finished) { + script.test('value of a', (finished) => { expect(Test.method(1)).to.equal(1); finished(); }); }); - Lab.report(script, { reporter: 'json', coverage: true, coveragePath: Path.join(__dirname, './coverage/json') }, function (err, code, output) { + Lab.report(script, { reporter: 'json', coverage: true, coveragePath: Path.join(__dirname, './coverage/json') }, (err, code, output) => { expect(err).not.to.exist(); - var result = JSON.parse(output); + const result = JSON.parse(output); expect(result.coverage.percent).to.equal(100); done(); }); }); }); - describe('html', function () { + describe('html', () => { - it('generates a coverage report', function (done) { + it('generates a coverage report', (done) => { - var Test = require('./coverage/html'); + const Test = require('./coverage/html'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(1, 2, 3); finished(); }); }); - Lab.report(script, { reporter: 'html', coverage: true, coveragePath: Path.join(__dirname, './coverage/html') }, function (err, code, output) { + Lab.report(script, { reporter: 'html', coverage: true, coveragePath: Path.join(__dirname, './coverage/html') }, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('
'); - expect(output).to.contain('69.23'); + expect(output).to.contain('71.43'); delete global.__$$testCovHtml; done(); }); }); - it('generates a coverage report including sourcemaps information', function (done) { + it('generates a coverage report including sourcemaps information', (done) => { - var Test = require('./coverage/sourcemaps-external'); + const Test = require('./coverage/sourcemaps-external'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(false); finished(); }); }); - Lab.report(script, { reporter: 'html', coverage: true, coveragePath: Path.join(__dirname, './coverage/sourcemaps-external'), sourcemaps: true }, function (err, code, output) { + Lab.report(script, { reporter: 'html', coverage: true, coveragePath: Path.join(__dirname, './coverage/sourcemaps-external'), sourcemaps: true }, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain([ @@ -1203,28 +1205,28 @@ describe('Reporter', function () { }); }); - it('generates a coverage report with linting enabled and multiple files', function (done) { + it('generates a coverage report with linting enabled and multiple files', (done) => { - var Test1 = require('./coverage/html-lint/html-lint.1'); - var Test2 = require('./coverage/html-lint/html-lint.2'); + const Test1 = require('./coverage/html-lint/html-lint.1'); + const Test2 = require('./coverage/html-lint/html-lint.2'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test1.method(1, 2, 3); finished(); }); - script.test('something', function (finished) { + script.test('something', (finished) => { Test2.method(1, 2, 3); finished(); }); }); - Lab.report(script, { reporter: 'html', coverage: true, coveragePath: Path.join(__dirname, './coverage/html-lint/'), lint: true, linter: 'eslint', lintingPath: Path.join(__dirname, './coverage/html-lint') }, function (err, code, output) { + Lab.report(script, { reporter: 'html', coverage: true, coveragePath: Path.join(__dirname, './coverage/html-lint/'), lint: true, linter: 'eslint', lintingPath: Path.join(__dirname, './coverage/html-lint') }, (err, code, output) => { expect(err).not.to.exist(); expect(output) @@ -1233,42 +1235,42 @@ describe('Reporter', function () { .and.to.contain('') .and.to.contain('8') .and.to.contain('1') - .and.to.contain('
  • L11 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • ') - .and.to.contain('
  • L12 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • ') .and.to.contain('
  • L13 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • ') - .and.to.contain('
  • L16 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • ') - .and.to.contain('
  • L19 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • ') - .and.to.contain('
  • L19 - WARNING - no-eq-null - Use ‘===’ to compare with ‘null’.
  • ') - .and.to.contain('
  • L19 - ERROR - eqeqeq - Expected '===' and instead saw '=='.
  • ') - .and.to.contain('
  • L19 - ERROR - semi - Missing semicolon.
  • ') - .and.to.contain('
  • L21 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • '); + .and.to.contain('
  • L14 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • ') + .and.to.contain('
  • L15 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • ') + .and.to.contain('
  • L18 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • ') + .and.to.contain('
  • L21 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • ') + .and.to.contain('
  • L21 - WARNING - no-eq-null - Use ‘===’ to compare with ‘null’.
  • ') + .and.to.contain('
  • L21 - ERROR - eqeqeq - Expected '===' and instead saw '=='.
  • ') + .and.to.contain('
  • L21 - ERROR - semi - Missing semicolon.
  • ') + .and.to.contain('
  • L23 - ERROR - indent - Expected indentation of 4 space characters but found 0.
  • '); delete global.__$$testCovHtml; done(); }); }); - it('generates a coverage report with linting enabled with thresholds', function (done) { + it('generates a coverage report with linting enabled with thresholds', (done) => { - var Test1 = require('./coverage/html-lint/html-lint.1'); - var Test2 = require('./coverage/html-lint/html-lint.2'); + const Test1 = require('./coverage/html-lint/html-lint.1'); + const Test2 = require('./coverage/html-lint/html-lint.2'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test1.method(1, 2, 3); finished(); }); - script.test('something', function (finished) { + script.test('something', (finished) => { Test2.method(1, 2, 3); finished(); }); }); - Lab.report(script, { reporter: 'html', coverage: true, coveragePath: Path.join(__dirname, './coverage/html-lint/'), lint: true, linter: 'eslint', lintingPath: Path.join(__dirname, './coverage/html-lint'), 'lint-errors-threshold': 2, 'lint-warnings-threshold': 2 }, function (err, code, output) { + Lab.report(script, { reporter: 'html', coverage: true, coveragePath: Path.join(__dirname, './coverage/html-lint/'), lint: true, linter: 'eslint', lintingPath: Path.join(__dirname, './coverage/html-lint'), 'lint-errors-threshold': 2, 'lint-warnings-threshold': 2 }, (err, code, output) => { expect(err).not.to.exist(); expect(output) @@ -1280,19 +1282,19 @@ describe('Reporter', function () { }); }); - it('generates a report with test script errors', function (done) { + it('generates a report with test script errors', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.before(function (finished) { }); - script.test('works', function (finished) { + script.before((finished) => { }); + script.test('works', (finished) => { finished(); }); }); - Lab.report(script, { reporter: 'html', 'context-timeout': 1 }, function (err, code, output) { + Lab.report(script, { reporter: 'html', 'context-timeout': 1 }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); @@ -1303,31 +1305,31 @@ describe('Reporter', function () { }); }); - it('generates a report with test script errors that are not Error', function (done) { + it('generates a report with test script errors that are not Error', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.before(function (finished) { throw 'abc'; }); - script.test('works', function (finished) { + script.before((finished) => { throw 'abc'; }); + script.test('works', (finished) => { finished(); }); }); - Lab.report(script, { reporter: 'html', 'context-timeout': 1 }, function (err, code, output) { + Lab.report(script, { reporter: 'html', 'context-timeout': 1 }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); - expect(output).to.contain('
    abc
    '); + expect(output).to.contain('Non Error object received or caught'); done(); }); }); - it('tags file percentile based on levels', function (done) { + it('tags file percentile based on levels', (done) => { - var reporter = Reporters.generate({ reporter: 'html' }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'html' }); + const notebook = { coverage: { percent: 30, files: [ @@ -1351,7 +1353,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('10'); @@ -1362,10 +1364,10 @@ describe('Reporter', function () { }); }); - it('tags total percentile (terrible)', function (done) { + it('tags total percentile (terrible)', (done) => { - var reporter = Reporters.generate({ reporter: 'html' }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'html' }); + const notebook = { coverage: { percent: 10, files: [ @@ -1377,7 +1379,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('10'); @@ -1385,10 +1387,10 @@ describe('Reporter', function () { }); }); - it('tags total percentile (high)', function (done) { + it('tags total percentile (high)', (done) => { - var reporter = Reporters.generate({ reporter: 'html' }); - var notebook = { + const reporter = Reporters.generate({ reporter: 'html' }); + const notebook = { coverage: { percent: 80, files: [ @@ -1400,7 +1402,7 @@ describe('Reporter', function () { } }; - reporter.finalize(notebook, function (err, code, output) { + reporter.finalize(notebook, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('80'); @@ -1408,22 +1410,22 @@ describe('Reporter', function () { }); }); - it('includes test run data', function (done) { + it('includes test run data', (done) => { - var Test = require('./coverage/html'); + const Test = require('./coverage/html'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.describe('lab', function () { + script.describe('lab', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(1, 2, 3); finished(); }); - script.test('something else', function (finished) { + script.test('something else', (finished) => { Test.method(1, 2, 3); finished(); @@ -1431,7 +1433,7 @@ describe('Reporter', function () { }); }); - Lab.report(script, { reporter: 'html', coveragePath: Path.join(__dirname, './coverage/html') }, function (err, code, output) { + Lab.report(script, { reporter: 'html', coveragePath: Path.join(__dirname, './coverage/html') }, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('Test Report'); @@ -1442,82 +1444,82 @@ describe('Reporter', function () { }); }); - describe('tap', function () { + describe('tap', () => { - it('generates a report', function (done) { + it('generates a report', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { expect(true).to.equal(true); finished(); }); - script.test('skip', { skip: true }, function (finished) { + script.test('skip', { skip: true }, (finished) => { finished(); }); script.test('todo'); - script.test('fails', function (finished) { + script.test('fails', (finished) => { expect(true).to.equal(false); finished(); }); - script.test('fails with non-error', function (finished) { + script.test('fails with non-error', (finished) => { finished('boom'); }); }); - Lab.report(script, { reporter: 'tap' }, function (err, code, output) { + Lab.report(script, { reporter: 'tap' }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); - var result = output.replace(/ .*\n/g, ' \n'); + const result = output.replace(/ .*\n/g, ' \n'); expect(result).to.match(/^TAP version 13\n1..5\nok 1 \(1\) test works\n ---\n duration_ms: \d+\n ...\nok 2 # SKIP \(2\) test skip\nok 3 # TODO \(3\) test todo\nnot ok 4 \(4\) test fails\n ---\n duration_ms: \d+\n stack: |-\n Expected true to equal specified value\n(?: \n)+ ...\nnot ok 5 \(5\) test fails with non-error\n ---\n duration_ms: \d+\n ...\n# tests 4\n# pass 1\n# fail 2\n# skipped 1\n# todo 1\n$/); done(); }); }); }); - describe('junit', function () { + describe('junit', () => { - it('generates a report', function (done) { + it('generates a report', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { expect(true).to.equal(true); finished(); }); - script.test('skip', { skip: true }, function (finished) { + script.test('skip', { skip: true }, (finished) => { finished(); }); script.test('todo'); - script.test('fails', function (finished) { + script.test('fails', (finished) => { expect(true).to.equal(false); finished(); }); - script.test('fails with non-error', function (finished) { + script.test('fails with non-error', (finished) => { finished('boom'); }); }); - Lab.report(script, { reporter: 'junit' }, function (err, code, output) { + Lab.report(script, { reporter: 'junit' }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(1); @@ -1534,52 +1536,52 @@ describe('Reporter', function () { }); }); - describe('lcov', function () { + describe('lcov', () => { - it('generates a lcov report', function (done) { + it('generates a lcov report', (done) => { - var Test = require('./coverage/html'); + const Test = require('./coverage/html'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(1, 2, 3); finished(); }); }); - Lab.report(script, { reporter: 'lcov', coverage: true }, function (err, code, output) { + Lab.report(script, { reporter: 'lcov', coverage: true }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(0); expect(output).to.contain('coverage/html.js'); expect(output).to.contain('DA:1,1'); // Check that line is marked as covered - expect(output).to.contain('LF:13'); // Total Lines - expect(output).to.contain('LH:9'); // Lines Hit + expect(output).to.contain('LF:14'); // Total Lines + expect(output).to.contain('LH:10'); // Lines Hit expect(output).to.contain('end_of_record'); done(); }); }); - it('runs without coverage but doesn\'t generate output', function (done) { + it('runs without coverage but doesn\'t generate output', (done) => { - var Test = require('./coverage/html'); + const Test = require('./coverage/html'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(1, 2, 3); finished(); }); }); - Lab.report(script, { reporter: 'lcov', coverage: false }, function (err, code, output) { + Lab.report(script, { reporter: 'lcov', coverage: false }, (err, code, output) => { expect(err).to.not.exist(); expect(code).to.equal(0); @@ -1590,24 +1592,24 @@ describe('Reporter', function () { }); }); - describe('clover', function () { + describe('clover', () => { - it('generates a report', function (done) { + it('generates a report', (done) => { - var Test = require('./coverage/clover'); + const Test = require('./coverage/clover'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.describe('lab', function () { + script.describe('lab', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(1, 2, 3); finished(); }); - script.test('something else', function (finished) { + script.test('something else', (finished) => { Test.method(1, 2, 3); finished(); @@ -1615,36 +1617,36 @@ describe('Reporter', function () { }); }); - Lab.report(script, { reporter: 'clover', coverage: true, coveragePath: Path.join(__dirname, './coverage/clover') }, function (err, code, output) { + Lab.report(script, { reporter: 'clover', coverage: true, coveragePath: Path.join(__dirname, './coverage/clover') }, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.contain('clover.test.coverage'); - expect(output).to.contain(''); + expect(output).to.contain(''); delete global.__$$testCovHtml; done(); }); }); - it('correctly defaults a package root name', function (done) { + it('correctly defaults a package root name', (done) => { - var reporter = Reporters.generate({ reporter: 'clover', coveragePath: null }); + const reporter = Reporters.generate({ reporter: 'clover', coveragePath: null }); expect(reporter.settings.packageRoot).to.equal('root'); - var Test = require('./coverage/clover'); + const Test = require('./coverage/clover'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.describe('lab', function () { + script.describe('lab', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(1, 2, 3); finished(); }); - script.test('something else', function (finished) { + script.test('something else', (finished) => { Test.method(1, 2, 3); finished(); @@ -1652,10 +1654,10 @@ describe('Reporter', function () { }); }); - var origCwd = process.cwd(); + const origCwd = process.cwd(); process.chdir(Path.join(__dirname, './coverage/')); - Lab.report(script, { reporter: 'clover', coverage: true, coveragePath: Path.join(__dirname, './coverage/clover') }, function (err, code, output) { + Lab.report(script, { reporter: 'clover', coverage: true, coveragePath: Path.join(__dirname, './coverage/clover') }, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.not.contain('clover.test.coverage'); @@ -1666,30 +1668,30 @@ describe('Reporter', function () { }); }); - it('correctly determines a package root name', function (done) { + it('correctly determines a package root name', (done) => { - var reporter = Reporters.generate({ reporter: 'clover', coveragePath: Path.join(__dirname, './somepath') }); + const reporter = Reporters.generate({ reporter: 'clover', coveragePath: Path.join(__dirname, './somepath') }); expect(reporter.settings.packageRoot).to.equal('somepath'); done(); }); - it('results in an empty generation', function (done) { + it('results in an empty generation', (done) => { - var Test = require('./coverage/clover'); + const Test = require('./coverage/clover'); - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.describe('lab', function () { + script.describe('lab', () => { - script.test('something', function (finished) { + script.test('something', (finished) => { Test.method(1, 2, 3); finished(); }); - script.test('something else', function (finished) { + script.test('something else', (finished) => { Test.method(1, 2, 3); finished(); @@ -1697,7 +1699,7 @@ describe('Reporter', function () { }); }); - Lab.report(script, { reporter: 'clover', coverage: false, coveragePath: Path.join(__dirname, './coverage/clover') }, function (err, code, output) { + Lab.report(script, { reporter: 'clover', coverage: false, coveragePath: Path.join(__dirname, './coverage/clover') }, (err, code, output) => { expect(err).not.to.exist(); expect(output).to.not.contain('clover.test.coverage'); @@ -1707,10 +1709,10 @@ describe('Reporter', function () { }); }); - it('should generate a report with multiple files', function (done) { + it('should generate a report with multiple files', (done) => { - var output = ''; - var reporter = Reporters.generate({ reporter: 'clover' }); + let output = ''; + const reporter = Reporters.generate({ reporter: 'clover' }); reporter.report = function (text) { @@ -1733,11 +1735,11 @@ describe('Reporter', function () { }); }); - describe('multiple reporters', function () { + describe('multiple reporters', () => { - it('with multiple outputs are supported', function (done) { + it('with multiple outputs are supported', (done) => { - var Recorder = function () { + const Recorder = function () { Stream.Writable.call(this); @@ -1752,19 +1754,19 @@ describe('Reporter', function () { next(); }; - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - var recorder = new Recorder(); - var filename = Path.join(Os.tmpDir(), [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-')); + const recorder = new Recorder(); + const filename = Path.join(Os.tmpDir(), [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-')); - Lab.report(script, { reporter: ['lcov', 'console'], output: [filename, recorder], coverage: true }, function (err, code, output) { + Lab.report(script, { reporter: ['lcov', 'console'], output: [filename, recorder], coverage: true }, (err, code, output) => { expect(err).to.not.exist(); expect(code.lcov).to.equal(0); @@ -1777,9 +1779,9 @@ describe('Reporter', function () { }); - it('that are duplicates with multiple outputs are supported', function (done) { + it('that are duplicates with multiple outputs are supported', (done) => { - var Recorder = function () { + const Recorder = function () { Stream.Writable.call(this); @@ -1794,19 +1796,19 @@ describe('Reporter', function () { next(); }; - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - var recorder = new Recorder(); - var filename = Path.join(Os.tmpDir(), [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-')); + const recorder = new Recorder(); + const filename = Path.join(Os.tmpDir(), [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-')); - Lab.report(script, { reporter: ['console', 'console'], output: [filename, recorder], coverage: true }, function (err, code, output) { + Lab.report(script, { reporter: ['console', 'console'], output: [filename, recorder], coverage: true }, (err, code, output) => { expect(err).to.not.exist(); expect(code.console).to.equal(0); @@ -1819,42 +1821,42 @@ describe('Reporter', function () { }); }); - describe('custom reporters', function () { + describe('custom reporters', () => { - it('requires a custom reporter relatively if starts with .', function (done) { + it('requires a custom reporter relatively if starts with .', (done) => { - var reporter = './node_modules/lab-event-reporter/index.js'; + const reporter = './node_modules/lab-event-reporter/index.js'; - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - Lab.report(script, { reporter: reporter }, function (err, code, output) { + Lab.report(script, { reporter: reporter }, (err, code, output) => { expect(err).to.not.exist(); done(); }); }); - it('requires a custom reporter from node_modules if not starting with .', function (done) { + it('requires a custom reporter from node_modules if not starting with .', (done) => { - var reporter = 'lab-event-reporter'; + const reporter = 'lab-event-reporter'; - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (finished) { + script.test('works', (finished) => { finished(); }); }); - Lab.report(script, { reporter: reporter }, function (err, code, output) { + Lab.report(script, { reporter: reporter }, (err, code, output) => { expect(err).to.not.exist(); done(); diff --git a/test/runner.js b/test/runner.js index 4997d43e..721a4487 100755 --- a/test/runner.js +++ b/test/runner.js @@ -1,38 +1,40 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../test_runner'); -var Lab = require('../'); +const Code = require('code'); +const _Lab = require('../test_runner'); +const Lab = require('../'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; // save references to timer globals -var setTimeout = global.setTimeout; -var clearTimeout = global.clearTimeout; -var setImmediate = global.setImmediate; +const setTimeout = global.setTimeout; +const clearTimeout = global.clearTimeout; +const setImmediate = global.setImmediate; -describe('Runner', function () { +describe('Runner', () => { - it('sets environment', { parallel: false }, function (done) { + it('sets environment', { parallel: false }, (done) => { - var orig = process.env.NODE_ENV; + const orig = process.env.NODE_ENV; - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { expect(process.env.NODE_ENV).to.equal('lab'); process.env.NODE_ENV = orig; @@ -40,7 +42,7 @@ describe('Runner', function () { }); }); - Lab.execute(script, { environment: 'lab' }, null, function (err, notebook) { + Lab.execute(script, { environment: 'lab' }, null, (err, notebook) => { expect(err).not.to.exist(); expect(notebook.tests).to.have.length(1); @@ -49,14 +51,14 @@ describe('Runner', function () { }); }); - it('won\'t set the environment when passing null', { parallel: false }, function (done) { + it('won\'t set the environment when passing null', { parallel: false }, (done) => { - var orig = process.env.NODE_ENV; + const orig = process.env.NODE_ENV; - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { expect(process.env.NODE_ENV).to.equal(orig); process.env.NODE_ENV = orig; @@ -64,7 +66,7 @@ describe('Runner', function () { }); }); - Lab.execute(script, { environment: null }, null, function (err, notebook) { + Lab.execute(script, { environment: null }, null, (err, notebook) => { expect(err).not.to.exist(); expect(notebook.tests).to.have.length(1); @@ -73,14 +75,14 @@ describe('Runner', function () { }); }); - it('the environment defaults to test', { parallel: false }, function (done) { + it('the environment defaults to test', { parallel: false }, (done) => { - var orig = process.env.NODE_ENV; + const orig = process.env.NODE_ENV; - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { expect(process.env.NODE_ENV).to.equal('test'); process.env.NODE_ENV = orig; @@ -88,7 +90,7 @@ describe('Runner', function () { }); }); - Lab.execute(script, {}, null, function (err, notebook) { + Lab.execute(script, {}, null, (err, notebook) => { expect(err).not.to.exist(); expect(notebook.tests).to.have.length(1); @@ -97,35 +99,35 @@ describe('Runner', function () { }); }); - it('filters on ids', function (done) { + it('filters on ids', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('1', function (testDone) { + script.test('1', (testDone) => { testDone(); }); - script.test('2', function (testDone) { + script.test('2', (testDone) => { throw new Error(); }); - script.test('3', function (testDone) { + script.test('3', (testDone) => { testDone(); }); - script.test('4', function (testDone) { + script.test('4', (testDone) => { throw new Error(); }); }); - var filterFirstIds = function (next) { + const filterFirstIds = function (next) { - Lab.execute(script, { ids: [1, 3] }, null, function (err, notebook) { + Lab.execute(script, { ids: [1, 3] }, null, (err, notebook) => { expect(err).not.to.exist(); expect(notebook.tests).to.have.length(2); @@ -134,9 +136,9 @@ describe('Runner', function () { }); }; - var filterLastIds = function (next) { + const filterLastIds = function (next) { - Lab.execute(script, { ids: [2, 4] }, null, function (err, notebook) { + Lab.execute(script, { ids: [2, 4] }, null, (err, notebook) => { expect(err).not.to.exist(); expect(notebook.tests).to.have.length(2); @@ -145,41 +147,41 @@ describe('Runner', function () { }); }; - filterFirstIds(function () { + filterFirstIds(() => { filterLastIds(done); }); }); - it('filters on grep', function (done) { + it('filters on grep', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('1', function (testDone) { + script.test('1', (testDone) => { testDone(); }); - script.test('a', function (testDone) { + script.test('a', (testDone) => { throw new Error(); }); - script.test('3', function (testDone) { + script.test('3', (testDone) => { testDone(); }); - script.test('b', function (testDone) { + script.test('b', (testDone) => { throw new Error(); }); }); - var filterDigit = function (next) { + const filterDigit = function (next) { - Lab.execute(script, { grep: '\\d' }, null, function (err, notebook) { + Lab.execute(script, { grep: '\\d' }, null, (err, notebook) => { expect(err).not.to.exist(); expect(notebook.tests).to.have.length(2); @@ -188,9 +190,9 @@ describe('Runner', function () { }); }; - var filterAlpha = function (next) { + const filterAlpha = function (next) { - Lab.execute(script, { grep: '[ab]' }, null, function (err, notebook) { + Lab.execute(script, { grep: '[ab]' }, null, (err, notebook) => { expect(err).not.to.exist(); expect(notebook.tests).to.have.length(2); @@ -199,39 +201,39 @@ describe('Runner', function () { }); }; - filterDigit(function () { + filterDigit(() => { filterAlpha(done); }); }); - it('dry run', function (done) { + it('dry run', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('1', function (testDone) { + script.test('1', (testDone) => { testDone(); }); - script.test('a', function (testDone) { + script.test('a', (testDone) => { throw new Error(); }); - script.test('3', function (testDone) { + script.test('3', (testDone) => { testDone(); }); - script.test('b', function (testDone) { + script.test('b', (testDone) => { throw new Error(); }); }); - Lab.execute(script, { dry: true }, null, function (err, notebook) { + Lab.execute(script, { dry: true }, null, (err, notebook) => { expect(err).not.to.exist(); expect(notebook.tests).to.have.length(4); @@ -240,14 +242,14 @@ describe('Runner', function () { }); }); - it('debug domain error', function (done) { + it('debug domain error', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('a', function (testDone) { + script.test('a', (testDone) => { - setImmediate(function () { + setImmediate(() => { throw new Error('throwing stack later'); }); @@ -256,7 +258,7 @@ describe('Runner', function () { }); }); - Lab.execute(script, { debug: true }, null, function (err, notebook) { + Lab.execute(script, { debug: true }, null, (err, notebook) => { expect(err).not.to.exist(); expect(notebook.errors.length).to.greaterThan(0); @@ -264,25 +266,25 @@ describe('Runner', function () { }); }); - it('skips tests on failed before', function (done) { + it('skips tests on failed before', (done) => { - var steps = []; - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const steps = []; + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.before(function (testDone) { + script.before((testDone) => { steps.push('before'); testDone(new Error('oops')); }); - script.test('works', function (testDone) { + script.test('works', (testDone) => { steps.push('test'); testDone(); }); - script.test('skips', { skip: true }, function (testDone) { + script.test('skips', { skip: true }, (testDone) => { steps.push('test'); testDone(); @@ -290,17 +292,17 @@ describe('Runner', function () { script.test('todo'); - script.experiment('inner', { skip: true }, function () { + script.experiment('inner', { skip: true }, () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { steps.push('test'); testDone(); }); - script.experiment('inner', function () { + script.experiment('inner', () => { - script.test('works', function (testDone) { + script.test('works', (testDone) => { steps.push('test'); testDone(); @@ -308,23 +310,23 @@ describe('Runner', function () { }); }); - script.experiment('inner2', function () { + script.experiment('inner2', () => { - script.test('works', { skip: true }, function (testDone) { + script.test('works', { skip: true }, (testDone) => { steps.push('test'); testDone(); }); }); - script.after(function (testDone) { + script.after((testDone) => { steps.push('after'); testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests[0].err).to.equal('\'before\' action failed'); expect(steps).to.deep.equal(['before']); @@ -332,32 +334,32 @@ describe('Runner', function () { }); }); - it('skips tests on failed beforeEach', function (done) { + it('skips tests on failed beforeEach', (done) => { - var steps = []; - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const steps = []; + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.beforeEach(function (testDone) { + script.beforeEach((testDone) => { steps.push('before'); testDone(new Error('oops')); }); - script.test('works', function (testDone) { + script.test('works', (testDone) => { steps.push('test'); testDone(); }); - script.afterEach(function (testDone) { + script.afterEach((testDone) => { steps.push('after'); testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(notebook.tests[0].err).to.equal('\'before each\' action failed'); expect(steps).to.deep.equal(['before']); @@ -365,65 +367,65 @@ describe('Runner', function () { }); }); - it('runs afterEaches in nested experiments from inside, out (by experiments)', function (done) { + it('runs afterEaches in nested experiments from inside, out (by experiments)', (done) => { - var steps = []; - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const steps = []; + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.beforeEach(function (testDone) { + script.beforeEach((testDone) => { steps.push('outer beforeEach'); testDone(); }); - script.afterEach(function (testDone) { + script.afterEach((testDone) => { steps.push('outer afterEach 1'); testDone(); }); - script.test('first works', function (testDone) { + script.test('first works', (testDone) => { steps.push('first test'); testDone(); }); - script.experiment('inner test', function () { + script.experiment('inner test', () => { - script.beforeEach(function (testDone) { + script.beforeEach((testDone) => { steps.push('inner beforeEach'); testDone(); }); - script.afterEach(function (testDone) { + script.afterEach((testDone) => { steps.push('inner afterEach 1'); testDone(); }); - script.test('works', function (testDone) { + script.test('works', (testDone) => { steps.push('second test'); testDone(); }); - script.afterEach(function (testDone) { + script.afterEach((testDone) => { steps.push('inner afterEach 2'); testDone(); }); }); - script.afterEach(function (testDone) { + script.afterEach((testDone) => { steps.push('outer afterEach 2'); testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(err).not.to.exist(); expect(steps).to.deep.equal([ @@ -443,29 +445,29 @@ describe('Runner', function () { }); }); - it('executes in parallel', function (done) { + it('executes in parallel', (done) => { - var steps = []; - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const steps = []; + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('1', function (testDone) { + script.test('1', (testDone) => { - setTimeout(function () { + setTimeout(() => { steps.push('1'); testDone(); }, 5); }); - script.test('2', function (testDone) { + script.test('2', (testDone) => { steps.push('2'); testDone(); }); }); - Lab.execute(script, { parallel: true }, null, function (err, notebook) { + Lab.execute(script, { parallel: true }, null, (err, notebook) => { expect(err).not.to.exist(); expect(steps).to.deep.equal(['2', '1']); @@ -473,29 +475,29 @@ describe('Runner', function () { }); }); - it('executes in parallel with exceptions', function (done) { + it('executes in parallel with exceptions', (done) => { - var steps = []; - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const steps = []; + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('1', { parallel: false }, function (testDone) { + script.test('1', { parallel: false }, (testDone) => { - setTimeout(function () { + setTimeout(() => { steps.push('1'); testDone(); }, 5); }); - script.test('2', function (testDone) { + script.test('2', (testDone) => { steps.push('2'); testDone(); }); }); - Lab.execute(script, { parallel: true }, null, function (err, notebook) { + Lab.execute(script, { parallel: true }, null, (err, notebook) => { expect(err).not.to.exist(); expect(steps).to.deep.equal(['1', '2']); @@ -503,29 +505,29 @@ describe('Runner', function () { }); }); - it('executes in parallel (individuals)', function (done) { + it('executes in parallel (individuals)', (done) => { - var steps = []; - var script = Lab.script({ schedule: false }); - script.experiment('test', function () { + const steps = []; + const script = Lab.script({ schedule: false }); + script.experiment('test', () => { - script.test('1', { parallel: true }, function (testDone) { + script.test('1', { parallel: true }, (testDone) => { - setTimeout(function () { + setTimeout(() => { steps.push('1'); testDone(); }, 5); }); - script.test('2', { parallel: true }, function (testDone) { + script.test('2', { parallel: true }, (testDone) => { steps.push('2'); testDone(); }); }); - Lab.execute(script, null, null, function (err, notebook) { + Lab.execute(script, null, null, (err, notebook) => { expect(err).not.to.exist(); expect(steps).to.deep.equal(['2', '1']); @@ -533,19 +535,19 @@ describe('Runner', function () { }); }); - it('reports double done()', function (done) { + it('reports double done()', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('1', function (testDone) { + script.test('1', (testDone) => { testDone(); testDone(); }); }); - Lab.report(script, { output: false }, function (err, code, output) { + Lab.report(script, { output: false }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -553,18 +555,18 @@ describe('Runner', function () { }); }); - it('uses provided linter', function (done) { + it('uses provided linter', (done) => { - var script = Lab.script(); - script.experiment('test', function () { + const script = Lab.script(); + script.experiment('test', () => { - script.test('1', function (testDone) { + script.test('1', (testDone) => { testDone(); }); }); - Lab.report(script, { output: false, lint: true, linter: 'eslint', lintingPath: 'test/lint' }, function (err, code, output) { + Lab.report(script, { output: false, lint: true, linter: 'eslint', lintingPath: 'test/lint' }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -573,20 +575,20 @@ describe('Runner', function () { }); }); - it('extends report with assertions library support', function (done) { + it('extends report with assertions library support', (done) => { - var script = Lab.script(); - var assertions = Code; - script.experiment('test', function () { + const script = Lab.script(); + const assertions = Code; + script.experiment('test', () => { - script.test('1', function (testDone) { + script.test('1', (testDone) => { assertions.expect(true).to.be.true(); testDone(); }); }); - Lab.report(script, { output: false, assert: assertions }, function (err, code, output) { + Lab.report(script, { output: false, assert: assertions }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(0); @@ -595,20 +597,20 @@ describe('Runner', function () { }); }); - it('extends report with assertions library support (incomplete assertions)', function (done) { + it('extends report with assertions library support (incomplete assertions)', (done) => { - var script = Lab.script(); - var assertions = Code; - script.experiment('test', function () { + const script = Lab.script(); + const assertions = Code; + script.experiment('test', () => { - script.test('1', function (testDone) { + script.test('1', (testDone) => { assertions.expect(true).to.be.true; testDone(); }); }); - Lab.report(script, { output: false, assert: assertions }, function (err, code, output) { + Lab.report(script, { output: false, assert: assertions }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -618,20 +620,20 @@ describe('Runner', function () { }); }); - it('extends report with assertions library support (incompatible)', function (done) { + it('extends report with assertions library support (incompatible)', (done) => { - var script = Lab.script(); - var assertions = Code; - script.experiment('test', function () { + const script = Lab.script(); + const assertions = Code; + script.experiment('test', () => { - script.test('1', function (testDone) { + script.test('1', (testDone) => { assertions.expect(true).to.be.true(); testDone(); }); }); - Lab.report(script, { output: false, assert: {} }, function (err, code, output) { + Lab.report(script, { output: false, assert: {} }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(0); @@ -640,27 +642,29 @@ describe('Runner', function () { }); }); - it('reports errors with shared event emitters', function (done) { + it('reports errors with shared event emitters', (done) => { - var script = Lab.script(); - var EventEmitter = require('events').EventEmitter; + const script = Lab.script(); + const EventEmitter = require('events').EventEmitter; - script.experiment('shared test', function () { + script.experiment('shared test', () => { - var shared; - script.beforeEach(function (testDone) { + let shared; + script.beforeEach((testDone) => { shared = new EventEmitter(); - shared.on('whatever', function () { + const onWhatever = function () { this.emit('something'); - }); + }; + + shared.on('whatever', onWhatever); testDone(); }); - script.test('1', function (testDone) { + script.test('1', (testDone) => { - shared.on('something', function () { + shared.on('something', () => { throw new Error('assertion failed !'); }); @@ -668,7 +672,7 @@ describe('Runner', function () { }); }); - Lab.report(script, { output: false, assert: {} }, function (err, code, output) { + Lab.report(script, { output: false, assert: {} }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -679,38 +683,40 @@ describe('Runner', function () { }); }); - it('reports errors with shared event emitters and nested experiments', function (done) { + it('reports errors with shared event emitters and nested experiments', (done) => { - var script = Lab.script(); - var EventEmitter = require('events').EventEmitter; + const script = Lab.script(); + const EventEmitter = require('events').EventEmitter; - script.experiment('shared test', function () { + script.experiment('shared test', () => { - var shared; - script.beforeEach(function (testDone) { + let shared; + script.beforeEach((testDone) => { shared = new EventEmitter(); - shared.on('whatever', function () { + const onWhatever = function () { this.emit('something'); - }); + }; + + shared.on('whatever', onWhatever); testDone(); }); - script.test('1', function (testDone) { + script.test('1', (testDone) => { - shared.on('something', function () { + shared.on('something', () => { throw new Error('assertion failed !'); }); shared.emit('whatever'); }); - script.experiment('nested test', function () { + script.experiment('nested test', () => { - script.test('2', function (testDone) { + script.test('2', (testDone) => { - shared.on('something', function () { + shared.on('something', () => { throw new Error('assertion failed !'); }); @@ -719,7 +725,7 @@ describe('Runner', function () { }); }); - Lab.report(script, { output: false, assert: {} }, function (err, code, output) { + Lab.report(script, { output: false, assert: {} }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -730,38 +736,40 @@ describe('Runner', function () { }); }); - it('reports errors with shared event emitters and nested experiments with a single deep failure', function (done) { + it('reports errors with shared event emitters and nested experiments with a single deep failure', (done) => { - var script = Lab.script(); - var EventEmitter = require('events').EventEmitter; + const script = Lab.script(); + const EventEmitter = require('events').EventEmitter; - script.experiment('shared test', function () { + script.experiment('shared test', () => { - var shared; - script.beforeEach(function (testDone) { + let shared; + script.beforeEach((testDone) => { shared = new EventEmitter(); - shared.on('whatever', function () { + const onWhatever = function () { this.emit('something'); - }); + }; + + shared.on('whatever', onWhatever); testDone(); }); - script.test('1', function (testDone) { + script.test('1', (testDone) => { - shared.on('something', function () { + shared.on('something', () => { testDone(); }); shared.emit('whatever'); }); - script.experiment('nested test', function () { + script.experiment('nested test', () => { - script.test('2', function (testDone) { + script.test('2', (testDone) => { - shared.on('something', function () { + shared.on('something', () => { throw new Error('assertion failed !'); }); @@ -770,7 +778,7 @@ describe('Runner', function () { }); }); - Lab.report(script, { output: false, assert: {} }, function (err, code, output) { + Lab.report(script, { output: false, assert: {} }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -781,59 +789,64 @@ describe('Runner', function () { }); }); - it('reports errors with shared event emitters in parallel', function (done) { + it('reports errors with shared event emitters in parallel', (done) => { - var script = Lab.script(); - var EventEmitter = require('events').EventEmitter; + const script = Lab.script(); + const EventEmitter = require('events').EventEmitter; - script.experiment('parallel shared test', { parallel: true }, function () { + script.experiment('parallel shared test', { parallel: true }, () => { - var shared; - script.beforeEach(function (testDone) { + let shared; + script.beforeEach((testDone) => { shared = new EventEmitter(); - shared.on('foo', function () { + const onFoo = function () { this.emit('bar'); - }); - shared.on('beep', function () { + }; + + shared.on('foo', onFoo); + + const onBeep = function () { this.emit('boop'); - }); + }; + + shared.on('beep', onBeep); setTimeout(testDone, 100); // done(); }); - script.test('1', function (testDone) { + script.test('1', (testDone) => { - shared.on('bar', function () { + shared.on('bar', () => { throw new Error('foo failed !'); }); - setTimeout(function () { + setTimeout(() => { shared.emit('foo'); }, 50); }); - script.test('2', function (testDone) { + script.test('2', (testDone) => { - shared.on('boop', function () { + shared.on('boop', () => { throw new Error('beep failed !'); }); - setTimeout(function () { + setTimeout(() => { shared.emit('beep'); }, 100); }); }); - Lab.report(script, { output: false, assert: {} }, function (err, code, output) { + Lab.report(script, { output: false, assert: {} }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -844,80 +857,85 @@ describe('Runner', function () { }); }); - it('reports errors with shared event emitters in parallel', function (done) { + it('reports errors with shared event emitters in parallel', (done) => { - var script = Lab.script(); - var EventEmitter = require('events').EventEmitter; + const script = Lab.script(); + const EventEmitter = require('events').EventEmitter; - script.experiment('parallel shared test', { parallel: true }, function () { + script.experiment('parallel shared test', { parallel: true }, () => { - var shared; - script.beforeEach(function (testDone) { + let shared; + script.beforeEach((testDone) => { shared = new EventEmitter(); - shared.on('foo', function () { + const onFoo = function () { this.emit('bar'); - }); - shared.on('beep', function () { + }; + + shared.on('foo', onFoo); + + const onBeep = function () { this.emit('boop'); - }); + }; + + shared.on('beep', onBeep); setTimeout(testDone, 100); // done(); }); - script.test('1', function (testDone) { + script.test('1', (testDone) => { - shared.on('bar', function () { + shared.on('bar', () => { throw new Error('foo failed !'); }); - setTimeout(function () { + setTimeout(() => { shared.emit('foo'); }, 50); }); - script.test('2', function (testDone) { + script.test('2', (testDone) => { - shared.on('boop', function () { + shared.on('boop', () => { throw new Error('beep failed !'); }); - setTimeout(function () { + setTimeout(() => { shared.emit('beep'); }, 100); }); - script.experiment('parallel shared test', function () { + script.experiment('parallel shared test', () => { - script.test('3', function (testDone) { + script.test('3', (testDone) => { - shared.on('bar', function () { + shared.on('bar', () => { throw new Error('foo failed !'); }); - setTimeout(function () { + setTimeout(() => { shared.emit('foo'); }, 100); }); - script.test('4', function (testDone) { + script.test('4', (testDone) => { - shared.on('boop', function () { + shared.on('boop', () => { throw new Error('beep failed !'); }); - setTimeout(function () { + setTimeout(() => { shared.emit('beep'); }, 50); @@ -925,7 +943,7 @@ describe('Runner', function () { }); }); - Lab.report(script, { output: false, assert: {} }, function (err, code, output) { + Lab.report(script, { output: false, assert: {} }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(1); @@ -937,22 +955,22 @@ describe('Runner', function () { }); }); - describe('global timeout functions', function () { + describe('global timeout functions', () => { // We can't poison global.Date because the normal implementation of // global.setTimeout uses it [1] so if the runnable.js keeps a copy of // global.setTimeout (like it's supposed to), that will blow up. // [1]: https://github.com/joyent/node/blob/7fc835afe362ebd30a0dbec81d3360bd24525222/lib/timers.js#L74 - var overrideGlobals = function (testDone) { + const overrideGlobals = function (testDone) { - var fn = function () {}; + const fn = function () {}; global.setTimeout = fn; global.clearTimeout = fn; global.setImmediate = fn; testDone(); }; - var resetGlobals = function (testDone) { + const resetGlobals = function (testDone) { global.setTimeout = setTimeout; global.clearTimeout = clearTimeout; @@ -960,22 +978,22 @@ describe('Runner', function () { testDone(); }; - it('setImmediate still functions correctly', function (done) { + it('setImmediate still functions correctly', (done) => { - var script = Lab.script(); + const script = Lab.script(); script.before(overrideGlobals); script.after(resetGlobals); - script.experiment('test', function () { + script.experiment('test', () => { - script.test('1', function (testDone) { + script.test('1', (testDone) => { setImmediate(testDone); }); }); - Lab.report(script, { output: false }, function (err, code, output) { + Lab.report(script, { output: false }, (err, code, output) => { expect(err).not.to.exist(); expect(code).to.equal(0); @@ -983,23 +1001,23 @@ describe('Runner', function () { }); }); - it('test timeouts still function correctly', function (done) { + it('test timeouts still function correctly', (done) => { - var script = Lab.script(); + const script = Lab.script(); script.before(overrideGlobals); script.after(resetGlobals); - script.experiment('test', function () { + script.experiment('test', () => { - script.test('timeout', { timeout: 5 }, function (testDone) { + script.test('timeout', { timeout: 5 }, (testDone) => { testDone(); }); }); - var now = Date.now(); - Lab.execute(script, null, null, function (err, notebook) { + const now = Date.now(); + Lab.execute(script, null, null, (err, notebook) => { expect(err).not.to.exist(); expect(Date.now() - now).to.be.below(100); @@ -1007,26 +1025,26 @@ describe('Runner', function () { }); }); - it('setTimeout still functions correctly', function (done) { + it('setTimeout still functions correctly', (done) => { - var script = Lab.script(); + const script = Lab.script(); script.before(overrideGlobals); script.after(resetGlobals); - script.experiment('test', { timeout: 5 }, function () { + script.experiment('test', { timeout: 5 }, () => { - script.test('timeout', { timeout: 0 }, function (testDone) { + script.test('timeout', { timeout: 0 }, (testDone) => { - setTimeout(function () { + setTimeout(() => { testDone(); }, 10); }); }); - var now = Date.now(); - Lab.execute(script, null, null, function (err, notebook) { + const now = Date.now(); + Lab.execute(script, null, null, (err, notebook) => { expect(err).not.to.exist(); expect(Date.now() - now).to.be.above(9); diff --git a/test/transform.js b/test/transform.js old mode 100644 new mode 100755 index 15a41fd5..b108f5e0 --- a/test/transform.js +++ b/test/transform.js @@ -1,16 +1,18 @@ +'use strict'; + // Load modules -var Os = require('os'); -var Path = require('path'); -var Code = require('code'); -var _Lab = require('../test_runner'); -var Lab = require('../'); -var Transform = require('../lib/transform'); +const Os = require('os'); +const Path = require('path'); +const Code = require('code'); +const _Lab = require('../test_runner'); +const Lab = require('../'); +const Transform = require('../lib/transform'); // Declare internals -var internals = { +const internals = { transform: [ { ext: '.new', transform: function (content, filename) { @@ -34,38 +36,38 @@ var internals = { // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Transform', function () { +describe('Transform', () => { Lab.coverage.instrument({ coveragePath: Path.join(__dirname, './transform/'), coverageExclude: 'exclude', transform: internals.transform }); - it('instruments and measures coverage', function (done) { + it('instruments and measures coverage', (done) => { - var Test = require('./transform/basic-transform'); + const Test = require('./transform/basic-transform'); expect(Test.method(1)).to.equal(3); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'transform/basic-transform') }); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'transform/basic-transform') }); expect(cov.percent).to.equal(100); done(); }); - it('does not transform unneeded files', function (done) { + it('does not transform unneeded files', (done) => { - var Test = require('./transform/basic'); + const Test = require('./transform/basic'); expect(Test.method(1)).to.equal('!NOCOMPILE!'); - var cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'transform/basic') }); + const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'transform/basic') }); expect(cov.percent).to.equal(100); done(); }); - it('unit tests transform.retrieveFile', function (done) { + it('unit tests transform.retrieveFile', (done) => { - var content = Transform.retrieveFile('test/transform/exclude/lab-noexport.js'); + let content = Transform.retrieveFile('test/transform/exclude/lab-noexport.js'); expect(content).to.contain('// no code'); content = Transform.retrieveFile('test/transform/exclude/lab-noexport.js'); @@ -77,23 +79,23 @@ describe('Transform', function () { done(); }); - it('should return transformed file through for relative (cwd-rooted) and absolute paths', function (done) { + it('should return transformed file through for relative (cwd-rooted) and absolute paths', (done) => { require('./transform/basic-transform'); // prime the cache - var rel = Transform.retrieveFile('test/transform/basic-transform.new'); + const rel = Transform.retrieveFile('test/transform/basic-transform.new'); expect(rel).to.not.contain('!NOCOMPILE!'); - var abs = Transform.retrieveFile(process.cwd() + '/test/transform/basic-transform.new'); + const abs = Transform.retrieveFile(process.cwd() + '/test/transform/basic-transform.new'); expect(abs).to.not.contain('!NOCOMPILE!'); done(); }); }); -describe('Transform.install', function () { +describe('Transform.install', () => { - lab.before(function (done) { + lab.before((done) => { internals.js = require.extensions['.js']; internals.new = require.extensions['.new']; @@ -101,7 +103,7 @@ describe('Transform.install', function () { done(); }); - lab.after(function (done) { + lab.after((done) => { require.extensions['.js'] = internals.js; require.extensions['.new'] = internals.new; @@ -109,14 +111,14 @@ describe('Transform.install', function () { done(); }); - it('works correctly', function (done) { + it('works correctly', (done) => { Transform.install({ transform: internals.transform }); - var Test = require('./transform/sourcemaps'); + const Test = require('./transform/sourcemaps'); expect(Test.method(false)).to.equal(false); - var Test2 = require('./transform/exclude/transform-basic'); + const Test2 = require('./transform/exclude/transform-basic'); expect(Test2.method()).to.equal(1); done(); diff --git a/test/transform/basic-transform.new b/test/transform/basic-transform.new old mode 100644 new mode 100755 index 8b629419..c40142df --- a/test/transform/basic-transform.new +++ b/test/transform/basic-transform.new @@ -3,7 +3,7 @@ // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/transform/basic.js b/test/transform/basic.js old mode 100644 new mode 100755 index 2c7f5022..050eb492 --- a/test/transform/basic.js +++ b/test/transform/basic.js @@ -1,9 +1,11 @@ +'use strict'; + // Load modules // Declare internals -var internals = {}; +const internals = {}; exports.method = function (value) { diff --git a/test/transform/exclude/ext-test.new.js b/test/transform/exclude/ext-test.new.js old mode 100644 new mode 100755 index 3c462c23..cdbdc308 --- a/test/transform/exclude/ext-test.new.js +++ b/test/transform/exclude/ext-test.new.js @@ -1,25 +1,27 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../../../test_runner'); -var Test = require('../basic-transform'); +const Code = require('code'); +const _Lab = require('../../../test_runner'); +const Test = require('../basic-transform'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Test a transformed file', function () { +describe('Test a transformed file', () => { - it('that adds 2 to input', function (done) { + it('that adds 2 to input', (done) => { // Test.method(5) will be replaced by Test.method(1) during transform expect(!Test.method(5)!).to.equal(3); diff --git a/test/transform/exclude/lab-noexport.js b/test/transform/exclude/lab-noexport.js old mode 100644 new mode 100755 index acf0e79b..5ed83fa9 --- a/test/transform/exclude/lab-noexport.js +++ b/test/transform/exclude/lab-noexport.js @@ -1 +1,3 @@ +'use strict'; + // no code \ No newline at end of file diff --git a/test/transform/exclude/lab-transform.js b/test/transform/exclude/lab-transform.js old mode 100644 new mode 100755 index 1a06a89b..c40d3fa5 --- a/test/transform/exclude/lab-transform.js +++ b/test/transform/exclude/lab-transform.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = [ { ext: '.new', diff --git a/test/transform/exclude/transform-basic.js b/test/transform/exclude/transform-basic.js old mode 100644 new mode 100755 index aaa51bfd..233f7f7a --- a/test/transform/exclude/transform-basic.js +++ b/test/transform/exclude/transform-basic.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports.method = function () { return 1; }; diff --git a/test/transform/exclude/transform-test.js b/test/transform/exclude/transform-test.js old mode 100644 new mode 100755 index 56162c90..96d02007 --- a/test/transform/exclude/transform-test.js +++ b/test/transform/exclude/transform-test.js @@ -1,25 +1,27 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../../../test_runner'); -var Test = require('../basic-transform'); +const Code = require('code'); +const _Lab = require('../../../test_runner'); +const Test = require('../basic-transform'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Test a transformed file', function () { +describe('Test a transformed file', () => { - it('that adds 2 to input', function (done) { + it('that adds 2 to input', (done) => { expect(Test.method(1)).to.equal(3); done(); diff --git a/test/transform/sourcemaps.inl b/test/transform/sourcemaps.inl old mode 100644 new mode 100755 index 49ae5a7b..15e1956d --- a/test/transform/sourcemaps.inl +++ b/test/transform/sourcemaps.inl @@ -1,6 +1,6 @@ "use strict"; -var __moduleName = "while"; -var internals = {}; +const __moduleName = "while"; +const internals = {}; exports.method = function(value) { while (value) { value = false; diff --git a/test/utils.js b/test/utils.js index dd19f9c5..56ab0feb 100755 --- a/test/utils.js +++ b/test/utils.js @@ -1,95 +1,97 @@ +'use strict'; + // Load modules -var Code = require('code'); -var _Lab = require('../test_runner'); -var Utils = require('../lib/utils'); +const Code = require('code'); +const _Lab = require('../test_runner'); +const Utils = require('../lib/utils'); // Declare internals -var internals = {}; +const internals = {}; // Test shortcuts -var lab = exports.lab = _Lab.script(); -var describe = lab.describe; -var it = lab.it; -var expect = Code.expect; +const lab = exports.lab = _Lab.script(); +const describe = lab.describe; +const it = lab.it; +const expect = Code.expect; -describe('Utils', function () { +describe('Utils', () => { - it('merges options', function (done) { + it('merges options', (done) => { - var parent = { + const parent = { a: 1, b: 2 }; - var child = { + const child = { b: 3, c: 4 }; - var merged = Utils.mergeOptions(parent, child); + const merged = Utils.mergeOptions(parent, child); expect(merged).to.deep.equal({ a: 1, b: 3, c: 4 }); done(); }); - it('merges options (no child)', function (done) { + it('merges options (no child)', (done) => { - var parent = { + const parent = { a: 1, b: 2 }; - var merged = Utils.mergeOptions(parent, null); + const merged = Utils.mergeOptions(parent, null); expect(merged).to.deep.equal({ a: 1, b: 2 }); done(); }); - it('merges options (no parent)', function (done) { + it('merges options (no parent)', (done) => { - var child = { + const child = { b: 3, c: 4 }; - var merged = Utils.mergeOptions(null, child); + const merged = Utils.mergeOptions(null, child); expect(merged).to.deep.equal({ b: 3, c: 4 }); done(); }); - it('ignores parent options', function (done) { + it('ignores parent options', (done) => { - var parent = { + const parent = { a: 1, b: 2, e: 5, f: 6 }; - var child = { + const child = { b: 3, c: 4 }; - var merged = Utils.mergeOptions(parent, child, ['e', 'f']); + const merged = Utils.mergeOptions(parent, child, ['e', 'f']); expect(merged).to.deep.equal({ a: 1, b: 3, c: 4 }); done(); }); - it('copy child keys onto parent', function (done) { + it('copy child keys onto parent', (done) => { - var parent = { + const parent = { a: 1, b: 2, e: 5, f: 6 }; - var child = { + const child = { b: 3, c: 4 };