fixes to make npm load it automatically

This commit is contained in:
scottbommarito
2016-06-15 16:55:09 -07:00
parent 031fc606e0
commit f8a744b4e9
13 changed files with 7 additions and 9 deletions

View File

@@ -1,36 +0,0 @@
{
"name": "code-push-plugin-testing-framework",
"version": "0.0.1",
"description": "Plugin Testing Framework for CodePush Plugins",
"main": "script/index.js",
"scripts": {
"test": "gulp"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Microsoft/code-push.git"
},
"author": {
"name": "Microsoft Corporation"
},
"license": "MIT",
"homepage": "https://microsoft.github.io/code-push",
"dependencies": {
"base-64": "^0.1.0",
"mocha": "latest",
"mocha-junit-reporter": "latest",
"node-uuid": "^1.4.3",
"q": "^1.4.1",
"replace": "latest",
"superagent": "^1.7.2",
"superagent-proxy": "^1.0.0"
},
"bugs": {
"url": "https://github.com/Microsoft/code-push/issues"
},
"readme": "ERROR: No README data found!",
"_id": "code-push-plugin-testing-framework@0.0.1",
"_shasum": "6ea33a661710628af266d714949fe95f88d71f0d",
"_from": "../code-push/plugin-testing-framework/bin",
"_resolved": "file:../code-push/plugin-testing-framework/bin"
}

View File

@@ -1,17 +0,0 @@
"use strict";
var Platform = require("./platform");
exports.Platform = Platform;
var PluginTestingFramework = require("./test");
exports.PluginTestingFramework = PluginTestingFramework;
var projectManager_1 = require("./projectManager");
exports.ProjectManager = projectManager_1.ProjectManager;
exports.setupTestRunScenario = projectManager_1.setupTestRunScenario;
exports.setupUpdateScenario = projectManager_1.setupUpdateScenario;
var ServerUtil = require("./serverUtil");
exports.ServerUtil = ServerUtil;
var testBuilder_1 = require("./testBuilder");
exports.TestBuilder = testBuilder_1.TestBuilder;
var TestConfig = require("./testConfig");
exports.TestConfig = TestConfig;
var testUtil_1 = require("./testUtil");
exports.TestUtil = testUtil_1.TestUtil;

View File

