|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const fs = require('fs'); |
| 4 | +const test = require('tape'); |
| 5 | +const promisify = require('es6-promisify'); |
| 6 | +const pullout = require('pullout'); |
| 7 | +const request = require('request'); |
| 8 | + |
| 9 | +const before = require('./before'); |
| 10 | + |
| 11 | +const warp = (fn, ...a) => (...b) => fn(...b, ...a); |
| 12 | + |
| 13 | +const _pullout = promisify(pullout); |
| 14 | + |
| 15 | +const get = promisify((url, fn) => { |
| 16 | + fn(null, request(url)); |
| 17 | +}); |
| 18 | + |
| 19 | +test('cloudcmd: plugins', (t) => { |
| 20 | + const config = {}; |
| 21 | + const plugins = []; |
| 22 | + |
| 23 | + before(config, plugins, (port, after) => { |
| 24 | + get(`http://localhost:${port}/plugins.js`) |
| 25 | + .then(warp(_pullout, 'string')) |
| 26 | + .then((content) => { |
| 27 | + t.equal(content, '', 'should content be empty'); |
| 28 | + t.end(); |
| 29 | + after(); |
| 30 | + }) |
| 31 | + .catch((error) => { |
| 32 | + console.log(error); |
| 33 | + }); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +test('cloudcmd: plugins', (t) => { |
| 38 | + const config = {}; |
| 39 | + const plugins = [ |
| 40 | + __filename |
| 41 | + ]; |
| 42 | + |
| 43 | + before(config, plugins, (port, after) => { |
| 44 | + get(`http://localhost:${port}/plugins.js`) |
| 45 | + .then(warp(_pullout, 'string')) |
| 46 | + .then((content) => { |
| 47 | + const file = fs.readFileSync(__filename, 'utf8'); |
| 48 | + t.equal(content, file, 'should return file plugin content'); |
| 49 | + t.end(); |
| 50 | + after(); |
| 51 | + }) |
| 52 | + .catch((error) => { |
| 53 | + console.log(error); |
| 54 | + }); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +test('cloudcmd: plugins: load error', (t) => { |
| 59 | + const config = {}; |
| 60 | + const noEntry = __filename + Math.random(); |
| 61 | + const plugins = [ |
| 62 | + __filename, |
| 63 | + noEntry |
| 64 | + ]; |
| 65 | + |
| 66 | + const msg = `ENOENT: no such file or directory, open '${noEntry}'`; |
| 67 | + |
| 68 | + before(config, plugins, (port, after) => { |
| 69 | + get(`http://localhost:${port}/plugins.js`) |
| 70 | + .then(warp(_pullout, 'string')) |
| 71 | + .then((content) => { |
| 72 | + const file = fs.readFileSync(__filename, 'utf8') + msg; |
| 73 | + t.equal(content, file, 'should return file plugin content'); |
| 74 | + t.end(); |
| 75 | + after(); |
| 76 | + }) |
| 77 | + .catch((error) => { |
| 78 | + console.log(error); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
| 82 | + |
0 commit comments