Use const/let in specs, not var

This commit is contained in:
Steve Gravrock
2022-04-16 13:41:44 -07:00
parent 482dc883eb
commit 1166d10e43
111 changed files with 2522 additions and 2675 deletions

View File

@@ -1,18 +1,21 @@
describe('npm package', function() {
var path = require('path'),
const path = require('path'),
temp = require('temp').track(),
fs = require('fs');
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, {
silent: true
});
const untar = shell.exec(
'tar -xzf ' + this.tarball + ' -C ' + this.tmpDir,
{
silent: true
}
);
expect(untar.code).toBe(0);
this.packagedCore = require(path.join(
@@ -26,7 +29,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)
};
@@ -58,7 +61,7 @@ describe('npm package', function() {
'jasmine-html.js'
]);
var packagedCore = this.packagedCore;
const packagedCore = this.packagedCore;
this.packagedCore.files.jsFiles.forEach(function(fileName) {
expect(fileName).toExistInPath(packagedCore.files.path);
});
@@ -67,7 +70,7 @@ describe('npm package', function() {
it('has cssFiles', function() {
expect(this.packagedCore.files.cssFiles).toEqual(['jasmine.css']);
var packagedCore = this.packagedCore;
const packagedCore = this.packagedCore;
this.packagedCore.files.cssFiles.forEach(function(fileName) {
expect(fileName).toExistInPath(packagedCore.files.path);
});
@@ -77,22 +80,20 @@ describe('npm package', function() {
expect(this.packagedCore.files.bootFiles).toEqual(['boot0.js', 'boot1.js']);
expect(this.packagedCore.files.nodeBootFiles).toEqual(['node_boot.js']);
var packagedCore = this.packagedCore;
this.packagedCore.files.bootFiles.forEach(function(fileName) {
expect(fileName).toExistInPath(packagedCore.files.bootDir);
});
for (const fileName of this.packagedCore.files.bootFiles) {
expect(fileName).toExistInPath(this.packagedCore.files.bootDir);
}
var packagedCore = this.packagedCore;
this.packagedCore.files.nodeBootFiles.forEach(function(fileName) {
expect(fileName).toExistInPath(packagedCore.files.bootDir);
});
for (const fileName of this.packagedCore.files.nodeBootFiles) {
expect(fileName).toExistInPath(this.packagedCore.files.bootDir);
}
});
it('has an imagesDir', function() {
expect(this.packagedCore.files.imagesDir).toEqual(
fs.realpathSync(path.resolve(this.tmpDir, 'package/images'))
);
var images = fs.readdirSync(path.resolve(this.tmpDir, 'package/images'));
const images = fs.readdirSync(path.resolve(this.tmpDir, 'package/images'));
expect(images).toContain('jasmine-horizontal.png');
expect(images).toContain('jasmine-horizontal.svg');
@@ -109,12 +110,12 @@ describe('npm package', function() {
});
it('does not have any unexpected files in the root directory', function() {
var files = fs.readdirSync(this.tmpDir);
const files = fs.readdirSync(this.tmpDir);
expect(files).toEqual(['package']);
});
it('does not have any unexpected files in the package directory', function() {
var files = fs.readdirSync(path.resolve(this.tmpDir, 'package'));
const files = fs.readdirSync(path.resolve(this.tmpDir, 'package'));
files.sort();
expect(files).toEqual([
'MIT.LICENSE',
@@ -126,23 +127,20 @@ describe('npm package', function() {
});
it('only has images in the images dir', function() {
var files = fs.readdirSync(path.resolve(this.tmpDir, 'package/images')),
i;
const files = fs.readdirSync(path.resolve(this.tmpDir, 'package/images'));
for (i = 0; i < files.length; i++) {
for (let i = 0; i < files.length; i++) {
expect(files[i]).toMatch(/\.(svg|png)$/);
}
});
it('only has JS and CSS files in the lib dir', function() {
var files = [],
i;
const files = [];
function getFiles(dir) {
var dirents = fs.readdirSync(dir, { withFileTypes: true }),
j;
const dirents = fs.readdirSync(dir, { withFileTypes: true });
for (j = 0; j < dirents.length; j++) {
for (let j = 0; j < dirents.length; j++) {
const dirent = dirents[j];
if (dirent.isDirectory()) {
@@ -155,7 +153,7 @@ describe('npm package', function() {
getFiles(path.resolve(this.tmpDir, 'package/lib'));
for (i = 0; i < files.length; i++) {
for (let i = 0; i < files.length; i++) {
expect(files[i]).toMatch(/\.(js|css)$/);
}
});