Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use es2015 syntax in mocha tests #1788

Merged
merged 4 commits into from
Dec 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -32,6 +33,11 @@
"engines": {
"node": ">=0.10.0"
},
"babel": {
"presets": [
"es2015"
]
},
"h5bp-configs": {
"directories": {
"archive": "archive",
Expand All @@ -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"
}
39 changes: 19 additions & 20 deletions test/file_content.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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);
});

Expand Down
42 changes: 22 additions & 20 deletions test/file_existence.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -63,18 +65,18 @@ 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
});

// 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) {
Expand All @@ -92,18 +94,18 @@ 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);
});

});

// 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);
});
});
Expand All @@ -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);
});

Expand Down