@stonyx/cron 0.2.1-alpha.0 → 0.2.1-beta.1

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.
@@ -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,10 +9,10 @@
9
9
  [gc]
10
10
  auto = 0
11
11
  [http "https://github.com/"]
12
- extraheader = AUTHORIZATION: basic eC1hY2Nlc3MtdG9rZW46Z2hzX3VEalZ2VU1jcHZHb1d4YzJHRFlqbER6VkxRVDVrQzEzU1JZQQ==
13
- [branch "fix/use-published-dependencies"]
12
+ extraheader = AUTHORIZATION: basic eC1hY2Nlc3MtdG9rZW46Z2hwX2hBdU5WbnJNcml2bktkZTlmaU80WW9lZk9QenZtdTFiUWtQNA==
13
+ [branch "main"]
14
14
  remote = origin
15
- merge = refs/heads/fix/use-published-dependencies
15
+ merge = refs/heads/main
16
16
  [user]
17
17
  name = github-actions[bot]
18
18
  email = github-actions[bot]@users.noreply.github.com
@@ -2,35 +2,15 @@ name: CI
2
2
 
3
3
  on:
4
4
  pull_request:
5
- branches:
6
- - dev
7
- - main
5
+ branches: [dev, main]
8
6
 
9
7
  concurrency:
10
8
  group: ci-${{ github.head_ref || github.ref }}
11
9
  cancel-in-progress: true
12
10
 
11
+ permissions:
12
+ contents: read
13
+
13
14
  jobs:
14
15
  test:
15
- runs-on: ubuntu-latest
16
-
17
- steps:
18
- - name: Checkout code
19
- uses: actions/checkout@v3
20
-
21
- - name: Setup pnpm
22
- uses: pnpm/action-setup@v4
23
- with:
24
- version: 9
25
-
26
- - name: Set up Node.js
27
- uses: actions/setup-node@v3
28
- with:
29
- node-version: 24.13.0
30
- cache: 'pnpm'
31
-
32
- - name: Install dependencies
33
- run: pnpm install --frozen-lockfile
34
-
35
- - name: Run tests
36
- run: pnpm test
16
+ uses: abofs/stonyx-workflows/.github/workflows/ci.yml@main
@@ -1,7 +1,8 @@
1
1
  name: Publish to NPM
2
2
 
3
3
  on:
4
- # Manual trigger (kept for flexibility)
4
+ repository_dispatch:
5
+ types: [cascade-publish]
5
6
  workflow_dispatch:
6
7
  inputs:
7
8
  version-type:
@@ -9,7 +10,6 @@ on:
9
10
  required: true
10
11
  type: choice
11
12
  options:
12
- - alpha
13
13
  - patch
14
14
  - minor
15
15
  - major
@@ -17,127 +17,35 @@ on:
17
17
  description: 'Custom version (optional, overrides version-type)'
18
18
  required: false
19
19
  type: string
20
-
21
- # Auto-publish alpha on PR
22
20
  pull_request:
23
21
  types: [opened, synchronize, reopened]
24
- branches: [main, dev]
25
-
26
- # Auto-publish stable on merge to main
22
+ branches: [main]
27
23
  push:
28
24
  branches: [main]
29
25
 
26
+ concurrency:
27
+ group: ${{ github.event_name == 'repository_dispatch' && 'cascade-update' || format('publish-{0}', github.ref) }}
28
+ cancel-in-progress: false
29
+
30
30
  permissions:
31
31
  contents: write
32
- id-token: write # Required for npm provenance
33
- pull-requests: write # For PR comments
32
+ id-token: write
33
+ pull-requests: write
34
34
 
35
35
  jobs:
36
36
  publish:
