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) }) diff --git a/package.json b/package.json index 5ae8350b9..0210d9412 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "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", "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..d7fe59721 --- /dev/null +++ b/test/e2e/output.test.ts @@ -0,0 +1,71 @@ +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 } + + 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) + }) +})