From d535bac654432001103160760ef4526d46cae153 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 12 Feb 2017 03:23:14 +0700 Subject: [PATCH] Initial ES2015ification --- .travis.yml | 2 - benchmark/module.js | 4 +- gulpfile.js | 28 +-- lib/actions/help.js | 34 +-- lib/actions/install.js | 42 ++-- lib/actions/spawn-command.js | 6 +- lib/actions/user.js | 16 +- lib/index.js | 153 +++++++------- lib/util/binary-diff.js | 24 +-- lib/util/conflicter.js | 46 +++-- lib/util/deprecate.js | 20 +- lib/util/prompt-suggestion.js | 40 ++-- lib/util/storage.js | 16 +- package.json | 8 +- test/base.js | 376 +++++++++++++++++----------------- test/conflicter.js | 92 ++++----- test/deprecate.js | 34 +-- test/generators.js | 12 +- test/install.js | 92 ++++----- test/prompt-suggestion.js | 118 +++++------ test/spawn-command.js | 10 +- test/storage.js | 60 +++--- test/user.js | 46 ++--- 23 files changed, 641 insertions(+), 638 deletions(-) diff --git a/.travis.yml b/.travis.yml index de01b73a..8797713f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ sudo: false language: node_js node_js: - - 0.10 - - 0.12 - 4 - 6 - node diff --git a/benchmark/module.js b/benchmark/module.js index f4c31e43..d361cbbb 100644 --- a/benchmark/module.js +++ b/benchmark/module.js @@ -1,8 +1,8 @@ /* global suite, bench */ 'use strict'; -suite('yeoman-generator module', function () { - bench('require', function () { +suite('yeoman-generator module', () => { + bench('require', () => { require('..'); // eslint-disable-line import/no-unassigned-import delete require.cache[require.resolve('..')]; }); diff --git a/gulpfile.js b/gulpfile.js index 1d73ceb7..498e60a9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,17 +1,17 @@ 'use strict'; -var path = require('path'); -var gulp = require('gulp'); -var mocha = require('gulp-mocha'); -var istanbul = require('gulp-istanbul'); -var nsp = require('gulp-nsp'); -var plumber = require('gulp-plumber'); -var coveralls = require('gulp-coveralls'); +const path = require('path'); +const gulp = require('gulp'); +const mocha = require('gulp-mocha'); +const istanbul = require('gulp-istanbul'); +const nsp = require('gulp-nsp'); +const plumber = require('gulp-plumber'); +const coveralls = require('gulp-coveralls'); -gulp.task('nsp', function (cb) { +gulp.task('nsp', cb => { nsp({package: path.resolve('package.json')}, cb); }); -gulp.task('pre-test', function () { +gulp.task('pre-test', () => { return gulp.src([ 'lib/**/*.js' ]) @@ -19,22 +19,22 @@ gulp.task('pre-test', function () { .pipe(istanbul.hookRequire()); }); -gulp.task('test', ['pre-test'], function (cb) { - var mochaErr; +gulp.task('test', ['pre-test'], cb => { + let mochaErr; gulp.src('test/*.js') .pipe(plumber()) .pipe(mocha({reporter: 'spec', timeout: 3000})) - .on('error', function (err) { + .on('error', err => { mochaErr = err; }) .pipe(istanbul.writeReports()) - .on('end', function () { + .on('end', () => { cb(mochaErr); }); }); -gulp.task('coveralls', ['test'], function () { +gulp.task('coveralls', ['test'], () => { if (!process.env.CI) { return; } diff --git a/lib/actions/help.js b/lib/actions/help.js index 1b11f319..34b81eaa 100644 --- a/lib/actions/help.js +++ b/lib/actions/help.js @@ -1,15 +1,15 @@ 'use strict'; -var path = require('path'); -var fs = require('fs'); -var _ = require('lodash'); -var table = require('text-table'); -var pathExists = require('path-exists'); +const path = require('path'); +const fs = require('fs'); +const _ = require('lodash'); +const table = require('text-table'); +const pathExists = require('path-exists'); /** * @mixin * @alias actions/help */ -var help = module.exports; +const help = module.exports; /** * Tries to get the description from a USAGE file one folder above the @@ -17,9 +17,9 @@ var help = module.exports; */ help.help = function () { - var filepath = path.join(this.sourceRoot(), '../USAGE'); - var exists = pathExists.sync(filepath); - var out = [ + const filepath = path.join(this.sourceRoot(), '../USAGE'); + const exists = pathExists.sync(filepath); + let out = [ 'Usage:', ' ' + this.usage(), '' @@ -52,7 +52,7 @@ help.help = function () { }; function formatArg(config) { - var arg = '<' + config.name + '>'; + let arg = '<' + config.name + '>'; if (!config.required) { arg = '[' + arg + ']'; @@ -67,16 +67,16 @@ function formatArg(config) { */ help.usage = function () { - var options = Object.keys(this._options).length ? '[options]' : ''; - var name = ' ' + this.options.namespace; - var args = ''; + const options = Object.keys(this._options).length ? '[options]' : ''; + let name = ' ' + this.options.namespace; + let args = ''; if (this._arguments.length > 0) { args = this._arguments.map(formatArg).join(' '); } name = name.replace(/^yeoman:/, ''); - var out = 'yo' + name + ' ' + options + ' ' + args; + let out = 'yo' + name + ' ' + options + ' ' + args; if (this.description) { out += '\n\n' + this.description; @@ -101,7 +101,7 @@ help.desc = function (description) { * @returns {String} Text of options in formatted table */ help.argumentsHelp = function () { - var rows = this._arguments.map(function (config) { + const rows = this._arguments.map(config => { return [ '', config.name ? config.name : '', @@ -119,11 +119,11 @@ help.argumentsHelp = function () { * @returns {String} Text of options in formatted table */ help.optionsHelp = function () { - var options = _.reject(this._options, function (el) { + const options = _.reject(this._options, el => { return el.hide; }); - var rows = options.map(function (opt) { + const rows = options.map(opt => { return [ '', opt.alias ? '-' + opt.alias + ', ' : '', diff --git a/lib/actions/install.js b/lib/actions/install.js index 55b75cd4..914c6416 100644 --- a/lib/actions/install.js +++ b/lib/actions/install.js @@ -1,15 +1,15 @@ 'use strict'; -var assert = require('assert'); -var _ = require('lodash'); -var dargs = require('dargs'); -var async = require('async'); -var chalk = require('chalk'); +const assert = require('assert'); +const _ = require('lodash'); +const dargs = require('dargs'); +const async = require('async'); +const chalk = require('chalk'); /** * @mixin * @alias actions/install */ -var install = module.exports; +const install = module.exports; /** * Combine package manager cmd line arguments and run the `install` command. @@ -36,7 +36,7 @@ install.runInstall = function (installer, paths, options, cb, spawnOptions) { cb = cb || function () {}; paths = Array.isArray(paths) ? paths : (paths && paths.split(' ')) || []; - var args = ['install'].concat(paths).concat(dargs(options)); + let args = ['install'].concat(paths).concat(dargs(options)); // Yarn uses the `add` command to specifically add a package to a project. if (installer === 'yarn' && paths.length > 0) { @@ -54,22 +54,22 @@ install.runInstall = function (installer, paths, options, cb, spawnOptions) { return this; } - this.env.runLoop.add('install', function (done) { + this.env.runLoop.add('install', done => { this.emit(installer + 'Install', paths); this.spawnCommand(installer, args, spawnOptions) - .on('error', function (err) { + .on('error', err => { console.log(chalk.red('Could not finish installation. \n') + 'Please install ' + installer + ' with ' + chalk.yellow('npm install -g ' + installer) + ' and try again.' ); cb(err); }) - .on('exit', function (err) { + .on('exit', err => { this.emit(installer + 'Install:end', paths); cb(err); done(); - }.bind(this)); - }.bind(this), {once: installer + ' ' + args.join(' '), run: false}); + }); + }, {once: installer + ' ' + args.join(' '), run: false}); return this; }; @@ -97,8 +97,8 @@ install.runInstall = function (installer, paths, options, cb, spawnOptions) { install.installDependencies = function (options) { options = options || {}; - var commands = []; - var msg = { + const commands = []; + const msg = { commands: [], template: _.template('\n\nI\'m all done. ' + '<%= skipInstall ? "Just run" : "Running" %> <%= commands %> ' + @@ -114,29 +114,29 @@ install.installDependencies = function (options) { if (options.npm !== false) { msg.commands.push('npm install'); - commands.push(function (cb) { + commands.push(cb => { this.npmInstall(null, null, cb); - }.bind(this)); + }); } if (options.yarn === true) { msg.commands.push('yarn install'); - commands.push(function (cb) { + commands.push(cb => { this.yarnInstall(null, null, cb); - }.bind(this)); + }); } if (options.bower !== false) { msg.commands.push('bower install'); - commands.push(function (cb) { + commands.push(cb => { this.bowerInstall(null, null, cb); - }.bind(this)); + }); } assert(msg.commands.length, 'installDependencies needs at least one of `npm`, `bower` or `yarn` to run.'); if (!options.skipMessage) { - var tplValues = _.extend({ + const tplValues = _.extend({ skipInstall: false }, this.options, { commands: chalk.yellow.bold(msg.commands.join(' && ')) diff --git a/lib/actions/spawn-command.js b/lib/actions/spawn-command.js index 52b644fe..3ddb3c9a 100644 --- a/lib/actions/spawn-command.js +++ b/lib/actions/spawn-command.js @@ -1,12 +1,12 @@ 'use strict'; -var _ = require('lodash'); -var spawn = require('cross-spawn'); +const _ = require('lodash'); +const spawn = require('cross-spawn'); /** * @mixin * @alias actions/spawn-command */ -var spawnCommand = module.exports; +const spawnCommand = module.exports; /** * Normalize a command across OS and spawn it (asynchronously). diff --git a/lib/actions/user.js b/lib/actions/user.js index 10b1446a..81c8d8d5 100644 --- a/lib/actions/user.js +++ b/lib/actions/user.js @@ -1,15 +1,15 @@ 'use strict'; -var shell = require('shelljs'); -var githubUsername = require('github-username'); +const shell = require('shelljs'); +const githubUsername = require('github-username'); -var nameCache = {}; -var emailCache = {}; +const nameCache = {}; +const emailCache = {}; /** * @mixin * @alias actions/user */ -var user = module.exports; +const user = module.exports; user.git = {}; user.github = {}; @@ -20,7 +20,7 @@ user.github = {}; */ user.git.name = function () { - var name = nameCache[process.cwd()]; + let name = nameCache[process.cwd()]; if (name) { return name; @@ -40,7 +40,7 @@ user.git.name = function () { */ user.git.email = function () { - var email = emailCache[process.cwd()]; + let email = emailCache[process.cwd()]; if (email) { return email; @@ -59,7 +59,7 @@ user.git.email = function () { */ user.github.username = function (cb) { - var promise = githubUsername(user.git.email()); + const promise = githubUsername(user.git.email()); if (cb) { promise.then( diff --git a/lib/index.js b/lib/index.js index fafbfd4b..1ef95f06 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,26 +1,26 @@ 'use strict'; -var util = require('util'); -var path = require('path'); -var events = require('events'); -var assert = require('assert'); -var _ = require('lodash'); -var findUp = require('find-up'); -var readPkgUp = require('read-pkg-up'); -var chalk = require('chalk'); -var mkdirp = require('mkdirp'); -var minimist = require('minimist'); -var runAsync = require('run-async'); -var through = require('through2'); -var userHome = require('user-home'); -var FileEditor = require('mem-fs-editor'); -var pathIsAbsolute = require('path-is-absolute'); -var pathExists = require('path-exists'); -var debug = require('debug')('yeoman:generator'); -var Conflicter = require('./util/conflicter'); -var Storage = require('./util/storage'); -var promptSuggestion = require('./util/prompt-suggestion'); - -var EMPTY = '@@_YEOMAN_EMPTY_MARKER_@@'; +const util = require('util'); +const path = require('path'); +const events = require('events'); +const assert = require('assert'); +const _ = require('lodash'); +const findUp = require('find-up'); +const readPkgUp = require('read-pkg-up'); +const chalk = require('chalk'); +const mkdirp = require('mkdirp'); +const minimist = require('minimist'); +const runAsync = require('run-async'); +const through = require('through2'); +const userHome = require('user-home'); +const FileEditor = require('mem-fs-editor'); +const pathIsAbsolute = require('path-is-absolute'); +const pathExists = require('path-exists'); +const debug = require('debug')('yeoman:generator'); +const Conflicter = require('./util/conflicter'); +const Storage = require('./util/storage'); +const promptSuggestion = require('./util/prompt-suggestion'); + +const EMPTY = '@@_YEOMAN_EMPTY_MARKER_@@'; /** * The `Base` class provides the common API shared by all generators. @@ -58,7 +58,7 @@ var EMPTY = '@@_YEOMAN_EMPTY_MARKER_@@'; * }; */ -var Base = module.exports = function (args, options) { +const Base = function (args, options) { events.EventEmitter.call(this); if (!Array.isArray(args)) { @@ -120,7 +120,7 @@ var Base = module.exports = function (args, options) { // Determine the app root this.contextRoot = this.env.cwd; - var rootPath = findUp.sync('.yo-rc.json', { + let rootPath = findUp.sync('.yo-rc.json', { cwd: this.env.cwd }); rootPath = rootPath ? path.dirname(rootPath) : this.env.cwd; @@ -165,14 +165,14 @@ Base.prototype.prompt = function (questions) { questions = promptSuggestion.prefillQuestions(this._globalConfig, questions); questions = promptSuggestion.prefillQuestions(this.config, questions); - return this.env.adapter.prompt(questions).then(function (answers) { + return this.env.adapter.prompt(questions).then(answers => { if (!this.options['skip-cache']) { promptSuggestion.storeAnswers(this._globalConfig, questions, answers, false); promptSuggestion.storeAnswers(this.config, questions, answers, true); } return answers; - }.bind(this)); + }); }; /** @@ -202,16 +202,16 @@ Base.prototype.option = function (name, config) { config.description = config.description || config.desc; _.defaults(config, { - name: name, + name, description: 'Description for ' + name, type: Boolean, hide: false }); // Check whether boolean option is invalid (starts with no-) - var boolOptionRegex = /^no-/; + const boolOptionRegex = /^no-/; if (config.type === Boolean && name.match(boolOptionRegex)) { - let simpleName = name.replace(boolOptionRegex, ''); + const simpleName = name.replace(boolOptionRegex, ''); return this.emit('error', new Error([ `Option name ${chalk.yellow(name)} cannot start with ${chalk.red('no-')}\n`, `Option name prefixed by ${chalk.yellow('--no')} are parsed as implicit`, @@ -260,7 +260,7 @@ Base.prototype.argument = function (name, config) { config.description = config.description || config.desc; _.defaults(config, { - name: name, + name, required: config.default === null || config.default === undefined, type: String }); @@ -272,14 +272,14 @@ Base.prototype.argument = function (name, config) { }; Base.prototype.parseOptions = function () { - var minimistDef = { + const minimistDef = { string: [], boolean: [], alias: {}, default: {} }; - _.each(this._options, function (option) { + _.each(this._options, option => { if (option.type === Boolean) { minimistDef.boolean.push(option.name); if (!('default' in option) && !option.required) { @@ -302,12 +302,12 @@ Base.prototype.parseOptions = function () { } else if ('default' in option) { minimistDef.default[option.name] = option.default; } - }.bind(this)); + }); - var parsedOpts = minimist(this._args, minimistDef); + const parsedOpts = minimist(this._args, minimistDef); // Parse options to the desired type - _.each(parsedOpts, function (option, name) { + _.each(parsedOpts, (option, name) => { // Manually set value as undefined if it should be. if (option === EMPTY) { parsedOpts[name] = undefined; @@ -316,11 +316,11 @@ Base.prototype.parseOptions = function () { if (this._options[name] && option !== undefined) { parsedOpts[name] = this._options[name].type(option); } - }.bind(this)); + }); // Parse positional arguments to valid options - this._arguments.forEach(function (config, index) { - var value; + this._arguments.forEach((config, index) => { + let value; if (index >= parsedOpts._.length) { if (config.name in this._initOptions) { value = this._initOptions[config.name]; @@ -336,11 +336,12 @@ Base.prototype.parseOptions = function () { } parsedOpts[config.name] = value; - }.bind(this)); + }); // Make the parsed options available to the instance _.extend(this.options, parsedOpts); - this.args = this.arguments = parsedOpts._; + this.args = parsedOpts._; + this.arguments = parsedOpts._; // Make sure required args are all present this.checkRequiredArgs(); @@ -384,18 +385,18 @@ Base.prototype.checkRequiredArgs = function () { Base.prototype.run = function (cb) { cb = cb || function () {}; - var self = this; + const self = this; this._running = true; this.emit('run'); - var methods = Object.getOwnPropertyNames(Object.getPrototypeOf(this)); - var validMethods = methods.filter(methodIsValid); + const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(this)); + const validMethods = methods.filter(methodIsValid); assert(validMethods.length, 'This Generator is empty. Add at least one method for it to run.'); - this.env.runLoop.once('end', function () { + this.env.runLoop.once('end', () => { this.emit('end'); cb(); - }.bind(this)); + }); // Ensure a prototype method is a candidate run by default function methodIsValid(name) { @@ -405,7 +406,7 @@ Base.prototype.run = function (cb) { function addMethod(method, methodName, queueName) { queueName = queueName || 'default'; debug('Queueing ' + methodName + ' in ' + queueName); - self.env.runLoop.add(queueName, function (completed) { + self.env.runLoop.add(queueName, completed => { debug('Running ' + methodName); self.emit('method:' + methodName); @@ -415,12 +416,12 @@ Base.prototype.run = function (cb) { }.bind(this); return method.apply(self, self.args); - })().then(completed).catch(function (err) { + })().then(completed).catch(err => { debug('An error occured while running ' + methodName, err); // Ensure we emit the error event outside the promise context so it won't be // swallowed when there's no listeners. - setImmediate(function () { + setImmediate(() => { self.emit('error', err); cb(err); }); @@ -429,8 +430,8 @@ Base.prototype.run = function (cb) { } function addInQueue(name) { - var item = Object.getPrototypeOf(self)[name]; - var queueName = self.env.runLoop.queueNames.indexOf(name) === -1 ? null : name; + const item = Object.getPrototypeOf(self)[name]; + const queueName = self.env.runLoop.queueNames.indexOf(name) === -1 ? null : name; // Name points to a function; run it! if (_.isFunction(item)) { @@ -443,7 +444,7 @@ Base.prototype.run = function (cb) { } // Run each queue items - _.each(item, function (method, methodName) { + _.each(item, (method, methodName) => { if (!_.isFunction(method) || !methodIsValid(methodName)) { return; } @@ -454,7 +455,7 @@ Base.prototype.run = function (cb) { validMethods.forEach(addInQueue); - var writeFiles = function () { + const writeFiles = function () { this.env.runLoop.add('conflicts', this._writeFiles.bind(this), { once: 'write memory fs to disk' }); @@ -464,15 +465,15 @@ Base.prototype.run = function (cb) { writeFiles(); // Add the default conflicts handling - this.env.runLoop.add('conflicts', function (done) { - this.conflicter.resolve(function (err) { + this.env.runLoop.add('conflicts', done => { + this.conflicter.resolve(err => { if (err) { this.emit('error', err); } done(); - }.bind(this)); - }.bind(this)); + }); + }); _.invokeMap(this._composedWith, 'run'); return this; @@ -497,7 +498,7 @@ Base.prototype.run = function (cb) { */ Base.prototype.composeWith = function (modulePath, options) { - var generator; + let generator; options = options || {}; // Pass down the default options so they're correclty mirrored down the chain. @@ -509,17 +510,17 @@ Base.prototype.composeWith = function (modulePath, options) { }, options); try { - var Generator = require(modulePath); // eslint-disable-line import/no-dynamic-require + const Generator = require(modulePath); // eslint-disable-line import/no-dynamic-require Generator.resolved = require.resolve(modulePath); Generator.namespace = this.env.namespace(modulePath); generator = this.env.instantiate(Generator, { - options: options, + options, arguments: options.arguments }); } catch (err) { if (err.code === 'MODULE_NOT_FOUND') { generator = this.env.create(modulePath, { - options: options, + options, arguments: options.arguments }); } else { @@ -542,7 +543,7 @@ Base.prototype.composeWith = function (modulePath, options) { */ Base.prototype.rootGeneratorName = function () { - var pkg = readPkgUp.sync({cwd: this.resolved}).pkg; + const pkg = readPkgUp.sync({cwd: this.resolved}).pkg; return pkg ? pkg.name : '*'; }; @@ -552,7 +553,7 @@ Base.prototype.rootGeneratorName = function () { */ Base.prototype.rootGeneratorVersion = function () { - var pkg = readPkgUp.sync({cwd: this.resolved}).pkg; + const pkg = readPkgUp.sync({cwd: this.resolved}).pkg; return pkg ? pkg.version : '0.0.0'; }; @@ -563,7 +564,7 @@ Base.prototype.rootGeneratorVersion = function () { */ Base.prototype._getStorage = function () { - var storePath = path.join(this.destinationRoot(), '.yo-rc.json'); + const storePath = path.join(this.destinationRoot(), '.yo-rc.json'); return new Storage(this.rootGeneratorName(), this.fs, storePath); }; @@ -574,8 +575,8 @@ Base.prototype._getStorage = function () { */ Base.prototype._getGlobalStorage = function () { - var storePath = path.join(userHome, '.yo-rc-global.json'); - var storeName = util.format('%s:%s', this.rootGeneratorName(), this.rootGeneratorVersion()); + const storePath = path.join(userHome, '.yo-rc-global.json'); + const storeName = util.format('%s:%s', this.rootGeneratorName(), this.rootGeneratorVersion()); return new Storage(storeName, this.fs, storePath); }; @@ -627,7 +628,7 @@ Base.prototype.sourceRoot = function (rootPath) { */ Base.prototype.templatePath = function () { - var filepath = path.join.apply(path, arguments); + let filepath = path.join.apply(path, arguments); if (!pathIsAbsolute(filepath)) { filepath = path.join(this.sourceRoot(), filepath); @@ -643,7 +644,7 @@ Base.prototype.templatePath = function () { */ Base.prototype.destinationPath = function () { - var filepath = path.join.apply(path, arguments); + let filepath = path.join.apply(path, arguments); if (!pathIsAbsolute(filepath)) { filepath = path.join(this.destinationRoot(), filepath); @@ -661,7 +662,7 @@ Base.prototype.destinationPath = function () { * @return {String} The name of the application */ Base.prototype.determineAppname = function () { - var appname = this.fs.readJSON(this.destinationPath('bower.json'), {}).name; + let appname = this.fs.readJSON(this.destinationPath('bower.json'), {}).name; if (!appname) { appname = this.fs.readJSON(this.destinationPath('package.json'), {}).name; @@ -697,10 +698,10 @@ Base.prototype.registerTransformStream = function (streams) { * @param {Function} done - callback once files are written */ Base.prototype._writeFiles = function (done) { - var self = this; + const self = this; - var conflictChecker = through.obj(function (file, enc, cb) { - var stream = this; + const conflictChecker = through.obj(function (file, enc, cb) { + const stream = this; // If the file has no state requiring action, move on if (file.state === null) { @@ -708,14 +709,14 @@ Base.prototype._writeFiles = function (done) { } // Config file should not be processed by the conflicter. Just pass through - var filename = path.basename(file.path); + const filename = path.basename(file.path); if (filename === '.yo-rc.json' || filename === '.yo-rc-global.json') { this.push(file); return cb(); } - self.conflicter.checkForCollision(file.path, file.contents, function (err, status) { + self.conflicter.checkForCollision(file.path, file.contents, (err, status) => { if (err) { cb(err); return; @@ -732,8 +733,8 @@ Base.prototype._writeFiles = function (done) { self.conflicter.resolve(); }); - var transformStreams = this._transformStreams.concat([conflictChecker]); - this.fs.commit(transformStreams, function () { + const transformStreams = this._transformStreams.concat([conflictChecker]); + this.fs.commit(transformStreams, () => { done(); }); }; @@ -752,3 +753,5 @@ Base.prototype._writeFiles = function (done) { * }); */ Base.extend = require('class-extend').extend; + +module.exports = Base; diff --git a/lib/util/binary-diff.js b/lib/util/binary-diff.js index 9f8f18b1..66705f08 100644 --- a/lib/util/binary-diff.js +++ b/lib/util/binary-diff.js @@ -1,24 +1,24 @@ 'use strict'; -var fs = require('fs'); -var readChunk = require('read-chunk'); -var istextorbinary = require('istextorbinary'); -var dateFormat = require('dateformat'); -var prettyBytes = require('pretty-bytes'); -var Table = require('cli-table'); +const fs = require('fs'); +const readChunk = require('read-chunk'); +const istextorbinary = require('istextorbinary'); +const dateFormat = require('dateformat'); +const prettyBytes = require('pretty-bytes'); +const Table = require('cli-table'); module.exports = { - isBinary: function (existingFilePath, newFileContents) { - var existingHeader = readChunk.sync(existingFilePath, 0, 512); + isBinary(existingFilePath, newFileContents) { + const existingHeader = readChunk.sync(existingFilePath, 0, 512); return istextorbinary.isBinarySync(undefined, existingHeader) || istextorbinary.isBinarySync(undefined, newFileContents); }, - diff: function (existingFilePath, newFileContents) { - var existingStat = fs.statSync(existingFilePath); - var table = new Table({ + diff(existingFilePath, newFileContents) { + const existingStat = fs.statSync(existingFilePath); + const table = new Table({ head: ['', 'Existing', 'Replacement', 'Diff'] }); - var sizeDiff; + let sizeDiff; if (existingStat.size > newFileContents.length) { sizeDiff = '-'; diff --git a/lib/util/conflicter.js b/lib/util/conflicter.js index 9fbe15de..b19c86b2 100644 --- a/lib/util/conflicter.js +++ b/lib/util/conflicter.js @@ -1,14 +1,14 @@ 'use strict'; -var fs = require('fs'); -var path = require('path'); -var async = require('async'); -var detectConflict = require('detect-conflict'); -var _ = require('lodash'); -var pathExists = require('path-exists'); -var typedError = require('error/typed'); -var binaryDiff = require('./binary-diff'); - -var AbortedError = typedError({ +const fs = require('fs'); +const path = require('path'); +const async = require('async'); +const detectConflict = require('detect-conflict'); +const _ = require('lodash'); +const pathExists = require('path-exists'); +const typedError = require('error/typed'); +const binaryDiff = require('./binary-diff'); + +const AbortedError = typedError({ type: 'AbortedError', message: 'Process aborted by user' }); @@ -28,7 +28,7 @@ var AbortedError = typedError({ * @param {Boolean} force - When set to true, we won't check for conflict. (the * conflicter become a passthrough) */ -var Conflicter = module.exports = function (adapter, force) { +const Conflicter = function (adapter, force) { this.force = force === true; this.adapter = adapter; this.conflicts = []; @@ -46,9 +46,9 @@ Conflicter.prototype.checkForCollision = function (filepath, contents, callback) this.conflicts.push({ file: { path: path.resolve(filepath), - contents: contents + contents }, - callback: callback + callback }); }; @@ -71,15 +71,15 @@ Conflicter.prototype.checkForCollision = function (filepath, contents, callback) Conflicter.prototype.resolve = function (cb) { cb = cb || _.noop; - var self = this; - var resolveConflicts = function (conflict) { + const self = this; + const resolveConflicts = function (conflict) { return function (next) { if (!conflict) { next(); return; } - self.collision(conflict.file, function (status) { + self.collision(conflict.file, status => { // Remove the resolved conflict from the queue _.pull(self.conflicts, conflict); conflict.callback(null, status); @@ -107,7 +107,7 @@ Conflicter.prototype.resolve = function (cb) { * @return {null} nothing */ Conflicter.prototype.collision = function (file, cb) { - var rfilepath = path.relative(process.cwd(), file.path); + const rfilepath = path.relative(process.cwd(), file.path); if (!pathExists.sync(file.path)) { this.adapter.log.create(rfilepath); @@ -137,8 +137,8 @@ Conflicter.prototype.collision = function (file, cb) { * @param {Function} cb */ Conflicter.prototype._ask = function (file, cb) { - var rfilepath = path.relative(process.cwd(), file.path); - var prompt = { + const rfilepath = path.relative(process.cwd(), file.path); + const prompt = { name: 'action', type: 'expand', message: 'Overwrite ' + rfilepath + '?', @@ -170,7 +170,7 @@ Conflicter.prototype._ask = function (file, cb) { }); } - this.adapter.prompt([prompt], function (result) { + this.adapter.prompt([prompt], result => { if (result.action === 'abort') { this.adapter.log.writeln('Aborting ...'); throw new AbortedError(); @@ -180,7 +180,7 @@ Conflicter.prototype._ask = function (file, cb) { if (binaryDiff.isBinary(file.path, file.contents)) { this.adapter.log.writeln(binaryDiff.diff(file.path, file.contents)); } else { - var existing = fs.readFileSync(file.path); + const existing = fs.readFileSync(file.path); this.adapter.diff(existing.toString(), (file.contents || '').toString()); } @@ -197,5 +197,7 @@ Conflicter.prototype._ask = function (file, cb) { this.adapter.log[result.action](rfilepath); return cb(result.action); - }.bind(this)); + }); }; + +module.exports = Conflicter; diff --git a/lib/util/deprecate.js b/lib/util/deprecate.js index b043da5b..1c73a0ec 100644 --- a/lib/util/deprecate.js +++ b/lib/util/deprecate.js @@ -1,8 +1,8 @@ 'use strict'; -var _ = require('lodash'); -var chalk = require('chalk'); +const _ = require('lodash'); +const chalk = require('chalk'); -var deprecate = function (message, fn) { +const deprecate = function (message, fn) { return function () { deprecate.log(message); return fn.apply(this, arguments); @@ -14,27 +14,27 @@ deprecate.log = function (message) { }; deprecate.object = function (message, object) { - var msgTpl = _.template(message); - var mirror = []; + const msgTpl = _.template(message); + const mirror = []; - Object.keys(object).forEach(function (name) { - var func = object[name]; + Object.keys(object).forEach(name => { + const func = object[name]; if (!_.isFunction(func)) { mirror[name] = func; return; } - mirror[name] = deprecate(msgTpl({name: name}), func); + mirror[name] = deprecate(msgTpl({name}), func); }); return mirror; }; deprecate.property = function (message, object, property) { - var original = object[property]; + const original = object[property]; Object.defineProperty(object, property, { - get: function () { + get() { deprecate.log(message); return original; } diff --git a/lib/util/prompt-suggestion.js b/lib/util/prompt-suggestion.js index a15b66a1..8aa2b63e 100644 --- a/lib/util/prompt-suggestion.js +++ b/lib/util/prompt-suggestion.js @@ -1,12 +1,12 @@ 'use strict'; -var assert = require('assert'); -var _ = require('lodash'); +const assert = require('assert'); +const _ = require('lodash'); /** * @mixin * @alias util/prompt-suggestion */ -var promptSuggestion = module.exports; +const promptSuggestion = module.exports; /** * Returns the default value for a checkbox. @@ -16,10 +16,10 @@ var promptSuggestion = module.exports; * @return {*} Default value to set * @private */ -var getCheckboxDefault = function (question, defaultValue) { +const getCheckboxDefault = function (question, defaultValue) { // For simplicity we uncheck all boxes and // use .default to set the active ones. - _.each(question.choices, function (choice) { + _.each(question.choices, choice => { if (typeof choice === 'object') { choice.checked = false; } @@ -36,8 +36,8 @@ var getCheckboxDefault = function (question, defaultValue) { * @return {*} Default value to set * @private */ -var getListDefault = function (question, defaultValue) { - var choiceValues = _.map(question.choices, function (choice) { +const getListDefault = function (question, defaultValue) { + const choiceValues = _.map(question.choices, choice => { if (typeof choice === 'object') { return choice.value; } @@ -57,14 +57,14 @@ var getListDefault = function (question, defaultValue) { * @return {Boolean} Answer to be stored * @private */ -var storeListAnswer = function (question, answer, storeAll) { - var choiceValues = _.map(question.choices, function (choice) { +const storeListAnswer = function (question, answer, storeAll) { + const choiceValues = _.map(question.choices, choice => { if (Object.prototype.hasOwnProperty.call(choice, 'value')) { return choice.value; } return choice; }); - var choiceIndex = choiceValues.indexOf(answer); + const choiceIndex = choiceValues.indexOf(answer); // Check if answer is not equal to default value if (storeAll || question.default !== choiceIndex) { @@ -84,7 +84,7 @@ var storeListAnswer = function (question, answer, storeAll) { * @return {Boolean} Answer to be stored * @private */ -var storeAnswer = function (question, answer, storeAll) { +const storeAnswer = function (question, answer, storeAll) { // Check if answer is not equal to default value or is undefined if (answer !== undefined && (storeAll || question.default !== answer)) { return true; @@ -104,7 +104,7 @@ promptSuggestion.prefillQuestions = function (store, questions) { assert(store, 'A store parameter is required'); assert(questions, 'A questions parameter is required'); - var promptValues = store.get('promptValues') || {}; + const promptValues = store.get('promptValues') || {}; if (!Array.isArray(questions)) { questions = [questions]; @@ -113,12 +113,12 @@ promptSuggestion.prefillQuestions = function (store, questions) { questions = questions.map(_.clone); // Write user defaults back to prompt - return questions.map(function (question) { + return questions.map(question => { if (question.store !== true) { return question; } - var storedValue = promptValues[question.name]; + const storedValue = promptValues[question.name]; if (storedValue === undefined) { return question; @@ -157,20 +157,20 @@ promptSuggestion.storeAnswers = function (store, questions, answers, storeAll) { assert.ok(_.isObject(answers), 'answers must be a object'); storeAll = storeAll || false; - var promptValues = store.get('promptValues') || {}; + const promptValues = store.get('promptValues') || {}; if (!Array.isArray(questions)) { questions = [questions]; } - _.each(questions, function (question) { + _.each(questions, question => { if (question.store !== true) { return; } - var saveAnswer; - var key = question.name; - var answer = answers[key]; + let saveAnswer; + const key = question.name; + const answer = answers[key]; switch (question.type) { case 'rawlist': @@ -188,7 +188,7 @@ promptSuggestion.storeAnswers = function (store, questions, answers, storeAll) { } }); - if (Object.keys(promptValues).length) { + if (Object.keys(promptValues).length > 0) { store.set('promptValues', promptValues); } }; diff --git a/lib/util/storage.js b/lib/util/storage.js index a69b7612..8033e626 100644 --- a/lib/util/storage.js +++ b/lib/util/storage.js @@ -1,6 +1,6 @@ 'use strict'; -var assert = require('assert'); -var _ = require('lodash'); +const assert = require('assert'); +const _ = require('lodash'); /** * Storage instances handle a json file where Generator authors can store data. @@ -20,7 +20,7 @@ var _ = require('lodash'); * }); */ -var Storage = module.exports = function (name, fs, configPath) { +const Storage = function (name, fs, configPath) { assert(name, 'A name parameter is required to create a storage'); assert(configPath, 'A config filepath is required to create a storage'); @@ -44,7 +44,7 @@ Storage.prototype._store = function () { * @param {Object} val - current configuration values */ Storage.prototype._persist = function (val) { - var fullStore = this.fs.readJSON(this.path, {}); + const fullStore = this.fs.readJSON(this.path, {}); fullStore[this.name] = val; this.fs.write(this.path, JSON.stringify(fullStore, null, ' ')); }; @@ -87,7 +87,7 @@ Storage.prototype.getAll = function () { Storage.prototype.set = function (key, val) { assert(!_.isFunction(val), 'Storage value can\'t be a function'); - var store = this._store(); + const store = this._store(); if (_.isObject(key)) { val = _.extend(store, key); @@ -106,7 +106,7 @@ Storage.prototype.set = function (key, val) { */ Storage.prototype.delete = function (key) { - var store = this._store(); + const store = this._store(); delete store[key]; this._persist(store); }; @@ -120,7 +120,9 @@ Storage.prototype.delete = function (key) { Storage.prototype.defaults = function (defaults) { assert(_.isObject(defaults), 'Storage `defaults` method only accept objects'); - var val = _.defaults(this.getAll(), defaults); + const val = _.defaults(this.getAll(), defaults); this.set(val); return val; }; + +module.exports = Storage; diff --git a/package.json b/package.json index 5c3a21c1..0c196b86 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "author": "Yeoman", "main": "lib", "engines": { - "node": ">=0.10.0" + "node": ">=4" }, "scripts": { "test": "xo && gulp", @@ -78,16 +78,14 @@ "proxyquire": "^1.0.0", "sinon": "^1.9.1", "tui-jsdoc-template": "^1.0.4", - "xo": "^0.16.0", + "xo": "^0.17.0", "yeoman-assert": "^3.0.0", "yeoman-test": "^1.0.0" }, "xo": { - "esnext": false, "space": true, "rules": { - "quote-props": "off", - "import/newline-after-import": "off" + "promise/no-callback-in-promise": "off" }, "overrides": [ { diff --git a/test/base.js b/test/base.js index ea18004e..b7d4c70e 100644 --- a/test/base.js +++ b/test/base.js @@ -1,34 +1,34 @@ 'use strict'; -var fs = require('fs'); -var os = require('os'); -var LF = require('os').EOL; -var path = require('path'); -var util = require('util'); -var sinon = require('sinon'); -var mkdirp = require('mkdirp'); -var mockery = require('mockery'); -var rimraf = require('rimraf'); -var through = require('through2'); -var pathExists = require('path-exists'); -var Promise = require('pinkie-promise'); -var yeoman = require('yeoman-environment'); -var userHome = require('user-home'); +const fs = require('fs'); +const os = require('os'); +const LF = require('os').EOL; +const path = require('path'); +const util = require('util'); +const sinon = require('sinon'); +const mkdirp = require('mkdirp'); +const mockery = require('mockery'); +const rimraf = require('rimraf'); +const through = require('through2'); +const pathExists = require('path-exists'); +const Promise = require('pinkie-promise'); +const yeoman = require('yeoman-environment'); +const userHome = require('user-home'); mockery.enable({ warnOnReplace: false, warnOnUnregistered: false }); -var assert = require('yeoman-assert'); -var helpers = require('yeoman-test'); -var TestAdapter = require('yeoman-test/lib/adapter').TestAdapter; -var Base = require('..'); -var Conflicter = require('../lib/util/conflicter'); +const assert = require('yeoman-assert'); +const helpers = require('yeoman-test'); +const TestAdapter = require('yeoman-test/lib/adapter').TestAdapter; +const Base = require('..'); +const Conflicter = require('../lib/util/conflicter'); -var tmpdir = path.join(os.tmpdir(), 'yeoman-base'); -var resolveddir = path.join(os.tmpdir(), 'yeoman-base-generator'); +const tmpdir = path.join(os.tmpdir(), 'yeoman-base'); +const resolveddir = path.join(os.tmpdir(), 'yeoman-base-generator'); -describe('Base', function () { +describe('Base', () => { before(helpers.setUpTestDirectory(tmpdir)); beforeEach(function () { @@ -41,7 +41,7 @@ describe('Base', function () { this.dummy = new this.Dummy(['bar', 'baz', 'bom'], { foo: false, something: 'else', - // Mandatory options, created by the env#create() helper + // Mandatory options, created by the `env#create()` helper resolved: resolveddir, namespace: 'dummy', env: this.env, @@ -49,14 +49,14 @@ describe('Base', function () { }); }); - describe('constructor', function () { + describe('constructor', () => { it('set the CWD where `.yo-rc.json` is found', function () { - var projectDir = path.join(__dirname, 'fixtures/dummy-project'); - var subdir = path.join(projectDir, 'subdir'); + const projectDir = path.join(__dirname, 'fixtures/dummy-project'); + const subdir = path.join(projectDir, 'subdir'); process.chdir(subdir); this.env.cwd = process.cwd(); - var dummy = new this.Dummy(['foo'], { + const dummy = new this.Dummy(['foo'], { resolved: 'ember/all', env: this.env }); @@ -69,7 +69,7 @@ describe('Base', function () { it('use the environment options', function () { this.env.registerStub(Base.extend(), 'ember:model'); - var generator = this.env.create('ember:model', { + const generator = this.env.create('ember:model', { options: { 'test-framework': 'jasmine' } @@ -79,7 +79,7 @@ describe('Base', function () { }); it('set generator.options from constructor options', function () { - var generator = new Base({ + const generator = new Base({ env: this.env, resolved: 'test', 'test-framework': 'mocha' @@ -89,7 +89,7 @@ describe('Base', function () { }); it('set options based on nopt arguments', function () { - var generator = new Base(['--foo', 'bar'], { + const generator = new Base(['--foo', 'bar'], { env: this.env, resolved: 'test' }); @@ -100,7 +100,7 @@ describe('Base', function () { }); it('set arguments based on nopt arguments', function () { - var generator = new Base(['--foo', 'bar'], { + const generator = new Base(['--foo', 'bar'], { env: this.env, resolved: 'test' }); @@ -110,17 +110,17 @@ describe('Base', function () { assert.equal(generator.options.baz, 'bar'); }); - it('set options with false values', function (done) { + it('set options with false values', done => { var generator = helpers .run(path.join(__dirname, './fixtures/options-generator')) - .withOptions({testOption: false}).on('end', function () { + .withOptions({testOption: false}).on('end', () => { assert.equal(generator.options.testOption, false); done(); }); }); it('setup fs editor', function () { - var generator = new Base([], { + const generator = new Base([], { env: this.env, resolved: 'test' }); @@ -129,24 +129,24 @@ describe('Base', function () { }); }); - describe('prototype', function () { + describe('prototype', () => { it('methods doesn\'t conflict with Env#runQueue', function () { assert.notImplement(Base.prototype, this.env.runLoop.queueNames); }); }); - describe('#appname', function () { + describe('#appname', () => { it('is set to the `determineAppname()` return value', function () { assert.equal(this.dummy.appname, this.dummy.determineAppname()); }); }); - describe('#determineAppname()', function () { - beforeEach(function () { + describe('#determineAppname()', () => { + beforeEach(() => { process.chdir(tmpdir); }); - afterEach(function () { + afterEach(() => { rimraf.sync('bower.json'); rimraf.sync('package.json'); delete require.cache[path.join(process.cwd(), 'bower.json')]; @@ -176,31 +176,31 @@ describe('Base', function () { }); }); - describe('.extend()', function () { + describe('.extend()', () => { it('create a new object inheriting the Generator', function () { - var gen = new (Base.extend())([], {resolved: 'path/', env: this.env}); + const gen = new (Base.extend())([], {resolved: 'path/', env: this.env}); assert.ok(gen instanceof Base); }); - it('pass the extend method along', function () { - var Sub = Base.extend(); + it('pass the extend method along', () => { + const Sub = Base.extend(); assert.equal(Sub.extend, Base.extend); }); - it('assign prototype methods', function () { - var proto = {foo: function () {}}; - var Sub = Base.extend(proto); + it('assign prototype methods', () => { + const proto = {foo() {}}; + const Sub = Base.extend(proto); assert.equal(Sub.prototype.foo, proto.foo); }); - it('assign static methods', function () { - var staticProps = {foo: function () {}}; - var Sub = Base.extend({}, staticProps); + it('assign static methods', () => { + const staticProps = {foo() {}}; + const Sub = Base.extend({}, staticProps); assert.equal(Sub.foo, staticProps.foo); }); }); - describe('#run()', function () { + describe('#run()', () => { beforeEach(function () { this.TestGenerator = Base.extend({ exec: sinon.spy(), @@ -238,11 +238,11 @@ describe('Base', function () { it('run prototype methods (not instances one)', function (done) { this.testGen.exec = sinon.spy(); - this.testGen.run(function () { + this.testGen.run(() => { assert.ok(this.execSpy.calledOnce); assert.equal(this.testGen.exec.callCount, 0); done(); - }.bind(this)); + }); }); it('don\'t try running prototype attributes', function (done) { @@ -252,17 +252,17 @@ describe('Base', function () { it('pass instance .args property to the called methods', function (done) { this.testGen.args = ['2', 'args']; - this.testGen.run(function () { + this.testGen.run(() => { assert(this.execSpy.withArgs('2', 'args').calledOnce); done(); - }.bind(this)); + }); }); it('resolve conflicts after it ran', function (done) { - this.testGen.run(function () { + this.testGen.run(() => { assert.equal(this.resolveSpy.callCount, 1); done(); - }.bind(this)); + }); }); it('can emit error from async methods', function (done) { @@ -270,7 +270,7 @@ describe('Base', function () { this.async()('some error'); }; - this.testGen.on('error', function (err) { + this.testGen.on('error', err => { assert.equal(err, 'some error'); done(); }); @@ -279,13 +279,13 @@ describe('Base', function () { }); it('can emit error from sync methods', function (done) { - var error = new Error(); + const error = new Error(); this.TestGenerator.prototype.throwing = function () { throw error; }; - this.testGen.on('error', function (err) { + this.testGen.on('error', err => { assert.equal(err, error); done(); }); @@ -294,8 +294,8 @@ describe('Base', function () { }); it('stop queue processing once an error is thrown', function (done) { - var error = new Error(); - var spy = sinon.spy(); + const error = new Error(); + const spy = sinon.spy(); this.TestGenerator.prototype.throwing = function () { throw error; @@ -303,19 +303,19 @@ describe('Base', function () { this.TestGenerator.prototype.afterError = spy; this.testGen.on('error', sinon.spy()); - this.testGen.run(function (err) { + this.testGen.run(err => { assert.equal(err, error); done(); }); }); it('handle function returning promises as asynchronous', function (done) { - var spy1 = sinon.spy(); - var spy2 = sinon.spy(); + const spy1 = sinon.spy(); + const spy2 = sinon.spy(); this.TestGenerator.prototype.first = function () { - return new Promise(function (resolve) { - setTimeout(function () { + return new Promise(resolve => { + setTimeout(() => { spy1(); resolve(); }, 10); @@ -326,7 +326,7 @@ describe('Base', function () { spy2(); }; - this.testGen.run(function () { + this.testGen.run(() => { spy1.calledBefore(spy2); done(); }); @@ -334,12 +334,12 @@ describe('Base', function () { it('handle failing promises as errors', function (done) { this.TestGenerator.prototype.failing = function () { - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { reject('some error'); }); }; - this.testGen.on('error', function (err) { + this.testGen.on('error', err => { assert.equal(err, 'some error'); done(); }); @@ -348,14 +348,14 @@ describe('Base', function () { }); it('run methods in series', function (done) { - var async1Running = false; - var async1Ran = false; + let async1Running = false; + let async1Ran = false; this.TestGenerator.prototype.async1 = function () { async1Running = true; - var cb = this.async(); + const cb = this.async(); - setTimeout(function () { + setTimeout(() => { async1Running = false; async1Ran = true; cb(); @@ -372,7 +372,7 @@ describe('Base', function () { }); it('throws if no method is available', function () { - var gen = new (Base.extend())([], { + const gen = new (Base.extend())([], { resolved: 'generator-ember/all/index.js', namespace: 'dummy', env: this.env @@ -382,7 +382,7 @@ describe('Base', function () { }); it('will run non-enumerable methods', function (done) { - var Generator = function () { + const Generator = function () { Base.apply(this, arguments); }; @@ -393,62 +393,62 @@ describe('Base', function () { writable: true }); - var gen = new Generator([], { + const gen = new Generator([], { resolved: 'dummy', namespace: 'dummy', env: this.env }); - gen.run(function () { + gen.run(() => { assert(gen.nonenumerable.called); done(); }); }); it('ignore underscore prefixed method', function (done) { - this.testGen.run(function () { + this.testGen.run(() => { assert(this.TestGenerator.prototype._private.notCalled); done(); - }.bind(this)); + }); }); it('run methods in a queue hash', function (done) { - this.testGen.run(function () { + this.testGen.run(() => { assert(this.TestGenerator.prototype.prompting.m1.calledOnce); assert(this.TestGenerator.prototype.prompting.m2.calledOnce); done(); - }.bind(this)); + }); }); it('ignore underscore prefixed method in a queue hash', function (done) { - this.testGen.run(function () { + this.testGen.run(() => { assert(this.TestGenerator.prototype.prompting._private.notCalled); done(); - }.bind(this)); + }); }); it('run named queued methods in order', function (done) { - var initSpy = this.TestGenerator.prototype.initializing; - var promptSpy = this.TestGenerator.prototype.prompting.m1; + const initSpy = this.TestGenerator.prototype.initializing; + const promptSpy = this.TestGenerator.prototype.prompting.m1; - this.testGen.run(function () { + this.testGen.run(() => { assert(initSpy.calledBefore(promptSpy)); done(); }); }); it('run queued methods in order even if not in order in prototype', function (done) { - var initSpy = this.TestGenerator.prototype.initializing; - var execSpy = this.TestGenerator.prototype.exec; + const initSpy = this.TestGenerator.prototype.initializing; + const execSpy = this.TestGenerator.prototype.exec; - this.testGen.run(function () { + this.testGen.run(() => { assert(initSpy.calledBefore(execSpy)); done(); }); }); it('commit mem-fs to disk', function (done) { - var filepath; + let filepath; this.TestGenerator.prototype.writing = function () { this.fs.write( @@ -457,41 +457,41 @@ describe('Base', function () { ); }; - this.testGen.run(function () { + this.testGen.run(() => { assert(pathExists.sync(filepath)); done(); }); }); it('allow skipping file writes to disk', function (done) { - var action = {action: 'skip'}; - var filepath = path.join(__dirname, '/fixtures/conflict.js'); + const action = {action: 'skip'}; + const filepath = path.join(__dirname, '/fixtures/conflict.js'); assert(pathExists.sync(filepath)); this.TestGenerator.prototype.writing = function () { this.fs.write(filepath, 'some new content'); }; - var env = yeoman.createEnv([], {'skip-install': true}, new TestAdapter(action)); - var testGen = new this.TestGenerator([], { + const env = yeoman.createEnv([], {'skip-install': true}, new TestAdapter(action)); + const testGen = new this.TestGenerator([], { resolved: 'generator/app/index.js', namespace: 'dummy', - env: env + env }); - testGen.run(function () { + testGen.run(() => { assert.equal(fs.readFileSync(filepath, 'utf8'), 'var a = 1;' + LF); done(); }); }); it('does not prompt again for skipped files', function (done) { - var action = {action: 'skip'}; - var filepath = path.join(__dirname, '/fixtures/conflict.js'); - var filepath2 = path.join(__dirname, '/fixtures/file-conflict.txt'); + const action = {action: 'skip'}; + const filepath = path.join(__dirname, '/fixtures/conflict.js'); + const filepath2 = path.join(__dirname, '/fixtures/file-conflict.txt'); sinon.spy(Conflicter.prototype, 'checkForCollision'); - var env = yeoman.createEnv([], {'skip-install': true}, new TestAdapter(action)); + const env = yeoman.createEnv([], {'skip-install': true}, new TestAdapter(action)); env.registerStub(this.Dummy, 'dummy:app'); // The composed generator need to write at least one file for it to go through it's @@ -505,13 +505,13 @@ describe('Base', function () { this.composeWith('dummy:app'); }; - var testGen = new this.TestGenerator([], { + const testGen = new this.TestGenerator([], { resolved: 'generator/app/index.js', namespace: 'dummy', - env: env + env }); - testGen.run(function () { + testGen.run(() => { sinon.assert.calledTwice(Conflicter.prototype.checkForCollision); Conflicter.prototype.checkForCollision.restore(); done(); @@ -534,14 +534,14 @@ describe('Base', function () { this.fs.write(this.destinationPath('foo.txt'), 'test'); }; - this.testGen.run(function () { + this.testGen.run(() => { assert(pathExists.sync(this.testGen.destinationPath('foo.txt'))); done(); - }.bind(this)); + }); }); }); - describe('#argument()', function () { + describe('#argument()', () => { it('add a new argument to the generator instance', function () { assert.equal(this.dummy._arguments.length, 0); this.dummy.argument('foo'); @@ -554,7 +554,7 @@ describe('Base', function () { }); it('allows specifying default argument values', function () { - var Generator = Base.extend({ + const Generator = Base.extend({ constructor: function () { Base.apply(this, arguments); @@ -562,7 +562,7 @@ describe('Base', function () { } }); - var gen = new Generator({ + const gen = new Generator({ env: this.env, resolved: 'test' }); @@ -571,7 +571,7 @@ describe('Base', function () { }); it('allows specifying default argument values', function () { - var Generator = Base.extend({ + const Generator = Base.extend({ constructor: function () { Base.apply(this, arguments); @@ -579,7 +579,7 @@ describe('Base', function () { } }); - var gen = new Generator({ + const gen = new Generator({ env: this.env, resolved: 'test' }); @@ -588,7 +588,7 @@ describe('Base', function () { }); it('properly uses arguments values passed from constructor', function () { - var Generator = Base.extend({ + const Generator = Base.extend({ constructor: function () { Base.apply(this, arguments); @@ -596,7 +596,7 @@ describe('Base', function () { } }); - var gen = new Generator({ + const gen = new Generator({ env: this.env, resolved: 'test', bar: 'foo' @@ -611,10 +611,10 @@ describe('Base', function () { }); it('raise an error if required arguments are not provided', function (done) { - var dummy = new Base([], { + const dummy = new Base([], { env: this.env, resolved: 'dummy/all' - }).on('error', function () { + }).on('error', () => { done(); }); @@ -622,7 +622,7 @@ describe('Base', function () { }); it('doesn\'t raise an error if required arguments are not provided, but the help option has been specified', function () { - var dummy = new Base([], { + const dummy = new Base([], { env: this.env, resolved: 'dummy:all', help: true @@ -634,7 +634,7 @@ describe('Base', function () { }); it('can be called before #option()', function () { - var dummy = new Base(['--foo', 'bar', 'baz'], { + const dummy = new Base(['--foo', 'bar', 'baz'], { env: this.env, resolved: 'dummy/all' }); @@ -646,10 +646,10 @@ describe('Base', function () { }); }); - describe('#option()', function () { + describe('#option()', () => { it('add a new option to the set of generator expected options', function () { // Every generator have the --help options - var generator = new this.Dummy([], { + const generator = new this.Dummy([], { env: this.env, resolved: 'test' }); @@ -664,7 +664,7 @@ describe('Base', function () { }); it('allow aliasing options', function () { - var Generator = Base.extend({ + const Generator = Base.extend({ constructor: function () { Base.apply(this, arguments); @@ -675,7 +675,7 @@ describe('Base', function () { } }); - var gen = new Generator({ + const gen = new Generator({ env: this.env, resolved: 'test', 'short-name': 'that value' @@ -685,7 +685,7 @@ describe('Base', function () { }); it('allows Boolean options to be undefined', function () { - var Generator = Base.extend({ + const Generator = Base.extend({ constructor: function () { Base.apply(this, arguments); @@ -693,7 +693,7 @@ describe('Base', function () { } }); - var gen = new Generator({ + const gen = new Generator({ env: this.env, resolved: 'test' }); @@ -702,18 +702,18 @@ describe('Base', function () { }); it('disallows Boolean options starting with no-', function () { - var generator = new this.Dummy([], { + const generator = new this.Dummy([], { env: this.env, resolved: 'test' }); - var addWrongOp = function () { + const addWrongOp = function () { generator.option('no-op'); }; assert.throws(addWrongOp, /this\.option\('op', \{type: Boolean\}\)/); }); }); - describe('#parseOptions()', function () { + describe('#parseOptions()', () => { beforeEach(function () { this.dummy = new this.Dummy(['start', '--foo', 'bar', '-s', 'baz', 'remain'], { env: this.env, @@ -746,7 +746,7 @@ describe('Base', function () { }); it('gracefully handle no args', function () { - var dummy = new this.Dummy({ + const dummy = new this.Dummy({ env: this.env, resolved: 'test' }); @@ -760,7 +760,7 @@ describe('Base', function () { }); }); - describe('#composeWith()', function () { + describe('#composeWith()', () => { beforeEach(function () { this.dummy = new this.Dummy([], { resolved: 'unknown', @@ -776,19 +776,19 @@ describe('Base', function () { it('runs the composed generators', function (done) { this.dummy.composeWith('composed:gen'); - var runSpy = sinon.spy(this.dummy, 'run'); + const runSpy = sinon.spy(this.dummy, 'run'); // I use a setTimeout here just to make sure composeWith() doesn't start the // generator before the base one is ran. - setTimeout(function () { - this.dummy.run(function () { + setTimeout(() => { + this.dummy.run(() => { sinon.assert.callOrder(runSpy, this.spy); assert.equal(this.spy.thisValues[0].options.skipInstall, true); assert.equal(this.spy.thisValues[0].options['skip-install'], true); assert(this.spy.calledAfter(runSpy)); done(); - }.bind(this)); - }.bind(this), 100); + }); + }, 100); }); it('run the composed generator even if main generator is already running.', function (done) { @@ -796,10 +796,10 @@ describe('Base', function () { this.composeWith('composed:gen'); }; - this.dummy.run(function () { + this.dummy.run(() => { assert(this.spy.called); done(); - }.bind(this)); + }); }); it('pass options and arguments to the composed generators', function (done) { @@ -808,13 +808,13 @@ describe('Base', function () { 'skip-install': true }); - this.dummy.run(function () { + this.dummy.run(() => { assert.equal(this.spy.firstCall.thisValue.options.foo, 'bar'); done(); - }.bind(this)); + }); }); - describe('when passing a local path to a generator', function () { + describe('when passing a local path to a generator', () => { beforeEach(function () { this.spy = sinon.spy(); this.stubPath = path.join(__dirname, 'fixtures/generator-mocha'); @@ -824,43 +824,43 @@ describe('Base', function () { it('runs the composed generator', function (done) { this.dummy.composeWith(this.stubPath, {}); - this.dummy.run(function () { + this.dummy.run(() => { assert(this.LocalDummy.prototype.exec.called); done(); - }.bind(this)); + }); }); it('pass options and arguments to the composed generators', function (done) { this.dummy.composeWith(this.stubPath, {foo: 'bar', 'skip-install': true}); - this.dummy.run(function () { + this.dummy.run(() => { assert.equal(this.spy.firstCall.thisValue.options.foo, 'bar'); done(); - }.bind(this)); + }); }); it('sets correct metadata on the Generator constructor', function (done) { this.dummy.composeWith(this.stubPath, {}); - this.dummy.run(function () { + this.dummy.run(() => { assert.equal(this.spy.firstCall.thisValue.options.namespace, 'mocha'); assert.equal( this.spy.firstCall.thisValue.options.resolved, require.resolve(this.stubPath) ); done(); - }.bind(this)); + }); }); }); }); - describe('#desc()', function () { + describe('#desc()', () => { it('update the internal description', function () { this.dummy.desc('A new desc for this generator'); assert.equal(this.dummy.description, 'A new desc for this generator'); }); }); - describe('#help()', function () { + describe('#help()', () => { it('return the expected help output', function () { this.dummy.option('ooOoo'); this.dummy.argument('baz', { @@ -870,8 +870,8 @@ describe('Base', function () { }); this.dummy.desc('A new desc for this generator'); - var help = this.dummy.help(); - var expected = [ + const help = this.dummy.help(); + const expected = [ 'Usage:', 'yo dummy [options] []', '', @@ -888,7 +888,7 @@ describe('Base', function () { '' ]; - help.split('\n').forEach(function (line, i) { + help.split('\n').forEach((line, i) => { // Do not test whitespace; we care about the content, not formatting. // formatting is best left up to the tests for module "text-table" assert.textEqual(line.trim().replace(/\s+/g, ' '), expected[i]); @@ -896,32 +896,32 @@ describe('Base', function () { }); }); - describe('#usage()', function () { + describe('#usage()', () => { it('returns the expected usage output with arguments', function () { this.dummy.argument('baz', { type: Number, required: false }); - var usage = this.dummy.usage(); + const usage = this.dummy.usage(); assert.equal(usage.trim(), 'yo dummy [options] []'); }); it('returns the expected usage output without arguments', function () { this.dummy._arguments.length = 0; - var usage = this.dummy.usage(); + const usage = this.dummy.usage(); assert.equal(usage.trim(), 'yo dummy [options]'); }); it('returns the expected usage output without options', function () { this.dummy._arguments.length = 0; this.dummy._options = {}; - var usage = this.dummy.usage(); + const usage = this.dummy.usage(); assert.equal(usage.trim(), 'yo dummy'); }); }); - describe('#config', function () { + describe('#config', () => { it('provide a storage instance', function () { assert.ok(this.dummy.config instanceof require('../lib/util/storage')); }); @@ -938,7 +938,7 @@ describe('Base', function () { }); }); - describe('#templatePath()', function () { + describe('#templatePath()', () => { it('joins path to the source root', function () { assert.equal( this.dummy.templatePath('bar.js'), @@ -951,7 +951,7 @@ describe('Base', function () { }); }); - describe('#destinationPath()', function () { + describe('#destinationPath()', () => { it('joins path to the source root', function () { assert.equal( this.dummy.destinationPath('bar.js'), @@ -964,7 +964,7 @@ describe('Base', function () { }); }); - describe('#registerTransformStream()', function () { + describe('#registerTransformStream()', () => { beforeEach(function () { this.filepath = path.join(os.tmpdir(), '/yeoman-transform-stream/filea.txt'); this.TestGenerator = Base.extend({ @@ -982,54 +982,54 @@ describe('Base', function () { }); it('add the transform stream to the commit stream', function (done) { - var self = this; + const self = this; this.TestGenerator.prototype.writing = function () { this.fs.write(self.filepath, 'not correct'); this - .registerTransformStream(through.obj(function (file, enc, cb) { - file.contents = new Buffer('a'); + .registerTransformStream(through.obj((file, enc, cb) => { + file.contents = Buffer.from('a'); cb(null, file); })) - .registerTransformStream(through.obj(function (file, enc, cb) { - file.contents = new Buffer(file.contents.toString() + 'b'); + .registerTransformStream(through.obj((file, enc, cb) => { + file.contents = Buffer.from(file.contents.toString() + 'b'); cb(null, file); })); }; - this.testGen.run(function () { + this.testGen.run(() => { assert.equal(fs.readFileSync(this.filepath, 'utf8'), 'ab'); done(); - }.bind(this)); + }); }); it('add multiple transform streams to the commit stream', function (done) { - var self = this; + const self = this; this.TestGenerator.prototype.writing = function () { this.fs.write(self.filepath, 'not correct'); this.registerTransformStream([ - through.obj(function (file, enc, cb) { - file.contents = new Buffer('a'); + through.obj((file, enc, cb) => { + file.contents = Buffer.from('a'); cb(null, file); }), - through.obj(function (file, enc, cb) { - file.contents = new Buffer(file.contents.toString() + 'b'); + through.obj((file, enc, cb) => { + file.contents = Buffer.from(file.contents.toString() + 'b'); cb(null, file); }) ]); }; - this.testGen.run(function () { + this.testGen.run(() => { assert.equal(fs.readFileSync(this.filepath, 'utf8'), 'ab'); done(); - }.bind(this)); + }); }); }); - describe('Events', function () { + describe('Events', () => { before(function () { - var Generator = this.Generator = function () { + const Generator = this.Generator = function () { Base.apply(this, arguments); }; @@ -1041,13 +1041,13 @@ describe('Base', function () { }); it('emits the series of event on a specific generator', function (done) { - var angular = new this.Generator([], { + const angular = new this.Generator([], { env: yeoman.createEnv([], {}, new TestAdapter()), resolved: __filename, 'skip-install': true }); - var lifecycle = ['run', 'method:createSomething', 'method:createSomethingElse', 'end']; + const lifecycle = ['run', 'method:createSomething', 'method:createSomethingElse', 'end']; function assertEvent(e) { return function () { @@ -1071,7 +1071,7 @@ describe('Base', function () { angular.run(); }); - it('only call the end event once (bug #402)', function (done) { + it('only call the end event once (bug #402)', done => { function GeneratorOnce() { Base.apply(this, arguments); this.sourceRoot(path.join(__dirname, 'fixtures')); @@ -1091,14 +1091,14 @@ describe('Base', function () { ); }; - var isFirstEndEvent = true; - var generatorOnce = new GeneratorOnce([], { + let isFirstEndEvent = true; + const generatorOnce = new GeneratorOnce([], { env: yeoman.createEnv([], {}, new TestAdapter()), resolved: __filename, 'skip-install': true }); - generatorOnce.on('end', function () { + generatorOnce.on('end', () => { assert.ok(isFirstEndEvent); if (isFirstEndEvent) { @@ -1111,12 +1111,12 @@ describe('Base', function () { generatorOnce.run(); }); - it('triggers end event after all generators methods are ran (#709)', function (done) { - var endSpy = sinon.spy(); - var GeneratorEnd = Base.extend({ + it('triggers end event after all generators methods are ran (#709)', done => { + const endSpy = sinon.spy(); + const GeneratorEnd = Base.extend({ constructor: function () { Base.apply(this, arguments); - this.on('end', function () { + this.on('end', () => { sinon.assert.calledOnce(endSpy); done(); }); @@ -1125,7 +1125,7 @@ describe('Base', function () { end: endSpy }); - var generatorEnd = new GeneratorEnd([], { + const generatorEnd = new GeneratorEnd([], { env: yeoman.createEnv([], {}, new TestAdapter()), resolved: __filename, 'skip-install': true @@ -1135,8 +1135,8 @@ describe('Base', function () { }); }); - describe('#rootGeneratorName', function () { - afterEach(function () { + describe('#rootGeneratorName', () => { + afterEach(() => { rimraf.sync(path.join(resolveddir, 'package.json')); }); @@ -1150,8 +1150,8 @@ describe('Base', function () { }); }); - describe('#rootGeneratorVersion', function () { - afterEach(function () { + describe('#rootGeneratorVersion', () => { + afterEach(() => { rimraf.sync(path.join(resolveddir, 'package.json')); }); diff --git a/test/conflicter.js b/test/conflicter.js index 0dd2b237..7b9a21c3 100644 --- a/test/conflicter.js +++ b/test/conflicter.js @@ -1,59 +1,59 @@ 'use strict'; -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); -var _ = require('lodash'); -var sinon = require('sinon'); -var TestAdapter = require('yeoman-test/lib/adapter').TestAdapter; -var Conflicter = require('../lib/util/conflicter'); - -describe('Conflicter', function () { +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const _ = require('lodash'); +const sinon = require('sinon'); +const TestAdapter = require('yeoman-test/lib/adapter').TestAdapter; +const Conflicter = require('../lib/util/conflicter'); + +describe('Conflicter', () => { beforeEach(function () { this.conflicter = new Conflicter(new TestAdapter()); }); it('#checkForCollision()', function () { - var spy = sinon.spy(); - var contents = fs.readFileSync(__filename, 'utf8'); + const spy = sinon.spy(); + const contents = fs.readFileSync(__filename, 'utf8'); this.conflicter.checkForCollision(__filename, contents, spy); - var conflict = this.conflicter.conflicts.pop(); + const conflict = this.conflicter.conflicts.pop(); assert.deepEqual(conflict.file.path, __filename); assert.deepEqual(conflict.file.contents, fs.readFileSync(__filename, 'utf8')); assert.deepEqual(conflict.callback, spy); }); - describe('#resolve()', function () { + describe('#resolve()', () => { it('wihout conflict', function (done) { this.conflicter.resolve(done); }); it('with a conflict', function (done) { - var spy = sinon.spy(); + const spy = sinon.spy(); this.conflicter.force = true; this.conflicter.checkForCollision(__filename, fs.readFileSync(__filename), spy); this.conflicter.checkForCollision('foo.js', 'var foo = "foo";\n', spy); - this.conflicter.resolve(function () { + this.conflicter.resolve(() => { assert.equal(spy.callCount, 2); assert.equal(this.conflicter.conflicts.length, 0, 'Expected conflicter to be empty after running'); done(); - }.bind(this)); + }); }); }); - describe('#collision()', function () { + describe('#collision()', () => { beforeEach(function () { this.conflictingFile = {path: __filename, contents: ''}; }); it('identical status', function (done) { - var me = fs.readFileSync(__filename, 'utf8'); + const me = fs.readFileSync(__filename, 'utf8'); this.conflicter.collision({ path: __filename, contents: me - }, function (status) { + }, status => { assert.equal(status, 'identical'); done(); }); @@ -63,34 +63,34 @@ describe('Conflicter', function () { this.conflicter.collision({ path: 'file-who-does-not-exist.js', contents: '' - }, function (status) { + }, status => { assert.equal(status, 'create'); done(); }); }); it('user choose "yes"', function (done) { - var conflicter = new Conflicter(new TestAdapter({action: 'write'})); + const conflicter = new Conflicter(new TestAdapter({action: 'write'})); - conflicter.collision(this.conflictingFile, function (status) { + conflicter.collision(this.conflictingFile, status => { assert.equal(status, 'force'); done(); }); }); it('user choose "skip"', function (done) { - var conflicter = new Conflicter(new TestAdapter({action: 'skip'})); + const conflicter = new Conflicter(new TestAdapter({action: 'skip'})); - conflicter.collision(this.conflictingFile, function (status) { + conflicter.collision(this.conflictingFile, status => { assert.equal(status, 'skip'); done(); }); }); it('user choose "force"', function (done) { - var conflicter = new Conflicter(new TestAdapter({action: 'force'})); + const conflicter = new Conflicter(new TestAdapter({action: 'force'})); - conflicter.collision(this.conflictingFile, function (status) { + conflicter.collision(this.conflictingFile, status => { assert.equal(status, 'force'); done(); }); @@ -98,7 +98,7 @@ describe('Conflicter', function () { it('force conflict status', function (done) { this.conflicter.force = true; - this.conflicter.collision(this.conflictingFile, function (status) { + this.conflicter.collision(this.conflictingFile, status => { assert.equal(status, 'force'); done(); }); @@ -108,19 +108,19 @@ describe('Conflicter', function () { this.conflicter.collision({ path: path.join(__dirname, 'fixtures/yeoman-logo.png'), contents: fs.readFileSync(path.join(__dirname, 'fixtures/yeoman-logo.png')) - }, function (status) { + }, status => { assert.equal(status, 'identical'); done(); }); }); - it('does not provide a diff option for directory', function (done) { - var conflicter = new Conflicter(new TestAdapter({action: 'write'})); - var spy = sinon.spy(conflicter.adapter, 'prompt'); + it('does not provide a diff option for directory', done => { + const conflicter = new Conflicter(new TestAdapter({action: 'write'})); + const spy = sinon.spy(conflicter.adapter, 'prompt'); conflicter.collision({ path: __dirname, contents: null - }, function () { + }, () => { assert.equal( _.filter(spy.firstCall.args[0][0].choices, {value: 'diff'}).length, 0 @@ -129,13 +129,13 @@ describe('Conflicter', function () { }); }); - it('displays default diff for text files', function (done) { - var testAdapter = new TestAdapter({action: 'diff'}); - var conflicter = new Conflicter(testAdapter); - var _prompt = testAdapter.prompt.bind(testAdapter); - var promptStub = sinon.stub(testAdapter, 'prompt', function (prompts, resultHandler) { + it('displays default diff for text files', done => { + const testAdapter = new TestAdapter({action: 'diff'}); + const conflicter = new Conflicter(testAdapter); + const _prompt = testAdapter.prompt.bind(testAdapter); + const promptStub = sinon.stub(testAdapter, 'prompt', (prompts, resultHandler) => { if (promptStub.calledTwice) { - var stubbedResultHandler = function (result) { + const stubbedResultHandler = function (result) { result.action = 'write'; return resultHandler(result); }; @@ -148,20 +148,20 @@ describe('Conflicter', function () { conflicter.collision({ path: path.join(__dirname, 'fixtures/foo.js'), contents: fs.readFileSync(path.join(__dirname, 'fixtures/foo-template.js')) - }, function () { + }, () => { sinon.assert.neverCalledWithMatch(testAdapter.log.writeln, /Existing.*Replacement.*Diff/); sinon.assert.called(testAdapter.diff); done(); }); }); - it('displays custom diff for binary files', function (done) { - var testAdapter = new TestAdapter({action: 'diff'}); - var conflicter = new Conflicter(testAdapter); - var _prompt = testAdapter.prompt.bind(testAdapter); - var promptStub = sinon.stub(testAdapter, 'prompt', function (prompts, resultHandler) { + it('displays custom diff for binary files', done => { + const testAdapter = new TestAdapter({action: 'diff'}); + const conflicter = new Conflicter(testAdapter); + const _prompt = testAdapter.prompt.bind(testAdapter); + const promptStub = sinon.stub(testAdapter, 'prompt', (prompts, resultHandler) => { if (promptStub.calledTwice) { - var stubbedResultHandler = function (result) { + const stubbedResultHandler = function (result) { result.action = 'write'; return resultHandler(result); }; @@ -174,7 +174,7 @@ describe('Conflicter', function () { conflicter.collision({ path: path.join(__dirname, 'fixtures/yeoman-logo.png'), contents: fs.readFileSync(path.join(__dirname, 'fixtures/testFile.tar.gz')) - }, function () { + }, () => { sinon.assert.calledWithMatch(testAdapter.log.writeln, /Existing.*Replacement.*Diff/); sinon.assert.notCalled(testAdapter.diff); done(); diff --git a/test/deprecate.js b/test/deprecate.js index dfd7dd42..80b6d928 100644 --- a/test/deprecate.js +++ b/test/deprecate.js @@ -1,34 +1,34 @@ 'use strict'; -var assert = require('assert'); -var chalk = require('chalk'); -var sinon = require('sinon'); -var deprecate = require('../lib/util/deprecate'); +const assert = require('assert'); +const chalk = require('chalk'); +const sinon = require('sinon'); +const deprecate = require('../lib/util/deprecate'); -describe('deprecate()', function () { - beforeEach(function () { +describe('deprecate()', () => { + beforeEach(() => { sinon.spy(console, 'log'); }); - afterEach(function () { + afterEach(() => { console.log.restore(); }); - it('log a message', function () { - var func = sinon.spy(); - var wrapped = deprecate('foo', func); + it('log a message', () => { + const func = sinon.spy(); + const wrapped = deprecate('foo', func); sinon.assert.notCalled(console.log); wrapped('bar', 2); sinon.assert.calledWith(console.log, chalk.yellow('(!) ') + 'foo'); sinon.assert.calledWith(func, 'bar', 2); }); - describe('.object()', function () { - it('wrap an object and log a message', function () { - var dummy = { + describe('.object()', () => { + it('wrap an object and log a message', () => { + const dummy = { foo: 1, func: sinon.spy() }; - var wrapped = deprecate.object('<%= name %> is deprecated', dummy); + const wrapped = deprecate.object('<%= name %> is deprecated', dummy); // Keep values assert.equal(wrapped.foo, 1); @@ -40,9 +40,9 @@ describe('deprecate()', function () { }); }); - describe('.property()', function () { - it('wrap a property getter and log a message', function () { - var dummy = { + describe('.property()', () => { + it('wrap a property getter and log a message', () => { + const dummy = { foo: 1 }; deprecate.property('foo is deprecated', dummy, 'foo'); diff --git a/test/generators.js b/test/generators.js index 35ef7efd..34d35a2a 100644 --- a/test/generators.js +++ b/test/generators.js @@ -1,11 +1,11 @@ 'use strict'; -var events = require('events'); -var Environment = require('yeoman-environment'); -var Base = require('..'); -var assert = require('yeoman-assert'); +const events = require('events'); +const Environment = require('yeoman-environment'); +const Base = require('..'); +const assert = require('yeoman-assert'); -describe('Generators module', function () { - describe('Base', function () { +describe('Generators module', () => { + describe('Base', () => { beforeEach(function () { this.env = Environment.createEnv(); this.generator = new Base({ diff --git a/test/install.js b/test/install.js index b3fa7b9d..98f3037f 100644 --- a/test/install.js +++ b/test/install.js @@ -1,11 +1,11 @@ 'use strict'; -var yeoman = require('yeoman-environment'); -var sinon = require('sinon'); -var TestAdapter = require('yeoman-test/lib/adapter').TestAdapter; -var Base = require('..'); +const yeoman = require('yeoman-environment'); +const sinon = require('sinon'); +const TestAdapter = require('yeoman-test/lib/adapter').TestAdapter; +const Base = require('..'); -var asyncStub = { - on: function (key, cb) { +const asyncStub = { + on(key, cb) { if (key === 'exit') { cb(); } @@ -14,11 +14,11 @@ var asyncStub = { } }; -describe('Base (actions/install mixin)', function () { +describe('Base (actions/install mixin)', () => { beforeEach(function () { this.env = yeoman.createEnv([], {}, new TestAdapter()); - var Dummy = Base.extend({ - exec: function () {} + const Dummy = Base.extend({ + exec() {} }); this.env.registerStub(Dummy, 'dummy'); this.dummy = this.env.create('dummy'); @@ -28,13 +28,13 @@ describe('Base (actions/install mixin)', function () { this.spawnCommandStub.returns(asyncStub); }); - describe('#runInstall()', function () { + describe('#runInstall()', () => { it('takes a config object and passes it to the spawned process', function (done) { - var callbackSpy = sinon.spy(); - var options = { + const callbackSpy = sinon.spy(); + const options = { save: true }; - var spawnEnv = { + const spawnEnv = { env: { PATH: '/path/to/bin' } @@ -42,7 +42,7 @@ describe('Base (actions/install mixin)', function () { // Args: installer, paths, options, cb this.dummy.runInstall('nestedScript', ['path1', 'path2'], options, callbackSpy, spawnEnv); - this.dummy.run(function () { + this.dummy.run(() => { sinon.assert.calledWithExactly( this.spawnCommandStub, 'nestedScript', @@ -52,10 +52,10 @@ describe('Base (actions/install mixin)', function () { sinon.assert.calledOnce(callbackSpy); done(); - }.bind(this)); + }); }); - describe('with --skip-install', function () { + describe('with --skip-install', () => { beforeEach(function () { this.dummy = this.env.create('dummy', { options: { @@ -66,33 +66,33 @@ describe('Base (actions/install mixin)', function () { it('does not spawn anything with skipInstall', function (done) { this.dummy.runInstall('npm', ['install']); - this.dummy.run(function () { + this.dummy.run(() => { sinon.assert.notCalled(this.spawnCommandStub); done(); - }.bind(this)); + }); }); it('does not spawn anything with skipInstall', function (done) { this.dummy.runInstall('yarn', ['install']); - this.dummy.run(function () { + this.dummy.run(() => { sinon.assert.notCalled(this.spawnCommandStub); done(); - }.bind(this)); + }); }); it('call callback if skipInstall', function (done) { - var spy = sinon.spy(); + const spy = sinon.spy(); this.dummy.runInstall('npm', ['install'], spy); - this.dummy.run(function () { + this.dummy.run(() => { sinon.assert.calledOnce(spy); done(); }); }); it('call callback if skipInstall', function (done) { - var spy = sinon.spy(); + const spy = sinon.spy(); this.dummy.runInstall('yarn', ['install'], spy); - this.dummy.run(function () { + this.dummy.run(() => { sinon.assert.calledOnce(spy); done(); }); @@ -100,19 +100,19 @@ describe('Base (actions/install mixin)', function () { }); }); - describe('#bowerInstall()', function () { + describe('#bowerInstall()', () => { it('spawn a bower process once per commands', function (done) { this.dummy.bowerInstall(); this.dummy.bowerInstall(); - this.dummy.run(function () { + this.dummy.run(() => { sinon.assert.calledOnce(this.spawnCommandStub); sinon.assert.calledWithExactly(this.spawnCommandStub, 'bower', ['install'], {}); done(); - }.bind(this)); + }); }); it('spawn a bower process with formatted options', function (done) { - this.dummy.bowerInstall('jquery', {saveDev: true}, function () { + this.dummy.bowerInstall('jquery', {saveDev: true}, () => { sinon.assert.calledOnce(this.spawnCommandStub); sinon.assert.calledWithExactly( this.spawnCommandStub, @@ -122,77 +122,77 @@ describe('Base (actions/install mixin)', function () { ); done(); - }.bind(this)); + }); this.dummy.run(); }); }); - describe('#npmInstall()', function () { + describe('#npmInstall()', () => { it('spawn an install process once per commands', function (done) { this.dummy.npmInstall(); this.dummy.npmInstall(); - this.dummy.run(function () { + this.dummy.run(() => { sinon.assert.calledOnce(this.spawnCommandStub); sinon.assert.calledWithExactly(this.spawnCommandStub, 'npm', ['install', '--cache-min', 86400], {}); done(); - }.bind(this)); + }); }); it('run without callback', function (done) { this.dummy.npmInstall('yo', {save: true}); - this.dummy.run(function () { + this.dummy.run(() => { sinon.assert.calledOnce(this.spawnCommandStub); done(); - }.bind(this)); + }); }); it('run with callback', function (done) { - this.dummy.npmInstall('yo', {save: true}, function () { + this.dummy.npmInstall('yo', {save: true}, () => { sinon.assert.calledOnce(this.spawnCommandStub); done(); - }.bind(this)); + }); this.dummy.run(); }); }); - describe('#yarnInstall()', function () { + describe('#yarnInstall()', () => { it('spawn an install process once per commands', function (done) { this.dummy.yarnInstall(); this.dummy.yarnInstall(); - this.dummy.run(function () { + this.dummy.run(() => { sinon.assert.calledOnce(this.spawnCommandStub); sinon.assert.calledWithExactly(this.spawnCommandStub, 'yarn', ['install'], {}); done(); - }.bind(this)); + }); }); it('run without callback', function (done) { this.dummy.yarnInstall('yo', {dev: true}); - this.dummy.run(function () { + this.dummy.run(() => { sinon.assert.calledOnce(this.spawnCommandStub); sinon.assert.calledWithExactly(this.spawnCommandStub, 'yarn', ['add', 'yo', '--dev'], {}); done(); - }.bind(this)); + }); }); it('run with callback', function (done) { - this.dummy.yarnInstall('yo', function () { + this.dummy.yarnInstall('yo', () => { sinon.assert.calledOnce(this.spawnCommandStub); sinon.assert.calledWithExactly(this.spawnCommandStub, 'yarn', ['add', 'yo'], {}); done(); - }.bind(this)); + }); this.dummy.run(); }); }); - describe('#installDependencies()', function () { + describe('#installDependencies()', () => { it('spawn npm and bower', function (done) { - this.dummy.installDependencies(function () { + this.dummy.installDependencies(() => { sinon.assert.calledTwice(this.spawnCommandStub); sinon.assert.calledWithExactly(this.spawnCommandStub, 'bower', ['install'], {}); sinon.assert.calledWithExactly(this.spawnCommandStub, 'npm', ['install', '--cache-min', 86400], {}); done(); - }.bind(this)); + }); this.dummy.run(); }); diff --git a/test/prompt-suggestion.js b/test/prompt-suggestion.js index 36d53c07..ff857439 100644 --- a/test/prompt-suggestion.js +++ b/test/prompt-suggestion.js @@ -1,15 +1,15 @@ 'use strict'; -var path = require('path'); -var assert = require('assert'); -var os = require('os'); -var rimraf = require('rimraf'); -var inquirer = require('inquirer'); -var env = require('yeoman-environment'); -var FileEditor = require('mem-fs-editor'); -var Storage = require('../lib/util/storage'); -var promptSuggestion = require('../lib/util/prompt-suggestion'); - -describe('PromptSuggestion', function () { +const path = require('path'); +const assert = require('assert'); +const os = require('os'); +const rimraf = require('rimraf'); +const inquirer = require('inquirer'); +const env = require('yeoman-environment'); +const FileEditor = require('mem-fs-editor'); +const Storage = require('../lib/util/storage'); +const promptSuggestion = require('../lib/util/prompt-suggestion'); + +describe('PromptSuggestion', () => { beforeEach(function () { this.memFs = env.createEnv().sharedFs; this.fs = FileEditor.create(this.memFs); @@ -22,8 +22,8 @@ describe('PromptSuggestion', function () { rimraf(this.storePath, done); }); - describe('.prefillQuestions()', function () { - it('require a store parameter', function () { + describe('.prefillQuestions()', () => { + it('require a store parameter', () => { assert.throws(promptSuggestion.prefillQuestions.bind(null)); }); @@ -36,58 +36,58 @@ describe('PromptSuggestion', function () { }); it('take a question object', function () { - var question = { + const question = { name: 'respuesta', default: 'bar', store: true }; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; assert.equal(result.default, 'foo'); }); it('take a question array', function () { - var question = [{ + const question = [{ name: 'respuesta', default: 'bar', store: true }]; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; assert.equal(result.default, 'foo'); }); it('don\'t override default when store is set to false', function () { - var question = { + const question = { name: 'respuesta', default: 'bar', store: false }; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; assert.equal(result.default, 'bar'); }); it('override default when store is set to true', function () { - var question = { + const question = { name: 'respuesta', default: 'bar', store: true }; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; assert.equal(result.default, 'foo'); }); it('keep inquirer objects', function () { - var question = { + const question = { type: 'checkbox', name: 'respuesta', default: ['bar'], store: true, choices: [new inquirer.Separator('spacer')] }; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; assert.ok(result.choices[0] instanceof inquirer.Separator); }); - describe('take a checkbox', function () { + describe('take a checkbox', () => { beforeEach(function () { this.store.set('promptValues', { respuesta: ['foo'] @@ -95,7 +95,7 @@ describe('PromptSuggestion', function () { }); it('override default from an array with objects', function () { - var question = { + const question = { type: 'checkbox', name: 'respuesta', default: ['bar'], @@ -111,9 +111,9 @@ describe('PromptSuggestion', function () { name: 'baz' }] }; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; - result.choices.forEach(function (choice) { + result.choices.forEach(choice => { assert.equal(choice.checked, false); }); @@ -121,18 +121,18 @@ describe('PromptSuggestion', function () { }); it('override default from an array with strings', function () { - var question = { + const question = { type: 'checkbox', name: 'respuesta', default: ['bar'], store: true, choices: ['foo', new inquirer.Separator('spacer'), 'bar', 'baz'] }; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; assert.deepEqual(result.default, ['foo']); }); - describe('with multiple defaults', function () { + describe('with multiple defaults', () => { beforeEach(function () { this.store.set('promptValues', { respuesta: ['foo', 'bar'] @@ -140,7 +140,7 @@ describe('PromptSuggestion', function () { }); it('from an array with objects', function () { - var question = { + const question = { type: 'checkbox', name: 'respuesta', default: ['bar'], @@ -156,9 +156,9 @@ describe('PromptSuggestion', function () { name: 'baz' }] }; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; - result.choices.forEach(function (choice) { + result.choices.forEach(choice => { assert.equal(choice.checked, false); }); @@ -166,20 +166,20 @@ describe('PromptSuggestion', function () { }); it('from an array with strings', function () { - var question = { + const question = { type: 'checkbox', name: 'respuesta', default: ['bar'], store: true, choices: ['foo', new inquirer.Separator('spacer'), 'bar', 'baz'] }; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; assert.deepEqual(result.default, ['foo', 'bar']); }); }); }); - describe('take a rawlist / expand', function () { + describe('take a rawlist / expand', () => { beforeEach(function () { this.store.set('promptValues', { respuesta: 'bar' @@ -187,7 +187,7 @@ describe('PromptSuggestion', function () { }); it('override default arrayWithObjects', function () { - var question = { + const question = { type: 'rawlist', name: 'respuesta', default: 0, @@ -203,30 +203,30 @@ describe('PromptSuggestion', function () { name: 'baz' }] }; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; assert.equal(result.default, 2); }); it('override default arrayWithObjects', function () { - var question = { + const question = { type: 'rawlist', name: 'respuesta', default: 0, store: true, choices: ['foo', new inquirer.Separator('spacer'), 'bar', 'baz'] }; - var result = promptSuggestion.prefillQuestions(this.store, question)[0]; + const result = promptSuggestion.prefillQuestions(this.store, question)[0]; assert.equal(result.default, 2); }); }); }); - describe('.storeAnswers()', function () { + describe('.storeAnswers()', () => { beforeEach(function () { this.store.set('promptValues', {respuesta: 'foo'}); }); - it('require a store parameter', function () { + it('require a store parameter', () => { assert.throws(promptSuggestion.storeAnswers.bind(null)); }); @@ -247,13 +247,13 @@ describe('PromptSuggestion', function () { }); it('store answer in global store', function () { - var question = { + const question = { name: 'respuesta', default: 'bar', store: true }; - var mockAnswers = { + const mockAnswers = { respuesta: 'baz' }; @@ -263,13 +263,13 @@ describe('PromptSuggestion', function () { }); it('don\'t store default answer in global store', function () { - var question = { + const question = { name: 'respuesta', default: 'bar', store: true }; - var mockAnswers = { + const mockAnswers = { respuesta: 'bar' }; @@ -280,13 +280,13 @@ describe('PromptSuggestion', function () { }); it('force store default answer in global store', function () { - var question = { + const question = { name: 'respuesta', default: 'bar', store: true }; - var mockAnswers = { + const mockAnswers = { respuesta: 'bar' }; @@ -297,13 +297,13 @@ describe('PromptSuggestion', function () { }); it('don\'t store answer in global store', function () { - var question = { + const question = { name: 'respuesta', default: 'bar', store: false }; - var mockAnswers = { + const mockAnswers = { respuesta: 'baz' }; @@ -313,7 +313,7 @@ describe('PromptSuggestion', function () { }); it('store answer from rawlist type', function () { - var question = { + const question = { type: 'rawlist', name: 'respuesta', default: 0, @@ -321,7 +321,7 @@ describe('PromptSuggestion', function () { choices: ['foo', new inquirer.Separator('spacer'), 'bar', 'baz'] }; - var mockAnswers = { + const mockAnswers = { respuesta: 'baz' }; @@ -330,12 +330,12 @@ describe('PromptSuggestion', function () { assert.equal(this.store.get('promptValues').respuesta, 'baz'); }); - describe('empty sotre', function () { + describe('empty sotre', () => { beforeEach(function () { this.store.delete('promptValues'); }); it('don\'t store default answer from rawlist type', function () { - var question = { + const question = { type: 'rawlist', name: 'respuesta', default: 0, @@ -343,7 +343,7 @@ describe('PromptSuggestion', function () { choices: ['foo', new inquirer.Separator('spacer'), 'bar', 'baz'] }; - var mockAnswers = { + const mockAnswers = { respuesta: 'foo' }; @@ -353,7 +353,7 @@ describe('PromptSuggestion', function () { }); it('force store default answer from rawlist type', function () { - var question = { + const question = { type: 'rawlist', name: 'respuesta', default: 0, @@ -361,7 +361,7 @@ describe('PromptSuggestion', function () { choices: ['foo', new inquirer.Separator('spacer'), 'bar', 'baz'] }; - var mockAnswers = { + const mockAnswers = { respuesta: 'foo' }; @@ -372,13 +372,13 @@ describe('PromptSuggestion', function () { }); it('store falsy answer (but not undefined) in global store', function () { - var question = { + const question = { name: 'respuesta', default: true, store: true }; - var mockAnswers = { + const mockAnswers = { respuesta: false }; diff --git a/test/spawn-command.js b/test/spawn-command.js index d3e01860..28cea08a 100644 --- a/test/spawn-command.js +++ b/test/spawn-command.js @@ -1,8 +1,8 @@ 'use strict'; -var proxyquire = require('proxyquire'); -var sinon = require('sinon'); +const proxyquire = require('proxyquire'); +const sinon = require('sinon'); -describe('generators.Base (actions/spawn-command)', function () { +describe('generators.Base (actions/spawn-command)', () => { beforeEach(function () { this.crossSpawn = sinon.spy(); this.crossSpawn.sync = sinon.spy(); @@ -11,7 +11,7 @@ describe('generators.Base (actions/spawn-command)', function () { }); }); - describe('#spawnCommand()', function () { + describe('#spawnCommand()', () => { it('provide default options', function () { this.spawn.spawnCommand('foo'); sinon.assert.calledWith(this.crossSpawn, 'foo', undefined, {stdio: 'inherit'}); @@ -33,7 +33,7 @@ describe('generators.Base (actions/spawn-command)', function () { }); }); - describe('#spawnCommandSync()', function () { + describe('#spawnCommandSync()', () => { it('provide default options', function () { this.spawn.spawnCommandSync('foo'); sinon.assert.calledWith(this.crossSpawn.sync, 'foo', undefined, {stdio: 'inherit'}); diff --git a/test/storage.js b/test/storage.js index e44b4c42..092c483c 100644 --- a/test/storage.js +++ b/test/storage.js @@ -1,15 +1,15 @@ 'use strict'; -var assert = require('assert'); -var fs = require('fs'); -var os = require('os'); -var path = require('path'); -var FileEditor = require('mem-fs-editor'); -var pathExists = require('path-exists'); -var env = require('yeoman-environment'); -var helpers = require('yeoman-test'); -var Storage = require('../lib/util/storage'); - -var tmpdir = path.join(os.tmpdir(), 'yeoman-storage'); +const assert = require('assert'); +const fs = require('fs'); +const os = require('os'); +const path = require('path'); +const FileEditor = require('mem-fs-editor'); +const pathExists = require('path-exists'); +const env = require('yeoman-environment'); +const helpers = require('yeoman-test'); +const Storage = require('../lib/util/storage'); + +const tmpdir = path.join(os.tmpdir(), 'yeoman-storage'); function rm(filepath) { if (pathExists.sync(filepath)) { @@ -17,7 +17,7 @@ function rm(filepath) { } } -describe('Storage', function () { +describe('Storage', () => { before(helpers.setUpTestDirectory(tmpdir)); beforeEach(function () { @@ -34,33 +34,33 @@ describe('Storage', function () { process.chdir(this.beforeDir); }); - describe('.constructor()', function () { - it('require a name parameter', function () { - assert.throws(function () { + describe('.constructor()', () => { + it('require a name parameter', () => { + assert.throws(() => { new Storage(); // eslint-disable-line no-new }); }); it('take a path parameter', function () { - var store = new Storage('test', this.fs, path.join(__dirname, './fixtures/config.json')); + const store = new Storage('test', this.fs, path.join(__dirname, './fixtures/config.json')); assert.equal(store.get('testFramework'), 'mocha'); assert.ok(store.existed); }); }); it('namespace each store sharing the same store file', function () { - var store = new Storage('foobar', this.fs, this.storePath); + const store = new Storage('foobar', this.fs, this.storePath); store.set('foo', 'something else'); assert.equal(this.store.get('foo'), 'bar'); }); - it('a config path is required', function () { + it('a config path is required', () => { assert.throws(function () { new Storage('yo', this.fs); // eslint-disable-line no-new }); }); - describe('#get()', function () { + describe('#get()', () => { beforeEach(function () { this.store.set('testFramework', 'mocha'); this.store.set('name', 'test'); @@ -72,7 +72,7 @@ describe('Storage', function () { }); }); - describe('#set()', function () { + describe('#set()', () => { it('set values', function () { this.store.set('name', 'Yeoman!'); assert.equal(this.store.get('name'), 'Yeoman!'); @@ -85,7 +85,7 @@ describe('Storage', function () { }); it('throws when invalid JSON values are passed', function () { - assert.throws(this.store.set.bind(this, 'foo', function () {})); + assert.throws(this.store.set.bind(this, 'foo', () => {})); }); it('save on each changes', function () { @@ -95,7 +95,7 @@ describe('Storage', function () { assert.equal(this.fs.readJSON(this.storePath).test.foo, 'oo'); }); - describe('@return', function () { + describe('@return', () => { beforeEach(function () { this.storePath = path.join(tmpdir, 'setreturn.json'); this.store = new Storage('test', this.fs, this.storePath); @@ -125,7 +125,7 @@ describe('Storage', function () { }); }); - describe('when multiples instances share the same file', function () { + describe('when multiples instances share the same file', () => { beforeEach(function () { this.store = new Storage('test', this.fs, this.storePath); this.store.set('foo', 'bar'); @@ -136,13 +136,13 @@ describe('Storage', function () { this.store2.set('bar', 'foo'); this.store.set('foo', 'bar'); - var json = this.fs.readJSON(this.storePath); + const json = this.fs.readJSON(this.storePath); assert.equal(json.test.foo, 'bar'); assert.equal(json.test2.bar, 'foo'); }); }); - describe('when multiples instances share the same namespace', function () { + describe('when multiples instances share the same namespace', () => { beforeEach(function () { this.store = new Storage('test', this.fs, this.storePath); this.store.set('foo', 'bar'); @@ -153,14 +153,14 @@ describe('Storage', function () { this.store2.set('bar', 'foo'); this.store.set('foo', 'bar'); - var json = this.fs.readJSON(this.storePath); + const json = this.fs.readJSON(this.storePath); assert.equal(json.test.foo, 'bar'); assert.equal(json.test.bar, 'foo'); }); }); }); - describe('#getAll()', function () { + describe('#getAll()', () => { beforeEach(function () { this.store.set({foo: 'bar', john: 'doe'}); }); @@ -175,7 +175,7 @@ describe('Storage', function () { }); }); - describe('#delete()', function () { + describe('#delete()', () => { beforeEach(function () { this.store.set('name', 'test'); }); @@ -186,7 +186,7 @@ describe('Storage', function () { }); }); - describe('#defaults()', function () { + describe('#defaults()', () => { beforeEach(function () { this.store.set('val1', 1); }); @@ -202,7 +202,7 @@ describe('Storage', function () { assert.throws(this.store.defaults.bind(this.store, 'foo')); }); - describe('@return', function () { + describe('@return', () => { beforeEach(function () { this.storePath = path.join(tmpdir, 'defaultreturn.json'); this.store = new Storage('test', this.fs, this.storePath); diff --git a/test/user.js b/test/user.js index ccaef8e5..a4ce0333 100644 --- a/test/user.js +++ b/test/user.js @@ -1,18 +1,18 @@ 'use strict'; -var assert = require('assert'); -var os = require('os'); -var path = require('path'); -var mkdirp = require('mkdirp'); -var nock = require('nock'); -var proxyquire = require('proxyquire'); -var rimraf = require('rimraf'); -var shell = require('shelljs'); -var sinon = require('sinon'); -var Base = require('..'); - -var tmpdir = path.join(os.tmpdir(), 'yeoman-user'); - -describe('Base#user', function () { +const assert = require('assert'); +const os = require('os'); +const path = require('path'); +const mkdirp = require('mkdirp'); +const nock = require('nock'); +const proxyquire = require('proxyquire'); +const rimraf = require('rimraf'); +const shell = require('shelljs'); +const sinon = require('sinon'); +const Base = require('..'); + +const tmpdir = path.join(os.tmpdir(), 'yeoman-user'); + +describe('Base#user', () => { before(function () { this.prevCwd = process.cwd(); this.tmp = tmpdir; @@ -42,12 +42,12 @@ describe('Base#user', function () { this.shell.exec.restore(); }); - it('is exposed on the Base generator', function () { + it('is exposed on the Base generator', () => { assert.equal(require('../lib/actions/user'), Base.prototype.user); }); - describe('.git', function () { - describe('.name()', function () { + describe('.git', () => { + describe('.name()', () => { it('is the name used by git', function () { assert.equal(this.user.git.name(), 'Yeoman'); }); @@ -66,7 +66,7 @@ describe('Base#user', function () { }); }); - describe('.email()', function () { + describe('.email()', () => { it('is the email used by git', function () { assert.equal(this.user.git.email(), 'yo@yeoman.io'); }); @@ -86,9 +86,9 @@ describe('Base#user', function () { }); }); - describe('.github', function () { - describe('.username()', function () { - beforeEach(function () { + describe('.github', () => { + describe('.username()', () => { + beforeEach(() => { nock('https://api.github.com') .filteringPath(/q=[^&]*/g, 'q=XXX') .get('/search/users?q=XXX') @@ -100,12 +100,12 @@ describe('Base#user', function () { }); }); - afterEach(function () { + afterEach(() => { nock.restore(); }); it('is the username used by GitHub', function (done) { - this.user.github.username(function (err, res) { + this.user.github.username((_, res) => { assert.equal(res, 'mockname'); done(); });