Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
import { describe, expect, layer } from '@effect/vitest';
import * as BunFileSystem from '@effect/platform-bun/BunFileSystem';
import * as FileSystem from '@effect/platform/FileSystem';
import { Effect, Layer } from 'effect';
import * as tempy from 'tempy';
import { JsPackageManagerDetector } from 'src/services/js-package-manager-detector';
import * as path from 'path';
describe('JsPackageManagerDetector', () => {
const testLayer = Layer.provideMerge(JsPackageManagerDetector.Default, BunFileSystem.layer);
layer(testLayer)(it => {
it.scoped('should detect pnpm from lock file', () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const detector = yield* JsPackageManagerDetector;
const cwd = tempy.temporaryDirectory();
yield* fs.writeFileString(path.join(cwd, 'pnpm-lock.yaml'), '');
const result = yield* detector.detectJsPackageManager(cwd);
expect(result).toEqual('pnpm');
})
);
it.scoped('should detect bun from lock file', () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const detector = yield* JsPackageManagerDetector;
const cwd = tempy.temporaryDirectory();
yield* fs.writeFileString(path.join(cwd, 'bun.lockb'), '');
const result = yield* detector.detectJsPackageManager(cwd);
expect(result).toEqual('bun');
})
);
it.scoped('should detect yarn from lock file', () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const detector = yield* JsPackageManagerDetector;
const cwd = tempy.temporaryDirectory();
yield* fs.writeFileString(path.join(cwd, 'yarn.lock'), '');
const result = yield* detector.detectJsPackageManager(cwd);
expect(result).toEqual('yarn');
})
);
it.scoped('should detect npm from lock file', () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const detector = yield* JsPackageManagerDetector;
const cwd = tempy.temporaryDirectory();
yield* fs.writeFileString(path.join(cwd, 'package-lock.json'), '');
const result = yield* detector.detectJsPackageManager(cwd);
expect(result).toEqual('npm');
})
);
it.scoped('should detect from package.json if no lock file is present', () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const detector = yield* JsPackageManagerDetector;
const cwd = tempy.temporaryDirectory();
yield* fs.writeFileString(
path.join(cwd, 'package.json'),
JSON.stringify({ packageManager: '[email protected]' })
);
const result = yield* detector.detectJsPackageManager(cwd);
expect(result).toEqual('pnpm');
})
);
it.scoped('should detect recursively from parent directory', () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const detector = yield* JsPackageManagerDetector;
const rootDir = tempy.temporaryDirectory();
yield* fs.writeFileString(
path.join(rootDir, 'package.json'),
JSON.stringify({ packageManager: '[email protected]' })
);
const subDir = path.join(rootDir, 'subdir');
yield* fs.makeDirectory(subDir);
const result = yield* detector.detectJsPackageManager(subDir);
expect(result).toEqual('pnpm');
})
);
});
});