<commit_before>'use strict';

const expect = require('chai').expect;
const tmp = require('tmp-sync');
const path = require('path');
const RSVP = require('rsvp');
const fs = require('fs-extra');
const fixtureBower = require('../fixtures/bower.json');
const fixturePackage = require('../fixtures/package.json');
const writeJSONFile = require('../helpers/write-json-file');
const mockery = require('mockery');

/* Some of the tests in this file intentionally DO NOT stub dependency manager adapter*/
const StubDependencyAdapter = require('../helpers/stub-dependency-manager-adapter');
const generateMockRun = require('../helpers/generate-mock-run');

const remove = RSVP.denodeify(fs.remove);
const root = process.cwd();
const tmproot = path.join(root, 'tmp');

const config = {
  scenarios: [
    {
      name: 'first',
      bower: {
        dependencies: {
          ember: '1.13.0',
          bootstrap: null,
        },
      },
      npm: {
        dependencies: {
          'ember-cli-deploy': '0.5.0',
        },
      },
    }, {
      name: 'second',
      bower: {
        dependencies: {
          ember: '2.0.0',
        },
        devDependencies: {
          jquery: '1.11.3',
        },
      },
      npm: {
        devDependencies: {
          'ember-cli-deploy': '0.5.1',
        },
      },
    },
    {
      name: 'with-bower-resolutions',
      bower: {
        dependencies: {
          ember: 'components/ember#beta',
        },
        resolutions: {
          ember: 'beta',
        },
      },
      npm: {
        dependencies: {
          'ember-cli-deploy': '0.5.1',
        },
      },
    }],
};

