66
77
88const path = require ( 'path' ) ;
9- const got = require ( 'got' ) ;
9+ const got = ( ... args ) => import ( 'got' ) . then ( ( { default : got } ) => got ( ... args ) ) ;
1010const config = require ( 'config' ) ;
1111const logger = require ( '../logger' ) ;
1212const log = logger . logger ;
@@ -19,12 +19,13 @@ const GET_TEST_STATUS = 'http://www.webpagetest.org/testStatus.php';
1919
2020const getTestResults = async ( testId , quality , cb ) => {
2121 let options = {
22+ method : "GET" ,
2223 url : RESULTS_URL ,
2324 searchParams : { test : testId } ,
2425 headers : { 'User-Agent' : 'WebSpeedTest' }
2526 } ;
2627 try {
27- const response = await got . get ( options )
28+ const response = await got ( options )
2829 const { statusCode, body} = response ;
2930 let resBody = JSON . parse ( body ) ;
3031 let rollBarMsg = { testId : resBody . data . id , analyzedUrl : resBody . data . testUrl , thirdPartyErrorCode : "" , file : path . basename ( ( __filename ) ) } ;
@@ -62,6 +63,7 @@ const runWtpTest = async (url, mobile, cb) => {
6263 const apiKeys = config . get ( 'wtp.apiKey' ) . split ( ',' ) ;
6364 const apiKey = apiKeys [ Math . floor ( Math . random ( ) * apiKeys . length ) ] ;
6465 let options = {
66+ method : "POST" ,
6567 url : RUN_TEST_URL ,
6668 searchParams : {
6769 url : url ,
@@ -81,7 +83,7 @@ const runWtpTest = async (url, mobile, cb) => {
8183 let response ;
8284 let rollBarMsg = { testId : "" , analyzedUrl : url , thirdPartyErrorCode : "" , file : path . basename ( ( __filename ) ) } ;
8385 try {
84- response = await got . post ( options ) ;
86+ response = await got ( options ) ;
8587 const { statusCode, body} = response ;
8688 if ( statusCode !== 200 ) {
8789 rollBarMsg . thirdPartyErrorCode = response . statusCode ;
@@ -112,14 +114,15 @@ const runWtpTest = async (url, mobile, cb) => {
112114
113115const checkTestStatus = async ( testId , quality , cb ) => {
114116 let options = {
117+ method : "GET" ,
115118 url : GET_TEST_STATUS ,
116119 searchParams : { test : testId , k : config . get ( 'wtp.apiKey' ) , f : "json" } ,
117120 'headers' : { 'User-Agent' : 'WebSpeedTest' }
118121 } ;
119122 let response ;
120123 let rollBarMsg = { } ;
121124 try {
122- response = await got . get ( options ) ;
125+ response = await got ( options ) ;
123126 const { statusCode, body} = response ;
124127 let bodyJson = JSON . parse ( body ) ;
125128 rollBarMsg = { testId : testId , thirdPartyErrorCode : "" , file : path . basename ( ( __filename ) ) } ;
0 commit comments