Skip to content

Commit

Permalink
Restore callerDependency to it's original state. Create a mock caller…
Browse files Browse the repository at this point in the history
…Dependency and add mockery to handle properly requiring the mock instead of the original callerDependency.
  • Loading branch information
drewpc committed Jan 18, 2017
1 parent 9070f45 commit c749a76
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
1 change: 0 additions & 1 deletion packages/react-server-cli/gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ gulp.task("eslint", [], () => {
});

gulp.task("test", ["default", "eslint"], () => {
process.env.NODE_ENV = "__react-server-cli-unit-test__"; // eslint-disable-line no-process-env
return gulp.src(getSpecGlob("target/__tests__/**/"))
.pipe(jasmine({}));
});
Expand Down
1 change: 1 addition & 0 deletions packages/react-server-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"gulp-eslint": "^3.0.1",
"gulp-jasmine": "^2.4.2",
"memory-stream": "0.0.3",
"mockery": "^2.0.0",
"nsp": "^2.6.2",
"react-hot-loader": "^1.3.1",
"react-server-gulp-module-tagger": "^0.4.10",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import fs from "fs";
const MemoryStream = require('memory-stream');
import path from "path";

import { writeWebpackCompatibleRoutesFile } from "../../compileClient";
import mockery from "mockery";

describe("compileClient", () => {
let mockFs;
let mockFs,
writeWebpackCompatibleRoutesFile;

beforeAll(() => {
mockery.registerSubstitute('./callerDependency', './callerDependency-Mock');
mockery.enable({
useCleanCache: true,
warnOnUnregistered: false,
});

writeWebpackCompatibleRoutesFile = require("../../compileClient").writeWebpackCompatibleRoutesFile;
});

afterAll(() => {
mockery.disable();
});

describe("writes client routes file for Webpack", () => {
const pathStringTests = [
Expand Down
8 changes: 8 additions & 0 deletions packages/react-server-cli/src/callerDependency-Mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import lookup from "look-up";
import path from "path";

export default function callerDependency(dep) {
// TODO: We should grab stuff based on what the routes file would get out
// of `require.resolve(dep)`. Using `process.cwd()` instead for now.
return lookup("packages/" + dep, {cwd: path.resolve(process.cwd() + '/..')});
}
13 changes: 2 additions & 11 deletions packages/react-server-cli/src/callerDependency.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import lookup from "look-up";
import path from "path";

// NOTE: if this function changes, make sure it also changes in the 'callerDependency-Mock.js' file as well.
export default function callerDependency(dep) {
// TODO: We should grab stuff based on what the routes file would get out
// of `require.resolve(dep)`. Using `process.cwd()` instead for now.
let cwd = process.cwd(),
lookupResult;

if (process.env.NODE_ENV === '__react-server-cli-unit-test__') { // eslint-disable-line no-process-env
cwd = path.resolve(cwd + '/..');
lookupResult = lookup("packages/" + dep, {cwd: cwd});
} else {
lookupResult = lookup("node_modules/" + dep, {cwd: cwd});
}
return lookupResult;
return lookup("node_modules/" + dep, {cwd: process.cwd()});
}

0 comments on commit c749a76

Please sign in to comment.