Skip to content

Commit 482385c

Browse files
author
Simon Renoult
committed
test: add end to end test
1 parent 1de4005 commit 482385c

File tree

6 files changed

+144
-79
lines changed

6 files changed

+144
-79
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "test/code-complexity-fixture"]
2+
path = test/code-complexity-fixture
3+
url = git@github.com:simonrenoult/code-complexity-fixture.git

.idea/workspace.xml

Lines changed: 26 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 69 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
"build": "tsc",
2121
"coverage": "NODE_ENV=test nyc report --reporter=text-lcov > coverage.lcov && codecov",
2222
"lint": "eslint --ext .ts .",
23-
"prepare": "npm run build",
24-
"pretest": "npm run lint",
23+
"prepare": "npm run lint && npm run build",
2524
"postversion": "git push --tags",
26-
"test": "NODE_ENV=test nyc mocha test/**/*.test.js"
25+
"test": "mocha test/*.ts --require ts-node/register"
2726
},
2827
"keywords": [
2928
"complexity",
@@ -39,9 +38,9 @@
3938
"node-sloc": "^0.1.12"
4039
},
4140
"devDependencies": {
42-
"@types/chai": "^4.2.10",
41+
"@types/chai": "^4.2.11",
4342
"@types/mocha": "^7.0.2",
44-
"@types/node": "^13.9.0",
43+
"@types/node": "^13.9.1",
4544
"@types/proxyquire": "^1.3.28",
4645
"@typescript-eslint/eslint-plugin": "^2.23.0",
4746
"@typescript-eslint/parser": "^2.23.0",
@@ -57,6 +56,7 @@
5756
"nyc": "^15.0.0",
5857
"prettier": "^1.19.1",
5958
"proxyquire": "^2.1.3",
59+
"ts-node": "^8.6.2",
6060
"typescript": "^3.8.3"
6161
}
6262
}

test/code-complexity-fixture

Submodule code-complexity-fixture added at e1b45eb

test/code-complexity.test.ts

Lines changed: 40 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,40 @@
1-
// FIXME: use proxyquire with TypeScript...
2-
// import { describe, it } from 'mocha'
3-
// import { expect } from 'chai'
4-
// import proxyquire from 'proxyquire'
5-
// const { computeComplexityPerFile } = proxyquire("../src/index.ts", {
6-
// "path-exists": {
7-
// sync() {
8-
// return true;
9-
// }
10-
// },
11-
// "./sloc-interface": {
12-
// getSloc() {
13-
// return { sloc: 2 };
14-
// }
15-
// }
16-
// });
17-
//
18-
// describe(".computeComplexityPerFile(rawCommitCount, directory)", () => {
19-
// it("returns the appropriate object", async () => {
20-
// // Given
21-
// const directory = "/qux/bar";
22-
// const rawCommitCount = [
23-
// "3 .eslintrc.js",
24-
// "2 .gitignore",
25-
// "1 LICENSE",
26-
// "7 README.md",
27-
// "9 package.json",
28-
// "8 server.js",
29-
// "28 src/foo.js"
30-
// ].join("\n");
31-
//
32-
// // When
33-
// const result = await computeComplexityPerFile(rawCommitCount, directory);
34-
//
35-
// // Then
36-
// expect(result).to.eql([
37-
// {
38-
// absolutePathToFile: "/qux/bar/server.js",
39-
// commitCount: 8,
40-
// overallComplexity: 16,
41-
// relativePathToFile: "server.js",
42-
// sloc: {
43-
// sloc: 2
44-
// }
45-
// },
46-
// {
47-
// absolutePathToFile: "/qux/bar/src/foo.js",
48-
// commitCount: 28,
49-
// overallComplexity: 56,
50-
// relativePathToFile: "src/foo.js",
51-
// sloc: {
52-
// sloc: 2
53-
// }
54-
// }
55-
// ]);
56-
// });
57-
// });
1+
import { execSync } from "child_process";
2+
import { describe, before, it } from "mocha";
3+
import { resolve } from "path";
4+
import { expect } from "chai";
5+
6+
const codeComplexity = resolve(__dirname, "../src/index.ts");
7+
const fixture = resolve(__dirname, "code-complexity-fixture");
8+
9+
describe("code-complexity", () => {
10+
let output;
11+
12+
before(() => {
13+
const command = [
14+
`ts-node ${codeComplexity}`,
15+
fixture,
16+
`--details`,
17+
`--limit 10`,
18+
`--sort complexity`
19+
].join(" ");
20+
21+
output = execSync(command, { encoding: "utf8" });
22+
});
23+
24+
it("outputs the appropriate values", () => {
25+
expect(output.trim()).to.deep.equal(
26+
[
27+
"lib/response.js 142416 (commits: 276, sloc: 516)",
28+
"test/app.router.js 54714 (commits: 66, sloc: 829)",
29+
"lib/router/index.js 40005 (commits: 105, sloc: 381)",
30+
"lib/application.js 32818 (commits: 122, sloc: 269)",
31+
"lib/request.js 21746 (commits: 131, sloc: 166)",
32+
"test/res.send.js 17822 (commits: 38, sloc: 469)",
33+
"test/res.sendFile.js 14674 (commits: 22, sloc: 667)",
34+
"test/Router.js 11100 (commits: 25, sloc: 444)",
35+
"lib/express.js 7875 (commits: 125, sloc: 63)",
36+
"lib/utils.js 7095 (commits: 55, sloc: 129)"
37+
].join("\n")
38+
);
39+
});
40+
});

0 commit comments

Comments
 (0)