import fs from "fs";
import path from "path";
import gql from "graphql-tag";
import { TruffleDB } from "truffle-db";
import * as Contracts from "truffle-workflow-compile";

jest.mock("truffle-workflow-compile", () => ({
 compile: function(config, callback) {
   const magicSquare= require(path.join(__dirname,"..", "artifacts", "test", "sources", "MagicSquare.json"));
   const migrations = require(path.join(__dirname, "..", "artifacts", "test", "sources", "Migrations.json"));
   const squareLib = require(path.join(__dirname, "..", "artifacts", "test", "sources", "SquareLib.json"));
   callback(null, {
     "contracts": [{
       "contract_name": "MagicSquare",
       ...magicSquare
     },
     {
       "contract_name": "Migrations",
       ...migrations
     },
     {
       "contract_name": "SquareLib",
       ...squareLib
     }
     ]
   });
 }
}));

const fixturesDirectory = path.join(__dirname, "..", "artifacts", "test");

// minimal config
const config = {
  contracts_build_directory: path.join(fixturesDirectory, "sources"),
  contracts_directory: path.join(fixturesDirectory, "compilationSources"),
  all: true
};

const db = new TruffleDB(config);

const Load = gql `
  mutation LoadArtifacts {
    loaders {
      artifactsLoad {
        success
      }
    }
  }
`

it("loads artifacts and returns true ", async () => {
  const {
    data: {
      loaders: {
        artifactsLoad: {
          success
        }
      }
    }
  } = await db.query(Load);
  expect(success).toEqual(true);
});

import fs from "fs";
import path from "path";
import gql from "graphql-tag";

import { TruffleDB } from "truffle-db";


const fixturesDirectory = path.join(__dirname, "..", "artifacts", "test");

// minimal config
const config = {
  contracts_build_directory: path.join(fixturesDirectory, "build"),
  contracts_directory: path.join(fixturesDirectory, "compilationSources"),
  all: true
};

const db = new TruffleDB(config);

const  Build = require(path.join(fixturesDirectory, "build", "SimpleStorage.json"));

const Load = gql `
  mutation LoadArtifacts {
    loaders {
      artifactsLoad {
        success
      }
    }
  }
` 

it("loads artifacts and returns true ", async () => {
  const {
    data: {
      loaders: {
        artifactsLoad: {
          success
        }
      }
    }
  } = await db.query(Load);
  expect(success).toEqual(true); 
});

--- 
+++ 
@@ -1,22 +1,42 @@
 import fs from "fs";
 import path from "path";
 import gql from "graphql-tag";
+import { TruffleDB } from "truffle-db";
+import * as Contracts from "truffle-workflow-compile";
 
-import { TruffleDB } from "truffle-db";
-
+jest.mock("truffle-workflow-compile", () => ({
+ compile: function(config, callback) {
+   const magicSquare= require(path.join(__dirname,"..", "artifacts", "test", "sources", "MagicSquare.json"));
+   const migrations = require(path.join(__dirname, "..", "artifacts", "test", "sources", "Migrations.json"));
+   const squareLib = require(path.join(__dirname, "..", "artifacts", "test", "sources", "SquareLib.json"));
+   callback(null, {
+     "contracts": [{
+       "contract_name": "MagicSquare",
+       ...magicSquare
+     },
+     {
+       "contract_name": "Migrations",
+       ...migrations
+     },
+     {
+       "contract_name": "SquareLib",
+       ...squareLib
+     }
+     ]
+   });
+ }
+}));
 
 const fixturesDirectory = path.join(__dirname, "..", "artifacts", "test");
 
 // minimal config
 const config = {
-  contracts_build_directory: path.join(fixturesDirectory, "build"),
+  contracts_build_directory: path.join(fixturesDirectory, "sources"),
   contracts_directory: path.join(fixturesDirectory, "compilationSources"),
   all: true
 };
 
 const db = new TruffleDB(config);
-
-const  Build = require(path.join(fixturesDirectory, "build", "SimpleStorage.json"));
 
 const Load = gql `
   mutation LoadArtifacts {
@@ -26,7 +46,7 @@
       }
     }
   }
-` 
+`
 
 it("loads artifacts and returns true ", async () => {
   const {
@@ -38,5 +58,5 @@
       }
     }
   } = await db.query(Load);
-  expect(success).toEqual(true); 
+  expect(success).toEqual(true);
 });
Add mocking of manual compilation to loader test file
