The CLI is not working for me on Windows, and the issue seems to be with this code:
https://github.com/avajs/ava/blob/f9fe8f242dd58d02ab1110f677e82172652d9d3d/cli.js#L11-L15
if (localCLI && localCLI !== __filename) {
debug('Using local install of AVA');
require(localCLI);
return;
}
The problem is with the use of !== to compare localCLI and __filename. In my case, the two variables hold the following values:
localCLI: c:\workspace\...\node_modules\ava\cli.js
__filename: C:\workspace\...\node_modules\ava\cli.js
As you can see, the drive letter c: is lowercase in localCLI and uppercase in __filename, thus failing the !== check.
Using !== to compare paths doesn't seem to be a particularly good idea since there are numerous different ways the exact same path can be encoded. Not sure what the best practice is for comparing paths in node.js is. Perhaps path.relative() could be used?
In the Windows command line, you can change your drive letter casing by switching to a different drive and changing directories on the C: drive. (Assuming you have a D: drive, the following commands will work):
C:\>D:
D:\>cd c:\
D:\>c:
c:\>
The problem is with the use of !== to compare localCLI and __filename.
Swapping !== with != wouldn't solve the problem, as the case of strings affects the result anyway.
@sindresorhus @jamestalmage @sotojuan @jfmengels Would a simple .toLowerCase() be a good fix for this case?
@vdemedes the suggestion is to use path methods to do the comparison. Lowercasing wouldn't work for case-sensitive file systems.
@novemberborn I meant to lowercase both variables: localCLI and __filename.
Although yes, path.relative would be better.
path.relative(localCLI, __filename) !== ''
Related Node.js issue: https://github.com/nodejs/node/issues/6624
Most helpful comment
Although yes,
path.relativewould be better.