jest-html-reporter icon indicating copy to clipboard operation
jest-html-reporter copied to clipboard

[FIX] ENAMETOOLONG: name too long, ... errors due to too long name of generated temp directory

Open ptabor opened this issue 2 years ago • 1 comments

In case of running jest-html-reporter in the deeply nested trees it fails with:

    Error: An error occurred while adding the reporter at path "/private/var/tmp/_bazel_ptabor/7822fa32d222a4d7f0cf5a703ea68dac/sandbox/darwin-sandbox/2035/execroot/sfc_snapps/bazel-out/darwin_arm64-fastbuild/bin/src/[redacted]/.aspect_rules_js/[email protected]/node_modules/jest-html-reporters/index.js".
    
    ENAMETOOLONG: name too long, unlink '/var/folders/p3/x51cvt2j2dj9cb7rrq2pzg_80000gn/T/L3ByaXZhdGUvdmFyL3RtcC9fYmF6ZWxfcHRhYm9yLzc4MjJmYTMyZDIyMmE0ZDdmMGNmNWE3MDNlYTY4ZGFjL3NhbmRib3gvZGFyd2luLXNhbmRib3gvMjAzNS9leGVjcm9vdC9zZmNfc25hcHBzL2JhemVsLW91dC9kYXJ3aW5fYXJtNjQtZmFzdGJ1aWxkL2Jpbi9zcmMvW3JlZGFjdGVkLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLnJlZGFjdGVkXQo/jest-html-reporters-temp']

This problem is especially likely to happen when using on Bazel (that uses long paths).

Here is a patch that fixes the problem - by generating SHA checksum of the base folder instead of encoding the entire path in its name:

https://github.com/Hargne/jest-html-reporter/compare/master...ptabor:20230901-checsum-instead-of-base64?expand=1

ptabor avatar Sep 01 '23 15:09 ptabor

@Hargne Could you, please, take a look and create PR from the diff (I cannot push a branch here).

sfc-gh-ptabor avatar Nov 09 '23 08:11 sfc-gh-ptabor

Hi and sorry for the late response 😅

Could you provided with an example of where this would be implemented in this code base? I am struggling to replicate the issue on my end.

Thanks a bunch!

Hargne avatar Jun 02 '24 17:06 Hargne

The whole patch to apply in your code is here:

https://github.com/Hargne/jest-html-reporter/compare/master...ptabor:20230901-checsum-instead-of-base64?expand=1#diff-9c4c6148b34d502eafc592468318c68e6b3383698e94c869700517af02b885a2

It's just using sha of the directory name instead of the full dictionary name.

To reproduce the issue try putting your jest-project in a directory that have very long name:

mkdir -p private/var/tmp/_bazel_ptabor/7822fa32d222a4d7f0cf5a703ea68dac/sandbox/darwin-sandbox/2035/execroot/sfc_snapps/bazel-out/darwin_arm64-fastbuild/bin/src/abcdefghijklmn123456789/

In the prior code, it would lead to an attempt of creation of working dir that has name exceeding 256 chars, like: L3ByaXZhdGUvdmFyL3RtcC9fYmF6ZWxfcHRhYm9yLzc4MjJmYTMyZDIyMmE0ZDdmMGNmNWE3MDNlYTY4ZGFjL3NhbmRib3gvZGFyd2luLXNhbmRib3gvMjAzNS9leGVjcm9vdC9zZmNfc25hcHBzL2JhemVsLW91dC9kYXJ3aW5fYXJtNjQtZmFzdGJ1aWxkL2Jpbi9zcmMvW3JlZGFjdGVkLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLnJlZGFjdGVkXQo

ptabor avatar Jun 02 '24 17:06 ptabor

Ahaa! You are referring a different library - https://github.com/Hazyzh/jest-html-reporters (notice the extra "s" at the end)

No wonder I was so confused above the linked code 😅

Hargne avatar Jun 02 '24 18:06 Hargne