Skip to content

Robustly clean up and restore state after tests #834

@nfischer

Description

@nfischer

Inspired by #833. We should create a robust solution to ensure each test runs with fresh state, and we successfully cleanup after each test.

Right now, some tests can cd() to change the working directory, and we won't properly cleanup after them. As an example, here's a bad afterEach() which assumes the test doesn't change working directory:

shelljs/test/ln.js

Lines 18 to 20 in 9035b27

test.afterEach.always(t => {
shell.rm('-rf', t.context.tmp);
});

Another issue is that t.context.tmp usually refers to a relative path returned by utils.getTempDir(). I think we can be more robust by returning an absolute path.


We should create utility functions to do robust setup and teardown, to be used by every test suite (and the test suites can extend this to provide additional setup).

@freitagbr any additional thoughts?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions