Skip to content
Snippets Groups Projects
Select Git revision
  • 4e2c33f10ed009f6dd147e27bb77593058ba8f5f
  • main default protected
  • renovate/main-ghcr.io-renovatebot-base-image-11.x
  • chore/maintainers-rarkins
  • 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
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • 41.86.0
  • 41.85.0
  • 41.84.0
  • 41.83.2
  • 41.83.1
  • 41.83.0
  • 41.82.10
  • 41.82.9
  • 41.82.8
  • 41.82.7
  • 41.82.6
  • 41.82.5
  • 41.82.4
  • 41.82.3
  • 41.82.2
  • 41.82.1
  • 41.82.0
  • 41.81.6
  • 41.81.5
  • 41.81.4
41 results

artifacts.spec.ts

Blame
  • user avatar
    Rhys Arkins authored and GitHub committed
    4e2c33f1
    History
    artifacts.spec.ts 7.10 KiB
    import { exec as _exec } from 'child_process';
    import _fs from 'fs-extra';
    import { join } from 'upath';
    import { envMock, mockExecAll } from '../../../test/exec-util';
    import { git, mocked } from '../../../test/util';
    import * as _datasource from '../../datasource';
    import { setExecConfig } from '../../util/exec';
    import { BinarySource } from '../../util/exec/common';
    import * as _env from '../../util/exec/env';
    import { StatusResult } from '../../util/git';
    import { updateArtifacts } from '.';
    
    jest.mock('fs-extra');
    jest.mock('child_process');
    jest.mock('../../util/exec/env');
    jest.mock('../../util/git');
    jest.mock('../../platform');
    jest.mock('../../datasource');
    
    const fs: jest.Mocked<typeof _fs> = _fs as any;
    const exec: jest.Mock<typeof _exec> = _exec as any;
    const env = mocked(_env);
    const datasource = mocked(_datasource);
    
    delete process.env.CP_HOME_DIR;
    
    const config = {
      localDir: join('/tmp/github/some/repo'),
      cacheDir: join('/tmp/cache'),
    };
    
    describe('.updateArtifacts()', () => {
      beforeEach(async () => {
        jest.resetAllMocks();
        env.getChildProcessEnv.mockReturnValue(envMock.basic);
        await setExecConfig(config);
    
        datasource.getPkgReleases.mockResolvedValue({
          releases: [
            { version: '1.2.0' },
            { version: '1.2.1' },
            { version: '1.2.2' },
            { version: '1.2.3' },
            { version: '1.2.4' },
            { version: '1.2.5' },
          ],
        });
      });
      it('returns null if no Podfile.lock found', async () => {
        const execSnapshots = mockExecAll(exec);
        expect(
          await updateArtifacts({
            packageFileName: 'Podfile',
            updatedDeps: ['foo'],
            newPackageFileContent: '',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('returns null if no updatedDeps were provided', async () => {
        const execSnapshots = mockExecAll(exec);
        expect(
          await updateArtifacts({
            packageFileName: 'Podfile',
            updatedDeps: [],
            newPackageFileContent: '',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('returns null for invalid local directory', async () => {
        const execSnapshots = mockExecAll(exec);
        const noLocalDirConfig = {
          localDir: undefined,
        };
        expect(
          await updateArtifacts({
            packageFileName: 'Podfile',
            updatedDeps: ['foo'],
            newPackageFileContent: '',
            config: noLocalDirConfig,
          })
        ).toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('returns null if updatedDeps is empty', async () => {
        const execSnapshots = mockExecAll(exec);
        expect(
          await updateArtifacts({
            packageFileName: 'Podfile',
            updatedDeps: [],
            newPackageFileContent: '',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('returns null if unchanged', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.readFile.mockResolvedValueOnce('Current Podfile' as any);
        git.getRepoStatus.mockResolvedValueOnce({
          modified: [],
        } as StatusResult);
        fs.readFile.mockResolvedValueOnce('Current Podfile' as any);
        expect(
          await updateArtifacts({
            packageFileName: 'Podfile',
            updatedDeps: ['foo'],
            newPackageFileContent: '',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('returns updated Podfile', async () => {
        const execSnapshots = mockExecAll(exec);
        await setExecConfig({ ...config, binarySource: BinarySource.Docker });
        fs.readFile.mockResolvedValueOnce('Old Podfile' as any);
        git.getRepoStatus.mockResolvedValueOnce({
          modified: ['Podfile.lock'],
        } as StatusResult);
        fs.readFile.mockResolvedValueOnce('New Podfile' as any);
        expect(
          await updateArtifacts({
            packageFileName: 'Podfile',
            updatedDeps: ['foo'],
            newPackageFileContent: 'plugin "cocoapods-acknowledgements"',
            config,
          })
        ).toMatchSnapshot();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('returns updated Podfile and Pods files', async () => {
        const execSnapshots = mockExecAll(exec);
        await setExecConfig({ ...config, binarySource: BinarySource.Docker });
        fs.readFile.mockResolvedValueOnce('Old Manifest.lock' as any);
        fs.readFile.mockResolvedValueOnce('New Podfile' as any);
        fs.readFile.mockResolvedValueOnce('Pods manifest' as any);
        git.getRepoStatus.mockResolvedValueOnce({
          not_added: ['Pods/New'],
          modified: ['Podfile.lock', 'Pods/Manifest.lock'],
          deleted: ['Pods/Deleted'],
        } as StatusResult);
        expect(
          await updateArtifacts({
            packageFileName: 'Podfile',
            updatedDeps: ['foo'],
            newPackageFileContent: '',
            config,
          })
        ).toMatchSnapshot();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('catches write error', async () => {
        const execSnapshots = mockExecAll(exec);
        fs.readFile.mockResolvedValueOnce('Current Podfile' as any);
        fs.outputFile.mockImplementationOnce(() => {
          throw new Error('not found');
        });
        expect(
          await updateArtifacts({
            packageFileName: 'Podfile',
            updatedDeps: ['foo'],
            newPackageFileContent: '',
            config,
          })
        ).toMatchSnapshot();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('returns pod exec error', async () => {
        const execSnapshots = mockExecAll(exec, new Error('exec exception'));
        fs.readFile.mockResolvedValueOnce('Old Podfile.lock' as any);
        fs.outputFile.mockResolvedValueOnce(null as never);
        fs.readFile.mockResolvedValueOnce('Old Podfile.lock' as any);
        expect(
          await updateArtifacts({
            packageFileName: 'Podfile',
            updatedDeps: ['foo'],
            newPackageFileContent: '',
            config,
          })
        ).toMatchSnapshot();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('dynamically selects Docker image tag', async () => {
        const execSnapshots = mockExecAll(exec);
    
        await setExecConfig({
          ...config,
          binarySource: 'docker',
        });
    
        fs.readFile.mockResolvedValueOnce('COCOAPODS: 1.2.4' as any);
    
        fs.readFile.mockResolvedValueOnce('New Podfile' as any);
    
        git.getRepoStatus.mockResolvedValueOnce({
          modified: ['Podfile.lock'],
        } as StatusResult);
    
        await updateArtifacts({
          packageFileName: 'Podfile',
          updatedDeps: ['foo'],
          newPackageFileContent: '',
          config,
        });
        expect(execSnapshots).toMatchSnapshot();
      });
      it('falls back to the `latest` Docker image tag', async () => {
        const execSnapshots = mockExecAll(exec);
    
        await setExecConfig({
          ...config,
          binarySource: 'docker',
        });
    
        fs.readFile.mockResolvedValueOnce('COCOAPODS: 1.2.4' as any);
        datasource.getPkgReleases.mockResolvedValueOnce({
          releases: [],
        });
    
        fs.readFile.mockResolvedValueOnce('New Podfile' as any);
    
        git.getRepoStatus.mockResolvedValueOnce({
          modified: ['Podfile.lock'],
        } as StatusResult);
    
        await updateArtifacts({
          packageFileName: 'Podfile',
          updatedDeps: ['foo'],
          newPackageFileContent: '',
          config,
        });
        expect(execSnapshots).toMatchSnapshot();
      });
    });