Giter Site home page Giter Site logo

Comments (4)

theKashey avatar theKashey commented on June 15, 2024

Cannot read properties of undefined (reading 'filename')

Can you please provide a more complete callstack.


What would change if you do rewiremock.overrideEntryPoint(module); before anything else?

In any case there is no recommendation to extract mocking of one file to a "setup" file, it was only to setup your unique configuration if present.
Would you consider automocking as a solution for azure-pipelines-task-lib?

from rewiremock.

Xerillio avatar Xerillio commented on June 15, 2024

@theKashey, here's the stacktrace:

TypeError: Cannot read properties of undefined (reading 'filename')
    at getModuleName (F:\coding\repos\azure-devops-pr-commentator\node_modules\rewiremock\lib\utils\modules.js:10:24)
    at Function.mockLoader [as _load] (F:\coding\repos\azure-devops-pr-commentator\node_modules\rewiremock\lib\executor.js:275:84)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
    at async formattedImport (F:\coding\repos\azure-devops-pr-commentator\node_modules\mocha\lib\nodejs\esm-utils.js:9:14)
    at async exports.requireOrImport (F:\coding\repos\azure-devops-pr-commentator\node_modules\mocha\lib\nodejs\esm-utils.js:42:28)
    at async exports.loadFilesAsync (F:\coding\repos\azure-devops-pr-commentator\node_modules\mocha\lib\nodejs\esm-utils.js:100:20)
    at async singleRun (F:\coding\repos\azure-devops-pr-commentator\node_modules\mocha\lib\cli\run-helpers.js:125:3)
    at async exports.handler (F:\coding\repos\azure-devops-pr-commentator\node_modules\mocha\lib\cli\run.js:370:5)

Moving the overrideEntryPoint call up produces a completely identical stacktrace:

import rewiremock from "rewiremock";
import * as sinon from "sinon";

rewiremock.overrideEntryPoint(module);

export const testInputs = new Map<string, any>();

rewiremock("azure-pipelines-task-lib")
    .with({
        getInput: sinon.stub().callsFake((i: string) => testInputs.get(i)),
        getInputRequired: sinon.stub().callsFake((i: string) => testInputs.get(i)),
        getBoolInput: sinon.stub().callsFake((i: string) => testInputs.get(i))
    });
rewiremock.enable();

I'll definitely take a look at automocking, thanks for suggesting that - I found the README a bit overwhelming so I didn't see that option 😅

from rewiremock.

Xerillio avatar Xerillio commented on June 15, 2024

@theKashey Just to make sure I'm not getting it wrong. If I want to mock a node module it currently doesn't work with automocking because of #121, right? Since it only looks for the __mocks__ folder inside a subfolder of node_modules - at least that's what my attempt at using that approach shows.

from rewiremock.

theKashey avatar theKashey commented on June 15, 2024

🤦 you are absolutely correct

from rewiremock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.