jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.29k stars 6.47k forks source link

[Bug]: Node 23 normalizes paths in a way that results in Jest finding no tests #15348

Open steveluscher opened 1 month ago

steveluscher commented 1 month ago

Version

main branch

Steps to reproduce

yarn jest-jasmine-ci e2e/__tests__/jestChangedFiles.test.ts

Expected behavior

Tests pass.

Actual behavior

includePaths ends up having '../jest-changed-files-test-dir' under Node 23 instead of '.' under Node <=22. This causes git to freak out because the directory is ‘outside the repository.’

/home/sol/src/jest/e2e/__tests__/jestChangedFiles.test.ts

  ● gets changed files for git

    Command failed with exit code 128: git diff --cached --name-only -- nested-dir nested-dir/second-nested-dir ../jest-changed-files-test-dir
    fatal: ../jest-changed-files-test-dir: '../jest-changed-files-test-dir' is outside repository at '/tmp/jest-changed-files-test-dir'

      207 |   ].map(filename => path.resolve(DIR, filename));
      208 |   console.log(roots);
    > 209 |   let {changedFiles: files} = await getChangedFilesForRoots(roots, {});
          |                               ^
      210 |   expect([...files].map(filePath => path.basename(filePath)).sort()).toEqual([
      211 |     'file1.txt',
      212 |     'file2.txt',

      at makeError (node_modules/execa/lib/error.js:60:11)
          at async Promise.all (index 0)
          at async Promise.all (index 0)
      at Object.<anonymous> (e2e/__tests__/jestChangedFiles.test.ts:209:31)

Additional context

This appears to be because of a bug in Node 23, but that's no reason not to try to strip the trailing slash in Jest, defensively. https://github.com/nodejs/node/issues/55448

Environment

System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (64) x64 AMD EPYC 7502P 32-Core Processor
  Binaries:
    Node: 23.0.0 - ~/n/bin/node
    Yarn: 3.8.5 - ~/.local/share/pnpm/yarn
    npm: 10.9.0 - ~/n/bin/npm
  npmPackages:
    jest: workspace:* => 30.0.0-alpha.6
steveluscher commented 1 month ago

Looks like this has been reverted in Node. https://github.com/nodejs/node/pull/55414

github-actions[bot] commented 4 days ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.