Skip to content
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

Merged
merged 6 commits into from
May 20, 2023

Conversation

adeelpm
Copy link
Contributor

@adeelpm adeelpm commented May 13, 2023

This 'always' option removes stryker-tmp folder irrespective of successful run or not

Verified

This commit was signed with the committer’s verified signature.
provinzkraut Janek Nouvertné
Added 'always' option to cleanTempDir

Always remove stryker-tmp folder, even if stryker is failing
@adeelpm adeelpm linked an issue May 15, 2023 that may be closed by this pull request
Copy link
Member

@nicojs nicojs left a 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.

adeelpm and others added 3 commits May 18, 2023 20:17

Verified

This commit was signed with the committer’s verified signature.
provinzkraut Janek Nouvertné

Verified

This commit was signed with the committer’s verified signature.
provinzkraut Janek Nouvertné
Review Changes

Verified

This commit was signed with the committer’s verified signature.
provinzkraut Janek Nouvertné
Copy link
Member

@nicojs nicojs left a 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines 203 to 249
});

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;
});
});
Copy link
Member

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;
    });

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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'"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for doing that.

adeelpm and others added 2 commits May 20, 2023 20:55

Verified

This commit was signed with the committer’s verified signature.
provinzkraut Janek Nouvertné
Review Changes

Verified

This commit was signed with the committer’s verified signature.
provinzkraut Janek Nouvertné
@nicojs nicojs enabled auto-merge (squash) May 20, 2023 16:17
@nicojs nicojs merged commit f02efb2 into stryker-mutator:master May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Always remove stryker-tmp folder, even if stryker is failing
2 participants