diff --git a/test/scripts/extend/filter.js b/test/scripts/extend/filter.js index 1c9d88bf32..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'); @@ -66,21 +66,20 @@ 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(); + const filter = 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', () => { const f = new Filter(); - const errorCallback = sinon.spy(err => { + const errorCallback = spy(err => { err.should.have.property('message', 'type is required'); }); @@ -95,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'); }); @@ -117,15 +116,15 @@ describe('Filter', () => { f.list('foo').length.should.eql(0); }); - it('exec()', () => { + 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'; @@ -134,22 +133,21 @@ 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 => { + 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; @@ -158,22 +156,21 @@ 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) => { + 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); }); @@ -181,44 +178,42 @@ 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}; - 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); }); 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()', () => { 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'; @@ -235,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; @@ -257,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); }); @@ -282,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); }); 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()', () => { 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()', () => { 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', () => {