diff --git a/test/plugins.js b/test/plugins.js index 43efd6af..9f8d4c5c 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -2,58 +2,54 @@ const fs = require('fs'); const test = require('tape'); -const {promisify} = require('es6-promisify'); -const pullout = require('pullout'); -const request = require('request'); +const cloudcmd = require('..'); -const before = require('./before'); +const config = { + auth: false, +}; -const warp = (fn, ...a) => (...b) => fn(...b, ...a); +const options = { + config +}; -const _pullout = promisify(pullout); - -const get = promisify((url, fn) => { - fn(null, request(url)); +const {request} = require('serve-once')(cloudcmd, { + options, }); -test('cloudcmd: plugins', (t) => { +test('cloudcmd: plugins', async (t) => { const plugins = []; + const options = { + plugins, + }; - before({plugins}, (port, after) => { - get(`http://localhost:${port}/plugins.js`) - .then(warp(_pullout, 'string')) - .then((content) => { - t.equal(content, '', 'should content be empty'); - t.end(); - after(); - }) - .catch((error) => { - console.log(error); - }); + const {body} = await request.get('/plugins.js', { + options, }); + + t.equal(body, '', 'should content be empty'); + t.end(); }); -test('cloudcmd: plugins', (t) => { +test('cloudcmd: plugins', async (t) => { const plugins = [ __filename ]; - before({plugins}, (port, after) => { - get(`http://localhost:${port}/plugins.js`) - .then(warp(_pullout, 'string')) - .then((content) => { - const file = fs.readFileSync(__filename, 'utf8'); - t.equal(content, file, 'should return file plugin content'); - t.end(); - after(); - }) - .catch((error) => { - console.log(error); - }); + const options = { + plugins, + }; + + const {body} = await request.get('/plugins.js', { + options, }); + + const file = fs.readFileSync(__filename, 'utf8'); + + t.equal(body, file, 'should return file plugin content'); + t.end(); }); -test('cloudcmd: plugins: load error', (t) => { +test('cloudcmd: plugins: load error', async (t) => { const noEntry = __filename + Math.random(); const plugins = [ __filename, @@ -62,18 +58,17 @@ test('cloudcmd: plugins: load error', (t) => { const msg = `ENOENT: no such file or directory, open '${noEntry}'`; - before({plugins}, (port, after) => { - get(`http://localhost:${port}/plugins.js`) - .then(warp(_pullout, 'string')) - .then((content) => { - const file = fs.readFileSync(__filename, 'utf8') + msg; - t.equal(content, file, 'should return file plugin content'); - t.end(); - after(); - }) - .catch((error) => { - console.log(error); - }); + const options = { + plugins, + }; + + const {body} = await request.get('/plugins.js', { + options, }); + + const file = fs.readFileSync(__filename, 'utf8') + msg; + + t.equal(body, file, 'should return file plugin content'); + t.end(); });