Skip to content
Snippets Groups Projects
Select Git revision
  • acd44b94c67e61cc4534c1abbd833f95dfbeb317
  • main default protected
  • renovate/main-docs-renovate-renovate-41.x
  • renovate/main-ghcr.io-renovatebot-base-image-11.x
  • renovate/main-sindresorhus-is-7.x
  • renovate/main-renovatebot-detect-tools-1.x
  • refactor/pin-new-value
  • fix/user-agent
  • feat/37517-base64-private-key
  • next
  • feat/gnupg
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • 41.122.3
  • 41.122.2
  • 41.122.1
  • 41.122.0
  • 41.121.4
  • 41.121.3
  • 41.121.2
  • 41.121.1
  • 41.121.0
  • 41.120.0
  • 41.119.6
  • 41.119.5
  • 41.119.4
  • 41.119.3
  • 41.119.2
  • 41.119.1
  • 41.119.0
  • 41.118.2
  • 41.118.1
  • 41.118.0
41 results

utils.ts

Blame
  • index.spec.ts 3.71 KiB
    import { getConfig } from './defaults';
    
    jest.mock('../datasource/npm');
    try {
      jest.mock('../../config.js');
    } catch (err) {
      // file does not exist
    }
    
    const defaultConfig = getConfig();
    
    describe('config/index', () => {
      describe('mergeChildConfig(parentConfig, childConfig)', () => {
        it('merges', async () => {
          const parentConfig = { ...defaultConfig };
          const childConfig = {
            foo: 'bar',
            rangeStrategy: 'replace',
            lockFileMaintenance: {
              schedule: ['on monday'],
            },
          };
          const configParser = await import('./index');
          const config = configParser.mergeChildConfig(parentConfig, childConfig);
          expect(config.foo).toEqual('bar');
          expect(config.rangeStrategy).toEqual('replace');
          expect(config.lockFileMaintenance.schedule).toEqual(['on monday']);
          expect(config.lockFileMaintenance).toMatchSnapshot();
        });
        it('merges packageRules', async () => {
          const parentConfig = { ...defaultConfig };
          Object.assign(parentConfig, {
            packageRules: [{ a: 1 }, { a: 2 }],
          });
          const childConfig = {
            packageRules: [{ a: 3 }, { a: 4 }],
          };
          const configParser = await import('./index');
          const config = configParser.mergeChildConfig(parentConfig, childConfig);
          expect(config.packageRules.map((rule) => rule.a)).toMatchObject([
            1, 2, 3, 4,
          ]);
        });
        it('merges constraints', async () => {
          const parentConfig = { ...defaultConfig };
          Object.assign(parentConfig, {
            constraints: {
              node: '>=12',
              npm: '^6.0.0',
            },
          });
          const childConfig = {
            constraints: {
              node: '<15',
            },
          };
          const configParser = await import('./index');
          const config = configParser.mergeChildConfig(parentConfig, childConfig);
          expect(config.constraints).toMatchSnapshot();
          expect(config.constraints.node).toEqual('<15');
        });
        it('handles null parent packageRules', async () => {
          const parentConfig = { ...defaultConfig };
          Object.assign(parentConfig, {
            packageRules: null,
          });
          const childConfig = {
            packageRules: [{ a: 3 }, { a: 4 }],
          };
          const configParser = await import('./index');
          const config = configParser.mergeChildConfig(parentConfig, childConfig);
          expect(config.packageRules).toHaveLength(2);
        });
        it('handles null child packageRules', async () => {
          const parentConfig = { ...defaultConfig };
          parentConfig.packageRules = [{ a: 3 }, { a: 4 }];
          const configParser = await import('./index');
          const config = configParser.mergeChildConfig(parentConfig, {});
          expect(config.packageRules).toHaveLength(2);
        });
        it('handles undefined childConfig', async () => {
          const parentConfig = { ...defaultConfig };
          const configParser = await import('./index');
          const config = configParser.mergeChildConfig(parentConfig, undefined);
          expect(config).toMatchObject(parentConfig);
        });
    
        it('getManagerConfig()', async () => {
          const parentConfig = { ...defaultConfig };
          const configParser = await import('./index');
          const config = configParser.getManagerConfig(parentConfig, 'npm');
          expect(config).toContainEntries([
            ['fileMatch', ['(^|/)package.json$']],
            ['rollbackPrs', true],
          ]);
          expect(
            configParser.getManagerConfig(parentConfig, 'html')
          ).toContainEntries([['fileMatch', ['\\.html?$']]]);
        });
    
        it('filterConfig()', async () => {
          const parentConfig = { ...defaultConfig };
          const configParser = await import('./index');
          const config = configParser.filterConfig(parentConfig, 'pr');
          expect(config).toBeObject();
        });
      });
    });