Skip to content

Commit f5b0207

Browse files
authored
Updated axios & fixed tests & other quality fixes (#37)
* Update deps * eslint * Add `.idea` * Update package-lock.json * Small quality fixes * Update * sefinek24/cronitor-js * @sefinek/cronitor * Update * Update GH workflows * Use `Buffer.from` * 2.3.5 * Replace to `cronitor` * cronitorio/cronitor-js * Quality fixes * Add `.npmignore` * Small fixes * Update README.md * Remove empty lines * #37 (comment) * Update tests
1 parent c8c252c commit f5b0207

13 files changed

+1004
-2244
lines changed

.eslintrc.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module.exports = {
2+
'extends': [
3+
'eslint:recommended',
4+
],
5+
'env': {
6+
'node': true,
7+
'es2023': true,
8+
},
9+
'parserOptions': {
10+
'ecmaVersion': 2023,
11+
},
12+
'rules': {
13+
'arrow-spacing': ['warn', { 'before': true, 'after': true }],
14+
'comma-dangle': ['error', 'always-multiline'],
15+
'comma-spacing': 'error',
16+
'comma-style': 'error',
17+
'curly': ['error', 'multi-line', 'consistent'],
18+
'dot-location': ['error', 'property'],
19+
'handle-callback-err': 'off',
20+
'indent': ['warn', 4],
21+
'keyword-spacing': 'warn',
22+
'max-nested-callbacks': ['error', { 'max': 4 }],
23+
'max-statements-per-line': ['error', { 'max': 2 }],
24+
'no-console': 'off',
25+
'no-empty-function': 'error',
26+
'no-floating-decimal': 'error',
27+
'no-lonely-if': 'error',
28+
'no-multi-spaces': 'warn',
29+
'no-multiple-empty-lines': ['warn', { 'max': 4, 'maxEOF': 1, 'maxBOF': 0 }],
30+
'no-shadow': ['error', { 'allow': ['err', 'resolve', 'reject'] }],
31+
'no-trailing-spaces': ['warn'],
32+
'no-var': 'error',
33+
'object-curly-spacing': ['error', 'always'],
34+
'prefer-const': 'error',
35+
'quotes': ['warn', 'single'],
36+
'semi': ['warn', 'always'],
37+
'space-before-blocks': 'error',
38+
'space-before-function-paren': ['error', {
39+
'anonymous': 'never',
40+
'named': 'never',
41+
'asyncArrow': 'always',
42+
}],
43+
'space-in-parens': 'error',
44+
'space-infix-ops': 'error',
45+
'space-unary-ops': 'error',
46+
'spaced-comment': 'warn',
47+
'yoda': 'error',
48+
'no-use-before-define': ['error', { 'functions': false, 'classes': true }],
49+
'no-unused-vars': 'warn',
50+
'wrap-regex': 'error',
51+
'sort-vars': 'warn',
52+
'no-unreachable': 'warn',
53+
},
54+
};

.github/workflows/node.js.yml

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3-
4-
name: Tests
1+
name: Node.js CI
52

63
on:
74
push:
85
pull_request:
96

107
jobs:
11-
build:
8+
test:
129

1310
runs-on: ubuntu-latest
1411

1512
strategy:
1613
matrix:
17-
node-version: [10.x, 12.x, 14.x]
14+
node-version: [16.x, 18.x, 20.x, 21.x]
1815

1916
steps:
20-
- uses: actions/checkout@v2
21-
- name: Use Node.js ${{ matrix.node-version }}
22-
uses: actions/setup-node@v1
23-
with:
24-
node-version: ${{ matrix.node-version }}
25-
- run: npm ci
26-
- run: npm run build --if-present
27-
- run: npm test
17+
- uses: actions/checkout@v4
18+
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Run tests
29+
run: npm run test

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
.idea
2+
.vscode
13
.DS_Store
24
node_modules
35
npm-debug.log
46
coverage
5-
.vscode

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.github

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Cronitor Node Library
22

3-
![Tests](https://github.com/cronitorio/cronitor-js/workflows/Tests/badge.svg)
3+
![Tests](https://github.com/cronitorio/cronitor-js/workflows/Node.js%20CI/badge.svg)
44

5-
[Cronitor](https://cronitor.io/) provides end-to-end monitoring for background jobs, websites, APIs, and anything else that can send or receive an HTTP request. This library provides convenient access to the Cronitor API from applications written in Javascript. See our [API docs](https://cronitor.io/docs/api) for detailed references on configuring monitors and sending telemetry pings.
5+
[Cronitor](https://cronitor.io) provides end-to-end monitoring for background jobs, websites, APIs, and anything else that can send or receive an HTTP request. This library provides convenient access to the Cronitor API from applications written in Javascript. See our [API docs](https://cronitor.io/docs/api) for detailed references on configuring monitors and sending telemetry pings.
66

77
In this guide:
88

@@ -34,7 +34,7 @@ cron.wraps(nodeCron);
3434

3535
// the first parameter is now the key that Cronitor will use
3636
// to send telemetry events when the jobs runs, completes or fails
37-
cron.schedule('SendWelcomeEmail', '*/5 * * * *', function() {
37+
cron.schedule('SendWelcomeEmail', '*/5 * * * *', () => {
3838
console.log('Sending welcome email to new sign ups every five minutes.');
3939
});
4040
```
@@ -46,7 +46,7 @@ Cronitor can wrap any function with telemetry pings.
4646
```javascript
4747
const cronitor = require('cronitor')('cronitor_api_key');
4848

49-
let asyncWorker = cronitor.wrap('background-worker', async function() {
49+
let asyncWorker = cronitor.wrap('background-worker', async () => {
5050
// do some async work
5151
});
5252

@@ -68,7 +68,7 @@ event = new cronitor.Event('monitor-key');
6868

6969
const app = Consumer.create({
7070
queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',
71-
pollingWaitTimeMs: 100 // duration to wait before repolling the queue (defaults to 0).
71+
pollingWaitTimeMs: 100, // duration to wait before repolling the queue (defaults to 0).
7272
handleMessage: async (message) => {
7373
// do some work with `message`
7474
}
@@ -206,7 +206,7 @@ const uptimeMonitor = await cronitor.Monitor.put({
206206
schedule: 'every 45 seconds',
207207
request: {
208208
url: 'https://cronitor.io'
209-
}
209+
},
210210
assertions: [
211211
'response.code = 200',
212212
'response.time < 600ms'
@@ -227,7 +227,7 @@ monitor.delete() // destroy the monitor
227227

228228
## Package Configuration
229229

230-
The package needs to be configured with your account's `API key`, which is available on the [account settings](https://cronitor.io/settings) page. You can also optionally specify an `api_version`, an `environment`, and a request `timeout`.
230+
The package needs to be configured with your account's `API key`, which is available on the [account settings](https://cronitor.io/settings) page. You can also optionally specify an `api_version`, an `environment`, and a request `timeout`.
231231

232232
These can also be supplied using the environment variables `CRONITOR_API_KEY`, `CRONITOR_API_VERSION`, `CRONITOR_ENVIRONMENT`, `CRONITOR_TIMEOUT`.
233233

examples/event-example.js

+22-24
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
1-
const axios = require('axios')
2-
const Parser = require('rss-parser')
3-
const cronitor = require('../lib/cronitor')('fakeApiKey')
4-
let parser = new Parser()
1+
const Parser = require('rss-parser');
2+
const cronitor = require('../lib/cronitor')('fakeApiKey');
3+
const parser = new Parser();
54

6-
const event = new cronitor.Event('monitor-key')
5+
const event = new cronitor.Event('monitor-key');
76

87
async function init() {
9-
let currStatus = status = await checkGithubStatus()
10-
while(true) {
11-
status = await checkGithubStatus()
12-
if (currStatus != status) {
13-
sendStatusAlert(status)
14-
currStatus = status
15-
} else {
16-
console.log("no new incident")
8+
let currStatus = status = await checkGithubStatus();
9+
while (true) {
10+
status = await checkGithubStatus();
11+
if (currStatus !== status) {
12+
await sendStatusAlert(status);
13+
currStatus = status;
14+
} else {
15+
console.log('No new incident');
16+
}
17+
18+
await sleep(1);
19+
event.tick();
1720
}
18-
await sleep(1)
19-
event.tick()
20-
}
21-
}; init()
21+
} init();
2222

2323
async function checkGithubStatus() {
24-
let feed = await parser.parseURL('https://www.githubstatus.com/history.rss')
25-
return feed.items[0]['title']
24+
const feed = await parser.parseURL('https://www.githubstatus.com/history.rss');
25+
return feed.items[0]['title'];
2626
}
2727

2828
function sleep(seconds) {
29-
return new Promise(resolve => setTimeout(resolve, (seconds * 1000)));
29+
return new Promise(resolve => setTimeout(resolve, (seconds * 1000)));
3030
}
3131

3232
function sendStatusAlert(status) {
33-
// simulate network call
34-
return new Promise(resolve => setTimeout(resolve, 100)).then(() => console.log(`New Incident! ${status}`));
33+
// simulate network call
34+
return new Promise(resolve => setTimeout(resolve, 100)).then(() => console.log(`New Incident! ${status}`));
3535
}
36-
37-

0 commit comments

Comments
 (0)