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

feature(stryker): #336 Configurable tmp folder location #475

Closed
wants to merge 6 commits into from

Conversation

avassem85
Copy link
Contributor

No description provided.

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.

Looks good! I still have some remarks.

Also: how do we prevent a user from using an absolute path? Using an absolute path (for example /tmp/dir/) breaks mocha tests, however it would not break karma tests.

Do we want to prevent users from configuring an absolute path? @simondel maybe you have an opion on this?


#### Temporary folder
**Command line:** `--tempFolder .stryker-tmp`
**Config file:** `logLevel: '.stryker-tmp'`
Copy link
Member

Choose a reason for hiding this comment

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

Still refers to logLevel here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -47,6 +47,7 @@ export default class StrykerCli {
.option('--timeoutFactor <number>', 'Tweak the standard deviation relative to the normal test run of a mutated test', parseFloat)
.option('--maxConcurrentTestRunners <n>', 'Set the number of max concurrent test runner to spawn (default: cpuCount)', parseInt)
.option('--logLevel <level>', 'Set the log4js log level. Possible values: fatal, error, warn, info, debug, trace, all and off. Default is "info"')
.option('--tempFolder <name>', 'Set name of the folder that contains temporary files')
Copy link
Member

Choose a reason for hiding this comment

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

Should we call it tempFolder or tempDir (or tempDirectory). I think tempDir is more clear, we should always refer to directory instead of folder.

Copy link
Member

Choose a reason for hiding this comment

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

I think tempDir is better. But if we change it we should also change the TempFolder class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to tempDir

@@ -15,6 +15,7 @@ export class TempFolder {
initialize(tempDirName = '.stryker-tmp') {
Copy link
Member

Choose a reason for hiding this comment

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

This variable tempDirName should not have a default value, as this is a duplicate from the Config class.


expect(fileUtils.deleteDir).to.have.been.calledWith(
tempFolderInstance.baseTempFolder
);

result.then(data => expect(data).equals('delResolveStub'));
expect(result).equals('delResolveStub');
Copy link
Member

Choose a reason for hiding this comment

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

This is better indeed 👍

**Default value:** `.stryker-tmp`
**Mandatory**: no
**Description:**
Set name of the folder that contains temporary files
Copy link
Member

Choose a reason for hiding this comment

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

I think it's smart to mention that stryker will attempt to delete this folder after it's done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -47,6 +47,7 @@ export default class StrykerCli {
.option('--timeoutFactor <number>', 'Tweak the standard deviation relative to the normal test run of a mutated test', parseFloat)
.option('--maxConcurrentTestRunners <n>', 'Set the number of max concurrent test runner to spawn (default: cpuCount)', parseInt)
.option('--logLevel <level>', 'Set the log4js log level. Possible values: fatal, error, warn, info, debug, trace, all and off. Default is "info"')
.option('--tempFolder <name>', 'Set name of the folder that contains temporary files')
Copy link
Member

Choose a reason for hiding this comment

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

I think tempDir is better. But if we change it we should also change the TempFolder class.

@simondel
Copy link
Member

@nicojs Why would an absolute path break mocha?

@avassem85
Copy link
Contributor Author

@simondel Because mocha uses Require that search node_modules up in the directories of the application. When the temp folder is not within the root of the application is will fail.

@avassem85 avassem85 self-assigned this Nov 27, 2017
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.

Some small cosmetic remarks.

@@ -19,6 +19,7 @@ export default class Config implements StrykerOptions {
mutator: string = 'es5';
transpilers: string[] = [];
maxConcurrentTestRunners: number = Infinity;
tempFolder: string = '.stryker-tmp';
Copy link
Member

Choose a reason for hiding this comment

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

This also needs to be renamed to tempDir

@@ -1,74 +0,0 @@
import * as fs from 'mz/fs';
Copy link
Member

Choose a reason for hiding this comment

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

Good catch! Removing code makes me happy

**Default value:** `.stryker-tmp`
**Mandatory**: no
**Description:**
Set name of the folder that contains temporary files
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this a little more descriptive. Something like:

Set the name of the directory that is used by Stryker as a working directory. This directory is used to keep copies of your files that are used by Stryker to mutate your code safely. This directory will be cleaned after a successful run. Warning! If you configure an absolute path (for example /tmp/stryker), node-based test runners like mocha will fail, because your node_modules cannot be loaded. Use with caution.

@@ -47,6 +47,7 @@ export default class StrykerCli {
.option('--timeoutFactor <number>', 'Tweak the standard deviation relative to the normal test run of a mutated test', parseFloat)
.option('--maxConcurrentTestRunners <n>', 'Set the number of max concurrent test runner to spawn (default: cpuCount)', parseInt)
.option('--logLevel <level>', 'Set the log4js log level. Possible values: fatal, error, warn, info, debug, trace, all and off. Default is "info"')
.option('--tempDir <name>', 'Set name of the folder that contains temporary files. Stryker will try to remove the content when the tests ran')
Copy link
Member

Choose a reason for hiding this comment

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

Let's also update this one. Something like:

"Set the name of the directory that is used by Stryker as a working directory. This directory will be cleaned after a successful run. "

@nicojs
Copy link
Member

nicojs commented Nov 28, 2017

Only the deepest directory is deleted. Is this acceptable?
image

Also it will be deleted regardless of any other data in the directory. So if you would point it to '/', your entire computer will be wiped clean after a successful run.

@avassem85
Copy link
Contributor Author

@nicojs

  1. If you delete more than the deepest directory you could end up deleting to much (temporary locations for other tools)
  2. You can't accidentally delete root(/) because the directory is always relative from the root of your project

@nicojs
Copy link
Member

nicojs commented Nov 28, 2017

You can't accidentally delete root(/) because the directory is always relative from the root of your project

Well... i could incidentally use tempDir: '../../../../../'

@avassem85
Copy link
Contributor Author

@nicojs true, but what do you want to do about it?

@nicojs
Copy link
Member

nicojs commented Dec 6, 2017

@nicojs true, but what do you want to do about it?

Well.. Maybe we could clean the directory first. Remove all sandbox sub directories. If the directory is empty after that, we can remove it safely.

To remove all sandbox sub directories, we can just use rimraf and give it the pattern: '.stryker-tmp/sandbox*'. Also i've noticed that we are creating a temp folder within the temp folder. I don't know why. I'm talking about this line: https://github.com/stryker-mutator/stryker/blob/24699e16e9c3c8ea77ecb52f4f1b6a8729ac5306/packages/stryker/src/utils/TempDir.ts#L17

I think we can safely remove that.

@simondel simondel added this to Review in Backlog Jan 10, 2018
@nicojs
Copy link
Member

nicojs commented May 11, 2018

This PR is stale. Closing for now, please create a new PR.

@nicojs nicojs closed this May 11, 2018
Backlog automation moved this from Review to Done May 11, 2018
@ghost ghost removed the 🔎 Needs review label May 11, 2018
@nicojs nicojs deleted the config-temp-dir branch July 4, 2018 06:29
@brunoqueiros
Copy link
Contributor

brunoqueiros commented Jul 12, 2019

any plans to implement the configurable tempFolder? @nicojs

@nicojs
Copy link
Member

nicojs commented Jul 15, 2019

We've got lot of plans 😅

This is pretty easy to solve if we can simply give it another name. If you want support for it inside your OS temp folder it will take some more time. What would you prefer?

@brunoqueiros
Copy link
Contributor

I was thinking something similar with this PR where you just specify another name inside the project itself. —tempDir=.another-path-tmp. The main reason for that is to be able to run multiple stryker run commands in parallel.

Do you need help with it?

@nicojs
Copy link
Member

nicojs commented Jul 15, 2019

Help is always welcome!

The best solution would be to make TempFolder injectable and implement the Disposable interface from typed-inject. That way we can also remove the explicit call to TempFolder.instance().clean (since it will be injectable).

If you need help setting up the dependency injection, please let me know.

Inside the TempFolder you can let the options be injected. We add an option as you propose.

We should also rename TempFolder to TempDir or TemporaryDirectory. Calling directories folders is kind of a pet peeve of mine 😅 .

@brunoqueiros
Copy link
Contributor

i created a PR #1644, could you check if I am going in the right track regarding the DI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants