Skip to content
Snippets Groups Projects
Select Git revision
  • 13d75e0607334b700fdb4a533768cde341619a50
  • master default protected
  • gh-pages
  • dependabot/npm_and_yarn/neostandard-0.12.2
  • dependabot/npm_and_yarn/eslint-plugin-import-2.32.0
  • dependabot/npm_and_yarn/typescript-eslint/parser-8.36.0
  • dependabot/npm_and_yarn/nock-14.0.5
  • dependabot/npm_and_yarn/react-19.1.0
  • dependabot/npm_and_yarn/react-dom-19.1.0
  • server-2025-02-01-6100669a
  • server-2024-11-01-87cba042
  • server-2024-10-01-6875b7c8
  • dependabot/npm_and_yarn/path-to-regexp-8.2.0
  • server-2024-09-01-3d52575c
  • daily-tests-gha2
  • daily-tests-gha
  • server-2023-12-01-92d8fb8e
  • server-2023-11-01-a80c93fd
  • server-2023-10-01-31096085
  • coc-v2
  • server-2023-09-01-8edc3810
  • server-2025-07-01
  • 5.0.2
  • 5.0.1
  • 5.0.0
  • server-2025-06-01
  • server-2025-05-01
  • server-2025-04-03
  • server-2025-03-02
  • server-2025-03-01
  • server-2025-02-02
  • server-2025-01-01
  • server-2024-12-01
  • server-2024-11-02
  • 4.1.0
  • server-2024-09-25
  • server-2024-09-02
  • server-2024-08-01
  • server-2024-07-01
  • 4.0.0
  • server-2024-06-01
41 results

svg-helpers.spec.js

Blame
  • artifacts.spec.ts 5.08 KiB
    import { exec as _exec } from 'child_process';
    import _fs from 'fs-extra';
    import { join } from 'upath';
    import { envMock, mockExecAll } from '../../../test/execUtil';
    import { git, mocked } from '../../../test/util';
    import { setUtilConfig } from '../../util';
    import { BinarySource } from '../../util/exec/common';
    import * as docker from '../../util/exec/docker';
    import * as _env from '../../util/exec/env';
    import { StatusResult } from '../../util/git';
    import * as pipenv from './artifacts';
    
    jest.mock('fs-extra');
    jest.mock('child_process');
    jest.mock('../../util/exec/env');
    jest.mock('../../util/git');
    jest.mock('../../util/host-rules');
    jest.mock('../../util/http');
    
    const fs: jest.Mocked<typeof _fs> = _fs as any;
    const exec: jest.Mock<typeof _exec> = _exec as any;
    const env = mocked(_env);
    
    const config = {
      // `join` fixes Windows CI
      localDir: join('/tmp/github/some/repo'),
      cacheDir: join('/tmp/renovate/cache'),
      dockerUser: 'foobar',
    };
    
    const dockerConfig = { ...config, binarySource: BinarySource.Docker };
    const lockMaintenceConfig = { ...config, isLockFileMaintenance: true };
    
    describe('.updateArtifacts()', () => {
      let pipFileLock;
      beforeEach(async () => {
        jest.resetAllMocks();
        env.getChildProcessEnv.mockReturnValue({
          ...envMock.basic,
          LANG: 'en_US.UTF-8',
          LC_ALL: 'en_US',
        });
    
        await setUtilConfig(config);
        docker.resetPrefetchedImages();
        pipFileLock = { _meta: { requires: {} } };
      });
    
      it('returns if no Pipfile.lock found', async () => {
        expect(
          await pipenv.updateArtifacts({
            packageFileName: 'Pipfile',
            updatedDeps: [],
            newPackageFileContent: '',
            config,
          })
        ).toBeNull();
      });
      it('returns null if unchanged', async () => {
        pipFileLock._meta.requires.python_full_version = '3.7.6';
        fs.readFile.mockResolvedValueOnce(JSON.stringify(pipFileLock) as any);
        const execSnapshots = mockExecAll(exec);
        fs.readFile.mockReturnValueOnce(JSON.stringify(pipFileLock) as any);
        expect(
          await pipenv.updateArtifacts({
            packageFileName: 'Pipfile',
            updatedDeps: [],
            newPackageFileContent: 'some new content',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('handles no constraint', async () => {
        fs.readFile.mockResolvedValueOnce('unparseable pipfile lock' as any);
        const execSnapshots = mockExecAll(exec);
        fs.readFile.mockReturnValueOnce('unparseable pipfile lock' as any);
        expect(
          await pipenv.updateArtifacts({
            packageFileName: 'Pipfile',
            updatedDeps: [],
            newPackageFileContent: 'some new content',
            config,
          })
        ).toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('returns updated Pipfile.lock', async () => {
        fs.readFile.mockResolvedValueOnce('current pipfile.lock' as any);
        const execSnapshots = mockExecAll(exec);
        git.getRepoStatus.mockResolvedValue({
          modified: ['Pipfile.lock'],
        } as StatusResult);
        fs.readFile.mockReturnValueOnce('New Pipfile.lock' as any);
        expect(
          await pipenv.updateArtifacts({
            packageFileName: 'Pipfile',
            updatedDeps: [],
            newPackageFileContent: 'some new content',
            config: { ...config, constraints: { python: '3.7' } },
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('supports docker mode', async () => {
        jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce();
        await setUtilConfig(dockerConfig);
        pipFileLock._meta.requires.python_version = '3.7';
        fs.readFile.mockResolvedValueOnce(JSON.stringify(pipFileLock) as any);
        const execSnapshots = mockExecAll(exec);
        git.getRepoStatus.mockResolvedValue({
          modified: ['Pipfile.lock'],
        } as StatusResult);
        fs.readFile.mockReturnValueOnce('new lock' as any);
        expect(
          await pipenv.updateArtifacts({
            packageFileName: 'Pipfile',
            updatedDeps: [],
            newPackageFileContent: 'some new content',
            config: dockerConfig,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
      it('catches errors', async () => {
        fs.readFile.mockResolvedValueOnce('Current Pipfile.lock' as any);
        fs.outputFile.mockImplementationOnce(() => {
          throw new Error('not found');
        });
        expect(
          await pipenv.updateArtifacts({
            packageFileName: 'Pipfile',
            updatedDeps: [],
            newPackageFileContent: '{}',
            config,
          })
        ).toMatchSnapshot();
      });
      it('returns updated Pipenv.lock when doing lockfile maintenance', async () => {
        fs.readFile.mockResolvedValueOnce('Current Pipfile.lock' as any);
        const execSnapshots = mockExecAll(exec);
        git.getRepoStatus.mockResolvedValue({
          modified: ['Pipfile.lock'],
        } as StatusResult);
        fs.readFile.mockReturnValueOnce('New Pipfile.lock' as any);
        expect(
          await pipenv.updateArtifacts({
            packageFileName: 'Pipfile',
            updatedDeps: [],
            newPackageFileContent: '{}',
            config: lockMaintenceConfig,
          })
        ).not.toBeNull();
        expect(execSnapshots).toMatchSnapshot();
      });
    });