37
- runs-on: ubuntu-latest
38
-
39
- steps:
40
- - name: Checkout code
41
- uses: actions/checkout@v3
42
- with:
43
- fetch-depth: 0
44
- # For PR events, check out the PR branch
45
- ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
46
-
47
- - name: Setup pnpm
48
- uses: pnpm/action-setup@v4
49
- with:
50
- version: 9
51
-
52
- - name: Set up Node.js
53
- uses: actions/setup-node@v3
54
- with:
55
- node-version: 24.13.0
56
- cache: 'pnpm'
57
- registry-url: 'https://registry.npmjs.org'
58
-
59
- - name: Install dependencies
60
- run: pnpm install --frozen-lockfile
61
-
62
- - name: Run tests
63
- run: pnpm test
64
-
65
- - name: Configure git
66
- run: |
67
- git config user.name "github-actions[bot]"
68
- git config user.email "github-actions[bot]@users.noreply.github.com"
69
-
70
- # Determine version type based on trigger
71
- - name: Determine version bump type
72
- id: version-type
73
- run: |
74
- if [ "${{ github.event_name }}" = "pull_request" ]; then
75
- echo "type=alpha" >> $GITHUB_OUTPUT
76
- elif [ "${{ github.event_name }}" = "push" ]; then
77
- echo "type=patch" >> $GITHUB_OUTPUT
78
- elif [ "${{ github.event.inputs.custom-version }}" != "" ]; then
79
- echo "type=custom" >> $GITHUB_OUTPUT
80
- else
81
- echo "type=${{ github.event.inputs.version-type }}" >> $GITHUB_OUTPUT
82
- fi
83
-
84
- # Version bumping
85
- - name: Bump version (custom)
86
- if: steps.version-type.outputs.type == 'custom'
87
- run: pnpm version ${{ github.event.inputs.custom-version }} --no-git-tag-version
88
-
89
- - name: Bump version (alpha)
90
- if: steps.version-type.outputs.type == 'alpha'
91
- run: pnpm version prerelease --preid=alpha --no-git-tag-version
92
-
93
- - name: Bump version (patch/minor/major)
94
- if: steps.version-type.outputs.type == 'patch' || steps.version-type.outputs.type == 'minor' || steps.version-type.outputs.type == 'major'
95
- run: pnpm version ${{ steps.version-type.outputs.type }} --no-git-tag-version
96
-
97
- - name: Get package version
98
- id: package-version
99
- run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
100
-
101
- # Publishing
102
- - name: Publish to NPM (alpha)
103
- if: contains(steps.package-version.outputs.version, 'alpha')
104
- run: pnpm publish --tag alpha --access public --no-git-checks
105
-
106
- - name: Publish to NPM (stable)
107
- if: "!contains(steps.package-version.outputs.version, 'alpha')"
108
- run: pnpm publish --access public
109
-
110
- # Only commit and tag for stable releases (push to main or manual stable)
111
- - name: Commit version bump and create tag
112
- if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !contains(steps.package-version.outputs.version, 'alpha'))
113
- run: |
114
- git add package.json
115
- git commit -m "chore: release v${{ steps.package-version.outputs.version }}"
116
- git tag v${{ steps.package-version.outputs.version }}
117
- git push origin main --tags
118
-
119
- - name: Create GitHub Release
120
- if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !contains(steps.package-version.outputs.version, 'alpha'))
121
- uses: actions/create-release@v1
122
- env:
123
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124
- with:
125
- tag_name: v${{ steps.package-version.outputs.version }}
126
- release_name: v${{ steps.package-version.outputs.version }}
127
- draft: false
128
- prerelease: false
129
-
130
- # Add PR comment with alpha version info
131
- - name: Comment on PR with alpha version
132
- if: github.event_name == 'pull_request'
133
- uses: actions/github-script@v6
134
- with:
135
- script: |
136
- const version = '${{ steps.package-version.outputs.version }}';
137
- const packageName = require('./package.json').name;
138
- github.rest.issues.createComment({
139
- issue_number: context.issue.number,
140
- owner: context.repo.owner,
141
- repo: context.repo.repo,
142
- body: `## 🚀 Alpha Version Published\n\n**Version:** \`${version}\`\n\n**Install:**\n\`\`\`bash\npnpm add ${packageName}@${version}\n# or\npnpm add ${packageName}@alpha # latest alpha\n\`\`\`\n\nThis alpha version is now available for testing!`
143
- });
37
+ if: "!contains(github.event.head_commit.message, '[skip ci]')"
38
+ uses: abofs/stonyx-workflows/.github/workflows/npm-publish.yml@main
39
+ with:
40
+ version-type: ${{ github.event.inputs.version-type }}
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 }}
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
- > All other methods and classes (like `MinHeap`) are used internally and are not intended for direct use.
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-alpha.0",
7
- "description": "",
6
+ "version": "0.2.1-beta.1",
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": "^0.2.2",
35
+ "@stonyx/utils": "0.2.3-beta.2",
36
36
  "qunit": "^2.24.1",
37
37
  "sinon": "^21.0.0"
38
38
  },
39
39
  "dependencies": {
40
- "stonyx": "^0.2.2"
40
+ "stonyx": "0.2.3-beta.1"
41
41
  },
42
42
  "scripts": {
43
- "test": "qunit --require ./stonyx-bootstrap.cjs"
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: ^0.2.2
13
- version: 0.2.2
12
+ specifier: 0.2.3-beta.1
13
+ version: 0.2.3-beta.1
14
14
  devDependencies:
15
15
  '@stonyx/utils':
16
- specifier: ^0.2.2
17
- version: 0.2.2
16
+ specifier: 0.2.3-beta.2
17
+ version: 0.2.3-beta.2
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.2':
37
- resolution: {integrity: sha512-z/pDbX3QPeVJ3kFpU1rQURj3+BLwvGkLHVJiSckmjaBZ/vQIZzaerkf6BTZnHbSmQuUwO0lFzJRwlKOTIaXp0g==}
36
+ '@stonyx/utils@0.2.3-beta.2':
37
+ resolution: {integrity: sha512-GsKNqYPtf2SpvcDTvWB+TBee7uzDeLWXjXDHwSQR/Y6wTMbjH6YtU4gaITB19P74vGe/4Xwpuf+3UTeM0/3PjQ==}
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.2:
168
- resolution: {integrity: sha512-X37/2R2YklI+CX4wKHckPg2pFmOL1hk0CwOMvn7E00sE+8JjhmbHvAeTI+0t50kufBsXKREPX3FBHVUd4Yi4Fw==}
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.2': {}
208
+ '@stonyx/utils@0.2.3-beta.2': {}
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.2:
346
+ stonyx@0.2.3-beta.1:
346
347
  dependencies:
347
348
  node-chronicle: 0.2.0
348
349
 
@@ -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;