# All files / src/utils test-utils.js

100% Statements 13/13
100% Branches 0/0
100% Functions 3/3
100% Lines 12/12

    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
    452x
    2x
    2x

    2x
    2x
    2x
    2x
    2x

    2x

    13x

    13x

    2x

     import { link } from "walt-link";
    import { getText } from "../utils/string";
    import {
      mapNode,
      walkNode,
      parser,
      semantics,
      validate,
      emitter,
      generator,
      prettyPrintNode,
    } from "..";

    export const harness = filepath => t => {
      const memory = new WebAssembly.Memory({ initial: 1 });
      const view = new DataView(memory.buffer);
      const decodeText = getText(view);
      const build = link(
        filepath,
        { logger: console },
        {
          mapNode,
          walkNode,
          parser,
          semantics,
          validate,
          emitter,
          generator,
          prettyPrintNode,
        }
      );
      return build({
        env: {
          memory,
          MEMORY_OFFSET: 0,
          log: console.log,
          assert(strPointer, value, expected) {
            const text = decodeText(strPointer);

            t.is(value, expected, text);
          },
        },
      }).then(module => module.instance.exports.run());
    };