<commit_before>'use strict';

const expect = require('chai').expect;
const injectr = require('injectr');
const sinon = require('sinon');
const _ = require('lodash');

let fsMock,
  packageTemplate,
  uglifySpy;

const initialise = function(fs, uglifyStub){

  uglifySpy = sinon.spy();
  fsMock = _.extend({
    existsSync: sinon.stub().returns(true),
    readFileSync: sinon.stub().returns('file content'),
    writeFile: sinon.stub().yields(null, 'ok')
  }, fs || {});

  packageTemplate = injectr('../../src/cli/domain/package-template.js', {
    'fs-extra': fsMock,
    'uglify-js': {
      minify: uglifyStub || function(code){
        uglifySpy();
        return { code: code };
      }
    }
  });
};

describe('cli : domain : package-template', () => {

  describe('when packaging component\'s template', () => {

    describe('when component is not valid', () => {

      describe('when component view is not found', () => {

        let error;
        before((done) => {

          initialise({
            existsSync: sinon.stub().returns(false)
          });

          packageTemplate({
            componentPath: '/path/to/component/',
            ocOptions: {
              files: {
                template: {
                  type: 'jade',
                  src: 'template.jade'
                }
              }
            },
            publishPath: '/path/to/component/_package/'
          }, (e) => {
            error = e;
            done();
          });
        });

        it('should show error', () => {
          expect(error).to.equal('file template.jade not found');
        });
      });

      describe('when component view type is not valid', () => {

        let error;
        before((done) => {

          initialise();

          packageTemplate({
            componentPath: '/path/to/component/',
            ocOptions: {
              files: {
                template: {
                  type: 'whazaaa',
                  src: 'template.wha'
                }
              }
            },
            publishPath: '/path/to/component/_package/'
          }, (e) => {
            error = e;
            done();
          });
        });

        it('should show error', () => {
          expect(error).to.equal('template.wha compilation failed - Error: Error requiring oc-template: "whazaaa" not found');
        });
      });
    });

    describe('when component is valid', () => {

      before((done) => {

        initialise({
          readFileSync: sinon.stub().returns('div this is a jade view')
        });

        packageTemplate({
          componentPath: '/path/to/component/',
          ocOptions: {
            files: {
              template: {
                type: 'jade',
                src: 'template.jade'
              }
            }
          },
          publishPath: '/path/to/component/_package/'
        }, done);<commit_msg>updated cli package-template test for split api<commit_after>'use strict';

const expect = require('chai').expect;
const injectr = require('injectr');
const sinon = require('sinon');
const _ = require('lodash');

let fsMock,
  packageTemplate,
  uglifySpy;

const initialise = function(fs, uglifyStub){

  uglifySpy = sinon.spy();
  fsMock = _.extend({
    existsSync: sinon.stub().returns(true),
    readFileSync: sinon.stub().returns('file content'),
    writeFile: sinon.stub().yields(null, 'ok')
  }, fs || {});

  packageTemplate = injectr('../../src/cli/domain/package-template.js', {
    'fs-extra': fsMock,
    'uglify-js': {
      minify: uglifyStub || function(code){
        uglifySpy();
        return { code: code };
      }
    }
  });
};

describe('cli : domain : package-template', () => {

  describe('when packaging component\'s template', () => {

    describe('when component is not valid', () => {

      describe('when component view is not found', () => {

        let error;
        before((done) => {

          initialise({
            existsSync: sinon.stub().returns(false)
          });

          packageTemplate({
            componentPath: '/path/to/component/',
            ocOptions: {
              files: {
                template: {
                  type: 'jade',
                  src: 'template.jade'
                }
              }
            },
            publishPath: '/path/to/component/_package/'
          }, (e) => {
            error = e;
            done();
          });
        });

        it('should show error', () => {
          expect(error).to.equal('file template.jade not found');
        });
      });

      describe('when component view type is not valid', () => {

        let error;
        before((done) => {

          initialise();

          packageTemplate({
            componentPath: '/path/to/component/',
            ocOptions: {
              files: {
                template: {
                  type: 'whazaaa',
                  src: 'template.wha'
                }
              }
            },
            publishPath: '/path/to/component/_package/'
          }, (e) => {
            error = e;
            done();
          });
        });

        it('should show error', () => {
<<<<<<< HEAD
          expect(error).to.equal('template.wha compilation failed - Error: Error requiring oc-template: "whazaaa" not found');
=======
          expect(error).to.equal('template.wha compilation failed - Error requiring oc-template: "whazaaa-compiler" not found');
>>>>>>> updated cli package-template test for split api
        });
      });
    });

    describe('when component is valid', () => {

      before((done) => {

        initialise({
          readFileSync: sinon.stub().returns('div this is a jade view')
        });

        packageTemplate({
          componentPath: '/path/to/component/',
          ocOptions: {
            files: {
              template: {
                type: 'jade',
                src: 'template.jade'
              }
            }
          },
          publishPath: '/path/to/component/_package/'
        }, done);
{'fraction_non_alphanumeric': 0.1541901291818483, 'fraction_numerical': 0.0, 'mean_word_length': 1.5697872340425532, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 36, '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': '6332350', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1649, 'n_words': 340}