Skip to content

Commit

Permalink
fix: Remove request package from botbuilder-core tests (#4514)
Browse files Browse the repository at this point in the history
* Replace request with axios in bb-core tests

* Include axios in package.json
  • Loading branch information
ceciliaavila authored Aug 7, 2023
1 parent e402eca commit e51063d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion libraries/botbuilder-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"zod": "~1.11.17"
},
"devDependencies": {
"axios": "^0.25.0",
"chatdown": "^1.2.4",
"request": "^2.88.2",
"unzipper": "^0.10.9"
},
"scripts": {
Expand Down
58 changes: 31 additions & 27 deletions libraries/botbuilder-core/tests/transcriptUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const path = require('path');
const url = require('url');
const promisify = require('util').promisify;
const readFileAsync = promisify(fs.readFile);
const request = require('request');
const axios = require('axios');
const unzip = require('unzipper');
const rimraf = require('rimraf');

Expand Down Expand Up @@ -138,33 +138,37 @@ function downloadAndExtractOnce(url) {
const writeStream = fs.createWriteStream(zipPath);

// download
request
.get(url)
.on('end', function () {
// unzip
console.log(`\tUnzipping ${zipPath} into ${outputPath}`);
decompressZip(zipPath, outputPath, function (unzipErr) {
fs.unlinkSync(zipPath); // delete zip
if (unzipErr) {
// error while extracting
return reject(unzipErr);
}

// get branch's inner folder
const childDirectories = getDirectories(outputPath);
let firstDirectory = childDirectories[0];
if (!firstDirectory) {
return reject('Downloaded ZIP did not contain a branch folder.');
}

firstDirectory = path.join(firstDirectory, zipTranscriptsRelativePath);

console.log(`\tTranscripts extracted at ${firstDirectory}`);
return resolve(firstDirectory);
});
axios
.get(url, { responseType: 'stream' })
.then((response) => {
response.data
.on('end', function () {
// unzip
console.log(`\tUnzipping ${zipPath} into ${outputPath}`);
decompressZip(zipPath, outputPath, function (unzipErr) {
fs.unlinkSync(zipPath); // delete zip
if (unzipErr) {
// error while extracting
return reject(unzipErr);
}

// get branch's inner folder
const childDirectories = getDirectories(outputPath);
let firstDirectory = childDirectories[0];
if (!firstDirectory) {
return reject('Downloaded ZIP did not contain a branch folder.');
}

firstDirectory = path.join(firstDirectory, zipTranscriptsRelativePath);

console.log(`\tTranscripts extracted at ${firstDirectory}`);
return resolve(firstDirectory);
});
})
.on('error', (e) => reject(e)) // reject on download error
.pipe(writeStream);
})
.on('error', (e) => reject(e)) // reject on download error
.pipe(writeStream);
.catch((e) => reject(e));
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10998,7 +10998,7 @@ request-promise-native@^1.0.5:
stealthy-require "^1.1.1"
tough-cookie "^2.3.3"

request@^2.88.0, request@^2.88.2:
request@^2.88.0:
version "2.88.2"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3"
integrity sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==
Expand Down

0 comments on commit e51063d

Please sign in to comment.