File tree Expand file tree Collapse file tree 7 files changed +45
-2
lines changed Expand file tree Collapse file tree 7 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 26
26
"gaxios" : " ^1.6.0" ,
27
27
"is-absolute-url" : " ^2.1.0" ,
28
28
"meow" : " ^5.0.0" ,
29
+ "server-destroy" : " ^1.0.1" ,
29
30
"update-notifier" : " ^2.5.0"
30
31
},
31
32
"devDependencies" : {
37
38
"@types/mocha" : " ^5.2.5" ,
38
39
"@types/nock" : " ^9.3.1" ,
39
40
"@types/node" : " ^11.9.3" ,
41
+ "@types/server-destroy" : " ^1.0.0" ,
40
42
"@types/sinon" : " ^7.0.5" ,
41
43
"@types/update-notifier" : " ^2.5.0" ,
42
44
"codecov" : " ^3.1.0" ,
Original file line number Diff line number Diff line change 1
1
import { EventEmitter } from 'events' ;
2
2
import * as gaxios from 'gaxios' ;
3
3
import * as http from 'http' ;
4
+ import enableDestroy = require( 'server-destroy' ) ;
4
5
5
6
import { getLinks } from './links' ;
6
7
@@ -55,6 +56,7 @@ export class LinkChecker extends EventEmitter {
55
56
if ( ! options . path . startsWith ( 'http' ) ) {
56
57
const port = options . port || 5000 + Math . round ( Math . random ( ) * 1000 ) ;
57
58
server = await this . startWebServer ( options . path , port ) ;
59
+ enableDestroy ( server ) ;
58
60
options . path = `http://localhost:${ port } ` ;
59
61
}
60
62
const results = await this . crawl (
@@ -64,7 +66,7 @@ export class LinkChecker extends EventEmitter {
64
66
passed : results . filter ( x => x . state === LinkState . BROKEN ) . length === 0
65
67
} ;
66
68
if ( server ) {
67
- server . close ( ) ;
69
+ server . destroy ( ) ;
68
70
}
69
71
return result ;
70
72
}
@@ -141,7 +143,8 @@ export class LinkChecker extends EventEmitter {
141
143
const urls = getLinks ( data , opts . checkOptions . path ) ;
142
144
for ( const url of urls ) {
143
145
// only crawl links that start with the same host
144
- const crawl = url . startsWith ( opts . checkOptions . path ) ;
146
+ const crawl = opts . checkOptions . recurse ! &&
147
+ url . startsWith ( opts . checkOptions . path ) ;
145
148
await this . crawl ( {
146
149
url,
147
150
crawl,
Original file line number Diff line number Diff line change
1
+ < html >
2
+ < body >
3
+ < a href ='/nothere.html '> </ a >
4
+ < a href ='http://www.google.com '> </ a >
5
+ </ body >
6
+ </ html >
Original file line number Diff line number Diff line change
1
+ < html >
2
+ < body >
3
+ < a href ='/ '> </ a >
4
+ < a href ='/second.html '> </ a >
5
+ </ body >
6
+ </ html >
Original file line number Diff line number Diff line change
1
+ < html >
2
+ < body >
3
+ < a href ="first.html "> go right over there</ a >
4
+ </ body >
5
+ </ html >
Original file line number Diff line number Diff line change
1
+ < html >
2
+ < body >
3
+ < a href ='http://fake.local '> Link to another castle</ a >
4
+ </ body >
5
+ </ html >
Original file line number Diff line number Diff line change @@ -75,4 +75,20 @@ describe('linkinator', () => {
75
75
assert . strictEqual (
76
76
results . links . filter ( x => x . state === LinkState . OK ) . length , 2 ) ;
77
77
} ) ;
78
+
79
+ it ( 'should perform a recursive scan' , async ( ) => {
80
+ // This test is making sure that we do a recursive scan of links,
81
+ // but also that we don't follow links to another site
82
+ const scope = nock ( 'http://fake.local' )
83
+ . get ( '/' )
84
+ . replyWithFile ( 200 , 'test/fixtures/recurse/fake.html' ) ;
85
+ const results = await check ( { path : 'test/fixtures/recurse' , recurse : true } ) ;
86
+ assert . strictEqual ( results . links . length , 5 ) ;
87
+ scope . done ( ) ;
88
+ } ) ;
89
+
90
+ it ( 'should not recurse by default' , async ( ) => {
91
+ const results = await check ( { path : 'test/fixtures/recurse' } ) ;
92
+ assert . strictEqual ( results . links . length , 2 ) ;
93
+ } ) ;
78
94
} ) ;
You can’t perform that action at this time.
0 commit comments