Skip to content
Snippets Groups Projects
Select Git revision
  • e5c6f38d750383538bab95a40184058fec5bf0e0
  • main default protected
  • next
  • renovate/main-redis-5.x
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • 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
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • gh-readonly-queue/next/pr-35009-9d5e583b7d7251148ab0d11ee8dd38149618d162
  • 41.17.2
  • 41.17.1
  • 41.17.0
  • 41.16.3
  • 41.16.2
  • 41.16.1
  • 41.16.0
  • 41.15.0
  • 41.14.0
  • 41.13.1
  • 41.13.0
  • 41.12.1
  • 41.12.0
  • 41.11.1
  • 41.11.0
  • 41.10.1
  • 41.10.0
  • 41.9.0
  • 41.8.0
  • 41.7.2
41 results

utils.spec.ts

Blame
  • utils.spec.ts 2.01 KiB
    import { Fixtures } from '../../../../test/fixtures';
    import type { LockFile } from './types';
    import { composeLockFile, parseLockFile } from './utils';
    
    describe('modules/manager/npm/utils', () => {
      describe('parseLockFile', () => {
        it('parses lockfile string into an object', () => {
          const lockFile = Fixtures.get('lockfile-parsing/package-lock.json');
          const parseLockFileResult = parseLockFile(lockFile);
          expect(parseLockFileResult).toStrictEqual({
            detectedIndent: '  ',
            lockFileParsed: {
              lockfileVersion: 2,
              name: 'lockfile-parsing',
              packages: {
                '': {
                  license: 'ISC',
                  name: 'lockfile-parsing',
                  version: '1.0.0',
                },
              },
              requires: true,
              version: '1.0.0',
            },
          });
        });
    
        it('can deal with invalid lockfiles', () => {
          const lockFile = '';
          const parseLockFileResult = parseLockFile(lockFile);
          expect(parseLockFileResult).toStrictEqual({
            detectedIndent: '  ',
            lockFileParsed: undefined,
          });
        });
      });
    
      describe('composeLockFile', () => {
        it('composes lockfile string out of an object', () => {
          const lockFile: LockFile = {
            lockfileVersion: 2,
            name: 'lockfile-parsing',
            packages: {
              '': {
                license: 'ISC',
                name: 'lockfile-parsing',
                version: '1.0.0',
              },
            },
            requires: true,
            version: '1.0.0',
          };
          const lockFileComposed = composeLockFile(lockFile, '  ');
          expect(lockFileComposed).toMatchSnapshot();
        });
    
        it('adds trailing newline to match npms behaviour and avoid diffs', () => {
          const lockFile = Fixtures.get('lockfile-parsing/package-lock.json');
          const { detectedIndent, lockFileParsed } = parseLockFile(lockFile);
          // TODO #7154
          const lockFileComposed = composeLockFile(lockFileParsed!, detectedIndent);
          expect(lockFileComposed).toBe(lockFile);
        });
      });
    });