From 20e1b242c8d4789855555d6a83943e4c397190ff Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Fri, 28 Jul 2023 14:12:15 +0000 Subject: [PATCH] adding updated lints and fixes --- packages/artifact/__tests__/download.test.ts | 6 +-- packages/artifact/__tests__/retry.test.ts | 2 +- packages/artifact/__tests__/upload.test.ts | 49 +++++++++---------- .../src/internal/download-http-client.ts | 31 ++++++------ packages/exec/__tests__/exec.test.ts | 6 +-- .../github/__tests__/github.proxy.test.ts | 4 +- 6 files changed, 48 insertions(+), 50 deletions(-) diff --git a/packages/artifact/__tests__/download.test.ts b/packages/artifact/__tests__/download.test.ts index d150d220..c36b3fe8 100644 --- a/packages/artifact/__tests__/download.test.ts +++ b/packages/artifact/__tests__/download.test.ts @@ -239,7 +239,7 @@ describe('Download Tests', () => { */ async function emptyMockReadBody(): Promise { return new Promise(resolve => { - resolve() + resolve('mockResolve') }) } @@ -276,7 +276,7 @@ describe('Download Tests', () => { ] } const returnData: string = JSON.stringify(response, null, 2) - mockReadBody = async function(): Promise { + mockReadBody = async function (): Promise { return new Promise(resolve => { resolve(returnData) }) @@ -447,7 +447,7 @@ describe('Download Tests', () => { ] } const returnData: string = JSON.stringify(response, null, 2) - mockReadBody = async function(): Promise { + mockReadBody = async function (): Promise { return new Promise(resolve => { resolve(returnData) }) diff --git a/packages/artifact/__tests__/retry.test.ts b/packages/artifact/__tests__/retry.test.ts index d1e9256e..37d4ce95 100644 --- a/packages/artifact/__tests__/retry.test.ts +++ b/packages/artifact/__tests__/retry.test.ts @@ -65,7 +65,7 @@ beforeAll(async () => { */ async function emptyMockReadBody(): Promise { return new Promise(resolve => { - resolve() + resolve('mockResolved') }) } diff --git a/packages/artifact/__tests__/upload.test.ts b/packages/artifact/__tests__/upload.test.ts index 75c228e1..fcf7ee26 100644 --- a/packages/artifact/__tests__/upload.test.ts +++ b/packages/artifact/__tests__/upload.test.ts @@ -2,22 +2,22 @@ import * as http from 'http' import * as io from '../../io/src/io' import * as net from 'net' import * as path from 'path' -import {mocked} from 'ts-jest/utils' -import {exec, execSync} from 'child_process' -import {createGunzip} from 'zlib' -import {promisify} from 'util' -import {UploadHttpClient} from '../src/internal/upload-http-client' +import { mocked } from 'ts-jest/utils' +import { exec, execSync } from 'child_process' +import { createGunzip } from 'zlib' +import { promisify } from 'util' +import { UploadHttpClient } from '../src/internal/upload-http-client' import * as core from '@actions/core' -import {promises as fs} from 'fs' -import {getRuntimeUrl} from '../src/internal/config-variables' -import {HttpClient, HttpClientResponse} from '@actions/http-client' +import { promises as fs } from 'fs' +import { getRuntimeUrl } from '../src/internal/config-variables' +import { HttpClient, HttpClientResponse } from '@actions/http-client' import { ArtifactResponse, PatchArtifactSizeSuccessResponse } from '../src/internal/contracts' -import {UploadSpecification} from '../src/internal/upload-specification' -import {getArtifactUrl} from '../src/internal/utils' -import {UploadOptions} from '../src/internal/upload-options' +import { UploadSpecification } from '../src/internal/upload-specification' +import { getArtifactUrl } from '../src/internal/utils' +import { UploadOptions } from '../src/internal/upload-options' const root = path.join(__dirname, '_temp', 'artifact-upload') const file1Path = path.join(root, 'file1.txt') @@ -38,11 +38,11 @@ jest.mock('@actions/http-client') describe('Upload Tests', () => { beforeAll(async () => { // mock all output so that there is less noise when running tests - jest.spyOn(console, 'log').mockImplementation(() => {}) - jest.spyOn(core, 'debug').mockImplementation(() => {}) - jest.spyOn(core, 'info').mockImplementation(() => {}) - jest.spyOn(core, 'warning').mockImplementation(() => {}) - jest.spyOn(core, 'error').mockImplementation(() => {}) + jest.spyOn(console, 'log').mockImplementation(() => { }) + jest.spyOn(core, 'debug').mockImplementation(() => { }) + jest.spyOn(core, 'info').mockImplementation(() => { }) + jest.spyOn(core, 'warning').mockImplementation(() => { }) + jest.spyOn(core, 'error').mockImplementation(() => { }) // setup mocking for calls that got through the HttpClient setupHttpClientMock() @@ -196,7 +196,7 @@ describe('Upload Tests', () => { // create a named pipe 'pipe' with content 'hello pipe' const content = Buffer.from('hello pipe') const pipeFilePath = path.join(root, 'pipe') - await promisify(exec)('mkfifo pipe', {cwd: root}) + await promisify(exec)('mkfifo pipe', { cwd: root }) // don't want to await here as that would block until read fs.writeFile(pipeFilePath, content) @@ -280,7 +280,7 @@ describe('Upload Tests', () => { const uploadResult = await uploadHttpClient.uploadArtifactToFileContainer( uploadUrl, uploadSpecification, - {continueOnError: true} + { continueOnError: true } ) expect(uploadResult.failedItems.length).toEqual(1) expect(uploadResult.uploadSize).toEqual(expectedPartialSize) @@ -317,7 +317,7 @@ describe('Upload Tests', () => { const uploadResult = await uploadHttpClient.uploadArtifactToFileContainer( uploadUrl, uploadSpecification, - {continueOnError: false} + { continueOnError: false } ) expect(uploadResult.failedItems.length).toEqual(2) expect(uploadResult.uploadSize).toEqual(expectedPartialSize) @@ -429,7 +429,7 @@ describe('Upload Tests', () => { */ async function emptyMockReadBody(): Promise { return new Promise(resolve => { - resolve() + resolve('mockResolve') }) } @@ -461,12 +461,11 @@ describe('Upload Tests', () => { fileContainerResourceUrl: `${getRuntimeUrl()}_apis/resources/Containers/13`, type: 'actions_storage', name: inputData.Name, - url: `${getRuntimeUrl()}_apis/pipelines/1/runs/1/artifacts?artifactName=${ - inputData.Name - }` + url: `${getRuntimeUrl()}_apis/pipelines/1/runs/1/artifacts?artifactName=${inputData.Name + }` } const returnData: string = JSON.stringify(response, null, 2) - mockReadBody = async function(): Promise { + mockReadBody = async function (): Promise { return new Promise(resolve => { resolve(returnData) }) @@ -534,7 +533,7 @@ describe('Upload Tests', () => { uploadUrl: `${getRuntimeUrl()}_apis/resources/Containers/13` } const returnData: string = JSON.stringify(response, null, 2) - mockReadBody = async function(): Promise { + mockReadBody = async function (): Promise { return new Promise(resolve => { resolve(returnData) }) diff --git a/packages/artifact/src/internal/download-http-client.ts b/packages/artifact/src/internal/download-http-client.ts index e9bf4c89..1da8b13b 100644 --- a/packages/artifact/src/internal/download-http-client.ts +++ b/packages/artifact/src/internal/download-http-client.ts @@ -14,16 +14,16 @@ import { rmFile, sleep } from './utils' -import {URL} from 'url' -import {StatusReporter} from './status-reporter' -import {performance} from 'perf_hooks' -import {ListArtifactsResponse, QueryArtifactResponse} from './contracts' -import {HttpClientResponse} from '@actions/http-client' -import {HttpManager} from './http-manager' -import {DownloadItem} from './download-specification' -import {getDownloadFileConcurrency, getRetryLimit} from './config-variables' -import {IncomingHttpHeaders} from 'http' -import {retryHttpClientRequest} from './requestUtils' +import { URL } from 'url' +import { StatusReporter } from './status-reporter' +import { performance } from 'perf_hooks' +import { ListArtifactsResponse, QueryArtifactResponse } from './contracts' +import { HttpClientResponse } from '@actions/http-client' +import { HttpManager } from './http-manager' +import { DownloadItem } from './download-specification' +import { getDownloadFileConcurrency, getRetryLimit } from './config-variables' +import { IncomingHttpHeaders } from 'http' +import { retryHttpClientRequest } from './requestUtils' export class DownloadHttpClient { // http manager is used for concurrent connections when downloading multiple files at once @@ -113,8 +113,7 @@ export class DownloadHttpClient { if (core.isDebug()) { core.debug( - `File: ${++downloadedFiles}/${downloadItems.length}. ${ - currentFileToDownload.targetPath + `File: ${++downloadedFiles}/${downloadItems.length}. ${currentFileToDownload.targetPath } took ${(performance.now() - startTime).toFixed( 3 )} milliseconds to finish downloading` @@ -280,8 +279,8 @@ export class DownloadHttpClient { // if a throttled status code is received, try to get the retryAfter header value, else differ to standard exponential backoff isThrottledStatusCode(response.message.statusCode) ? await backOff( - tryGetRetryAfterValueTimeInMilliseconds(response.message.headers) - ) + tryGetRetryAfterValueTimeInMilliseconds(response.message.headers) + ) : await backOff() } else { // Some unexpected response code, fail immediately and stop the download @@ -328,7 +327,7 @@ export class DownloadHttpClient { }) .pipe(destinationStream) .on('close', () => { - resolve() + resolve('closed') }) .on('error', error => { core.info( @@ -347,7 +346,7 @@ export class DownloadHttpClient { }) .pipe(destinationStream) .on('close', () => { - resolve() + resolve('closed') }) .on('error', error => { core.info( diff --git a/packages/exec/__tests__/exec.test.ts b/packages/exec/__tests__/exec.test.ts index e2f6fc37..1f83ce4a 100644 --- a/packages/exec/__tests__/exec.test.ts +++ b/packages/exec/__tests__/exec.test.ts @@ -357,7 +357,7 @@ describe('@actions/exec', () => { expect(exitCode).toBe(0) }) - it('Handles child process holding streams open', async function() { + it('Handles child process holding streams open', async function () { const semaphorePath = path.join( getTestTemp(), 'child-process-semaphore.txt' @@ -403,7 +403,7 @@ describe('@actions/exec', () => { fs.unlinkSync(semaphorePath) }, 10000) // this was timing out on some slower hosted macOS runs at default 5s - it('Handles child process holding streams open and non-zero exit code', async function() { + it('Handles child process holding streams open and non-zero exit code', async function () { const semaphorePath = path.join( getTestTemp(), 'child-process-semaphore.txt' @@ -457,7 +457,7 @@ describe('@actions/exec', () => { fs.unlinkSync(semaphorePath) }, 10000) // this was timing out on some slower hosted macOS runs at default 5s - it('Handles child process holding streams open and stderr', async function() { + it('Handles child process holding streams open and stderr', async function () { const semaphorePath = path.join( getTestTemp(), 'child-process-semaphore.txt' diff --git a/packages/github/__tests__/github.proxy.test.ts b/packages/github/__tests__/github.proxy.test.ts index aa79f8b7..2549bd9f 100644 --- a/packages/github/__tests__/github.proxy.test.ts +++ b/packages/github/__tests__/github.proxy.test.ts @@ -19,7 +19,7 @@ describe('@actions/github', () => { proxyServer = proxy() await new Promise(resolve => { const port = Number(proxyUrl.split(':')[2]) - proxyServer.listen(port, () => resolve()) + proxyServer.listen(port, () => resolve('mockResolve')) }) proxyServer.on('connect', req => { proxyConnects.push(req.url ?? '') @@ -33,7 +33,7 @@ describe('@actions/github', () => { afterAll(async () => { // Stop proxy server await new Promise(resolve => { - proxyServer.once('close', () => resolve()) + proxyServer.once('close', () => resolve('closed')) proxyServer.close() })