mirror of
https://github.com/h5bp/html5-boilerplate.git
synced 2026-01-09 14:48:02 -05:00
use es2015 syntax in mocha tests (#1788)
use import instead of require
use fat arrow => function instead of function() {} callback
use and let and const instead of var
use template stings instead of string concatenation
This commit is contained in:
committed by
Rob Larsen
parent
41b63975e5
commit
2ea87deb35
@@ -10,6 +10,7 @@
|
||||
"archiver": "^0.21.0",
|
||||
"babel-core": "^6.13.2",
|
||||
"babel-preset-es2015": "^6.6.0",
|
||||
"babel-register": "^6.8.0",
|
||||
"del": "^2.2.1",
|
||||
"glob": "^7.0.5",
|
||||
"gulp": "^3.9.1",
|
||||
@@ -32,6 +33,11 @@
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
"es2015"
|
||||
]
|
||||
},
|
||||
"h5bp-configs": {
|
||||
"directories": {
|
||||
"archive": "archive",
|
||||
@@ -46,7 +52,7 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "gulp build",
|
||||
"test": "gulp archive && mocha --reporter spec --timeout 5000"
|
||||
"test": "gulp archive && mocha --compilers js:babel-register --reporter spec --timeout 5000"
|
||||
},
|
||||
"version": "5.3.0"
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
/* jshint mocha: true */
|
||||
|
||||
var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
import assert from 'assert';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
var pkg = require('./../package.json');
|
||||
var dirs = pkg['h5bp-configs'].directories;
|
||||
import pkg from './../package.json';
|
||||
|
||||
const dirs = pkg['h5bp-configs'].directories;
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
function checkString(file, string, done) {
|
||||
|
||||
var character = '';
|
||||
var matchFound = false;
|
||||
var matchedPositions = 0;
|
||||
var readStream = fs.createReadStream(file, { 'encoding': 'utf8' });
|
||||
let character = '';
|
||||
let matchFound = false;
|
||||
let matchedPositions = 0;
|
||||
const readStream = fs.createReadStream(file, { 'encoding': 'utf8' });
|
||||
|
||||
readStream.on('close', done);
|
||||
readStream.on('error', done);
|
||||
@@ -48,29 +49,27 @@ function checkString(file, string, done) {
|
||||
|
||||
function runTests() {
|
||||
|
||||
var dir = dirs.dist;
|
||||
const dir = dirs.dist;
|
||||
|
||||
describe('Test if the files from the "' + dir + '" directory have the expected content', function () {
|
||||
describe(`Test if the files from the "${dir}" directory have the expected content`, () => {
|
||||
|
||||
it('".htaccess" should have the "ErrorDocument..." line uncommented', function (done) {
|
||||
var string = '\n\nErrorDocument 404 /404.html\n\n';
|
||||
it('".htaccess" should have the "ErrorDocument..." line uncommented', (done) => {
|
||||
const string = '\n\nErrorDocument 404 /404.html\n\n';
|
||||
checkString(path.resolve(dir, '.htaccess'), string, done);
|
||||
});
|
||||
|
||||
it('"index.html" should contain the correct jQuery version in the CDN URL', function (done) {
|
||||
var string = 'code.jquery.com/jquery-' + pkg.devDependencies.jquery + '.min.js';
|
||||
it('"index.html" should contain the correct jQuery version in the CDN URL', (done) => {
|
||||
const string = `code.jquery.com/jquery-${pkg.devDependencies.jquery}.min.js`;
|
||||
checkString(path.resolve(dir, 'index.html'), string, done);
|
||||
});
|
||||
|
||||
it('"index.html" should contain the correct jQuery version in the local URL', function (done) {
|
||||
var string = 'js/vendor/jquery-' + pkg.devDependencies.jquery + '.min.js';
|
||||
it('"index.html" should contain the correct jQuery version in the local URL', (done) => {
|
||||
const string = `js/vendor/jquery-${pkg.devDependencies.jquery}.min.js`;
|
||||
checkString(path.resolve(dir, 'index.html'), string, done);
|
||||
});
|
||||
|
||||
it('"main.css" should contain a custom banner', function (done) {
|
||||
var string = '/*! HTML5 Boilerplate v' + pkg.version +
|
||||
' | ' + pkg.license + ' License' +
|
||||
' | ' + pkg.homepage + ' */\n\n/*\n';
|
||||
const string = `/*! HTML5 Boilerplate v${pkg.version} | ${pkg.license} License | ${pkg.homepage} */\n\n/*\n`;
|
||||
checkString(path.resolve(dir, 'css/main.css'), string, done);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
/* jshint mocha: true */
|
||||
|
||||
var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
import assert from 'assert';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import glob from 'glob';
|
||||
|
||||
var pkg = require('./../package.json');
|
||||
var dirs = pkg['h5bp-configs'].directories;
|
||||
import pkg from './../package.json';
|
||||
|
||||
var expectedFilesInArchiveDir = [
|
||||
pkg.name + '_v' + pkg.version + '.zip'
|
||||
const dirs = pkg['h5bp-configs'].directories;
|
||||
|
||||
const expectedFilesInArchiveDir = [
|
||||
`${pkg.name}_v${pkg.version}.zip`
|
||||
];
|
||||
|
||||
var expectedFilesInDistDir = [
|
||||
const expectedFilesInDistDir = [
|
||||
|
||||
'.editorconfig',
|
||||
'.gitattributes',
|
||||
@@ -48,7 +50,7 @@ var expectedFilesInDistDir = [
|
||||
'js/main.js',
|
||||
'js/plugins.js',
|
||||
'js/vendor/',
|
||||
'js/vendor/jquery-' + pkg.devDependencies.jquery + '.min.js',
|
||||
`js/vendor/jquery-${pkg.devDependencies.jquery}.min.js`,
|
||||
'js/vendor/modernizr-2.8.3.min.js',
|
||||
|
||||
'LICENSE.txt',
|
||||
@@ -63,7 +65,7 @@ var expectedFilesInDistDir = [
|
||||
function checkFiles(directory, expectedFiles) {
|
||||
|
||||
// Get the list of files from the specified directory
|
||||
var files = require('glob').sync('**/*', {
|
||||
const files = glob.sync('**/*', {
|
||||
'cwd': directory,
|
||||
'dot': true, // include hidden files
|
||||
'mark': true // add a `/` character to directory matches
|
||||
@@ -71,10 +73,10 @@ function checkFiles(directory, expectedFiles) {
|
||||
|
||||
// Check if all expected files are present in the
|
||||
// specified directory, and are of the expected type
|
||||
expectedFiles.forEach(function (file) {
|
||||
expectedFiles.forEach( (file) => {
|
||||
|
||||
var ok = false;
|
||||
var expectedFileType = (file.slice(-1) !== '/' ? 'regular file' : 'directory');
|
||||
let ok = false;
|
||||
const expectedFileType = (file.slice(-1) !== '/' ? 'regular file' : 'directory');
|
||||
|
||||
// If file exists
|
||||
if (files.indexOf(file) !== -1) {
|
||||
@@ -92,7 +94,7 @@ function checkFiles(directory, expectedFiles) {
|
||||
|
||||
}
|
||||
|
||||
it('"' + file + '" should be present and it should be a ' + expectedFileType, function () {
|
||||
it(`"${file}" should be present and it should be a ${expectedFileType}`, () =>{
|
||||
assert.equal(true, ok);
|
||||
});
|
||||
|
||||
@@ -100,10 +102,10 @@ function checkFiles(directory, expectedFiles) {
|
||||
|
||||
// List all files that should be NOT
|
||||
// be present in the specified directory
|
||||
(files.filter(function (file) {
|
||||
(files.filter( (file) => {
|
||||
return expectedFiles.indexOf(file) === -1;
|
||||
})).forEach(function (file) {
|
||||
it('"' + file + '" should NOT be present', function () {
|
||||
})).forEach( (file) => {
|
||||
it(`"${file}" should NOT be present`, () => {
|
||||
assert(false);
|
||||
});
|
||||
});
|
||||
@@ -114,13 +116,13 @@ function checkFiles(directory, expectedFiles) {
|
||||
|
||||
function runTests() {
|
||||
|
||||
describe('Test if all the expected files, and only them, are present in the build directories', function () {
|
||||
describe('Test if all the expected files, and only them, are present in the build directories', () => {
|
||||
|
||||
describe(dirs.archive, function () {
|
||||
describe(dirs.archive, () => {
|
||||
checkFiles(dirs.archive, expectedFilesInArchiveDir);
|
||||
});
|
||||
|
||||
describe(dirs.dist, function () {
|
||||
describe(dirs.dist, () => {
|
||||
checkFiles(dirs.dist, expectedFilesInDistDir);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user