From de5f4ef1ba8993f7f4655b3928e9619887b5faca Mon Sep 17 00:00:00 2001 From: Joe Becher <71270647+drazisil-codecov@users.noreply.github.com> Date: Thu, 21 Oct 2021 07:02:02 -0400 Subject: [PATCH 1/3] fix: use correct variable for args so verbose logs show --- bin/codecov.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/codecov.ts b/bin/codecov.ts index 24320a96e..edf1a02d7 100755 --- a/bin/codecov.ts +++ b/bin/codecov.ts @@ -15,19 +15,19 @@ const realArgs = argv.argv const start = Date.now() -verbose(`Start of uploader: ${start}...`, Boolean(argv.verbose)) +verbose(`Start of uploader: ${start}...`, Boolean(realArgs.verbose)) main(realArgs) .then(() => { const end = Date.now() - verbose(`End of uploader: ${end - start} milliseconds`, argv.verbose) + verbose(`End of uploader: ${end - start} milliseconds`, realArgs.verbose) }) .catch(error => { if (error instanceof Error) { logError(`There was an error running the uploader: ${error.message}`) - verbose(`The error stack is: ${error.stack}`, argv.verbose) + verbose(`The error stack is: ${error.stack}`, realArgs.verbose) } const end = Date.now() - verbose(`End of uploader: ${end - start} milliseconds`, argv.verbose) + verbose(`End of uploader: ${end - start} milliseconds`, realArgs.verbose) process.exit(realArgs.nonZero ? -1 : 0) }) From b712b4a5ddcc822fa146ac12821d1c561a9b6d78 Mon Sep 17 00:00:00 2001 From: Joe Becher Date: Thu, 21 Oct 2021 09:13:12 -0400 Subject: [PATCH 2/3] test: verify logs display in pass and error states --- package.json | 1 + test/e2e/output.test.ts | 80 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 test/e2e/output.test.ts diff --git a/package.json b/package.json index 6e16def23..cd8e14ead 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "scripts": { "lint": "eslint \"src/**/*.ts\"", "test": "npm run lint && jest --runInBand", + "test:e2e": "jest test/e2e/output.test.ts", "build:clean": "rm -rf dist", "build": "tsc --build", "build-linux": "pkg . --targets linux --output out/codecov-linux", diff --git a/test/e2e/output.test.ts b/test/e2e/output.test.ts new file mode 100644 index 000000000..97f6f1191 --- /dev/null +++ b/test/e2e/output.test.ts @@ -0,0 +1,80 @@ +import { promisify } from 'util' +import { execFile } from 'child_process' +import { beforeAll } from 'jest-circus' + +const execFilePromise = promisify(execFile) + +describe('Uploader Output E2E Tests', () => { + let runResult: { stderr: string; stdout: string } + + beforeAll(async () => { + const buildResult = await execFilePromise('npm', ['run', 'build']) + + if (buildResult.stderr !== '') { + console.error(buildResult.stderr) + expect(true).toBeFalsy // Fail + } + }) + + describe('successful runs', () => { + beforeEach(async () => { + // Clear the results + runResult = { + stderr: '', + stdout: '', + } + + // Run the uploader + runResult = await execFilePromise('node', [ + 'dist/bin/codecov.js', + '-v', + ]) + + if (runResult.stderr !== '') { + console.error(runResult.stderr) + expect(true).toBeFalsy // Fail + } + }) + + it('should have starting log line', () => { + expect(runResult.stdout).toMatch(/Start of uploader:/) + }) + + it('should have ending log line', () => { + expect(runResult.stdout).toMatch(/End of uploader:/) + }) + + }) + + describe('error runs', () => { + beforeEach(() => { + // Clear the results + runResult = { + stderr: '', + stdout: '', + } + }) + it('should return an error', async () => { + // Run the uploader + runResult = await execFilePromise('node', [ + 'dist/bin/codecov.js', + '-v', + '-u', + 'https://foo.local' + ]) + + if (runResult.stderr !== '') { + console.error(runResult.stderr) + expect(true).toBeFalsy // Fail + } + + expect(runResult.stdout).toMatch( + /Error uploading to https:\/\/foo.local:/, + ) + + expect(runResult.stdout).toMatch( + /The error stack is:/, + ) + }, 20000) + }) +}) From ec22a6910029b13333d23a8970513564e96523dc Mon Sep 17 00:00:00 2001 From: Joe Becher Date: Thu, 21 Oct 2021 09:17:23 -0400 Subject: [PATCH 3/3] test: move build from test to script --- package.json | 2 +- test/e2e/output.test.ts | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/package.json b/package.json index cd8e14ead..94159fc45 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bin": "dist/bin/codecov.js", "scripts": { "lint": "eslint \"src/**/*.ts\"", - "test": "npm run lint && jest --runInBand", + "test": "npm run lint && npm run build && jest --runInBand", "test:e2e": "jest test/e2e/output.test.ts", "build:clean": "rm -rf dist", "build": "tsc --build", diff --git a/test/e2e/output.test.ts b/test/e2e/output.test.ts index 97f6f1191..d7fe59721 100644 --- a/test/e2e/output.test.ts +++ b/test/e2e/output.test.ts @@ -7,15 +7,6 @@ const execFilePromise = promisify(execFile) describe('Uploader Output E2E Tests', () => { let runResult: { stderr: string; stdout: string } - beforeAll(async () => { - const buildResult = await execFilePromise('npm', ['run', 'build']) - - if (buildResult.stderr !== '') { - console.error(buildResult.stderr) - expect(true).toBeFalsy // Fail - } - }) - describe('successful runs', () => { beforeEach(async () => { // Clear the results