Skip to content
Snippets Groups Projects
Select Git revision
  • cf5702500267a07750c6dbdce812faa89ce6ba34
  • main default protected
  • renovate/main-vitest-monorepo
  • next
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • renovate/main-redis-5.x
  • renovate/main-xmldoc-2.x
  • refactor/pin-new-value
  • 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
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • 41.11.1
  • 41.11.0
  • 41.10.1
  • 41.10.0
  • 41.9.0
  • 41.8.0
  • 41.7.2
  • 41.7.1
  • 41.7.0
  • 41.6.4
  • 41.6.3
  • 41.6.2
  • 41.6.1
  • 41.6.0
  • 41.5.0
  • 41.4.0
  • 41.3.0
  • 41.2.0
  • 41.1.4
  • 41.1.3
41 results

artifacts.spec.ts

Blame
  • artifacts.spec.ts 8.66 KiB
    import { join } from 'upath';
    import { envMock, exec, mockExecAll } from '../../../../test/exec-util';
    import { env, fs, git, mocked } from '../../../../test/util';
    import { GlobalConfig } from '../../../config/global';
    import type { RepoGlobalConfig } from '../../../config/types';
    import * as docker from '../../../util/exec/docker';
    import * as _hostRules from '../../../util/host-rules';
    import type { UpdateArtifactsConfig } from '../types';
    import * as nuget from './artifacts';
    import * as util from './util';
    
    jest.mock('child_process');
    jest.mock('../../../util/exec/env');
    jest.mock('../../../util/fs');
    jest.mock('../../../util/host-rules');
    jest.mock('../../../util/git');
    jest.mock('./util');
    
    const { getConfiguredRegistries, getDefaultRegistries, getRandomString } =
      mocked(util);
    const hostRules = mocked(_hostRules);
    
    const adminConfig: RepoGlobalConfig = {
      // `join` fixes Windows CI
      localDir: join('/tmp/github/some/repo'),
      cacheDir: join('/tmp/renovate/cache'),
    };
    
    const config: UpdateArtifactsConfig = {};
    
    describe('modules/manager/nuget/artifacts', () => {
      beforeEach(() => {
        jest.resetAllMocks();
        jest.resetModules();
        getDefaultRegistries.mockReturnValue([]);
        env.getChildProcessEnv.mockReturnValue(envMock.basic);
        fs.ensureCacheDir.mockImplementation((dirName: string) =>
          Promise.resolve(`others/${dirName}`)
        );
        git.getFileList.mockResolvedValueOnce([]);
        getRandomString.mockReturnValue('not-so-random');
        GlobalConfig.set(adminConfig);
        docker.resetPrefetchedImages();
      });
    
      afterEach(() => {
        GlobalConfig.reset();
      });
    
      it('aborts if no lock file found', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'foo' }, { depName: 'bar' }],
            newPackageFileContent: '{}',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toBeEmptyArray();
      });
    
      it('aborts if lock file is unchanged', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce(
          'path/with space/packages.lock.json'
        );
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'path/with space/project.csproj',
            updatedDeps: [{ depName: 'foo' }, { depName: 'bar' }],
            newPackageFileContent: '{}',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('updates lock file', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('does not update lock file when non-proj file is changed', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'otherfile.props',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toBeEmptyArray();
      });
    
      it('does not update lock file when no deps changed', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [],
            newPackageFileContent: '{}',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toBeEmptyArray();
      });
    
      it('performs lock file maintenance', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [],
            newPackageFileContent: '{}',
            config: {
              ...config,
              isLockFileMaintenance: true,
            },
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('supports docker mode', async () => {
        GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('supports global mode', async () => {
        GlobalConfig.set({ ...adminConfig, binarySource: 'global' });
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('catches errors', async () => {
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.writeLocalFile.mockImplementationOnce(() => {
          throw new Error('not found');
        });
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).toEqual([
          {
            artifactError: {
              lockFile: 'packages.lock.json',
              stderr: 'not found',
            },
          },
        ]);
      });
    
      it('authenticates at registries', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        getConfiguredRegistries.mockResolvedValueOnce([
          {
            name: 'myRegistry',
            url: 'https://my-registry.example.org',
          },
        ] as never);
        hostRules.find.mockImplementationOnce((search) => {
          if (
            search.hostType === 'nuget' &&
            search.url === 'https://my-registry.example.org'
          ) {
            return {
              username: 'some-username',
              password: 'some-password',
            };
          }
          return undefined;
        });
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    
      it('strips protocol version from feed url', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('Current packages.lock.json');
        fs.readLocalFile.mockResolvedValueOnce('New packages.lock.json');
        getConfiguredRegistries.mockResolvedValueOnce([
          {
            name: 'myRegistry',
            url: 'https://my-registry.example.org#protocolVersion=3',
          },
        ] as never);
        hostRules.find.mockImplementationOnce(() => ({}));
        expect(
          await nuget.updateArtifacts({
            packageFileName: 'project.csproj',
            updatedDeps: [{ depName: 'dep' }],
            newPackageFileContent: '{}',
            config,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    });