Skip to content

Commit a1ace37

Browse files
committed
Simplify hash handling in test harness
1 parent 5529153 commit a1ace37

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

code-push-plugin-testing-framework/script/serverUtil.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ function setupServer(targetPlatform) {
5555
}
5656
exports.setupServer = setupServer;
5757
/**
58-
* The real content hash of each update archive built during this run, keyed by archive path.
59-
* Populated by setPackageHashForPath and applied to exports.updateResponse.
58+
* The real content hash of the update archive most recently built during this test scenario.
6059
*/
61-
var packageHashesByPath = {};
60+
var knownPackageHash;
6261
var _updatePackagePath;
6362
Object.defineProperty(exports, "updatePackagePath", {
6463
enumerable: true,
@@ -70,18 +69,17 @@ Object.defineProperty(exports, "updatePackagePath", {
7069
}
7170
});
7271
/**
73-
* Records the real content hash for an update archive, so that any update_check response
74-
* pointing exports.updatePackagePath at this archive gets the matching package_hash instead
75-
* of the one filled in by default.
72+
* Records the real content hash for the update archive that will be served next, so that
73+
* any update_check response gets the matching package_hash instead of the one filled in
74+
* by default.
7675
*/
77-
function setPackageHashForPath(archivePath, packageHash) {
78-
packageHashesByPath[archivePath] = packageHash;
76+
function setKnownPackageHash(packageHash) {
77+
knownPackageHash = packageHash;
7978
}
80-
exports.setPackageHashForPath = setPackageHashForPath;
79+
exports.setKnownPackageHash = setKnownPackageHash;
8180
function applyKnownPackageHash() {
82-
var knownHash = _updatePackagePath && packageHashesByPath[_updatePackagePath];
83-
if (knownHash && exports.updateResponse && exports.updateResponse.update_info) {
84-
exports.updateResponse.update_info.package_hash = knownHash;
81+
if (knownPackageHash && exports.updateResponse && exports.updateResponse.update_info) {
82+
exports.updateResponse.update_info.package_hash = knownPackageHash;
8583
}
8684
}
8785
/**

code-push-plugin-testing-framework/typings/code-push-plugin-testing-framework.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,11 @@ declare module 'code-push-plugin-testing-framework/script/serverUtil' {
291291
*/
292292
export function cleanupServer(): void;
293293
/**
294-
* Records the real content hash for an update archive at archivePath, so any future
295-
* update_check response pointing updatePackagePath at it gets a matching package_hash.
294+
* Records the real content hash for the update archive that will be served next, so the
295+
* next update_check response gets a matching package_hash. Pass a falsy packageHash to
296+
* clear it.
296297
*/
297-
export function setPackageHashForPath(archivePath: string, packageHash: string): void;
298+
export function setKnownPackageHash(packageHash: string): void;
298299
/**
299300
* Class used to mock the codePush.checkForUpdate() response from the server.
300301
*/

test/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,10 @@ class RNProjectManager extends ProjectManager {
554554

555555
// Records the real hash of bundleFolder of an archive, so the mock server can hand back a
556556
// package_hash that matches what the client's verifyFolderHash integrity check will compute.
557+
// Diff updates clear it instead, since they don't have a precomputed real hash and must not
558+
// pick up a stale one left behind by a preceding full update.
557559
private updateMockPackageHash(bundleFolder: string, isDiff: boolean, archivePath: string): string {
558-
if (!isDiff) {
559-
ServerUtil.setPackageHashForPath(archivePath, computeUpdateContentsHash(bundleFolder));
560-
}
560+
ServerUtil.setKnownPackageHash(isDiff ? undefined : computeUpdateContentsHash(bundleFolder));
561561
return archivePath;
562562
}
563563

0 commit comments

Comments
 (0)