Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, layer } from '@effect/vitest'; |
| 2 | import * as BunFileSystem from '@effect/platform-bun/BunFileSystem'; |
| 3 | import * as FileSystem from 'effect/FileSystem'; |
| 4 | import { Effect, Layer } from 'effect'; |
| 5 | import * as tempy from 'tempy'; |
| 6 | import { JsPackageManagerDetector } from 'src/services/js-package-manager-detector'; |
| 7 | import * as path from 'path'; |
| 8 | |
| 9 | describe('JsPackageManagerDetector', () => { |
| 10 | const testLayer = Layer.provideMerge(JsPackageManagerDetector.Default, BunFileSystem.layer); |
| 11 | |
| 12 | layer(testLayer)(it => { |
| 13 | it.effect('should detect pnpm from lock file', () => |
| 14 | Effect.gen(function* () { |
| 15 | const fs = yield* FileSystem.FileSystem; |
| 16 | const detector = yield* JsPackageManagerDetector; |
| 17 | const cwd = tempy.temporaryDirectory(); |
| 18 | |
| 19 | yield* fs.writeFileString(path.join(cwd, 'pnpm-lock.yaml'), ''); |
| 20 | |
| 21 | const result = yield* detector.detectJsPackageManager(cwd); |
| 22 | |
| 23 | expect(result).toEqual('pnpm'); |
| 24 | }) |
| 25 | ); |
| 26 | |
| 27 | it.effect('should detect bun from lock file', () => |
| 28 | Effect.gen(function* () { |
| 29 | const fs = yield* FileSystem.FileSystem; |
| 30 | const detector = yield* JsPackageManagerDetector; |
| 31 | const cwd = tempy.temporaryDirectory(); |
| 32 | |
| 33 | yield* fs.writeFileString(path.join(cwd, 'bun.lockb'), ''); |
| 34 | |
| 35 | const result = yield* detector.detectJsPackageManager(cwd); |
| 36 | |
| 37 | expect(result).toEqual('bun'); |
| 38 | }) |
| 39 | ); |
| 40 | |
| 41 | it.effect('should detect yarn from lock file', () => |
| 42 | Effect.gen(function* () { |
| 43 | const fs = yield* FileSystem.FileSystem; |
| 44 | const detector = yield* JsPackageManagerDetector; |
| 45 | const cwd = tempy.temporaryDirectory(); |
| 46 | |
| 47 | yield* fs.writeFileString(path.join(cwd, 'yarn.lock'), ''); |
| 48 | |
| 49 | const result = yield* detector.detectJsPackageManager(cwd); |
| 50 | |
| 51 | expect(result).toEqual('yarn'); |
| 52 | }) |
| 53 | ); |
| 54 | |
| 55 | it.effect('should detect npm from lock file', () => |
| 56 | Effect.gen(function* () { |
| 57 | const fs = yield* FileSystem.FileSystem; |
| 58 | const detector = yield* JsPackageManagerDetector; |
| 59 | const cwd = tempy.temporaryDirectory(); |
| 60 | |
| 61 | yield* fs.writeFileString(path.join(cwd, 'package-lock.json'), ''); |
| 62 | |
| 63 | const result = yield* detector.detectJsPackageManager(cwd); |
| 64 | |
| 65 | expect(result).toEqual('npm'); |
| 66 | }) |
| 67 | ); |
| 68 | |
| 69 | it.effect('should detect from package.json if no lock file is present', () => |
| 70 | Effect.gen(function* () { |
| 71 | const fs = yield* FileSystem.FileSystem; |
| 72 | const detector = yield* JsPackageManagerDetector; |
| 73 | const cwd = tempy.temporaryDirectory(); |
| 74 | |
| 75 | yield* fs.writeFileString( |
| 76 | path.join(cwd, 'package.json'), |
| 77 | JSON.stringify({ packageManager: 'pnpm@8.6.0' }) |
| 78 | ); |
| 79 | |
| 80 | const result = yield* detector.detectJsPackageManager(cwd); |
| 81 | |
| 82 | expect(result).toEqual('pnpm'); |
| 83 | }) |
| 84 | ); |
| 85 | |
| 86 | it.effect('should detect recursively from parent directory', () => |
| 87 | Effect.gen(function* () { |
| 88 | const fs = yield* FileSystem.FileSystem; |
| 89 | const detector = yield* JsPackageManagerDetector; |
| 90 | const rootDir = tempy.temporaryDirectory(); |
| 91 | |
| 92 | yield* fs.writeFileString( |
| 93 | path.join(rootDir, 'package.json'), |
| 94 | JSON.stringify({ packageManager: 'pnpm@10.17.0' }) |
| 95 | ); |
| 96 | |
| 97 | const subDir = path.join(rootDir, 'subdir'); |
| 98 | yield* fs.makeDirectory(subDir); |
| 99 | |
| 100 | const result = yield* detector.detectJsPackageManager(subDir); |
| 101 | |
| 102 | expect(result).toEqual('pnpm'); |
| 103 | }) |
| 104 | ); |
| 105 | }); |
| 106 | }); |