From 02fc6a17a9c33689b5babb83f4b9e2a6b8e57479 Mon Sep 17 00:00:00 2001
From: Mark Wubben <mark@novemberborn.net>
Date: Wed, 23 Mar 2016 15:37:52 +0000
Subject: [PATCH 1/3] remove node 0.10 sigterm code handling

The child process is no longer killed from the main process, instead it exits
upon receiving an 'exit' message. This makes the changes from
<https://github.com/sindresorhus/ava/pull/155> redundant.
---
 lib/fork.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/fork.js b/lib/fork.js
index f8d5bb694..90b087a7e 100644
--- a/lib/fork.js
+++ b/lib/fork.js
@@ -79,7 +79,7 @@ module.exports = function (file, opts) {
 		});
 
 		ps.on('exit', function (code) {
-			if (code > 0 && code !== 143) {
+			if (code > 0) {
 				return reject(new AvaError(relFile + ' exited with a non-zero exit code: ' + code));
 			}
 

From 96e1263165a18d9d99fb54deb15d99fed8320017 Mon Sep 17 00:00:00 2001
From: Mark Wubben <mark@novemberborn.net>
Date: Wed, 23 Mar 2016 15:39:19 +0000
Subject: [PATCH 2/3] test fork rejection behavior

---
 test/fixture/immediate-3-exit.js |  1 +
 test/fork.js                     | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 test/fixture/immediate-3-exit.js

diff --git a/test/fixture/immediate-3-exit.js b/test/fixture/immediate-3-exit.js
new file mode 100644
index 000000000..cd0920add
--- /dev/null
+++ b/test/fixture/immediate-3-exit.js
@@ -0,0 +1 @@
+process.exit(3);
diff --git a/test/fork.js b/test/fork.js
index b2406db24..6a553a2a4 100644
--- a/test/fork.js
+++ b/test/fork.js
@@ -60,6 +60,22 @@ test('exit after tests are finished', function (t) {
 		});
 });
 
+test('rejects promise if the process exits with a non-zero code', function (t) {
+	return fork(fixture('immediate-3-exit.js'))
+		.catch(function (err) {
+			t.is(err.name, 'AvaError');
+			t.is(err.message, path.join('test', 'fixture', 'immediate-3-exit.js') + ' exited with a non-zero exit code: 3');
+		});
+});
+
+test('rejects promise if the process exits without results', function (t) {
+	return fork(fixture('immediate-0-exit.js'))
+		.catch(function (err) {
+			t.is(err.name, 'AvaError');
+			t.is(err.message, 'Test results were not received from ' + path.join('test', 'fixture', 'immediate-0-exit.js'));
+		});
+});
+
 test('fake timers do not break duration', function (t) {
 	fork(fixture('fake-timers.js'))
 		.run({})

From 8949b85be4b6b7072dd35cc493c229b19d4b8299 Mon Sep 17 00:00:00 2001
From: Mark Wubben <mark@novemberborn.net>
Date: Wed, 23 Mar 2016 15:45:33 +0000
Subject: [PATCH 3/3] reject test runs when forks exit with an unexpected
 signal

---
 lib/fork.js  |  6 +++++-
 test/fork.js | 12 ++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/lib/fork.js b/lib/fork.js
index 90b087a7e..25bef8ff9 100644
--- a/lib/fork.js
+++ b/lib/fork.js
@@ -78,11 +78,15 @@ module.exports = function (file, opts) {
 			send(ps, 'teardown');
 		});
 
-		ps.on('exit', function (code) {
+		ps.on('exit', function (code, signal) {
 			if (code > 0) {
 				return reject(new AvaError(relFile + ' exited with a non-zero exit code: ' + code));
 			}
 
+			if (code === null && signal) {
+				return reject(new AvaError(relFile + ' exited due to ' + signal));
+			}
+
 			if (results) {
 				resolve(results);
 			} else {
diff --git a/test/fork.js b/test/fork.js
index 6a553a2a4..274f6ddc3 100644
--- a/test/fork.js
+++ b/test/fork.js
@@ -76,6 +76,18 @@ test('rejects promise if the process exits without results', function (t) {
 		});
 });
 
+test('rejects promise if the process is killed', function (t) {
+	var forked = fork(fixture('es2015.js'));
+	return forked
+		.on('stats', function () {
+			this.kill('SIGKILL');
+		})
+		.catch(function (err) {
+			t.is(err.name, 'AvaError');
+			t.is(err.message, path.join('test', 'fixture', 'es2015.js') + ' exited due to SIGKILL');
+		});
+});
+
 test('fake timers do not break duration', function (t) {
 	fork(fixture('fake-timers.js'))
 		.run({})