import sinon from 'sinon';
import chai from 'chai';
const expect = chai.expect;
import * as fetch from '../../../../src/functions/fetch.js';
import checkMinifiedJs from '../../../../src/html/js/minify';

describe('html', function() {
  describe('test minify promise', function() {
    let sandbox;

    beforeEach(function() {
      sandbox = sinon.sandbox.create();
    });

    afterEach(function() {
      sandbox.restore();
    });

    it('should return original URL even if JS is not minified', () => {
      const result = {
        body: 'function something(text) { console.log("not minified javascript file"); }',
      };

      sandbox.stub(fetch, 'fetch').returns(result);

      return new Promise((resolve, reject) => {
          resolve('https://www.juffalow.com/jsfile.js');
        })
        .then(checkMinifiedJs)
        .then((url) => {
          expect(url).to.equal('https://www.juffalow.com/jsfile.js');
        });
    });
  });
});

@@ -518,220 +518,559 @@
 nst 
-result = %7B%0A        body: 'function something(text) %7B console.log(%22not minified javascript file%22); %7D',%0A      %7D;%0A%0A      sandbox.stub(fetch, 'fetch').returns(result);%0A%0A      return new Promise((resolve, reject) =%3E %7B
+html = %7B%0A        body: '%3Chtml%3E%3Chead%3E%3Clink rel=%22stylesheet%22 href=%22https://juffalow.com/cssfile.css%22 /%3E%3C/head%3E%3Cbody%3E%3Cp%3EText%3C/p%3E%3Ca href=%22#%22%3Elink%3C/a%3E%3Cscript src=%22https://juffalow.com/jsfile.js%22%3E%3C/script%3E%3C/body%3E%3C/html%3E',%0A      %7D;%0A%0A      const result = %7B%0A        body: 'function something(text) %7B console.log(%22not minified javascript file%22); %7D',%0A        response: %7B%0A          statusCode: 200,%0A        %7D,%0A      %7D;%0A%0A      sandbox.stub(fetch, 'fetch').callsFake((url) =%3E %7B%0A        switch (url) %7B%0A          case 'https://juffalow.com/':%0A            return html;
 %0A   
@@ -1080,16 +1080,13 @@
     
-resolve(
+case 
 'htt
@@ -1082,36 +1082,32 @@
   case 'https://
-www.
 juffalow.com/jsf
@@ -1105,33 +1105,59 @@
 w.com/jsfile.js'
-)
+:%0A            return result
 ;%0A        %7D)%0A   
@@ -1155,39 +1155,72 @@
    %7D
-)
 %0A      
-  .then(checkMinifiedJs
+%7D);%0A%0A      return checkMinifiedJs('https://juffalow.com/'
 )%0A  
@@ -1232,19 +1232,23 @@
  .then((
-url
+results
 ) =%3E %7B%0A 
@@ -1267,58 +1267,148 @@
 ect(
-url).to.equal('https://www.juffalow.com/jsfile.js'
+results.length).to.equal(1);%0A          expect(results%5B0%5D.messages.length).to.equal(0);%0A          expect(results%5B0%5D.errors.length).to.equal(1
 );%0A 

Fix js minify promise test