-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2046 from micalevisk/file-system-reader-refactor
refactor: use native fs promise-based API instead of promisify & fix formatting
- Loading branch information
Showing
13 changed files
with
153 additions
and
96 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
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
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
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
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
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
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
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
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
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
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,64 @@ | ||
import * as fs from 'fs'; | ||
import { | ||
NpmPackageManager, | ||
PackageManagerFactory, | ||
PnpmPackageManager, | ||
YarnPackageManager, | ||
} from '../../../lib/package-managers'; | ||
|
||
jest.mock('fs', () => ({ | ||
promises: { | ||
readdir: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('PackageManagerFactory', () => { | ||
afterAll(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('.prototype.find()', () => { | ||
it('should return NpmPackageManager when no lock file is found', async () => { | ||
(fs.promises.readdir as jest.Mock).mockResolvedValue([]); | ||
|
||
const whenPackageManager = PackageManagerFactory.find(); | ||
await expect(whenPackageManager).resolves.toBeInstanceOf( | ||
NpmPackageManager, | ||
); | ||
}); | ||
|
||
it('should return YarnPackageManager when "yarn.lock" file is found', async () => { | ||
(fs.promises.readdir as jest.Mock).mockResolvedValue(['yarn.lock']); | ||
|
||
const whenPackageManager = PackageManagerFactory.find(); | ||
await expect(whenPackageManager).resolves.toBeInstanceOf( | ||
YarnPackageManager, | ||
); | ||
}); | ||
|
||
it('should return PnpmPackageManager when "pnpm-lock.yaml" file is found', async () => { | ||
(fs.promises.readdir as jest.Mock).mockResolvedValue(['pnpm-lock.yaml']); | ||
|
||
const whenPackageManager = PackageManagerFactory.find(); | ||
await expect(whenPackageManager).resolves.toBeInstanceOf( | ||
PnpmPackageManager, | ||
); | ||
}); | ||
|
||
describe('when there are all supported lock files', () => { | ||
it('should prioritize "yarn.lock" file over all the others lock files', async () => { | ||
(fs.promises.readdir as jest.Mock).mockResolvedValue([ | ||
'pnpm-lock.yaml', | ||
'package-lock.json', | ||
// This is intentionally the last element in this array | ||
'yarn.lock', | ||
]); | ||
|
||
const whenPackageManager = PackageManagerFactory.find(); | ||
await expect(whenPackageManager).resolves.toBeInstanceOf( | ||
YarnPackageManager, | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.