Skip to content

Commit

Permalink
Replaced var with const and let
Browse files Browse the repository at this point in the history
  • Loading branch information
sgravrock committed Aug 31, 2021
1 parent 42b10d5 commit 93a904a
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 76 deletions.
12 changes: 6 additions & 6 deletions bin/jasmine.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env node

var path = require('path'),
Command = require('../lib/command'),
Jasmine = require('../lib/jasmine');
const path = require('path');
const Command = require('../lib/command');
const Jasmine = require('../lib/jasmine');

var jasmine = new Jasmine({ projectBaseDir: path.resolve() });
var examplesDir = path.join(path.dirname(require.resolve('jasmine-core')), 'jasmine-core', 'example', 'node_example');
var command = new Command(path.resolve(), examplesDir, console.log);
const jasmine = new Jasmine({ projectBaseDir: path.resolve() });
const examplesDir = path.join(path.dirname(require.resolve('jasmine-core')), 'jasmine-core', 'example', 'node_example');
const command = new Command(path.resolve(), examplesDir, console.log);

command.run(jasmine, process.argv.slice(2));
52 changes: 26 additions & 26 deletions lib/command.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var path = require('path'),
fs = require('fs');
const path = require('path');
const fs = require('fs');

exports = module.exports = Command;

var subCommands = {
const subCommands = {
init: {
description: 'initialize jasmine',
action: initJasmine
Expand All @@ -28,14 +28,14 @@ function Command(projectBaseDir, examplesDir, print) {
this.projectBaseDir = projectBaseDir;
this.specDir = path.join(projectBaseDir, 'spec');

var command = this;
const command = this;

this.run = function(jasmine, commands) {
setEnvironmentVariables(commands);

var commandToRun;
let commandToRun;
Object.keys(subCommands).forEach(function(cmd) {
var commandObject = subCommands[cmd];
const commandObject = subCommands[cmd];
if (commands.indexOf(cmd) >= 0) {
commandToRun = commandObject;
} else if(commandObject.alias && commands.indexOf(commandObject.alias) >= 0) {
Expand All @@ -46,7 +46,7 @@ function Command(projectBaseDir, examplesDir, print) {
if (commandToRun) {
commandToRun.action({jasmine: jasmine, projectBaseDir: command.projectBaseDir, specDir: command.specDir, examplesDir: examplesDir, print: print});
} else {
var env = parseOptions(commands);
const env = parseOptions(commands);
if (env.unknownOptions.length > 0) {
process.exitCode = 1;
print('Unknown options: ' + env.unknownOptions.join(', '));
Expand All @@ -64,7 +64,7 @@ function isFileArg(arg) {
}

function parseOptions(argv) {
var files = [],
let files = [],
helpers = [],
requires = [],
unknownOptions = [],
Expand All @@ -77,8 +77,8 @@ function parseOptions(argv) {
random,
seed;

for (var i in argv) {
var arg = argv[i];
for (let i in argv) {
const arg = argv[i];
if (arg === '--no-color') {
color = false;
} else if (arg === '--color') {
Expand Down Expand Up @@ -126,7 +126,7 @@ function parseOptions(argv) {
}

function runJasmine(jasmine, env, print) {
var loadConfig = require('./loadConfig');
const loadConfig = require('./loadConfig');
loadConfig(jasmine, env, print);
jasmine.execute(env.files, env.filter)
.catch(function(error) {
Expand All @@ -136,8 +136,8 @@ function runJasmine(jasmine, env, print) {
}

function initJasmine(options) {
var print = options.print;
var specDir = options.specDir;
const print = options.print;
const specDir = options.specDir;
makeDirStructure(path.join(specDir, 'support/'));
if(!fs.existsSync(path.join(specDir, 'support/jasmine.json'))) {
fs.writeFileSync(path.join(specDir, 'support/jasmine.json'), fs.readFileSync(path.join(__dirname, '../lib/examples/jasmine.json'), 'utf-8'));
Expand All @@ -148,9 +148,9 @@ function initJasmine(options) {
}

function installExamples(options) {
var specDir = options.specDir;
var projectBaseDir = options.projectBaseDir;
var examplesDir = options.examplesDir;
const specDir = options.specDir;
const projectBaseDir = options.projectBaseDir;
const examplesDir = options.examplesDir;

makeDirStructure(path.join(specDir, 'support'));
makeDirStructure(path.join(specDir, 'jasmine_examples'));
Expand All @@ -177,12 +177,12 @@ function installExamples(options) {
}

function help(options) {
var print = options.print;
const print = options.print;
print('Usage: jasmine [command] [options] [files] [--]');
print('');
print('Commands:');
Object.keys(subCommands).forEach(function(cmd) {
var commandNameText = cmd;
let commandNameText = cmd;
if(subCommands[cmd].alias) {
commandNameText = commandNameText + ',' + subCommands[cmd].alias;
}
Expand Down Expand Up @@ -210,7 +210,7 @@ function help(options) {
}

function version(options) {
var print = options.print;
const print = options.print;
print('jasmine v' + require('../package.json').version);
print('jasmine-core v' + options.jasmine.coreVersion());
}
Expand All @@ -224,7 +224,7 @@ function lPad(str, length) {
}

function copyFiles(srcDir, destDir, pattern) {
var srcDirFiles = fs.readdirSync(srcDir);
const srcDirFiles = fs.readdirSync(srcDir);
srcDirFiles.forEach(function(file) {
if (file.search(pattern) !== -1) {
fs.writeFileSync(path.join(destDir, file), fs.readFileSync(path.join(srcDir, file)));
Expand All @@ -233,10 +233,10 @@ function copyFiles(srcDir, destDir, pattern) {
}

function makeDirStructure(absolutePath) {
var splitPath = absolutePath.split(path.sep);
const splitPath = absolutePath.split(path.sep);
splitPath.forEach(function(dir, index) {
if(index > 1) {
var fullPath = path.join(splitPath.slice(0, index).join('/'), dir);
const fullPath = path.join(splitPath.slice(0, index).join('/'), dir);
if (!fs.existsSync(fullPath)) {
fs.mkdirSync(fullPath);
}
Expand All @@ -245,16 +245,16 @@ function makeDirStructure(absolutePath) {
}

function isEnvironmentVariable(command) {
var envRegExp = /(.*)=(.*)/;
const envRegExp = /(.*)=(.*)/;
return command.match(envRegExp);
}

function setEnvironmentVariables(commands) {
commands.forEach(function (command) {
var regExpMatch = isEnvironmentVariable(command);
const regExpMatch = isEnvironmentVariable(command);
if(regExpMatch) {
var key = regExpMatch[1];
var value = regExpMatch[2];
const key = regExpMatch[1];
const value = regExpMatch[2];
process.env[key] = value;
}
});
Expand Down
4 changes: 2 additions & 2 deletions lib/filters/console_spec_filter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = exports = ConsoleSpecFilter;

function ConsoleSpecFilter(options) {
var filterString = options && options.filterString;
var filterPattern = new RegExp(filterString);
const filterString = options && options.filterString;
const filterPattern = new RegExp(filterString);

this.matches = function(specName) {
return filterPattern.test(specName);
Expand Down
44 changes: 22 additions & 22 deletions lib/jasmine.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var path = require('path'),
util = require('util'),
glob = require('glob'),
Loader = require('./loader'),
CompletionReporter = require('./reporters/completion_reporter'),
ConsoleSpecFilter = require('./filters/console_spec_filter');
const path = require('path');
const util = require('util');
const glob = require('glob');
const Loader = require('./loader');
const CompletionReporter = require('./reporters/completion_reporter');
const ConsoleSpecFilter = require('./filters/console_spec_filter');

module.exports = Jasmine;
module.exports.ConsoleReporter = require('./reporters/console_reporter');
Expand Down Expand Up @@ -33,7 +33,7 @@ module.exports.ConsoleReporter = require('./reporters/console_reporter');
function Jasmine(options) {
options = options || {};
this.loader = options.loader || new Loader();
var jasmineCore = options.jasmineCore || require('jasmine-core');
const jasmineCore = options.jasmineCore || require('jasmine-core');
this.jasmineCorePath = path.join(jasmineCore.files.path, 'jasmine.js');
this.jasmine = jasmineCore.boot(jasmineCore);
this.projectBaseDir = options.projectBaseDir || path.resolve();
Expand All @@ -58,7 +58,7 @@ function Jasmine(options) {
this.addReporter(this.reporter);
this.defaultReporterConfigured = false;

var jasmineRunner = this;
const jasmineRunner = this;
this.completionReporter.onComplete(function(passed) {
jasmineRunner.exitCodeCompletion(passed);
});
Expand Down Expand Up @@ -228,8 +228,8 @@ Jasmine.prototype.loadRequires = function() {
*/
Jasmine.prototype.loadConfigFile = function(configFilePath) {
try {
var absoluteConfigFilePath = path.resolve(this.projectBaseDir, configFilePath || 'spec/support/jasmine.json');
var config = require(absoluteConfigFilePath);
const absoluteConfigFilePath = path.resolve(this.projectBaseDir, configFilePath || 'spec/support/jasmine.json');
const config = require(absoluteConfigFilePath);
this.loadConfig(config);
} catch (e) {
if(configFilePath || e.code != 'MODULE_NOT_FOUND') { throw e; }
Expand All @@ -244,7 +244,7 @@ Jasmine.prototype.loadConfig = function(config) {
/**
* @interface Configuration
*/
var envConfig = {...config.env};
const envConfig = {...config.env};

/**
* The directory that spec files are contained in, relative to the project
Expand Down Expand Up @@ -394,19 +394,19 @@ Jasmine.prototype.addSpecFiles = Jasmine.prototype.addMatchingSpecFiles;
Jasmine.prototype.addHelperFiles = Jasmine.prototype.addMatchingHelperFiles;

Jasmine.prototype.addRequires = function(requires) {
var jasmineRunner = this;
const jasmineRunner = this;
requires.forEach(function(r) {
jasmineRunner.requires.push(r);
});
};

function addFiles(kind) {
return function (files) {
var jasmineRunner = this;
var fileArr = this[kind];
const jasmineRunner = this;
const fileArr = this[kind];

var {includeFiles, excludeFiles} = files.reduce(function(ongoing, file) {
var hasNegation = file.startsWith('!');
const {includeFiles, excludeFiles} = files.reduce(function(ongoing, file) {
const hasNegation = file.startsWith('!');

if (hasNegation) {
file = file.substring(1);
Expand All @@ -423,7 +423,7 @@ function addFiles(kind) {
}, { includeFiles: [], excludeFiles: [] });

includeFiles.forEach(function(file) {
var filePaths = glob
const filePaths = glob
.sync(file, { ignore: excludeFiles })
.filter(function(filePath) {
// glob will always output '/' as a segment separator but the fileArr may use \ on windows
Expand Down Expand Up @@ -483,9 +483,9 @@ Jasmine.prototype.exitCodeCompletion = function(passed) {
// might exit before all previous writes have actually been
// written when Jasmine is piped to another process that isn't
// reading quickly enough.
var jasmineRunner = this;
var streams = [process.stdout, process.stderr];
var writesToWait = streams.length;
const jasmineRunner = this;
const streams = [process.stdout, process.stderr];
let writesToWait = streams.length;
streams.forEach(function(stream) {
stream.write('', null, exitIfAllStreamsCompleted);
});
Expand All @@ -502,7 +502,7 @@ Jasmine.prototype.exitCodeCompletion = function(passed) {
}
};

var checkExit = function(jasmineRunner) {
const checkExit = function(jasmineRunner) {
return function() {
if (!jasmineRunner.completionReporter.isComplete()) {
process.exitCode = 4;
Expand Down Expand Up @@ -543,7 +543,7 @@ Jasmine.prototype.execute = async function(files, filterString) {
}

if (filterString) {
var specFilter = new ConsoleSpecFilter({
const specFilter = new ConsoleSpecFilter({
filterString: filterString
});
this.env.configure({specFilter: function(spec) {
Expand Down
6 changes: 3 additions & 3 deletions lib/loadConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module.exports = exports = function(jasmine, env, print) {
}
if (env.reporter !== undefined) {
try {
var Report = require(env.reporter);
var reporter = new Report();
const Report = require(env.reporter);
const reporter = new Report();
jasmine.clearReporters();
jasmine.addReporter(reporter);
} catch(e) {
Expand All @@ -31,4 +31,4 @@ module.exports = exports = function(jasmine, env, print) {
}
}
jasmine.showColors(env.color);
};
};
4 changes: 2 additions & 2 deletions lib/reporters/completion_reporter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function() {
var onCompleteCallback = function() {};
var completed = false;
let onCompleteCallback = function() {};
let completed = false;

this.onComplete = function(callback) {
onCompleteCallback = callback;
Expand Down

0 comments on commit 93a904a

Please sign in to comment.