• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RobotWebTools / rclnodejs / 27193208698

09 Jun 2026 08:17AM UTC coverage: 91.22% (+5.7%) from 85.523%
27193208698

push

github

web-flow
Phase 2: convert lib/, index.js and tests to native ES modules (#1530)

**Overview:** 189 files changed, +957 / −1162. Converts `lib/`, `index.js`, `bin/`, `rosocket/` and the full test suite to native ES modules; keeps build/codegen tooling as `.cjs`; updates CI to ROS 2 Lyrical (Ubuntu 26.04); and fixes a native-addon debug-build compile error.

### Core ESM conversion
- **`index.js`** — converted to ESM entrypoint (`import`/`export`), module wiring reworked.
- **`lib/**`** — all library modules converted from `require`/`module.exports` to `import`/`export` (node, client, service, publisher, subscription, action/*, clock*, parameter*, logging*, runtime/*, serialization, time*, timer, qos*, utils, validator, native_loader, etc.).
- **`bin/rclnodejs-web.js`**, **`rosocket/index.js`**, **`rosocket/cli.js`** — converted to ESM.

### ESM/CJS boundary fixes (from Copilot review)
- **`lib/native_loader.js`** — load the CommonJS `bindings` helper via `createRequire`'s `require('bindings')` instead of `import bindings from 'bindings'`, preserving CJS caller context for addon resolution.
- **`lib/type_description_service.js`** — corrected sibling import from `'../lib/parameter.js'` to `'./parameter.js'`.

### CommonJS files kept as `.cjs`
- **`rosidl_gen/*.cjs`** (deallocator, idl_generator, index, primitive_types, templates/message-template), **`rostsd_gen/index.cjs`**, **`scripts/ros_distro.cjs`**, **`scripts/run_test.cjs`** — build/codegen tooling stays CJS (loads ESM helpers via supported `require(esm)` / `.default`).
- **`third_party/ref-napi/`** — `lib/ref.js` and `package.json` tweaks for module resolution.

### Tooling / config
- **`package.json`** — `"type": "module"` and script adjustments.
- **`eslint.config.mjs`** — ESM lint rules.
- **`.c8rc.json`** added, **`.nycrc.yml`** removed — switch coverage from nyc to c8.

### CI
- **`.github/workflows/linux-x64-asan-test.yml`**, **`.github/workflows/linux-x64-build-and-test.yml`** — migrated from ROS 2 ... (continued)

2044 of 2402 branches covered (85.1%)

Branch coverage included in aggregate %.

369 of 370 new or added lines in 65 files covered. (99.73%)

942 existing lines in 47 files now uncovered.

16688 of 18133 relevant lines covered (92.03%)

228.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.38
/lib/timer.js
1
// Copyright (c) 2017 Intel Corporation. All rights reserved.
27✔
2
//
27✔
3
// Licensed under the Apache License, Version 2.0 (the "License");
27✔
4
// you may not use this file except in compliance with the License.
27✔
5
// You may obtain a copy of the License at
27✔
6
//
27✔
7
//     http://www.apache.org/licenses/LICENSE-2.0
27✔
8
//
27✔
9
// Unless required by applicable law or agreed to in writing, software
27✔
10
// distributed under the License is distributed on an "AS IS" BASIS,
27✔
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27✔
12
// See the License for the specific language governing permissions and
27✔
13
// limitations under the License.
27✔
14

27✔
15
import rclnodejs from './native_loader.js';
27✔
16
import DistroUtils from './distro.js';
27✔
17

27✔
18
/**
27✔
19
 * @class - Class representing a Timer in ROS
27✔
20
 * @hideconstructor
27✔
21
 */
27✔
22

27✔
23
class Timer {
27✔
24
  constructor(handle, period, callback) {
27✔
25
    this._handle = handle;
71✔
26
    this._period = period;
71✔
27
    this.callback = callback;
71✔
28
  }
71✔
29

27✔
30
  /**
27✔
31
   * The period of the timer in nanoseconds.
27✔
32
   * @type {bigint}
27✔
33
   */
27✔
34
  get period() {
27✔
35
    return this._period;
3✔
36
  }
3✔
37

27✔
38
  get handle() {
27✔
39
    return this._handle;
8,165✔
40
  }
8,165✔
41

27✔
42
  /**
27✔
43
   * Check if the timer is ready.
27✔
44
   * @return {boolean} Return true if timer is ready, otherwise return false.
27✔
45
   */
27✔
46
  isReady() {
27✔
47
    return rclnodejs.isTimerReady(this._handle);
4,075✔
48
  }
4,075✔
49

27✔
50
  /**
27✔
51
   * Check if the timer is canceled.
27✔
52
   * @return {boolean} Return true if timer is canceled, otherwise return false.
27✔
53
   */
27✔
54
  isCanceled() {
27✔
55
    return rclnodejs.isTimerCanceled(this._handle);
3,008✔
56
  }
3,008✔
57

27✔
58
  /**
27✔
59
   * Cancel the timer.
27✔
60
   * @return {undefined}
27✔
61
   */
27✔
62
  cancel() {
27✔
63
    rclnodejs.cancelTimer(this._handle);
53✔
64
  }
53✔
65

27✔
66
  /**
27✔
67
   * Reset the timer.
27✔
68
   * @return {undefined}
27✔
69
   */
27✔
70
  reset() {
27✔
71
    rclnodejs.resetTimer(this._handle);
4✔
72
  }
4✔
73

27✔
74
  /**
27✔
75
   * Get the interval since the last call of this timer.
27✔
76
   * @return {bigint} - the interval value in nanoseconds.
27✔
77
   */
27✔
78
  timeSinceLastCall() {
27✔
79
    return rclnodejs.timerGetTimeSinceLastCall(this._handle);
1✔
80
  }
1✔
81

27✔
82
  /**
27✔
83
   * Get the interval until the next call will happen.
27✔
84
   * @return {bigint} - the interval value in nanoseconds.
27✔
85
   */
27✔
86
  timeUntilNextCall() {
27✔
87
    return rclnodejs.timerGetTimeUntilNextCall(this._handle);
1✔
88
  }
1✔
89

27✔
90
  /**
27✔
91
   * Get the absolute time in nanoseconds when the next callback is due.
27✔
92
   * Note: Only available on ROS2 distributions after Humble.
27✔
93
   * @return {bigint | null} - The next call time in nanoseconds, or null if the timer is canceled.
27✔
94
   *   Returns undefined if not supported on current ROS2 distribution.
27✔
95
   */
27✔
96
  getNextCallTime() {
27✔
97
    if (typeof rclnodejs.getTimerNextCallTime !== 'function') {
3!
98
      return undefined;
×
UNCOV
99
    }
×
100
    return rclnodejs.getTimerNextCallTime(this._handle);
3✔
101
  }
3✔
102

27✔
103
  /**
27✔
104
   * Change the timer period.
27✔
105
   * @param {bigint} period - The new period in nanoseconds.
27✔
106
   * @return {undefined}
27✔
107
   */
27✔
108
  changeTimerPeriod(period) {
27✔
109
    rclnodejs.changeTimerPeriod(this._handle, period);
1✔
110
  }
1✔
111

27✔
112
  /**
27✔
113
   * Get the timer period.
27✔
114
   * @return {bigint} - The period in nanoseconds.
27✔
115
   */
27✔
116
  get timerPeriod() {
27✔
117
    return rclnodejs.getTimerPeriod(this._handle);
2✔
118
  }
2✔
119

27✔
120
  /**
27✔
121
   * Set the on reset callback.
27✔
122
   * @param {function} callback - The callback to be called when the timer is reset.
27✔
123
   * @return {undefined}
27✔
124
   */
27✔
125
  setOnResetCallback(callback) {
27✔
126
    if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
3✔
127
      console.warn(
1✔
128
        'setOnResetCallback is not supported by this version of ROS 2'
1✔
129
      );
1✔
130
      return;
1✔
131
    }
1✔
132
    rclnodejs.setTimerOnResetCallback(this._handle, callback);
2✔
133
  }
3✔
134

27✔
135
  /**
27✔
136
   * Clear the on reset callback.
27✔
137
   * @return {undefined}
27✔
138
   */
27✔
139
  clearOnResetCallback() {
27✔
140
    if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
2✔
141
      console.warn(
1✔
142
        'clearOnResetCallback is not supported by this version of ROS 2'
1✔
143
      );
1✔
144
      return;
1✔
145
    }
1✔
146
    rclnodejs.clearTimerOnResetCallback(this._handle);
1✔
147
  }
2✔
148

27✔
149
  /**
27✔
150
   * Call a timer and starts counting again, retrieves actual and expected call time.
27✔
151
   * @return {{expectedCallTime: bigint, actualCallTime: bigint}} - The timer information.
27✔
152
   */
27✔
153
  callTimerWithInfo() {
27✔
154
    if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
2✔
155
      console.warn(
1✔
156
        'callTimerWithInfo is not supported by this version of ROS 2'
1✔
157
      );
1✔
158
      return;
1✔
159
    }
1✔
160
    return rclnodejs.callTimerWithInfo(this._handle);
1✔
161
  }
2✔
162
}
27✔
163

27✔
164
export default Timer;
27✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc