Comments (4)
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.
@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.
@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.
🤦 you are absolutely correct
from rewiremock.
Related Issues (20)
- Documentation Needed: jest.mock Equivalent HOT 1
- Please add a test for a module that returns a Class that gets newed up by the SUT HOT 1
- Something like cache problem HOT 3
- Testing a private function using rewiremock HOT 2
- Mocking non existent modules HOT 4
- how to use in webpack5
- Angular 11
- Usage inquiry ES6 HOT 1
- webpack.NamedModulesPlugin() has been deprecated HOT 12
- Configuration for Mocha/webpack5 HOT 1
- nodejs v18.3.0 Error: Rewiremock: there is no "parent module". Is there two HotModuleReplacementPlugins? HOT 3
- Typescript setup Error: Rewiremock: there is no "parent module". Is there two HotModuleReplacementPlugins?
- Mock called, but not stubbing dependency HOT 2
- Invoking 'proxy' to generate test object but stub not invoked HOT 3
- Is it enable can execute like a jest.mock? HOT 3
- Does rewiremock work with ts-node? HOT 3
- Question: Mocking local variable in the scope of original module HOT 1
- Ts-node and rewiremock HOT 2
- Mocking external module import HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rewiremock.