Skip to content

Commit

Permalink
fix(coverage): add unit tests for overload util
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Jun 8, 2019
1 parent 40e93c8 commit ec86b32
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ before_script:
script:
- npm run ci
after_success:
- if [ $TRAVIS_NODE_VERSION == '10' ]; then npm run release; fi
- npm run coverage
- if [ $TRAVIS_NODE_VERSION == '10' ]; then
- npm run release
- npm run coveralls
- fi
branches:
except:
- /^v\d+\.\d+\.\d+$/
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"ci": "run-s clean build test lint check-clean",
"prerelease": "tsc -p src",
"release": "semantic-release",
"coverage": "jest --runInBand --forceExit --detectOpenHandles --coverage --coverageReporters=text-lcov | coveralls"
"coverage": "npm run test -- --coverage",
"coveralls": "npm run coverage -- --coverageReporters=text-lcov | coveralls"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -52,11 +53,6 @@
"json"
]
},
"nyc": {
"include": [
"src/*"
]
},
"prettier": {
"tabWidth": 4
},
Expand Down
4 changes: 3 additions & 1 deletion scripts/overloads.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* istanbul ignore file */
import { Argument } from "./command";
import { get } from "lodash";

export const getOverloads = (args: Argument[]): Argument[][] => {
if (args.length <= 1) {
const overloads = [args];
if (args[0] && args[0].optional) {
if (get(args, "[0].optional")) {
overloads.push([]);
}
return overloads;
Expand Down
1 change: 1 addition & 0 deletions scripts/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* istanbul ignore file */
import { stringify as yamlify } from "yamljs";
import { Command } from "./command";
import { EOL } from "os";
Expand Down
23 changes: 23 additions & 0 deletions test/overloads.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { getOverloads } from "../scripts/overloads";

test("overloads for empty arguments", () => {
expect(getOverloads([])).toMatchInlineSnapshot(`
Array [
Array [],
]
`);
});

test("overloads for non-empty arguments", () => {
expect(getOverloads([{ name: "foo", type: "string" }]))
.toMatchInlineSnapshot(`
Array [
Array [
Object {
"name": "foo",
"type": "string",
},
],
]
`);
});

0 comments on commit ec86b32

Please sign in to comment.