Skip to content

Commit

Permalink
fix iOS test bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbommarito committed May 28, 2016
1 parent aa3931d commit 7e21b56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 60 deletions.
64 changes: 13 additions & 51 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,75 +40,37 @@ function spawnCommand(command, args, callback, silent, detached) {
options.stdio = ["ignore"];
}

var process = child_process.spawn(command, args, options);

process.stdout.on('data', function (data) {
if (!silent) console.log("" + data);
});

process.stderr.on('data', function (data) {
if (!silent) console.error("" + data);
});
var spawnProcess = child_process.spawn(command, args, options);

if (!silent) spawnProcess.stdout.pipe(process.stdout);
if (!silent) spawnProcess.stderr.pipe(process.stderr);

if (!detached) {
process.on('exit', function (code) {
spawnProcess.on('exit', function (code) {
callback && callback(code === 0 ? undefined : "Error code: " + code);
});
}

return process;
return spawnProcess;
};

function execCommand(command, args, callback, silent) {
var process = child_process.exec(command + " " + args.join(" "));

process.stdout.on('data', function (data) {
if (!silent) console.log("" + data);
});

process.stderr.on('data', function (data) {
if (!silent) console.error("" + data);
});
var execProcess = child_process.exec(command + " " + args.join(" "));

if (!silent) execProcess.stdout.pipe(process.stdout);
if (!silent) execProcess.stderr.pipe(process.stderr);

process.on('error', function (error) {
execProcess.on('error', function (error) {
callback && callback(error);
})

process.on('exit', function (code) {
execProcess.on('exit', function (code) {
callback && callback(code === 0 ? undefined : "Error code: " + code);
});

return process;
return execProcess;
};

/**
* Executes a child process and returns its output in the promise as a string
*/
function execCommandWithPromise(command, options, logOutput) {
var deferred = Q.defer();

options = options || {};
options.maxBuffer = 1024 * 500;
// abort processes that run longer than five minutes
options.timeout = 5 * 60 * 1000;

console.log("Running command: " + command);
child_process.exec(command, options, (error, stdout, stderr) => {

if (logOutput) stdout && console.log(stdout);
stderr && console.error(stderr);

if (error) {
console.error(error);
deferred.reject(error);
} else {
deferred.resolve(stdout.toString());
}
});

return deferred.promise;
}

function runTests(callback, options) {
var command = "mocha";
var args = ["./bin/test"];
Expand Down
19 changes: 10 additions & 9 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class RNAndroid extends Platform.Android implements RNPlatform {
// In order to run on Android without the package manager, we must create a release APK and then sign it with the debug certificate.
var androidDirectory: string = path.join(projectDirectory, PluginTestingFramework.TestAppName, "android");
var apkPath = this.getBinaryPath(projectDirectory);
return TestUtil.getProcessOutput("./gradlew assembleRelease --daemon", { cwd: androidDirectory })
.then<string>(TestUtil.getProcessOutput.bind(undefined, "jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android " + apkPath + " androiddebugkey", { cwd: androidDirectory }));
return TestUtil.getProcessOutput("./gradlew assembleRelease", { cwd: androidDirectory })
.then<string>(TestUtil.getProcessOutput.bind(undefined, "jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android " + apkPath + " androiddebugkey", { cwd: androidDirectory, noLogStdOut: true }));
}
}

Expand Down Expand Up @@ -228,8 +228,8 @@ class RNIOS extends Platform.IOS implements RNPlatform {

return this.getEmulatorManager().getTargetEmulator()
.then((targetEmulator: string) => {
var hashRegEx = /([0-9A-Z-]*)/g;
var hashWithParen = hashRegEx.exec(targetEmulator)[0];
var hashRegEx = /[(][0-9A-Z-]*[)]/g;
var hashWithParen = targetEmulator.match(hashRegEx)[0];
var hash = hashWithParen.substr(1, hashWithParen.length - 2);
return TestUtil.getProcessOutput("xcodebuild -workspace " + path.join(iOSProject, PluginTestingFramework.TestAppName) + ".xcworkspace -scheme " + PluginTestingFramework.TestAppName +
" -configuration Release -destination \"platform=iOS Simulator,id=" + hash + "\" -derivedDataPath build", { cwd: iOSProject, maxBuffer: 1024 * 1000 * 10, noLogStdOut: true });
Expand Down Expand Up @@ -435,10 +435,11 @@ class RNProjectManager extends ProjectManager {
return Q<string>(undefined)
.then(() => {
// Build if this scenario has not yet been built.
if (!RNProjectManager.currentScenarioHasBuilt[projectDirectory]) {
/* if (!RNProjectManager.currentScenarioHasBuilt[projectDirectory]) {
RNProjectManager.currentScenarioHasBuilt[projectDirectory] = true;
return (<RNPlatform><any>targetPlatform).buildApp(projectDirectory);
}
} */
return (<RNPlatform><any>targetPlatform).buildApp(projectDirectory);
})
.then(() => {
// Uninstall the app so that the app's data doesn't carry over between tests.
Expand Down Expand Up @@ -653,8 +654,8 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
(projectManager: ProjectManager, targetPlatform: Platform.IPlatform, done: MochaDone) => {
PluginTestingFramework.updateResponse = { updateInfo: PluginTestingFramework.createUpdateResponse(false, targetPlatform) };

/* pass an invalid path */
PluginTestingFramework.updatePackagePath = path.join(PluginTestingFramework.templatePath, "invalid_path.zip");
/* pass an invalid update url */
PluginTestingFramework.updateResponse.updateInfo.downloadURL = "invalid_url";

projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);

Expand Down Expand Up @@ -1346,7 +1347,7 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
})
.done(() => { done(); }, (e) => { done(e); });
}, false)
])
], undefined)
];

var rootTestBuilder = new PluginTestingFramework.TestBuilderDescribe("CodePush", testBuilderDescribes);
Expand Down

0 comments on commit 7e21b56

Please sign in to comment.