@@ -1,391 +0,0 @@
"use strict";
var Q = require("q");
var testUtil_1 = require("./testUtil");
//////////////////////////////////////////////////////////////////////////////////////////
// PLATFORMS
/**
* Android implementations of IPlatform.
*/
var Android = (function () {
function Android(emulatorManager) {
this.emulatorManager = emulatorManager;
}
/**
* Gets the platform name. (e.g. "android" for the Android platform).
*/
Android.prototype.getName = function () {
return "android";
};
/**
* The command line flag used to determine whether or not this platform should run.
* Runs when the flag is present, doesn't run otherwise.
*/
Android.prototype.getCommandLineFlagName = function () {
return "--android";
};
/**
* Gets the server url used for testing.
*/
Android.prototype.getServerUrl = function () {
if (!this.serverUrl)
this.serverUrl = testUtil_1.TestUtil.readMochaCommandLineOption(Android.ANDROID_SERVER_URL_OPTION_NAME, Android.DEFAULT_ANDROID_SERVER_URL);
return this.serverUrl;
};
/**
* Gets an IEmulatorManager that is used to control the emulator during the tests.
*/
Android.prototype.getEmulatorManager = function () {
return this.emulatorManager;
};
/**
* Gets the default deployment key.
*/
Android.prototype.getDefaultDeploymentKey = function () {
return "mock-android-deployment-key";
};
Android.ANDROID_SERVER_URL_OPTION_NAME = "--androidserver";
Android.DEFAULT_ANDROID_SERVER_URL = "http://10.0.2.2:3001";
return Android;
}());
exports.Android = Android;
/**
* IOS implementation of IPlatform.
*/
var IOS = (function () {
function IOS(emulatorManager) {
this.emulatorManager = emulatorManager;
}
/**
* Gets the platform name. (e.g. "android" for the Android platform).
*/
IOS.prototype.getName = function () {
return "ios";
};
/**
* The command line flag used to determine whether or not this platform should run.
* Runs when the flag is present, doesn't run otherwise.
*/
IOS.prototype.getCommandLineFlagName = function () {
return "--ios";
};
/**
* Gets the server url used for testing.
*/
IOS.prototype.getServerUrl = function () {
if (!this.serverUrl)
this.serverUrl = testUtil_1.TestUtil.readMochaCommandLineOption(IOS.IOS_SERVER_URL_OPTION_NAME, IOS.DEFAULT_IOS_SERVER_URL);
return this.serverUrl;
};
/**
* Gets an IEmulatorManager that is used to control the emulator during the tests.
*/
IOS.prototype.getEmulatorManager = function () {
return this.emulatorManager;
};
/**
* Gets the default deployment key.
*/
IOS.prototype.getDefaultDeploymentKey = function () {
return "mock-ios-deployment-key";
};
IOS.IOS_SERVER_URL_OPTION_NAME = "--iosserver";
IOS.DEFAULT_IOS_SERVER_URL = "http://127.0.0.1:3000";
return IOS;
}());
exports.IOS = IOS;
//////////////////////////////////////////////////////////////////////////////////////////
// EMULATOR MANAGERS
// bootEmulatorInternal constants
var emulatorMaxReadyAttempts = 5;
var emulatorReadyCheckDelayMs = 30 * 1000;
/**
* Helper function for EmulatorManager implementations to use to boot an emulator with a given platformName and check, start, and kill methods.
*/
function bootEmulatorInternal(platformName, restartEmulators, targetEmulator, checkEmulator, startEmulator, killEmulator) {
var deferred = Q.defer();
console.log("Setting up " + platformName + " emulator.");
function onEmulatorReady() {
console.log(platformName + " emulator is ready!");
deferred.resolve(undefined);
return deferred.promise;
}
// Called to check if the emulator for the platform is initialized.
function checkEmulatorReady() {
var checkDeferred = Q.defer();
console.log("Checking if " + platformName + " emulator is ready yet...");
// Dummy command that succeeds if emulator is ready and fails otherwise.
checkEmulator()
.then(function () {
checkDeferred.resolve(undefined);
}, function (error) {
console.log(platformName + " emulator is not ready yet!");
checkDeferred.reject(error);
});
return checkDeferred.promise;
}
var emulatorReadyAttempts = 0;
// Loops checks to see if the emulator is ready and eventually fails after surpassing emulatorMaxReadyAttempts.
function checkEmulatorReadyLooper() {
var looperDeferred = Q.defer();
emulatorReadyAttempts++;
if (emulatorReadyAttempts > emulatorMaxReadyAttempts) {
console.log(platformName + " emulator is not ready after " + emulatorMaxReadyAttempts + " attempts, abort.");
deferred.reject(platformName + " emulator failed to boot.");
looperDeferred.resolve(undefined);
}
setTimeout(function () {
checkEmulatorReady()
.then(function () {
looperDeferred.resolve(undefined);
onEmulatorReady();
}, function () {
return checkEmulatorReadyLooper().then(function () { looperDeferred.resolve(undefined); }, function () { looperDeferred.reject(undefined); });
});
}, emulatorReadyCheckDelayMs);
return looperDeferred.promise;
}
// Starts and loops the emulator.
function startEmulatorAndLoop() {
console.log("Booting " + platformName + " emulator named " + targetEmulator + ".");
startEmulator(targetEmulator).catch(function (error) { console.log(error); deferred.reject(error); });
return checkEmulatorReadyLooper();
}
var promise;
if (restartEmulators) {
console.log("Killing " + platformName + " emulator.");
promise = killEmulator().catch(function () { return null; }).then(startEmulatorAndLoop);
}
else {
promise = checkEmulatorReady().then(onEmulatorReady, startEmulatorAndLoop);
}
return deferred.promise;
}
var AndroidEmulatorManager = (function () {
function AndroidEmulatorManager() {
}
/**
* Returns the target emulator, which is specified through the command line.
*/
AndroidEmulatorManager.prototype.getTargetEmulator = function () {
if (this.targetEmulator)
return Q(this.targetEmulator);
else {
this.targetEmulator = testUtil_1.TestUtil.readMochaCommandLineOption(AndroidEmulatorManager.ANDROID_EMULATOR_OPTION_NAME, AndroidEmulatorManager.DEFAULT_ANDROID_EMULATOR);
console.log("Using Android emulator named " + this.targetEmulator);
return Q(this.targetEmulator);
}
};
/**
* Boots the target emulator.
*/
AndroidEmulatorManager.prototype.bootEmulator = function (restartEmulators) {
function checkAndroidEmulator() {
// A command that does nothing but only succeeds if the emulator is running.
// List all of the packages on the device.
return testUtil_1.TestUtil.getProcessOutput("adb shell pm list packages", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true }).then(function () { return null; });
}
function startAndroidEmulator(androidEmulatorName) {
return testUtil_1.TestUtil.getProcessOutput("emulator @" + androidEmulatorName).then(function () { return null; });
}
function killAndroidEmulator() {
return testUtil_1.TestUtil.getProcessOutput("adb emu kill").then(function () { return null; });
}
return this.getTargetEmulator()
.then(function (targetEmulator) {
return bootEmulatorInternal("Android", restartEmulators, targetEmulator, checkAndroidEmulator, startAndroidEmulator, killAndroidEmulator);
});
};
/**
* Launches an already installed application by app id.
*/
AndroidEmulatorManager.prototype.launchInstalledApplication = function (appId) {
return testUtil_1.TestUtil.getProcessOutput("adb shell monkey -p " + appId + " -c android.intent.category.LAUNCHER 1").then(function () { return null; });
};
/**
* Ends a running application given its app id.
*/
AndroidEmulatorManager.prototype.endRunningApplication = function (appId) {
return testUtil_1.TestUtil.getProcessOutput("adb shell am force-stop " + appId).then(function () { return null; });
};
/**
* Restarts an already installed application by app id.
*/
AndroidEmulatorManager.prototype.restartApplication = function (appId) {
var _this = this;
return this.endRunningApplication(appId)
.then(function () {
// Wait for a second before restarting.
return Q.delay(1000);
})
.then(function () {
return _this.launchInstalledApplication(appId);
});
};
/**
* Navigates away from the current app, waits for a delay (defaults to 1 second), then navigates to the specified app.
*/
AndroidEmulatorManager.prototype.resumeApplication = function (appId, delayBeforeResumingMs) {
var _this = this;
if (delayBeforeResumingMs === void 0) { delayBeforeResumingMs = 1000; }
// Open a default Android app (for example, settings).
return this.launchInstalledApplication("com.android.settings")
.then(function () {
console.log("Waiting for " + delayBeforeResumingMs + "ms before resuming the test application.");
return Q.delay(delayBeforeResumingMs);
})
.then(function () {
// Reopen the app.
return _this.launchInstalledApplication(appId);
});
};
/**
* Prepares the emulator for a test.
*/
AndroidEmulatorManager.prototype.prepareEmulatorForTest = function (appId) {
return this.endRunningApplication(appId)
.then(function () { return testUtil_1.TestUtil.getProcessOutput("adb shell pm clear " + appId); }).then(function () { return null; });
};
/**
* Uninstalls the app from the emulator.
*/
AndroidEmulatorManager.prototype.uninstallApplication = function (appId) {
return testUtil_1.TestUtil.getProcessOutput("adb uninstall " + appId).then(function () { return null; });
};
AndroidEmulatorManager.ANDROID_EMULATOR_OPTION_NAME = "--androidemu";
AndroidEmulatorManager.DEFAULT_ANDROID_EMULATOR = "emulator";
return AndroidEmulatorManager;
}());
exports.AndroidEmulatorManager = AndroidEmulatorManager;
var IOSEmulatorManager = (function () {
function IOSEmulatorManager() {
}
/**
* Returns the target emulator, which is specified through the command line.
*/
IOSEmulatorManager.prototype.getTargetEmulator = function () {
var _this = this;
if (this.targetEmulator)
return Q(this.targetEmulator);
else {
var deferred = Q.defer();
var targetIOSEmulator = testUtil_1.TestUtil.readMochaCommandLineOption(IOSEmulatorManager.IOS_EMULATOR_OPTION_NAME);
if (!targetIOSEmulator) {
// If no iOS simulator is specified, get the most recent iOS simulator to run tests on.
testUtil_1.TestUtil.getProcessOutput("xcrun simctl list", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true })
.then(function (listOfDevicesWithDevicePairs) {
var listOfDevices = listOfDevicesWithDevicePairs.slice(listOfDevicesWithDevicePairs.indexOf("-- iOS"), listOfDevicesWithDevicePairs.indexOf("-- tvOS"));
var phoneDevice = /iPhone (\S* )*(\(([0-9A-Z-]*)\))/g;
var match = listOfDevices.match(phoneDevice);
deferred.resolve(match[match.length - 1]);
}, function (error) {
deferred.reject(error);
});
}
else {
// Use the simulator specified on the command line.
deferred.resolve(targetIOSEmulator);
}
return deferred.promise
.then(function (targetEmulator) {
_this.targetEmulator = targetEmulator;
console.log("Using iOS simulator named " + _this.targetEmulator);
return _this.targetEmulator;
});
}
};
/**
* Boots the target emulator.
*/
IOSEmulatorManager.prototype.bootEmulator = function (restartEmulators) {
function checkIOSEmulator() {
// A command that does nothing but only succeeds if the emulator is running.
// Get the environment variable with the name "asdf" (return null, not an error, if not initialized).
return testUtil_1.TestUtil.getProcessOutput("xcrun simctl getenv booted asdf", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true }).then(function () { return null; });
}
function startIOSEmulator(iOSEmulatorName) {
return testUtil_1.TestUtil.getProcessOutput("xcrun instruments -w \"" + iOSEmulatorName + "\"", { noLogStdErr: true })
.catch(function (error) { return undefined; /* Always fails because we do not specify a template, which is not necessary to just start the emulator */ }).then(function () { return null; });
}
function killIOSEmulator() {
return testUtil_1.TestUtil.getProcessOutput("killall Simulator").then(function () { return null; });
}
return this.getTargetEmulator()
.then(function (targetEmulator) {
return bootEmulatorInternal("iOS", restartEmulators, targetEmulator, checkIOSEmulator, startIOSEmulator, killIOSEmulator);
});
};
/**
* Launches an already installed application by app id.
*/
IOSEmulatorManager.prototype.launchInstalledApplication = function (appId) {
return testUtil_1.TestUtil.getProcessOutput("xcrun simctl launch booted " + appId, undefined).then(function () { return null; });
};
/**
* Ends a running application given its app id.
*/
IOSEmulatorManager.prototype.endRunningApplication = function (appId) {
return testUtil_1.TestUtil.getProcessOutput("xcrun simctl spawn booted launchctl list", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true })
.then(function (processListOutput) {
// Find the app's process.
var regex = new RegExp("(\\S+" + appId + "\\S+)");
var execResult = regex.exec(processListOutput);
if (execResult) {
return execResult[0];
}
else {
return Q.reject("Could not get the running application label.");
}
})
.then(function (applicationLabel) {
// Kill the app if we found the process.
return testUtil_1.TestUtil.getProcessOutput("xcrun simctl spawn booted launchctl stop " + applicationLabel, undefined).then(function () { return null; });
}, function (error) {
// We couldn't find the app's process so it must not be running.
return Q.resolve(error);
});
};
/**
* Restarts an already installed application by app id.
*/
IOSEmulatorManager.prototype.restartApplication = function (appId) {
var _this = this;
return this.endRunningApplication(appId)
.then(function () {
// Wait for a second before restarting.
return Q.delay(1000);
})
.then(function () { return _this.launchInstalledApplication(appId); });
};
/**
* Navigates away from the current app, waits for a delay (defaults to 1 second), then navigates to the specified app.
*/
IOSEmulatorManager.prototype.resumeApplication = function (appId, delayBeforeResumingMs) {
var _this = this;
if (delayBeforeResumingMs === void 0) { delayBeforeResumingMs = 1000; }
// Open a default iOS app (for example, camera).
return this.launchInstalledApplication("com.apple.camera")
.then(function () {
console.log("Waiting for " + delayBeforeResumingMs + "ms before resuming the test application.");
return Q.delay(delayBeforeResumingMs);
})
.then(function () {
// Reopen the app.
return _this.launchInstalledApplication(appId);
});
};
/**
* Prepares the emulator for a test.
*/
IOSEmulatorManager.prototype.prepareEmulatorForTest = function (appId) {
return this.endRunningApplication(appId);
};
/**
* Uninstalls the app from the emulator.
*/
IOSEmulatorManager.prototype.uninstallApplication = function (appId) {
return testUtil_1.TestUtil.getProcessOutput("xcrun simctl uninstall booted " + appId).then(function () { return null; });
};
IOSEmulatorManager.IOS_EMULATOR_OPTION_NAME = "--iosemu";
return IOSEmulatorManager;
}());
exports.IOSEmulatorManager = IOSEmulatorManager;

