qunitx-cli 0.19.3 → 0.21.0
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/README.md +111 -0
- package/dist/cli.js +575 -230
- package/package.json +4 -6
package/README.md
CHANGED
|
@@ -227,6 +227,117 @@ Options:
|
|
|
227
227
|
--browser=<name> Browser engine: chromium (default), firefox, or webkit
|
|
228
228
|
```
|
|
229
229
|
|
|
230
|
+
## Timezone
|
|
231
|
+
|
|
232
|
+
The browser inherits the **OS system timezone** automatically — no Playwright `timezoneId` option is involved. The browser's `Intl.DateTimeFormat().resolvedOptions().timeZone` will match the timezone that Node.js itself reads from the OS.
|
|
233
|
+
|
|
234
|
+
### Setting a timezone for tests
|
|
235
|
+
|
|
236
|
+
| Platform | How Chrome resolves the timezone | Override |
|
|
237
|
+
|----------|----------------------------------|---------|
|
|
238
|
+
| **Linux** | glibc reads `TZ` env var first, then `/etc/localtime` | `TZ=America/New_York npx qunitx …` works |
|
|
239
|
+
| **macOS** | CoreFoundation reads the system timezone (ignores `TZ`) | Must set the system timezone: `sudo systemsetup -settimezone America/New_York` |
|
|
240
|
+
| **Windows** | Reads the registry timezone (ignores `TZ`) | Must set the system timezone: `tzutil /s "Eastern Standard Time"` |
|
|
241
|
+
|
|
242
|
+
On Linux, the `TZ` env var is the simplest way to run tests in a specific timezone:
|
|
243
|
+
|
|
244
|
+
```sh
|
|
245
|
+
TZ=UTC npx qunitx test/**/*.ts
|
|
246
|
+
TZ=America/Los_Angeles npx qunitx test/**/*.ts
|
|
247
|
+
TZ=Europe/Berlin npx qunitx test/**/*.ts
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### CI pitfalls
|
|
251
|
+
|
|
252
|
+
GitHub Actions (and most CI providers) run with **UTC** by default on all platforms. This is usually what you want for reproducible test results. If your tests assert on specific local times or date formatting, be aware:
|
|
253
|
+
|
|
254
|
+
**Linux CI** — override with `TZ` in your workflow step:
|
|
255
|
+
|
|
256
|
+
```yaml
|
|
257
|
+
- run: npx qunitx test/**/*.ts
|
|
258
|
+
env:
|
|
259
|
+
TZ: America/New_York
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**macOS CI** — `TZ` does not affect Chrome. Set the system timezone before running tests:
|
|
263
|
+
|
|
264
|
+
```yaml
|
|
265
|
+
- run: sudo systemsetup -settimezone America/New_York
|
|
266
|
+
- run: npx qunitx test/**/*.ts
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**Windows CI** — same constraint, use `tzutil`:
|
|
270
|
+
|
|
271
|
+
```yaml
|
|
272
|
+
- run: tzutil /s "Eastern Standard Time"
|
|
273
|
+
- run: npx qunitx test/**/*.ts
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
If your test suite does not assert on local times or timezone-sensitive date formatting, none of this matters — the default UTC CI timezone is fine.
|
|
277
|
+
|
|
278
|
+
### Mocking dates and times in tests
|
|
279
|
+
|
|
280
|
+
For most cases you do not need to touch system settings or env vars at all. `Date`, `Intl`, and timers are plain browser globals — mock them in a qunitx `before` / `beforeEach` hook just like any other value:
|
|
281
|
+
|
|
282
|
+
```js
|
|
283
|
+
// test/some-test.ts
|
|
284
|
+
import { module, test } from 'qunitx';
|
|
285
|
+
|
|
286
|
+
module('Invoice formatting', (hooks) => {
|
|
287
|
+
let realDate;
|
|
288
|
+
|
|
289
|
+
hooks.before(() => {
|
|
290
|
+
realDate = globalThis.Date;
|
|
291
|
+
// Pin "now" to a fixed instant for the whole module
|
|
292
|
+
const FIXED = new realDate('2024-06-01T12:00:00Z');
|
|
293
|
+
globalThis.Date = class extends realDate {
|
|
294
|
+
constructor(...args) { super(args.length ? args : [FIXED]); }
|
|
295
|
+
static now() { return FIXED.getTime(); }
|
|
296
|
+
};
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
hooks.after(() => { globalThis.Date = realDate; });
|
|
300
|
+
|
|
301
|
+
test('formats the current date correctly', (assert) => {
|
|
302
|
+
assert.equal(new Date().toISOString().slice(0, 10), '2024-06-01');
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
For richer control over timers (`setTimeout`, `setInterval`, `requestAnimationFrame`, …) use a fake-timer library such as [Sinon.JS](https://sinonjs.org/releases/latest/fake-timers/):
|
|
308
|
+
|
|
309
|
+
```js
|
|
310
|
+
import sinon from 'sinon';
|
|
311
|
+
|
|
312
|
+
module('Debounce logic', (hooks) => {
|
|
313
|
+
let clock;
|
|
314
|
+
|
|
315
|
+
hooks.before(() => { clock = sinon.useFakeTimers({ now: new Date('2024-06-01T00:00:00Z') }); });
|
|
316
|
+
hooks.after(() => { clock.restore(); });
|
|
317
|
+
|
|
318
|
+
test('fires after 300 ms', (assert) => {
|
|
319
|
+
// clock.tick(300) advances fake time without waiting in real time
|
|
320
|
+
clock.tick(300);
|
|
321
|
+
assert.ok(/* your assertion */);
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
If you need the mock active across the entire test run rather than inside a single module, put it in a `--before` script:
|
|
327
|
+
|
|
328
|
+
```js
|
|
329
|
+
// scripts/mock-date.js (passed as: qunitx … --before=scripts/mock-date.js)
|
|
330
|
+
const realDate = globalThis.Date;
|
|
331
|
+
const FIXED = new realDate('2024-06-01T12:00:00Z');
|
|
332
|
+
|
|
333
|
+
globalThis.Date = class extends realDate {
|
|
334
|
+
constructor(...args) { super(args.length ? args : [FIXED]); }
|
|
335
|
+
static now() { return FIXED.getTime(); }
|
|
336
|
+
};
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
This runs in the browser context before any test module loads, so every test in the run sees the mocked `Date` with no changes to the OS, no env vars, and no qunitx-cli configuration.
|
|
340
|
+
|
|
230
341
|
## Development
|
|
231
342
|
|
|
232
343
|
```sh
|