yeoman-test 1.9.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/adapter.js CHANGED
@@ -10,22 +10,22 @@ function DummyPrompt(answers, q) {
10
10
  this.question = q;
11
11
  }
12
12
 
13
- DummyPrompt.prototype.run = function() {
13
+ DummyPrompt.prototype.run = function () {
14
14
  var answer = this.answers[this.question.name];
15
15
  var isSet;
16
16
 
17
17
  switch (this.question.type) {
18
18
  case 'list':
19
- // List prompt accepts any answer value including null
19
+ // list prompt accepts any answer value including null
20
20
  isSet = answer !== undefined;
21
21
  break;
22
22
  case 'confirm':
23
- // Ensure that we don't replace `false` with default `true`
23
+ // ensure that we don't replace `false` with default `true`
24
24
  isSet = answer || answer === false;
25
25
  break;
26
26
  default:
27
- // Other prompts treat all falsy values to default
28
- isSet = Boolean(answer);
27
+ // other prompts treat all falsy values to default
28
+ isSet = !!answer;
29
29
  }
30
30
 
31
31
  if (!isSet) {
@@ -43,7 +43,7 @@ function TestAdapter(answers) {
43
43
  answers = answers || {};
44
44
  this.promptModule = inquirer.createPromptModule();
45
45
 
46
- Object.keys(this.promptModule.prompts).forEach(function(promptName) {
46
+ Object.keys(this.promptModule.prompts).forEach(function (promptName) {
47
47
  this.promptModule.registerPrompt(promptName, DummyPrompt.bind(DummyPrompt, answers));
48
48
  }, this);
49
49
 
@@ -51,7 +51,7 @@ function TestAdapter(answers) {
51
51
  this.log = sinon.spy();
52
52
  _.extend(this.log, events.EventEmitter.prototype);
53
53
 
54
- // Make sure all log methods are defined
54
+ // make sure all log methods are defined
55
55
  [
56
56
  'write',
57
57
  'writeln',
@@ -65,12 +65,12 @@ function TestAdapter(answers) {
65
65
  'identical',
66
66
  'info',
67
67
  'table'
68
- ].forEach(function(methodName) {
68
+ ].forEach(function (methodName) {
69
69
  this.log[methodName] = sinon.stub().returns(this.log);
70
70
  }, this);
71
71
  }
72
72
 
73
- TestAdapter.prototype.prompt = function(questions, cb) {
73
+ TestAdapter.prototype.prompt = function (questions, cb) {
74
74
  var promise = this.promptModule(questions);
75
75
  promise.then(cb || _.noop);
76
76
 
package/lib/index.js CHANGED
@@ -22,9 +22,9 @@ var adapter = require('./adapter');
22
22
  * @returns {Function} mocha callback
23
23
  */
24
24
 
25
- exports.setUpTestDirectory = function(dir) {
26
- return function(done) {
27
- exports.testDirectory(dir, function() {
25
+ exports.setUpTestDirectory = function before(dir) {
26
+ return function (done) {
27
+ exports.testDirectory(dir, function () {
28
28
  exports.gruntfile({ dummy: true }, done);
29
29
  });
30
30
  };
@@ -46,17 +46,18 @@ exports.setUpTestDirectory = function(dir) {
46
46
  *
47
47
  */
48
48
 
49
- exports.gruntfile = function(options, done) {
49
+ exports.gruntfile = function (options, done) {
50
50
  var config = 'grunt.initConfig(' + JSON.stringify(options, null, 2) + ');';
51
51
 
52
- config = config
53
- .split('\n')
54
- .map(function(line) {
55
- return ' ' + line;
56
- })
57
- .join('\n');
52
+ config = config.split('\n').map(function (line) {
53
+ return ' ' + line;
54
+ }).join('\n');
58
55
 
59
- var out = ['module.exports = function (grunt) {', config, '};'];
56
+ var out = [
57
+ 'module.exports = function (grunt) {',
58
+ config,
59
+ '};'
60
+ ];
60
61
 
61
62
  fs.writeFile('Gruntfile.js', out.join('\n'), done);
62
63
  };
@@ -72,7 +73,7 @@ exports.gruntfile = function(options, done) {
72
73
  * });
73
74
  */
74
75
 
75
- exports.testDirectory = function(dir, cb) {
76
+ exports.testDirectory = function (dir, cb) {
76
77
  if (!dir) {
77
78
  throw new Error('Missing directory');
78
79
  }
@@ -83,7 +84,7 @@ exports.testDirectory = function(dir, cb) {
83
84
  // test dir after cleaning up, this shouldn't be perceivable.
84
85
  process.chdir('/');
85
86
 
86
- rimraf(dir, function(err) {
87
+ rimraf(dir, function (err) {
87
88
  if (err) {
88
89
  return cb(err);
89
90
  }
@@ -104,12 +105,12 @@ exports.testDirectory = function(dir, cb) {
104
105
  * mockPrompt(angular, {'bootstrap': 'Y', 'compassBoostrap': 'Y'});
105
106
  */
106
107
 
107
- exports.mockPrompt = function(generator, answers) {
108
+ exports.mockPrompt = function (generator, answers) {
108
109
  var promptModule = generator.env.adapter.promptModule;
109
110
  answers = answers || {};
110
111
  var DummyPrompt = adapter.DummyPrompt;
111
112
 
112
- Object.keys(promptModule.prompts).forEach(function(name) {
113
+ Object.keys(promptModule.prompts).forEach(function (name) {
113
114
  promptModule.registerPrompt(name, DummyPrompt.bind(DummyPrompt, answers));
114
115
  });
115
116
  };
@@ -118,7 +119,7 @@ exports.mockPrompt = function(generator, answers) {
118
119
  * Restore defaults prompts on a generator.
119
120
  * @param {Generator} generator
120
121
  */
121
- exports.restorePrompt = function(generator) {
122
+ exports.restorePrompt = function (generator) {
122
123
  generator.env.adapter.promptModule.restoreDefaultPrompts();
123
124
  };
124
125
 
@@ -127,7 +128,7 @@ exports.restorePrompt = function(generator) {
127
128
  * @param {Generator} generator - a Yeoman generator
128
129
  * @param {Object} localConfig - localConfig - should look just like if called config.getAll()
129
130
  */
130
- exports.mockLocalConfig = function(generator, localConfig) {
131
+ exports.mockLocalConfig = function (generator, localConfig) {
131
132
  generator.config.defaults(localConfig);
132
133
  };
133
134
 
@@ -135,12 +136,11 @@ exports.mockLocalConfig = function(generator, localConfig) {
135
136
  * Create a simple, dummy generator
136
137
  */
137
138
 
138
- exports.createDummyGenerator = () =>
139
- class extends Generator {
140
- test() {
141
- this.shouldRun = true;
142
- }
143
- };
139
+ exports.createDummyGenerator = () => class extends Generator {
140
+ test() {
141
+ this.shouldRun = true;
142
+ }
143
+ };
144
144
 
145
145
  /**
146
146
  * Create a generator, using the given dependencies and controller arguments
@@ -161,7 +161,7 @@ exports.createDummyGenerator = () =>
161
161
  * var angular = createGenerator('angular:app', deps);
162
162
  */
163
163
 
164
- exports.createGenerator = function(name, dependencies, args, options) {
164
+ exports.createGenerator = function (name, dependencies, args, options) {
165
165
  var env = yeoman.createEnv();
166
166
  this.registerDependencies(env, dependencies);
167
167
 
@@ -175,8 +175,8 @@ exports.createGenerator = function(name, dependencies, args, options) {
175
175
  * @param {Array} dependencies - paths to the generators dependencies
176
176
  */
177
177
 
178
- exports.registerDependencies = function(env, dependencies) {
179
- dependencies.forEach(function(dependency) {
178
+ exports.registerDependencies = function (env, dependencies) {
179
+ dependencies.forEach(function (dependency) {
180
180
  if (_.isArray(dependency)) {
181
181
  env.registerStub.apply(env, dependency);
182
182
  } else {
@@ -191,7 +191,7 @@ exports.registerDependencies = function(env, dependencies) {
191
191
  * @return {RunContext}
192
192
  */
193
193
 
194
- exports.run = function(GeneratorOrNamespace, settings) {
194
+ exports.run = function (GeneratorOrNamespace, settings) {
195
195
  var RunContext = require('./run-context');
196
196
  return new RunContext(GeneratorOrNamespace, settings);
197
197
  };
@@ -26,7 +26,7 @@ var TestAdapter = require('./adapter').TestAdapter;
26
26
  * @return {this}
27
27
  */
28
28
 
29
- function RunContext(Generator, settings) {
29
+ var RunContext = module.exports = function RunContext(Generator, settings) {
30
30
  this._asyncHolds = 0;
31
31
  this.ran = false;
32
32
  this.inDirSet = false;
@@ -43,7 +43,8 @@ function RunContext(Generator, settings) {
43
43
  skipInstall: true
44
44
  });
45
45
  setTimeout(this._run.bind(this), 10);
46
- }
46
+ };
47
+
47
48
  util.inherits(RunContext, EventEmitter);
48
49
 
49
50
  /**
@@ -51,10 +52,10 @@ util.inherits(RunContext, EventEmitter);
51
52
  * @return {Function} Callback to notify the normal execution can resume
52
53
  */
53
54
 
54
- RunContext.prototype.async = function() {
55
+ RunContext.prototype.async = function () {
55
56
  this._asyncHolds++;
56
57
 
57
- return function() {
58
+ return function () {
58
59
  this._asyncHolds--;
59
60
  this._run();
60
61
  }.bind(this);
@@ -65,7 +66,7 @@ RunContext.prototype.async = function() {
65
66
  * @private
66
67
  */
67
68
 
68
- RunContext.prototype._run = function() {
69
+ RunContext.prototype._run = function () {
69
70
  if (!this.inDirSet && this.settings.tmpdir) {
70
71
  this.inTmpDir();
71
72
  }
@@ -95,64 +96,53 @@ RunContext.prototype._run = function() {
95
96
 
96
97
  helpers.mockPrompt(this.generator, this.answers);
97
98
 
98
- if (this.localConfig) {
99
- // Only mock local config when withLocalConfig was called
99
+ if (this.localConfig) { // only mock local config when withLocalConfig was called
100
100
  helpers.mockLocalConfig(this.generator, this.localConfig);
101
101
  }
102
102
 
103
- this.generator.on(
104
- 'error',
105
- function(err) {
106
- if (!this.emit('error', err)) {
107
- throw err;
108
- }
109
- }.bind(this)
110
- );
111
- this.generator.once(
112
- 'end',
113
- function() {
114
- helpers.restorePrompt(this.generator);
115
- this.emit('end');
116
- this.completed = true;
117
- }.bind(this)
118
- );
103
+ this.generator.on('error', function (err) {
104
+ if (!this.emit('error', err)) {
105
+ throw err;
106
+ }
107
+ }.bind(this));
108
+ this.generator.once('end', function () {
109
+ helpers.restorePrompt(this.generator);
110
+ this.emit('end');
111
+ this.completed = true;
112
+ }.bind(this));
119
113
 
120
114
  this.emit('ready', this.generator);
121
- this.generator.run().catch(err => this.emit('error', err));
115
+ this.generator.run();
122
116
  };
123
117
 
124
118
  /**
125
119
  * Return a promise representing the generator run process
126
120
  * @return {Promise} Promise resolved on end or rejected on error
127
121
  */
128
- RunContext.prototype.toPromise = function() {
129
- return new Promise(
130
- function(resolve, reject) {
131
- this.on(
132
- 'end',
133
- function() {
134
- resolve(this.targetDirectory);
135
- }.bind(this)
136
- );
137
- this.on('error', reject);
138
- }.bind(this)
139
- );
122
+ RunContext.prototype.toPromise = function () {
123
+ return new Promise(function (resolve, reject) {
124
+ this.on('end', function () {
125
+ resolve(this.targetDirectory);
126
+ }.bind(this));
127
+ this.on('error', reject);
128
+ }.bind(this));
140
129
  };
141
130
 
142
131
  /**
143
132
  * Promise `.then()` duck typing
144
133
  * @return {Promise}
145
134
  */
146
- RunContext.prototype.then = function() {
135
+ RunContext.prototype.then = function () {
147
136
  var promise = this.toPromise();
148
137
  return promise.then.apply(promise, arguments);
149
138
  };
150
139
 
140
+
151
141
  /**
152
142
  * Promise `.catch()` duck typing
153
143
  * @return {Promise}
154
144
  */
155
- RunContext.prototype.catch = function() {
145
+ RunContext.prototype.catch = function () {
156
146
  var promise = this.toPromise();
157
147
  return promise.catch.apply(promise, arguments);
158
148
  };
@@ -165,7 +155,7 @@ RunContext.prototype.catch = function() {
165
155
  * @return {this} run context instance
166
156
  */
167
157
 
168
- RunContext.prototype.inDir = function(dirPath, cb) {
158
+ RunContext.prototype.inDir = function (dirPath, cb) {
169
159
  this.inDirSet = true;
170
160
  this.targetDirectory = dirPath;
171
161
  var release = this.async();
@@ -183,7 +173,7 @@ RunContext.prototype.inDir = function(dirPath, cb) {
183
173
  * file path for predictable results
184
174
  * @return {this} run context instance
185
175
  */
186
- RunContext.prototype.cd = function(dirPath) {
176
+ RunContext.prototype.cd = function (dirPath) {
187
177
  this.inDirSet = true;
188
178
  this.targetDirectory = dirPath;
189
179
  dirPath = path.resolve(dirPath);
@@ -204,7 +194,7 @@ RunContext.prototype.cd = function(dirPath) {
204
194
  * @param {Function} [cb] - callback who'll receive the folder path as argument
205
195
  * @return {this} run context instance
206
196
  */
207
- RunContext.prototype.inTmpDir = function(cb) {
197
+ RunContext.prototype.inTmpDir = function (cb) {
208
198
  var tmpdir = path.join(os.tmpdir(), crypto.randomBytes(20).toString('hex'));
209
199
  return this.inDir(tmpdir, cb);
210
200
  };
@@ -212,7 +202,7 @@ RunContext.prototype.inTmpDir = function(cb) {
212
202
  /**
213
203
  * Clean the directory used for tests inside inDir/inTmpDir
214
204
  */
215
- RunContext.prototype.cleanTestDirectory = function() {
205
+ RunContext.prototype.cleanTestDirectory = function () {
216
206
  if (this.targetDirectory) {
217
207
  rimraf.sync(this.targetDirectory);
218
208
  }
@@ -224,12 +214,9 @@ RunContext.prototype.cleanTestDirectory = function() {
224
214
  * @return {this}
225
215
  */
226
216
 
227
- RunContext.prototype.withArguments = function(args) {
217
+ RunContext.prototype.withArguments = function (args) {
228
218
  var argsArray = _.isString(args) ? args.split(' ') : args;
229
- assert(
230
- _.isArray(argsArray),
231
- 'args should be either a string separated by spaces or an array'
232
- );
219
+ assert(_.isArray(argsArray), 'args should be either a string separated by spaces or an array');
233
220
  this.args = this.args.concat(argsArray);
234
221
  return this;
235
222
  };
@@ -240,10 +227,10 @@ RunContext.prototype.withArguments = function(args) {
240
227
  * @return {this}
241
228
  */
242
229
 
243
- RunContext.prototype.withOptions = function(options) {
230
+ RunContext.prototype.withOptions = function (options) {
244
231
  // Add options as both kebab and camel case. This is to stay backward compatibles with
245
232
  // the switch we made to meow for options parsing.
246
- Object.keys(options).forEach(function(key) {
233
+ Object.keys(options).forEach(function (key) {
247
234
  options[_.camelCase(key)] = options[key];
248
235
  options[_.kebabCase(key)] = options[key];
249
236
  });
@@ -258,7 +245,7 @@ RunContext.prototype.withOptions = function(options) {
258
245
  * @return {this}
259
246
  */
260
247
 
261
- RunContext.prototype.withPrompts = function(answers) {
248
+ RunContext.prototype.withPrompts = function (answers) {
262
249
  this.answers = _.extend(this.answers, answers);
263
250
  return this;
264
251
  };
@@ -280,7 +267,7 @@ RunContext.prototype.withPrompts = function(answers) {
280
267
  * });
281
268
  */
282
269
 
283
- RunContext.prototype.withGenerators = function(dependencies) {
270
+ RunContext.prototype.withGenerators = function (dependencies) {
284
271
  assert(_.isArray(dependencies), 'dependencies should be an array');
285
272
  this.dependencies = this.dependencies.concat(dependencies);
286
273
  return this;
@@ -291,10 +278,8 @@ RunContext.prototype.withGenerators = function(dependencies) {
291
278
  * @param {Object} localConfig - should look just like if called config.getAll()
292
279
  * @return {this}
293
280
  */
294
- RunContext.prototype.withLocalConfig = function(localConfig) {
281
+ RunContext.prototype.withLocalConfig = function (localConfig) {
295
282
  assert(_.isObject(localConfig), 'config should be an object');
296
283
  this.localConfig = localConfig;
297
284
  return this;
298
285
  };
299
-
300
- module.exports = RunContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-test",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
4
4
  "description": "Test utilities for Yeoman generators",
5
5
  "homepage": "http://yeoman.io/authoring/testing.html",
6
6
  "author": "The Yeoman Team",
@@ -13,43 +13,30 @@
13
13
  "unit test"
14
14
  ],
15
15
  "repository": "yeoman/yeoman-test",
16
- "license": "MIT",
17
16
  "devDependencies": {
18
- "coveralls": "^3.0.2",
19
- "eslint": "^5.2.0",
20
- "eslint-config-prettier": "^2.4.0",
21
- "eslint-config-xo": "^0.23.0",
22
- "eslint-plugin-prettier": "^2.2.0",
23
- "husky": "^0.14.3",
24
- "lint-staged": "^7.2.0",
25
- "mocha": "^5.2.0",
26
- "nyc": "^12.0.2",
27
- "prettier": "^1.7.0"
17
+ "eslint": "^4.2.0",
18
+ "gulp": "^4.0.0",
19
+ "gulp-coveralls": "^0.1.0",
20
+ "gulp-eslint": "^4.0.0",
21
+ "gulp-exclude-gitignore": "^1.0.0",
22
+ "gulp-istanbul": "^1.1.2",
23
+ "gulp-mocha": "^5.0.0",
24
+ "gulp-nsp": "^3.0.1",
25
+ "gulp-plumber": "^1.0.0"
26
+ },
27
+ "scripts": {
28
+ "prepublish": "gulp prepublish",
29
+ "test": "gulp"
28
30
  },
31
+ "license": "MIT",
29
32
  "dependencies": {
30
- "inquirer": "^6.0.0",
33
+ "inquirer": "^5.2.0",
31
34
  "lodash": "^4.17.10",
32
35
  "mkdirp": "^0.5.1",
33
36
  "pinkie-promise": "^2.0.1",
34
37
  "rimraf": "^2.4.4",
35
- "sinon": "^6.1.4",
38
+ "sinon": "^5.0.7",
36
39
  "yeoman-environment": "^2.3.0",
37
- "yeoman-generator": "^3.1.1"
38
- },
39
- "scripts": {
40
- "test": "nyc mocha",
41
- "pretest": "eslint .",
42
- "precommit": "lint-staged",
43
- "coverage": "nyc report --reporter=text-lcov | coveralls"
44
- },
45
- "lint-staged": {
46
- "*.js": [
47
- "eslint --fix",
48
- "git add"
49
- ],
50
- "*.json": [
51
- "prettier --write",
52
- "git add"
53
- ]
40
+ "yeoman-generator": "^2.0.5"
54
41
  }
55
42
  }