From f0b76b7ea87e9d3d6b1ff36e9d312dc66043ad63 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 4 Oct 2018 11:50:15 -0700 Subject: [PATCH] Use async/await in tests --- .../base/parts/ipc/test/node/ipc.cp.test.ts | 18 +++++------ .../base/parts/ipc/test/node/ipc.net.test.ts | 23 +++++++------- src/vs/base/parts/ipc/test/node/ipc.test.ts | 30 +++++++++++-------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/vs/base/parts/ipc/test/node/ipc.cp.test.ts b/src/vs/base/parts/ipc/test/node/ipc.cp.test.ts index 7be2fb0a9ae..6aa818040b6 100644 --- a/src/vs/base/parts/ipc/test/node/ipc.cp.test.ts +++ b/src/vs/base/parts/ipc/test/node/ipc.cp.test.ts @@ -60,20 +60,18 @@ suite('IPC, Child Process', () => { let count = 0; const disposable = service.onMarco(() => count++); - const result = service.marco().then(answer => { + const result = service.marco().then(async answer => { assert.equal(answer, 'polo'); assert.equal(count, 1); - return service.marco().then(answer => { - assert.equal(answer, 'polo'); - assert.equal(count, 2); - disposable.dispose(); + const answer_1 = await service.marco(); + assert.equal(answer_1, 'polo'); + assert.equal(count, 2); + disposable.dispose(); - return service.marco().then(answer => { - assert.equal(answer, 'polo'); - assert.equal(count, 2); - }); - }); + const answer_2 = await service.marco(); + assert.equal(answer_2, 'polo'); + assert.equal(count, 2); }); return always(result, () => client.dispose()); diff --git a/src/vs/base/parts/ipc/test/node/ipc.net.test.ts b/src/vs/base/parts/ipc/test/node/ipc.net.test.ts index 667cc674d41..c094414be18 100644 --- a/src/vs/base/parts/ipc/test/node/ipc.net.test.ts +++ b/src/vs/base/parts/ipc/test/node/ipc.net.test.ts @@ -38,29 +38,28 @@ suite('IPC, Socket Protocol', () => { stream = new MockDuplex(); }); - test('read/write', () => { + test('read/write', async () => { const a = new Protocol(stream); const b = new Protocol(stream); - return new Promise(resolve => { + await new Promise(resolve => { const sub = b.onMessage(data => { sub.dispose(); assert.equal(data.toString(), 'foobarfarboo'); resolve(null); }); a.send(Buffer.from('foobarfarboo')); - }).then(() => { - return new Promise(resolve => { - const sub = b.onMessage(data => { - sub.dispose(); - assert.equal(data.readInt8(0), 123); - resolve(null); - }); - const buffer = Buffer.allocUnsafe(1); - buffer.writeInt8(123, 0); - a.send(buffer); + }); + return new Promise(resolve => { + const sub_1 = b.onMessage(data => { + sub_1.dispose(); + assert.equal(data.readInt8(0), 123); + resolve(null); }); + const buffer = Buffer.allocUnsafe(1); + buffer.writeInt8(123, 0); + a.send(buffer); }); }); diff --git a/src/vs/base/parts/ipc/test/node/ipc.test.ts b/src/vs/base/parts/ipc/test/node/ipc.test.ts index 7cf1c1840ff..df09c38af14 100644 --- a/src/vs/base/parts/ipc/test/node/ipc.test.ts +++ b/src/vs/base/parts/ipc/test/node/ipc.test.ts @@ -231,23 +231,27 @@ suite('Base IPC', function () { server.dispose(); }); - test('call success', function () { - return ipcService.marco() - .then(r => assert.equal(r, 'polo')); + test('call success', async function () { + const r = await ipcService.marco(); + return assert.equal(r, 'polo'); }); - test('call error', function () { - return ipcService.error('nice error').then( - () => assert.fail('should not reach here'), - err => assert.equal(err.message, 'nice error') - ); + test('call error', async function () { + try { + await ipcService.error('nice error'); + return assert.fail('should not reach here'); + } catch (err) { + return assert.equal(err.message, 'nice error'); + } }); - test('cancel call with cancelled cancellation token', function () { - return ipcService.neverCompleteCT(CancellationToken.Cancelled).then( - _ => assert.fail('should not reach here'), - err => assert(err.message === 'Canceled') - ); + test('cancel call with cancelled cancellation token', async function () { + try { + await ipcService.neverCompleteCT(CancellationToken.Cancelled); + return assert.fail('should not reach here'); + } catch (err) { + return assert(err.message === 'Canceled'); + } }); test('cancel call with cancellation token (sync)', function () { -- GitLab