PHP 8.2.30
Preview: getDistVersion.spec.ts Size: 810 B
/home/byroehnu/.trash/node_modules11/simple-update-notifier/src/getDistVersion.spec.ts

import Stream from 'stream';
import https from 'https';
import getDistVersion from './getDistVersion';

jest.mock('https', () => ({
  get: jest.fn(),
}));

test('Valid response returns version', async () => {
  const st = new Stream();
  (https.get as jest.Mock).mockImplementation((url, cb) => {
    cb(st);

    st.emit('data', '{"latest":"1.0.0"}');
    st.emit('end');
  });

  const version = await getDistVersion('test', 'latest');

  expect(version).toEqual('1.0.0');
});

test('Invalid response throws error', async () => {
  const st = new Stream();
  (https.get as jest.Mock).mockImplementation((url, cb) => {
    cb(st);

    st.emit('data', 'some invalid json');
    st.emit('end');
  });

  expect(getDistVersion('test', 'latest')).rejects.toThrow(
    'Could not parse version response'
  );
});

Directory Contents

Dirs: 0 × Files: 11

Name Size Perms Modified Actions
371 B lrw-r--r-- 2026-02-03 15:06:46
Edit Download
527 B lrw-r--r-- 2026-02-03 15:06:46
Edit Download
1.03 KB lrw-r--r-- 2026-02-03 15:06:46
Edit Download
810 B lrw-r--r-- 2026-02-03 15:06:46
Edit Download
811 B lrw-r--r-- 2026-02-03 15:06:46
Edit Download
2.32 KB lrw-r--r-- 2026-02-03 15:06:46
Edit Download
1.12 KB lrw-r--r-- 2026-02-03 15:06:46
Edit Download
744 B lrw-r--r-- 2026-02-03 15:06:46
Edit Download
984 B lrw-r--r-- 2026-02-03 15:06:46
Edit Download
444 B lrw-r--r-- 2026-02-03 15:06:46
Edit Download
202 B lrw-r--r-- 2026-02-03 15:06:46
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).