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

Cleanup temporary files on process.exit event. #34

Open
akshitsinha opened this issue Apr 18, 2021 · 2 comments
Open

Cleanup temporary files on process.exit event. #34

akshitsinha opened this issue Apr 18, 2021 · 2 comments

Comments

@akshitsinha
Copy link

akshitsinha commented Apr 18, 2021

Can there be an option to .file() and .directory() which cleans up files/directories on process.exit?

Example:
tempy.directory({ cleanup: true })

I've tried using tempy.file.task() but Jest ignores tests enclosed in any external function.
Example:

describe("Sample test", () => {
    tempy.file.task(tempFile => {

        // Both these tests dont get executed by Jest
        it("Sample 1", () => {
            expect(true).toBeTruthy() // Wanted to use the file in here.
        })
    
        it("Sample 2", () => {
            expect(true).toBeTruthy() // And the same file here again.
        })
    })
})

I can create a file/directory externally outside and then delete it myself, but that would be tedious. Temporary files on Windows don't get deleted automatically unlike on MacOS, so an option to cleanup on node process exit would be pretty convenient.

@sindresorhus
Copy link
Owner

The problem is that there's no reliable way to detect if a process is exiting. process.exit misses a lot of cases. See: nodejs/tooling#42

@HARDY8118
Copy link

If {cleanup: true} option is passed maybe create file in temporary directories (/tmp for linux and %localappdata%\Temp for windows). For windows system, files may be not deleted automatically but wont be a task for manual deletion for the user.
What are your thoughts?

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

No branches or pull requests

3 participants