View File

@@ -1,81 +0,0 @@
"use strict";
var TestConfig = require("./testConfig");
/**
* In charge of project related operations.
*/
var ProjectManager = (function () {
function ProjectManager() {
}
//// ABSTRACT METHODS
// (not actually abstract because there are some issues with our dts generator that causes it to incorrectly generate abstract classes)
/**
* Returns the name of the plugin being tested, for example Cordova or React-Native.
*
* Overwrite this in your implementation!
*/
ProjectManager.prototype.getPluginName = function () { throw ProjectManager.NOT_IMPLEMENTED_ERROR_MSG; };
/**
* Creates a new test application at the specified path, and configures it
* with the given server URL, android and ios deployment keys.
*
* Overwrite this in your implementation!
*/
ProjectManager.prototype.setupProject = function (projectDirectory, templatePath, appName, appNamespace, version) {
if (version === void 0) { version = ProjectManager.DEFAULT_APP_VERSION; }
throw ProjectManager.NOT_IMPLEMENTED_ERROR_MSG;
};
/**
* Sets up the scenario for a test in an already existing project.
*
* Overwrite this in your implementation!
*/
ProjectManager.prototype.setupScenario = function (projectDirectory, appId, templatePath, jsPath, targetPlatform, version) {
if (version === void 0) { version = ProjectManager.DEFAULT_APP_VERSION; }
throw ProjectManager.NOT_IMPLEMENTED_ERROR_MSG;
};
/**
* Creates a CodePush update package zip for a project.
*
* Overwrite this in your implementation!
*/
ProjectManager.prototype.createUpdateArchive = function (projectDirectory, targetPlatform, isDiff) { throw ProjectManager.NOT_IMPLEMENTED_ERROR_MSG; };
/**
* Prepares a specific platform for tests.
*
* Overwrite this in your implementation!
*/
ProjectManager.prototype.preparePlatform = function (projectDirectory, targetPlatform) { throw ProjectManager.NOT_IMPLEMENTED_ERROR_MSG; };
/**
* Cleans up a specific platform after tests.
*
* Overwrite this in your implementation!
*/
ProjectManager.prototype.cleanupAfterPlatform = function (projectDirectory, targetPlatform) { throw ProjectManager.NOT_IMPLEMENTED_ERROR_MSG; };
/**
* Runs the test app on the given target / platform.
*
* Overwrite this in your implementation!
*/
ProjectManager.prototype.runApplication = function (projectDirectory, targetPlatform) { throw ProjectManager.NOT_IMPLEMENTED_ERROR_MSG; };
ProjectManager.DEFAULT_APP_VERSION = "Store version";
ProjectManager.NOT_IMPLEMENTED_ERROR_MSG = "This method is unimplemented! Please extend ProjectManager and overwrite it!";
return ProjectManager;
}());
exports.ProjectManager = ProjectManager;
//////////////////////////////////////////////////////////////////////////////////////////
// Wrapper functions for simpler code in test cases.
/**
* Wrapper for ProjectManager.setupScenario in the TestRun directory.
*/
function setupTestRunScenario(projectManager, targetPlatform, scenarioJsPath, version) {
return projectManager.setupScenario(TestConfig.testRunDirectory, TestConfig.TestNamespace, TestConfig.templatePath, scenarioJsPath, targetPlatform, version);
}
exports.setupTestRunScenario = setupTestRunScenario;
/**
* Creates an update and zip for the test app using the specified scenario and version.
*/
function setupUpdateScenario(projectManager, targetPlatform, scenarioJsPath, version) {
return projectManager.setupScenario(TestConfig.updatesDirectory, TestConfig.TestNamespace, TestConfig.templatePath, scenarioJsPath, targetPlatform, version)
.then(projectManager.createUpdateArchive.bind(projectManager, TestConfig.updatesDirectory, targetPlatform));
}
exports.setupUpdateScenario = setupUpdateScenario;

View File

