Skip to content

Commit

Permalink
test: Added unit tests for network-manager class
Browse files Browse the repository at this point in the history
  • Loading branch information
steilerDev committed Nov 27, 2023
1 parent 0c72bf2 commit fe2f5c6
Show file tree
Hide file tree
Showing 3 changed files with 763 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"--runInBand",
"--config", "jest.config.json",
//"--detectOpenHandles",
"test/api/api.test.ts"
"test/unit/resources.network-manager.test.ts"
],
"env": {
"NODE_NO_WARNINGS": "1"
Expand Down
12 changes: 6 additions & 6 deletions app/src/lib/resources/network-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ export class NetworkManager {
* Pending jobs will be cancelled and running jobs will be awaited
* @param queue - The queue to settle
*/
async settleQueue(queue: PQueue, clearQueuedJobs: boolean = true) {
if (clearQueuedJobs && queue.size > 0) {
async settleQueue(queue: PQueue) {
if (queue.size > 0) {
Resources.logger(this).info(`Clearing queue with ${queue.size} queued job(s)...`);
queue.clear();
}
Expand Down Expand Up @@ -334,7 +334,7 @@ export class NetworkManager {

Resources.logger(this).info(`Generated HAR archive with ${generatedObject.log.entries.length} entries`);

jsonc.write(Resources.manager().harFilePath, generatedObject, {autoPath: true});
await jsonc.write(Resources.manager().harFilePath, generatedObject, {autoPath: true});
Resources.logger(this).info(`HAR file written`);
return true;
} catch (err) {
Expand Down Expand Up @@ -478,11 +478,11 @@ export class NetworkManager {
*/
async downloadData(url: string, location: string): Promise<void> {
await this._streamingCCYLimiter.add(async () => {
const fileExists = await fs.stat(location)
.then(stat => stat.isFile())
const locationExists = await fs.stat(location)
.then(() => true)
.catch(() => false);

if (fileExists) {
if (locationExists) {
Resources.logger(this).info(`File ${location} already exists - skipping download`);
return;
}
Expand Down

0 comments on commit fe2f5c6

Please sign in to comment.