2

Whenever I edit a file called filename.something, my text editor creates a file called .#filename.something when I modify anything. That file exists until I save. These files never were a problem until now. However, Truffle does not get along with them. Whenever I run

truffle test

with any modified but unsaved files, I now get this error message:

Error: ENOENT: no such file or directory, stat '/path/to/project/test/.#Contract.test.js'

This even happens when I run the command and start editing as my contracts compile. So I always have to sit through that, not doing anything. How can I tell Truffle to just ignore file names that start with .#?

I use Truffle v5.0.37.

1

If you're using Truffle 4.x, then you can patch their source code as follows:

Step 1 - open file:

/node_modules/truffle/build/cli.bundled.js

Step 2 - search for:

dir.files(config.test_directory, callback);

Step 3 - replace it with:

dir.files(config.test_directory, (x, y) => callback(x, y.filter(f => !f.includes(".#"))));
  • Thank you. But I use Truffle 5 and that line doesn't exist. I should've mentioned the version in my question. I'm sorry. Instead, there is this line: files = dir.files(config.test_directory, { sync: true }) || []; And a few lines below, there's: return file.match(config.test_file_extension_regexp) != null; So I added this to my truffle-config.js inside module.exports: test_file_extension_regexp: /^(\.#.*)$/, However, the regex seems to be off as now no test files are found. Can you please help me to get it right? – UTF-8 Jan 13 at 15:32
  • @UTF-8: Sounds like Truffle 5 allows you to configure this from the outside (i.e., via truffle-config.js or something like that). In any case, you'd still need to figure out the exact regular expression, and I'm afraid I'm not much of a fast shooter when it comes to that (i.e., I'd have to look it up just like you do). You can post a question on stack overflow I suppose, where you are pretty much guaranteed to get an imminent response. I believe that in your regexp, you are looking for 0 or more occurrences of .#, while you should be looking for 1 or more occurrences of that string. – goodvibration Jan 13 at 15:49
  • I now figured out a regex that's not only ugly but should demand that the first character of the file name be a letter or a digit: test_file_extension_regexp: /^(.*)\/test\/([a-zA-Z0-9])(.*).test.js$/, However, the error is still thrown. It seems to me that Truffle is encountering a problem without using the file because it's not a regular file but a broken symbolic link. – UTF-8 Jan 13 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.