0

I'm working on a npm module that return content of folders.

I'm trying to test all possible use cases, and I want my tests to run on Travis.

I know git cannot handle empty folders, as described on this SO question, we typically have to put hidden files to store semi-empty folders on git.

But if I put an empty file in my folder, I'm testing a different use case, so I cannot follow this pattern. And neither I cannot run a script on Travis to create an empty folder, because the test would fail on my local machine.

Have you ever found yourself in a similar situation? How do you suggest me to handle this situation?

EDIT: I'm thinking to just add a files in empty folders, and to delete it at start of my test, but could be easy to do if someone knows a smarter way to do this. Deletion of placeholder files is a little intricated, because at each test run on my development machine, they appear as an unstaged edit on my git status...

Community
  • 1
  • 1
Andrea Parodi
  • 5,534
  • 27
  • 46

1 Answers1

0

I followed the intricate path. In case it could be useful to someone in future, the code of the test is on GitHub.

And, just in the case that GitHub will be shutted down, and we are still alive despite the catastrophe, here is an extract of the code:

...

describe("webdisk", function() {

    before(function() {
        fs.unlinkSync("test/files/fold2/remove.this");
        fs.unlinkSync("test/only-folders/fold1/remove.this");
    });

    after(function() {
        fs.writeFileSync("test/files/fold2/remove.this", "remove.this");
        fs.writeFileSync("test/only-folders/fold1/remove.this", "remove.this");
    });

...

Initially it's a little ugly as I wrote it in a asynchronous way, rewritten as Louis suggested it's really improved.

Andrea Parodi
  • 5,534
  • 27
  • 46
  • 1
    Yes, ugly. Why use the asynchronous versions of ``fs.unlink`` and ``fs.writeFile`` in ``before`` and ``after``, rather than use the synchronous version of both calls? – Louis Jan 27 '14 at 19:39
  • Thank you, good suggestion. It's just the habit to use asynchronous, but in this case sync is better... – Andrea Parodi Jan 27 '14 at 19:53