@stonyx/cron 0.2.1-beta.0 → 0.2.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/architecture.md +215 -0
- package/.claude/extension-guide.md +291 -0
- package/.claude/improvements.md +53 -0
- package/.claude/project-structure.md +29 -661
- package/.claude/testing.md +85 -0
- package/.git/config +1 -1
- package/.github/workflows/publish.yml +17 -1
- package/README.md +1 -1
- package/package.json +5 -5
- package/pnpm-lock.yaml +11 -10
- package/stonyx-bootstrap.cjs +0 -9
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Testing Guidelines
|
|
2
|
+
|
|
3
|
+
## Testing Guidelines
|
|
4
|
+
|
|
5
|
+
### Test Structure
|
|
6
|
+
Tests are located in `stonyx-cron/test/unit/` and use QUnit modules:
|
|
7
|
+
|
|
8
|
+
```javascript
|
|
9
|
+
import QUnit from 'qunit';
|
|
10
|
+
import sinon from 'sinon';
|
|
11
|
+
import { setupIntegrationTests } from "stonyx/test-helpers";
|
|
12
|
+
|
|
13
|
+
const { module, test } = QUnit;
|
|
14
|
+
|
|
15
|
+
module('[Unit] Cron', function (hooks) {
|
|
16
|
+
setupIntegrationTests(hooks);
|
|
17
|
+
|
|
18
|
+
let cron, clock;
|
|
19
|
+
|
|
20
|
+
hooks.beforeEach(function () {
|
|
21
|
+
clock = sinon.useFakeTimers({ shouldAdvanceTime: false });
|
|
22
|
+
cron = new Cron();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
hooks.afterEach(function () {
|
|
26
|
+
sinon.restore();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('test description', async function (assert) {
|
|
30
|
+
// Test implementation
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Fake Timers Pattern (CRITICAL)
|
|
36
|
+
**Always use fake timers for time-based tests:**
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
// Setup in beforeEach
|
|
40
|
+
clock = sinon.useFakeTimers({ shouldAdvanceTime: false });
|
|
41
|
+
|
|
42
|
+
// Advance time synchronously
|
|
43
|
+
clock.tick(5000); // Advance 5 seconds
|
|
44
|
+
|
|
45
|
+
// For async operations, use tickAsync
|
|
46
|
+
clock.tick(5000);
|
|
47
|
+
await clock.tickAsync(0); // Process async callbacks
|
|
48
|
+
|
|
49
|
+
// Cleanup in afterEach
|
|
50
|
+
sinon.restore();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Why `shouldAdvanceTime: false`?**
|
|
54
|
+
Prevents real time from interfering with fake time, ensuring deterministic tests.
|
|
55
|
+
|
|
56
|
+
### Spies & Stubs Patterns
|
|
57
|
+
```javascript
|
|
58
|
+
// Spy on function calls
|
|
59
|
+
const cb = sinon.spy();
|
|
60
|
+
cron.register('job1', cb, 5);
|
|
61
|
+
assert.ok(cb.calledOnce, 'Callback executed once');
|
|
62
|
+
|
|
63
|
+
// Stub methods
|
|
64
|
+
const stub = sinon.stub().rejects(new Error('boom'));
|
|
65
|
+
cron.register('jobErr', stub, 1);
|
|
66
|
+
|
|
67
|
+
// Spy on existing methods
|
|
68
|
+
const logSpy = sinon.spy(log, 'cron');
|
|
69
|
+
cron.log('test message');
|
|
70
|
+
assert.ok(logSpy.calledOnce, 'Log called');
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Test Coverage Expectations
|
|
74
|
+
Tests should cover:
|
|
75
|
+
- Job registration and execution
|
|
76
|
+
- Rescheduling behavior
|
|
77
|
+
- Unregistration
|
|
78
|
+
- Error handling
|
|
79
|
+
- Configuration-driven logging
|
|
80
|
+
- Edge cases (empty heap, multiple jobs, etc.)
|
|
81
|
+
|
|
82
|
+
### Running Tests
|
|
83
|
+
```bash
|
|
84
|
+
pnpm test # Runs: stonyx test
|
|
85
|
+
```
|
package/.git/config
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[gc]
|
|
10
10
|
auto = 0
|
|
11
11
|
[http "https://github.com/"]
|
|
12
|
-
extraheader = AUTHORIZATION: basic
|
|
12
|
+
extraheader = AUTHORIZATION: basic eC1hY2Nlc3MtdG9rZW46Z2hwX2hBdU5WbnJNcml2bktkZTlmaU80WW9lZk9QenZtdTFiUWtQNA==
|
|
13
13
|
[branch "main"]
|
|
14
14
|
remote = origin
|
|
15
15
|
merge = refs/heads/main
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
name: Publish to NPM
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
|
+
repository_dispatch:
|
|
5
|
+
types: [cascade-publish]
|
|
4
6
|
workflow_dispatch:
|
|
5
7
|
inputs:
|
|
6
8
|
version-type:
|
|
@@ -17,10 +19,14 @@ on:
|
|
|
17
19
|
type: string
|
|
18
20
|
pull_request:
|
|
19
21
|
types: [opened, synchronize, reopened]
|
|
20
|
-
branches: [main
|
|
22
|
+
branches: [main]
|
|
21
23
|
push:
|
|
22
24
|
branches: [main]
|
|
23
25
|
|
|
26
|
+
concurrency:
|
|
27
|
+
group: ${{ github.event_name == 'repository_dispatch' && 'cascade-update' || format('publish-{0}', github.ref) }}
|
|
28
|
+
cancel-in-progress: false
|
|
29
|
+
|
|
24
30
|
permissions:
|
|
25
31
|
contents: write
|
|
26
32
|
id-token: write
|
|
@@ -28,8 +34,18 @@ permissions:
|
|
|
28
34
|
|
|
29
35
|
jobs:
|
|
30
36
|
publish:
|
|
37
|
+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
|
|
31
38
|
uses: abofs/stonyx-workflows/.github/workflows/npm-publish.yml@main
|
|
32
39
|
with:
|
|
33
40
|
version-type: ${{ github.event.inputs.version-type }}
|
|
34
41
|
custom-version: ${{ github.event.inputs.custom-version }}
|
|
42
|
+
cascade-source: ${{ github.event.client_payload.source_package || '' }}
|
|
43
|
+
secrets: inherit
|
|
44
|
+
|
|
45
|
+
cascade:
|
|
46
|
+
needs: publish
|
|
47
|
+
uses: abofs/stonyx-workflows/.github/workflows/cascade.yml@main
|
|
48
|
+
with:
|
|
49
|
+
package-name: ${{ needs.publish.outputs.package-name }}
|
|
50
|
+
published-version: ${{ needs.publish.outputs.published-version }}
|
|
35
51
|
secrets: inherit
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ When a job is executed, its next trigger time is updated, and it is re-inserted
|
|
|
31
31
|
| `register` | `key: string, callback: Function, interval: number, runOnInit?: boolean` | Register a new job with a given interval in seconds. If `runOnInit` is true, the job runs immediately upon registration. |
|
|
32
32
|
| `unregister` | `key: string` | Remove a previously registered job. |
|
|
33
33
|
|
|
34
|
-
>
|
|
34
|
+
> `MinHeap` is also exported as a public subpath (`@stonyx/cron/min-heap`) and can be imported directly for advanced usage.
|
|
35
35
|
|
|
36
36
|
## Configuration
|
|
37
37
|
|
package/package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"keywords": [
|
|
4
4
|
"stonyx-module"
|
|
5
5
|
],
|
|
6
|
-
"version": "0.2.1-beta.
|
|
7
|
-
"description": "",
|
|
6
|
+
"version": "0.2.1-beta.2",
|
|
7
|
+
"description": "Cron/job scheduler for Stonyx framework",
|
|
8
8
|
"main": "src/main.js",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"files": [
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/abofs/stonyx-cron#readme",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@stonyx/utils": "
|
|
35
|
+
"@stonyx/utils": "0.2.3-beta.3",
|
|
36
36
|
"qunit": "^2.24.1",
|
|
37
37
|
"sinon": "^21.0.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"stonyx": "
|
|
40
|
+
"stonyx": "0.2.3-beta.1"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
|
-
"test": "
|
|
43
|
+
"test": "stonyx test"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/pnpm-lock.yaml
CHANGED
|
@@ -9,12 +9,12 @@ importers:
|
|
|
9
9
|
.:
|
|
10
10
|
dependencies:
|
|
11
11
|
stonyx:
|
|
12
|
-
specifier:
|
|
13
|
-
version: 0.2.
|
|
12
|
+
specifier: 0.2.3-beta.1
|
|
13
|
+
version: 0.2.3-beta.1
|
|
14
14
|
devDependencies:
|
|
15
15
|
'@stonyx/utils':
|
|
16
|
-
specifier:
|
|
17
|
-
version: 0.2.
|
|
16
|
+
specifier: 0.2.3-beta.3
|
|
17
|
+
version: 0.2.3-beta.3
|
|
18
18
|
qunit:
|
|
19
19
|
specifier: ^2.24.1
|
|
20
20
|
version: 2.25.0
|
|
@@ -33,8 +33,8 @@ packages:
|
|
|
33
33
|
'@sinonjs/samsam@8.0.3':
|
|
34
34
|
resolution: {integrity: sha512-hw6HbX+GyVZzmaYNh82Ecj1vdGZrqVIn/keDTg63IgAwiQPO+xCz99uG6Woqgb4tM0mUiFENKZ4cqd7IX94AXQ==}
|
|
35
35
|
|
|
36
|
-
'@stonyx/utils@0.2.
|
|
37
|
-
resolution: {integrity: sha512-
|
|
36
|
+
'@stonyx/utils@0.2.3-beta.3':
|
|
37
|
+
resolution: {integrity: sha512-CLmz/DPgNWU7IXJYQXzmAdph65iapp6mHnvKZQULrd6IdKPGb6KlVMVL29yuyXg0fOapkkoPV4Xf6PmksSE8bw==}
|
|
38
38
|
|
|
39
39
|
call-bind-apply-helpers@1.0.2:
|
|
40
40
|
resolution: {integrity: sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==}
|
|
@@ -164,8 +164,9 @@ packages:
|
|
|
164
164
|
sinon@21.0.1:
|
|
165
165
|
resolution: {integrity: sha512-Z0NVCW45W8Mg5oC/27/+fCqIHFnW8kpkFOq0j9XJIev4Ld0mKmERaZv5DMLAb9fGCevjKwaEeIQz5+MBXfZcDw==}
|
|
166
166
|
|
|
167
|
-
stonyx@0.2.
|
|
168
|
-
resolution: {integrity: sha512-
|
|
167
|
+
stonyx@0.2.3-beta.1:
|
|
168
|
+
resolution: {integrity: sha512-WdMFVHASjPAdZFMVrZ8rHj/7A0onfVUigLLiNrlYHKZFtnxXV9KibQgXlEFEzY6M9z5o0I/bycOqaBWZvjcCfw==}
|
|
169
|
+
hasBin: true
|
|
169
170
|
|
|
170
171
|
supports-color@7.2.0:
|
|
171
172
|
resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==}
|
|
@@ -204,7 +205,7 @@ snapshots:
|
|
|
204
205
|
'@sinonjs/commons': 3.0.1
|
|
205
206
|
type-detect: 4.1.0
|
|
206
207
|
|
|
207
|
-
'@stonyx/utils@0.2.
|
|
208
|
+
'@stonyx/utils@0.2.3-beta.3': {}
|
|
208
209
|
|
|
209
210
|
call-bind-apply-helpers@1.0.2:
|
|
210
211
|
dependencies:
|
|
@@ -342,7 +343,7 @@ snapshots:
|
|
|
342
343
|
diff: 8.0.3
|
|
343
344
|
supports-color: 7.2.0
|
|
344
345
|
|
|
345
|
-
stonyx@0.2.
|
|
346
|
+
stonyx@0.2.3-beta.1:
|
|
346
347
|
dependencies:
|
|
347
348
|
node-chronicle: 0.2.0
|
|
348
349
|
|
package/stonyx-bootstrap.cjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* commonJS Bootstrap loading - Stonyx must be loaded first, prior to the rest of the application
|
|
3
|
-
*/
|
|
4
|
-
const { default:Stonyx } = require('stonyx');
|
|
5
|
-
const { default:config } = require('./config/environment.js');
|
|
6
|
-
|
|
7
|
-
new Stonyx(config, __dirname);
|
|
8
|
-
|
|
9
|
-
module.exports = Stonyx;
|