@@ -1,237 +0,0 @@
"use strict";
// IMPORTS
var assert = require("assert");
var bodyparser = require("body-parser");
var express = require("express");
var Q = require("q");
//////////////////////////////////////////////////////////////////////////////////////////
// Use these functions to set up and shut down the server.
/**
* Sets up the server that the test app uses to send test messages and check for and download updates.
*/
function setupServer(targetPlatform) {
console.log("Setting up server at " + targetPlatform.getServerUrl());
var app = express();
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({ extended: true }));
app.use(function (req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "*");
res.setHeader("Access-Control-Allow-Headers", "origin, content-type, accept, X-CodePush-SDK-Version");
next();
});
app.get("/updateCheck", function (req, res) {
exports.updateCheckCallback && exports.updateCheckCallback(req);
res.send(exports.updateResponse);
console.log("Update check called from the app.");
console.log("Request: " + JSON.stringify(req.query));
console.log("Response: " + JSON.stringify(exports.updateResponse));
});
app.get("/download", function (req, res) {
console.log("Application downloading the package.");
res.download(exports.updatePackagePath);
});
app.post("/reportTestMessage", function (req, res) {
console.log("Application reported a test message.");
console.log("Body: " + JSON.stringify(req.body));
if (!exports.testMessageResponse) {
console.log("Sending OK");
res.sendStatus(200);
}
else {
console.log("Sending body: " + exports.testMessageResponse);
res.status(200).send(exports.testMessageResponse);
}
exports.testMessageCallback && exports.testMessageCallback(req.body);
});
var serverPortRegEx = /:([0-9]+)/;
exports.server = app.listen(+targetPlatform.getServerUrl().match(serverPortRegEx)[1]);
}
exports.setupServer = setupServer;
/**
* Closes the server.
*/
function cleanupServer() {
if (exports.server) {
exports.server.close();
exports.server = undefined;
}
}
exports.cleanupServer = cleanupServer;
//////////////////////////////////////////////////////////////////////////////////////////
// Classes and methods used for sending mock responses to the app.
/**
* Class used to mock the codePush.checkForUpdate() response from the server.
*/
var CheckForUpdateResponseMock = (function () {
function CheckForUpdateResponseMock() {
}
return CheckForUpdateResponseMock;
}());
exports.CheckForUpdateResponseMock = CheckForUpdateResponseMock;
/**
* The model class of the codePush.checkForUpdate() request to the server.
*/
var UpdateCheckRequestMock = (function () {
function UpdateCheckRequestMock() {
}
return UpdateCheckRequestMock;
}());
exports.UpdateCheckRequestMock = UpdateCheckRequestMock;
/**
* Returns a default empty response to give to the app in a checkForUpdate request
*/
function createDefaultResponse() {
var defaultResponse = new CheckForUpdateResponseMock();
defaultResponse.downloadURL = "";
defaultResponse.description = "";
defaultResponse.isAvailable = false;
defaultResponse.isMandatory = false;
defaultResponse.appVersion = "";
defaultResponse.packageHash = "";
defaultResponse.label = "";
defaultResponse.packageSize = 0;
defaultResponse.updateAppVersion = false;
return defaultResponse;
}
exports.createDefaultResponse = createDefaultResponse;
/**
* Returns a default update response to give to the app in a checkForUpdate request
*/
function createUpdateResponse(mandatory, targetPlatform, randomHash) {
if (mandatory === void 0) { mandatory = false; }
if (randomHash === void 0) { randomHash = true; }
var updateResponse = new CheckForUpdateResponseMock();
updateResponse.isAvailable = true;
updateResponse.appVersion = "1.0.0";
updateResponse.downloadURL = "mock.url/download";
updateResponse.isMandatory = mandatory;
updateResponse.label = "mock-update";
updateResponse.packageHash = "12345-67890";
updateResponse.packageSize = 12345;
updateResponse.updateAppVersion = false;
if (!!targetPlatform)
updateResponse.downloadURL = targetPlatform.getServerUrl() + "/download";
// We need unique hashes to avoid conflicts.
if (randomHash) {
updateResponse.packageHash = "randomHash-" + Math.floor(Math.random() * 10000);
}
return updateResponse;
}
exports.createUpdateResponse = createUpdateResponse;
/**
* Returns a promise that waits for the next set of test messages sent by the app and resolves if that they are equal to the expected messages or rejects if they are not.
*/
function expectTestMessages(expectedMessages) {
var deferred = Q.defer();
var messageIndex = 0;
exports.testMessageCallback = function (requestBody) {
try {
console.log("Message index: " + messageIndex);
if (typeof expectedMessages[messageIndex] === "string") {
assert.equal(requestBody.message, expectedMessages[messageIndex]);
}
else {
assert(areEqual(requestBody, expectedMessages[messageIndex]));
}
/* end of message array */
if (++messageIndex === expectedMessages.length) {
deferred.resolve(undefined);
}
}
catch (e) {
deferred.reject(e);
}
};
return deferred.promise;
}
exports.expectTestMessages = expectTestMessages;
;
//////////////////////////////////////////////////////////////////////////////////////////
// Test messages used by the test app to send state information to the server.
/**
* Contains all the messages sent from the application to the mock server during tests.
*/
var TestMessage = (function () {
function TestMessage() {
}
TestMessage.CHECK_UP_TO_DATE = "CHECK_UP_TO_DATE";
TestMessage.CHECK_UPDATE_AVAILABLE = "CHECK_UPDATE_AVAILABLE";
TestMessage.CHECK_ERROR = "CHECK_ERROR";
TestMessage.DOWNLOAD_SUCCEEDED = "DOWNLOAD_SUCCEEDED";
TestMessage.DOWNLOAD_ERROR = "DOWNLOAD_ERROR";
TestMessage.UPDATE_INSTALLED = "UPDATE_INSTALLED";
TestMessage.INSTALL_ERROR = "INSTALL_ERROR";
TestMessage.DEVICE_READY_AFTER_UPDATE = "DEVICE_READY_AFTER_UPDATE";
TestMessage.UPDATE_FAILED_PREVIOUSLY = "UPDATE_FAILED_PREVIOUSLY";
TestMessage.NOTIFY_APP_READY_SUCCESS = "NOTIFY_APP_READY_SUCCESS";
TestMessage.NOTIFY_APP_READY_FAILURE = "NOTIFY_APP_READY_FAILURE";
TestMessage.SKIPPED_NOTIFY_APPLICATION_READY = "SKIPPED_NOTIFY_APPLICATION_READY";
TestMessage.SYNC_STATUS = "SYNC_STATUS";
TestMessage.RESTART_SUCCEEDED = "RESTART_SUCCEEDED";
TestMessage.RESTART_FAILED = "RESTART_FAILED";
TestMessage.PENDING_PACKAGE = "PENDING_PACKAGE";
TestMessage.CURRENT_PACKAGE = "CURRENT_PACKAGE";
TestMessage.SYNC_UP_TO_DATE = 0;
TestMessage.SYNC_UPDATE_INSTALLED = 1;
TestMessage.SYNC_UPDATE_IGNORED = 2;
TestMessage.SYNC_ERROR = 3;
TestMessage.SYNC_IN_PROGRESS = 4;
TestMessage.SYNC_CHECKING_FOR_UPDATE = 5;
TestMessage.SYNC_AWAITING_USER_ACTION = 6;
TestMessage.SYNC_DOWNLOADING_PACKAGE = 7;
TestMessage.SYNC_INSTALLING_UPDATE = 8;
return TestMessage;
}());
exports.TestMessage = TestMessage;
/**
* Contains all the messages sent from the mock server back to the application during tests.
*/
var TestMessageResponse = (function () {
function TestMessageResponse() {
}
TestMessageResponse.SKIP_NOTIFY_APPLICATION_READY = "SKIP_NOTIFY_APPLICATION_READY";
return TestMessageResponse;
}());
exports.TestMessageResponse = TestMessageResponse;
/**
* Defines the messages sent from the application to the mock server during tests.
*/
var AppMessage = (function () {
function AppMessage(message, args) {
this.message = message;
this.args = args;
}
AppMessage.fromString = function (message) {
return new AppMessage(message, undefined);
};
return AppMessage;
}());
exports.AppMessage = AppMessage;
/**
* Checks if two messages are equal.
*/
function areEqual(m1, m2) {
/* compare objects */
if (m1 === m2) {
return true;
}
/* compare messages */
if (!m1 || !m2 || m1.message !== m2.message) {
return false;
}
/* compare arguments */
if (m1.args === m2.args) {
return true;
}
if (!m1.args || !m2.args || m1.args.length !== m2.args.length) {
return false;
}
for (var i = 0; i < m1.args.length; i++) {
if (m1.args[i] !== m2.args[i]) {
return false;
}
}
return true;
}
exports.areEqual = areEqual;

View File

