All files / Sources/Testing setupTestEnv.js

96.77% Statements 30/31
80% Branches 8/10
100% Functions 8/8
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77                                    1x 1x 1x 1x   1x 3809x 211x 211x 211x 3807x   211x 1x           1x 3807x 3807x 3807x       1x 1x 1x 1x             1x 1x 1x     1x               1x 1x 3807x   1x   1x      
import test from 'tape';
 
// Load default classes for tests
import '../IO/Core/DataAccessHelper/HtmlDataAccessHelper';
import '../IO/Core/DataAccessHelper/HttpDataAccessHelper';
import '../IO/Core/DataAccessHelper/JSZipDataAccessHelper';
 
// Load the rendering pieces we want to use (for both WebGL and WebGPU)
import '../Rendering/Profiles/All';
 
/**
 * Buffers written objects until a reader attaches,
 * after which all writes go to the reader.
 *
 * Only supports a single reader.
 *
 */
function BufferedObjectPipe() {
  const buffer = [];
  let closed = false;
  let reader = null;
  let flushTimeout = null;
 
  const scheduleFlush = () => {
    if (reader && flushTimeout === null) {
      flushTimeout = setTimeout(() => {
        flushTimeout = null;
        while (buffer.length) {
          reader.onData(buffer.shift());
        }
        if (closed) {
          reader.onClose();
        }
      }, 0);
    }
  };
 
  const write = (data) => {
    if (!closed) {
      buffer.push(data);
      scheduleFlush();
    }
  };
 
  const end = () => {
    Iif (closed) return;
    closed = true;
    scheduleFlush();
  };
 
  /**
   * Called when karma is loaded in browser.
   * @param {*} reader
   */
  const setReader = (r) => {
    reader = r;
    scheduleFlush();
  };
 
  return {
    write,
    end,
    setReader,
  };
}
 
// pipe tape objects to karma adapter in tap-object-stream
const pipe = BufferedObjectPipe();
test.createStream({ objectMode: true }).on('data', (row) => {
  pipe.write(row);
});
test.onFinish(() => pipe.end());
 
window.__TapeEnv__ = {
  pipe,
};