Skip to content

Commit 252a7e7

Browse files
authored
Merge pull request #9 from emartech/prtest
Test reqwrite and formatting
2 parents 7dd2282 + 20d56c2 commit 252a7e7

25 files changed

+284
-288
lines changed

.eslintrc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
"impliedStrict": true
1111
}
1212
},
13-
"globals": {
14-
"expect": true
15-
},
13+
"plugins": ["@typescript-eslint", "prettier"],
1614
"rules": {
17-
"security/detect-object-injection": 0,
1815
"security/detect-non-literal-regexp": 0,
1916
"no-unused-expressions": 0,
20-
"func-style": 0
17+
"@typescript-eslint/no-explicit-any": 0,
18+
"@typescript-eslint/ban-types": 0,
19+
"comma-dangle": 0
2120
},
2221
"extends": [
22+
"eslint:recommended",
23+
"plugin:@typescript-eslint/recommended",
24+
"plugin:prettier/recommended",
2325
"emarsys"
2426
]
2527
}

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
*.spec.js
2+
*.spec.d.ts
23
node_modules
34
.idea
45
examples
56
src
7+
.eslintrc
8+
.prettierrc

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"parser": "typescript",
3+
"bracketSpacing": true,
4+
"trailingComma": "all",
5+
"singleQuote": true,
6+
"semi": true,
7+
"useTabs": false,
8+
"tabWidth": 2,
9+
"printWidth": 120
10+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ npm install @emartech/json-logger
1010
```
1111

1212

13+
1314
### Usage
1415

1516
#### Script

package.json

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"description": "Tiny and fast json logger with namespace support",
44
"main": "dist/index.js",
55
"scripts": {
6-
"test": "mocha --require ts-node/register ./src --recursive",
7-
"test:watch": "mocha --require ts-node/register ./src --recursive --watch",
8-
"lint": "eslint ./src/**/*.{ts,js}",
6+
"test": "mocha --require ts-node/register --extension ts ./src --recursive",
7+
"test:watch": "mocha --require ts-node/register --extension ts ./src --recursive --watch",
8+
"lint": "eslint ./src/**/*.ts",
9+
"lint:fix": "eslint ./src/**/*.ts --fix",
910
"build": "rm -rf dist && tsc --project ./tsconfig.json",
1011
"release": "CI=true semantic-release",
1112
"example-js": "DEBUG=* node examples/index-js.js",
@@ -25,21 +26,31 @@
2526
"debug",
2627
"json"
2728
],
28-
"dependencies": {},
2929
"devDependencies": {
30-
"@types/node": "18.7.14",
31-
"@typescript-eslint/parser": "5.36.1",
30+
"@types/chai": "4.3.3",
31+
"@types/mocha": "10.0.0",
32+
"@types/node": "18.7.23",
33+
"@types/sinon": "10.0.13",
34+
"@types/sinon-chai": "3.2.8",
35+
"@typescript-eslint/eslint-plugin": "5.38.1",
36+
"@typescript-eslint/parser": "5.38.1",
37+
"axios": "0.27.2",
3238
"chai": "4.3.6",
33-
"eslint": "8.23.0",
39+
"eslint": "8.24.0",
3440
"eslint-config-emarsys": "5.1.0",
41+
"eslint-config-prettier": "8.5.0",
3542
"eslint-plugin-no-only-tests": "3.0.0",
43+
"eslint-plugin-prettier": "4.2.1",
3644
"eslint-plugin-security": "1.5.0",
45+
"install": "0.13.0",
3746
"mocha": "10.0.0",
47+
"npm": "8.19.2",
48+
"prettier": "2.7.1",
3849
"semantic-release": "19.0.5",
3950
"sinon": "14.0.0",
4051
"sinon-chai": "3.7.0",
4152
"ts-node": "10.9.1",
42-
"typescript": "4.8.3"
53+
"typescript": "4.8.4"
4354
},
4455
"repository": {
4556
"type": "git",

src/enabled/enabled.spec.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/enabled/enabled.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { isNamespaceEnabled } from './enabled';
2+
import { expect } from 'chai';
3+
4+
describe('isNamespaceAvailable', () => {
5+
it('should enable when variables only contain one', () => {
6+
expect(isNamespaceEnabled('mongo', 'mongo')).to.eql(true);
7+
});
8+
9+
it('should disable when not in availables', () => {
10+
expect(isNamespaceEnabled('mongo', 'redis')).to.eql(false);
11+
});
12+
13+
it('should enable when part of available and available contains *', () => {
14+
expect(isNamespaceEnabled('mongo*', 'mongolab')).to.eql(true);
15+
});
16+
17+
it('should allow multiple available namespaces', () => {
18+
const availableNamespaces = 'mongo,redis';
19+
20+
expect(isNamespaceEnabled(availableNamespaces, 'mongo')).to.eql(true);
21+
expect(isNamespaceEnabled(availableNamespaces, 'redis')).to.eql(true);
22+
});
23+
24+
it('should disable names starting with -', () => {
25+
expect(isNamespaceEnabled('mongo*,-*lab', 'mongolab')).to.eql(false);
26+
});
27+
28+
it('should not work with empty strings', () => {
29+
expect(isNamespaceEnabled('', '')).to.eql(false);
30+
});
31+
32+
it('should enable everything for star', () => {
33+
expect(isNamespaceEnabled('*', 'mongo')).to.eql(true);
34+
});
35+
});

src/enabled/enabled.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
export function isNamespaceEnabled(availableNamespace: string, namespace: string) {
1+
export const isNamespaceEnabled = (availableNamespace: string, namespace: string) => {
22
const availableNamespaces = availableNamespace.split(/[\s,]+/);
33
let enabled = false;
44
const adds: RegExp[] = [];
55
const skips: RegExp[] = [];
66

7-
availableNamespaces.forEach(function(name) {
7+
availableNamespaces.forEach((name) => {
88
if (!name) {
99
return;
1010
}
@@ -17,17 +17,17 @@ export function isNamespaceEnabled(availableNamespace: string, namespace: string
1717
}
1818
});
1919

20-
adds.forEach(function(addRegexp) {
20+
adds.forEach((addRegexp) => {
2121
if (addRegexp.test(namespace)) {
2222
enabled = true;
2323
}
2424
});
2525

26-
skips.forEach(function(addRegexp) {
26+
skips.forEach((addRegexp) => {
2727
if (addRegexp.test(namespace)) {
2828
enabled = false;
2929
}
3030
});
3131

3232
return enabled;
33-
}
33+
};

src/formatter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { logentriesFormatter } from './logentries';
33

44
export const formatter = {
55
json: jsonFormatter,
6-
logentries: logentriesFormatter
6+
logentries: logentriesFormatter,
77
};

src/formatter/json.spec.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)