@@ -1,104 +0,0 @@
"use strict";
var Q = require("q");
var ServerUtil = require("./serverUtil");
var testBuilder_1 = require("./testBuilder");
var TestConfig = require("./testConfig");
var testUtil_1 = require("./testUtil");
//////////////////////////////////////////////////////////////////////////////////////////
/**
* Call this function to initialize the automated tests.
*/
function initializeTests(projectManager, supportedTargetPlatforms, describeTests) {
// DETERMINE PLATFORMS TO TEST //
/** The platforms to test on. */
var targetPlatforms = [];
supportedTargetPlatforms.forEach(function (supportedPlatform) {
if (testUtil_1.TestUtil.readMochaCommandLineFlag(supportedPlatform.getCommandLineFlagName()))
targetPlatforms.push(supportedPlatform);
});
// Log current configuration
console.log("Initializing tests for " + testUtil_1.TestUtil.getPluginName());
console.log(TestConfig.TestAppName + "\n" + TestConfig.TestNamespace);
console.log("Testing " + TestConfig.thisPluginPath + ".");
targetPlatforms.forEach(function (platform) {
console.log("On " + platform.getName());
});
console.log("test run directory = " + TestConfig.testRunDirectory);
console.log("updates directory = " + TestConfig.updatesDirectory);
if (TestConfig.onlyRunCoreTests)
console.log("--only running core tests--");
if (TestConfig.shouldSetup)
console.log("--setting up--");
if (TestConfig.restartEmulators)
console.log("--restarting emulators--");
// FUNCTIONS //
function cleanupTest() {
console.log("Cleaning up!");
ServerUtil.updateResponse = undefined;
ServerUtil.testMessageCallback = undefined;
ServerUtil.updateCheckCallback = undefined;
ServerUtil.testMessageResponse = undefined;
}
/**
* Sets up tests for each platform.
* Creates the test project directory and the test update directory.
* Starts required emulators.
*/
function setupTests() {
it("sets up tests correctly", function (done) {
var promises = [];
targetPlatforms.forEach(function (platform) {
promises.push(platform.getEmulatorManager().bootEmulator(TestConfig.restartEmulators));
});
console.log("Building test project.");
// create the test project
promises.push(createTestProject(TestConfig.testRunDirectory)
.then(function () {
console.log("Building update project.");
// create the update project
return createTestProject(TestConfig.updatesDirectory);
}).then(function () { return null; }));
Q.all(promises).then(function () { done(); }, function (error) { done(error); });
});
}
/**
* Creates a test project directory at the given path.
*/
function createTestProject(directory) {
return projectManager.setupProject(directory, TestConfig.templatePath, TestConfig.TestAppName, TestConfig.TestNamespace);
}
/**
* Creates and runs the tests from the projectManager and TestBuilderDescribe objects passed to initializeTests.
*/
function createAndRunTests(targetPlatform) {
describe("CodePush", function () {
before(function () {
ServerUtil.setupServer(targetPlatform);
return targetPlatform.getEmulatorManager().uninstallApplication(TestConfig.TestNamespace)
.then(projectManager.preparePlatform.bind(projectManager, TestConfig.testRunDirectory, targetPlatform))
.then(projectManager.preparePlatform.bind(projectManager, TestConfig.updatesDirectory, targetPlatform));
});
after(function () {
ServerUtil.cleanupServer();
return projectManager.cleanupAfterPlatform(TestConfig.testRunDirectory, targetPlatform).then(projectManager.cleanupAfterPlatform.bind(projectManager, TestConfig.updatesDirectory, targetPlatform));
});
testBuilder_1.TestContext.projectManager = projectManager;
testBuilder_1.TestContext.targetPlatform = targetPlatform;
// Build the tests.
describeTests(projectManager, targetPlatform);
});
}
// BEGIN TESTING //
describe("CodePush " + projectManager.getPluginName() + " Plugin", function () {
this.timeout(100 * 60 * 1000);
if (TestConfig.shouldSetup)
describe("Setting Up For Tests", function () { return setupTests(); });
else {
targetPlatforms.forEach(function (platform) {
var prefix = (TestConfig.onlyRunCoreTests ? "Core Tests " : "Tests ") + TestConfig.thisPluginPath + " on ";
describe(prefix + platform.getName(), function () { return createAndRunTests(platform); });
});
}
});
}
exports.initializeTests = initializeTests;

View File

@@ -1,88 +0,0 @@
"use strict";
var ServerUtil = require("./serverUtil");
var TestConfig = require("./testConfig");
//////////////////////////////////////////////////////////////////////////////////////////
// Use this class to create and structure the tests.
// Usage is almost identical to Mocha, but with the addition of the optional "scenarioPath" in describe() and the required "isCoreTest" in it().
var TestBuilder = (function () {
function TestBuilder() {
}
TestBuilder.describe = getDescribe();
TestBuilder.it = getIt();
return TestBuilder;
}());
exports.TestBuilder = TestBuilder;
//////////////////////////////////////////////////////////////////////////////////////////
// Mocha mimicry
/** Singleton class for TestBuilder.describe to use internally to define the context. */
var TestContext = (function () {
function TestContext() {
}
return TestContext;
}());
exports.TestContext = TestContext;
function describeInternal(func, description, spec, scenarioPath) {
if (!TestContext.projectManager || !TestContext.targetPlatform) {
throw new Error("TestContext.projectManager or TestContext.targetPlatform are not defined! Did you call TestBuilder.describe outside of a function you passed to PluginTestingFramework.initializeTests?");
}
return func(description, function () {
afterEach(function () {
console.log("Cleaning up!");
ServerUtil.updateResponse = undefined;
ServerUtil.testMessageCallback = undefined;
ServerUtil.updateCheckCallback = undefined;
ServerUtil.testMessageResponse = undefined;
});
beforeEach(function () {
return TestContext.targetPlatform.getEmulatorManager().prepareEmulatorForTest(TestConfig.TestNamespace)
.catch(function () { });
});
if (scenarioPath) {
before(function () {
return TestContext.projectManager.setupScenario(TestConfig.testRunDirectory, TestConfig.TestNamespace, TestConfig.templatePath, scenarioPath, TestContext.targetPlatform);
});
}
spec();
});
}
/**
* Returns a hybrid type that mimics mocha's describe object.
*/
function getDescribe() {
var describer = function (description, spec, scenarioPath) {
describeInternal(describe, description, spec, scenarioPath);
};
describer.only = function (description, spec, scenarioPath) {
describeInternal(describe.only, description, spec, scenarioPath);
};
describer.skip = function (description, spec, scenarioPath) {
describeInternal(describe.skip, description, spec, scenarioPath);
};
return describer;
}
function itInternal(func, expectation, isCoreTest, assertion) {
if ((!TestConfig.onlyRunCoreTests || isCoreTest)) {
// Create a wrapper around the assertion to set the timeout on the test to 10 minutes.
var assertionWithTimeout = function (done) {
this.timeout(10 * 60 * 1000);
assertion(done);
};
return it(expectation, assertionWithTimeout);
}
return null;
}
/**
* Returns a hybrid type that mimics mocha's it object.
*/
function getIt() {
var itr = function (expectation, isCoreTest, assertion) {
itInternal(it, expectation, isCoreTest, assertion);
};
itr.only = function (expectation, isCoreTest, assertion) {
itInternal(it.only, expectation, isCoreTest, assertion);
};
itr.skip = function (expectation, isCoreTest, assertion) {
itInternal(it.skip, expectation, isCoreTest, assertion);
};
return itr;
}

View File

@@ -1,30 +0,0 @@
"use strict";
// IMPORTS //
var os = require("os");
var path = require("path");
var TestUtil_1 = require("./TestUtil");
//////////////////////////////////////////////////////////////////////////////////////////
// Configuration variables.
// What plugin to use, what project directories to use, etc.
// COMMAND LINE OPTION NAMES, FLAGS, AND DEFAULTS
var TEST_RUN_DIRECTORY_OPTION_NAME = "--test-directory";
var DEFAULT_TEST_RUN_DIRECTORY = path.join(os.tmpdir(), TestUtil_1.TestUtil.getPluginName(), "test-run");
var TEST_UPDATES_DIRECTORY_OPTION_NAME = "--updates-directory";
var DEFAULT_UPDATES_DIRECTORY = path.join(os.tmpdir(), TestUtil_1.TestUtil.getPluginName(), "updates");
var CORE_TESTS_ONLY_FLAG_NAME = "--core";
var PULL_FROM_NPM_FLAG_NAME = "--npm";
var DEFAULT_PLUGIN_PATH = path.join(__dirname, "../../..");
var NPM_PLUGIN_PATH = TestUtil_1.TestUtil.getPluginName();
var SETUP_FLAG_NAME = "--setup";
var RESTART_EMULATORS_FLAG_NAME = "--clean";
// CONST VARIABLES
exports.TestAppName = "TestCodePush";
exports.TestNamespace = "com.microsoft.codepush.test";
exports.AcquisitionSDKPluginName = "code-push";
exports.templatePath = path.join(__dirname, "../../../test/template");
exports.thisPluginPath = TestUtil_1.TestUtil.readMochaCommandLineFlag(PULL_FROM_NPM_FLAG_NAME) ? NPM_PLUGIN_PATH : DEFAULT_PLUGIN_PATH;
exports.testRunDirectory = TestUtil_1.TestUtil.readMochaCommandLineOption(TEST_RUN_DIRECTORY_OPTION_NAME, DEFAULT_TEST_RUN_DIRECTORY);
exports.updatesDirectory = TestUtil_1.TestUtil.readMochaCommandLineOption(TEST_UPDATES_DIRECTORY_OPTION_NAME, DEFAULT_UPDATES_DIRECTORY);
exports.onlyRunCoreTests = TestUtil_1.TestUtil.readMochaCommandLineFlag(CORE_TESTS_ONLY_FLAG_NAME);
exports.shouldSetup = TestUtil_1.TestUtil.readMochaCommandLineFlag(SETUP_FLAG_NAME);
exports.restartEmulators = TestUtil_1.TestUtil.readMochaCommandLineFlag(RESTART_EMULATORS_FLAG_NAME);

