Files
vercel/packages/fs-detectors/test/unit.get-workspaces.test.ts
Nathan Rajlich 3138415533 [fs-detectors] Resolve symlinks in LocalFileSystemDetector#readdir() (#10126)
`LocalFileSystemDetector#readdir()` was throwing an error when a symlink was encountered, due to `fs.readdir()` `withFileTypes: true` option performing an lstat instead of a stat operation.

So re-implement the `readdir()` logic to use `fs.stat()` so that the symlink is resolved (only "dir" and "file" types are expected in the result).
2023-06-22 18:19:28 +00:00

45 lines
1.5 KiB
TypeScript
Vendored

import path from 'path';
import { LocalFileSystemDetector } from '../src';
import { getWorkspaces, Workspace } from '../src/workspaces/get-workspaces';
describe.each<[string, Workspace[]]>([
['21-npm-workspaces', [{ type: 'npm', rootPath: '/' }]],
['23-pnpm-workspaces', [{ type: 'pnpm', rootPath: '/' }]],
['27-yarn-workspaces', [{ type: 'yarn', rootPath: '/' }]],
['25-multiple-lock-files-yarn', [{ type: 'yarn', rootPath: '/' }]],
['26-multiple-lock-files-pnpm', [{ type: 'pnpm', rootPath: '/' }]],
[
'29-nested-workspaces',
[
{ type: 'pnpm', rootPath: '/backend' },
{ type: 'yarn', rootPath: '/frontend' },
],
],
[
'30-double-nested-workspaces',
[
{ type: 'pnpm', rootPath: '/packages/backend' },
{ type: 'yarn', rootPath: '/packages/frontend' },
],
],
['22-pnpm', []],
['35-no-monorepo', []],
])('`getWorkspaces()`', (fixturePath, workspaces) => {
const expectedImplementations = workspaces.map(({ type }) => type);
const testName =
workspaces.length > 0
? `should detect ${expectedImplementations.join()} workspace${
expectedImplementations.length > 1 ? 's' : ''
} for ${fixturePath}`
: `should not detect any workspace for ${fixturePath}`;
it(testName, async () => {
const fixture = path.join(__dirname, 'fixtures', fixturePath);
const fs = new LocalFileSystemDetector(fixture);
const actualWorkspaces = await getWorkspaces({ fs });
expect(actualWorkspaces).toEqual(expect.arrayContaining(workspaces));
});
});