var expect = require('chai').expect;
var storybookCheck = require('../src/check');

describe('screener-storybook/src/check', function() {

  it('should error if there are no dependencies found', function() {
    try {
      storybookCheck();
    } catch (err) {
      expect(err.toString()).to.equal('Error: No dependencies found in package.json');
    }
    try {
      storybookCheck({});
    } catch (err) {
      expect(err.toString()).to.equal('Error: No dependencies found in package.json');
    }
  });

  it('should return react storybook v3', function() {
    var pjson = {
      devDependencies: {
        '@storybook/react': '^3.1.3'
      }
    };
    var result = storybookCheck(pjson);
    expect(result).to.deep.equal({
      app: 'react',
      version: 3,
      range: '^3.1.3'
    });
  });

  it('should return vue storybook v3', function() {
    var pjson = {
      devDependencies: {
        '@storybook/vue': '^3.0.0-alpha.0'
      }
    };
    var result = storybookCheck(pjson);
    expect(result).to.deep.equal({
      app: 'vue',
      version: 3,
      range: '^3.0.0-alpha.0'
    });
  });

  it('should return vue storybook v3', function() {
    var pjson = {
      devDependencies: {
        '@storybook/vue': '^3.0.0-alpha.0'
      }
    };
    var result = storybookCheck(pjson);
    expect(result).to.deep.equal({
      app: 'vue',
      version: 3,
      range: '^3.0.0-alpha.0'
    });
  });

  it('should return react storybook v2', function() {
    var pjson = {
      devDependencies: {
        '@kadira/storybook': '^2.35.0'
      }
    };
    var result = storybookCheck(pjson);
    expect(result).to.deep.equal({
      app: 'react',
      version: 2,
      range: '^2.35.0'
    });
  });

  it('should error when storybook not found', function() {
    var pjson = {
      dependencies: {},
      devDependencies: {}
    };
    try {
      storybookCheck(pjson);
    } catch (err) {
      expect(err.toString()).to.equal('Error: Storybook module not found in package.json');
    }
  });

  it('should error when storybook version is out of range', function() {
    var pjson = {
      devDependencies: {
        '@storybook/react': '^4.0.0'
      }
    };
    try {
      storybookCheck(pjson);
    } catch (err) {
      expect(err.toString()).to.equal('Error: Storybook version must be >= 2.17.0 and < 4.x');
    }
  });

});

@@ -30,16 +30,48 @@
 expect;%0A
+var rewire = require('rewire');%0A
 var stor
@@ -81,26 +81,25 @@
 okCheck = re
-qu
+w
 ire('../src/
@@ -180,48 +180,33 @@
 uld 
-error if there are no dependencies found
+return react storybook v3
 ', f
@@ -217,28 +217,16 @@
 ion() %7B%0A
-    try %7B%0A  
     stor
@@ -239,414 +239,137 @@
 heck
-();%0A    %7D catch (err) %7B%0A      expect(err.toString()).to.equal('Error: No dependencies
+.__set__('require', %7B%0A      resolve:
  f
-o
 un
-d in package.json');%0A    %7D%0A    try %7B%0A      storybookCheck(%7B%7D);%0A    %7D catch (err) %7B%0A      expect(err.toString()).to.equal('Error: No dependencies found in package.json');%0A    %7D%0A  %7D);%0A%0A  it('should return react storybook v3', function() %7B%0A    var pjson = %7B%0A      devDependencies: %7B%0A        '@storybook/react': '%5E3.1.3'
+ction(path) %7B%0A        if (path === '@storybook/react') %7B%0A          return true;%0A        %7D
 %0A   
@@ -370,32 +370,33 @@
  %7D%0A      %7D%0A    %7D
+)
 ;%0A    var result
@@ -405,37 +405,32 @@
  storybookCheck(
-pjson
 );%0A    expect(re
@@ -491,31 +491,8 @@
 n: 3
-,%0A      range: '%5E3.1.3'
 %0A   
@@ -563,398 +563,149 @@
     
-var pjson = %7B%0A      devDependencies: %7B%0A        '@storybook/vue': '%5E3.0.0-alpha.0'%0A      %7D%0A    %7D;%0A    var result = storybookCheck(pjson);%0A    expect(result).to.deep.equal(%7B%0A      app: 'vu
+storybookCheck.__set__('requir
 e',
+ %7B
 %0A      
-version: 3,%0A      range: '%5E3.0.0-alpha.0'%0A    %7D);%0A  %7D);%0A%0A  it('should return vue storybook v3', function() %7B%0A    var pjson = %7B%0A      devDependencies: %7B%0A        '@storybook/vue': '%5E3.0.0-alpha.0'
+resolve: function(path) %7B%0A        if (path === '@storybook/vue') %7B%0A          return true;%0A        %7D
 %0A   
@@ -706,32 +706,33 @@
  %7D%0A      %7D%0A    %7D
+)
 ;%0A    var result
@@ -741,37 +741,32 @@
  storybookCheck(
-pjson
 );%0A    expect(re
@@ -825,39 +825,8 @@
 n: 3
-,%0A      range: '%5E3.0.0-alpha.0'
 %0A   
@@ -899,85 +899,152 @@
     
-var pjson = %7B%0A      devDependencies: %7B%0A        '@kadira/storybook': '%5E2.35.0'
+storybookCheck.__set__('require', %7B%0A      resolve: function(path) %7B%0A        if (path === '@kadira/storybook') %7B%0A          return true;%0A        %7D
 %0A   
@@ -1049,24 +1049,25 @@
      %7D%0A    %7D
+)
 ;%0A    var re
@@ -1084,29 +1084,24 @@
 rybookCheck(
-pjson
 );%0A    expec
@@ -1166,32 +1166,8 @@
 n: 2
-,%0A      range: '%5E2.35.0'
 %0A   
@@ -1245,409 +1245,79 @@
     
-var pjson = %7B%0A      dependencies: %7B%7D,%0A      devDependencies: %7B%7D%0A    %7D;%0A    try %7B%0A      storybookCheck(pjson);%0A    %7D catch (err) %7B%0A      expect(err.toString()).to.equal('Error: Storybook module not found in package.json');%0A    %7D%0A  %7D);%0A%0A  it('should error when storybook version is out of range', function() %7B%0A    var pjson = %7B%0A      devDependencies: %7B%0A        '@storybook/react': '%5E4.0.0'%0A      
+storybookCheck.__set__('require', %7B%0A      resolve: function() %7B
 %7D%0A    %7D
+)
 ;%0A  
@@ -1349,13 +1349,8 @@
 eck(
-pjson
 );%0A 
@@ -1428,43 +1428,24 @@
 ook 
-version must be %3E= 2.17.0 and %3C 4.x
+module not found
 ');%0A

update tests