Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(() => {
this.env = yeoman.createEnv([], {}, new TestAdapter());
const Dummy = class extends Base {
exec() {}
};
this.env.registerStub(Dummy, 'dummy');
this.dummy = this.env.create('dummy');
// Keep track of all commands executed by spawnCommand.
this.spawnCommandStub = sinon.stub(this.dummy, 'spawnCommand');
this.spawnCommandStub.returns(asyncStub);
});
it('shows old content for deleted 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')
.callsFake((prompts, resultHandler) => {
if (promptStub.calledTwice) {
const stubbedResultHandler = result => {
result.action = 'write';
return resultHandler(result);
};
return _prompt(prompts, stubbedResultHandler);
}
return _prompt(prompts, resultHandler);
});
it('allow skipping file writes to disk', function() {
const action = { action: 'skip' };
const filepath = path.join(__dirname, '/fixtures/conflict.js');
assert(fs.existsSync(filepath));
this.TestGenerator.prototype.writing = function() {
this.fs.write(filepath, 'some new content');
};
const env = yeoman.createEnv([], { 'skip-install': true }, new TestAdapter(action));
const testGen = new this.TestGenerator([], {
resolved: 'generator/app/index.js',
namespace: 'dummy',
env
});
return testGen.run().then(() => {
assert.equal(fs.readFileSync(filepath, 'utf8'), 'var a = 1;\n');
});
});
it('skip deleted file with dryRun', function(done) {
const conflicter = new Conflicter(new TestAdapter(), false, {
dryRun: true
});
conflicter.collision(
{
path: path.join(__dirname, 'fixtures/foo.js'),
contents: null
},
status => {
assert.equal(status, 'skip');
done();
}
);
});
it('emits the series of event on a specific generator', function(done) {
const angular = new this.Generator([], {
env: yeoman.createEnv([], {}, new TestAdapter()),
resolved: __filename,
'skip-install': true
});
const lifecycle = [
'run',
'method:createSomething',
'method:createSomethingElse',
'end'
];
function assertEvent(e) {
return function() {
assert.equal(e, lifecycle.shift());
if (e === 'end') {
beforeEach(function () {
this.env = yeoman.createEnv([], {}, new TestAdapter());
this.Generator = generators.Base.extend({
exec: function () {}
});
this.gen = new this.Generator({
namespace: 'foo:lab',
resolved: 'path/',
env: this.env,
'skip-install': true
});
this.SubGen = generators.Base.extend({
exec: function () {
this.stubGenRan = true;
}
});
beforeEach(function () {
this.env = yeoman.createEnv([], {}, new TestAdapter());
var Dummy = generators.Base.extend({
exec: sinon.spy()
});
this.env.registerStub(Dummy, 'dummy');
this.dummy = this.env.create('dummy');
nock('https://github.com')
.get('/yeoman/generator/archive/master.tar.gz')
.replyWithFile(200, path.join(__dirname, 'fixtures/testRemoteFile.tar.gz'));
});
beforeEach(function () {
this.dummy = new generators.Base({
env: yeoman.createEnv([], {}, new TestAdapter()),
resolved: 'test:fetch'
});
});
beforeEach(function () {
var env = this.env = generators([], {}, new TestAdapter());
var Dummy = generators.Base.extend({
exec: function () {}
});
env.registerStub(Dummy, 'dummy');
this.dummy = env.create('dummy');
this.fixtures = path.join(__dirname, 'fixtures');
this.dummy.sourceRoot(this.fixtures);
this.dummy.foo = 'bar';
});