|
| 1 | +import { execSync } from "child_process"; |
| 2 | +import TestRepositoryFixture from "../fixtures/test-repository.fixture"; |
| 3 | +import { expect } from "chai"; |
| 4 | + |
| 5 | +describe("CLI", () => { |
| 6 | + context("when format is json", () => { |
| 7 | + it("generates the appropriate output", () => { |
| 8 | + // Given |
| 9 | + const repo = new TestRepositoryFixture(); |
| 10 | + repo |
| 11 | + .addFile({ name: "a.js", lines: 2, commits: 2 }) |
| 12 | + .addFile({ name: "b.ts", lines: 1, commits: 1 }) |
| 13 | + .writeOnDisk(); |
| 14 | + |
| 15 | + // When |
| 16 | + const result = execSync( |
| 17 | + `npx ts-node bin/code-complexity.ts ${repo.location} --format=json`, |
| 18 | + { encoding: "utf8" } |
| 19 | + ).trim(); |
| 20 | + |
| 21 | + // Then |
| 22 | + expect(result).to.deep.equal( |
| 23 | + JSON.stringify([ |
| 24 | + { path: "a.js", churn: 2, complexity: 2, score: 4 }, |
| 25 | + { path: "b.ts", churn: 1, complexity: 1, score: 1 }, |
| 26 | + ]) |
| 27 | + ); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + context("when format is csv", () => { |
| 32 | + it("generates the appropriate output", () => { |
| 33 | + // Given |
| 34 | + const repo = new TestRepositoryFixture(); |
| 35 | + repo |
| 36 | + .addFile({ name: "a.js", lines: 2, commits: 2 }) |
| 37 | + .addFile({ name: "b.ts", lines: 1, commits: 1 }) |
| 38 | + .writeOnDisk(); |
| 39 | + |
| 40 | + // When |
| 41 | + const result = execSync( |
| 42 | + `npx ts-node bin/code-complexity.ts ${repo.location} --format=csv`, |
| 43 | + { encoding: "utf8" } |
| 44 | + ).trim(); |
| 45 | + |
| 46 | + // Then |
| 47 | + expect(result).to.deep.equal( |
| 48 | + ["file,complexity,churn,score", "a.js,2,2,4", "b.ts,1,1,1"].join("\n") |
| 49 | + ); |
| 50 | + }); |
| 51 | + }); |
| 52 | +}); |
0 commit comments