-
Notifications
You must be signed in to change notification settings - Fork 2
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 #47 from Financial-Times/screenshot
Refactor url setup into it's own file
- Loading branch information
Showing
11 changed files
with
102 additions
and
101 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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const { URL } = require('url'); | ||
|
||
module.exports = (path, urlOpts, suiteOpts, globalOpts) => { | ||
const options = typeof urlOpts === 'object' ? Object.assign({}, urlOpts) : { status: urlOpts }; | ||
let host = globalOpts.host || 'http://localhost:3002'; | ||
|
||
if (!/https?\:\/\//.test(host)) { | ||
host = 'http://' + host; | ||
} | ||
|
||
options.requestHeaders = Object.assign({}, globalOpts.headers || {}, suiteOpts.headers || {}, urlOpts.headers || {}); | ||
options.requestHeaderPaths = urlOpts.requestHeaderPaths || suiteOpts.requestHeaderPaths || []; | ||
|
||
options.method = urlOpts.method || suiteOpts.method; | ||
options.body = urlOpts.body || suiteOpts.body; | ||
options.user = suiteOpts.user; | ||
options.https = urlOpts.https || suiteOpts.https; | ||
options.breakpoint = urlOpts.breakpoint || suiteOpts.breakpoint || globalOpts.breakpoint; | ||
|
||
const browsers = urlOpts.browsers || suiteOpts.browsers; | ||
const enabledBrowsers = globalOpts.browsers || ['chrome', 'firefox', 'safari', 'internet explorer', 'MicrosoftEdge']; | ||
|
||
options.browsersToRun = ['chrome']; | ||
if(Array.isArray(browsers)) { | ||
options.browsersToRun = browsers.filter(browser => enabledBrowsers.includes(browser)); | ||
} else if (browsers === true) { | ||
options.browsersToRun = enabledBrowsers; | ||
} | ||
|
||
if(options.user && !host.includes('local')) { | ||
options.requestHeaders['FT-Test-Host'] = host.replace('https://', '').replace('http://', ''); | ||
host = 'https://www.ft.com'; | ||
} else if (options.user) { | ||
//eslint-disable-next-line | ||
console.warn('Cannot run user based tests on local URLs, as they rely on the FT-Test-Host. To run this locally, please use ngrok'); | ||
options.user = false; | ||
} | ||
|
||
options.url = new URL(path, host); | ||
|
||
if(options.https) { | ||
options.url.protocol = 'https'; | ||
} | ||
|
||
return options; | ||
|
||
}; |
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
Empty file.
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