View File

@@ -1,150 +0,0 @@
"use strict";
var archiver = require("archiver");
var child_process = require("child_process");
var del = require("del");
var fs = require("fs");
var replace = require("replace");
var Q = require("q");
var TestUtil = (function () {
function TestUtil() {
}
//// Command Line Input Functions
/**
* Reads a command line option passed to mocha and returns a default if unspecified.
*/
TestUtil.readMochaCommandLineOption = function (optionName, defaultValue) {
var optionValue = undefined;
for (var i = 0; i < process.argv.length; i++) {
if (process.argv[i] === optionName) {
if (i + 1 < process.argv.length) {
optionValue = process.argv[i + 1];
}
break;
}
}
if (!optionValue)
optionValue = defaultValue;
return optionValue;
};
/**
* Reads command line options passed to mocha.
*/
TestUtil.readMochaCommandLineFlag = function (optionName) {
for (var i = 0; i < process.argv.length; i++) {
if (process.argv[i] === optionName) {
return true;
}
}
return false;
};
//// Utility Functions
/**
* Executes a child process and returns a promise that resolves with its output or rejects with its error.
*/
TestUtil.getProcessOutput = function (command, options) {
var deferred = Q.defer();
options = options || {};
// set default options
if (options.maxBuffer === undefined)
options.maxBuffer = 1024 * 500;
if (options.timeout === undefined)
options.timeout = 10 * 60 * 1000;
if (!options.noLogCommand)
console.log("Running command: " + command);
var execProcess = child_process.exec(command, options, function (error, stdout, stderr) {
if (error) {
if (!options.noLogStdErr)
console.error("" + error);
deferred.reject(error);
}
else {
deferred.resolve(stdout.toString());
}
});
if (!options.noLogStdOut)
execProcess.stdout.pipe(process.stdout);
if (!options.noLogStdErr)
execProcess.stderr.pipe(process.stderr);
execProcess.on('error', function (error) {
if (!options.noLogStdErr)
console.error("" + error);
deferred.reject(error);
});
return deferred.promise;
};
/**
* Returns the name of the plugin that is being tested.
*/
TestUtil.getPluginName = function () {
var packageFile = eval("(" + fs.readFileSync("./package.json", "utf8") + ")");
return packageFile.name;
};
/**
* Replaces a regex in a file with a given string.
*/
TestUtil.replaceString = function (filePath, regex, replacement) {
console.log("replacing \"" + regex + "\" with \"" + replacement + "\" in " + filePath);
replace({ regex: regex, replacement: replacement, recursive: false, silent: true, paths: [filePath] });
};
/**
* Copies a file from a given location to another.
*/
TestUtil.copyFile = function (source, destination, overwrite) {
var deferred = Q.defer();
try {
var errorHandler = function (error) {
deferred.reject(error);
};
if (overwrite && fs.existsSync(destination)) {
fs.unlinkSync(destination);
}
var readStream = fs.createReadStream(source);
readStream.on("error", errorHandler);
var writeStream = fs.createWriteStream(destination);
writeStream.on("error", errorHandler);
writeStream.on("close", deferred.resolve.bind(undefined, undefined));
readStream.pipe(writeStream);
}
catch (e) {
deferred.reject(e);
}
return deferred.promise;
};
/**
* Archives the contents of sourceFolder and puts it in an archive at archivePath in targetFolder.
*/
TestUtil.archiveFolder = function (sourceFolder, targetFolder, archivePath, isDiff) {
var deferred = Q.defer();
var archive = archiver.create("zip", {});
console.log("Creating an update archive at: " + archivePath);
if (fs.existsSync(archivePath)) {
fs.unlinkSync(archivePath);
}
var writeStream = fs.createWriteStream(archivePath);
writeStream.on("close", function () {
deferred.resolve(archivePath);
});
archive.on("error", function (e) {
deferred.reject(e);
});
if (isDiff) {
archive.append("{\"deletedFiles\":[]}", { name: "hotcodepush.json" });
}
archive.directory(sourceFolder, targetFolder);
archive.pipe(writeStream);
archive.finalize();
return deferred.promise;
};
//// Placeholders
// Used in the template to represent data that needs to be added by the testing framework at runtime.
TestUtil.ANDROID_KEY_PLACEHOLDER = "CODE_PUSH_ANDROID_DEPLOYMENT_KEY";
TestUtil.IOS_KEY_PLACEHOLDER = "CODE_PUSH_IOS_DEPLOYMENT_KEY";
TestUtil.SERVER_URL_PLACEHOLDER = "CODE_PUSH_SERVER_URL";
TestUtil.INDEX_JS_PLACEHOLDER = "CODE_PUSH_INDEX_JS_PATH";
TestUtil.CODE_PUSH_APP_VERSION_PLACEHOLDER = "CODE_PUSH_APP_VERSION";
TestUtil.CODE_PUSH_TEST_APP_NAME_PLACEHOLDER = "CODE_PUSH_TEST_APP_NAME";
TestUtil.CODE_PUSH_APP_ID_PLACEHOLDER = "CODE_PUSH_TEST_APPLICATION_ID";
TestUtil.PLUGIN_VERSION_PLACEHOLDER = "CODE_PUSH_PLUGIN_VERSION";
return TestUtil;
}());
exports.TestUtil = TestUtil;

View File

