-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup for multiple test files #144
Comments
Can you please provide a more complete callstack. What would change if you do 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. |
* Changed `rewire.ts` to provide helper methods instead of rewiring directly in the global scope which seemed to cause issues. See theKashey/rewiremock#144. * Added NPM package `nyc` to provide coverage reports. Use `npm run coverage`. * Improved coverage of `Inputs`.
@theKashey, here's the stacktrace:
Moving the 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 😅 |
@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 |
🤦 you are absolutely correct |
I started using this library for a single test file using Mocha to run the tests with
mocha ./bin/tests/**/*.test.js
- all good. Then I wanted to add tests in another file and suddenly I got an error message similar to the one described in #96 :The README suggests putting the rewiring in a common file that all tests can use instead of a per-test-file rewiring, so this was my
rewire.ts
:This starts failing even if I add a new empty
*.test.ts
file, while having only one*.test.ts
file works fine. Perhaps this is a duplicate of #96, but if not, how is it recommend to set up a test project with multiple test files?What I have now as a workaround for the above issue:
This boilerplate with
before
,after
andcreateSut
would be duplicated in each test file.The text was updated successfully, but these errors were encountered: