Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Es6 #477

Merged
merged 2 commits into from Oct 30, 2015
Merged

Es6 #477

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
@@ -1,6 +1,8 @@
language: node_js

node_js:
- 4.0
- 4
- 5

sudo: false
10 changes: 6 additions & 4 deletions 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);
Expand All @@ -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');
});
2 changes: 2 additions & 0 deletions bin/lab
@@ -1,3 +1,5 @@
#!/usr/bin/env node

'use strict';

require('../lib/cli').run();
68 changes: 35 additions & 33 deletions 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();
Expand All @@ -35,7 +37,7 @@ exports.run = function () {
}

if (settings.sourcemaps) {
var sourceMapOptions = {};
let sourceMapOptions = {};

if (settings.transform) {
sourceMapOptions = {
Expand All @@ -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) {

Expand All @@ -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) {

Expand All @@ -124,7 +126,7 @@ internals.traverse = function (paths, options) {

internals.options = function () {

var definition = {
const definition = {
assert: {
alias: 'a',
type: 'string',
Expand Down Expand Up @@ -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]'));
Expand All @@ -303,7 +305,7 @@ internals.options = function () {
process.exit(0);
}

var options = {
const options = {
paths: argv._ ? [].concat(argv._) : ['test']
};

Expand All @@ -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]];
}
Expand Down Expand Up @@ -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 {
Expand Down