@@ -1,490 +0,0 @@
declare module 'code-push-plugin-testing-framework/script/platform' {
import Q = require("q");
/**
* Defines a platform supported by CodePush.
*/
export interface IPlatform {
/**
* Gets the platform name. (e.g. "android" for the Android platform).
*/
getName(): string;
/**
* The command line flag used to determine whether or not this platform should run.
* Runs when the flag is present, doesn't run otherwise.
*/
getCommandLineFlagName(): string;
/**
* Gets the server url used for testing.
*/
getServerUrl(): string;
/**
* Gets an IEmulatorManager that is used to control the emulator during the tests.
*/
getEmulatorManager(): IEmulatorManager;
/**
* Gets the default deployment key.
*/
getDefaultDeploymentKey(): string;
}
/**
* Manages the interaction with the emulator.
*/
export interface IEmulatorManager {
/**
* Returns the target emulator, which is specified through the command line.
*/
getTargetEmulator(): Q.Promise<string>;
/**
* Boots the target emulator.
*/
bootEmulator(restartEmulators: boolean): Q.Promise<void>;
/**
* Launches an already installed application by app id.
*/
launchInstalledApplication(appId: string): Q.Promise<void>;
/**
* Ends a running application given its app id.
*/
endRunningApplication(appId: string): Q.Promise<void>;
/**
* Restarts an already installed application by app id.
*/
restartApplication(appId: string): Q.Promise<void>;
/**
* Navigates away from the current app, waits for a delay (defaults to 1 second), then navigates to the specified app.
*/
resumeApplication(appId: string, delayBeforeResumingMs?: number): Q.Promise<void>;
/**
* Prepares the emulator for a test.
*/
prepareEmulatorForTest(appId: string): Q.Promise<void>;
/**
* Uninstalls the app from the emulator.
*/
uninstallApplication(appId: string): Q.Promise<void>;
}
/**
* Android implementations of IPlatform.
*/
export class Android implements IPlatform {
private emulatorManager;
private serverUrl;
constructor(emulatorManager: IEmulatorManager);
/**
* Gets the platform name. (e.g. "android" for the Android platform).
*/
getName(): string;
/**
* The command line flag used to determine whether or not this platform should run.
* Runs when the flag is present, doesn't run otherwise.
*/
getCommandLineFlagName(): string;
private static ANDROID_SERVER_URL_OPTION_NAME;
private static DEFAULT_ANDROID_SERVER_URL;
/**
* Gets the server url used for testing.
*/
getServerUrl(): string;
/**
* Gets an IEmulatorManager that is used to control the emulator during the tests.
*/
getEmulatorManager(): IEmulatorManager;
/**
* Gets the default deployment key.
*/
getDefaultDeploymentKey(): string;
}
/**
* IOS implementation of IPlatform.
*/
export class IOS implements IPlatform {
private emulatorManager;
private serverUrl;
constructor(emulatorManager: IEmulatorManager);
/**
* Gets the platform name. (e.g. "android" for the Android platform).
*/
getName(): string;
/**
* The command line flag used to determine whether or not this platform should run.
* Runs when the flag is present, doesn't run otherwise.
*/
getCommandLineFlagName(): string;
private static IOS_SERVER_URL_OPTION_NAME;
private static DEFAULT_IOS_SERVER_URL;
/**
* Gets the server url used for testing.
*/
getServerUrl(): string;
/**
* Gets an IEmulatorManager that is used to control the emulator during the tests.
*/
getEmulatorManager(): IEmulatorManager;
/**
* Gets the default deployment key.
*/
getDefaultDeploymentKey(): string;
}
export class AndroidEmulatorManager implements IEmulatorManager {
private static ANDROID_EMULATOR_OPTION_NAME;
private static DEFAULT_ANDROID_EMULATOR;
private targetEmulator;
/**
* Returns the target emulator, which is specified through the command line.
*/
getTargetEmulator(): Q.Promise<string>;
/**
* Boots the target emulator.
*/
bootEmulator(restartEmulators: boolean): Q.Promise<void>;
/**
* Launches an already installed application by app id.
*/
launchInstalledApplication(appId: string): Q.Promise<void>;
/**
* Ends a running application given its app id.
*/
endRunningApplication(appId: string): Q.Promise<void>;
/**
* Restarts an already installed application by app id.
*/
restartApplication(appId: string): Q.Promise<void>;
/**
* Navigates away from the current app, waits for a delay (defaults to 1 second), then navigates to the specified app.
*/
resumeApplication(appId: string, delayBeforeResumingMs?: number): Q.Promise<void>;
/**
* Prepares the emulator for a test.
*/
prepareEmulatorForTest(appId: string): Q.Promise<void>;
/**
* Uninstalls the app from the emulator.
*/
uninstallApplication(appId: string): Q.Promise<void>;
}
export class IOSEmulatorManager implements IEmulatorManager {
private static IOS_EMULATOR_OPTION_NAME;
private targetEmulator;
/**
* Returns the target emulator, which is specified through the command line.
*/
getTargetEmulator(): Q.Promise<string>;
/**
* Boots the target emulator.
*/
bootEmulator(restartEmulators: boolean): Q.Promise<void>;
/**
* Launches an already installed application by app id.
*/
launchInstalledApplication(appId: string): Q.Promise<void>;
/**
* Ends a running application given its app id.
*/
endRunningApplication(appId: string): Q.Promise<void>;
/**
* Restarts an already installed application by app id.
*/
restartApplication(appId: string): Q.Promise<void>;
/**
* Navigates away from the current app, waits for a delay (defaults to 1 second), then navigates to the specified app.
*/
resumeApplication(appId: string, delayBeforeResumingMs?: number): Q.Promise<void>;
/**
* Prepares the emulator for a test.
*/
prepareEmulatorForTest(appId: string): Q.Promise<void>;
/**
* Uninstalls the app from the emulator.
*/
uninstallApplication(appId: string): Q.Promise<void>;
}
}
declare module 'code-push-plugin-testing-framework/script/projectManager' {
import Q = require("q");
import platform = require('code-push-plugin-testing-framework/script/platform');
/**
* In charge of project related operations.
*/
export class ProjectManager {
static DEFAULT_APP_VERSION: string;
private static NOT_IMPLEMENTED_ERROR_MSG;
/**
* Returns the name of the plugin being tested, for example Cordova or React-Native.
*
* Overwrite this in your implementation!
*/
getPluginName(): string;
/**
* Creates a new test application at the specified path, and configures it
* with the given server URL, android and ios deployment keys.
*
* Overwrite this in your implementation!
*/
setupProject(projectDirectory: string, templatePath: string, appName: string, appNamespace: string, version?: string): Q.Promise<void>;
/**
* Sets up the scenario for a test in an already existing project.
*
* Overwrite this in your implementation!
*/
setupScenario(projectDirectory: string, appId: string, templatePath: string, jsPath: string, targetPlatform: platform.IPlatform, version?: string): Q.Promise<void>;
/**
* Creates a CodePush update package zip for a project.
*
* Overwrite this in your implementation!
*/
createUpdateArchive(projectDirectory: string, targetPlatform: platform.IPlatform, isDiff?: boolean): Q.Promise<string>;
/**
* Prepares a specific platform for tests.
*
* Overwrite this in your implementation!
*/
preparePlatform(projectDirectory: string, targetPlatform: platform.IPlatform): Q.Promise<void>;
/**
* Cleans up a specific platform after tests.
*
* Overwrite this in your implementation!
*/
cleanupAfterPlatform(projectDirectory: string, targetPlatform: platform.IPlatform): Q.Promise<void>;
/**
* Runs the test app on the given target / platform.
*
* Overwrite this in your implementation!
*/
runApplication(projectDirectory: string, targetPlatform: platform.IPlatform): Q.Promise<void>;
}
/**
* Wrapper for ProjectManager.setupScenario in the TestRun directory.
*/
export function setupTestRunScenario(projectManager: ProjectManager, targetPlatform: platform.IPlatform, scenarioJsPath: string, version?: string): Q.Promise<void>;
/**
* Creates an update and zip for the test app using the specified scenario and version.
*/
export function setupUpdateScenario(projectManager: ProjectManager, targetPlatform: platform.IPlatform, scenarioJsPath: string, version: string): Q.Promise<string>;
}
declare module 'code-push-plugin-testing-framework/script/test' {
import Platform = require('code-push-plugin-testing-framework/script/platform');
import { ProjectManager } from 'code-push-plugin-testing-framework/script/projectManager';
/**
* Call this function to initialize the automated tests.
*/
export function initializeTests(projectManager: ProjectManager, supportedTargetPlatforms: Platform.IPlatform[], describeTests: (projectManager: ProjectManager, targetPlatform: Platform.IPlatform) => void): void;
}
declare module 'code-push-plugin-testing-framework/script/serverUtil' {
import platform = require('code-push-plugin-testing-framework/script/platform');
import Q = require("q");
/** The server to respond to requests from the app. */
export var server: any;
/** Response the server gives the next update check request */
export var updateResponse: any;
/** Response the server gives the next test message request */
export var testMessageResponse: any;
/** Called after the next test message request */
export var testMessageCallback: (requestBody: any) => void;
/** Called after the next update check request */
export var updateCheckCallback: (requestBody: any) => void;
/** Location of the update package given in the update check response */
export var updatePackagePath: string;
/**
* Sets up the server that the test app uses to send test messages and check for and download updates.
*/
export function setupServer(targetPlatform: platform.IPlatform): void;
/**
* Closes the server.
*/
export function cleanupServer(): void;
/**
* Class used to mock the codePush.checkForUpdate() response from the server.
*/
export class CheckForUpdateResponseMock {
downloadURL: string;
isAvailable: boolean;
packageSize: number;
updateAppVersion: boolean;
appVersion: string;
description: string;
label: string;
packageHash: string;
isMandatory: boolean;
}
/**
* The model class of the codePush.checkForUpdate() request to the server.
*/
export class UpdateCheckRequestMock {
deploymentKey: string;
appVersion: string;
packageHash: string;
isCompanion: boolean;
}
/**
* Returns a default empty response to give to the app in a checkForUpdate request
*/
export function createDefaultResponse(): CheckForUpdateResponseMock;
/**
* Returns a default update response to give to the app in a checkForUpdate request
*/
export function createUpdateResponse(mandatory?: boolean, targetPlatform?: platform.IPlatform, randomHash?: boolean): CheckForUpdateResponseMock;
/**
* Returns a promise that waits for the next set of test messages sent by the app and resolves if that they are equal to the expected messages or rejects if they are not.
*/
export function expectTestMessages(expectedMessages: (string | AppMessage)[]): Q.Promise<void>;
/**
* Contains all the messages sent from the application to the mock server during tests.
*/
export class TestMessage {
static CHECK_UP_TO_DATE: string;
static CHECK_UPDATE_AVAILABLE: string;
static CHECK_ERROR: string;
static DOWNLOAD_SUCCEEDED: string;
static DOWNLOAD_ERROR: string;
static UPDATE_INSTALLED: string;
static INSTALL_ERROR: string;
static DEVICE_READY_AFTER_UPDATE: string;
static UPDATE_FAILED_PREVIOUSLY: string;
static NOTIFY_APP_READY_SUCCESS: string;
static NOTIFY_APP_READY_FAILURE: string;
static SKIPPED_NOTIFY_APPLICATION_READY: string;
static SYNC_STATUS: string;
static RESTART_SUCCEEDED: string;
static RESTART_FAILED: string;
static PENDING_PACKAGE: string;
static CURRENT_PACKAGE: string;
static SYNC_UP_TO_DATE: number;
static SYNC_UPDATE_INSTALLED: number;
static SYNC_UPDATE_IGNORED: number;
static SYNC_ERROR: number;
static SYNC_IN_PROGRESS: number;
static SYNC_CHECKING_FOR_UPDATE: number;
static SYNC_AWAITING_USER_ACTION: number;
static SYNC_DOWNLOADING_PACKAGE: number;
static SYNC_INSTALLING_UPDATE: number;
}
/**
* Contains all the messages sent from the mock server back to the application during tests.
*/
export class TestMessageResponse {
static SKIP_NOTIFY_APPLICATION_READY: string;
}
/**
* Defines the messages sent from the application to the mock server during tests.
*/
export class AppMessage {
message: string;
args: any[];
constructor(message: string, args: any[]);
static fromString(message: string): AppMessage;
}
/**
* Checks if two messages are equal.
*/
export function areEqual(m1: AppMessage, m2: AppMessage): boolean;
}
declare module 'code-push-plugin-testing-framework/script/testBuilder' {
import Platform = require('code-push-plugin-testing-framework/script/platform');
import { ProjectManager } from 'code-push-plugin-testing-framework/script/projectManager';
export class TestBuilder {
static describe: ITestBuilderContextDefintion;
static it: ITestBuilderTestDefinition;
}
/** Singleton class for TestBuilder.describe to use internally to define the context. */
export class TestContext {
static projectManager: ProjectManager;
static targetPlatform: Platform.IPlatform;
}
export interface ITestBuilderContextDefintion {
(description: string, spec: () => void, scenarioPath?: string): void;
only(description: string, spec: () => void, scenarioPath?: string): void;
skip(description: string, spec: () => void, scenarioPath?: string): void;
}
export interface ITestBuilderTestDefinition {
(expectation: string, isCoreTest: boolean, assertion: (done: MochaDone) => void): void;
only(expectation: string, isCoreTest: boolean, assertion: (done: MochaDone) => void): void;
skip(expectation: string, isCoreTest: boolean, assertion: (done: MochaDone) => void): void;
}
}
declare module 'code-push-plugin-testing-framework/script/testConfig' {
export const TestAppName: string;
export const TestNamespace: string;
export const AcquisitionSDKPluginName: string;
export const templatePath: string;
export const thisPluginPath: string;
export const testRunDirectory: string;
export const updatesDirectory: string;
export const onlyRunCoreTests: boolean;
export const shouldSetup: boolean;
export const restartEmulators: boolean;
}
declare module 'code-push-plugin-testing-framework/script/testUtil' {
import Q = require("q");
export class TestUtil {
static ANDROID_KEY_PLACEHOLDER: string;
static IOS_KEY_PLACEHOLDER: string;
static SERVER_URL_PLACEHOLDER: string;
static INDEX_JS_PLACEHOLDER: string;
static CODE_PUSH_APP_VERSION_PLACEHOLDER: string;
static CODE_PUSH_TEST_APP_NAME_PLACEHOLDER: string;
static CODE_PUSH_APP_ID_PLACEHOLDER: string;
static PLUGIN_VERSION_PLACEHOLDER: string;
/**
* Reads a command line option passed to mocha and returns a default if unspecified.
*/
static readMochaCommandLineOption(optionName: string, defaultValue?: string): string;
/**
* Reads command line options passed to mocha.
*/
static readMochaCommandLineFlag(optionName: string): boolean;
/**
* Executes a child process and returns a promise that resolves with its output or rejects with its error.
*/
static getProcessOutput(command: string, options?: {
cwd?: string;
stdio?: any;
customFds?: any;
env?: any;
encoding?: string;
timeout?: number;
maxBuffer?: number;
killSignal?: string;
noLogCommand?: boolean;
noLogStdOut?: boolean;
noLogStdErr?: boolean;
}): Q.Promise<string>;
/**
* Returns the name of the plugin that is being tested.
*/
static getPluginName(): string;
/**
* Replaces a regex in a file with a given string.
*/
static replaceString(filePath: string, regex: string, replacement: string): void;
/**
* Copies a file from a given location to another.
*/
static copyFile(source: string, destination: string, overwrite: boolean): Q.Promise<void>;
/**
* Archives the contents of sourceFolder and puts it in an archive at archivePath in targetFolder.
*/
static archiveFolder(sourceFolder: string, targetFolder: string, archivePath: string, isDiff: boolean): Q.Promise<string>;
}
}
declare module 'code-push-plugin-testing-framework/script/index' {
import * as Platform from 'code-push-plugin-testing-framework/script/platform';
import * as PluginTestingFramework from 'code-push-plugin-testing-framework/script/test';
import { ProjectManager, setupTestRunScenario, setupUpdateScenario } from 'code-push-plugin-testing-framework/script/projectManager';
import * as ServerUtil from 'code-push-plugin-testing-framework/script/serverUtil';
import { TestBuilder } from 'code-push-plugin-testing-framework/script/testBuilder';
import * as TestConfig from 'code-push-plugin-testing-framework/script/testConfig';
import { TestUtil } from 'code-push-plugin-testing-framework/script/testUtil';
export { Platform, PluginTestingFramework, ProjectManager, setupTestRunScenario, setupUpdateScenario, ServerUtil, TestBuilder, TestConfig, TestUtil };
}
declare module 'code-push-plugin-testing-framework' {
import main = require('code-push-plugin-testing-framework/script/index');
export = main;
}