async.test.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. const test = require('tap').test;
  2. const almostEqual = require("./almost-equal.js");
  3. const CephesWrapper = require('../cephes-wrapper.js');
  4. test("not waiting fails in async mode", function (t) {
  5. const cephes = new CephesWrapper(false); // async mode
  6. t.throws(() => cephes._cephes_exp(2), 'cephes._cephes_exp is not a function');
  7. t.end();
  8. });
  9. test("waiting works in async mode", async function (t) {
  10. const cephes = new CephesWrapper(false); // async mode
  11. await cephes.compiled;
  12. almostEqual(t, cephes._cephes_exp(2), Math.exp(2));
  13. t.end();
  14. });
  15. test("waiting is optional when in sync mode", async function (t) {
  16. const cephes = new CephesWrapper(true); // sync mode
  17. await cephes.compiled;
  18. almostEqual(t, cephes._cephes_exp(2), Math.exp(2));
  19. t.end();
  20. });
  21. test("cephes-browser.js is cephes in async mode", async function (t) {
  22. const cephes = require('../cephes-browser.js');
  23. t.throws(() => cephes._cephes_exp(2), 'cephes._cephes_exp is not a function');
  24. await cephes.compiled;
  25. almostEqual(t, cephes._cephes_exp(2), Math.exp(2));
  26. t.end();
  27. });