'use strict';

const RSVP = require('rsvp');
const ember = require('../helpers/ember');
const path = require('path');
let remove = RSVP.denodeify(require('fs-extra').remove);
let root = process.cwd();
let tmproot = path.join(root, 'tmp');
const mkTmpDirIn = require('../../lib/utilities/mk-tmp-dir-in');

const chai = require('../chai');
let expect = chai.expect;
let file = chai.file;

describe('Acceptance: ember install', function() {
  this.timeout(60000);

  beforeEach(function() {
    return mkTmpDirIn(tmproot).then(function(tmpdir) {
      process.chdir(tmpdir);
    });
  });

  afterEach(function() {
    process.chdir(root);
    return remove(tmproot);
  });

  function initApp() {
    return ember([
      'init',
      '--name=my-app',
      '--skip-npm',
      '--skip-bower',
    ]);
  }

  function installAddon(args) {
    let generateArgs = ['install'].concat(args);

    return initApp().then(function() {
      return ember(generateArgs);
    });
  }

  it('installs addons via npm and runs generators', function() {
    return installAddon(['ember-cli-fastclick', 'ember-cli-photoswipe']).then(function(result) {
      expect(file('package.json'))
        .to.match(/"ember-cli-fastclick": ".*"/)
        .to.match(/"ember-cli-photoswipe": ".*"/);

      expect(file('bower.json'))
        .to.match(/"photoswipe": ".*"/);

      expect(result.outputStream.join()).not.to.include('The `ember generate` command ' +
                                              'requires an entity name to be specified. For more details, use `ember help`.');
    });
  });
});

@@ -8,16 +8,42 @@
 rict';%0A%0A
+const co = require('co');%0A
 const RS
@@ -490,32 +490,40 @@
  beforeEach(
+co.wrap(
 function
 () %7B%0A    ret
@@ -502,32 +502,34 @@
 co.wrap(function
+ *
 () %7B%0A    return 
@@ -521,22 +521,34 @@
 ) %7B%0A    
-return
+let tmpdir = yield
  mkTmpDi
@@ -563,35 +563,10 @@
 oot)
-.then(function(tmpdir) %7B%0A  
+;%0A
     
@@ -590,25 +590,18 @@
 dir);%0A  
-  %7D);%0A  
 %7D
+)
 );%0A%0A  af
@@ -1035,24 +1035,32 @@
 ators', 
+co.wrap(
 function
 () %7B%0A   
@@ -1043,32 +1043,34 @@
 co.wrap(function
+ *
 () %7B%0A    return 
@@ -1062,22 +1062,34 @@
 ) %7B%0A    
-return
+let result = yield
  install
@@ -1146,35 +1146,11 @@
 e'%5D)
-.then(function(result) %7B%0A  
+;%0A%0A
     
@@ -1170,34 +1170,32 @@
 package.json'))%0A
-  
       .to.match(
@@ -1223,34 +1223,32 @@
 %22: %22.*%22/)%0A      
-  
 .to.match(/%22embe
@@ -1267,34 +1267,32 @@
 wipe%22: %22.*%22/);%0A%0A
-  
     expect(file(
@@ -1308,26 +1308,24 @@
 on'))%0A      
-  
 .to.match(/%22
@@ -1346,18 +1346,16 @@
 .*%22/);%0A%0A
-  
     expe
@@ -1384,16 +1384,23 @@
 .join())
+%0A      
 .not.to.
@@ -1441,59 +1441,8 @@
 and 
-' +%0A                                              '
 requ
@@ -1519,24 +1519,17 @@
 %60.');%0A  
-  %7D);%0A  
 %7D
+)
 );%0A%7D);%0A

Convert promise chains to coroutines