File tree Expand file tree Collapse file tree 5 files changed +80
-17
lines changed
Ch4_AdvancedPromises/test Expand file tree Collapse file tree 5 files changed +80
-17
lines changed Original file line number Diff line number Diff line change 11var assert = require ( 'power-assert' ) ;
22var getURL = require ( "../src/xhr-promise" ) . getURL ;
3-
4- require ( "http-echo" ) ;
3+ var echoServer = require ( "../../test/echo-server" ) ;
54describe ( '#getURL' , function ( ) {
5+ beforeEach ( ( ) => {
6+ return echoServer . start ( ) ;
7+ } ) ;
8+ afterEach ( ( ) => {
9+ return echoServer . stop ( ) ;
10+ } ) ;
611 describe ( "when get data" , function ( ) {
712 it ( "should resolve with value" , function ( ) {
813 var URL = "http://localhost:3000/?status=200&body=text" ;
@@ -19,4 +24,4 @@ describe('#getURL', function () {
1924 } ) ;
2025 } ) ;
2126 } ) ;
22- } ) ;
27+ } ) ;
Original file line number Diff line number Diff line change 11"use strict" ;
22var assert = require ( 'power-assert' ) ;
33var getURL = require ( "../src/deferred/xhr-deferred" ) . getURL ;
4+ var echoServer = require ( "../../test/echo-server" ) ;
45
5- require ( "http-echo" ) ;
66describe ( '#cancelableXHR' , function ( ) {
7+ beforeEach ( ( ) => {
8+ return echoServer . start ( ) ;
9+ } ) ;
10+ afterEach ( ( ) => {
11+ return echoServer . stop ( ) ;
12+ } ) ;
713 describe ( "when get data" , function ( ) {
814 it ( "should resolve with value" , function ( ) {
915 var URL = "http://localhost:3000/?status=200&body=text" ;
@@ -21,4 +27,4 @@ describe('#cancelableXHR', function () {
2127 } ) ;
2228 } ) ;
2329
24- } ) ;
30+ } ) ;
Original file line number Diff line number Diff line change 1313 "build-js-min" : " gulp build-js-min" ,
1414 "embed" : " gulp embed" ,
1515 "lint-html" : " gulp lint-html" ,
16- "textlint" : " textlint -f pretty-error Appendix-*/ Ch*/" ,
17- "textlint:fix" : " textlint --fix Appendix-*/ Ch*/" ,
18- "test" : " mocha ./Ch**/test/*.js && npm run textlint "
16+ "textlint" : " textlint \" Appendix-*/*/**.adoc \" \" Ch*/*/**.adoc \" " ,
17+ "textlint:fix" : " textlint --fix \" Appendix-*/*/**.adoc \" \" Ch*/*/**.adoc \" " ,
18+ "test" : " mocha \" ./Ch**/test/*.js\" "
1919 },
2020 "directories" : {
2121 "test" : " Ch*/test/"
2929 "codemirror" : " ^5.46.0" ,
3030 "codemirror-console-ui" : " ^2.0.5" ,
3131 "native-promise-only" : " ^0.8.1" ,
32- "w3c-xmlhttprequest" : " ^2.1.0 " ,
32+ "w3c-xmlhttprequest" : " ^2.1.3 " ,
3333 "ypromise" : " ^0.3.0"
3434 },
3535 "devDependencies" : {
4747 "gulp-remove-use-strict" : " 0.0.2" ,
4848 "gulp-rename" : " ~1.4.0" ,
4949 "handlebars" : " ^4.1.2" ,
50- "http-echo" : " 0.0.2" ,
5150 "inlining-node-require" : " ^0.1.0" ,
5251 "intelli-espower-loader" : " ^1.0.0" ,
5352 "minifyify" : " ^7.0.1" ,
Original file line number Diff line number Diff line change 1+ var http = require ( "http" ) ;
2+ var url = require ( "url" ) ;
3+ var querystring = require ( "querystring" ) ;
4+ var server = null ;
5+ var port = process . env . PORT || 3000 ;
6+ function start ( ) {
7+ server = http . createServer ( ) ;
8+ server . on ( "request" , function ( request , response ) {
9+ var uri = url . parse ( request . url ) ;
10+ var qs = uri . query ? querystring . parse ( uri . query ) : { } ;
11+
12+ var status = qs . status || 200 ;
13+ var contentType = qs . contentType || "text/plain" ;
14+ var body = qs . body || "hello there!" ;
15+
16+ response . writeHead ( status , {
17+ "Content-Type" : contentType ,
18+ "Content-Length" : body . length
19+ } ) ;
20+
21+ console . log ( uri . pathname + " - HTTP " + status + " (" + contentType + "): " + body ) ;
22+
23+ response . end ( body ) ;
24+ } ) ;
25+
26+ return new Promise ( ( resolve , reject ) => {
27+ server . listen ( port , function ( error ) {
28+ if ( error ) {
29+ return reject ( error ) ;
30+ }
31+ console . log ( "listening on port " + port ) ;
32+ resolve ( ) ;
33+ } ) ;
34+ } ) ;
35+
36+ }
37+
38+ function stop ( ) {
39+ return new Promise ( ( resolve , reject ) => {
40+ if ( ! server ) {
41+ return resolve ( ) ;
42+ }
43+ server . close ( ( error ) => {
44+ if ( error ) {
45+ reject ( error ) ;
46+ } else {
47+ resolve ( ) ;
48+ }
49+ } ) ;
50+ } ) ;
51+ }
52+
53+ module . exports = {
54+ start,
55+ stop
56+ } ;
Original file line number Diff line number Diff line change @@ -2519,10 +2519,6 @@ htmlparser2@^3.9.1:
25192519 inherits "^2.0.1"
25202520 readable-stream "^2.0.2"
25212521
2522- 2523- version "0.0.2"
2524- resolved "https://registry.yarnpkg.com/http-echo/-/http-echo-0.0.2.tgz#42f4d4b785ae5ec83e9ccad8128163f8561af05d"
2525-
25262522https-browserify@^1.0.0 :
25272523 version "1.0.0"
25282524 resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
@@ -5798,9 +5794,10 @@ vm-browserify@^1.0.0:
57985794 resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.0.tgz#bd76d6a23323e2ca8ffa12028dc04559c75f9019"
57995795 integrity sha512-iq+S7vZJE60yejDYM0ek6zg308+UZsdtPExWP9VZoCFCz1zkJoXFnAX7aZfd/ZwrkidzdUZL0C/ryW+JwAiIGw==
58005796
5801- w3c-xmlhttprequest@^2.1.0 :
5802- version "2.1.2"
5803- resolved "https://registry.yarnpkg.com/w3c-xmlhttprequest/-/w3c-xmlhttprequest-2.1.2.tgz#f0bc8937562828e2c2b9b40366486a1351fe41a0"
5797+ w3c-xmlhttprequest@^2.1.3 :
5798+ version "2.1.3"
5799+ resolved "https://registry.yarnpkg.com/w3c-xmlhttprequest/-/w3c-xmlhttprequest-2.1.3.tgz#b0aa5e060577ab874295529e4e2d037312874122"
5800+ integrity sha512-NOCpSoUIcGQl/D3tMLUizhytW9J0mLUqw/nf1lzOpub7X5wgg6+T5jxnLz9foineWGs8baLt+Ldxf8DDyuQHjg==
58045801
58055802watchify@^3.11.1 :
58065803 version "3.11.1"
You can’t perform that action at this time.
0 commit comments