| 5 | const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18 |
| 6 | |
| 7 | async function readNormalizedNFT(next, name) { |
| 8 | const data = await next.readJSON(name) |
| 9 | const result = [ |
| 10 | ...new Set( |
| 11 | data.files |
| 12 | .filter((file: string) => { |
| 13 | // They are important, but they are never actually included by themselves but rather as |
| 14 | // part of some JS files in the same directory tree, which are higher-signal for the |
| 15 | // screenshot below. |
| 16 | if (file.endsWith('/package.json')) { |
| 17 | return false |
| 18 | } |
| 19 | |
| 20 | // Filter out the many symlinks that power node_modules |
| 21 | const fileAbsolute = path.join(next.testDir, name, '..', file) |
| 22 | try { |
| 23 | if (fs.lstatSync(fileAbsolute).isSymbolicLink()) { |
| 24 | return false |
| 25 | } |
| 26 | } catch (e) { |
| 27 | // File doesn't exist - this is a bug in the NFT generation! |
| 28 | // Keep it in the list so the test can catch it |
| 29 | } |
| 30 | return true |
| 31 | }) |
| 32 | .map((file: string) => { |
| 33 | // Normalize sharp, different architectures have different files |
| 34 | if (file.includes('/node_modules/@img/sharp-libvips-')) { |
| 35 | return '/node_modules/@img/sharp-libvips-*' |
| 36 | } |
| 37 | if ( |
| 38 | file.match( |
| 39 | /\/node_modules\/@img\/sharp-\w+-\w+\/lib\/sharp-\w+-\w+.node$/ |
| 40 | ) |
| 41 | ) { |
| 42 | return '/node_modules/@img/sharp-*/sharp-*.node' |
| 43 | } |
| 44 | |
| 45 | // Strip double node_modules to simplify output |
| 46 | const firstNodeModules = file.indexOf('/node_modules/') |
| 47 | const lastNodeModules = file.lastIndexOf('/node_modules/') |
| 48 | if (firstNodeModules !== lastNodeModules) { |
| 49 | return file.slice(lastNodeModules) |
| 50 | } |
| 51 | |
| 52 | return file |
| 53 | }) |
| 54 | ), |
| 55 | ] |
| 56 | result.sort() |
| 57 | return result |
| 58 | } |
| 59 | |
| 60 | // Only run this test for Turbopack as it is more conservative (i.e. aggressive) in including |
| 61 | // referenced files and might include too many. (The Webpack snapshots would different slightly from |