Skip to content

Windows: fakeload fails to match due to case differences in path #83

@cwienands1

Description

@cwienands1

I discovered this issue in Quibble 0.6.14 on my Windows developer machine.

I wrote a test case that is supposed to fake an inner dependency, like this:

// logic.js
const lwa = require("./login-with-aws"); // a local js file

module.exports.login = async (request, reply) => {
    return await lwa.retrieveProfile(request.body.accessToken);
};

// test-logic.js
let lwa;
let logic;

describe("handler", () => {
    beforeEach(async () => {
        lwa = td.replace("../src/login-with-aws");
        logic = require("../src/logic");
    });

    it("should login", async () => {
        td.when(lwa.retrieveProfile(td.matchers.anything())).thenResolve({ user_id: "xyz" });
        const profile = await logic.login({ body: { accessToken: "1234" } });
        console.log(profile);
    });
});

When logic executes, it does not use a fake/stub but the real implementation. I tracked the problem down to the following...

The require("./login-with-aws") call from logic.js eventually reaches the fakeload() method in quibble.js. After the quibble.absolutify() call, the path looks like this: C:\\Home\\my-project\\src\\logic.js
Note the upper-case drive and folder names.

Inside stubbingThatMatchesRequest(), the stubbedPath variable starts with a lower-case drive letter, though, like c:\\Home\\my-project\\src\\login-with-aws.js, and therefore the fake/stub lookup fails. A quick fix for this problem looks like this...

var stubbingThatMatchesRequest = function (request) {
  request = request.toLowerCase();
  return _.ooFind(quibbles, function (stubbing, stubbedPath) {
    if (request === stubbedPath.toLowerCase()) return true
    if (nodeResolve(request) === stubbedPath) return true
  }, quibbles)
}

...but 1) this is ugly and probably the quibbles keys should already be added in lower-case format, 2) my quick and dirty fix could result in issues on Linux, which has a case-sensitive file system, and 3) there are probably more platform (Windows) specific issues in quibble, as I came across some strange behavior of testdouble, too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions