Skip to content

Commit

Permalink
Replaced var with const and let in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
sgravrock committed Aug 31, 2021
1 parent 93a904a commit e5b3989
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 94 deletions.
37 changes: 18 additions & 19 deletions spec/command_spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
var fs = require('fs'),
path = require('path');
const fs = require('fs');
const path = require('path');
const Command = require('../lib/command');

var Command = require('../lib/command');

var projectBaseDir = 'spec/fixtures/sample_empty_project/';
var spec = path.join(projectBaseDir, 'spec');
const projectBaseDir = 'spec/fixtures/sample_empty_project/';
const spec = path.join(projectBaseDir, 'spec');

function deleteDirectory(dir) {
if (fs.existsSync(dir)) {
var dirFiles = fs.readdirSync(dir);
const dirFiles = fs.readdirSync(dir);
dirFiles.forEach(function(file) {
var fullPath = path.join(dir, file);
const fullPath = path.join(dir, file);
if (fs.statSync(fullPath).isDirectory()) {
deleteDirectory(fullPath);
}
Expand All @@ -23,7 +22,7 @@ function deleteDirectory(dir) {
}

function withValueForIsTTY(value, func) {
var wasTTY = process.stdout.isTTY;
const wasTTY = process.stdout.isTTY;
try {
process.stdout.isTTY = value;
func();
Expand All @@ -35,12 +34,12 @@ function withValueForIsTTY(value, func) {

describe('command', function() {
beforeEach(function() {
var examplesDir = path.resolve(path.join(__dirname, 'fixtures', 'example'));
const examplesDir = path.resolve(path.join(__dirname, 'fixtures', 'example'));

fs.mkdirSync(projectBaseDir);

this.out = (function() {
var output = "";
let output = "";
return {
print: function(str) {
output += str;
Expand Down Expand Up @@ -86,8 +85,8 @@ describe('command', function() {
});

it('writes default settings to jasmine.json', function() {
var realJson = fs.readFileSync(path.join(spec, 'support/', 'jasmine.json'), 'utf-8');
var fixtureJson = fs.readFileSync(path.join(__dirname, '../', 'lib/', 'examples/', 'jasmine.json'), 'utf-8');
const realJson = fs.readFileSync(path.join(spec, 'support/', 'jasmine.json'), 'utf-8');
const fixtureJson = fs.readFileSync(path.join(__dirname, '../', 'lib/', 'examples/', 'jasmine.json'), 'utf-8');
expect(realJson).toEqual(fixtureJson);
});
});
Expand All @@ -99,7 +98,7 @@ describe('command', function() {
});

it('displays the version of jasmine', function() {
var packageVersion = require('../package.json').version;
const packageVersion = require('../package.json').version;
expect(this.out.getOutput()).toContain('jasmine v' + packageVersion);
});

Expand All @@ -115,7 +114,7 @@ describe('command', function() {
});

it('displays the version of jasmine', function() {
var packageVersion = require('../package.json').version;
const packageVersion = require('../package.json').version;
expect(this.out.getOutput()).toContain('jasmine v' + packageVersion);
});

Expand Down Expand Up @@ -265,23 +264,23 @@ describe('command', function() {
});

it('can specify a reporter', function() {
var reporterPath = path.resolve(path.join(__dirname, 'fixtures', 'customReporter.js'));
var Reporter = require(reporterPath);
const reporterPath = path.resolve(path.join(__dirname, 'fixtures', 'customReporter.js'));
const Reporter = require(reporterPath);
this.command.run(this.fakeJasmine, ['--reporter=' + reporterPath]);
expect(this.fakeJasmine.clearReporters).toHaveBeenCalled();
expect(this.fakeJasmine.addReporter).toHaveBeenCalledWith(jasmine.any(Reporter));
});

it('prints an error if the file does not export a reporter', function() {
var reporterPath = path.resolve(path.join(__dirname, 'fixtures', 'badReporter.js'));
const reporterPath = path.resolve(path.join(__dirname, 'fixtures', 'badReporter.js'));
this.command.run(this.fakeJasmine, ['--reporter=' + reporterPath]);
expect(this.fakeJasmine.clearReporters).not.toHaveBeenCalled();
expect(this.fakeJasmine.addReporter).not.toHaveBeenCalled();
expect(this.out.getOutput()).toContain('failed to register reporter');
});

it('prints an error if the reporter file does not exist', function() {
var reporterPath = path.resolve(path.join(__dirname, 'fixtures', 'missingReporter.js'));
const reporterPath = path.resolve(path.join(__dirname, 'fixtures', 'missingReporter.js'));
this.command.run(this.fakeJasmine, ['--reporter=' + reporterPath]);
expect(this.fakeJasmine.clearReporters).not.toHaveBeenCalled();
expect(this.fakeJasmine.addReporter).not.toHaveBeenCalled();
Expand Down
10 changes: 5 additions & 5 deletions spec/filters/console_spec_filter_spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var ConsoleSpecFilter = require('../../lib/filters/console_spec_filter');
const ConsoleSpecFilter = require('../../lib/filters/console_spec_filter');

describe("ConsoleSpecFilter", function() {

it("should match when no string is provided", function() {
var specFilter = new ConsoleSpecFilter();
const specFilter = new ConsoleSpecFilter();

expect(specFilter.matches("foo")).toBe(true);
expect(specFilter.matches("*bar")).toBe(true);
});

it("should match the provided string", function() {
var specFilter = new ConsoleSpecFilter({
const specFilter = new ConsoleSpecFilter({
filterString: "foo"
});

Expand All @@ -19,12 +19,12 @@ describe("ConsoleSpecFilter", function() {
});

it("should match by part of spec name", function() {
var specFilter = new ConsoleSpecFilter({
const specFilter = new ConsoleSpecFilter({
filterString: "ba"
});

expect(specFilter.matches("foo")).toBe(false);
expect(specFilter.matches("bar")).toBe(true);
expect(specFilter.matches("baz")).toBe(true);
});
});
});
42 changes: 21 additions & 21 deletions spec/jasmine_spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
describe('Jasmine', function() {
var path = require('path'),
slash = require('slash'),
Jasmine = require('../lib/jasmine');
const path = require('path');
const slash = require('slash');
const Jasmine = require('../lib/jasmine');

describe('Jasmine', function() {
beforeEach(function() {
this.bootedJasmine = {
getEnv: jasmine.createSpy('getEnv').and.returnValue({
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('Jasmine', function() {

function hasCommonFileGlobBehavior(method, destProp) {
it('adds a file with an absolute path', function() {
var aFile = path.join(this.testJasmine.projectBaseDir, this.testJasmine.specDir, 'spec/command_spec.js');
const aFile = path.join(this.testJasmine.projectBaseDir, this.testJasmine.specDir, 'spec/command_spec.js');
expect(this.testJasmine[destProp]).toEqual([]);
this.testJasmine[method]([aFile]);
expect(this.testJasmine[destProp]).toEqual([slash(aFile)]);
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('Jasmine', function() {
});

it('adds new files to existing files', function() {
var aFile = path.join(this.testJasmine.projectBaseDir, this.testJasmine.specDir, 'spec/command_spec.js');
const aFile = path.join(this.testJasmine.projectBaseDir, this.testJasmine.specDir, 'spec/command_spec.js');
this.testJasmine[destProp] = [aFile, 'b'];
this.testJasmine[method](['spec/fixtures/jasmine_spec/*.js']);
expect(this.testJasmine[destProp].map(basename)).toEqual([
Expand All @@ -130,13 +130,13 @@ describe('Jasmine', function() {
it('registers a console reporter upon construction', function() {
spyOn(Jasmine, 'ConsoleReporter').and.returnValue({someProperty: 'some value'});

var testJasmine = new Jasmine({ jasmineCore: this.fakeJasmineCore });
const testJasmine = new Jasmine({ jasmineCore: this.fakeJasmineCore });

expect(testJasmine.env.addReporter).toHaveBeenCalledWith({someProperty: 'some value'});
});

it('exposes #addReporter and #clearReporters', function() {
var testJasmine = new Jasmine({ jasmineCore: this.fakeJasmineCore });
const testJasmine = new Jasmine({ jasmineCore: this.fakeJasmineCore });
expect(testJasmine.reportersCount).toEqual(1);
testJasmine.clearReporters();
expect(testJasmine.reportersCount).toEqual(0);
Expand All @@ -152,13 +152,13 @@ describe('Jasmine', function() {
});

it('sets the options on the console reporter', function() {
var reporterOptions = {
const reporterOptions = {
print: 'printer',
showColors: true,
jasmineCorePath: 'path',
};

var expectedReporterOptions = Object.keys(reporterOptions).reduce(function(options, key) {
const expectedReporterOptions = Object.keys(reporterOptions).reduce(function(options, key) {
options[key] = reporterOptions[key];
return options;
}, {});
Expand All @@ -169,11 +169,11 @@ describe('Jasmine', function() {
});

it('creates a reporter with a default option if an option is not specified', function() {
var reporterOptions = {};
const reporterOptions = {};

this.testJasmine.configureDefaultReporter(reporterOptions);

var expectedReporterOptions = {
const expectedReporterOptions = {
print: jasmine.any(Function),
showColors: true,
jasmineCorePath: path.normalize('fake/jasmine/path/jasmine.js')
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('Jasmine', function() {

describe('without options', function() {
it('falls back to an empty string with an undefined spec_dir', function() {
var config = this.configObject;
const config = this.configObject;
delete config.spec_dir;

this.fixtureJasmine.loadConfig(config);
Expand Down Expand Up @@ -352,7 +352,7 @@ describe('Jasmine', function() {
});

it('loads the specified configuration file from an absolute path', function() {
var absoluteConfigPath = path.join(__dirname, 'fixtures/sample_project/spec/support/jasmine_alternate.json');
const absoluteConfigPath = path.join(__dirname, 'fixtures/sample_project/spec/support/jasmine_alternate.json');
this.fixtureJasmine.loadConfigFile(absoluteConfigPath);
expect(this.fixtureJasmine.helperFiles).toEqual(['spec/fixtures/sample_project/spec/helper.js']);
expect(this.fixtureJasmine.requires).toEqual(['ts-node/register']);
Expand All @@ -363,13 +363,13 @@ describe('Jasmine', function() {
});

it('throw error if specified configuration file doesn\'t exist', function() {
var jasmine = this.fixtureJasmine;
const jasmine = this.fixtureJasmine;
function load() { jasmine.loadConfigFile('missing.json'); }
expect(load).toThrow();
});

it('no error if default configuration file doesn\'t exist', function() {
var jasmine = this.fixtureJasmine;
const jasmine = this.fixtureJasmine;
function load() {
jasmine.projectBaseDir += '/missing';
jasmine.loadConfigFile();
Expand Down Expand Up @@ -409,7 +409,7 @@ describe('Jasmine', function() {

describe('#onComplete', function() {
it('stores an onComplete function', function() {
var fakeOnCompleteCallback = function() {};
const fakeOnCompleteCallback = function() {};
spyOn(this.testJasmine.completionReporter, 'onComplete');

this.testJasmine.onComplete(fakeOnCompleteCallback);
Expand Down Expand Up @@ -464,7 +464,7 @@ describe('Jasmine', function() {
});

it('loads helper files before checking if any reporters were added', async function() {
var loadHelpers = spyOn(this.testJasmine, 'loadHelpers');
const loadHelpers = spyOn(this.testJasmine, 'loadHelpers');
spyOn(this.testJasmine, 'configureDefaultReporter').and.callFake(function() {
expect(loadHelpers).toHaveBeenCalled();
});
Expand All @@ -483,7 +483,7 @@ describe('Jasmine', function() {

await this.testJasmine.execute(['spec/fixtures/sample_project/**/*spec.js']);

var relativePaths = this.testJasmine.specFiles.map(function(filePath) {
const relativePaths = this.testJasmine.specFiles.map(function(filePath) {
return slash(path.relative(__dirname, filePath));
});

Expand All @@ -498,7 +498,7 @@ describe('Jasmine', function() {
});

it('adds an exit code reporter', async function() {
var completionReporterSpy = jasmine.createSpyObj('reporter', ['onComplete']);
const completionReporterSpy = jasmine.createSpyObj('reporter', ['onComplete']);
this.testJasmine.completionReporter = completionReporterSpy;
spyOn(this.testJasmine, 'addReporter');

Expand All @@ -523,7 +523,7 @@ describe('Jasmine', function() {
});

it('leaves it if the suite has completed', function() {
var completionReporterSpy = jasmine.createSpyObj('reporter', ['isComplete']);
const completionReporterSpy = jasmine.createSpyObj('reporter', ['isComplete']);
completionReporterSpy.isComplete.and.returnValue(true);
this.testJasmine.completionReporter = completionReporterSpy;

Expand Down
10 changes: 5 additions & 5 deletions spec/load_config_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe('loadConfig', function() {
var path = require('path'),
loadConfig = require('../lib/loadConfig');
const path = require('path');
const loadConfig = require('../lib/loadConfig');

describe('loadConfig', function() {
it('should configure the jasmine object based on env and call execute', function() {
var fakeJasmine = jasmine.createSpyObj('jasmine', ['loadConfigFile', 'addHelperFiles', 'addRequires', 'showColors', 'execute', 'stopSpecOnExpectationFailure',
const fakeJasmine = jasmine.createSpyObj('jasmine', ['loadConfigFile', 'addHelperFiles', 'addRequires', 'showColors', 'execute', 'stopSpecOnExpectationFailure',
'stopOnSpecFailure', 'randomizeTests', 'seed', 'coreVersion', 'clearReporters', 'addReporter']),
env = {
configPath: 'somewhere.json',
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('loadConfig', function() {
});

it('should not configure the jasmine object when env is an empty object and call execute', function() {
var fakeJasmine = jasmine.createSpyObj('jasmine', ['loadConfigFile', 'addHelperFiles', 'addRequires', 'showColors', 'execute', 'stopSpecOnExpectationFailure',
const fakeJasmine = jasmine.createSpyObj('jasmine', ['loadConfigFile', 'addHelperFiles', 'addRequires', 'showColors', 'execute', 'stopSpecOnExpectationFailure',
'stopOnSpecFailure', 'randomizeTests', 'seed', 'coreVersion', 'clearReporters', 'addReporter']),
env = {};
loadConfig(fakeJasmine, env, console.log);
Expand Down
14 changes: 7 additions & 7 deletions spec/npm_package_spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
describe('npm package', function() {
var path = require('path'),
temp = require('temp').track(),
fs = require('fs');
const path = require('path');
const temp = require('temp').track();
const fs = require('fs');

describe('npm package', function() {
beforeAll(function() {
var shell = require('shelljs'),
const shell = require('shelljs'),
pack = shell.exec('npm pack', { silent: true });

this.tarball = pack.stdout.split('\n')[0];
this.tmpDir = temp.mkdirSync(); // automatically deleted on exit

var untar = shell.exec('tar -xzf ' + this.tarball + ' -C ' + this.tmpDir, {
const untar = shell.exec('tar -xzf ' + this.tarball + ' -C ' + this.tmpDir, {
silent: true
});
expect(untar.code).toBe(0);
Expand All @@ -21,7 +21,7 @@ describe('npm package', function() {
toExistInPath: function() {
return {
compare: function(actual, expected) {
var fullPath = path.resolve(expected, actual);
const fullPath = path.resolve(expected, actual);
return {
pass: fs.existsSync(fullPath)
};
Expand Down
4 changes: 2 additions & 2 deletions spec/reporters/completion_reporter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('CompletionReporter', function() {
var CompletionReporter = require('../../lib/reporters/completion_reporter');
const CompletionReporter = require('../../lib/reporters/completion_reporter');

describe('CompletionReporter', function() {
beforeEach(function() {
this.reporter = new CompletionReporter();
this.onComplete = jasmine.createSpy('onComplete');
Expand Down

0 comments on commit e5b3989

Please sign in to comment.