-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from yujiosaka/resolve_url
Resolve url
- Loading branch information
Showing
4 changed files
with
111 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ const { | |
jsonStableReplacer, | ||
hash, | ||
generateKey, | ||
resolveUrl, | ||
debugRequest, | ||
debugBrowser, | ||
} = require('../lib/helper'); | ||
|
@@ -51,24 +52,70 @@ describe('Helper', () => { | |
describe('Helper.jsonStableReplacer', () => { | ||
it('sorts keys by order', () => { | ||
const obj = { c: 8, b: [{ z: 6, y: 5, x: 4 }, 7], a: 3 }; | ||
const actual = '{"a":3,"b":[{"x":4,"y":5,"z":6},7],"c":8}'; | ||
const expected = JSON.stringify(obj, jsonStableReplacer); | ||
const actual = JSON.stringify(obj, jsonStableReplacer); | ||
const expected = '{"a":3,"b":[{"x":4,"y":5,"z":6},7],"c":8}'; | ||
assert.equal(actual, expected); | ||
}); | ||
}); | ||
|
||
describe('Helper.resolveUrl', () => { | ||
const baseUrl = 'https://github.com/yujiosaka/headless-chrome-crawler'; | ||
|
||
it('returns null when the argument is null', () => { | ||
const actual = resolveUrl(null, baseUrl); | ||
const expected = null; | ||
assert.equal(actual, expected); | ||
}); | ||
|
||
it('returns null when the argument starts With hash', () => { | ||
const actual = resolveUrl('#headless-chrome-crawler---', baseUrl); | ||
const expected = null; | ||
assert.equal(actual, expected); | ||
}); | ||
|
||
it('returns null when the argument starts with javascript:', () => { | ||
const actual = resolveUrl('javascript:void(0)', baseUrl); /* eslint no-script-url: 0 */ | ||
const expected = null; | ||
assert.equal(actual, expected); | ||
}); | ||
|
||
it('returns null when the argument starts with mailto:', () => { | ||
const actual = resolveUrl('mail:[email protected]', baseUrl); | ||
const expected = null; | ||
assert.equal(actual, expected); | ||
}); | ||
|
||
it('returns full URL when the argument is an absolute URL', () => { | ||
const actual = resolveUrl('https://github.com/yujiosaka/headless-chrome-crawler', baseUrl); | ||
const expected = 'https://github.com/yujiosaka/headless-chrome-crawler'; | ||
assert.equal(actual, expected); | ||
}); | ||
|
||
it('strips hash when the argument is an absolute URL with hash', () => { | ||
const actual = resolveUrl('https://github.com/yujiosaka/headless-chrome-crawler#headless-chrome-crawler---', baseUrl); | ||
const expected = 'https://github.com/yujiosaka/headless-chrome-crawler'; | ||
assert.equal(actual, expected); | ||
}); | ||
|
||
it('resolves url when the argument is a relative URL', () => { | ||
const actual = resolveUrl('headless-chrome-crawler/settings', baseUrl); | ||
const expected = 'https://github.com/yujiosaka/headless-chrome-crawler/settings'; | ||
assert.equal(actual, expected); | ||
}); | ||
}); | ||
|
||
describe('Helper.debugRequest', () => { | ||
it('does not throw an error', () => { | ||
assert.doesNotThrow(() => { | ||
debugRequest('Start requesting http://example.com/'); | ||
debugRequest('Start requesting https://github.com/yujiosaka/headless-chrome-crawler'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Helper.debugBrowser', () => { | ||
it('does not throw an error', () => { | ||
assert.doesNotThrow(() => { | ||
debugBrowser('Console log init.. http://example.com/'); | ||
debugBrowser('Console log init https://github.com/yujiosaka/headless-chrome-crawler'); | ||
}); | ||
}); | ||
}); | ||
|