Skip to content

Commit

Permalink
Merge pull request #82 from MichaelCurrin/test-add-tests
Browse files Browse the repository at this point in the history
Test: Add tests
  • Loading branch information
MichaelCurrin authored Dec 18, 2020
2 parents fc8e6f5 + 17b42df commit 2674cff
Show file tree
Hide file tree
Showing 13 changed files with 584 additions and 108 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default: install

h help:
@egrep '^\S|^$$' Makefile
@egrep '^[a-z#]' Makefile


.PHONY: hooks
Expand All @@ -14,10 +14,12 @@ install:

l lint:
yarn lint:fix

t test:
yarn compile
yarn test:unit

s serve: lint test
s serve: lint
yarn start


Expand Down
41 changes: 40 additions & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Roadmap

- [ ] Add tests
- [x] Add tests
- [ ] Refactor JS to be DRY
- [x] Add TS support
- [ ] Use interfaces and types
Expand Down Expand Up @@ -166,10 +166,49 @@ Therefore formatting rules can be set at a few levels, which makes things confus
- Editor Config file (for indentation at least.)


## Tests

All functions tested needed `export` so they can be imported. A leading underscore is used to indicate functions are private - intended for use only within a module and not to be called directly (except in tests).

A template for new tests:

```
describe("#foo", () => {
it("", () => {
expect(
foo(
""
)
).toBe("");
});
});
```


## Packages

On upgrading packages.

Check outdated plugins:

```sh
$ npx vue outdated
```

Outdated packages:

```sh
$ yarn outdated
```

Upgrade:

```sh
$ yarn add foo
```

That will use the high available without conflicting with extant packages.

I attempted to upgrade these outdated packages as follows:

```
Expand Down
13 changes: 10 additions & 3 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
## Run dev server

This will compile TS to JS and serve the app.

```sh
$ yarn start
```

This does the same but adds lint fixes and tests first.
This does the same but adds lint fixes first. Tests are left out so the app can still be used without passing tests.

```sh
$ make serve
Expand Down Expand Up @@ -39,11 +40,17 @@ Run unit tests.

```sh
$ yarn test:unit
$ # Or
```

Note that it able to work with the TS files directly. It this does need or produce any output JS files.

To add the ability to get errors from the TypeScript compiler (such as bad use of arguments) before the tests are run, use this:

```sh
$ make test
```

Note that this does need or produce any output directory. It operates directly on the `.ts` files.
Or just look for TypeScript errors in the IDE.


## Compile
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
preset: "@vue/cli-plugin-unit-jest/presets/typescript-and-babel",
testPathIgnorePatterns: ["<rootDir>/dist/"],
};
32 changes: 18 additions & 14 deletions src/core/Repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
GITHUB_GREEN,
GITHUB_IO,
GREEN,
LICENSE,
SHIELDS_GH,
// eslint-disable-next-line prettier/prettier
STYLES
Expand Down Expand Up @@ -103,24 +104,27 @@ export class Repo {
return markdownImageWithLink(title, imgUrl, target);
}

_licenseTarget(localLicense: boolean) {
if (localLicense) {
return "#license";
}
const repoUrl = this.ghURL();

return `${repoUrl}/blob/${DEFAULT_BRANCH}/LICENSE`;
}

licenseBadge(licenseType: string, localLicense = true) {
if (!licenseType || !this._isValid()) {
return "";
}
const label = "License",
message = licenseType,
color = DEFAULT_COLOR,
isLarge = false;

let target;
if (localLicense) {
target = "#license";
} else {
const repoUrl = this.ghURL();
target = `${repoUrl}/blob/${DEFAULT_BRANCH}/LICENSE`;
}

return genericBadge(label, message, color, isLarge, target);
return genericBadge(
LICENSE.LABEL,
licenseType,
LICENSE.COLOR,
LICENSE.IS_LARGE,
this._licenseTarget(localLicense)
);
}

gh() {
Expand All @@ -146,7 +150,7 @@ export class Repo {
}

private _ghSocialShield(type: string) {
return `${SHIELDS_GH}/${type}/${this.username}/${this.repoName}${STYLES.SOCIAL}`;
return `${SHIELDS_GH}/${type}/${this.username}/${this.repoName}?style=${STYLES.SOCIAL}`;
}

/* Stars or forks counter */
Expand Down
7 changes: 7 additions & 0 deletions src/core/badges.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type StrMap = { [key: string]: string };

export type GenericBadge = {
label?: string;
message: string;
color: string;
};
Loading

0 comments on commit 2674cff

Please sign in to comment.