-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): migrate using yarn when nxJson has another package manager…
- Loading branch information
1 parent
4233eff
commit 0defcad
Showing
2 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
jest.mock('fs'); | ||
import * as fs from 'fs'; | ||
import * as configModule from 'nx/src/config/configuration'; | ||
import { detectPackageManager } from 'nx/src/utils/package-manager'; | ||
|
||
describe('package-manager', () => { | ||
it('should detect package manager in nxJson', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({ | ||
cli: { | ||
packageManager: 'pnpm', | ||
}, | ||
}); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('pnpm'); | ||
expect(fs.existsSync).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should detect yarn package manager from yarn.lock', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); | ||
(fs.existsSync as jest.Mock).mockReturnValueOnce(true); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('yarn'); | ||
expect(fs.existsSync).toHaveBeenNthCalledWith(1, 'yarn.lock'); | ||
}); | ||
|
||
it('should detect pnpm package manager from pnpm-lock.yaml', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); | ||
(fs.existsSync as jest.Mock).mockImplementation((path) => { | ||
return path === 'pnpm-lock.yaml'; | ||
}); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('pnpm'); | ||
expect(fs.existsSync).toHaveBeenCalledTimes(3); | ||
}); | ||
|
||
it('should use npm package manager as default', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); | ||
(fs.existsSync as jest.Mock).mockReturnValue(false); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('npm'); | ||
expect(fs.existsSync).toHaveBeenCalledTimes(5); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters