Files
vercel/packages/fs-detectors/test/unit.detect-package-managers.test.ts
Trek Glowacki 2f5b0aeeb1 [cli] Update bun detection and add tests for projects with both bunlock.b and yarn.lock files (#10583)
Updates package manager detection to account for two lock files. All other managers will only have the one lock file. Bun, however, may have both a `bun.lockb` _and_ a `yarn.lock` file. To ensure bun is properly detected, the presence of `bun.lockb` with `yarn.lock` must occur before `yarn.lock` so we don't mistake the presence of a `yarn.lock` to mean "Yarn".

This PR also adds a test for this situation in `fs-detectors`. The behavior is currently correct there, but was not tested initially. It is now to avoid future regressions.
2023-09-26 21:11:57 +00:00

36 lines
1.0 KiB
TypeScript
Vendored

import path from 'path';
import {
packageManagers,
detectFramework,
LocalFileSystemDetector,
} from '../src';
describe('package-managers', () => {
describe.each([
['50-no-specified-package-manager', 'yarn'],
['51-npm-with-lockfile', 'npm'],
['52-npm-with-corepack', 'npm'],
['53-yarn-with-lockfile', 'yarn'],
['54-yarn-with-corepack', 'yarn'],
['55-pnpm-with-lockfile', 'pnpm'],
['56-pnpm-with-corepack', 'pnpm'],
['57-bun-with-lockfile', 'bun'],
['58-bun-with-corepack', 'bun'],
['59-bun-with-binary-and-readable-lockfile', 'bun'],
])('with detectFramework', (fixturePath, frameworkSlug) => {
const testName = `should detect package manager '${frameworkSlug}' for ${fixturePath}`;
it(testName, async () => {
const fixture = path.join(__dirname, 'fixtures', fixturePath);
const fs = new LocalFileSystemDetector(fixture);
const result = await detectFramework({
fs,
frameworkList: packageManagers,
});
expect(result).toBe(frameworkSlug);
});
});
});