mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
test(static) add
This commit is contained in:
parent
94fcdfcded
commit
e8f91f4908
1 changed files with 58 additions and 0 deletions
58
test/static.js
Normal file
58
test/static.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const test = require('tape');
|
||||
const promisify = require('es6-promisify');
|
||||
const pullout = require('pullout');
|
||||
const request = require('request');
|
||||
|
||||
const before = require('./before');
|
||||
|
||||
const warp = (fn, ...a) => (...b) => fn(...b, ...a);
|
||||
|
||||
const _pullout = promisify(pullout);
|
||||
|
||||
const get = promisify((url, fn) => {
|
||||
fn(null, request(url));
|
||||
});
|
||||
|
||||
test('cloudcmd: staatic', (t) => {
|
||||
before({}, (port, after) => {
|
||||
const name = 'package.json';
|
||||
|
||||
get(`http://localhost:${port}/${name}`)
|
||||
.then(warp(_pullout, 'string'))
|
||||
.then(JSON.parse)
|
||||
.then((json) => {
|
||||
t.equal(json.name, 'cloudcmd', 'should download file');
|
||||
t.end();
|
||||
after();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: staatic: not found', (t) => {
|
||||
const name = 'package.json';
|
||||
|
||||
before({}, (port, after) => {
|
||||
const name = Math.random();
|
||||
get(`http://localhost:${port}/${name}`)
|
||||
.then((res) => {
|
||||
res.on('response', (res) => {
|
||||
t.equal(res.statusCode, 404, 'should return 404');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue