worker-spec.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* spec tests gl-matrix when embedded into a Web Worker */
  2. // only test with workers if workers are available
  3. if (typeof(Worker) !== 'undefined') {
  4. describe("Embedded within Web Workers", function() {
  5. it("should initialize successfully", function() {
  6. let xhr = new XMLHttpRequest();
  7. let source = null;
  8. xhr.onreadystatechange = function() {
  9. if (this.readyState == this.DONE) {
  10. if (this.status == 200) {
  11. source = this.responseText;
  12. }
  13. }
  14. };
  15. xhr.open("GET", "/dist/gl-matrix-min.js");
  16. xhr.send();
  17. let result = null;
  18. waitsFor(function() {
  19. if (!source) return false;
  20. let blob = new Blob([
  21. source,
  22. "self.postMessage(vec3.create());"
  23. ],
  24. {type: "application/javascript"}
  25. );
  26. let worker = new Worker(URL.createObjectURL(blob));
  27. worker.onmessage = function(e) {
  28. result = e.data;
  29. };
  30. return true;
  31. });
  32. waitsFor(function() {
  33. if (!result) return false;
  34. expect(result).toBeEqualish([0, 0, 0]);
  35. return true;
  36. });
  37. });
  38. });
  39. }