describe('tryEach', () => {
  let tmpdir;

  beforeEach(() => {
    tmpdir = tmp.in(tmproot);
    process.chdir(tmpdir);
    mockery.enable({
      warnOnUnregistered: false,
      useCleanCache: true,
    });
    require('chalk').enabled = false;
  });

  afterEach(() => {
    mockery.deregisterAll();
    mockery.disable();
    process.chdir(root);
    return remove(tmproot);
  });

  describe('with bower scenarios', () => {
    it('works without an initial bower.json', function() {
      this.timeout(300000);

      let mockedRun = generateMockRun('ember test', () => {
        return RSVP.resolve(0);
      });
      mockery.registerMock('./run', mockedRun);

      let output = [];
      let outputFn = function(log) {
        output.push(log);
      };

      let TryEachTask = require('../../lib/tasks/try-each');
      let tryEachTask = new TryEachTask({
        ui: { writeLine: outputFn },
        project: { root: tmpdir },
        config,
        _on() {},
      });

      writeJSONFile('package.json', fixturePackage);
      fs.mkdirSync('node_modules');

      expect(fs.existsSync('bower.json')).to.eql(false);
      return tryEachTask.run(config.scenarios, {}).then(() => {
        expect(output).to.include('All 3 scenarios succeeded');
        expect(fs.existsSync('bower.json')).to.eql(false);
        expect(fs.existsSync('bower_components')).to.eql(false);
      });
    });
  });

  describe('with both npm and bower', () => {
    it('succeeds when scenario\'s tests succeed', function() {
      this.timeout(300000);

      let mockedRun = generateMockRun('ember test', () => {
        return RSVP.resolve(0);
      });

      mockery.registerMock('./run', mockedRun);

      let output = [];
      let outputFn = function(log) {
        output.push(log);
      };

      let TryEachTask = require('../../lib/tasks/try-each');
      let tryEachTask = new TryEachTask({
        ui: { writeLine: outputFn },
        project: { root: tmpdir },
        config,
        _on() {},
      });

      writeJSONFile('package.json', fixturePackage);
      fs.writeFileSync('yarn.lock', '');
      fs.mkdirSync('node_modules');
      writeJSONFile('bower.json', fixtureBower);
      return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
        expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
        expect(output).to.include('Detected a yarn.lock file, add useYarn: true to your configuration if you want to use Yarn to install npm dependencies.');
        expect(output).to.include('Scenario first: SUCCESS');
        expect(output).to.include('Scenario second: SUCCESS');
        expect(output).to.include('Scenario with-bower-resolutions: SUCCESS');
        expect(output).to.include('All 3 scenarios succeeded');
      });
    });
<commit_msg>Update test to match new error message output<commit_after>'use strict';

const expect = require('chai').expect;
const tmp = require('tmp-sync');
const path = require('path');
const RSVP = require('rsvp');
const fs = require('fs-extra');
const fixtureBower = require('../fixtures/bower.json');
const fixturePackage = require('../fixtures/package.json');
const writeJSONFile = require('../helpers/write-json-file');
const mockery = require('mockery');

/* Some of the tests in this file intentionally DO NOT stub dependency manager adapter*/
const StubDependencyAdapter = require('../helpers/stub-dependency-manager-adapter');
const generateMockRun = require('../helpers/generate-mock-run');

const remove = RSVP.denodeify(fs.remove);
const root = process.cwd();
const tmproot = path.join(root, 'tmp');

const config = {
  scenarios: [
    {
      name: 'first',
      bower: {
        dependencies: {
          ember: '1.13.0',
          bootstrap: null,
        },
      },
      npm: {
        dependencies: {
          'ember-cli-deploy': '0.5.0',
        },
      },
    }, {
      name: 'second',
      bower: {
        dependencies: {
          ember: '2.0.0',
        },
        devDependencies: {
          jquery: '1.11.3',
        },
      },
      npm: {
        devDependencies: {
          'ember-cli-deploy': '0.5.1',
        },
      },
    },
    {
      name: 'with-bower-resolutions',
      bower: {
        dependencies: {
          ember: 'components/ember#beta',
        },
        resolutions: {
          ember: 'beta',
        },
      },
      npm: {
        dependencies: {
          'ember-cli-deploy': '0.5.1',
        },
      },
    }],
};

describe('tryEach', () => {
  let tmpdir;

  beforeEach(() => {
    tmpdir = tmp.in(tmproot);
    process.chdir(tmpdir);
    mockery.enable({
      warnOnUnregistered: false,
      useCleanCache: true,
    });
    require('chalk').enabled = false;
  });

  afterEach(() => {
    mockery.deregisterAll();
    mockery.disable();
    process.chdir(root);
    return remove(tmproot);
  });

  describe('with bower scenarios', () => {
    it('works without an initial bower.json', function() {
      this.timeout(300000);

      let mockedRun = generateMockRun('ember test', () => {
        return RSVP.resolve(0);
      });
      mockery.registerMock('./run', mockedRun);

      let output = [];
      let outputFn = function(log) {
        output.push(log);
      };

      let TryEachTask = require('../../lib/tasks/try-each');
      let tryEachTask = new TryEachTask({
        ui: { writeLine: outputFn },
        project: { root: tmpdir },
        config,
        _on() {},
      });

      writeJSONFile('package.json', fixturePackage);
      fs.mkdirSync('node_modules');

      expect(fs.existsSync('bower.json')).to.eql(false);
      return tryEachTask.run(config.scenarios, {}).then(() => {
        expect(output).to.include('All 3 scenarios succeeded');
        expect(fs.existsSync('bower.json')).to.eql(false);
        expect(fs.existsSync('bower_components')).to.eql(false);
      });
    });
  });

  describe('with both npm and bower', () => {
    it('succeeds when scenario\'s tests succeed', function() {
      this.timeout(300000);

      let mockedRun = generateMockRun('ember test', () => {
        return RSVP.resolve(0);
      });

      mockery.registerMock('./run', mockedRun);

      let output = [];
      let outputFn = function(log) {
        output.push(log);
      };

      let TryEachTask = require('../../lib/tasks/try-each');
      let tryEachTask = new TryEachTask({
        ui: { writeLine: outputFn },
        project: { root: tmpdir },
        config,
        _on() {},
      });

      writeJSONFile('package.json', fixturePackage);
      fs.writeFileSync('yarn.lock', '');
      fs.mkdirSync('node_modules');
      writeJSONFile('bower.json', fixtureBower);
      return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
        expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
        expect(output).to.include('Detected a yarn.lock file. Add `useYarn: true` to your `config/ember-try.js` configuration file if you want to use Yarn to install npm dependencies.');
        expect(output).to.include('Scenario first: SUCCESS');
        expect(output).to.include('Scenario second: SUCCESS');
        expect(output).to.include('Scenario with-bower-resolutions: SUCCESS');
        expect(output).to.include('All 3 scenarios succeeded');
      });
    });

{'fraction_non_alphanumeric': 0.1659746380877567, 'fraction_numerical': 0.008528784648187633, 'mean_word_length': 2.398932112890923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2460363', 'n_tokens_mistral': 2784, 'n_tokens_neox': 2691, 'n_words': 533}