From 9b41c2da9f49d9777660b7865ffa1ffa14b27fc1 Mon Sep 17 00:00:00 2001 From: Marco Biedermann Date: Thu, 11 Feb 2016 12:57:22 +0100 Subject: [PATCH] use es2015 syntax in mocha tests --- package.json | 10 +++++++++- test/file_content.js | 41 ++++++++++++++++++++--------------------- test/file_existence.js | 42 ++++++++++++++++++++++-------------------- 3 files changed, 51 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 9e59fa685c..49edbb982f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "@alrra/travis-scripts": "^1.1.1", "apache-server-configs": "2.14.0", "archiver": "^0.21.0", + "babel-core": "^6.5.1", + "babel-preset-es2015": "^6.5.0", + "babel-register": "^6.5.1", "del": "^2.0.2", "glob": "^6.0.1", "gulp": "^3.8.11", @@ -23,6 +26,11 @@ "engines": { "node": ">=0.10.0" }, + "babel": { + "presets": [ + "es2015" + ] + }, "h5bp-configs": { "directories": { "archive": "archive", @@ -40,7 +48,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" } diff --git a/test/file_content.js b/test/file_content.js index 32b8e1da12..57da3ba856 100644 --- a/test/file_content.js +++ b/test/file_content.js @@ -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.type + ' License' + - ' | ' + pkg.homepage + ' */\n\n/*\n'; + it('"main.css" should contain a custom banner', (done) => { + const string = `/*! HTML5 Boilerplate v${pkg.version} | ${pkg.license.type} License | ${pkg.homepage} */\n\n/*\n`; checkString(path.resolve(dir, 'css/main.css'), string, done); }); diff --git a/test/file_existence.js b/test/file_existence.js index ecc9376d18..6993fac26d 100644 --- a/test/file_existence.js +++ b/test/file_existence.js @@ -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', @@ -49,7 +51,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', @@ -64,7 +66,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 @@ -72,10 +74,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) { @@ -93,7 +95,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); }); @@ -101,10 +103,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); }); }); @@ -115,13 +117,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); });