Description: replace ava by jest
 Generated using jest-codemods
Author: Xavier Guimard <yadd@debian.org>
Forwarded: not-needed
Last-Update: 2020-12-16

--- a/test.js
+++ b/test.js
@@ -1,5 +1,4 @@
-import {serial as test} from 'ava';
-import hookStd from '.';
+const hookStd = require('.');
 
 const {stdout, stderr} = process;
 
@@ -19,73 +18,33 @@
 	});
 }
 
-test.beforeEach(restore);
-test.afterEach(restore);
+beforeEach(restore);
+afterEach(restore);
 
-test.cb('hook stdout & stderr', t => {
-	t.plan(2);
-
-	let i = 0;
-
-	const promise = hookStd(string => {
-		if (string === 'foo' || string === 'bar') {
-			t.pass();
-		}
-
-		if (++i === 2) {
-			promise.unhook();
-			t.end();
-		}
-	});
-
-	process.stdout.write('foo');
-	process.stderr.write('bar');
-});
-
-test.cb('hook stdout', t => {
-	t.plan(1);
+test('hook stdout', done => {
+	expect.assertions(1);
 
 	const promise = hookStd.stdout(string => {
-		t.is(string, 'foo');
+		expect(string).toBe('foo');
 		promise.unhook();
-		t.end();
+		done();
 	});
 
 	process.stdout.write('foo');
 });
 
-test.cb('hook stderr', t => {
-	t.plan(1);
+test('hook stderr', done => {
+	expect.assertions(1);
 
 	const promise = hookStd.stderr(string => {
-		t.is(string, 'foo');
+		expect(string).toBe('foo');
 		promise.unhook();
-		t.end();
+		done();
 	});
 
 	process.stderr.write('foo');
 });
 
-test.cb('hook custom stream', t => {
-	t.plan(1);
-	const streams = [{write: () => {}}];
-
-	let i = 0;
-
-	const promise = hookStd({streams}, string => {
-		if (string === 'foo') {
-			t.pass();
-		}
-
-		if (++i === 1) {
-			promise.unhook();
-			t.end();
-		}
-	});
-
-	streams[0].write('foo');
-});
-
 function loggingWrite(log, returnValueValue) {
 	return (...items) => {
 		while (items[items.length - 1] === undefined) {
@@ -98,8 +57,8 @@
 	};
 }
 
-test('passes through the return value of the underlying write call', t => {
-	t.plan(3);
+test('passes through the return value of the underlying write call', () => {
+	expect.assertions(3);
 
 	const log = [];
 	let returnValue = false;
@@ -110,51 +69,14 @@
 
 	hookStd.stdout({silent: false}, string => string);
 
-	t.false(process.stdout.write('foo'));
+	expect(process.stdout.write('foo')).toBe(false);
 	returnValue = true;
-	t.true(process.stdout.write('bar'));
-	t.deepEqual(log, [['foo'], ['bar']]);
-});
-
-test('if silent, returns true by default', t => {
-	t.plan(2);
-	const log = [];
-
-	process.stdout = {
-		write: () => t.fail()
-	};
-
-	hookStd.stdout(string => {
-		log.push(string);
-		return string;
-	});
-
-	t.true(process.stdout.write('foo'));
-	t.deepEqual(log, ['foo']);
-});
-
-test('if silent, callback can return a boolean', t => {
-	t.plan(3);
-	const log = [];
-	let returnValue = true;
-
-	process.stdout = {
-		write: () => t.fail()
-	};
-
-	hookStd.stdout(string => {
-		log.push(string);
-		return returnValue;
-	});
-
-	t.true(process.stdout.write('foo'));
-	returnValue = false;
-	t.false(process.stdout.write('bar'));
-	t.deepEqual(log, ['foo', 'bar']);
+	expect(process.stdout.write('bar')).toBe(true);
+	expect(log).toEqual([['foo'], ['bar']]);
 });
 
-test('callback can return a buffer', t => {
-	t.plan(3);
+test('callback can return a buffer', () => {
+	expect.assertions(3);
 	const log = [];
 
 	process.stdout = {
@@ -163,13 +85,13 @@
 
 	hookStd.stdout({silent: false}, string => Buffer.from(string));
 
-	t.true(process.stdout.write('foo'));
-	t.true(process.stdout.write('bar'));
-	t.deepEqual(log, [[Buffer.from('foo')], [Buffer.from('bar')]]);
+	expect(process.stdout.write('foo')).toBe(true);
+	expect(process.stdout.write('bar')).toBe(true);
+	expect(log).toEqual([[Buffer.from('foo')], [Buffer.from('bar')]]);
 });
 
-test('if no options are assigned, behave as silent', t => {
-	t.plan(1);
+test('if no options are assigned, behave as silent', () => {
+	expect.assertions(1);
 	const log = [];
 	let returnValue = false;
 
@@ -181,11 +103,11 @@
 
 	process.stdout.write('foo');
 	returnValue = true;
-	t.deepEqual(log, []);
+	expect(log).toEqual([]);
 });
 
-test('if once option is true, only the first write is silent', t => {
-	t.plan(1);
+test('if once option is true, only the first write is silent', () => {
+	expect.assertions(1);
 	let returnValue;
 	const log = [];
 
@@ -199,11 +121,11 @@
 	process.stdout.write('bar');
 	process.stdout.write('unicorn');
 
-	t.deepEqual(log, [['bar'], ['unicorn']]);
+	expect(log).toEqual([['bar'], ['unicorn']]);
 });
 
-test('if once option is true and silent is false, hook only prints the first write and std prints all writes', t => {
-	t.plan(4);
+test('if once option is true and silent is false, hook only prints the first write and std prints all writes', () => {
+	expect.assertions(4);
 	let hookReturnValue;
 	const log = [];
 
@@ -217,37 +139,37 @@
 	});
 
 	process.stdout.write('foo');
-	t.deepEqual(hookReturnValue, 'foo');
-	t.deepEqual(log, [['foo']]);
+	expect(hookReturnValue).toEqual('foo');
+	expect(log).toEqual([['foo']]);
 
 	hookReturnValue = false;
 
 	process.stdout.write('bar');
-	t.deepEqual(hookReturnValue, false);
-	t.deepEqual(log, [['foo'], ['bar']]);
+	expect(hookReturnValue).toEqual(false);
+	expect(log).toEqual([['foo'], ['bar']]);
 });
 
-test('output is converted to string', t => {
-	t.plan(4);
+test('output is converted to string', () => {
+	expect.assertions(4);
 	const log = [];
 
 	hookStd.stdout(string => log.push(string));
 
 	process.stdout.write('foo');
-	t.deepEqual(log, ['foo']);
+	expect(log).toEqual(['foo']);
 
 	process.stdout.write(123);
-	t.deepEqual(log, ['foo', '123']);
+	expect(log).toEqual(['foo', '123']);
 
 	process.stdout.write({});
-	t.deepEqual(log, ['foo', '123', '[object Object]']);
+	expect(log).toEqual(['foo', '123', '[object Object]']);
 
 	process.stdout.write(true);
-	t.deepEqual(log, ['foo', '123', '[object Object]', 'true']);
+	expect(log).toEqual(['foo', '123', '[object Object]', 'true']);
 });
 
-test('string returned by callback is converted to correct encoding', t => {
-	t.plan(2);
+test('string returned by callback is converted to correct encoding', () => {
+	expect.assertions(2);
 
 	process.stdout = {
 		write: output => output
@@ -255,12 +177,12 @@
 
 	hookStd.stdout({silent: false}, () => 'tést');
 
-	t.is(process.stdout.write('foo', 'hex'), '74c3a97374');
-	t.is(process.stdout.write('bar', 'ascii'), 'tC)st');
+	expect(process.stdout.write('foo', 'hex')).toBe('74c3a97374');
+	expect(process.stdout.write('bar', 'ascii')).toBe('tC)st');
 });
 
-test('string returned by callback is not converted if encoding is invalid', t => {
-	t.plan(4);
+test('string returned by callback is not converted if encoding is invalid', () => {
+	expect.assertions(4);
 
 	process.stdout = {
 		write: output => output
@@ -268,28 +190,28 @@
 
 	hookStd.stdout({silent: false}, () => 'tést');
 
-	t.is(process.stdout.write('foo', 123), 'tést');
-	t.is(process.stdout.write('bar', null), 'tést');
-	t.is(process.stdout.write('ping', {}), 'tést');
-	t.is(process.stdout.write('pong', () => {}), 'tést');
+	expect(process.stdout.write('foo', 123)).toBe('tést');
+	expect(process.stdout.write('bar', null)).toBe('tést');
+	expect(process.stdout.write('ping', {})).toBe('tést');
+	expect(process.stdout.write('pong', () => {})).toBe('tést');
 });
 
-test('promise resolves when stdout & stderr are hooked and released via promise unhook method', async t => {
-	t.plan(1);
+test('promise resolves when stdout & stderr are hooked and released via promise unhook method', async () => {
+	expect.assertions(1);
 	const log = [];
 
 	const promise = hookStd(string => log.push(string));
 
 	process.stdout.write('foo');
 	process.stderr.write('bar');
-	t.deepEqual(log, ['foo', 'bar']);
+	expect(log).toEqual(['foo', 'bar']);
 
 	promise.unhook();
 	await promise;
 });
 
-test('promise resolves when stdout & stderr are hooked and released via callback', async t => {
-	t.plan(1);
+test('promise resolves when stdout & stderr are hooked and released via callback', async () => {
+	expect.assertions(1);
 	const log = [];
 
 	const promise = hookStd((string, unhook) => {
@@ -299,33 +221,33 @@
 
 	process.stdout.write('foo');
 	process.stderr.write('bar');
-	t.deepEqual(log, ['foo', 'bar']);
+	expect(log).toEqual(['foo', 'bar']);
 
 	await promise;
 });
 
-test('promise resolves when stdout is released via promise unhook method', async t => {
-	t.plan(1);
+test('promise resolves when stdout is released via promise unhook method', async () => {
+	expect.assertions(1);
 	const promise = hookStd.stdout(string => {
-		t.is(string, 'foo');
+		expect(string).toBe('foo');
 	});
 	process.stdout.write('foo');
 	promise.unhook();
 	await promise;
 });
 
-test('promise resolves when stderr is released via promise unhook method', async t => {
-	t.plan(1);
+test('promise resolves when stderr is released via promise unhook method', async () => {
+	expect.assertions(1);
 	const promise = hookStd.stderr(string => {
-		t.is(string, 'foo');
+		expect(string).toBe('foo');
 	});
 	process.stderr.write('foo');
 	promise.unhook();
 	await promise;
 });
 
-test('promise resolves when streams are hooked and released via callback', async t => {
-	t.plan(1);
+test('promise resolves when streams are hooked and released via callback', async () => {
+	expect.assertions(1);
 	const log = [];
 	const streams = [{write: () => {}}, {write: () => {}}];
 
@@ -336,7 +258,7 @@
 
 	streams[0].write('foo');
 	streams[1].write('bar');
-	t.deepEqual(log, ['foo', 'bar']);
+	expect(log).toEqual(['foo', 'bar']);
 
 	await promise;
 });
