@remotex-labs/xjet 1.0.1 → 1.1.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 +1 -0
- package/dist/bash.js +16 -16
- package/dist/bash.js.map +5 -5
- package/dist/index.d.ts +441 -90
- package/dist/index.js +23 -23
- package/dist/index.js.map +1 -1
- package/dist/shared.d.ts +337 -0
- package/dist/shared.js +59 -59
- package/dist/shared.js.map +5 -5
- package/package.json +4 -4
package/dist/shared.d.ts
CHANGED
|
@@ -1556,6 +1556,343 @@ interface InjectableOptionsInterface {
|
|
|
1556
1556
|
factory?: FunctionType;
|
|
1557
1557
|
}
|
|
1558
1558
|
|
|
1559
|
+
/**
|
|
1560
|
+
* Import will remove at compile time
|
|
1561
|
+
*/
|
|
1562
|
+
/**
|
|
1563
|
+
* Provides a virtual timer system that mimics native `setTimeout`/`setInterval`
|
|
1564
|
+
* while allowing controlled execution for deterministic tests.
|
|
1565
|
+
*
|
|
1566
|
+
* @remarks
|
|
1567
|
+
* This service replaces the global timing functions with fake timers so that
|
|
1568
|
+
* time can be manually advanced and callbacks triggered predictably.
|
|
1569
|
+
* It is intended for unit testing scenarios where you need full control over
|
|
1570
|
+
* asynchronous timing without waiting in real time.
|
|
1571
|
+
*
|
|
1572
|
+
* @example
|
|
1573
|
+
* ```ts
|
|
1574
|
+
* useFakeTimers();
|
|
1575
|
+
* setTimeout(() => console.log('done'), 1000);
|
|
1576
|
+
* advanceTimersByTime(1000); // logs 'done' immediately
|
|
1577
|
+
* useRealTimers();
|
|
1578
|
+
* ```
|
|
1579
|
+
*
|
|
1580
|
+
* @since 1.1.0
|
|
1581
|
+
*/
|
|
1582
|
+
declare class TimerService {
|
|
1583
|
+
/**
|
|
1584
|
+
* Active timers managed by the fake timer engine.
|
|
1585
|
+
* @since 1.1.0
|
|
1586
|
+
*/
|
|
1587
|
+
readonly timers: Map<number, TimerInterface>;
|
|
1588
|
+
/**
|
|
1589
|
+
* Stores original `Date.now` to restore when real timers are re-enabled.
|
|
1590
|
+
* @since 1.1.0
|
|
1591
|
+
*/
|
|
1592
|
+
readonly originalDateNow: () => number;
|
|
1593
|
+
/**
|
|
1594
|
+
* Stores original global `setTimeout`.
|
|
1595
|
+
* @since 1.1.0
|
|
1596
|
+
*/
|
|
1597
|
+
readonly originalSetTimeout: typeof setTimeout;
|
|
1598
|
+
/**
|
|
1599
|
+
* Stores original global `setInterval`.
|
|
1600
|
+
* @since 1.1.0
|
|
1601
|
+
*/
|
|
1602
|
+
readonly originalSetInterval: typeof setInterval;
|
|
1603
|
+
/**
|
|
1604
|
+
* Stores original global `clearTimeout`.
|
|
1605
|
+
* @since 1.1.0
|
|
1606
|
+
*/
|
|
1607
|
+
readonly originalClearTimeout: typeof clearTimeout;
|
|
1608
|
+
/**
|
|
1609
|
+
* Stores original global `clearInterval`.
|
|
1610
|
+
* @since 1.1.0
|
|
1611
|
+
*/
|
|
1612
|
+
readonly originalClearInterval: typeof clearInterval;
|
|
1613
|
+
/**
|
|
1614
|
+
* Simulated current timestamp for the fake timers.
|
|
1615
|
+
* @since 1.1.0
|
|
1616
|
+
*/
|
|
1617
|
+
private now;
|
|
1618
|
+
/**
|
|
1619
|
+
* Incremental id used to register timers uniquely.
|
|
1620
|
+
* @since 1.1.0
|
|
1621
|
+
*/
|
|
1622
|
+
private nextId;
|
|
1623
|
+
/**
|
|
1624
|
+
* Replaces the global timer functions with in-memory fakes.
|
|
1625
|
+
*
|
|
1626
|
+
* @remarks
|
|
1627
|
+
* After calling this method, any calls to `setTimeout`, `setInterval`,
|
|
1628
|
+
* `clearTimeout`, or `clearInterval` will be intercepted and stored in the
|
|
1629
|
+
* {@link timers} map instead of scheduling real OS timers.
|
|
1630
|
+
* This allows tests to control time progression manually using
|
|
1631
|
+
* {@link advanceTimersByTime}, {@link runAllTimers}, or
|
|
1632
|
+
* {@link runOnlyPendingTimers}.
|
|
1633
|
+
*
|
|
1634
|
+
* @example
|
|
1635
|
+
* ```ts
|
|
1636
|
+
* timerService.useFakeTimers();
|
|
1637
|
+
* const id = setTimeout(() => console.log('done'), 1000);
|
|
1638
|
+
* timerService.advanceTimersByTime(1000); // logs "done" immediately
|
|
1639
|
+
* ```
|
|
1640
|
+
*
|
|
1641
|
+
* @since 1.1.0
|
|
1642
|
+
*/
|
|
1643
|
+
useFakeTimers(): void;
|
|
1644
|
+
/**
|
|
1645
|
+
* Restores the original global timer APIs and `Date.now`.
|
|
1646
|
+
*
|
|
1647
|
+
* @remarks
|
|
1648
|
+
* This method undoes the effects of {@link useFakeTimers}, re-binding
|
|
1649
|
+
* the native implementations of `setTimeout`, `setInterval`,
|
|
1650
|
+
* `clearTimeout`, `clearInterval`, and `Date.now`.
|
|
1651
|
+
* After calling this, timers once again behave according to real system
|
|
1652
|
+
* time and manual advancement methods such as
|
|
1653
|
+
* {@link advanceTimersByTime} no longer apply.
|
|
1654
|
+
*
|
|
1655
|
+
* @example
|
|
1656
|
+
* ```ts
|
|
1657
|
+
* timerService.useFakeTimers();
|
|
1658
|
+
* // ...run tests with controlled time...
|
|
1659
|
+
* timerService.useRealTimers(); // restore native timers
|
|
1660
|
+
* ```
|
|
1661
|
+
*
|
|
1662
|
+
* @since 1.1.0
|
|
1663
|
+
*/
|
|
1664
|
+
useRealTimers(): void;
|
|
1665
|
+
/**
|
|
1666
|
+
* Advances the simulated clock by a specific number of milliseconds and
|
|
1667
|
+
* executes all timers whose scheduled time has elapsed.
|
|
1668
|
+
*
|
|
1669
|
+
* @remarks
|
|
1670
|
+
* Use this method after calling {@link useFakeTimers} to fast-forward the
|
|
1671
|
+
* internal clock without waiting in real time.
|
|
1672
|
+
* Any `setTimeout` or `setInterval` callbacks scheduled within the
|
|
1673
|
+
* advanced period will run immediately in order of their scheduled time.
|
|
1674
|
+
*
|
|
1675
|
+
* @param ms - The number of milliseconds to move the simulated time forward.
|
|
1676
|
+
*
|
|
1677
|
+
* @example
|
|
1678
|
+
* ```ts
|
|
1679
|
+
* timerService.useFakeTimers();
|
|
1680
|
+
* setTimeout(() => console.log('done'), 500);
|
|
1681
|
+
* timerService.advanceTimersByTime(500); // logs "done"
|
|
1682
|
+
* ```
|
|
1683
|
+
*
|
|
1684
|
+
* @since 1.1.0
|
|
1685
|
+
*/
|
|
1686
|
+
advanceTimersByTime(ms: number): void;
|
|
1687
|
+
/**
|
|
1688
|
+
* Executes every scheduled timer until none remain.
|
|
1689
|
+
*
|
|
1690
|
+
* @remarks
|
|
1691
|
+
* This method repeatedly advances the simulated clock to the next
|
|
1692
|
+
* scheduled timer and runs its callback until the {@link timers} map
|
|
1693
|
+
* is empty.
|
|
1694
|
+
* It is useful when you want to immediately flush **all** pending
|
|
1695
|
+
* `setTimeout` or `setInterval` callbacks regardless of their delay,
|
|
1696
|
+
* without specifying a time increment.
|
|
1697
|
+
*
|
|
1698
|
+
* @example
|
|
1699
|
+
* ```ts
|
|
1700
|
+
* timerService.useFakeTimers();
|
|
1701
|
+
* setTimeout(() => console.log('A'), 100);
|
|
1702
|
+
* setTimeout(() => console.log('B'), 200);
|
|
1703
|
+
* timerService.runAllTimers(); // logs "A" then "B"
|
|
1704
|
+
* ```
|
|
1705
|
+
*
|
|
1706
|
+
* @since 1.1.0
|
|
1707
|
+
*/
|
|
1708
|
+
runAllTimers(): void;
|
|
1709
|
+
/**
|
|
1710
|
+
* Executes only the timers that are currently pending at the time of call,
|
|
1711
|
+
* without running any new timers that may be scheduled by those callbacks.
|
|
1712
|
+
*
|
|
1713
|
+
* @remarks
|
|
1714
|
+
* Unlike {@link runAllTimers}, this method captures the set of timers
|
|
1715
|
+
* that exist when the method is invoked and restricts execution to that
|
|
1716
|
+
* initial set.
|
|
1717
|
+
* If any of those timers schedule additional timers while running,
|
|
1718
|
+
* the newly scheduled ones will **not** be executed during this call.
|
|
1719
|
+
*
|
|
1720
|
+
* @example
|
|
1721
|
+
* ```ts
|
|
1722
|
+
* timerService.useFakeTimers();
|
|
1723
|
+
* setTimeout(() => {
|
|
1724
|
+
* console.log('first');
|
|
1725
|
+
* setTimeout(() => console.log('second'), 100);
|
|
1726
|
+
* }, 100);
|
|
1727
|
+
*
|
|
1728
|
+
* timerService.runOnlyPendingTimers();
|
|
1729
|
+
* // Logs only "first" because "second" was created afterward.
|
|
1730
|
+
* ```
|
|
1731
|
+
*
|
|
1732
|
+
* @since 1.1.0
|
|
1733
|
+
*/
|
|
1734
|
+
runOnlyPendingTimers(): void;
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Globally enables fake timers using the shared {@link TimerService}.
|
|
1738
|
+
*
|
|
1739
|
+
* @remarks
|
|
1740
|
+
* After calling this function, all calls to `setTimeout`, `setInterval`,
|
|
1741
|
+
* `clearTimeout`, and `clearInterval` will be intercepted by the
|
|
1742
|
+
* {@link TimerService} and stored in-memory instead of executing in real time.
|
|
1743
|
+
* This allows deterministic testing by manually advancing time with
|
|
1744
|
+
* {@link advanceTimersByTime}, {@link runAllTimers}, or
|
|
1745
|
+
* {@link runOnlyPendingTimers}.
|
|
1746
|
+
*
|
|
1747
|
+
* @example
|
|
1748
|
+
* ```ts
|
|
1749
|
+
* useFakeTimers();
|
|
1750
|
+
* setTimeout(() => console.log('done'), 1000);
|
|
1751
|
+
* advanceTimersByTime(1000); // logs "done" immediately
|
|
1752
|
+
* ```
|
|
1753
|
+
*
|
|
1754
|
+
* @since 1.1.0
|
|
1755
|
+
*/
|
|
1756
|
+
declare function useFakeTimers(): void;
|
|
1757
|
+
/**
|
|
1758
|
+
* Restores real timers globally using the shared {@link TimerService}.
|
|
1759
|
+
*
|
|
1760
|
+
* @remarks
|
|
1761
|
+
* This function undoes the effects of {@link useFakeTimers}, restoring the
|
|
1762
|
+
* native implementations of `setTimeout`, `setInterval`, `clearTimeout`,
|
|
1763
|
+
* `clearInterval`, and `Date.now`.
|
|
1764
|
+
* After calling this, timers once again behave according to real system time,
|
|
1765
|
+
* and manual advancement methods like {@link advanceTimersByTime} no longer apply.
|
|
1766
|
+
*
|
|
1767
|
+
* @example
|
|
1768
|
+
* ```ts
|
|
1769
|
+
* useFakeTimers();
|
|
1770
|
+
* // ...run tests with controlled time...
|
|
1771
|
+
* useRealTimers(); // restore native timers
|
|
1772
|
+
* ```
|
|
1773
|
+
*
|
|
1774
|
+
* @since 1.1.0
|
|
1775
|
+
*/
|
|
1776
|
+
declare function useRealTimers(): void;
|
|
1777
|
+
/**
|
|
1778
|
+
* Executes all timers currently registered in the {@link TimerService}.
|
|
1779
|
+
*
|
|
1780
|
+
* @remarks
|
|
1781
|
+
* This function repeatedly runs all pending `setTimeout` and `setInterval`
|
|
1782
|
+
* callbacks until no timers remain.
|
|
1783
|
+
* It is equivalent to calling {@link TimerService.runAllTimers} on the
|
|
1784
|
+
* injected service instance and is useful for immediately flushing
|
|
1785
|
+
* all scheduled timers in tests.
|
|
1786
|
+
*
|
|
1787
|
+
* @example
|
|
1788
|
+
* ```ts
|
|
1789
|
+
* useFakeTimers();
|
|
1790
|
+
* setTimeout(() => console.log('A'), 100);
|
|
1791
|
+
* setTimeout(() => console.log('B'), 200);
|
|
1792
|
+
* runAllTimers(); // logs "A" then "B"
|
|
1793
|
+
* ```
|
|
1794
|
+
*
|
|
1795
|
+
* @since 1.1.0
|
|
1796
|
+
*/
|
|
1797
|
+
declare function runAllTimers(): void;
|
|
1798
|
+
/**
|
|
1799
|
+
* Executes only the timers that are pending at the time of invocation.
|
|
1800
|
+
*
|
|
1801
|
+
* @remarks
|
|
1802
|
+
* This function runs the callbacks of timers that exist when the function
|
|
1803
|
+
* is called, without executing any new timers that may be scheduled
|
|
1804
|
+
* during their execution.
|
|
1805
|
+
* It delegates to {@link TimerService.runOnlyPendingTimers} on the injected
|
|
1806
|
+
* service instance.
|
|
1807
|
+
*
|
|
1808
|
+
* @example
|
|
1809
|
+
* ```ts
|
|
1810
|
+
* useFakeTimers();
|
|
1811
|
+
* setTimeout(() => {
|
|
1812
|
+
* console.log('first');
|
|
1813
|
+
* setTimeout(() => console.log('second'), 100);
|
|
1814
|
+
* }, 100);
|
|
1815
|
+
*
|
|
1816
|
+
* runOnlyPendingTimers();
|
|
1817
|
+
* // Logs only "first"; "second" is not executed yet
|
|
1818
|
+
* ```
|
|
1819
|
+
*
|
|
1820
|
+
* @since 1.1.0
|
|
1821
|
+
*/
|
|
1822
|
+
declare function runOnlyPendingTimers(): void;
|
|
1823
|
+
/**
|
|
1824
|
+
* Advances the simulated time by a specified number of milliseconds and
|
|
1825
|
+
* executes all timers that are due.
|
|
1826
|
+
*
|
|
1827
|
+
* @remarks
|
|
1828
|
+
* This function delegates to {@link TimerService.advanceTimersByTime}
|
|
1829
|
+
* on the injected service instance.
|
|
1830
|
+
* It is intended to be used after {@link useFakeTimers} to fast-forward
|
|
1831
|
+
* time in tests without waiting for real timers.
|
|
1832
|
+
*
|
|
1833
|
+
* @param ms - The number of milliseconds to advance (default is `0`).
|
|
1834
|
+
*
|
|
1835
|
+
* @example
|
|
1836
|
+
* ```ts
|
|
1837
|
+
* useFakeTimers();
|
|
1838
|
+
* setTimeout(() => console.log('done'), 500);
|
|
1839
|
+
* advanceTimersByTime(500); // logs "done"
|
|
1840
|
+
* ```
|
|
1841
|
+
*
|
|
1842
|
+
* @since 1.1.0
|
|
1843
|
+
*/
|
|
1844
|
+
declare function advanceTimersByTime(ms?: number): void;
|
|
1845
|
+
|
|
1846
|
+
/**
|
|
1847
|
+
* Interface representing a single timer stored and executed by the {@link TimerService}.
|
|
1848
|
+
*
|
|
1849
|
+
* @remarks
|
|
1850
|
+
* This interface tracks all properties needed to manage both one-time
|
|
1851
|
+
* and repeating timers within the fake timer system.
|
|
1852
|
+
*
|
|
1853
|
+
* @example
|
|
1854
|
+
* ```ts
|
|
1855
|
+
* const timer: TimerInterface = {
|
|
1856
|
+
* id: 1,
|
|
1857
|
+
* time: 1000,
|
|
1858
|
+
* args: [],
|
|
1859
|
+
* callback: () => console.log('done'),
|
|
1860
|
+
* interval: null,
|
|
1861
|
+
* };
|
|
1862
|
+
* ```
|
|
1863
|
+
*
|
|
1864
|
+
* @since 1.1.0
|
|
1865
|
+
*/
|
|
1866
|
+
interface TimerInterface {
|
|
1867
|
+
/**
|
|
1868
|
+
* Unique identifier for the timer.
|
|
1869
|
+
* @since 1.1.0
|
|
1870
|
+
*/
|
|
1871
|
+
id: number;
|
|
1872
|
+
/**
|
|
1873
|
+
* The simulated timestamp (in milliseconds) when the timer is next due to run.
|
|
1874
|
+
* @since 1.1.0
|
|
1875
|
+
*/
|
|
1876
|
+
time: number;
|
|
1877
|
+
/**
|
|
1878
|
+
* Arguments passed to the timer's callback function.
|
|
1879
|
+
* @since 1.1.0
|
|
1880
|
+
*/
|
|
1881
|
+
args: Array<unknown>;
|
|
1882
|
+
/**
|
|
1883
|
+
* Callback function to execute when the timer triggers.
|
|
1884
|
+
* @since 1.1.0
|
|
1885
|
+
*/
|
|
1886
|
+
callback: () => void;
|
|
1887
|
+
/**
|
|
1888
|
+
* Interval in milliseconds for repeating timers.
|
|
1889
|
+
* `null` indicates a one-time timer (like `setTimeout`), otherwise behaves like `setInterval`.
|
|
1890
|
+
*
|
|
1891
|
+
* @since 1.1.0
|
|
1892
|
+
*/
|
|
1893
|
+
interval: number | null;
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1559
1896
|
/**
|
|
1560
1897
|
* Imports
|
|
1561
1898
|
*/
|