2022-05-11 07:19:35 +02:00
|
|
|
import { detectGlobalConfig } from '.';
|
2025-03-13 18:52:09 +01:00
|
|
|
import { fs } from '~test/util';
|
2021-09-29 21:58:42 +02:00
|
|
|
|
2025-02-26 10:35:54 +01:00
|
|
|
vi.mock('../../../util/fs');
|
2021-09-29 21:58:42 +02:00
|
|
|
|
2022-03-03 10:35:26 +01:00
|
|
|
describe('modules/manager/npm/detect', () => {
|
2021-09-29 21:58:42 +02:00
|
|
|
describe('.detectGlobalConfig()', () => {
|
|
|
|
it('detects .npmrc in home directory', async () => {
|
2022-07-01 15:57:30 +03:00
|
|
|
fs.readSystemFile.mockResolvedValueOnce(
|
2023-11-07 12:50:29 -03:00
|
|
|
'registry=https://registry.npmjs.org\n',
|
2021-09-29 21:58:42 +02:00
|
|
|
);
|
|
|
|
const res = await detectGlobalConfig();
|
|
|
|
expect(res).toMatchInlineSnapshot(`
|
2022-08-16 14:22:29 +02:00
|
|
|
{
|
|
|
|
"npmrc": "registry=https://registry.npmjs.org
|
|
|
|
",
|
|
|
|
"npmrcMerge": true,
|
|
|
|
}
|
|
|
|
`);
|
2021-09-29 21:58:42 +02:00
|
|
|
expect(res.npmrc).toBeDefined();
|
|
|
|
expect(res.npmrcMerge).toBe(true);
|
|
|
|
});
|
2022-04-12 16:49:49 +02:00
|
|
|
|
2021-09-29 21:58:42 +02:00
|
|
|
it('handles no .npmrc', async () => {
|
2022-07-01 15:57:30 +03:00
|
|
|
fs.readSystemFile.mockRejectedValueOnce('error');
|
2021-09-29 21:58:42 +02:00
|
|
|
const res = await detectGlobalConfig();
|
|
|
|
expect(res).toEqual({});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|