Skip to content

Commit 93a904a

Browse files
committed
Replaced var with const and let
1 parent 42b10d5 commit 93a904a

File tree

7 files changed

+76
-76
lines changed

7 files changed

+76
-76
lines changed

bin/jasmine.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env node
22

3-
var path = require('path'),
4-
Command = require('../lib/command'),
5-
Jasmine = require('../lib/jasmine');
3+
const path = require('path');
4+
const Command = require('../lib/command');
5+
const Jasmine = require('../lib/jasmine');
66

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

1111
command.run(jasmine, process.argv.slice(2));

lib/command.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var path = require('path'),
2-
fs = require('fs');
1+
const path = require('path');
2+
const fs = require('fs');
33

44
exports = module.exports = Command;
55

6-
var subCommands = {
6+
const subCommands = {
77
init: {
88
description: 'initialize jasmine',
99
action: initJasmine
@@ -28,14 +28,14 @@ function Command(projectBaseDir, examplesDir, print) {
2828
this.projectBaseDir = projectBaseDir;
2929
this.specDir = path.join(projectBaseDir, 'spec');
3030

31-
var command = this;
31+
const command = this;
3232

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

36-
var commandToRun;
36+
let commandToRun;
3737
Object.keys(subCommands).forEach(function(cmd) {
38-
var commandObject = subCommands[cmd];
38+
const commandObject = subCommands[cmd];
3939
if (commands.indexOf(cmd) >= 0) {
4040
commandToRun = commandObject;
4141
} else if(commandObject.alias && commands.indexOf(commandObject.alias) >= 0) {
@@ -46,7 +46,7 @@ function Command(projectBaseDir, examplesDir, print) {
4646
if (commandToRun) {
4747
commandToRun.action({jasmine: jasmine, projectBaseDir: command.projectBaseDir, specDir: command.specDir, examplesDir: examplesDir, print: print});
4848
} else {
49-
var env = parseOptions(commands);
49+
const env = parseOptions(commands);
5050
if (env.unknownOptions.length > 0) {
5151
process.exitCode = 1;
5252
print('Unknown options: ' + env.unknownOptions.join(', '));
@@ -64,7 +64,7 @@ function isFileArg(arg) {
6464
}
6565

6666
function parseOptions(argv) {
67-
var files = [],
67+
let files = [],
6868
helpers = [],
6969
requires = [],
7070
unknownOptions = [],
@@ -77,8 +77,8 @@ function parseOptions(argv) {
7777
random,
7878
seed;
7979

80-
for (var i in argv) {
81-
var arg = argv[i];
80+
for (let i in argv) {
81+
const arg = argv[i];
8282
if (arg === '--no-color') {
8383
color = false;
8484
} else if (arg === '--color') {
@@ -126,7 +126,7 @@ function parseOptions(argv) {
126126
}
127127

128128
function runJasmine(jasmine, env, print) {
129-
var loadConfig = require('./loadConfig');
129+
const loadConfig = require('./loadConfig');
130130
loadConfig(jasmine, env, print);
131131
jasmine.execute(env.files, env.filter)
132132
.catch(function(error) {
@@ -136,8 +136,8 @@ function runJasmine(jasmine, env, print) {
136136
}
137137

138138
function initJasmine(options) {
139-
var print = options.print;
140-
var specDir = options.specDir;
139+
const print = options.print;
140+
const specDir = options.specDir;
141141
makeDirStructure(path.join(specDir, 'support/'));
142142
if(!fs.existsSync(path.join(specDir, 'support/jasmine.json'))) {
143143
fs.writeFileSync(path.join(specDir, 'support/jasmine.json'), fs.readFileSync(path.join(__dirname, '../lib/examples/jasmine.json'), 'utf-8'));
@@ -148,9 +148,9 @@ function initJasmine(options) {
148148
}
149149

150150
function installExamples(options) {
151-
var specDir = options.specDir;
152-
var projectBaseDir = options.projectBaseDir;
153-
var examplesDir = options.examplesDir;
151+
const specDir = options.specDir;
152+
const projectBaseDir = options.projectBaseDir;
153+
const examplesDir = options.examplesDir;
154154

155155
makeDirStructure(path.join(specDir, 'support'));
156156
makeDirStructure(path.join(specDir, 'jasmine_examples'));
@@ -177,12 +177,12 @@ function installExamples(options) {
177177
}
178178

179179
function help(options) {
180-
var print = options.print;
180+
const print = options.print;
181181
print('Usage: jasmine [command] [options] [files] [--]');
182182
print('');
183183
print('Commands:');
184184
Object.keys(subCommands).forEach(function(cmd) {
185-
var commandNameText = cmd;
185+
let commandNameText = cmd;
186186
if(subCommands[cmd].alias) {
187187
commandNameText = commandNameText + ',' + subCommands[cmd].alias;
188188
}
@@ -210,7 +210,7 @@ function help(options) {
210210
}
211211

212212
function version(options) {
213-
var print = options.print;
213+
const print = options.print;
214214
print('jasmine v' + require('../package.json').version);
215215
print('jasmine-core v' + options.jasmine.coreVersion());
216216
}
@@ -224,7 +224,7 @@ function lPad(str, length) {
224224
}
225225

226226
function copyFiles(srcDir, destDir, pattern) {
227-
var srcDirFiles = fs.readdirSync(srcDir);
227+
const srcDirFiles = fs.readdirSync(srcDir);
228228
srcDirFiles.forEach(function(file) {
229229
if (file.search(pattern) !== -1) {
230230
fs.writeFileSync(path.join(destDir, file), fs.readFileSync(path.join(srcDir, file)));
@@ -233,10 +233,10 @@ function copyFiles(srcDir, destDir, pattern) {
233233
}
234234

235235
function makeDirStructure(absolutePath) {
236-
var splitPath = absolutePath.split(path.sep);
236+
const splitPath = absolutePath.split(path.sep);
237237
splitPath.forEach(function(dir, index) {
238238
if(index > 1) {
239-
var fullPath = path.join(splitPath.slice(0, index).join('/'), dir);
239+
const fullPath = path.join(splitPath.slice(0, index).join('/'), dir);
240240
if (!fs.existsSync(fullPath)) {
241241
fs.mkdirSync(fullPath);
242242
}
@@ -245,16 +245,16 @@ function makeDirStructure(absolutePath) {
245245
}
246246

247247
function isEnvironmentVariable(command) {
248-
var envRegExp = /(.*)=(.*)/;
248+
const envRegExp = /(.*)=(.*)/;
249249
return command.match(envRegExp);
250250
}
251251

252252
function setEnvironmentVariables(commands) {
253253
commands.forEach(function (command) {
254-
var regExpMatch = isEnvironmentVariable(command);
254+
const regExpMatch = isEnvironmentVariable(command);
255255
if(regExpMatch) {
256-
var key = regExpMatch[1];
257-
var value = regExpMatch[2];
256+
const key = regExpMatch[1];
257+
const value = regExpMatch[2];
258258
process.env[key] = value;
259259
}
260260
});

lib/filters/console_spec_filter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = exports = ConsoleSpecFilter;
22

33
function ConsoleSpecFilter(options) {
4-
var filterString = options && options.filterString;
5-
var filterPattern = new RegExp(filterString);
4+
const filterString = options && options.filterString;
5+
const filterPattern = new RegExp(filterString);
66

77
this.matches = function(specName) {
88
return filterPattern.test(specName);

lib/jasmine.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var path = require('path'),
2-
util = require('util'),
3-
glob = require('glob'),
4-
Loader = require('./loader'),
5-
CompletionReporter = require('./reporters/completion_reporter'),
6-
ConsoleSpecFilter = require('./filters/console_spec_filter');
1+
const path = require('path');
2+
const util = require('util');
3+
const glob = require('glob');
4+
const Loader = require('./loader');
5+
const CompletionReporter = require('./reporters/completion_reporter');
6+
const ConsoleSpecFilter = require('./filters/console_spec_filter');
77

88
module.exports = Jasmine;
99
module.exports.ConsoleReporter = require('./reporters/console_reporter');
@@ -33,7 +33,7 @@ module.exports.ConsoleReporter = require('./reporters/console_reporter');
3333
function Jasmine(options) {
3434
options = options || {};
3535
this.loader = options.loader || new Loader();
36-
var jasmineCore = options.jasmineCore || require('jasmine-core');
36+
const jasmineCore = options.jasmineCore || require('jasmine-core');
3737
this.jasmineCorePath = path.join(jasmineCore.files.path, 'jasmine.js');
3838
this.jasmine = jasmineCore.boot(jasmineCore);
3939
this.projectBaseDir = options.projectBaseDir || path.resolve();
@@ -58,7 +58,7 @@ function Jasmine(options) {
5858
this.addReporter(this.reporter);
5959
this.defaultReporterConfigured = false;
6060

61-
var jasmineRunner = this;
61+
const jasmineRunner = this;
6262
this.completionReporter.onComplete(function(passed) {
6363
jasmineRunner.exitCodeCompletion(passed);
6464
});
@@ -228,8 +228,8 @@ Jasmine.prototype.loadRequires = function() {
228228
*/
229229
Jasmine.prototype.loadConfigFile = function(configFilePath) {
230230
try {
231-
var absoluteConfigFilePath = path.resolve(this.projectBaseDir, configFilePath || 'spec/support/jasmine.json');
232-
var config = require(absoluteConfigFilePath);
231+
const absoluteConfigFilePath = path.resolve(this.projectBaseDir, configFilePath || 'spec/support/jasmine.json');
232+
const config = require(absoluteConfigFilePath);
233233
this.loadConfig(config);
234234
} catch (e) {
235235
if(configFilePath || e.code != 'MODULE_NOT_FOUND') { throw e; }
@@ -244,7 +244,7 @@ Jasmine.prototype.loadConfig = function(config) {
244244
/**
245245
* @interface Configuration
246246
*/
247-
var envConfig = {...config.env};
247+
const envConfig = {...config.env};
248248

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

396396
Jasmine.prototype.addRequires = function(requires) {
397-
var jasmineRunner = this;
397+
const jasmineRunner = this;
398398
requires.forEach(function(r) {
399399
jasmineRunner.requires.push(r);
400400
});
401401
};
402402

403403
function addFiles(kind) {
404404
return function (files) {
405-
var jasmineRunner = this;
406-
var fileArr = this[kind];
405+
const jasmineRunner = this;
406+
const fileArr = this[kind];
407407

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

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

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

505-
var checkExit = function(jasmineRunner) {
505+
const checkExit = function(jasmineRunner) {
506506
return function() {
507507
if (!jasmineRunner.completionReporter.isComplete()) {
508508
process.exitCode = 4;
@@ -543,7 +543,7 @@ Jasmine.prototype.execute = async function(files, filterString) {
543543
}
544544

545545
if (filterString) {
546-
var specFilter = new ConsoleSpecFilter({
546+
const specFilter = new ConsoleSpecFilter({
547547
filterString: filterString
548548
});
549549
this.env.configure({specFilter: function(spec) {

lib/loadConfig.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ module.exports = exports = function(jasmine, env, print) {
2020
}
2121
if (env.reporter !== undefined) {
2222
try {
23-
var Report = require(env.reporter);
24-
var reporter = new Report();
23+
const Report = require(env.reporter);
24+
const reporter = new Report();
2525
jasmine.clearReporters();
2626
jasmine.addReporter(reporter);
2727
} catch(e) {
@@ -31,4 +31,4 @@ module.exports = exports = function(jasmine, env, print) {
3131
}
3232
}
3333
jasmine.showColors(env.color);
34-
};
34+
};

lib/reporters/completion_reporter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = function() {
2-
var onCompleteCallback = function() {};
3-
var completed = false;
2+
let onCompleteCallback = function() {};
3+
let completed = false;
44

55
this.onComplete = function(callback) {
66
onCompleteCallback = callback;

0 commit comments

Comments
 (0)