Skip to content

Commit 295fd1a

Browse files
committed
Add code coverage
1 parent 334fe44 commit 295fd1a

7 files changed

+63
-2
lines changed

.coveralls.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
service_name: travis-pro
2+
repo_token: iHctMRQ1rYAUMqiyQH6PITDEQXvwaTknc

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
package-lock.json
44
yarn.lock
55
.idea
6+
/coverage

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ script:
99
- npm run lint
1010
- npm run build
1111
- npm run test
12+
- npm run coveralls
1213
- npm run pkg-ok

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Build Status](https://img.shields.io/travis/abraham/reflection.svg?style=flat)](https://travis-ci.org/abraham/reflection)
33
[![Dependency Status](https://david-dm.org/abraham/reflection.svg?style=flat)](https://david-dm.org/abraham/reflection)
44
[![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/@abraham/reflection.svg?style=flat&colorB=4bc524)](https://bundlephobia.com/result?p=@abraham/reflection)
5-
5+
[![Coverage Status](https://coveralls.io/repos/github/abraham/reflection/badge.svg?branch=master)](https://coveralls.io/github/abraham/reflection?branch=master)
66

77
Reflection
88
====

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"build": "tsc && rollup -c",
1010
"clean": "rimraf dist",
11+
"coveralls": "cat ./coverage/lcov.info | coveralls",
1112
"lint": "eslint src --ext .ts",
1213
"prebuild": "npm run clean",
1314
"prepare": "npm run build",
@@ -40,6 +41,7 @@
4041
"@types/jest": "25.1.4",
4142
"@typescript-eslint/eslint-plugin": "2.23.0",
4243
"@typescript-eslint/parser": "2.23.0",
44+
"coveralls": "3.0.9",
4345
"eslint": "6.8.0",
4446
"eslint-plugin-import": "2.20.1",
4547
"eslint-plugin-jest": "23.8.2",
@@ -51,6 +53,7 @@
5153
"typescript": "3.8.3"
5254
},
5355
"jest": {
56+
"collectCoverage": true,
5457
"roots": [
5558
"<rootDir>/src"
5659
],

src/decorate.test.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,26 @@ test('with property and descriptor and invalid decorators', () => {
3434
expect(() => Reflect.decorate(decorators, target, property, descriptor)).toThrow(TypeError);
3535
});
3636

37-
test('with decorators, property, and descriptor and invalid target ', () => {
37+
test('with decorators, property, and descriptor and invalid target', () => {
3838
const decorators: PropertyDecorator[] = [];
3939
const target: any = 1;
4040
const property = 'name';
4141
const descriptor = {};
4242
expect(() => Reflect.decorate(decorators, target, property, descriptor)).toThrow(TypeError);
4343
});
4444

45+
test('with decorators, undefined property, and descriptor and invalid target', () => {
46+
const sent: Function[] = [];
47+
const decorators: any = [
48+
(target: Function): void => { sent.push(target); },
49+
];
50+
const target: any = 1;
51+
const property = undefined;
52+
const descriptor = {};
53+
const result = Reflect.decorate(decorators, target, property, descriptor);
54+
expect(result).toBeUndefined();
55+
});
56+
4557
test('executes decorators in reverse order for function', () => {
4658
const order: number[] = [];
4759
const decorators = [

src/has-metadata.test.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import './index';
2+
3+
test('with invalid target', () => {
4+
const target: any = undefined;
5+
expect(() => Reflect.hasMetadata('key', target)).toThrow(TypeError);
6+
});
7+
8+
test('when not defined', () => {
9+
const target = {};
10+
expect(Reflect.hasMetadata('key', target)).toBeFalsy();
11+
});
12+
13+
test('when defined', () => {
14+
const target = {};
15+
Reflect.defineMetadata('key', 'value', target);
16+
expect(Reflect.hasMetadata('key', target)).toBeTruthy();
17+
});
18+
19+
test('when defined on prototype', () => {
20+
const prototype = {};
21+
const target = Object.create(prototype);
22+
Reflect.defineMetadata('key', 'value', prototype);
23+
expect(Reflect.hasMetadata('key', target)).toBeTruthy();
24+
});
25+
26+
test('with key and not defined', () => {
27+
const target = {};
28+
expect(Reflect.hasMetadata('key', target, 'name')).toBeFalsy();
29+
});
30+
31+
test('with key and defined', () => {
32+
const target = {};
33+
Reflect.defineMetadata('key', 'value', target, 'name');
34+
expect(Reflect.hasMetadata('key', target, 'name')).toBeTruthy();
35+
});
36+
37+
test('when defined on prototype with a property key', () => {
38+
const prototype = {};
39+
const target = Object.create(prototype);
40+
Reflect.defineMetadata('key', 'value', prototype, 'name');
41+
expect(Reflect.hasMetadata('key', target, 'name')).toBeTruthy();
42+
});

0 commit comments

Comments
 (0)