All files / kernel-platforms/src platform-test.ts

100% Statements 16/16
100% Branches 2/2
100% Functions 5/5
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60        2x       2x 2x 2x     2x                                                 6x     6x   6x 6x       2x 2x 2x 2x   2x 2x 2x        
import { describe, expect, it, vi } from 'vitest';
 
import type { PlatformFactory } from './types.ts';
 
export const createPlatformTestSuite = (
  makePlatform: PlatformFactory,
  platformName: string,
): void => {
  describe(`${platformName} platform`, () => {
    it('exports makePlatform function', () => {
      expect(typeof makePlatform).toBe('function');
    });
 
    it.each([
      {
        name: 'fetch capability',
        config: { fetch: {} },
        expectedFetch: { type: 'function' },
        expectedFs: { type: 'undefined' },
      },
      {
        name: 'fs capability',
        config: { fs: { rootDir: '/tmp' } },
        expectedFetch: { type: 'undefined' },
        expectedFs: { type: 'object' },
      },
      {
        name: 'both capabilities',
        config: {
          fetch: {},
          fs: { rootDir: '/tmp' },
        },
        expectedFetch: { type: 'function' },
        expectedFs: { type: 'object' },
      },
    ])(
      'creates platform with $name',
      async ({ config, expectedFetch, expectedFs }) => {
        const options = config.fetch
          ? { fetch: { fromFetch: vi.fn() } }
          : undefined;
        const platform = await makePlatform(config, options as never);
 
        expect(typeof platform.fetch).toBe(expectedFetch.type);
        expect(typeof platform.fs).toBe(expectedFs.type);
      },
    );
 
    it('creates platform with partial config', async () => {
      const config = { fetch: {} };
      const options = { fetch: { fromFetch: vi.fn() } };
      const platform = await makePlatform(config, options as never);
 
      expect(platform.fetch).toBeDefined();
      expect(platform.fs).toBeUndefined();
      expect(typeof platform.fetch).toBe('function');
    });
  });
};