vojtajina/testacular — pull request #7 by xrd (2012-06-25 13:09:38+00:00)
Title: bug with load order of JS files?

I think I have identified a bug in testacular.

lib/config.js loads files listed in the config. The entire final list of files *could* come back sorted because async callbacks for reading files from a directory can return out of order.

This works if you are using a single directory because the end result is that the file list is sorted alphabetically, which is how we expect a directory listing to return.

However, if you have files which need to be loaded in a specific order, and they are in different directories, it does not always work.

For example, if the testacular.conf config file specifies paths like this:

b/first.js
a/last.js

And, you need to load b/first.js first, and then load a/last.js next, the current implementation of testacular *can* fail (though might not fail). It is unfortunately non-deterministic, because the loading of b/first.js could return first, and then sorting does not occur. But, you could get a situation where the list of files gets returned as [ 'a/last.js', 'b/first.js' ]. If you have defined something in b/first.js that a/last.js depends on, errors occur.

I've forked the repo, and I think the solution is simply to remove the sorting function and load files synchronously.

https://github.com/xrd/testacular
https://github.com/xrd/testacular/blob/master/lib/config.js

I tried to create a repository which shows the failure and uses my patch to show the problem, but since this bug is not guaranteed to occur, it was difficult to isolate in my test example. But, the repository is here:

https://github.com/xrd/testacular-load-order
(with-patch.js checks out fixed version, runs npm install, and then runs the test and without-patch.js checks out old version (unpatched testacular), npm installs, and runs test...)

Chris