-
Notifications
You must be signed in to change notification settings - Fork 252
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
Feat(config): Add 'always' option to cleanTempDir #4187
Conversation
Added 'always' option to cleanTempDir Always remove stryker-tmp folder, even if stryker is failing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Love the fact that you've also updated the docs. I have some small improvement suggestions.
I'm also missing a small test addition to 'stryker-cli.spec.ts' for the "always"
value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to make the requested changes! I have some new remarks on your new code 😅. If you need more help, please let me know.
@@ -17,7 +17,7 @@ export class TemporaryDirectory implements Disposable { | |||
public static readonly inject = tokens(commonTokens.logger, commonTokens.options); | |||
constructor(private readonly log: Logger, options: StrykerOptions) { | |||
this.temporaryDirectory = path.resolve(options.tempDirName); | |||
this.removeDuringDisposal = options.cleanTempDir; | |||
this.removeDuringDisposal = typeof options.cleanTempDir === 'boolean' ? options.cleanTempDir : options.cleanTempDir == 'always' ? true : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.removeDuringDisposal = typeof options.cleanTempDir === 'boolean' ? options.cleanTempDir : options.cleanTempDir == 'always' ? true : false; | |
this.removeDuringDisposal = Boolean(options.cleanTempDir) |
This should work here, right? Seems a lot simpler.
}); | ||
|
||
describe('runMutationTest()', () => { | ||
beforeEach(() => { | ||
injectorMock = factory.injector(); | ||
loggerMock = factory.logger(); | ||
strOptions = factory.strykerOptions({ cleanTempDir: 'always' }); | ||
getLoggerStub = sinon.stub(); | ||
mutantResults = []; | ||
temporaryDirectoryMock = sinon.createStubInstance(TemporaryDirectory); | ||
prepareExecutorMock = sinon.createStubInstance(PrepareExecutor); | ||
mutantInstrumenterExecutorMock = sinon.createStubInstance(MutantInstrumenterExecutor); | ||
dryRunExecutorMock = sinon.createStubInstance(DryRunExecutor); | ||
mutationTestExecutorMock = sinon.createStubInstance(MutationTestExecutor); | ||
injectorMock.injectClass | ||
.withArgs(PrepareExecutor) | ||
.returns(prepareExecutorMock) | ||
.withArgs(MutantInstrumenterExecutor) | ||
.returns(mutantInstrumenterExecutorMock) | ||
.withArgs(DryRunExecutor) | ||
.returns(dryRunExecutorMock) | ||
.withArgs(MutationTestExecutor) | ||
.returns(mutationTestExecutorMock); | ||
injectorMock.resolve | ||
.withArgs(commonTokens.getLogger) | ||
.returns(getLoggerStub) | ||
.withArgs(coreTokens.temporaryDirectory) | ||
.returns(temporaryDirectoryMock) | ||
.withArgs(commonTokens.options) | ||
.returns(strOptions); | ||
getLoggerStub.returns(loggerMock); | ||
|
||
prepareExecutorMock.execute.resolves(injectorMock as typedInject.Injector<MutationTestContext>); | ||
mutantInstrumenterExecutorMock.execute.resolves(injectorMock as typedInject.Injector<MutationTestContext>); | ||
dryRunExecutorMock.execute.resolves(injectorMock as typedInject.Injector<MutationTestContext>); | ||
mutationTestExecutorMock.execute.resolves(mutantResults); | ||
|
||
cliOptions = {}; | ||
sut = new Stryker(cliOptions, () => injectorMock as typedInject.Injector<MutationTestContext>); | ||
}); | ||
|
||
it('should not disable `removeDuringDisposal` on the temp dir when dry run rejects and cleanTempDir is set to `always`', async () => { | ||
dryRunExecutorMock.execute.rejects(new Error('expected error for testing')); | ||
await expect(sut.runMutationTest()).rejected; | ||
expect(temporaryDirectoryMock.removeDuringDisposal).not.false; | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you recreate an entire describe
here? You should be able to just put this test in the previous describe
:
it('should not disable `removeDuringDisposal` on the temp dir when dry run rejects and cleanTempDir is set to `always`', async () => {
testInjector.options.cleanTempDir= 'always';
dryRunExecutorMock.execute.rejects(new Error('expected error for testing'));
await expect(sut.runMutationTest()).rejected;
expect(temporaryDirectoryMock.removeDuringDisposal).not.false;
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for my blunder here, removed the describe section and I have a question why this line
expect(temporaryDirectoryMock.removeDuringDisposal).not.false;
when set to
expect(temporaryDirectoryMock.removeDuringDisposal).true;
throws AssertionError: expected undefined to be true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, this is because temporaryDirectoryMock
is a mock, created on line 36. The property removeDuringDisposal
is simply never set, so it doesn't get reflected here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added a unit test for the in temporary-directory.spec.ts
: "should remove the dir if cleanTempDir option is 'always'"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank for doing that.
This 'always' option removes stryker-tmp folder irrespective of successful run or not