From 2f585afb8e278e9a2bc014574a2a2bb0022b31e3 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Thu, 19 Dec 2019 04:51:32 +0000 Subject: [PATCH 1/5] refactor(test-extend-filter): async/await --- test/scripts/extend/filter.js | 47 ++++++++++++++++------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/test/scripts/extend/filter.js b/test/scripts/extend/filter.js index 1c9d88bf32..55bb42b759 100644 --- a/test/scripts/extend/filter.js +++ b/test/scripts/extend/filter.js @@ -66,16 +66,15 @@ describe('Filter', () => { f.list('test').map(item => item.priority).should.eql([5, 10, 15]); }); - it('unregister()', () => { + it('unregister()', async () => { const f = new Filter(); const filter = sinon.spy(); f.register('test', filter); f.unregister('test', filter); - return f.exec('test').then(() => { - filter.called.should.be.false; - }); + await f.exec('test'); + filter.called.should.eql(false); }); it('unregister() - type is required', () => { @@ -117,7 +116,7 @@ describe('Filter', () => { f.list('foo').length.should.eql(0); }); - it('exec()', () => { + it('exec()', async () => { const f = new Filter(); const filter1 = sinon.spy(data => { @@ -134,14 +133,13 @@ describe('Filter', () => { f.register('test', filter1); f.register('test', filter2); - return f.exec('test', '').then(data => { - filter1.calledOnce.should.be.true; - filter2.calledOnce.should.be.true; - data.should.eql('foobar'); - }); + const data = await f.exec('test', ''); + filter1.calledOnce.should.eql(true); + filter2.calledOnce.should.eql(true); + data.should.eql('foobar'); }); - it('exec() - pointer', () => { + it('exec() - pointer', async () => { const f = new Filter(); const filter1 = sinon.spy(data => { @@ -158,14 +156,13 @@ describe('Filter', () => { f.register('test', filter1); f.register('test', filter2); - return f.exec('test', {}).then(data => { - filter1.calledOnce.should.be.true; - filter2.calledOnce.should.be.true; - data.should.eql({foo: 1, bar: 2}); - }); + const data = await f.exec('test', {}); + filter1.calledOnce.should.eql(true); + filter2.calledOnce.should.eql(true); + data.should.eql({ foo: 1, bar: 2 }); }); - it('exec() - args', () => { + it('exec() - args', async () => { const f = new Filter(); const filter1 = sinon.spy((data, arg1, arg2) => { @@ -181,15 +178,14 @@ describe('Filter', () => { f.register('test', filter1); f.register('test', filter2); - return f.exec('test', {}, { + await f.exec('test', {}, { args: [1, 2] - }).then(() => { - filter1.calledOnce.should.be.true; - filter2.calledOnce.should.be.true; }); + filter1.calledOnce.should.eql(true); + filter2.calledOnce.should.eql(true); }); - it('exec() - context', () => { + it('exec() - context', async () => { const f = new Filter(); const ctx = {foo: 1, bar: 2}; @@ -204,10 +200,9 @@ describe('Filter', () => { f.register('test', filter1); f.register('test', filter2); - return f.exec('test', {}, {context: ctx}).then(() => { - filter1.calledOnce.should.be.true; - filter2.calledOnce.should.be.true; - }); + await f.exec('test', {}, { context: ctx }); + filter1.calledOnce.should.eql(true); + filter2.calledOnce.should.eql(true); }); it('execSync()', () => { From 607a06b846b935c5dba5adab5fdffd8c0d070c09 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Thu, 19 Dec 2019 04:52:25 +0000 Subject: [PATCH 2/5] refactor(test-extend-filter): destructure --- test/scripts/extend/filter.js | 40 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/scripts/extend/filter.js b/test/scripts/extend/filter.js index 55bb42b759..2b9eb1063b 100644 --- a/test/scripts/extend/filter.js +++ b/test/scripts/extend/filter.js @@ -1,6 +1,6 @@ 'use strict'; -const sinon = require('sinon'); +const { spy } = require('sinon'); describe('Filter', () => { const Filter = require('../../../lib/extend/filter'); @@ -68,7 +68,7 @@ describe('Filter', () => { it('unregister()', async () => { const f = new Filter(); - const filter = sinon.spy(); + const filter = spy(); f.register('test', filter); f.unregister('test', filter); @@ -79,7 +79,7 @@ describe('Filter', () => { it('unregister() - type is required', () => { const f = new Filter(); - const errorCallback = sinon.spy(err => { + const errorCallback = spy(err => { err.should.have.property('message', 'type is required'); }); @@ -94,7 +94,7 @@ describe('Filter', () => { it('unregister() - fn must be a function', () => { const f = new Filter(); - const errorCallback = sinon.spy(err => { + const errorCallback = spy(err => { err.should.have.property('message', 'fn must be a function'); }); @@ -119,12 +119,12 @@ describe('Filter', () => { it('exec()', async () => { const f = new Filter(); - const filter1 = sinon.spy(data => { + const filter1 = spy(data => { data.should.eql(''); return data + 'foo'; }); - const filter2 = sinon.spy(data => { + const filter2 = spy(data => { filter1.calledOnce.should.be.true; data.should.eql('foo'); return data + 'bar'; @@ -142,12 +142,12 @@ describe('Filter', () => { it('exec() - pointer', async () => { const f = new Filter(); - const filter1 = sinon.spy(data => { + const filter1 = spy(data => { data.should.eql({}); data.foo = 1; }); - const filter2 = sinon.spy(data => { + const filter2 = spy(data => { filter1.calledOnce.should.be.true; data.should.eql({foo: 1}); data.bar = 2; @@ -165,12 +165,12 @@ describe('Filter', () => { it('exec() - args', async () => { const f = new Filter(); - const filter1 = sinon.spy((data, arg1, arg2) => { + const filter1 = spy((data, arg1, arg2) => { arg1.should.eql(1); arg2.should.eql(2); }); - const filter2 = sinon.spy((data, arg1, arg2) => { + const filter2 = spy((data, arg1, arg2) => { arg1.should.eql(1); arg2.should.eql(2); }); @@ -189,11 +189,11 @@ describe('Filter', () => { const f = new Filter(); const ctx = {foo: 1, bar: 2}; - const filter1 = sinon.spy(function(data) { + const filter1 = spy(function(data) { this.should.eql(ctx); }); - const filter2 = sinon.spy(function(data) { + const filter2 = spy(function(data) { this.should.eql(ctx); }); @@ -208,12 +208,12 @@ describe('Filter', () => { it('execSync()', () => { const f = new Filter(); - const filter1 = sinon.spy(data => { + const filter1 = spy(data => { data.should.eql(''); return data + 'foo'; }); - const filter2 = sinon.spy(data => { + const filter2 = spy(data => { filter1.calledOnce.should.be.true; data.should.eql('foo'); return data + 'bar'; @@ -230,12 +230,12 @@ describe('Filter', () => { it('execSync() - pointer', () => { const f = new Filter(); - const filter1 = sinon.spy(data => { + const filter1 = spy(data => { data.should.eql({}); data.foo = 1; }); - const filter2 = sinon.spy(data => { + const filter2 = spy(data => { filter1.calledOnce.should.be.true; data.should.eql({foo: 1}); data.bar = 2; @@ -252,12 +252,12 @@ describe('Filter', () => { it('execSync() - args', () => { const f = new Filter(); - const filter1 = sinon.spy((data, arg1, arg2) => { + const filter1 = spy((data, arg1, arg2) => { arg1.should.eql(1); arg2.should.eql(2); }); - const filter2 = sinon.spy((data, arg1, arg2) => { + const filter2 = spy((data, arg1, arg2) => { arg1.should.eql(1); arg2.should.eql(2); }); @@ -277,11 +277,11 @@ describe('Filter', () => { const f = new Filter(); const ctx = {foo: 1, bar: 2}; - const filter1 = sinon.spy(function(data) { + const filter1 = spy(function(data) { this.should.eql(ctx); }); - const filter2 = sinon.spy(function(data) { + const filter2 = spy(function(data) { this.should.eql(ctx); }); From 166e3f5a15ad9bfbd18e98b0cce61e64b5a1a9df Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Thu, 19 Dec 2019 04:54:25 +0000 Subject: [PATCH 3/5] refactor(test-extend-generator): async/await --- test/scripts/extend/generator.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/scripts/extend/generator.js b/test/scripts/extend/generator.js index ee713bf075..b8f74c5bbf 100644 --- a/test/scripts/extend/generator.js +++ b/test/scripts/extend/generator.js @@ -26,16 +26,15 @@ describe('Generator', () => { } }); - it('register() - promisify', () => { + it('register() - promisify', async () => { const g = new Generator(); g.register('test', (locals, render, callback) => { callback(null, 'foo'); }); - g.get('test')({}, {}).then(result => { - result.should.eql('foo'); - }); + const result = await g.get('test')({}, {}); + result.should.eql('foo'); }); it('get()', () => { From 6bf86306da89af068e9115006dca80258d55377c Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Thu, 19 Dec 2019 04:55:54 +0000 Subject: [PATCH 4/5] refactor(test-extend-migrator): async/await --- test/scripts/extend/migrator.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/scripts/extend/migrator.js b/test/scripts/extend/migrator.js index a00a341945..a05fa6bc3d 100644 --- a/test/scripts/extend/migrator.js +++ b/test/scripts/extend/migrator.js @@ -45,7 +45,7 @@ describe('Migrator', () => { }); }); - it('register() - Promise.method', () => { + it('register() - Promise.method', async () => { const d = new Migrator(); d.register('test', args => { @@ -53,11 +53,11 @@ describe('Migrator', () => { return 'foo'; }); - d.get('test')({ + const result = await d.get('test')({ foo: 'bar' - }).then(result => { - result.should.eql('foo'); }); + + result.should.eql('foo'); }); it('list()', () => { From fcc8ae5ff3719d81ff1f56c3f80620a2c9e9ecc5 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Thu, 19 Dec 2019 05:00:05 +0000 Subject: [PATCH 5/5] refactor(test-extend-renderer): async/await --- test/scripts/extend/renderer.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/scripts/extend/renderer.js b/test/scripts/extend/renderer.js index 5d3de80393..42072dfd0b 100644 --- a/test/scripts/extend/renderer.js +++ b/test/scripts/extend/renderer.js @@ -48,7 +48,7 @@ describe('Renderer', () => { } }); - it('register() - promisify', () => { + it('register() - promisify', async () => { const r = new Renderer(); // async @@ -56,16 +56,14 @@ describe('Renderer', () => { callback(null, 'foo'); }); - r.get('yaml')({}, {}).then(result => { - result.should.eql('foo'); - }); + const yaml = await r.get('yaml')({}, {}); + yaml.should.eql('foo'); // sync r.register('swig', 'html', (data, options) => 'foo', true); - r.get('swig')({}, {}).then(result => { - result.should.eql('foo'); - }); + const swig = await r.get('swig')({}, {}); + swig.should.eql('foo'); }); it('register() - compile', () => {