Skip to content

Commit 681ed1c

Browse files
committed
test: added tests
1 parent abc5cd0 commit 681ed1c

File tree

13 files changed

+1120
-35
lines changed

13 files changed

+1120
-35
lines changed

index.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,13 @@ class Bree {
229229
if (
230230
typeof job.interval !== 'undefined' &&
231231
typeof job.cron !== 'undefined'
232-
)
232+
) {
233233
errors.push(
234234
new Error(
235235
`${prefix} cannot have both interval and cron configuration`
236236
)
237237
);
238+
}
238239

239240
// don't allow users to mix timeout AND date
240241
if (typeof job.timeout !== 'undefined' && typeof job.date !== 'undefined')
@@ -306,13 +307,14 @@ class Bree {
306307
if (schedule.isValid()) {
307308
this.config.jobs[i].interval = schedule;
308309
// delete this.config.jobs[i].cron;
309-
} else {
310-
errors.push(
311-
new Error(
312-
`${prefix} had an invalid cron schedule (see <https://crontab.guru> if you need help)`
313-
)
314-
);
315-
}
310+
} // else {
311+
// errors.push(
312+
// new Error(
313+
// `${prefix} had an invalid cron schedule (see <https://crontab.guru> if you need help)`
314+
// )
315+
// );
316+
// }
317+
// above code will never be called
316318
} else {
317319
for (const message of result.getError()) {
318320
errors.push(
@@ -330,7 +332,9 @@ class Bree {
330332
job.closeWorkerAfterMs <= 0)
331333
)
332334
errors.push(
333-
`${prefix} had an invalid closeWorkerAfterMs value of ${job.closeWorkerAfterMs} (it must be a finite number > 0`
335+
new Error(
336+
`${prefix} had an invalid closeWorkersAfterMs value of ${job.closeWorkersAfterMs} (it must be a finite number > 0)`
337+
)
334338
);
335339

336340
// if timeout was undefined, cron was undefined,

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"files": [
88
"test/*.js",
99
"test/**/*.js",
10-
"!test/jobs"
10+
"!test/jobs",
11+
"!test/noIndexJobs"
1112
],
1213
"verbose": true
1314
},
@@ -31,13 +32,16 @@
3132
"devDependencies": {
3233
"@commitlint/cli": "latest",
3334
"@commitlint/config-conventional": "latest",
35+
"@sinonjs/fake-timers": "^6.0.1",
3436
"ava": "latest",
3537
"codecov": "latest",
3638
"cross-env": "latest",
39+
"delay": "^4.3.0",
3740
"eslint": "^7.4.0",
3841
"eslint-config-xo-lass": "latest",
3942
"fixpack": "latest",
4043
"husky": "latest",
44+
"into-stream": "^5.1.1",
4145
"lint-staged": "latest",
4246
"nyc": "latest",
4347
"remark-cli": "latest",

test/jobs/done.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const delay = require('delay');
2+
const { parentPort } = require('worker_threads');
3+
4+
(async () => {
5+
await delay(1);
6+
7+
if (parentPort) {
8+
parentPort.postMessage('get ready');
9+
parentPort.postMessage('done');
10+
}
11+
})();

test/jobs/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// eslint-disable-next-line prettier/prettier
2+
module.exports = [ 'basic' ];

test/jobs/infinite.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// eslint-disable-next-line unicorn/no-process-exit
2+
setInterval(() => process.exit(0), 100);

test/jobs/leroy.js/test

Whitespace-only changes.

test/jobs/message.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { parentPort } = require('worker_threads');
2+
3+
setInterval(() => {}, 10);
4+
5+
if (parentPort) {
6+
parentPort.on('message', (message) => {
7+
if (message === 'error') throw new Error('oops');
8+
if (message === 'cancel') {
9+
parentPort.postMessage('cancelled');
10+
return;
11+
}
12+
13+
parentPort.postMessage(message);
14+
process.exit(0);
15+
});
16+
}

test/jobs/short.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setInterval(() => {}, 10);

test/noIndexJobs/basic.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('hello');

test/snapshots/test.js.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Snapshot report for `test/test.js`
2+
3+
The actual snapshot is saved in `test.js.snap`.
4+
5+
Generated by [AVA](https://avajs.dev).
6+
7+
## creates job with cron string
8+
9+
> Snapshot 1
10+
11+
{
12+
isValid: Function isValid {},
13+
next: Function next {},
14+
nextRange: Function nextRange {},
15+
prev: Function prev {},
16+
prevRange: Function prevRange {},
17+
}
18+
19+
## parseValue()
20+
21+
> Snapshot 1
22+
23+
{
24+
isValid: Function isValid {},
25+
next: Function next {},
26+
nextRange: Function nextRange {},
27+
prev: Function prev {},
28+
prevRange: Function prevRange {},
29+
}
30+
31+
## getWorkerMetadata()
32+
33+
> Snapshot 1
34+
35+
{}

test/snapshots/test.js.snap

307 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)