-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app): cache robot releases manifest for offline usage (#6494)
Fixes #5992
- Loading branch information
Showing
5 changed files
with
101 additions
and
13 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
57 changes: 57 additions & 0 deletions
57
app-shell/src/buildroot/__tests__/release-manifest.test.js
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// @flow | ||
import fse from 'fs-extra' | ||
import tempy from 'tempy' | ||
import * as Http from '../../http' | ||
import { downloadManifest } from '../release-manifest' | ||
|
||
jest.mock('../../http') | ||
|
||
const fetchJson: JestMockFn<[string], mixed> = Http.fetchJson | ||
|
||
describe('release manifest utilities', () => { | ||
let manifestFile | ||
|
||
beforeEach(() => { | ||
manifestFile = tempy.file({ extension: 'json' }) | ||
}) | ||
|
||
afterEach(() => { | ||
return fse.remove(manifestFile) | ||
}) | ||
|
||
it('should download the manifest from a url', () => { | ||
const result = { mockResult: true } | ||
const manifestUrl = 'http://example.com/releases.json' | ||
|
||
fetchJson.mockImplementation(url => { | ||
if (url === manifestUrl) return Promise.resolve(result) | ||
}) | ||
|
||
return expect(downloadManifest(manifestUrl, manifestFile)).resolves.toBe( | ||
result | ||
) | ||
}) | ||
|
||
it('should save the manifest to the given path', () => { | ||
const result = { mockResult: true } | ||
const manifestUrl = 'http://example.com/releases.json' | ||
|
||
fetchJson.mockResolvedValue(result) | ||
|
||
return downloadManifest(manifestUrl, manifestFile) | ||
.then(() => fse.readJson(manifestFile)) | ||
.then(file => expect(file).toEqual(result)) | ||
}) | ||
|
||
it('should pull the manifest from the file if the manifest download fails', () => { | ||
const manifest = { mockResult: true } | ||
const manifestUrl = 'http://example.com/releases.json' | ||
|
||
fse.writeJsonSync(manifestFile, manifest) | ||
fetchJson.mockRejectedValue(new Error('AH')) | ||
|
||
return downloadManifest(manifestUrl, manifestFile).then(result => | ||
expect(result).toEqual(manifest) | ||
) | ||
}) | ||
}) |
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
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
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