Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Killing the process #27

Closed
yuchi opened this issue Oct 3, 2014 · 10 comments
Closed

Killing the process #27

yuchi opened this issue Oct 3, 2014 · 10 comments

Comments

@yuchi
Copy link

yuchi commented Oct 3, 2014

Ok, there’s no way to kill the app and sim, but what about killing the titanium process?

Given a new option, "killFactor": function (log, kill) { kill(); } or "killFactor": /\d+ .* failed/i we could something like the following:

// ...
var killFactorType = Object.prototype.toString.call(options.killFactor).slice(8, -1);
var killFactor =
  killFactorType === 'Function' ? options.killFactor
  killFactorType === 'RegExp' ? function (data, kill) {
    if (options.killFactor.test(data)) kill();
  } :
  null;

var ti = spawn(getTitaniumPath(), args, {stdio: 'inherit'});

var closed = false;

if (killFactor) {
  ti.stdout.on('data', function (data) {
    killFactor(data, kill);
  });
}

function kill() {
  if (!closed) ti.kill();
}

ti.on('close', function(code) {
  closed = true;
  // ...
});

// ...
@yuchi
Copy link
Author

yuchi commented Oct 3, 2014

What we also need is the exit status of the task, so that I can use it for unit tests.

@yuchi
Copy link
Author

yuchi commented Oct 4, 2014

Here’s a working version: https://github.com/smclab/ti-superagent/blob/f5d1c0e59e57bc1edd3036b7269a5d58b1d480a7/tasks/titanium.js#L227

The problem is with colors by now. But that means that we just need to check for failureTest and successTest if none of them is set the pass { stdio: 'inherit' } to spawn().

@tonylukasavage
Copy link
Owner

The working version looks usable. Let me play with it a bit and maybe I'll incorporate it. Or if you want to make a PR and I can review/modify that, that'll work too.

FYI, that original killFactor code is pretty cryptic!

@yuchi
Copy link
Author

yuchi commented Oct 6, 2014

Sorry for that code! I’m still recovering from a few years of clever-code-illness!

We have a lot of different opportunities:

  • let the dev to pass a function as a test
  • let the dev to pass a regexp as a test
  • have a single test
  • have separated tests for success and failure
  • maybe more…

What do you expect from such a feature? What are the scenarios you can expect it to cover?

Here’s a few:

  1. Unit testing applications
  2. Unit testing modules’ test app
  3. Launching more than one app at the same time (we’re closing the log stream, not the app)

BTW point 3 opens another question: would you consider collaborating on a gulp-titanium plugin?
I’m slowly drifting in the stream-space…

@yuchi
Copy link
Author

yuchi commented Oct 10, 2014

I’d love any feedback on this.

I summon @Sophrinix as an automation geek, in attack position.
I summon @FokkeZB in defense position.

@yuchi
Copy link
Author

yuchi commented Oct 10, 2014

Also @lele85 as a unit tests geek.

@Sophrinix
Copy link

Why are we saying that there is no way to kill the simulator and app? Are we talking about iOS?
https://github.com/appcelerator/ioslib#force-stop-an-application-running-on-simulator might be our friend here.

@FokkeZB
Copy link
Contributor

FokkeZB commented Oct 10, 2014

Thx for spamming my mailbox @yuchi :)

@yuchi
Copy link
Author

yuchi commented Oct 10, 2014

  1. Both iOS and Android
  2. Stopping “from the inside” of the app, once tests have run, for example (so that we gain control again and grunt can move to other tasks)

@yuchi
Copy link
Author

yuchi commented Nov 20, 2014

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants