'use strict';

require('mocha');
var assert = require('assert');
var lazyCache = require('./');

describe('lazy-cache', function() {
  afterEach(function() {
    delete require.cache[require.resolve('./index.js')];
    process.env.UNLAZY = false;
    lazyCache = require('./');
  });

  it('should return a function that lazyily requires a module', function() {
    var lazy = lazyCache(require);
    var yellow = lazy('ansi-yellow');
    assert.deepEqual(typeof yellow, 'function');
    assert.deepEqual(typeof yellow(), 'function');
  });

  it('should add a property to the lazy function with the camelcased name', function() {
    var lazy = lazyCache(require);
    lazy('ansi-yellow');
    assert.deepEqual(typeof lazy.ansiYellow, 'function');
  });

  it('should only require a dependency once', function() {
    var calls = {};
    var lazy = lazyCache(function(mod) {
      calls[mod] = (calls[mod] || 0) + 1;
      return require(mod);
    });

    assert.deepEqual(calls, {});
    lazy('ansi-yellow');
    assert.deepEqual(calls, {});

    lazy.ansiYellow('one');
    assert.deepEqual(calls, {'ansi-yellow': 1});
    lazy.ansiYellow('two');
    assert.deepEqual(calls, {'ansi-yellow': 1});
    lazy.ansiYellow('three');
    assert.deepEqual(calls, {'ansi-yellow': 1});
    lazy.ansiYellow('four');
    assert.deepEqual(calls, {'ansi-yellow': 1});
  });

  it('should allow loading a dependency immediately with `process.env.UNLAZY` setting', function() {
    process.env.UNLAZY = true;
    var calls = {};
    var lazy = lazyCache(function(mod) {
      calls[mod] = (calls[mod] || 0) + 1;
      return require(mod);
    });

    assert.deepEqual(calls, {});
    lazy('ansi-yellow');
    assert.deepEqual(calls, {'ansi-yellow': 1});

    lazy.ansiYellow('one');
    assert.deepEqual(calls, {'ansi-yellow': 1});
    lazy.ansiYellow('two');
    assert.deepEqual(calls, {'ansi-yellow': 1});
    lazy.ansiYellow('three');
    assert.deepEqual(calls, {'ansi-yellow': 1});
    lazy.ansiYellow('four');
    assert.deepEqual(calls, {'ansi-yellow': 1});
  });

  it('should support passing an alias as the second argument:', function() {
    var calls = {};
    var lazy = lazyCache(function(mod) {
      calls[mod] = (calls[mod] || 0) + 1;
      return require(mod);
    });

    assert.deepEqual(calls, {});
    lazy('ansi-yellow', 'yellow');
    assert.deepEqual(calls, {});

    lazy.yellow('one');
    assert.deepEqual(calls, {'ansi-yellow': 1});
    lazy.yellow('two');
    assert.deepEqual(calls, {'ansi-yellow': 1});
    lazy.yellow('three');
    assert.deepEqual(calls, {'ansi-yellow': 1});
    lazy.yellow('four');
    assert.deepEqual(calls, {'ansi-yellow': 1});
  });
});

@@ -997,32 +997,128 @@
 'ansi-yellow');%0A
+    if (process.env.TRAVIS) %7B%0A      assert.deepEqual(calls, %7B'ansi-yellow': 1%7D);%0A    %7D else %7B%0A  
     assert.deepE
@@ -1125,32 +1125,38 @@
 qual(calls, %7B%7D);
+%0A    %7D
 %0A%0A    lazy.ansiY
@@ -2432,32 +2432,128 @@
 ow', 'yellow');%0A
+    if (process.env.TRAVIS) %7B%0A      assert.deepEqual(calls, %7B'ansi-yellow': 1%7D);%0A    %7D else %7B%0A  
     assert.deepE
@@ -2568,16 +2568,22 @@
 ls, %7B%7D);
+%0A    %7D
 %0A%0A    la

check for travis