All files / source/test CaffeineMcTestHelper.js

100% Statements 19/19
100% Branches 0/0
100% Functions 7/7
100% Lines 17/17

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 78 79 80 81 82 83 84 85 86 87 88  3x 3x 3x                                                     3x     3x 28x 3x 24x 24x 24x   3x                                     3x 22x 22x 22x   22x 3x                                            
"use strict";
let Caf = require("caffeine-script-runtime");
Caf.defMod(module, () => {
  return Caf.importInvoke(
    [
      "BaseObject",
      "path",
      "process",
      "WorkingCache",
      "CaffeineMc",
      "Tools",
      "Metacompiler",
      "mockFs",
    ],
    [
      global,
      require("./StandardImport"),
      { path: require("path"), mockFs: require("mock-fs") },
    ],
    (
      BaseObject,
      path,
      process,
      WorkingCache,
      CaffeineMc,
      Tools,
      Metacompiler,
      mockFs
    ) => {
      let CaffeineMcTestHelper;
      return (global.CaffeineMcTestHelper = CaffeineMcTestHelper = Caf.defClass(
        class CaffeineMcTestHelper extends BaseObject {},
        function (CaffeineMcTestHelper, classSuper, instanceSuper) {
          this.classProperty({ testLog: [] });
          this.log = (str) => this.testLog.push(str);
          this.reset = () => {
            WorkingCache.resetWorkingCache();
            CaffeineMc.SourceRoots._resetSourceRoots();
            return (this.testLog = []);
          };
          this.testFiles = {
            alpha: path.join(
              process.cwd(),
              "test",
              "files",
              "SourceRoots",
              "DotCaffeineRoot",
              "HurlockAlpha.caf"
            ),
            beta: path.join(
              process.cwd(),
              "test",
              "files",
              "SourceRoots",
              "DotCaffeineRoot",
              "SubAwesome",
              "BetaRelease.caf"
            ),
          };
          this.mockFileSystem = () => {
            Tools.__preloadCoffeeScriptForTests();
            Metacompiler.getCaffeineScript();
            return mockFs(this.initialFs);
          };
          this.unmockFileSystem = () => mockFs.restore();
          this.initialFs = {
            test: {
              files: {
                "MyCompiler.caffeine":
                  "|coffee-script:\n  {Parser} = require 'babel-bridge'\n  {compactFlatten} = require 'art-standard-lib'\n\n  class MyParser extends Parser\n    @rule\n      root:\n        pattern: 'word+ _?'\n        node: toJs: -> (w.toWord() for w in @words).join ', '\n\n      word:\n        pattern: '_? wordRegExp'\n        node: toWord: -> @wordRegExp.toString()\n\n      wordRegExp: /[^s]+/\n      _: /s+/\n\n  @compiler = compile: (source) ->\n    myParser = new MyParser\n    root = myParser.parse source\n    compiled: js: \"module.exports = '#{root.toJs()}'\"\n\nthis is how it should work!",
                SourceRoots: {
                  DotCaffeineRoot: {
                    SubAwesome: { "BetaRelease.caf": "b.caf ran" },
                    "caffeine-mc.config.caf":
                      '|CoffeeScript\n  CoffeeScript = require \'coffee-script\'\n  path = require \'path\'\n  {formattedInspect} = require \'art-standard-lib\'\n  CaffeineMcTestHelper.log "caffeine-mc.config.caf loaded"\n\n  @compiler = class ItWorkedCompiler\n    @version: "1.2.3"\n    @compile: (source, options) ->\n      {sourceFile, mySpecialConfig} = options\n      CaffeineMcTestHelper.log "caffeine-mc.config.caf custom compiler used on: #{path.basename sourceFile}, mySpecialConfig: #{formattedInspect mySpecialConfig}"\n      CoffeeScript.compile source, options\n\nCaffeineMcTestHelper.log "caffeine-mc.config.caf ran"\nmodule.exports = mySpecialConfig: "worked!"',
                    "HurlockAlpha.caf": "a.caf ran",
                  },
                  "DotCaffeineRootPeer.caf": "",
                },
              },
            },
          };
        }
      ));
    }
  );
});