Skip to content
Mickael Daniel edited this page Jan 30, 2013 · 2 revisions

test-actions

yeoman.generators.Base

generator.prompt(defaults, prompts, cb).

this.dummy.prompt([], done);

generator.sourceRoot(root)

should update the "_sourceRoot" property when root is given.

this.dummy.sourceRoot(this.fixtures);
assert.equal(this.dummy._sourceRoot, this.fixtures);

should return the uddated or current value of "_sourceRoot".

assert.equal(this.dummy.sourceRoot(), this.fixtures);

generator.destinationRoot(root)

should update the "_destinationRoot" property when root is given.

this.dummy.destinationRoot('.');
assert.equal(this.dummy._destinationRoot, process.cwd());

should return the uddated or current value of "_destinationRoot".

assert.equal(this.dummy.destinationRoot(), process.cwd());

generator.copy(source, destination, options)

should copy source files relative to the "sourceRoot" value.

fs.stat('write/to/foo.js', done);

should allow absolute path, and prevent the relative paths join.

fs.stat('write/to/bar.js', done);

should allow to copy without using the templating (conficting with lodash/underscore).

fs.stat('write/to/lodash.js', done);

generator.read(filepath, encoding)

should read files relative to the "sourceRoot" value.

var body = this.dummy.read('foo.js');
assert.equal(body, 'var foo = \'foo\';\n');

should allow absolute path, and prevent the relative paths join.

var body = this.dummy.read(path.join(__dirname, 'fixtures/foo.js'));
assert.equal(body, 'var foo = \'foo\';\n');

generator.write(filepath, content)

should write the specified files relative to the "destinationRoot" value.

var body = this.body;
fs.readFile('write/to/foobar.js', 'utf8', function (err, actual) {
  if (err) {
    return done(err);
  }
  assert.ok(actual, body);
  done();
});

generator.template(source, destination, data)

should copy and process source file to destination.

fs.stat('write/to/from-template.js', done);

should defaults the destination to the source filepath value, relative to "destinationRoot" value.

var body = fs.readFileSync('foo-template.js', 'utf8');
assert.equal(body, 'var fooooooo = \'fooooooo\';\n');

should process underscore templates with the passed-in data.

var body = fs.readFileSync('write/to/from-template-bar.js', 'utf8');
assert.equal(body, 'var bar = \'bar\';\n');

should process underscore templates with the actual generator instance, when no data is given.

var body = fs.readFileSync('write/to/from-template.js', 'utf8');
assert.equal(body, 'var fooooooo = \'fooooooo\';\n');

generator.directory(source, destination)

should copy and process source files to destination.

fs.stat('directory/foo-template.js', function (err) {
  if (err) {
    return done(err);
  }
  fs.stat('directory/foo.js', done);
});

should defaults the destination to the source filepath value, relative to "destinationRoot" value.

fs.stat('foo-template.js', function (err) {
  if (err) {
    return done(err);
  }
  fs.stat('foo.js', done);
});

should process underscore templates with the actual generator instance.

var body = fs.readFileSync('directory/foo-template.js', 'utf8');
var foo = this.dummy.foo;
assert.equal(body, 'var ' + foo + ' = \'' + foo + '\';\n');