diff --git a/__mocks__/electron-store.js b/__mocks__/electron-store.js index 26ce0d7fdfc..7155319b831 100644 --- a/__mocks__/electron-store.js +++ b/__mocks__/electron-store.js @@ -1,6 +1,5 @@ // mock electron-store 'use strict' -import { vi } from 'vitest' import { DEFAULTS_V12 } from '../app-shell-odd/src/config/migrate' const Store = function () { diff --git a/app-shell-odd/src/system-update/__tests__/release-files.test.ts b/app-shell-odd/src/system-update/__tests__/release-files.test.ts index 67558bec3b8..907aa507c3a 100644 --- a/app-shell-odd/src/system-update/__tests__/release-files.test.ts +++ b/app-shell-odd/src/system-update/__tests__/release-files.test.ts @@ -1,7 +1,6 @@ // TODO(mc, 2020-06-11): test all release-files functions import { vi, describe, it, expect, afterAll } from 'vitest' import path from 'path' -import { describe, afterAll, it } from 'vitest' import { promises as fs } from 'fs' import fse from 'fs-extra' import tempy from 'tempy' diff --git a/app-shell-odd/src/system-update/__tests__/release-manifest.test.ts b/app-shell-odd/src/system-update/__tests__/release-manifest.test.ts index 4933b0b382a..76437688cfe 100644 --- a/app-shell-odd/src/system-update/__tests__/release-manifest.test.ts +++ b/app-shell-odd/src/system-update/__tests__/release-manifest.test.ts @@ -1,47 +1,41 @@ -import { describe, it, vi, beforeEach, afterEach } from 'vitest' -import fse from 'fs-extra' +import { describe, it, vi, beforeEach, afterEach, expect } from 'vitest' import * as Http from '../../http' import * as Dirs from '../directories' import { downloadAndCacheReleaseManifest } from '../release-manifest' -vi.mock('fs-extra') vi.mock('../../http') vi.mock('../directories') - +vi.mock('electron-store') const fetchJson = Http.fetchJson -const outputJson = fse.outputJson -const readJson = fse.readJson const getManifestCacheDir = Dirs.getManifestCacheDir const MOCK_DIR = 'mock_dir' const MANIFEST_URL = 'http://example.com/releases.json' -const MOCK_MANIFEST = {} +const MOCK_MANIFEST = {} as any describe('release manifest utilities', () => { beforeEach(() => { vi.mocked(getManifestCacheDir).mockReturnValue(MOCK_DIR) vi.mocked(fetchJson).mockResolvedValue(MOCK_MANIFEST) - vi.mocked(outputJson).mockResolvedValue() - vi.mocked(readJson) - // @ts-expect-error readJson takes additional optional arguments which is tweaking jest-when - .mockResolvedValue(MOCK_MANIFEST) }) afterEach(() => { vi.resetAllMocks() }) - it('should download and save the manifest from a url', () => { - return downloadAndCacheReleaseManifest(MANIFEST_URL).then(manifest => { - expect(manifest).toBe(MOCK_MANIFEST) - expect(outputJson).toHaveBeenCalledWith(MOCK_DIR, MOCK_MANIFEST) - }) + it('should download and save the manifest from a url', async () => { + await expect( + downloadAndCacheReleaseManifest(MANIFEST_URL) + ).resolves.toEqual(MOCK_MANIFEST) + expect(fetchJson).toHaveBeenCalledWith(MANIFEST_URL) }) - it('should pull the manifest from the file if the manifest download fails', () => { - vi.mocked(fetchJson).mockRejectedValue('oh no!') - return downloadAndCacheReleaseManifest(MANIFEST_URL).then(manifest => - expect(manifest).toBe(MOCK_MANIFEST) - ) + it('should pull the manifest from the file if the manifest download fails', async () => { + const error = new Error('Failed to download') + vi.mocked(fetchJson).mockRejectedValue(error) + await expect( + downloadAndCacheReleaseManifest(MANIFEST_URL) + ).resolves.toEqual(MOCK_MANIFEST) + expect(fetchJson).toHaveBeenCalledWith(MANIFEST_URL) }) }) diff --git a/app-shell/src/protocol-storage/__tests__/file-system.test.ts b/app-shell/src/protocol-storage/__tests__/file-system.test.ts index 337b45e7769..831c10c518c 100644 --- a/app-shell/src/protocol-storage/__tests__/file-system.test.ts +++ b/app-shell/src/protocol-storage/__tests__/file-system.test.ts @@ -4,7 +4,7 @@ import path from 'path' import fs from 'fs-extra' import tempy from 'tempy' import Electron from 'electron' -import { vi, describe, beforeEach, it, afterAll } from 'vitest' +import { vi, describe, beforeEach, it, afterAll, expect } from 'vitest' import uuid from 'uuid/v4' import { @@ -16,14 +16,12 @@ import { PROTOCOLS_DIRECTORY_NAME, PROTOCOLS_DIRECTORY_PATH, } from '../file-system' -import { getConfig } from '../../config' import { analyzeProtocolSource } from '../../protocol-analysis' - vi.mock('uuid/v4') vi.mock('electron') -vi.mock('../../config') vi.mock('../../protocol-analysis') +vi.mock('electron-store') const trashItem = Electron.shell.trashItem @@ -37,9 +35,6 @@ describe('protocol storage directory utilities', () => { } beforeEach(() => { protocolsDir = makeEmptyDir() - vi.mocked(getConfig).mockReturnValue({ - python: { pathToPythonOverride: null }, - } as any) vi.mocked(analyzeProtocolSource).mockReturnValue(Promise.resolve()) })