Skip to content

Commit 003afd0

Browse files
authored
cleanup tests and linting (cap-js-community#1)
* linter * update logger snapshots after cf-node-logging library update * resolve ipv4 ipv6 ambivalence of redis default host=localhost
1 parent e983343 commit 003afd0

5 files changed

+33
-24
lines changed

CODE_OF_CONDUCT.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
1717
Examples of behavior that contributes to a positive environment for our
1818
community include:
1919

20-
* Demonstrating empathy and kindness toward other people
21-
* Being respectful of differing opinions, viewpoints, and experiences
22-
* Giving and gracefully accepting constructive feedback
23-
* Accepting responsibility and apologizing to those affected by our mistakes,
20+
- Demonstrating empathy and kindness toward other people
21+
- Being respectful of differing opinions, viewpoints, and experiences
22+
- Giving and gracefully accepting constructive feedback
23+
- Accepting responsibility and apologizing to those affected by our mistakes,
2424
and learning from the experience
25-
* Focusing on what is best not just for us as individuals, but for the overall
25+
- Focusing on what is best not just for us as individuals, but for the overall
2626
community
2727

2828
Examples of unacceptable behavior include:
2929

30-
* The use of sexualized language or imagery, and sexual attention or advances of
30+
- The use of sexualized language or imagery, and sexual attention or advances of
3131
any kind
32-
* Trolling, insulting or derogatory comments, and personal or political attacks
33-
* Public or private harassment
34-
* Publishing others' private information, such as a physical or email address,
32+
- Trolling, insulting or derogatory comments, and personal or political attacks
33+
- Public or private harassment
34+
- Publishing others' private information, such as a physical or email address,
3535
without their explicit permission
36-
* Other conduct which could reasonably be considered inappropriate in a
36+
- Other conduct which could reasonably be considered inappropriate in a
3737
professional setting
3838

3939
## Enforcement Responsibilities

CONTRIBUTING.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Instances of abusive, harassing, or otherwise unacceptable behavior may be repor
1010

1111
We use GitHub to manage reviews of pull requests.
1212

13-
* If you are a new contributor, see: [Steps to Contribute](#steps-to-contribute)
13+
- If you are a new contributor, see: [Steps to Contribute](#steps-to-contribute)
1414

15-
* Before implementing your change, create an issue that describes the problem you would like to solve or the code that should be enhanced. Please note that you are willing to work on that issue.
15+
- Before implementing your change, create an issue that describes the problem you would like to solve or the code that should be enhanced. Please note that you are willing to work on that issue.
1616

17-
* The team will review the issue and decide whether it should be implemented as a pull request. In that case, they will assign the issue to you. If the team decides against picking up the issue, the team will post a comment with an explanation.
17+
- The team will review the issue and decide whether it should be implemented as a pull request. In that case, they will assign the issue to you. If the team decides against picking up the issue, the team will post a comment with an explanation.
1818

1919
## Steps to Contribute
2020

@@ -28,11 +28,11 @@ You are welcome to contribute code in order to fix a bug or to implement a new f
2828

2929
The following rule governs code contributions:
3030

31-
* Contributions must be licensed under the [Apache 2.0 License](./LICENSE)
32-
* Due to legal reasons, contributors will be asked to accept a Developer Certificate of Origin (DCO) when they create the first pull request to this project. This happens in an automated fashion during the submission process. SAP uses [the standard DCO text of the Linux Foundation](https://developercertificate.org/).
31+
- Contributions must be licensed under the [Apache 2.0 License](./LICENSE)
32+
- Due to legal reasons, contributors will be asked to accept a Developer Certificate of Origin (DCO) when they create the first pull request to this project. This happens in an automated fashion during the submission process. SAP uses [the standard DCO text of the Linux Foundation](https://developercertificate.org/).
3333

3434
## Issues and Planning
3535

36-
* We use GitHub issues to track bugs and enhancement requests.
36+
- We use GitHub issues to track bugs and enhancement requests.
3737

38-
* Please provide as much context as possible when you open an issue. The information you provide must be comprehensive enough to reproduce that issue for the assignee.
38+
- Please provide as much context as possible when you open an issue. The information you provide must be comprehensive enough to reproduce that issue for the assignee.

src/redisWrapper.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ const _createClientBase = () => {
9595
);
9696
}
9797
} else {
98-
return redis.createClient({ socket: { reconnectStrategy: _localReconnectStrategy } });
98+
// NOTE: documentation is buried here https://github.com/redis/node-redis/blob/master/docs/client-configuration.md
99+
// NOTE: we make the host explicit here to avoid ipv4/ipv6 ambivalence problems that got introduced with node v18
100+
return redis.createClient({ socket: { host: "127.0.0.1", reconnectStrategy: _localReconnectStrategy } });
99101
}
100102
};
101103

test/logger.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ describe("logger test", () => {
102102
expect(processStreamSpy.stdout.mock.calls.map(cleanupJSONLogCalls)).toMatchInlineSnapshot(`
103103
[
104104
[
105-
"{"component_type":"application","layer":"Testing","logger":"nodejs-logger","level":"error","stacktrace":["FeatureTogglesError: error during registered validator: bad validator"],"msg":"","type":"log","errInfo":"{\\"validator\\":\\"mockConstructor\\",\\"key\\":\\"test/feature_b\\",\\"value\\":1}"}",
105+
"{"logger":"nodejs-logger","type":"log","msg":"","level":"error","stacktrace":["FeatureTogglesError: error during registered validator: bad validator"],"layer":"Testing","errInfo":"{\\"validator\\":\\"mockConstructor\\",\\"key\\":\\"test/feature_b\\",\\"value\\":1}"}",
106106
],
107107
[
108-
"{"component_type":"application","layer":"Testing","logger":"nodejs-logger","level":"warn","stacktrace":["FeatureTogglesError: found invalid fallback values during initialization"],"msg":"","type":"log","errInfo":"{\\"validationErrors\\":\\"[{\\\\\\"key\\\\\\":\\\\\\"test/feature_b\\\\\\",\\\\\\"errorMessage\\\\\\":\\\\\\"registered validator \\\\\\\\\\\\\\"{0}\\\\\\\\\\\\\\" failed for value \\\\\\\\\\\\\\"{1}\\\\\\\\\\\\\\" with error {2}\\\\\\",\\\\\\"errorMessageValues\\\\\\":[\\\\\\"mockConstructor\\\\\\",1,\\\\\\"bad validator\\\\\\"]}]\\"}"}",
108+
"{"logger":"nodejs-logger","type":"log","msg":"","level":"warn","stacktrace":["FeatureTogglesError: found invalid fallback values during initialization"],"layer":"Testing","errInfo":"{\\"validationErrors\\":\\"[{\\\\\\"key\\\\\\":\\\\\\"test/feature_b\\\\\\",\\\\\\"errorMessage\\\\\\":\\\\\\"registered validator \\\\\\\\\\\\\\"{0}\\\\\\\\\\\\\\" failed for value \\\\\\\\\\\\\\"{1}\\\\\\\\\\\\\\" with error {2}\\\\\\",\\\\\\"errorMessageValues\\\\\\":[\\\\\\"mockConstructor\\\\\\",1,\\\\\\"bad validator\\\\\\"]}]\\"}"}",
109109
],
110110
[
111-
"{"component_type":"application","layer":"Testing","logger":"nodejs-logger","level":"info","msg":"finished initialization with 8 feature toggles with NO_REDIS","type":"log"}",
111+
"{"logger":"nodejs-logger","type":"log","msg":"finished initialization with 8 feature toggles with NO_REDIS","level":"info","layer":"Testing"}",
112112
],
113113
]
114114
`);

test/redisWrapper.test.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,16 @@ describe("redis wrapper test", () => {
6868
const client = redisWrapper._._createClientBase();
6969

7070
expect(redis.createClient).toHaveBeenCalledTimes(1);
71-
expect(redis.createClient).toHaveBeenCalledWith({
72-
socket: { reconnectStrategy: redisWrapper._._localReconnectStrategy },
73-
});
71+
expect(redis.createClient.mock.calls[0]).toMatchInlineSnapshot(`
72+
[
73+
{
74+
"socket": {
75+
"host": "127.0.0.1",
76+
"reconnectStrategy": [Function],
77+
},
78+
},
79+
]
80+
`);
7481
expect(client).toBe(mockClient);
7582
expect(loggerSpy.error).not.toHaveBeenCalled();
7683
});

0 commit comments

Comments
 (0)