Skip to content

Commit

Permalink
chore: Switch to axios usage (appium#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored May 4, 2020
1 parent 7d766c9 commit f6b3c6b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
29 changes: 8 additions & 21 deletions Scripts/fetch-prebuilt-wda.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const path = require('path');
const request = require('request-promise');
const requestCallback = require('request');
const axios = require('axios');
const { asyncify } = require('asyncbox');
const { logger, fs, mkdirp } = require('appium-support');
const { logger, fs, mkdirp, net } = require('appium-support');
const _ = require('lodash');
const _fs = require('fs');
const B = require('bluebird');

const log = logger.getLogger('WDA');
Expand All @@ -16,14 +14,15 @@ async function fetchPrebuiltWebDriverAgentAssets () {
log.info(`Getting WDA release ${downloadUrl}`);
let releases;
try {
releases = await request.get(downloadUrl, {
releases = (await axios({
url: downloadUrl,
headers: {
'user-agent': 'appium',
'accept': 'application/json, */*',
},
json: true,
});
})).data;
} catch (e) {
throw new Error(`Could not fetch endpoint '${downloadUrl}. Reason: ${e.message}'`);
throw new Error(`Could not fetch endpoint ${downloadUrl}. Reason: ${e.message}`);
}

const webdriveragentsDir = path.resolve(__dirname, '..', 'prebuilt-agents');
Expand All @@ -34,19 +33,7 @@ async function fetchPrebuiltWebDriverAgentAssets () {
// Define a method that does a streaming download of an asset
async function downloadAgent (url, targetPath) {
try {
// don't use request-promise here, we need streams
return await new B((resolve, reject) => {
requestCallback(url)
.on('error', reject) // handle real errors, like connection errors
.on('response', (res) => {
// handle responses that fail, like 404s
if (res.statusCode >= 400) {
return reject(new Error(`${res.statusCode} - ${res.statusMessage}`));
}
})
.pipe(_fs.createWriteStream(targetPath))
.on('close', resolve);
});
await net.downloadFile(url, targetPath);
} catch (err) {
throw new Error(`Problem downloading webdriveragent from url ${url}: ${err.message}`);
}
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@
"@babel/runtime": "^7.0.0",
"appium-base-driver": "^5.0.2",
"appium-ios-simulator": "^3.14.0",
"appium-support": "^2.37.0",
"appium-support": "^2.46.0",
"async-lock": "^1.0.0",
"asyncbox": "^2.5.3",
"axios": "^0.19.2",
"bluebird": "^3.5.5",
"lodash": "^4.17.11",
"node-simctl": "^6.0.2",
"request": "^2.79.0",
"request-promise": "^4.1.1",
"source-map-support": "^0.5.12",
"stream-equal": "^1.1.1",
"teen_process": "^1.14.1"
Expand Down
4 changes: 2 additions & 2 deletions test/functional/helpers/session.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import wd from 'wd';
import request from 'request-promise';
import { startServer } from '../../..';
import { util } from 'appium-support';
import _ from 'lodash';
import axios from 'axios';


const {SAUCE_RDC, SAUCE_EMUSIM, CLOUD} = process.env;
Expand Down Expand Up @@ -96,7 +96,7 @@ function getServer () {
async function initWDA (caps) {
// first, see if this is necessary
try {
await request.get({url: `http://${HOST}:${WDA_PORT}/status`});
await axios({url: `http://${HOST}:${WDA_PORT}/status`, timeout: 5000});
} catch (err) {
// easiest way to initialize WDA is to go through a test startup
// otherwise every change to the system would require a change here
Expand Down
4 changes: 2 additions & 2 deletions test/functional/webdriveragent-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import Simctl from 'node-simctl';
import { getVersion } from 'appium-xcode';
import { getSimulator } from 'appium-ios-simulator';
import { killAllSimulators, shutdownSimulator } from './helpers/simulator';
import request from 'request-promise';
import { SubProcess } from 'teen_process';
import { PLATFORM_VERSION, DEVICE_NAME } from './desired';
import { retryInterval } from 'asyncbox';
import { WebDriverAgent } from '../..';
import axios from 'axios';


const SIM_DEVICE_NAME = 'webDriverAgentTest';
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('WebDriverAgent', function () {
const agent = new WebDriverAgent(xcodeVersion, getStartOpts(device));

await agent.launch('sessionId');
await request(testUrl).should.be.eventually.rejectedWith(/unknown command/);
await axios({url: testUrl}).should.be.eventually.rejected;
await agent.quit();
});

Expand Down

0 comments on commit f6b3c6b

Please sign in to comment.