-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
17 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
app-shell-odd/src/system-update/__tests__/release-files.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 15 additions & 21 deletions
36
app-shell-odd/src/system-update/__tests__/release-manifest.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters