import Oasis from "oasis";
import webworkerAdapter from "oasis/webworker_adapter";

module('Webworker Sandboxes', {
  setup: function() {
    Oasis.reset();
  }
});

test("throws an error if the sandbox type is html", function() {
  raises(function() {
    Oasis.createSandbox({
      url: "fixtures/html_sandbox.html",
      type: 'html',
      adapter: webworkerAdapter,
      capabilities: ['assertions'],
      services: {
        assertions: Oasis.Service
      }
    });
  }, Error, "Creating a sandbox with type: html but adapter: webworker fails.");
});

test("The workers are uniquely named to improve debugging", function() {
  Oasis.register({
    url: "fixtures/index.js",
    capabilities: []
  });

  var sandbox1, sandbox2;

  sandbox1 = Oasis.createSandbox({
    adapter: webworkerAdapter,
    url: 'fixtures/index.js'
  });
  sandbox1.start();

  sandbox2 = Oasis.createSandbox({
    adapter: webworkerAdapter,
    url: 'fixtures/index.js'
  });
  sandbox2.start();

  ok( sandbox1.worker.name !== sandbox2.worker.name, 'The workers have a unique name');
  ok( /fixtures\/index.js/.test( sandbox1.worker.name ), 'The worker name contains the url' );
});

@@ -77,16 +77,38 @@
 pter%22;%0A%0A
+if( this.Worker ) %7B%0A  
 module('
@@ -131,16 +131,18 @@
 xes', %7B%0A
+  
   setup:
@@ -155,24 +155,26 @@
 ion() %7B%0A    
+  
 Oasis.reset(
@@ -182,15 +182,21 @@
 ;%0A  
-%7D%0A
+  %7D%0A  
 %7D);%0A%0A
+  
 test
@@ -256,16 +256,18 @@
 ion() %7B%0A
+  
   raises
@@ -276,24 +276,26 @@
 unction() %7B%0A
+  
     Oasis.cr
@@ -310,24 +310,26 @@
 box(%7B%0A      
+  
 url: %22fixtur
@@ -357,16 +357,18 @@
 ,%0A      
+  
 type: 'h
@@ -373,16 +373,18 @@
 'html',%0A
+  
       ad
@@ -410,24 +410,26 @@
 pter,%0A      
+  
 capabilities
@@ -452,16 +452,18 @@
 ,%0A      
+  
 services
@@ -466,16 +466,18 @@
 ices: %7B%0A
+  
         
@@ -512,18 +512,22 @@
     
-%7D%0A
+  %7D%0A  
     %7D);%0A
   %7D,
@@ -522,16 +522,18 @@
     %7D);%0A
+  
   %7D, Err
@@ -605,21 +605,25 @@
 ils.%22);%0A
+  
 %7D);%0A%0A
+  
 test(%22Th
@@ -687,16 +687,18 @@
 ion() %7B%0A
+  
   Oasis.
@@ -708,24 +708,26 @@
 ister(%7B%0A    
+  
 url: %22fixtur
@@ -740,24 +740,26 @@
 ex.js%22,%0A    
+  
 capabilities
@@ -763,23 +763,27 @@
 ies: %5B%5D%0A
+  
   %7D);%0A%0A
+  
   var sa
@@ -801,16 +801,18 @@
 dbox2;%0A%0A
+  
   sandbo
@@ -830,32 +830,34 @@
 createSandbox(%7B%0A
+  
     adapter: web
@@ -867,32 +867,34 @@
 kerAdapter,%0A    
+  
 url: 'fixtures/i
@@ -894,38 +894,42 @@
 tures/index.js'%0A
+  
   %7D);%0A
+  
   sandbox1.start
@@ -933,16 +933,18 @@
 art();%0A%0A
+  
   sandbo
@@ -970,24 +970,26 @@
 ndbox(%7B%0A    
+  
 adapter: web
@@ -999,24 +999,26 @@
 kerAdapter,%0A
+  
     url: 'fi
@@ -1034,22 +1034,26 @@
 dex.js'%0A
+  
   %7D);%0A
+  
   sandbo
@@ -1065,16 +1065,18 @@
 art();%0A%0A
+  
   ok( sa
@@ -1155,16 +1155,18 @@
 name');%0A
+  
   ok( /f
@@ -1252,12 +1252,16 @@
 url' );%0A
+  
 %7D);%0A
+%7D%0A

Test web workers only when supported by the browser