content large_stringlengths 3 20.5k | url large_stringlengths 54 193 | branch large_stringclasses 4 values | source large_stringclasses 42 values | embeddings listlengths 384 384 | score float64 -0.21 0.65 |
|---|---|---|---|---|---|
JavaScript's prototypal inheritance model. First, a stream developer would declare a new JavaScript class that extends one of the four basic stream classes (`stream.Writable`, `stream.Readable`, `stream.Duplex`, or `stream.Transform`), making sure they call the appropriate parent class constructor: ```js const { Writable } = require('node:stream'); class MyWritable extends Writable { constructor({ highWaterMark, ...options }) { super({ highWaterMark }); // ... } } ``` When extending streams, keep in mind what options the user can and should provide before forwarding these to the base constructor. For example, if the implementation makes assumptions in regard to the `autoDestroy` and `emitClose` options, do not allow the user to override these. Be explicit about what options are forwarded instead of implicitly forwarding all options. The new stream class must then implement one or more specific methods, depending on the type of stream being created, as detailed in the chart below: | Use-case | Class | Method(s) to implement | | --------------------------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------ | | Reading only | [`Readable`][] | [`\_read()`][stream-\_read] | | Writing only | [`Writable`][] | [`\_write()`][stream-\_write], [`\_writev()`][stream-\_writev], [`\_final()`][stream-\_final] | | Reading and writing | [`Duplex`][] | [`\_read()`][stream-\_read], [`\_write()`][stream-\_write], [`\_writev()`][stream-\_writev], [`\_final()`][stream-\_final] | | Operate on written data, then read the result | [`Transform`][] | [`\_transform()`][stream-\_transform], [`\_flush()`][stream-\_flush], [`\_final()`][stream-\_final] | The implementation code for a stream should \_never\_ call the "public" methods of a stream that are intended for use by consumers (as described in the [API for stream consumers][] section). Doing so may lead to adverse side effects in application code consuming the stream. Avoid overriding public methods such as `write()`, `end()`, `cork()`, `uncork()`, `read()` and `destroy()`, or emitting internal events such as `'error'`, `'data'`, `'end'`, `'finish'` and `'close'` through `.emit()`. Doing so can break current and future stream invariants leading to behavior and/or compatibility issues with other streams, stream utilities, and user expectations. ### Simplified construction For many simple cases, it is possible to create a stream without relying on inheritance. This can be accomplished by directly creating instances of the `stream.Writable`, `stream.Readable`, `stream.Duplex`, or `stream.Transform` objects and passing appropriate methods as constructor options. ```js const { Writable } = require('node:stream'); const myWritable = new Writable({ construct(callback) { // Initialize state and load resources... }, write(chunk, encoding, callback) { // ... }, destroy() { // Free resources... }, }); ``` ### Implementing a writable stream The `stream.Writable` class is extended to implement a [`Writable`][] stream. Custom `Writable` streams \_must\_ call the `new stream.Writable([options])` constructor and implement the `writable.\_write()` and/or `writable.\_writev()` method. #### `new stream.Writable([options])` \* `options` {Object} \* `highWaterMark` {number} Buffer level when [`stream.write()`][stream-write] starts returning `false`. \*\*Default:\*\* `65536` (64 KiB), or `16` for `objectMode` streams. \* `decodeStrings` {boolean} Whether to encode `string`s passed to [`stream.write()`][stream-write] to `Buffer`s (with the encoding specified in the [`stream.write()`][stream-write] call) before passing them to [`stream.\_write()`][stream-\_write]. Other types of data are not converted (i.e. `Buffer`s are not decoded into `string`s). Setting to false will prevent `string`s from being converted. \*\*Default:\*\* `true`. \* `defaultEncoding` {string} The default encoding that is used when no encoding is specified as an argument to [`stream.write()`][stream-write]. \*\*Default:\*\* `'utf8'`. \* `objectMode` {boolean} Whether or not the [`stream.write(anyObj)`][stream-write] is a valid operation. When set, it becomes possible to write JavaScript values other than string, {Buffer}, {TypedArray} or {DataView} if supported by the stream implementation. \*\*Default:\*\* `false`. \* `emitClose` {boolean} Whether or not the stream should emit `'close'` after it has been destroyed. \*\*Default:\*\* `true`. \* `write` {Function} Implementation for the [`stream.\_write()`][stream-\_write] method. \* `writev` {Function} Implementation for the [`stream.\_writev()`][stream-\_writev] method. \* `destroy` {Function} Implementation for the [`stream.\_destroy()`][writable-\_destroy] method. \* `final` {Function} Implementation for the [`stream.\_final()`][stream-\_final] method. \* `construct` {Function} Implementation for the [`stream.\_construct()`][writable-\_construct] method. | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.09636393189430237,
-0.007456588093191385,
0.06552191823720932,
-0.01060499344021082,
0.03436831012368202,
0.002353120129555464,
-0.035348232835531235,
0.0912311002612114,
-0.06783662736415863,
-0.02940836176276207,
-0.011149433441460133,
0.03116554580628872,
-0.09695668518543243,
0.06490463763475418,
0.04543311893939972,
-0.01674475334584713,
-0.005441592540591955,
-0.0277041494846344,
-0.060863807797431946,
-0.05365777388215065,
0.0669810026884079,
-0.12434910982847214,
-0.032684534788131714,
-0.023099930956959724,
-0.00931188091635704,
0.02728625014424324,
0.021441379562020302,
-0.01681266352534294,
0.08140111714601517,
-0.004944507963955402,
0.04314094036817551,
-0.03252377361059189,
-0.12763863801956177,
-0.010739840567111969,
-0.10283786803483963,
0.06474145501852036,
0.007183942943811417,
-0.03764268010854721,
-0.021382613107562065,
0.020937936380505562,
0.07054930925369263,
0.03787532076239586,
-0.06493115425109863,
-0.0006435982650145888,
0.014710545539855957,
0.018627574667334557,
0.01738673821091652,
-0.02562909945845604,
-0.11234890669584274,
0.0324094183743,
-0.007833283394575119,
-0.06461166590452194,
-0.03475663810968399,
0.07042621076107025,
-0.021571436896920204,
-0.034027572721242905,
-0.035562995821237564,
-0.03405540809035301,
0.04505816474556923,
-0.004426673054695129,
-0.04802800714969635,
-0.03398085758090019,
-0.02085292525589466,
-0.04088285192847252,
0.018623223528265953,
-0.018349286168813705,
-0.037029605358839035,
0.12473680078983307,
0.053356003016233444,
0.1254369169473648,
0.0068672639317810535,
0.06687356531620026,
0.04892073944211006,
0.052953701466321945,
0.0026691907551139593,
-0.10890369117259979,
0.012506268918514252,
0.04902421683073044,
-0.03355110064148903,
0.002996162511408329,
-0.00501648522913456,
-0.05607719346880913,
-0.009852631017565727,
0.010605412535369396,
0.01901925355195999,
0.0997684970498085,
-0.012373803183436394,
-0.05238960683345795,
0.04730145260691643,
0.04638415947556496,
-0.09403671324253082,
-0.08969825506210327,
0.01427194569259882,
0.0018475025426596403,
-0.010955090634524822,
0.03531379997730255,
-0.016588082537055016,
-0.06527071446180344,
0.025556547567248344,
-0.021185556426644325,
0.01211465522646904,
-0.0029101609252393246,
0.08694633841514587,
-0.0025396442506462336,
0.0733071118593216,
-0.062332794070243835,
-0.05122585594654083,
0.08133503049612045,
0.01864832080900669,
-0.041960641741752625,
-0.017650071531534195,
0.032683614641427994,
-0.00324994046241045,
-0.04645373299717903,
-0.07080357521772385,
0.05120937526226044,
-0.040887653827667236,
-0.06473123282194138,
0.05103757977485657,
0.025451697409152985,
0.030911466106772423,
0.02074401080608368,
0.0680849701166153,
0.0340314581990242,
0.06244373694062233,
-0.003969608806073666,
-0.04105584695935249,
1.5156528449204946e-33,
-0.0009767240844666958,
-0.008654831908643246,
-0.08675021678209305,
0.08693280816078186,
0.018002919852733612,
0.014709919691085815,
0.016852721571922302,
-0.017949700355529785,
-0.10098642855882645,
-0.02556329406797886,
0.023243317380547523,
0.04857802391052246,
-0.05813249200582504,
0.07198052853345871,
0.05995554476976395,
-0.05634249746799469,
0.021917471662163734,
0.016579361632466316,
0.030430829152464867,
0.009876493364572525,
0.058229219168424606,
0.06748306751251221,
-0.0702301636338234,
-0.06235625967383385,
-0.03689027205109596,
0.005466700065881014,
0.015891294926404953,
0.00824734941124916,
-0.08363645523786545,
0.030126668512821198,
0.02941380813717842,
-0.010740976780653,
0.022710546851158142,
0.04674491658806801,
0.02541058324277401,
-0.013442432507872581,
0.00018487765919417143,
-0.05679326876997948,
-0.050208836793899536,
-0.045370448380708694,
0.06538289785385132,
0.023840924724936485,
-0.04821845516562462,
-0.027204440906643867,
-0.008847822435200214,
-0.027681224048137665,
0.016183124855160713,
-0.006229350343346596,
0.0075561306439340115,
-0.07219633460044861,
-0.008117922581732273,
0.06275228410959244,
-0.021090125665068626,
0.004863215610384941,
0.06972341239452362,
-0.012281963601708412,
-0.018900392577052116,
0.0345020666718483,
0.03382206708192825,
0.0027140090242028236,
0.024311263114213943,
0.060418155044317245,
-0.0273238867521286,
0.05431037023663521,
-0.016509905457496643,
0.06252627819776535,
-0.004255307838320732,
-0.048066526651382446,
0.09927089512348175,
-0.12341979891061783,
-0.03913869708776474,
0.020604362711310387,
-0.05712355300784111,
0.05547833442687988,
-0.0026195307727903128,
-0.005225407890975475,
0.04255550354719162,
-0.004514767788350582,
0.04197652265429497,
0.014910317957401276,
-0.08323869109153748,
0.017968375235795975,
0.011387265287339687,
0.16259771585464478,
0.014126073569059372,
-0.0583646297454834,
-0.044900234788656235,
-0.06615456193685532,
-0.021602172404527664,
0.03570543974637985,
-0.016545051708817482,
-0.026053205132484436,
0.0616634227335453,
-0.06389061361551285,
-0.010504912585020065,
-3.393843943339922e-33,
0.021201174706220627,
-0.001006967038847506,
-0.05286771431565285,
0.058709535747766495,
0.018673138692975044,
0.006320311222225428,
0.023701602593064308,
0.03163139522075653,
0.03989952430129051,
-0.026516970247030258,
-0.09013905376195908,
0.05498305708169937,
-0.06186435744166374,
-0.03130916878581047,
-0.0526127815246582,
-0.065217524766922,
-0.07014203816652298,
-0.09490052610635757,
0.06102954223752022,
-0.07078658044338226,
0.007252049632370472,
-0.0031806044280529022,
0.049066346138715744,
0.0714225172996521,
0.05354141443967819,
0.044209402054548264,
-0.06516421586275101,
0.06014044210314751,
-0.01870633289217949,
-0.024427516385912895,
-0.030730606988072395,
0.012575101107358932,
0.04764755070209503,
0.007347503677010536,
0.01738896034657955,
0.01747414842247963,
-0.00835085567086935,
0.12725228071212769,
0.021153192967176437,
0.05081510543823242,
0.025214849039912224,
-0.03221004828810692,
-0.019501956179738045,
-0.027211563661694527,
-0.004460650496184826,
0.10477451235055923,
-0.020681625232100487,
-0.010943570174276829,
0.05135180056095123,
0.023224681615829468,
-0.02179148606956005,
-0.045106951147317886,
0.01273538637906313,
0.05010947585105896,
0.0015826227609068155,
-0.058184463530778885,
0.14464841783046722,
-0.052340250462293625,
-0.004729603882879019,
0.05072589963674545,
0.0757136419415474,
-0.067542165517807,
0.033815350383520126,
-0.059591811150312424,
-0.011934363283216953,
-0.01410464197397232,
-0.03904395550489426,
0.0329032801091671,
0.03896530717611313,
-0.026759155094623566,
0.0037009785883128643,
-0.07337686419487,
0.0048738201148808,
-0.039615850895643234,
0.07431379705667496,
-0.054358359426259995,
0.011635292321443558,
-0.01705523394048214,
0.047417592257261276,
-0.025349531322717667,
-0.10396305471658707,
0.06316353380680084,
-0.05474993214011192,
0.03728461638092995,
0.089439757168293,
-0.02160239964723587,
0.010763500817120075,
-0.0822906345129013,
0.026094093918800354,
-0.008665104396641254,
0.05160630866885185,
0.03980414196848869,
-0.1666983664035797,
0.009835004806518555,
-0.05241771042346954,
-4.746677007005928e-8,
-0.06134716793894768,
-0.021105261519551277,
-0.04016009718179703,
-0.013293679803609848,
0.0030525100883096457,
-0.06551777571439743,
-0.004410285037010908,
0.04410626366734505,
0.053870756179094315,
-0.025351030752062798,
-0.034832872450351715,
0.003929757513105869,
0.10508908331394196,
-0.05686468631029129,
0.019826408475637436,
-0.07093049585819244,
0.023666581138968468,
-0.03399009630084038,
-0.10455209016799927,
0.04589514061808586,
-0.010936591774225235,
0.0021881344728171825,
-0.015410028398036957,
0.05034025385975838,
-0.04460998624563217,
-0.011404434219002724,
0.08857665956020355,
0.011630230583250523,
0.05340481549501419,
0.031242460012435913,
-0.0621834322810173,
0.12281355261802673,
-0.01338213961571455,
0.12646925449371338,
-0.012684148736298084,
0.013397577218711376,
-0.0754573792219162,
0.03290793299674988,
-0.06022396683692932,
0.09291307628154755,
0.05376548320055008,
-0.031852561980485916,
-0.06704429537057877,
0.027958951890468597,
0.04737762361764908,
0.03244253620505333,
-0.018456825986504555,
-0.059757452458143234,
-0.007119448389858007,
0.07939806580543518,
-0.032275523990392685,
0.05083036422729492,
-0.021723885089159012,
0.04764234274625778,
0.018181871622800827,
-0.020326420664787292,
-0.024881893768906593,
-0.0923682376742363,
-0.05945096164941788,
-0.05248712748289108,
0.08480539172887802,
0.022516796365380287,
0.05094064772129059,
0.06292282044887543
] | 0.032161 |
should emit `'close'` after it has been destroyed. \*\*Default:\*\* `true`. \* `write` {Function} Implementation for the [`stream.\_write()`][stream-\_write] method. \* `writev` {Function} Implementation for the [`stream.\_writev()`][stream-\_writev] method. \* `destroy` {Function} Implementation for the [`stream.\_destroy()`][writable-\_destroy] method. \* `final` {Function} Implementation for the [`stream.\_final()`][stream-\_final] method. \* `construct` {Function} Implementation for the [`stream.\_construct()`][writable-\_construct] method. \* `autoDestroy` {boolean} Whether this stream should automatically call `.destroy()` on itself after ending. \*\*Default:\*\* `true`. \* `signal` {AbortSignal} A signal representing possible cancellation. ```js const { Writable } = require('node:stream'); class MyWritable extends Writable { constructor(options) { // Calls the stream.Writable() constructor. super(options); // ... } } ``` Or, when using pre-ES6 style constructors: ```js const { Writable } = require('node:stream'); const util = require('node:util'); function MyWritable(options) { if (!(this instanceof MyWritable)) return new MyWritable(options); Writable.call(this, options); } util.inherits(MyWritable, Writable); ``` Or, using the simplified constructor approach: ```js const { Writable } = require('node:stream'); const myWritable = new Writable({ write(chunk, encoding, callback) { // ... }, writev(chunks, callback) { // ... }, }); ``` Calling `abort` on the `AbortController` corresponding to the passed `AbortSignal` will behave the same way as calling `.destroy(new AbortError())` on the writeable stream. ```js const { Writable } = require('node:stream'); const controller = new AbortController(); const myWritable = new Writable({ write(chunk, encoding, callback) { // ... }, writev(chunks, callback) { // ... }, signal: controller.signal, }); // Later, abort the operation closing the stream controller.abort(); ``` #### `writable.\_construct(callback)` \* `callback` {Function} Call this function (optionally with an error argument) when the stream has finished initializing. The `\_construct()` method MUST NOT be called directly. It may be implemented by child classes, and if so, will be called by the internal `Writable` class methods only. This optional function will be called in a tick after the stream constructor has returned, delaying any `\_write()`, `\_final()` and `\_destroy()` calls until `callback` is called. This is useful to initialize state or asynchronously initialize resources before the stream can be used. ```js const { Writable } = require('node:stream'); const fs = require('node:fs'); class WriteStream extends Writable { constructor(filename) { super(); this.filename = filename; this.fd = null; } \_construct(callback) { fs.open(this.filename, 'w', (err, fd) => { if (err) { callback(err); } else { this.fd = fd; callback(); } }); } \_write(chunk, encoding, callback) { fs.write(this.fd, chunk, callback); } \_destroy(err, callback) { if (this.fd) { fs.close(this.fd, (er) => callback(er || err)); } else { callback(err); } } } ``` #### `writable.\_write(chunk, encoding, callback)` \* `chunk` {Buffer|string|any} The `Buffer` to be written, converted from the `string` passed to [`stream.write()`][stream-write]. If the stream's `decodeStrings` option is `false` or the stream is operating in object mode, the chunk will not be converted & will be whatever was passed to [`stream.write()`][stream-write]. \* `encoding` {string} If the chunk is a string, then `encoding` is the character encoding of that string. If chunk is a `Buffer`, or if the stream is operating in object mode, `encoding` may be ignored. \* `callback` {Function} Call this function (optionally with an error argument) when processing is complete for the supplied chunk. All `Writable` stream implementations must provide a [`writable.\_write()`][stream-\_write] and/or [`writable.\_writev()`][stream-\_writev] method to send data to the underlying resource. [`Transform`][] streams provide their own implementation of the [`writable.\_write()`][stream-\_write]. This function MUST NOT be called by application code directly. It should be implemented by child classes, and called by the internal `Writable` class methods only. The `callback` function must be called synchronously inside of `writable.\_write()` or asynchronously (i.e. different tick) to signal either that the write completed successfully or failed with an error. The first argument passed to the `callback` must be the `Error` object if the call failed or `null` if the | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.046082381159067154,
0.0018279553623870015,
0.012669113464653492,
-0.025282898917794228,
0.04760943353176117,
-0.063873291015625,
0.02374187298119068,
0.0155932093039155,
0.039742279797792435,
0.00797589123249054,
-0.010479525662958622,
0.03541738539934158,
-0.07603295147418976,
0.01332837250083685,
-0.04492678493261337,
-0.010710478760302067,
-0.09883307665586472,
-0.06607570499181747,
-0.08216670155525208,
-0.05115918070077896,
0.05528859421610832,
0.03072480484843254,
0.0025638325605541468,
0.07632171362638474,
0.023236524313688278,
0.009265710599720478,
-0.004868354182690382,
-0.022030601277947426,
0.019859161227941513,
-0.03015446476638317,
0.02020360715687275,
-0.053067877888679504,
-0.06963376700878143,
-0.06247083842754364,
0.045903731137514114,
0.10711797326803207,
-0.024672599509358406,
-0.05719175189733505,
-0.074509397149086,
-0.060019273310899734,
-0.0015226396499201655,
0.0011429248843342066,
-0.09891890734434128,
-0.026576705276966095,
-0.038041241466999054,
0.08237219601869583,
-0.08078625798225403,
-0.0646350234746933,
-0.08284628391265869,
0.02255357801914215,
-0.11504355072975159,
0.020342033356428146,
-0.010693253949284554,
-0.023217270150780678,
0.0832706019282341,
-0.04380634054541588,
0.04150794818997383,
-0.01882936991751194,
-0.04562487453222275,
0.016817672178149223,
-0.024903256446123123,
0.07136905193328857,
-0.10243160277605057,
0.042743779718875885,
0.056286390870809555,
-0.014495757408440113,
-0.023626888170838356,
0.022238345816731453,
0.06807360053062439,
0.08003278821706772,
-0.04720379784703255,
0.0390508770942688,
-0.06509000062942505,
0.05110033228993416,
0.010210305452346802,
-0.06697066873311996,
-0.02934688702225685,
-0.031000299379229546,
-0.0576714426279068,
-0.042742837220430374,
-0.002542754402384162,
-0.09235459566116333,
0.007355955895036459,
-0.012308109551668167,
0.007941200397908688,
0.11788913607597351,
-0.006072065327316523,
-0.03485547751188278,
0.12948280572891235,
0.09108789265155792,
-0.0844041183590889,
0.03178765997290611,
0.08646465092897415,
0.09006711840629578,
-0.009179039858281612,
0.05637586489319801,
0.053816091269254684,
-0.0007266597240231931,
0.011350021697580814,
0.049430202692747116,
-0.024912653490900993,
0.034180622547864914,
0.04107567295432091,
-0.05910196900367737,
0.06686561554670334,
-0.02786625549197197,
-0.007082114927470684,
0.05754116550087929,
0.04241662099957466,
-0.08824934810400009,
-0.01602388545870781,
-0.0023267457727342844,
-0.008171224035322666,
-0.02566046454012394,
-0.005732536315917969,
0.0936816930770874,
-0.011197315528988838,
0.057379115372896194,
0.020547352731227875,
0.12585921585559845,
0.12099406868219376,
0.0044219763949513435,
-0.06497634947299957,
0.02529093064367771,
0.07832835614681244,
-0.04378807172179222,
0.07768244296312332,
1.6965292830883894e-33,
-0.0005404526018537581,
-0.1176878958940506,
-0.09422837942838669,
0.08025799691677094,
0.05162511393427849,
0.015782294794917107,
0.005593092180788517,
0.08210135251283646,
-0.09684079885482788,
0.026473892852663994,
0.03400678187608719,
-0.04148857295513153,
-0.08745904266834259,
0.06850266456604004,
0.053635939955711365,
-0.07399020344018936,
0.09783641248941422,
0.0026968377642333508,
-0.05177801474928856,
0.009524268098175526,
0.10762947052717209,
0.02769496478140354,
-0.045198336243629456,
-0.03176778554916382,
-0.03586871176958084,
0.04670059680938721,
0.029141021892428398,
0.026540257036685944,
-0.049965161830186844,
0.04178682342171669,
-0.057462360709905624,
-0.0245222020894289,
-0.004588392563164234,
0.06690998375415802,
-0.012637612409889698,
-0.00473149074241519,
-0.09229966253042221,
-0.057704851031303406,
-0.038876134902238846,
-0.050011876970529556,
-0.008282613009214401,
0.039100103080272675,
-0.13930292427539825,
-0.012475186958909035,
0.020897043868899345,
-0.11352801322937012,
-0.018171602860093117,
0.07851594686508179,
0.024239642545580864,
-0.013340119272470474,
0.07081110775470734,
0.04838421195745468,
0.07238438725471497,
0.00253402441740036,
0.05485739931464195,
0.013220769353210926,
-0.03102440945804119,
-0.007611474953591824,
0.03627996891736984,
0.00021102673781570047,
0.06745855510234833,
0.0951070636510849,
-0.022831467911601067,
0.008420715108513832,
-0.000468935671960935,
0.01410334836691618,
0.057018596678972244,
-0.004128713626414537,
0.10678558796644211,
-0.09044372290372849,
-0.10816214233636856,
-0.00559995137155056,
-0.017048660665750504,
-0.005714848171919584,
-0.009361770004034042,
-0.00397667707875371,
-0.002900468884035945,
-0.08553506433963776,
0.015199175104498863,
-0.027583716437220573,
0.030049612745642662,
-0.025035826489329338,
0.0030974424444139004,
0.020928092300891876,
0.02353288047015667,
-0.031881678849458694,
-0.008967271074652672,
-0.030259056016802788,
-0.0523342527449131,
0.05497566983103752,
-0.0846429243683815,
-0.05263518542051315,
0.07759542763233185,
-0.05566966533660889,
-0.051056768745183945,
-5.085242560928957e-33,
0.02176189050078392,
0.001804988132789731,
-0.08351681381464005,
0.044303011149168015,
-0.0700337216258049,
-0.05380219593644142,
-0.026075094938278198,
0.011234110221266747,
0.012930053286254406,
-0.044899679720401764,
-0.029124069958925247,
0.020744260400533676,
-0.006848588585853577,
0.01740146428346634,
-0.04355844482779503,
-0.02206542156636715,
0.026098331436514854,
-0.10048459470272064,
-0.028172528371214867,
-0.011649015359580517,
-0.0430699847638607,
0.026239076629281044,
0.04984593018889427,
0.013541778549551964,
0.035608068108558655,
-0.04109389707446098,
-0.0018715894548222423,
0.016684211790561676,
-0.014204274863004684,
-0.01978532411158085,
0.08589092642068863,
0.016389116644859314,
-0.01603166200220585,
0.034817565232515335,
0.053422532975673676,
-0.027439439669251442,
0.05219811201095581,
0.047143079340457916,
-0.006909508723765612,
-0.023749973624944687,
0.18458227813243866,
0.03113361820578575,
-0.022165635600686073,
-0.058023601770401,
0.032149482518434525,
0.053698357194662094,
-0.026464521884918213,
0.032309915870428085,
-0.007473652251064777,
-0.030840208753943443,
-0.01213309820741415,
-0.10906223952770233,
0.013209410943090916,
0.03037257306277752,
0.0166932400316,
-0.008444865234196186,
0.13686016201972961,
-0.023545050993561745,
-0.030431749299168587,
-0.04263807460665703,
0.020036956295371056,
-0.06838415563106537,
0.034637536853551865,
-0.03194071725010872,
0.047200459986925125,
-0.04470376670360565,
-0.04599824920296669,
0.10869618505239487,
-0.008646690286695957,
-0.031985122710466385,
0.027176277711987495,
0.04949324578046799,
-0.06732948869466782,
0.001973137492313981,
-0.02237444370985031,
0.02533205971121788,
0.02351241186261177,
-0.05013701692223549,
-0.02768360823392868,
0.068345807492733,
-0.006578722968697548,
0.05503968521952629,
-0.03531593084335327,
0.05051513388752937,
-0.016088195145130157,
-0.044682424515485764,
-0.04708452895283699,
-0.03240632265806198,
-0.01008311752229929,
0.050429195165634155,
-0.001838147290982306,
0.04835878312587738,
-0.035052135586738586,
-0.011092442087829113,
-0.06375494599342346,
-4.3343867162093375e-8,
-0.06164035573601723,
-0.027490030974149704,
-0.024973750114440918,
0.0035506202839314938,
0.023041531443595886,
-0.07130499929189682,
0.010700395330786705,
0.02286682277917862,
0.0026484099216759205,
-0.09609505534172058,
0.013498504646122456,
-0.016448576003313065,
0.02265479415655136,
-0.011854919604957104,
-0.057097528129816055,
-0.11079691350460052,
0.015274628065526485,
0.008078185841441154,
-0.04705452919006348,
-0.06211468577384949,
-0.011361674405634403,
-0.05330481380224228,
-0.023607328534126282,
0.01660902611911297,
-0.04321380332112312,
-0.03152304142713547,
0.05697060748934746,
-0.010408386588096619,
-0.02161155268549919,
-0.05341409146785736,
0.012751663103699684,
0.05459459125995636,
0.0951123908162117,
0.06087356433272362,
-0.04522175341844559,
0.06235654652118683,
-0.014622458256781101,
0.022271152585744858,
-0.01732354424893856,
0.04730730876326561,
0.02517438493669033,
0.029794108122587204,
-0.005756612401455641,
0.02721235156059265,
0.023969314992427826,
-0.05087018385529518,
0.017159903421998024,
-0.01608029194176197,
-0.011624837294220924,
0.019853340461850166,
-0.027731869369745255,
0.05895594134926796,
-0.05273531749844551,
0.059143032878637314,
0.0386265367269516,
-0.054522935301065445,
0.022905400022864342,
-0.04227524995803833,
-0.05492696911096573,
-0.008859975263476372,
0.0781841054558754,
0.05258404463529587,
0.04648177698254585,
0.0030204341746866703
] | 0.145288 |
methods only. The `callback` function must be called synchronously inside of `writable.\_write()` or asynchronously (i.e. different tick) to signal either that the write completed successfully or failed with an error. The first argument passed to the `callback` must be the `Error` object if the call failed or `null` if the write succeeded. All calls to `writable.write()` that occur between the time `writable.\_write()` is called and the `callback` is called will cause the written data to be buffered. When the `callback` is invoked, the stream might emit a [`'drain'`][] event. If a stream implementation is capable of processing multiple chunks of data at once, the `writable.\_writev()` method should be implemented. If the `decodeStrings` property is explicitly set to `false` in the constructor options, then `chunk` will remain the same object that is passed to `.write()`, and may be a string rather than a `Buffer`. This is to support implementations that have an optimized handling for certain string data encodings. In that case, the `encoding` argument will indicate the character encoding of the string. Otherwise, the `encoding` argument can be safely ignored. The `writable.\_write()` method is prefixed with an underscore because it is internal to the class that defines it, and should never be called directly by user programs. #### `writable.\_writev(chunks, callback)` \* `chunks` {Object\[]} The data to be written. The value is an array of {Object} that each represent a discrete chunk of data to write. The properties of these objects are: \* `chunk` {Buffer|string} A buffer instance or string containing the data to be written. The `chunk` will be a string if the `Writable` was created with the `decodeStrings` option set to `false` and a string was passed to `write()`. \* `encoding` {string} The character encoding of the `chunk`. If `chunk` is a `Buffer`, the `encoding` will be `'buffer'`. \* `callback` {Function} A callback function (optionally with an error argument) to be invoked when processing is complete for the supplied chunks. This function MUST NOT be called by application code directly. It should be implemented by child classes, and called by the internal `Writable` class methods only. The `writable.\_writev()` method may be implemented in addition or alternatively to `writable.\_write()` in stream implementations that are capable of processing multiple chunks of data at once. If implemented and if there is buffered data from previous writes, `\_writev()` will be called instead of `\_write()`. The `writable.\_writev()` method is prefixed with an underscore because it is internal to the class that defines it, and should never be called directly by user programs. #### `writable.\_destroy(err, callback)` \* `err` {Error} A possible error. \* `callback` {Function} A callback function that takes an optional error argument. The `\_destroy()` method is called by [`writable.destroy()`][writable-destroy]. It can be overridden by child classes but it \*\*must not\*\* be called directly. #### `writable.\_final(callback)` \* `callback` {Function} Call this function (optionally with an error argument) when finished writing any remaining data. The `\_final()` method \*\*must not\*\* be called directly. It may be implemented by child classes, and if so, will be called by the internal `Writable` class methods only. This optional function will be called before the stream closes, delaying the `'finish'` event until `callback` is called. This is useful to close resources or write buffered data before a stream ends. #### Errors while writing Errors occurring during the processing of the [`writable.\_write()`][], [`writable.\_writev()`][] and [`writable.\_final()`][] methods must be propagated by invoking the callback and passing the error as the first argument. Throwing an `Error` from within these methods or manually emitting an `'error'` event results in undefined behavior. If a `Readable` stream pipes into a `Writable` stream when `Writable` emits an | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.06308449804782867,
-0.026233449578285217,
-0.04563356935977936,
0.07719706743955612,
-0.05088530108332634,
-0.08525906503200531,
-0.03288009762763977,
0.028590327128767967,
0.06385913491249084,
0.0022887494415044785,
-0.040547072887420654,
0.11984677612781525,
-0.038892004638910294,
-0.0677822157740593,
-0.04575418308377266,
-0.045998331159353256,
-0.014667613431811333,
-0.036236539483070374,
-0.10249517112970352,
-0.06786838173866272,
0.05758441239595413,
-0.01651778072118759,
-0.01213770266622305,
0.062740758061409,
-0.0010565933771431446,
-0.01139375101774931,
-0.0359281525015831,
-0.023521075025200844,
0.052419938147068024,
0.054717548191547394,
-0.022728759795427322,
-0.045211948454380035,
-0.0777706578373909,
-0.03997278958559036,
-0.05029084160923958,
0.10354415327310562,
0.03846091777086258,
-0.09173578768968582,
-0.09613960981369019,
-0.005101568531244993,
0.04795872047543526,
-0.005249830428510904,
-0.1077149361371994,
-0.0114374915137887,
-0.09282289445400238,
0.02245272509753704,
-0.014733566902577877,
-0.021214360371232033,
-0.10275080054998398,
-0.02941661886870861,
-0.01880526728928089,
0.1250268816947937,
-0.07659763097763062,
0.023637432605028152,
0.037433918565511703,
-0.05738067254424095,
0.003286203136667609,
-0.0014476513024419546,
-0.07633872330188751,
-0.016358358785510063,
-0.028948822990059853,
0.025786414742469788,
-0.042005203664302826,
0.03338785097002983,
0.0520172119140625,
-0.021408159285783768,
0.01628287322819233,
0.031979288905858994,
0.03625071421265602,
0.007872484624385834,
-0.032536596059799194,
0.04089287295937538,
-0.14415714144706726,
0.0341726578772068,
0.043453190475702286,
-0.06082804873585701,
0.05864713340997696,
-0.00008805195830063894,
-0.06621399521827698,
-0.0578698106110096,
0.019383549690246582,
-0.029334597289562225,
-0.009874669834971428,
-0.00972848292440176,
0.015056213364005089,
-0.026749158278107643,
0.01884237863123417,
0.07351116836071014,
0.03779170662164688,
0.005623735953122377,
-0.026492992416024208,
0.0050781783647835255,
0.005203713662922382,
0.06893037259578705,
-0.028576478362083435,
0.045478567481040955,
0.11611346155405045,
0.03823871165513992,
0.02006172202527523,
-0.021624108776450157,
0.02160094678401947,
0.01021886058151722,
0.02159447968006134,
-0.0002976803225465119,
0.0575152151286602,
-0.03524777665734291,
0.018934447318315506,
-0.02684735506772995,
0.002282041124999523,
-0.04939005523920059,
-0.0167853944003582,
0.004019699990749359,
0.051829803735017776,
0.035272352397441864,
0.009868533350527287,
0.01754780299961567,
-0.054264266043901443,
0.0073508452624082565,
0.015733227133750916,
0.08522303402423859,
0.0588759183883667,
0.006451404187828302,
-0.017993468791246414,
-0.03877552971243858,
0.04131127521395683,
-0.03362725302577019,
0.020075732842087746,
8.640225565767002e-35,
0.03123464807868004,
-0.07128433883190155,
-0.03388996049761772,
0.003798432182520628,
-0.01994270645081997,
0.07889779657125473,
0.027567189186811447,
-0.0032779457978904247,
-0.03414959833025932,
-0.02342594414949417,
0.008440693840384483,
-0.08261220902204514,
0.02071688137948513,
0.08008025586605072,
0.047073960304260254,
-0.008611672557890415,
0.052861157804727554,
-0.009792244993150234,
0.01976705901324749,
0.09858476370573044,
0.09354198724031448,
0.0447913222014904,
-0.03180947154760361,
-0.013453125953674316,
-0.028584297746419907,
-0.013402078300714493,
-0.03932579234242439,
-0.03826117888092995,
-0.08503826707601547,
0.025262484326958656,
-0.07621099054813385,
-0.02545541524887085,
-0.03684048727154732,
-0.011915581300854683,
0.038187719881534576,
-0.008028757758438587,
-0.05871453508734703,
-0.07671387493610382,
-0.07642879337072372,
-0.07228933274745941,
0.0025697711389511824,
0.007104116026312113,
-0.08853660523891449,
0.008092380128800869,
-0.07611725479364395,
-0.04529012367129326,
-0.07511904090642929,
0.08931225538253784,
0.025252003222703934,
-0.003541626501828432,
0.010017537511885166,
0.08413799107074738,
0.06684239208698273,
0.027326347306370735,
0.048290759325027466,
-0.0031507143285125494,
-0.0024842964485287666,
-0.039735566824674606,
-0.010992471128702164,
0.05585582181811333,
0.05020672082901001,
0.04315813630819321,
-0.02697416953742504,
0.0031279565300792456,
0.007287776563316584,
0.06247121840715408,
0.025648558512330055,
0.028137853369116783,
0.07403318583965302,
-0.05358238145709038,
-0.0663035660982132,
0.05412447825074196,
-0.07018965482711792,
0.04533644765615463,
-0.009585564024746418,
0.014994480647146702,
-0.0026123104616999626,
-0.09903082251548767,
0.0020149839110672474,
0.024424176663160324,
-0.03266976401209831,
-0.005417591892182827,
-0.058565497398376465,
0.000517665350344032,
-0.06705264002084732,
0.012201501056551933,
0.006344020366668701,
-0.032501786947250366,
-0.031721606850624084,
-0.018535206094384193,
-0.04589012265205383,
-0.038756079971790314,
0.10232321172952652,
-0.089384526014328,
-0.04684395343065262,
-3.6856846605025405e-33,
0.012788639403879642,
-0.06938484311103821,
-0.08596944063901901,
0.09117907285690308,
-0.06636831164360046,
-0.03146777302026749,
-0.02248871698975563,
0.02557661570608616,
0.0192140843719244,
-0.01763327233493328,
-0.08833195269107819,
-0.008799005299806595,
-0.014137803576886654,
0.032741956412792206,
-0.014106620103120804,
-0.04600675031542778,
-0.00616086320951581,
-0.10052698105573654,
0.03064497373998165,
-0.04403461888432503,
-0.014875244349241257,
-0.00781481247395277,
0.06713705509901047,
0.01985524222254753,
-0.008891753852367401,
-0.03229449316859245,
-0.055886123329401016,
-0.003417074214667082,
0.015962492674589157,
-0.06487169116735458,
0.03152612969279289,
0.017192969098687172,
-0.024159666150808334,
0.010204844176769257,
0.009938519448041916,
-0.01177346333861351,
0.0345827154815197,
0.00013842519547324628,
-0.009822065941989422,
-0.022666463628411293,
0.18209727108478546,
0.08320996910333633,
0.052607212215662,
-0.002958115190267563,
0.059276241809129715,
0.06692211329936981,
-0.10037463158369064,
0.0033323762472718954,
-0.0153493108227849,
0.02952277846634388,
0.049761440604925156,
-0.048643045127391815,
0.0153896389529109,
0.12960056960582733,
0.08783560991287231,
0.0025598141364753246,
0.11951105296611786,
-0.039350565522909164,
0.01617361418902874,
0.009575405158102512,
-0.04587070643901825,
-0.05577263981103897,
0.053162749856710434,
-0.019910702481865883,
0.0017384386155754328,
0.05678335577249527,
0.052183039486408234,
-0.03174758329987526,
0.06798850744962692,
-0.029126206412911415,
0.08227953314781189,
-0.026601126417517662,
0.001219363883137703,
0.016438746824860573,
0.00962795689702034,
0.06098155677318573,
-0.07394880056381226,
-0.07803545147180557,
-0.07499393075704575,
0.061123210936784744,
-0.04539533331990242,
0.03556963428854942,
0.0025522687938064337,
0.09227325767278671,
0.015357034280896187,
-0.024259885773062706,
0.0018366739386692643,
0.00801233109086752,
-0.010582353919744492,
-0.04347951337695122,
0.046035077422857285,
0.04439390078186989,
-0.09199364483356476,
0.04778296500444412,
-0.06011177599430084,
-5.370672795379505e-8,
-0.02063131518661976,
-0.06065645441412926,
-0.048606909811496735,
0.05475268140435219,
-0.022893229499459267,
-0.03759106248617172,
0.06313459575176239,
-0.08267278224229813,
0.058996621519327164,
-0.00419568782672286,
0.03906901925802231,
-0.11133095622062683,
0.012847510166466236,
-0.07963711023330688,
0.020027095451951027,
0.017793167382478714,
0.029405925422906876,
-0.05995012819766998,
-0.04713347926735878,
-0.030620872974395752,
0.009314123541116714,
-0.06327908486127853,
-0.1070619523525238,
0.06352788209915161,
-0.03443526849150658,
0.019228598102927208,
0.09331930428743362,
0.051807861775159836,
-0.051233865320682526,
-0.06746362894773483,
0.042179614305496216,
0.069990374147892,
0.08321308344602585,
0.1259031891822815,
-0.0005511609488166869,
-0.0032293868716806173,
0.041868824511766434,
0.029704919084906578,
0.025825954973697662,
0.06845119595527649,
0.04699371010065079,
0.004684098996222019,
-0.024803506210446358,
0.009923630394041538,
0.11319205164909363,
-0.043624307960271835,
-0.08356963843107224,
-0.01058744452893734,
-0.00957969855517149,
0.011237958446145058,
-0.040188439190387726,
0.0677211582660675,
0.0291378702968359,
0.08201137185096741,
0.05112022906541824,
-0.05076247453689575,
-0.025269364938139915,
-0.05152008309960365,
0.004096080549061298,
-0.0032906504347920418,
0.06408168375492096,
0.06094677001237869,
0.061329036951065063,
0.0057232994586229324
] | 0.111577 |
[`writable.\_write()`][], [`writable.\_writev()`][] and [`writable.\_final()`][] methods must be propagated by invoking the callback and passing the error as the first argument. Throwing an `Error` from within these methods or manually emitting an `'error'` event results in undefined behavior. If a `Readable` stream pipes into a `Writable` stream when `Writable` emits an error, the `Readable` stream will be unpiped. ```js const { Writable } = require('node:stream'); const myWritable = new Writable({ write(chunk, encoding, callback) { if (chunk.toString().indexOf('a') >= 0) { callback(new Error('chunk is invalid')); } else { callback(); } }, }); ``` #### An example writable stream The following illustrates a rather simplistic (and somewhat pointless) custom `Writable` stream implementation. While this specific `Writable` stream instance is not of any real particular usefulness, the example illustrates each of the required elements of a custom [`Writable`][] stream instance: ```js const { Writable } = require('node:stream'); class MyWritable extends Writable { \_write(chunk, encoding, callback) { if (chunk.toString().indexOf('a') >= 0) { callback(new Error('chunk is invalid')); } else { callback(); } } } ``` #### Decoding buffers in a writable stream Decoding buffers is a common task, for instance, when using transformers whose input is a string. This is not a trivial process when using multi-byte characters encoding, such as UTF-8. The following example shows how to decode multi-byte strings using `StringDecoder` and [`Writable`][]. ```js const { Writable } = require('node:stream'); const { StringDecoder } = require('node:string\_decoder'); class StringWritable extends Writable { constructor(options) { super(options); this.\_decoder = new StringDecoder(options?.defaultEncoding); this.data = ''; } \_write(chunk, encoding, callback) { if (encoding === 'buffer') { chunk = this.\_decoder.write(chunk); } this.data += chunk; callback(); } \_final(callback) { this.data += this.\_decoder.end(); callback(); } } const euro = [[0xE2, 0x82], [0xAC]].map(Buffer.from); const w = new StringWritable(); w.write('currency: '); w.write(euro[0]); w.end(euro[1]); console.log(w.data); // currency: € ``` ### Implementing a readable stream The `stream.Readable` class is extended to implement a [`Readable`][] stream. Custom `Readable` streams \_must\_ call the `new stream.Readable([options])` constructor and implement the [`readable.\_read()`][] method. #### `new stream.Readable([options])` \* `options` {Object} \* `highWaterMark` {number} The maximum [number of bytes][hwm-gotcha] to store in the internal buffer before ceasing to read from the underlying resource. \*\*Default:\*\* `65536` (64 KiB), or `16` for `objectMode` streams. \* `encoding` {string} If specified, then buffers will be decoded to strings using the specified encoding. \*\*Default:\*\* `null`. \* `objectMode` {boolean} Whether this stream should behave as a stream of objects. Meaning that [`stream.read(n)`][stream-read] returns a single value instead of a `Buffer` of size `n`. \*\*Default:\*\* `false`. \* `emitClose` {boolean} Whether or not the stream should emit `'close'` after it has been destroyed. \*\*Default:\*\* `true`. \* `read` {Function} Implementation for the [`stream.\_read()`][stream-\_read] method. \* `destroy` {Function} Implementation for the [`stream.\_destroy()`][readable-\_destroy] method. \* `construct` {Function} Implementation for the [`stream.\_construct()`][readable-\_construct] method. \* `autoDestroy` {boolean} Whether this stream should automatically call `.destroy()` on itself after ending. \*\*Default:\*\* `true`. \* `signal` {AbortSignal} A signal representing possible cancellation. ```js const { Readable } = require('node:stream'); class MyReadable extends Readable { constructor(options) { // Calls the stream.Readable(options) constructor. super(options); // ... } } ``` Or, when using pre-ES6 style constructors: ```js const { Readable } = require('node:stream'); const util = require('node:util'); function MyReadable(options) { if (!(this instanceof MyReadable)) return new MyReadable(options); Readable.call(this, options); } util.inherits(MyReadable, Readable); ``` Or, using the simplified constructor approach: ```js const { Readable } = require('node:stream'); const myReadable = new Readable({ read(size) { // ... }, }); ``` Calling `abort` on the `AbortController` corresponding to the passed `AbortSignal` will behave the same way as calling `.destroy(new AbortError())` on the readable created. ```js const { Readable } = require('node:stream'); const controller = new AbortController(); const read = new Readable({ read(size) { // ... }, | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.027738049626350403,
-0.007483793888241053,
0.011819352395832539,
0.02942449040710926,
-0.0049293446354568005,
-0.05353508144617081,
-0.04260893166065216,
0.05897853150963783,
0.019954156130552292,
-0.028908373787999153,
-0.06900536268949509,
0.05999020114541054,
-0.04602891579270363,
0.0394175685942173,
-0.07155110687017441,
-0.09466499835252762,
-0.027603255584836006,
0.045630600303411484,
-0.07162439823150635,
-0.07006688416004181,
0.026525797322392464,
0.008322065696120262,
-0.020372558385133743,
0.0414617583155632,
0.020366506651043892,
0.017677150666713715,
-0.06716110557317734,
-0.053092747926712036,
0.05189434438943863,
-0.0003395022649783641,
0.013810054399073124,
-0.05737854912877083,
-0.12198925763368607,
-0.051931388676166534,
-0.023174352943897247,
0.10236828774213791,
0.009656945243477821,
-0.10915977507829666,
-0.04820970818400383,
-0.042763516306877136,
0.0905701294541359,
0.0469386912882328,
-0.08805190026760101,
-0.010539165697991848,
-0.04000318795442581,
-0.03193092718720436,
-0.050011079758405685,
-0.033565133810043335,
-0.12304819375276566,
0.07628364861011505,
-0.045861031860113144,
0.01708669401705265,
-0.00975919608026743,
0.03331189230084419,
0.03981978818774223,
-0.0518922433257103,
-0.016110872849822044,
0.0006042246241122484,
0.0009766813600435853,
-0.0000794809966464527,
-0.0018223486840724945,
-0.021865639835596085,
0.02083456702530384,
0.018389031291007996,
0.07014966756105423,
0.007361615542322397,
0.0007394853746518493,
0.054531779140233994,
0.03818288818001747,
0.0584355928003788,
0.005462794564664364,
0.05743541941046715,
-0.09108588099479675,
0.04604650288820267,
-0.03499316796660423,
-0.05176865682005882,
-0.01386282779276371,
0.026264173910021782,
-0.08619289845228195,
0.05760074034333229,
-0.07325821369886398,
-0.050473980605602264,
0.02881617285311222,
0.006456973496824503,
-0.02775486186146736,
0.1079137921333313,
-0.029556959867477417,
0.028875526040792465,
0.06836361438035965,
0.03523449972271919,
-0.12856197357177734,
0.02647869475185871,
0.02151193842291832,
0.06272677332162857,
0.024198291823267937,
0.020393341779708862,
0.060260653495788574,
-0.010196142829954624,
-0.01156628131866455,
0.0027319041546434164,
-0.010471233166754246,
0.08500415831804276,
0.03816558048129082,
-0.03307409957051277,
0.07047991454601288,
-0.04363160580396652,
-0.030688656494021416,
-0.05593124404549599,
-0.0641859695315361,
-0.030745478346943855,
-0.00915086641907692,
0.023609930649399757,
0.04510113224387169,
-0.005795143079012632,
0.003246394917368889,
0.008606860414147377,
-0.017763223499059677,
-0.02867804653942585,
0.017876069992780685,
0.13422749936580658,
0.05016852915287018,
-0.015411974862217903,
0.016039052978157997,
0.010271929204463959,
0.08236998319625854,
-0.04189828410744667,
0.035879820585250854,
-3.7715056663461526e-34,
0.014069285243749619,
-0.04631951451301575,
-0.042210303246974945,
0.0646355077624321,
0.05832551419734955,
0.030694961547851562,
0.0340285524725914,
-0.041958075016736984,
-0.049049828201532364,
-0.04428265988826752,
0.05576722323894501,
0.004220372997224331,
-0.010665425099432468,
0.01069385651499033,
0.07102692127227783,
-0.0029692882671952248,
0.0533178448677063,
-0.011143060401082039,
0.021390400826931,
0.048115454614162445,
0.07381648570299149,
-0.0063248309306800365,
-0.05614886060357094,
-0.0357639379799366,
-0.05119524896144867,
-0.03148897737264633,
-0.03140021115541458,
0.018144164234399796,
-0.006213577464222908,
0.015871167182922363,
0.015088510699570179,
-0.007945804856717587,
0.013047605752944946,
-0.01742137037217617,
0.03576787933707237,
-0.10115832090377808,
0.0026363462675362825,
-0.022098081186413765,
-0.09135448187589645,
-0.009432771243155003,
0.04666664078831673,
0.0076118092983961105,
-0.05723389983177185,
0.02172837406396866,
-0.02233600616455078,
-0.06699119508266449,
-0.06281488388776779,
0.003953738138079643,
0.014302273280918598,
-0.030210480093955994,
0.01830090954899788,
0.09210383892059326,
0.07011743634939194,
-0.007925446145236492,
0.056672219187021255,
-0.011543200351297855,
-0.002993952948600054,
-0.0218487735837698,
-0.039041925221681595,
0.04321876913309097,
0.05121589079499245,
0.11260643601417542,
-0.01704021915793419,
0.03356653079390526,
-0.007693067658692598,
0.05899429693818092,
-0.0322239063680172,
0.013036898337304592,
0.05950239673256874,
-0.1303093135356903,
-0.09630029648542404,
-0.016019798815250397,
-0.0604739673435688,
0.06069222092628479,
-0.03330561891198158,
-0.03791480511426926,
0.004578358959406614,
-0.09539619833230972,
0.01583045721054077,
-0.054361555725336075,
-0.013487178832292557,
-0.046580296009778976,
-0.005625204183161259,
0.1403256207704544,
-0.009003830142319202,
0.01285723689943552,
-0.05847160145640373,
-0.051601164042949677,
-0.053315747529268265,
0.0507422499358654,
-0.007910793647170067,
0.00951416976749897,
0.08258945494890213,
-0.1301332414150238,
-0.016442762687802315,
-3.207350662556012e-33,
-0.008785873651504517,
-0.016104523092508316,
-0.08045576512813568,
0.10838544368743896,
-0.014267104677855968,
-0.02578025311231613,
0.0018917270936071873,
0.024306537583470345,
0.08035094290971756,
-0.0336277149617672,
-0.12358234077692032,
0.04992728680372238,
-0.027583139017224312,
0.04657630994915962,
-0.05196444317698479,
-0.05602264404296875,
-0.0737556517124176,
-0.11136128753423691,
0.026483815163373947,
-0.03928669914603233,
0.03850399702787399,
-0.02718740701675415,
0.08562556654214859,
0.04627120494842529,
-0.05343889817595482,
0.0693444311618805,
-0.043868083506822586,
-0.026723051443696022,
-0.044171977788209915,
-0.07465729117393494,
0.017094986513257027,
0.021892769262194633,
-0.0220809169113636,
0.000512771075591445,
0.03162272647023201,
-0.053790174424648285,
0.006739696953445673,
0.08654201775789261,
0.008994601666927338,
-0.041926391422748566,
0.09877949208021164,
0.052010416984558105,
0.018621083348989487,
-0.03779078647494316,
0.02316271699965,
0.02067292295396328,
0.006821298971772194,
-0.029599642381072044,
0.019549552351236343,
0.022335605695843697,
-0.0016436614096164703,
-0.03427731618285179,
-0.0017961891135200858,
0.1386181116104126,
0.04650872200727463,
0.0037304218858480453,
0.0991642102599144,
-0.04336286336183548,
-0.00040698377415537834,
0.018462039530277252,
-0.02701398730278015,
-0.07302850484848022,
0.01189135666936636,
-0.011853487230837345,
0.0544792041182518,
-0.05051634460687637,
-0.006062893662601709,
-0.02489679493010044,
0.09260451048612595,
-0.017798829823732376,
0.041593097150325775,
-0.013255852274596691,
0.0020302014891058207,
-0.028758637607097626,
0.09479877352714539,
0.009582635015249252,
-0.03128562495112419,
-0.08140850812196732,
0.01742754876613617,
0.047619257122278214,
-0.051406677812337875,
0.1288185864686966,
-0.042776379734277725,
0.052560001611709595,
0.1345490664243698,
-0.018055368214845657,
-0.008745359256863594,
-0.04883740842342377,
-0.02023979276418686,
0.009705007076263428,
0.04895664006471634,
0.039218027144670486,
-0.11598506569862366,
-0.01793302223086357,
-0.02995658852159977,
-4.322116353705496e-8,
-0.046702656894922256,
-0.056968554854393005,
-0.12250439822673798,
0.014352494850754738,
0.014037814922630787,
-0.08034379780292511,
0.0025453248526901007,
-0.06837136298418045,
0.04154224321246147,
-0.039052993059158325,
-0.0009401679853908718,
-0.025399085134267807,
0.03275343403220177,
-0.046909742057323456,
-0.02602371945977211,
-0.03220786526799202,
0.03037603758275509,
0.024707812815904617,
-0.07801862806081772,
0.004689296707510948,
-0.01787855662405491,
-0.004081427119672298,
-0.05804846063256264,
0.053100865334272385,
-0.05499548837542534,
-0.03162236884236336,
0.05309106409549713,
0.036392271518707275,
-0.012417555786669254,
-0.011930623091757298,
-0.010521960444748402,
0.05554598569869995,
0.12018287926912308,
0.0891622006893158,
-0.04627710208296776,
0.012665273621678352,
-0.0047795744612813,
0.021984770894050598,
-0.013871723785996437,
0.006775832735002041,
0.10111478716135025,
0.007731459569185972,
-0.004938342142850161,
0.04213554039597511,
0.0022498879116028547,
-0.03740648552775383,
-0.025667015463113785,
0.018124908208847046,
0.01095439214259386,
0.03308095782995224,
-0.041494257748126984,
0.08691616356372833,
-0.025741316378116608,
0.05720824748277664,
0.002601283136755228,
-0.045913659036159515,
0.01250481978058815,
-0.09334810823202133,
-0.06591954827308655,
-0.011822786182165146,
0.13262978196144104,
0.04929114505648613,
0.03930816054344177,
0.0034382485318928957
] | 0.092612 |
// ... }, }); ``` Calling `abort` on the `AbortController` corresponding to the passed `AbortSignal` will behave the same way as calling `.destroy(new AbortError())` on the readable created. ```js const { Readable } = require('node:stream'); const controller = new AbortController(); const read = new Readable({ read(size) { // ... }, signal: controller.signal, }); // Later, abort the operation closing the stream controller.abort(); ``` #### `readable.\_construct(callback)` \* `callback` {Function} Call this function (optionally with an error argument) when the stream has finished initializing. The `\_construct()` method MUST NOT be called directly. It may be implemented by child classes, and if so, will be called by the internal `Readable` class methods only. This optional function will be scheduled in the next tick by the stream constructor, delaying any `\_read()` and `\_destroy()` calls until `callback` is called. This is useful to initialize state or asynchronously initialize resources before the stream can be used. ```js const { Readable } = require('node:stream'); const fs = require('node:fs'); class ReadStream extends Readable { constructor(filename) { super(); this.filename = filename; this.fd = null; } \_construct(callback) { fs.open(this.filename, (err, fd) => { if (err) { callback(err); } else { this.fd = fd; callback(); } }); } \_read(n) { const buf = Buffer.alloc(n); fs.read(this.fd, buf, 0, n, null, (err, bytesRead) => { if (err) { this.destroy(err); } else { this.push(bytesRead > 0 ? buf.slice(0, bytesRead) : null); } }); } \_destroy(err, callback) { if (this.fd) { fs.close(this.fd, (er) => callback(er || err)); } else { callback(err); } } } ``` #### `readable.\_read(size)` \* `size` {number} Number of bytes to read asynchronously This function MUST NOT be called by application code directly. It should be implemented by child classes, and called by the internal `Readable` class methods only. All `Readable` stream implementations must provide an implementation of the [`readable.\_read()`][] method to fetch data from the underlying resource. When [`readable.\_read()`][] is called, if data is available from the resource, the implementation should begin pushing that data into the read queue using the [`this.push(dataChunk)`][stream-push] method. `\_read()` will be called again after each call to [`this.push(dataChunk)`][stream-push] once the stream is ready to accept more data. `\_read()` may continue reading from the resource and pushing data until `readable.push()` returns `false`. Only when `\_read()` is called again after it has stopped should it resume pushing additional data into the queue. Once the [`readable.\_read()`][] method has been called, it will not be called again until more data is pushed through the [`readable.push()`][stream-push] method. Empty data such as empty buffers and strings will not cause [`readable.\_read()`][] to be called. The `size` argument is advisory. For implementations where a "read" is a single operation that returns data can use the `size` argument to determine how much data to fetch. Other implementations may ignore this argument and simply provide data whenever it becomes available. There is no need to "wait" until `size` bytes are available before calling [`stream.push(chunk)`][stream-push]. The [`readable.\_read()`][] method is prefixed with an underscore because it is internal to the class that defines it, and should never be called directly by user programs. #### `readable.\_destroy(err, callback)` \* `err` {Error} A possible error. \* `callback` {Function} A callback function that takes an optional error argument. The `\_destroy()` method is called by [`readable.destroy()`][readable-destroy]. It can be overridden by child classes but it \*\*must not\*\* be called directly. #### `readable.push(chunk[, encoding])` \* `chunk` {Buffer|TypedArray|DataView|string|null|any} Chunk of data to push into the read queue. For streams not operating in object mode, `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. For object mode streams, `chunk` may be any JavaScript value. \* `encoding` {string} Encoding of string chunks. Must be a valid `Buffer` | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.08232107013463974,
0.00367768038995564,
-0.017048262059688568,
0.04107500612735748,
0.04051641374826431,
-0.013387016952037811,
-0.01092706061899662,
0.06682867556810379,
0.05850674584507942,
-0.0034773540683090687,
-0.034238941967487335,
0.10433559864759445,
-0.0862729400396347,
-0.008303030394017696,
-0.05717115104198456,
0.007059226743876934,
-0.009668870829045773,
-0.004581654444336891,
-0.0438663475215435,
-0.039839763194322586,
0.07141776382923126,
0.021319974213838577,
0.01937299221754074,
0.06695199012756348,
-0.05431366339325905,
-0.04551542550325394,
-0.02425725944340229,
-0.05029865354299545,
0.04380771145224571,
-0.019721537828445435,
0.02045479789376259,
-0.07321178168058395,
-0.06924612820148468,
-0.03452557697892189,
-0.11966252326965332,
0.08735285699367523,
-0.043668609112501144,
-0.10547224432229996,
-0.0020043044351041317,
-0.012387977913022041,
0.09586070477962494,
0.08453816920518875,
-0.13776947557926178,
-0.020072922110557556,
0.023942623287439346,
-0.004785222467035055,
-0.07903215289115906,
-0.04203574359416962,
-0.0736830085515976,
0.012722548097372055,
-0.05581517890095711,
0.019030096009373665,
-0.04850258678197861,
0.0668022483587265,
0.037865880876779556,
-0.06511332094669342,
-0.014065643772482872,
-0.010921146720647812,
0.04194822534918785,
0.045930441468954086,
-0.04539964348077774,
0.024061545729637146,
-0.01842963509261608,
-0.009470675140619278,
0.07174143940210342,
0.010009287856519222,
0.009896522387862206,
0.004143045283854008,
0.08862552046775818,
0.07373552024364471,
0.0400719977915287,
-0.026774365454912186,
-0.012411142699420452,
0.015065012499690056,
-0.03216061368584633,
-0.05811120942234993,
0.002243577502667904,
0.0067129433155059814,
-0.08598165214061737,
0.030551040545105934,
-0.05608314275741577,
-0.08264900743961334,
0.0009635307360440493,
-0.06387142091989517,
-0.03617716580629349,
0.09289473295211792,
-0.01683531329035759,
-0.043654847890138626,
0.0729164183139801,
-0.01974230259656906,
-0.13187046349048615,
0.021747317165136337,
-0.009714036248624325,
0.07424242794513702,
-0.01992555521428585,
0.02905365638434887,
0.03151903674006462,
-0.09057629853487015,
-0.05529245734214783,
-0.0001040725182974711,
-0.02288707159459591,
0.05408491939306259,
0.022640082985162735,
-0.006723238620907068,
0.018478896468877792,
-0.09873811155557632,
-0.06852363049983978,
0.07538928836584091,
-0.0010814620181918144,
-0.04361410811543465,
-0.010720625519752502,
0.013261386193335056,
0.01421611662954092,
0.04129183292388916,
-0.006685600616037846,
0.10723158717155457,
0.060873907059431076,
0.012969986535608768,
0.05622900649905205,
0.08537793904542923,
0.09885671734809875,
-0.009731316938996315,
-0.02243400178849697,
-0.00045278118341229856,
0.0732259675860405,
-0.01957148313522339,
0.06293804198503494,
1.5387539721435412e-33,
-0.038797035813331604,
-0.07906568050384521,
-0.08669731020927429,
0.09829150140285492,
0.06773625314235687,
0.017152709886431694,
-0.0028333712834864855,
0.0012122149346396327,
-0.044006410986185074,
0.025102682411670685,
-0.027492545545101166,
-0.08208738267421722,
-0.01635626330971718,
0.052857283502817154,
0.05937245860695839,
-0.0905069038271904,
0.07976699620485306,
-0.040007028728723526,
0.013488936237990856,
-0.008882509544491768,
0.11114555597305298,
-0.012596704997122288,
-0.05957154184579849,
-0.008806134574115276,
0.002905251458287239,
0.0026505349669605494,
-0.02010236494243145,
0.06097392737865448,
-0.007060668431222439,
0.014229334890842438,
0.03508701175451279,
0.019787916913628578,
-0.04427453875541687,
0.021733509376645088,
0.067482128739357,
-0.10184706747531891,
-0.01623939909040928,
0.00927858054637909,
-0.07884471118450165,
-0.03293738514184952,
-0.00515849981456995,
0.023021738976240158,
-0.16855596005916595,
0.013327216729521751,
0.002142258919775486,
-0.13961561024188995,
0.04201173409819603,
0.0008331899880431592,
0.053351327776908875,
-0.061674151569604874,
0.010429988615214825,
0.017325295135378838,
0.07237352430820465,
0.011214369907975197,
0.046521686017513275,
0.03691605478525162,
0.013463716953992844,
-0.09052309393882751,
-0.019184956327080727,
0.012269308790564537,
0.0778285562992096,
-0.024171805009245872,
-0.0017851891461759806,
0.03257415443658829,
-0.030053982511162758,
0.028077110648155212,
-0.03440025448799133,
-0.04118910804390907,
0.0463564395904541,
-0.09250227361917496,
-0.07395192980766296,
0.042119719088077545,
0.0050501637160778046,
-0.007044562604278326,
-0.0013120132498443127,
0.008660269901156425,
-0.038719624280929565,
-0.011474459432065487,
0.027440231293439865,
0.0044384426437318325,
0.1071416437625885,
-0.04202931746840477,
0.026595864444971085,
0.09010064601898193,
0.05983023717999458,
0.00973538774996996,
0.013316403143107891,
-0.07666640728712082,
-0.01125286053866148,
0.02001974917948246,
-0.02106049656867981,
0.007592708338052034,
0.058021314442157745,
-0.07414175570011139,
-0.0470210425555706,
-4.289027339871234e-33,
0.0030942088924348354,
-0.03285602852702141,
-0.03168785944581032,
0.03949479013681412,
-0.003944835625588894,
-0.06055402755737305,
-0.03447538986802101,
0.05286475270986557,
0.007998697459697723,
-0.005006121005862951,
-0.015371443703770638,
0.04732498899102211,
0.024268409237265587,
0.04992852732539177,
-0.06748413294553757,
0.001164309331215918,
0.024385904893279076,
-0.1258164644241333,
-0.033774904906749725,
-0.017178092151880264,
-0.02564704604446888,
-0.06507653743028641,
0.03228893131017685,
-0.035785067826509476,
-0.020778927952051163,
0.03868882358074188,
-0.012075398117303848,
0.02669760212302208,
-0.02270475961267948,
-0.04869755730032921,
0.00927381869405508,
-0.026005340740084648,
0.043518900871276855,
0.036774471402168274,
0.049106623977422714,
-0.022737497463822365,
0.025816520676016808,
0.1324094533920288,
-0.08111248165369034,
-0.04533786699175835,
0.140274316072464,
0.04181786999106407,
-0.006982490886002779,
-0.06145486980676651,
0.029127413406968117,
-0.031229160726070404,
0.0221448615193367,
0.020591486245393753,
-0.08580006659030914,
0.01542846579104662,
-0.05627182871103287,
-0.014270850457251072,
0.016279421746730804,
0.07027990370988846,
0.007347656413912773,
-0.04903750121593475,
0.12934260070323944,
0.007909485138952732,
0.060008708387613297,
-0.01626753993332386,
0.03848215565085411,
-0.09569006413221359,
0.044150758534669876,
-0.009784677065908909,
0.07817661762237549,
0.005934647750109434,
-0.001730476156808436,
0.04894964396953583,
0.12947553396224976,
0.016836147755384445,
0.07150480151176453,
0.04562976583838463,
-0.05122176185250282,
-0.0031683293636888266,
-0.0018628103425726295,
-0.018510928377509117,
-0.043126460164785385,
-0.04887755960226059,
0.005532005336135626,
0.02012060210108757,
-0.00029814441222697496,
0.030303968116641045,
-0.015821214765310287,
0.05767136067152023,
0.016682298853993416,
-0.010158316232264042,
-0.006776680238544941,
-0.05571959167718887,
-0.021399131044745445,
-0.046046800911426544,
-0.005439418833702803,
-0.016553130000829697,
-0.052224718034267426,
0.013455172069370747,
-0.023394180461764336,
-4.6869278236272294e-8,
-0.03269527852535248,
0.018152354285120964,
-0.0442303866147995,
-0.025353942066431046,
0.037840232253074646,
-0.10496830940246582,
0.00525950500741601,
-0.01903771236538887,
-0.018195683136582375,
0.008319349028170109,
-0.015141324140131474,
0.018765587359666824,
0.07672084867954254,
-0.020390061661601067,
-0.02865646220743656,
-0.047571077942848206,
0.040127817541360855,
0.012600299902260303,
0.00041555092320777476,
-0.021114805713295937,
-0.02338256500661373,
-0.05426163226366043,
-0.014308116398751736,
0.0389469638466835,
0.02865108847618103,
-0.007043229416012764,
0.09077636897563934,
0.05577078089118004,
0.013050537556409836,
-0.040899887681007385,
-0.05686504766345024,
0.06526606529951096,
0.08488692343235016,
0.0856969952583313,
-0.09472912549972534,
0.0272541344165802,
-0.015411686152219772,
0.0327996127307415,
0.003782555228099227,
0.07666414231061935,
0.07024839520454407,
0.02893347665667534,
-0.009483392350375652,
0.05205061286687851,
0.045836757868528366,
-0.0036713622976094484,
0.004221961367875338,
-0.0005968516925349832,
0.027437184005975723,
0.09461822360754013,
-0.013548548333346844,
0.015591979026794434,
-0.051336728036403656,
0.02114599384367466,
0.00772341201081872,
-0.07334974408149719,
-0.037125516682863235,
-0.1374044567346573,
-0.10195110738277435,
0.008132127113640308,
0.05735274404287338,
0.050456684082746506,
0.00024651121930219233,
0.007977848872542381
] | 0.120709 |
\* `chunk` {Buffer|TypedArray|DataView|string|null|any} Chunk of data to push into the read queue. For streams not operating in object mode, `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. For object mode streams, `chunk` may be any JavaScript value. \* `encoding` {string} Encoding of string chunks. Must be a valid `Buffer` encoding, such as `'utf8'` or `'ascii'`. \* Returns: {boolean} `true` if additional chunks of data may continue to be pushed; `false` otherwise. When `chunk` is a {Buffer}, {TypedArray}, {DataView} or {string}, the `chunk` of data will be added to the internal queue for users of the stream to consume. Passing `chunk` as `null` signals the end of the stream (EOF), after which no more data can be written. When the `Readable` is operating in paused mode, the data added with `readable.push()` can be read out by calling the [`readable.read()`][stream-read] method when the [`'readable'`][] event is emitted. When the `Readable` is operating in flowing mode, the data added with `readable.push()` will be delivered by emitting a `'data'` event. The `readable.push()` method is designed to be as flexible as possible. For example, when wrapping a lower-level source that provides some form of pause/resume mechanism, and a data callback, the low-level source can be wrapped by the custom `Readable` instance: ```js // `\_source` is an object with readStop() and readStart() methods, // and an `ondata` member that gets called when it has data, and // an `onend` member that gets called when the data is over. class SourceWrapper extends Readable { constructor(options) { super(options); this.\_source = getLowLevelSourceObject(); // Every time there's data, push it into the internal buffer. this.\_source.ondata = (chunk) => { // If push() returns false, then stop reading from source. if (!this.push(chunk)) this.\_source.readStop(); }; // When the source ends, push the EOF-signaling `null` chunk. this.\_source.onend = () => { this.push(null); }; } // \_read() will be called when the stream wants to pull more data in. // The advisory size argument is ignored in this case. \_read(size) { this.\_source.readStart(); } } ``` The `readable.push()` method is used to push the content into the internal buffer. It can be driven by the [`readable.\_read()`][] method. For streams not operating in object mode, if the `chunk` parameter of `readable.push()` is `undefined`, it will be treated as empty string or buffer. See [`readable.push('')`][] for more information. #### Errors while reading Errors occurring during processing of the [`readable.\_read()`][] must be propagated through the [`readable.destroy(err)`][readable-\_destroy] method. Throwing an `Error` from within [`readable.\_read()`][] or manually emitting an `'error'` event results in undefined behavior. ```js const { Readable } = require('node:stream'); const myReadable = new Readable({ read(size) { const err = checkSomeErrorCondition(); if (err) { this.destroy(err); } else { // Do some work. } }, }); ``` #### An example counting stream The following is a basic example of a `Readable` stream that emits the numerals from 1 to 1,000,000 in ascending order, and then ends. ```js const { Readable } = require('node:stream'); class Counter extends Readable { constructor(opt) { super(opt); this.\_max = 1000000; this.\_index = 1; } \_read() { const i = this.\_index++; if (i > this.\_max) this.push(null); else { const str = String(i); const buf = Buffer.from(str, 'ascii'); this.push(buf); } } } ``` ### Implementing a duplex stream A [`Duplex`][] stream is one that implements both [`Readable`][] and [`Writable`][], such as a TCP socket connection. Because JavaScript does not have support for multiple inheritance, the `stream.Duplex` class is extended to implement a [`Duplex`][] stream (as opposed to extending the `stream.Readable` \_and\_ `stream.Writable` classes). The `stream.Duplex` class prototypically inherits from `stream.Readable` and parasitically from `stream.Writable`, but `instanceof` will work properly for both base classes due to overriding | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.04893339052796364,
-0.028950754553079605,
-0.044520918279886246,
0.02634940855205059,
-0.08196493238210678,
-0.04925859346985817,
0.037900883704423904,
-0.023954052478075027,
0.016085635870695114,
-0.03913908079266548,
-0.03517802059650421,
0.047188181430101395,
-0.06568117439746857,
0.00017320715414825827,
-0.004891814664006233,
-0.014456918463110924,
0.022203922271728516,
-0.10517054051160812,
-0.03685910999774933,
0.00831895973533392,
0.09950810670852661,
-0.021584877744317055,
-0.028139129281044006,
-0.017874952405691147,
0.014792577363550663,
0.0724407508969307,
-0.03232022747397423,
-0.051846958696842194,
0.06662273406982422,
-0.024583175778388977,
0.021715758368372917,
-0.06078670918941498,
-0.028739850968122482,
0.009872792288661003,
-0.05269249528646469,
0.06830563396215439,
0.02397341839969158,
-0.09289948642253876,
-0.09719602018594742,
-0.03442972153425217,
0.07634249329566956,
0.025595540180802345,
-0.13835518062114716,
0.04435285925865173,
-0.018139149993658066,
-0.009032984264194965,
-0.041909534484148026,
-0.02525121532380581,
-0.07722429186105728,
-0.00793502014130354,
-0.13579368591308594,
0.03212745860219002,
-0.04351391643285751,
0.09267928451299667,
0.08294621109962463,
-0.0221435334533453,
-0.02057076059281826,
0.04183462634682655,
0.000916694407351315,
0.008956811390817165,
-0.06114104390144348,
-0.050560399889945984,
0.06980349123477936,
0.052910126745700836,
0.06999076902866364,
-0.02257744036614895,
0.033311136066913605,
0.03585546836256981,
0.04851812124252319,
-0.056169409304857254,
-0.025083741173148155,
0.03806658089160919,
-0.06126334145665169,
0.020918749272823334,
-0.04193573072552681,
-0.038664814084768295,
0.06704987585544586,
-0.05439399182796478,
0.00723303435370326,
-0.009923095814883709,
-0.07415800541639328,
-0.08865135163068771,
-0.02005123160779476,
0.01293956395238638,
-0.008720827288925648,
0.033405646681785583,
-0.019059618934988976,
0.060035593807697296,
-0.05494026839733124,
0.05237509310245514,
-0.043410155922174454,
-0.003751045558601618,
0.015080115757882595,
0.10355912894010544,
0.008571668528020382,
0.028463078662753105,
0.03754357993602753,
-0.0031044459901750088,
-0.014105821028351784,
-0.006392756476998329,
0.007912266999483109,
0.06914319097995758,
0.06123380362987518,
0.039134856313467026,
-0.022233746945858,
-0.14174038171768188,
0.028272399678826332,
0.007861848920583725,
-0.08093886822462082,
0.008204092271625996,
0.024081995710730553,
0.05895063653588295,
0.03633125126361847,
-0.02243063971400261,
-0.09283636510372162,
0.03750322386622429,
-0.05623815581202507,
-0.018395228311419487,
0.009003558196127415,
0.10017245262861252,
0.036384500563144684,
-0.04095685854554176,
-0.08433119207620621,
-0.025350727140903473,
0.09006661176681519,
-0.03768698126077652,
0.06659124791622162,
2.8973592105907435e-33,
-0.024324240162968636,
-0.07794573158025742,
-0.030021343380212784,
0.0007634185021743178,
-0.015891864895820618,
0.0011444049887359142,
0.003541470505297184,
0.08411727100610733,
-0.02201092429459095,
-0.05032773315906525,
-0.04678844287991524,
-0.029840897768735886,
0.025839127600193024,
0.10338795185089111,
0.03307127580046654,
-0.04576632007956505,
0.09180380403995514,
0.022641660645604134,
-0.05177057534456253,
0.03842947259545326,
0.04756080359220505,
0.014952448196709156,
-0.06518976390361786,
-0.010621779598295689,
-0.04757671430706978,
-0.0020706006325781345,
-0.03431928902864456,
0.012236563488841057,
-0.028364935889840126,
0.023987354710698128,
-0.04276222735643387,
-0.04629233479499817,
-0.015345346182584763,
-0.0035001288633793592,
0.08275948464870453,
-0.044330667704343796,
-0.026655856519937515,
-0.024821335449814796,
-0.057480182498693466,
-0.07523912936449051,
0.015014510601758957,
-0.005914926994591951,
-0.05663350969552994,
-0.007259837351739407,
-0.10972253978252411,
-0.09147859364748001,
-0.0330464169383049,
-0.008253398351371288,
-0.07676156610250473,
0.010323944501578808,
0.052841413766145706,
0.061951834708452225,
0.03340897336602211,
0.02082768827676773,
0.022753553465008736,
-0.02133610099554062,
0.024088915437459946,
-0.011782699264585972,
-0.005138564854860306,
0.06314461678266525,
-0.032795846462249756,
0.058395449072122574,
0.0917709544301033,
0.038341064006090164,
-0.005344956647604704,
0.05968165770173073,
0.004285737406462431,
-0.015354843810200691,
0.045387499034404755,
-0.042202889919281006,
-0.05064627528190613,
0.017513224855065346,
0.04467377811670303,
0.054741472005844116,
-0.05043841153383255,
0.018767433241009712,
-0.07109289616346359,
-0.08338882029056549,
-0.017955441027879715,
-0.017927471548318863,
0.05245509371161461,
-0.04749426245689392,
0.02484295889735222,
0.02212141454219818,
-0.05139530822634697,
0.03501010686159134,
-0.012962193228304386,
-0.08970581740140915,
0.021927285939455032,
0.012216256000101566,
-0.02223225124180317,
-0.029294105246663094,
0.03380042687058449,
-0.14252056181430817,
0.011089333333075047,
-4.789006964262201e-33,
0.046460140496492386,
-0.028255963698029518,
-0.08273687958717346,
0.010655960999429226,
-0.03819825127720833,
0.00134480488486588,
-0.005619877949357033,
0.09553840011358261,
0.05309716612100601,
-0.08159709721803665,
-0.06855163723230362,
0.06042546406388283,
-0.011782306246459484,
0.011978940106928349,
-0.03208749368786812,
0.004320907406508923,
-0.012763705104589462,
-0.0876089408993721,
0.01194660272449255,
-0.01814463920891285,
-0.013135158456861973,
-0.05117560178041458,
0.005185721907764673,
0.0805177092552185,
-0.01540397573262453,
0.04349653422832489,
-0.016539668664336205,
0.01679849438369274,
0.01400813739746809,
0.001585997873917222,
0.0032330004032701254,
-0.03314721956849098,
-0.06727715581655502,
-0.017411913722753525,
0.014341691508889198,
-0.022080453112721443,
0.050938528031110764,
0.08996783196926117,
-0.01872917078435421,
0.0036898734979331493,
0.1474798619747162,
0.05586637556552887,
-0.010958898812532425,
0.011485815979540348,
0.034821245819330215,
-0.028516851365566254,
0.004858857952058315,
0.038161151111125946,
-0.07421920448541641,
-0.013093199580907822,
0.058384306728839874,
0.03313463181257248,
0.046942029148340225,
0.06647095084190369,
0.03743717446923256,
0.017296453937888145,
0.01715012639760971,
-0.07320606708526611,
0.007931659929454327,
-0.03413907811045647,
-0.03392275422811508,
-0.1150592491030693,
-0.01343496236950159,
-0.03283321112394333,
0.02886214666068554,
-0.058849725872278214,
0.032884906977415085,
-0.08117575943470001,
0.0405191108584404,
-0.0765792652964592,
0.03143011033535004,
-0.041269559413194656,
0.036849167197942734,
0.045740481466054916,
0.010535736568272114,
0.04090138524770737,
-0.06845644861459732,
-0.07520057260990143,
0.01538250595331192,
0.1010415256023407,
0.030170071870088577,
0.07028315961360931,
0.04504658654332161,
0.09323598444461823,
0.08072583377361298,
0.03112037107348442,
-0.03353269025683403,
-0.051526207476854324,
-0.04026184603571892,
-0.0671774297952652,
-0.02379259094595909,
0.06792324781417847,
-0.1052648052573204,
0.043319083750247955,
-0.02656199038028717,
-5.3116934850550024e-8,
0.006870155688375235,
-0.06093563511967659,
-0.060046516358852386,
0.060714539140462875,
0.022566257044672966,
-0.07365382462739944,
-0.07591500133275986,
-0.04447583109140396,
0.06580408662557602,
-0.02609923854470253,
0.05252930894494057,
-0.005724345333874226,
-0.046298518776893616,
-0.05832809582352638,
0.05681416392326355,
0.022583292797207832,
0.04284178093075752,
-0.05487760901451111,
-0.02086418680846691,
0.03888127952814102,
0.025019662454724312,
-0.04657978564500809,
-0.0756191834807396,
0.03718430548906326,
0.032917652279138565,
0.05284106731414795,
0.07181480526924133,
0.07812024652957916,
0.025864766910672188,
-0.03839607909321785,
0.029098263010382652,
0.07099061459302902,
0.07956866919994354,
0.06843027472496033,
-0.016919797286391258,
0.03144830837845802,
0.10840875655412674,
0.036140140146017075,
0.030762728303670883,
0.07616759836673737,
0.16756434738636017,
-0.02273983135819435,
-0.012210479006171227,
0.01987208053469658,
-0.008361450396478176,
0.0035258918069303036,
-0.047276902943849564,
0.08053477108478546,
0.02422860637307167,
0.010408081114292145,
-0.0062203360721468925,
0.031169142574071884,
-0.04369292035698891,
0.06082034856081009,
-0.0020304482895880938,
-0.07413579523563385,
0.009521536529064178,
-0.036720406264066696,
0.007868080399930477,
0.05435055121779442,
0.1179022416472435,
0.03369234502315521,
0.016453690826892853,
-0.012176483869552612
] | 0.103493 |
JavaScript does not have support for multiple inheritance, the `stream.Duplex` class is extended to implement a [`Duplex`][] stream (as opposed to extending the `stream.Readable` \_and\_ `stream.Writable` classes). The `stream.Duplex` class prototypically inherits from `stream.Readable` and parasitically from `stream.Writable`, but `instanceof` will work properly for both base classes due to overriding [`Symbol.hasInstance`][] on `stream.Writable`. Custom `Duplex` streams \_must\_ call the `new stream.Duplex([options])` constructor and implement \_both\_ the [`readable.\_read()`][] and `writable.\_write()` methods. #### `new stream.Duplex(options)` \* `options` {Object} Passed to both `Writable` and `Readable` constructors. Also has the following fields: \* `allowHalfOpen` {boolean} If set to `false`, then the stream will automatically end the writable side when the readable side ends. \*\*Default:\*\* `true`. \* `readable` {boolean} Sets whether the `Duplex` should be readable. \*\*Default:\*\* `true`. \* `writable` {boolean} Sets whether the `Duplex` should be writable. \*\*Default:\*\* `true`. \* `readableObjectMode` {boolean} Sets `objectMode` for readable side of the stream. Has no effect if `objectMode` is `true`. \*\*Default:\*\* `false`. \* `writableObjectMode` {boolean} Sets `objectMode` for writable side of the stream. Has no effect if `objectMode` is `true`. \*\*Default:\*\* `false`. \* `readableHighWaterMark` {number} Sets `highWaterMark` for the readable side of the stream. Has no effect if `highWaterMark` is provided. \* `writableHighWaterMark` {number} Sets `highWaterMark` for the writable side of the stream. Has no effect if `highWaterMark` is provided. ```js const { Duplex } = require('node:stream'); class MyDuplex extends Duplex { constructor(options) { super(options); // ... } } ``` Or, when using pre-ES6 style constructors: ```js const { Duplex } = require('node:stream'); const util = require('node:util'); function MyDuplex(options) { if (!(this instanceof MyDuplex)) return new MyDuplex(options); Duplex.call(this, options); } util.inherits(MyDuplex, Duplex); ``` Or, using the simplified constructor approach: ```js const { Duplex } = require('node:stream'); const myDuplex = new Duplex({ read(size) { // ... }, write(chunk, encoding, callback) { // ... }, }); ``` When using pipeline: ```js const { Transform, pipeline } = require('node:stream'); const fs = require('node:fs'); pipeline( fs.createReadStream('object.json') .setEncoding('utf8'), new Transform({ decodeStrings: false, // Accept string input rather than Buffers construct(callback) { this.data = ''; callback(); }, transform(chunk, encoding, callback) { this.data += chunk; callback(); }, flush(callback) { try { // Make sure is valid json. JSON.parse(this.data); this.push(this.data); callback(); } catch (err) { callback(err); } }, }), fs.createWriteStream('valid-object.json'), (err) => { if (err) { console.error('failed', err); } else { console.log('completed'); } }, ); ``` #### An example duplex stream The following illustrates a simple example of a `Duplex` stream that wraps a hypothetical lower-level source object to which data can be written, and from which data can be read, albeit using an API that is not compatible with Node.js streams. The following illustrates a simple example of a `Duplex` stream that buffers incoming written data via the [`Writable`][] interface that is read back out via the [`Readable`][] interface. ```js const { Duplex } = require('node:stream'); const kSource = Symbol('source'); class MyDuplex extends Duplex { constructor(source, options) { super(options); this[kSource] = source; } \_write(chunk, encoding, callback) { // The underlying source only deals with strings. if (Buffer.isBuffer(chunk)) chunk = chunk.toString(); this[kSource].writeSomeData(chunk); callback(); } \_read(size) { this[kSource].fetchSomeData(size, (data, encoding) => { this.push(Buffer.from(data, encoding)); }); } } ``` The most important aspect of a `Duplex` stream is that the `Readable` and `Writable` sides operate independently of one another despite co-existing within a single object instance. #### Object mode duplex streams For `Duplex` streams, `objectMode` can be set exclusively for either the `Readable` or `Writable` side using the `readableObjectMode` and `writableObjectMode` options respectively. In the following example, for instance, a new `Transform` stream (which is a type of [`Duplex`][] stream) is created that has an object mode `Writable` side that accepts JavaScript numbers that are converted to | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.0476725809276104,
-0.0526629313826561,
0.036518488079309464,
-0.00036076034302823246,
-0.027745002880692482,
-0.0014509832253679633,
0.009400399401783943,
0.0101414630189538,
-0.05910728499293327,
-0.06570761650800705,
-0.056461308151483536,
0.07258899509906769,
-0.06209651008248329,
0.10187356173992157,
0.022705813869833946,
-0.013440561480820179,
-0.029796507209539413,
-0.014682143926620483,
-0.09985512495040894,
0.03248107060790062,
0.08614205569028854,
-0.046314120292663574,
-0.009556801058351994,
0.00036583811743184924,
-0.026094181463122368,
0.02435564436018467,
-0.018392289057374,
-0.016818616539239883,
0.05383153632283211,
-0.03273268789052963,
0.03375464305281639,
-0.039503972977399826,
-0.13432911038398743,
-0.020188728347420692,
-0.030900316312909126,
0.03944137319922447,
0.03512599319219589,
-0.042410194873809814,
0.016185296699404716,
0.03403787314891815,
0.02806839533150196,
0.05382988974452019,
-0.026729781180620193,
-0.03030554950237274,
-0.05010638386011124,
0.017808061093091965,
-0.05930465832352638,
-0.0022082007490098476,
-0.07344505190849304,
0.017309535294771194,
-0.01508231833577156,
0.0004163908597547561,
-0.014677660539746284,
0.04247081279754639,
0.05657798424363136,
-0.01498502865433693,
-0.048492033034563065,
0.02693342976272106,
-0.031448859721422195,
0.021107375621795654,
-0.10256858915090561,
0.042658597230911255,
0.023248106241226196,
0.00503501296043396,
-0.037004537880420685,
-0.02576158195734024,
-0.026738176122307777,
0.11428170651197433,
-0.0031557432375848293,
0.05675058811903,
-0.007727369666099548,
0.05952025577425957,
0.04124664142727852,
0.048516176640987396,
-0.008353197947144508,
-0.10519525408744812,
0.02118811011314392,
0.05830520763993263,
-0.017089227214455605,
-0.03334122896194458,
-0.10508178174495697,
-0.11236152797937393,
0.016965476796030998,
0.025566626340150833,
0.016836272552609444,
0.0219130739569664,
-0.03196942061185837,
-0.025402069091796875,
0.06939967721700668,
0.0684085339307785,
-0.08977097272872925,
0.021140845492482185,
0.04497205838561058,
0.06532406061887741,
-0.0006762091652490199,
0.04453685134649277,
0.013901110738515854,
-0.014229943975806236,
-0.03366168960928917,
0.02129237726330757,
-0.018873346969485283,
0.01665974035859108,
0.09712891280651093,
0.000536533712875098,
0.08465537428855896,
-0.04395313933491707,
-0.03828065097332001,
0.00832524523139,
0.025524325668811798,
-0.09188675135374069,
-0.005309091415256262,
0.04760999605059624,
0.021177127957344055,
-0.0014781856443732977,
-0.029985807836055756,
0.09158021956682205,
-0.026990637183189392,
-0.04214237257838249,
0.058910347521305084,
0.10801137238740921,
0.058985672891139984,
-0.018379919230937958,
0.028059888631105423,
0.002354925498366356,
0.10359528660774231,
-0.048316363245248795,
-0.00939790066331625,
-3.692925705703606e-34,
0.0035324993077665567,
-0.029775694012641907,
-0.07771016657352448,
0.07498149573802948,
-0.019451694563031197,
0.020411580801010132,
-0.033477745950222015,
0.08641880750656128,
-0.16158412396907806,
-0.038257841020822525,
0.06390596926212311,
0.057300206273794174,
-0.06805595010519028,
0.040568459779024124,
0.05375523120164871,
-0.016255907714366913,
0.03786946088075638,
0.03565245866775513,
0.05105014890432358,
0.05543442815542221,
0.0686725303530693,
0.08280080556869507,
-0.05165359750390053,
-0.006586684845387936,
-0.06853760778903961,
-0.019093526527285576,
-0.009657640010118484,
0.0023265602067112923,
-0.037666864693164825,
0.033783212304115295,
0.026198331266641617,
-0.028096193447709084,
-0.02614644542336464,
0.018198687583208084,
0.0015092206886038184,
-0.06530972570180893,
-0.014425004832446575,
-0.03397350758314133,
-0.06996702402830124,
-0.04506321996450424,
0.03645719587802887,
-0.04859640449285507,
-0.025089683011174202,
-0.07873732596635818,
0.002707453677430749,
-0.07111890614032745,
-0.033574268221855164,
-0.0056929029524326324,
-0.0226467065513134,
-0.043397270143032074,
0.007382568903267384,
0.059920672327280045,
-0.00009111960389418527,
0.00451433751732111,
0.05377788469195366,
-0.03992116078734398,
-0.04627128317952156,
0.05480599030852318,
0.026407292112708092,
-0.024438651278614998,
0.07440148293972015,
0.09699441492557526,
-0.030968796461820602,
0.031403541564941406,
-0.02137795276939869,
0.01366550475358963,
-0.0036878834944218397,
-0.02968181110918522,
0.08819460868835449,
-0.09069234132766724,
-0.05227489396929741,
0.010315976105630398,
-0.07865087687969208,
0.03971467539668083,
0.011544620618224144,
-0.0580940805375576,
-0.003463167930021882,
-0.04704077169299126,
0.08614178746938705,
-0.002211111132055521,
-0.020456884056329727,
-0.02563682571053505,
0.002069395035505295,
0.08362361043691635,
-0.04712237790226936,
0.007641439326107502,
-0.010706739500164986,
-0.029489358887076378,
0.012980940751731396,
0.03604967147111893,
-0.028063183650374413,
-0.05277244746685028,
0.04151367023587227,
-0.15283586084842682,
0.006901596672832966,
-4.063898498511673e-33,
0.008492838591337204,
-0.026672163978219032,
-0.071256123483181,
0.03776007145643234,
-0.017721502110362053,
0.0007259568083100021,
0.00606513163074851,
0.008646249771118164,
0.036098409444093704,
-0.05469156801700592,
-0.01715979538857937,
0.03413398563861847,
-0.027135387063026428,
-0.022294797003269196,
-0.03921873867511749,
-0.04679114744067192,
-0.04443028196692467,
-0.09781157225370407,
0.03560255095362663,
-0.058763980865478516,
-0.002556039020419121,
-0.028080902993679047,
0.0631793662905693,
0.05960962921380997,
0.0202629491686821,
0.04168429970741272,
-0.1290542185306549,
0.03551999852061272,
0.027941174805164337,
0.02251216396689415,
-0.05464762821793556,
0.030670929700136185,
0.01730240136384964,
0.014529095031321049,
0.03265745937824249,
-0.026047473773360252,
-0.017213184386491776,
0.07849393784999847,
-0.04638078808784485,
-0.012266527861356735,
0.03506020829081535,
-0.022256765514612198,
0.02254006266593933,
0.0038546104915440083,
0.03406378999352455,
0.061919718980789185,
0.007940612733364105,
0.018862420693039894,
0.04728591814637184,
-0.004031628370285034,
0.022637899965047836,
-0.09043651074171066,
0.012420760467648506,
0.060524832457304,
0.011152146384119987,
-0.04642526060342789,
0.09963178634643555,
-0.08030416071414948,
0.017158133909106255,
0.03630887344479561,
0.0901324525475502,
-0.10116036981344223,
-0.07339045405387878,
-0.04030364379286766,
-0.010111823678016663,
-0.03410010039806366,
-0.0555575005710125,
0.024489352479577065,
0.03404514491558075,
-0.014855531975626945,
-0.0038798030000180006,
-0.0610104575753212,
0.0071052503772079945,
-0.09790774434804916,
0.01958855427801609,
0.105875663459301,
0.018800705671310425,
-0.023288721218705177,
-0.036839112639427185,
0.04671807587146759,
-0.05739568918943405,
0.03353455290198326,
-0.05368632450699806,
0.007750862743705511,
0.059761159121990204,
-0.024944249540567398,
0.018290290609002113,
-0.03797933831810951,
-0.012921911664307117,
-0.04265487194061279,
0.013933883979916573,
0.08404593914747238,
-0.1320045292377472,
-0.03341498225927353,
-0.07032649964094162,
-4.809433562513732e-8,
-0.044981714338064194,
-0.047502968460321426,
-0.08561140298843384,
-0.05106845870614052,
0.005284355487674475,
-0.10061977058649063,
-0.0385812409222126,
-0.037217877805233,
0.035597655922174454,
-0.002117239637300372,
-0.01575738936662674,
0.058710645884275436,
0.0854332447052002,
-0.05522462725639343,
0.008512954227626324,
-0.06877987831830978,
-0.02813388593494892,
-0.02523900754749775,
-0.04604380577802658,
0.038349658250808716,
0.04147941246628761,
-0.07032451778650284,
-0.01287147868424654,
0.0648241937160492,
-0.07889433950185776,
0.02646534889936447,
0.03904465585947037,
-0.03819644823670387,
0.06652037054300308,
0.02931695058941841,
-0.0037188357673585415,
0.0711960569024086,
0.057468149811029434,
0.08187159150838852,
-0.016131894662976265,
-0.007814458571374416,
-0.02426506020128727,
0.07164458185434341,
-0.024015378206968307,
0.09244195371866226,
0.12747596204280853,
-0.07324063777923584,
-0.09871944040060043,
0.06435506045818329,
0.10675091296434402,
-0.024942349642515182,
0.009955773130059242,
-0.03608230501413345,
0.01380231138318777,
0.03246006742119789,
-0.08872860670089722,
0.13276536762714386,
-0.006363335996866226,
0.05191062018275261,
-0.023008299991488457,
-0.01165754720568657,
-0.0031855779234319925,
-0.03534512594342232,
-0.09355738759040833,
-0.0557815358042717,
0.08044116944074631,
0.024728521704673767,
0.07538209855556488,
0.038118962198495865
] | 0.033573 |
set exclusively for either the `Readable` or `Writable` side using the `readableObjectMode` and `writableObjectMode` options respectively. In the following example, for instance, a new `Transform` stream (which is a type of [`Duplex`][] stream) is created that has an object mode `Writable` side that accepts JavaScript numbers that are converted to hexadecimal strings on the `Readable` side. ```js const { Transform } = require('node:stream'); // All Transform streams are also Duplex Streams. const myTransform = new Transform({ writableObjectMode: true, transform(chunk, encoding, callback) { // Coerce the chunk to a number if necessary. chunk |= 0; // Transform the chunk into something else. const data = chunk.toString(16); // Push the data onto the readable queue. callback(null, '0'.repeat(data.length % 2) + data); }, }); myTransform.setEncoding('ascii'); myTransform.on('data', (chunk) => console.log(chunk)); myTransform.write(1); // Prints: 01 myTransform.write(10); // Prints: 0a myTransform.write(100); // Prints: 64 ``` ### Implementing a transform stream A [`Transform`][] stream is a [`Duplex`][] stream where the output is computed in some way from the input. Examples include [zlib][] streams or [crypto][] streams that compress, encrypt, or decrypt data. There is no requirement that the output be the same size as the input, the same number of chunks, or arrive at the same time. For example, a `Hash` stream will only ever have a single chunk of output which is provided when the input is ended. A `zlib` stream will produce output that is either much smaller or much larger than its input. The `stream.Transform` class is extended to implement a [`Transform`][] stream. The `stream.Transform` class prototypically inherits from `stream.Duplex` and implements its own versions of the `writable.\_write()` and [`readable.\_read()`][] methods. Custom `Transform` implementations \_must\_ implement the [`transform.\_transform()`][stream-\_transform] method and \_may\_ also implement the [`transform.\_flush()`][stream-\_flush] method. Care must be taken when using `Transform` streams in that data written to the stream can cause the `Writable` side of the stream to become paused if the output on the `Readable` side is not consumed. #### `new stream.Transform([options])` \* `options` {Object} Passed to both `Writable` and `Readable` constructors. Also has the following fields: \* `transform` {Function} Implementation for the [`stream.\_transform()`][stream-\_transform] method. \* `flush` {Function} Implementation for the [`stream.\_flush()`][stream-\_flush] method. ```js const { Transform } = require('node:stream'); class MyTransform extends Transform { constructor(options) { super(options); // ... } } ``` Or, when using pre-ES6 style constructors: ```js const { Transform } = require('node:stream'); const util = require('node:util'); function MyTransform(options) { if (!(this instanceof MyTransform)) return new MyTransform(options); Transform.call(this, options); } util.inherits(MyTransform, Transform); ``` Or, using the simplified constructor approach: ```js const { Transform } = require('node:stream'); const myTransform = new Transform({ transform(chunk, encoding, callback) { // ... }, }); ``` #### Event: `'end'` The [`'end'`][] event is from the `stream.Readable` class. The `'end'` event is emitted after all data has been output, which occurs after the callback in [`transform.\_flush()`][stream-\_flush] has been called. In the case of an error, `'end'` should not be emitted. #### Event: `'finish'` The [`'finish'`][] event is from the `stream.Writable` class. The `'finish'` event is emitted after [`stream.end()`][stream-end] is called and all chunks have been processed by [`stream.\_transform()`][stream-\_transform]. In the case of an error, `'finish'` should not be emitted. #### `transform.\_flush(callback)` \* `callback` {Function} A callback function (optionally with an error argument and data) to be called when remaining data has been flushed. This function MUST NOT be called by application code directly. It should be implemented by child classes, and called by the internal `Readable` class methods only. In some cases, a transform operation may need to emit an additional bit of data at the end of the stream. For example, a `zlib` compression stream will store an amount of internal state used to | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.0440545454621315,
0.0042700013145804405,
-0.0603952519595623,
0.020032158121466637,
-0.10746443271636963,
0.033358242362737656,
-0.025234278291463852,
0.027898306027054787,
-0.0010996157070621848,
-0.05750473961234093,
-0.08815278112888336,
0.04641178250312805,
-0.05845232680439949,
0.04599160701036453,
0.0024442386347800493,
-0.08268138021230698,
-0.008847353979945183,
0.0680336058139801,
-0.027432095259428024,
-0.03514055162668228,
0.09431907534599304,
-0.026465028524398804,
-0.013414308428764343,
-0.05731378495693207,
0.08630108833312988,
0.04670559987425804,
-0.029956799000501633,
-0.02609524317085743,
0.08081977069377899,
-0.0508318729698658,
0.028171546757221222,
-0.06162838265299797,
-0.07179395109415054,
-0.04116038978099823,
-0.028442686423659325,
0.060065463185310364,
-0.02901287190616131,
-0.1090589240193367,
-0.01543854083865881,
0.00048675324069336057,
0.13942007720470428,
0.07039864361286163,
-0.05847914144396782,
0.0039206016808748245,
-0.0015573773998767138,
-0.01670520193874836,
-0.050450537353754044,
-0.0074364361353218555,
-0.03805043548345566,
0.0774509459733963,
0.005520360544323921,
0.012469449080526829,
-0.03017517738044262,
0.10168128460645676,
-0.010477688163518906,
0.003484910586848855,
-0.052686817944049835,
0.021919604390859604,
0.03722309693694115,
-0.024268601089715958,
-0.06839016079902649,
0.014831876382231712,
0.1008671298623085,
-0.012021469883620739,
0.01997462287545204,
0.026464160531759262,
0.017718343064188957,
0.05140277370810509,
-0.010265897028148174,
0.03617146238684654,
0.02537686936557293,
0.05672582611441612,
0.027192139998078346,
0.05404360964894295,
-0.024153923615813255,
-0.07595253735780716,
-0.03563084080815315,
0.010792724788188934,
-0.02582160197198391,
0.06931833922863007,
-0.0375744067132473,
-0.07668066769838333,
0.038061466068029404,
0.057408977299928665,
-0.03273162990808487,
0.07756650447845459,
-0.015578721649944782,
0.041324105113744736,
0.0041841911152005196,
0.04938821867108345,
-0.11629534512758255,
0.042159952223300934,
0.05232447013258934,
0.022363094612956047,
-0.01201243232935667,
0.05496180057525635,
0.04247685894370079,
0.05859515815973282,
0.022985724732279778,
-0.03375919535756111,
0.04254385828971863,
0.016365086659789085,
0.04921838268637657,
0.03227347508072853,
-0.02234671451151371,
-0.1132199615240097,
0.018515808507800102,
0.0010697911493480206,
-0.04153360053896904,
0.006790316663682461,
0.0127590112388134,
0.0959000512957573,
0.04080449044704437,
-0.0470944344997406,
0.0066390568390488625,
0.02259410358965397,
-0.012312297709286213,
-0.0426933653652668,
0.029276283457875252,
0.09857859462499619,
0.027102194726467133,
-0.022202108055353165,
-0.0730079710483551,
0.06604752689599991,
0.09846699237823486,
-0.02214748039841652,
0.07098858803510666,
1.300714070214624e-33,
-0.017625421285629272,
-0.0156097412109375,
0.011047087609767914,
0.04947025701403618,
-0.004410110879689455,
0.03403545543551445,
-0.004899631720036268,
0.009794731624424458,
-0.09809041023254395,
-0.03648747503757477,
-0.038295794278383255,
0.06578338891267776,
-0.010124602355062962,
0.015260657295584679,
-0.053138621151447296,
-0.07020501047372818,
0.06269749253988266,
-0.0009764063288457692,
0.03971581906080246,
0.01075300294905901,
0.06958416104316711,
0.024387361481785774,
-0.047980304807424545,
0.0189359150826931,
-0.045771218836307526,
-0.025490062311291695,
-0.035265274345874786,
0.013599543832242489,
-0.014530188404023647,
-0.003254898823797703,
-0.00786628108471632,
0.027856845408678055,
-0.061602480709552765,
0.014066621661186218,
0.05524248257279396,
-0.08810094743967056,
0.0067483349703252316,
-0.003238387405872345,
-0.07138901203870773,
0.007398152258247137,
0.0681724101305008,
0.009590277448296547,
-0.08734558522701263,
-0.04350549355149269,
-0.03673159331083298,
-0.006063826847821474,
0.03652473911643028,
-0.035602569580078125,
0.02659011259675026,
-0.07978173345327377,
-0.01094298716634512,
0.08882921189069748,
-0.02923142910003662,
-0.08154628425836563,
0.05333254113793373,
-0.028786880895495415,
0.07218768447637558,
-0.00728441821411252,
-0.00539240799844265,
0.044560451060533524,
0.007763178553432226,
0.13298942148685455,
0.04248316213488579,
0.02082804962992668,
0.013215390034019947,
0.012654736638069153,
-0.008294664323329926,
-0.062217019498348236,
-0.013933208771049976,
-0.12094910442829132,
-0.07270235568284988,
-0.023780370131134987,
-0.0036559095606207848,
0.05039834603667259,
-0.018724555149674416,
-0.008614921011030674,
-0.04539050906896591,
-0.03345710411667824,
-0.010510259307920933,
-0.045248012989759445,
-0.004880462773144245,
0.030420424416661263,
0.010319613851606846,
0.05022582784295082,
0.03805287182331085,
-0.012090694159269333,
-0.06603126227855682,
-0.09104103595018387,
0.01057788822799921,
0.03346172720193863,
0.02723311260342598,
-0.03048144467175007,
0.021777810528874397,
-0.14210598170757294,
0.0030947518534958363,
-2.3581467275571135e-33,
-0.059832118451595306,
-0.022951800376176834,
-0.07150108367204666,
0.12726634740829468,
-0.05930713936686516,
-0.015415679663419724,
0.014916704036295414,
0.11025337129831314,
0.14934790134429932,
0.010536879301071167,
-0.0035788915120065212,
0.011226442642509937,
-0.10088799893856049,
-0.05586051195859909,
-0.04264584928750992,
-0.05842867121100426,
-0.058059051632881165,
-0.03158274292945862,
0.010892268270254135,
-0.07271983474493027,
0.027971351519227028,
0.005967034492641687,
-0.005943777970969677,
0.09134611487388611,
-0.003974728286266327,
0.07756299525499344,
-0.0667046457529068,
0.036294810473918915,
0.040334492921829224,
-0.0436319038271904,
-0.06351019442081451,
-0.021844318136572838,
-0.00132111762650311,
-0.016585679724812508,
-0.051214996725320816,
-0.0866108387708664,
0.004886852111667395,
0.12309928238391876,
-0.013509148731827736,
0.01836441643536091,
0.012128975242376328,
-0.026018911972641945,
-0.03644424304366112,
0.020509496331214905,
0.04636666178703308,
0.013205192051827908,
-0.023568954318761826,
0.0073613449931144714,
0.017824620008468628,
0.047785788774490356,
0.01151302084326744,
0.009724529460072517,
-0.07139579206705093,
0.06633906066417694,
0.02299933321774006,
-0.04708714410662651,
0.043066903948783875,
-0.0964847058057785,
0.03824920952320099,
0.009926573373377323,
0.018402811139822006,
-0.08290478587150574,
0.053367841988801956,
-0.06485211849212646,
0.07680250704288483,
-0.0016262249555438757,
-0.007050154730677605,
-0.06367883831262589,
0.06999527662992477,
0.02974989265203476,
0.006761675234884024,
-0.06534560024738312,
0.07930885255336761,
-0.02798404172062874,
0.06539411842823029,
-0.060830410569906235,
-0.013561354950070381,
-0.0287085622549057,
0.01698431558907032,
0.05863288417458534,
0.0027470302302390337,
0.05782869830727577,
-0.020969925448298454,
0.06839179247617722,
0.0850873664021492,
0.025424232706427574,
0.002649302827194333,
-0.042003609240055084,
-0.003990336786955595,
-0.0021131541579961777,
-0.03728820011019707,
0.037008386105298996,
-0.09720032662153244,
-0.013113223016262054,
-0.07275219261646271,
-4.9676465607717546e-8,
-0.07787223160266876,
-0.04335929825901985,
-0.14239850640296936,
0.04577859118580818,
-0.0010548350401222706,
-0.06662164628505707,
-0.07594503462314606,
-0.035939496010541916,
0.07895215600728989,
-0.02106359414756298,
0.024537425488233566,
-0.04414279758930206,
0.02126462198793888,
-0.065973661839962,
0.04200407490134239,
-0.010786011815071106,
0.08509376645088196,
-0.01944357343018055,
-0.03158515691757202,
0.02591569535434246,
-0.004168480169028044,
0.026707423850893974,
-0.06437647342681885,
0.0417182594537735,
0.04762446880340576,
-0.0013833226403221488,
0.02896067500114441,
0.05960989370942116,
0.0555514357984066,
0.013888908550143242,
-0.07006623595952988,
0.03185465186834335,
0.09027660638093948,
0.06605526059865952,
-0.1028069332242012,
-0.023692036047577858,
0.05425653234124184,
0.08165662735700607,
0.049379412084817886,
0.036731839179992676,
0.13349899649620056,
0.009348518215119839,
-0.08962821215391159,
0.0646776556968689,
-0.004420415498316288,
-0.014268568716943264,
0.011178587563335896,
0.03536895290017128,
0.030463464558124542,
-0.006183667108416557,
-0.010148338973522186,
0.007655569817870855,
-0.019797269254922867,
0.0027888815384358168,
-0.006361686158925295,
-0.0629035234451294,
0.0029773504938930273,
-0.07123342901468277,
-0.03549274429678917,
0.0679607093334198,
0.04644951596856117,
-0.02308688312768936,
0.010387040674686432,
-0.019644251093268394
] | 0.06429 |
be implemented by child classes, and called by the internal `Readable` class methods only. In some cases, a transform operation may need to emit an additional bit of data at the end of the stream. For example, a `zlib` compression stream will store an amount of internal state used to optimally compress the output. When the stream ends, however, that additional data needs to be flushed so that the compressed data will be complete. Custom [`Transform`][] implementations \_may\_ implement the `transform.\_flush()` method. This will be called when there is no more written data to be consumed, but before the [`'end'`][] event is emitted signaling the end of the [`Readable`][] stream. Within the `transform.\_flush()` implementation, the `transform.push()` method may be called zero or more times, as appropriate. The `callback` function must be called when the flush operation is complete. The `transform.\_flush()` method is prefixed with an underscore because it is internal to the class that defines it, and should never be called directly by user programs. #### `transform.\_transform(chunk, encoding, callback)` \* `chunk` {Buffer|string|any} The `Buffer` to be transformed, converted from the `string` passed to [`stream.write()`][stream-write]. If the stream's `decodeStrings` option is `false` or the stream is operating in object mode, the chunk will not be converted & will be whatever was passed to [`stream.write()`][stream-write]. \* `encoding` {string} If the chunk is a string, then this is the encoding type. If chunk is a buffer, then this is the special value `'buffer'`. Ignore it in that case. \* `callback` {Function} A callback function (optionally with an error argument and data) to be called after the supplied `chunk` has been processed. This function MUST NOT be called by application code directly. It should be implemented by child classes, and called by the internal `Readable` class methods only. All `Transform` stream implementations must provide a `\_transform()` method to accept input and produce output. The `transform.\_transform()` implementation handles the bytes being written, computes an output, then passes that output off to the readable portion using the `transform.push()` method. The `transform.push()` method may be called zero or more times to generate output from a single input chunk, depending on how much is to be output as a result of the chunk. It is possible that no output is generated from any given chunk of input data. The `callback` function must be called only when the current chunk is completely consumed. The first argument passed to the `callback` must be an `Error` object if an error occurred while processing the input or `null` otherwise. If a second argument is passed to the `callback`, it will be forwarded on to the `transform.push()` method, but only if the first argument is falsy. In other words, the following are equivalent: ```js transform.prototype.\_transform = function(data, encoding, callback) { this.push(data); callback(); }; transform.prototype.\_transform = function(data, encoding, callback) { callback(null, data); }; ``` The `transform.\_transform()` method is prefixed with an underscore because it is internal to the class that defines it, and should never be called directly by user programs. `transform.\_transform()` is never called in parallel; streams implement a queue mechanism, and to receive the next chunk, `callback` must be called, either synchronously or asynchronously. #### Class: `stream.PassThrough` The `stream.PassThrough` class is a trivial implementation of a [`Transform`][] stream that simply passes the input bytes across to the output. Its purpose is primarily for examples and testing, but there are some use cases where `stream.PassThrough` is useful as a building block for novel sorts of streams. ## Additional notes ### Streams compatibility with async generators and async iterators With the support of async generators and iterators in JavaScript, async generators are effectively a | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.13822542130947113,
0.07427546381950378,
-0.02742253988981247,
0.03218567371368408,
-0.056335385888814926,
-0.10595734417438507,
-0.042201150208711624,
0.03396352007985115,
0.021868722513318062,
-0.02420056238770485,
-0.02511165849864483,
0.10345679521560669,
-0.011726956814527512,
-0.020618557929992676,
-0.02439800649881363,
-0.021335959434509277,
-0.07031349092721939,
0.03374433517456055,
-0.11593541502952576,
-0.08006748557090759,
0.07112976908683777,
0.04565443471074104,
-0.030306460335850716,
0.047084931284189224,
0.024315573275089264,
-0.014121044427156448,
-0.02323879860341549,
-0.04892838001251221,
0.07747931033372879,
0.008232401683926582,
-0.0037120541092008352,
0.007158682215958834,
-0.030078759416937828,
0.006223354022949934,
-0.04845178499817848,
0.11261262744665146,
0.07333884388208389,
-0.0741390660405159,
-0.0930401161313057,
-0.007684500887989998,
0.06686511635780334,
0.022209040820598602,
-0.08897049725055695,
0.06331483274698257,
-0.0776810273528099,
0.07442619651556015,
0.02936716005206108,
-0.061623409390449524,
-0.12800447642803192,
-0.03121871128678322,
-0.013088290579617023,
0.036150701344013214,
-0.04886994883418083,
0.1451369673013687,
-0.019599363207817078,
-0.016371838748455048,
0.03299683332443237,
-0.05203825980424881,
-0.05100726708769798,
-0.04887763783335686,
-0.13258126378059387,
0.04616769030690193,
-0.08043346554040909,
0.026827307417988777,
-0.04140330106019974,
0.013497745618224144,
0.05610718950629234,
0.002929129870608449,
0.07190413773059845,
-0.019489392638206482,
-0.08558505773544312,
-0.0000748276652302593,
-0.06767639517784119,
0.08176805824041367,
0.020856592804193497,
-0.12519575655460358,
0.03636801242828369,
-0.0035390518605709076,
-0.0475742444396019,
-0.03251028060913086,
0.06440753489732742,
-0.0623103566467762,
0.09775419533252716,
0.04142489284276962,
0.07532180100679398,
0.03684747964143753,
-0.04795930162072182,
0.0020778714679181576,
0.025197535753250122,
0.03802300989627838,
-0.048933256417512894,
0.015378250740468502,
0.030696112662553787,
0.07457861304283142,
-0.015864524990320206,
0.011327662505209446,
0.1105191558599472,
-0.0368431992828846,
-0.035368699580430984,
0.08027570694684982,
0.019306153059005737,
0.029566926881670952,
0.04039192944765091,
-0.03939124196767807,
0.021741874516010284,
-0.06854303926229477,
-0.00046381945139728487,
0.019369125366210938,
-0.07176411896944046,
-0.015486630611121655,
0.026776574552059174,
-0.055914025753736496,
0.0026076477952301502,
-0.06762820482254028,
0.033091168850660324,
0.05312627926468849,
-0.0631503239274025,
0.07254165410995483,
-0.021916477009654045,
0.0838410034775734,
0.08178303390741348,
0.03835441544651985,
-0.073826365172863,
0.012923670932650566,
0.03453059494495392,
0.04213539510965347,
-0.05265873298048973,
6.78111512838432e-34,
-0.0627870112657547,
-0.04340646043419838,
-0.0671805888414383,
0.08620699495077133,
-0.07555830478668213,
0.09554890543222427,
0.057819608598947525,
0.032502058893442154,
-0.02454891800880432,
0.013172187842428684,
-0.008821263909339905,
0.05311785638332367,
-0.02585785463452339,
0.06556256860494614,
-0.01344302948564291,
-0.048669297248125076,
0.06026716157793999,
0.09149868786334991,
-0.0005563174490816891,
0.04814007505774498,
0.10679484903812408,
0.09174909442663193,
-0.03989782929420471,
-0.02545374631881714,
-0.00629676366224885,
0.05036472901701927,
-0.05709049105644226,
-0.03137883543968201,
-0.04228559881448746,
0.02811186946928501,
-0.045384060591459274,
0.020650580525398254,
-0.008766268379986286,
-0.060685254633426666,
0.012837192043662071,
-0.04998656362295151,
0.023951148614287376,
-0.07154064625501633,
-0.0672580748796463,
-0.13780952990055084,
-0.021240554749965668,
0.0012585633667185903,
-0.10724712908267975,
-0.011274975724518299,
-0.044274114072322845,
-0.08827187120914459,
-0.013494334183633327,
0.05416775494813919,
0.010319456458091736,
-0.01430870033800602,
0.03393004462122917,
0.09154168516397476,
-0.03856914862990379,
0.033609721809625626,
-0.001137420767918229,
-0.014935453422367573,
0.04243776202201843,
0.010154914110898972,
-0.01057672593742609,
-0.016219362616539,
-0.003683235263451934,
0.07684075087308884,
0.010493033565580845,
0.021494485437870026,
0.020363114774227142,
0.013956946320831776,
-0.0024071100633591413,
0.007756786420941353,
0.09690988063812256,
-0.026065025478601456,
-0.07839030772447586,
0.05113440379500389,
-0.11076780408620834,
0.03953281417489052,
0.011987466365098953,
-0.003430101089179516,
-0.005171727854758501,
-0.05785806477069855,
-0.011864345520734787,
-0.013587313704192638,
-0.0026477838400751352,
0.013073114678263664,
0.02798589877784252,
0.012487681582570076,
0.024238934740424156,
-0.03931255638599396,
0.011796465143561363,
-0.008434166200459003,
-0.07902608811855316,
-0.02104293182492256,
-0.03513883426785469,
-0.047826994210481644,
0.06378880143165588,
-0.05375150218605995,
-0.013282409869134426,
-3.369849164903762e-33,
0.07444721460342407,
0.033242885023355484,
-0.12004351615905762,
0.07162102311849594,
-0.046156302094459534,
-0.03369716927409172,
0.023254629224538803,
0.021246645599603653,
0.0031708835158497095,
-0.05194096639752388,
-0.030156370252370834,
0.019490813836455345,
-0.031130118295550346,
-0.012466531246900558,
0.03803963214159012,
0.023291965946555138,
-0.06608497351408005,
-0.10358542948961258,
-0.0004771375679410994,
-0.019895445555448532,
-0.01706688292324543,
0.0019312244839966297,
0.007318195886909962,
0.01852957345545292,
-0.06504406780004501,
-0.020385801792144775,
-0.08633457869291306,
0.013109385035932064,
0.08045779913663864,
0.03461376577615738,
-0.007935427129268646,
-0.005212024319916964,
-0.042027197778224945,
-0.047529786825180054,
-0.046629708260297775,
-0.01720474846661091,
-0.030794547870755196,
0.0674632266163826,
-0.02021840773522854,
0.013040479272603989,
0.13379736244678497,
0.013164864853024483,
-0.006655300967395306,
0.04909602925181389,
0.010478823445737362,
0.007202852517366409,
-0.062302544713020325,
-0.01322640385478735,
0.006632487289607525,
0.0028009417001158,
0.020160455256700516,
0.011510510928928852,
0.01031876914203167,
0.06522268056869507,
0.06033477187156677,
-0.007687510922551155,
0.06139600649476051,
-0.030163371935486794,
-0.04497942700982094,
-0.014842712320387363,
-0.002731449669227004,
-0.061263952404260635,
0.014606968499720097,
-0.07985762506723404,
-0.03343383967876434,
-0.0028978462796658278,
-0.01145305298268795,
-0.035655293613672256,
0.06661848723888397,
0.004475190304219723,
0.05068846791982651,
0.02297145314514637,
0.015474717132747173,
-0.058648284524679184,
-0.020859122276306152,
0.06606598198413849,
0.030867408961057663,
-0.022860398516058922,
-0.019545655697584152,
0.07022987306118011,
-0.0960366502404213,
0.02735135145485401,
0.024883875623345375,
0.0681358352303505,
-0.032714344561100006,
-0.1011372059583664,
0.05759275332093239,
-0.010800065472722054,
0.04208359122276306,
-0.0360649935901165,
0.005058910697698593,
0.08121168613433838,
-0.08893632888793945,
0.05065634101629257,
-0.026006098836660385,
-6.016936993091804e-8,
-0.035212691873311996,
-0.06127944961190224,
0.017294632270932198,
0.03823244199156761,
-0.000466466968646273,
-0.02208045870065689,
-0.0019224992720410228,
0.04807967692613602,
-0.0196804478764534,
-0.0381682813167572,
0.03551281616091728,
-0.014120501466095448,
0.08217820525169373,
-0.03681641444563866,
0.034759294241666794,
0.02897142618894577,
0.0003761276020668447,
-0.022650746628642082,
-0.046629730612039566,
0.0014497401425614953,
-0.012646538205444813,
-0.023204458877444267,
-0.05855846405029297,
0.052485495805740356,
-0.043864451348781586,
-0.01452118344604969,
0.026826292276382446,
0.05651051923632622,
-0.019642701372504234,
-0.04810918867588043,
0.06900490820407867,
0.03969484567642212,
0.08965659141540527,
0.0554986298084259,
-0.043668556958436966,
0.06556381285190582,
0.07654185593128204,
0.022426646202802658,
0.03287220001220703,
0.05072612315416336,
0.014260069467127323,
-0.034238193184137344,
-0.06621897220611572,
0.043197374790906906,
0.008161108009517193,
-0.02843794971704483,
-0.01220504567027092,
0.015848729759454727,
-0.013521517626941204,
0.1141723021864891,
-0.012509970925748348,
0.05311625823378563,
-0.0867876261472702,
0.033534061163663864,
0.07467302680015564,
-0.006140921264886856,
-0.027549635618925095,
-0.04854457452893257,
-0.025683900341391563,
0.05616248399019241,
-0.004097972065210342,
0.042600877583026886,
0.0234735906124115,
-0.005003469530493021
] | 0.148227 |
for examples and testing, but there are some use cases where `stream.PassThrough` is useful as a building block for novel sorts of streams. ## Additional notes ### Streams compatibility with async generators and async iterators With the support of async generators and iterators in JavaScript, async generators are effectively a first-class language-level stream construct at this point. Some common interop cases of using Node.js streams with async generators and async iterators are provided below. #### Consuming readable streams with async iterators ```js (async function() { for await (const chunk of readable) { console.log(chunk); } })(); ``` Async iterators register a permanent error handler on the stream to prevent any unhandled post-destroy errors. #### Creating readable streams with async generators A Node.js readable stream can be created from an asynchronous generator using the `Readable.from()` utility method: ```js const { Readable } = require('node:stream'); const ac = new AbortController(); const signal = ac.signal; async function \* generate() { yield 'a'; await someLongRunningFn({ signal }); yield 'b'; yield 'c'; } const readable = Readable.from(generate()); readable.on('close', () => { ac.abort(); }); readable.on('data', (chunk) => { console.log(chunk); }); ``` #### Piping to writable streams from async iterators When writing to a writable stream from an async iterator, ensure correct handling of backpressure and errors. [`stream.pipeline()`][] abstracts away the handling of backpressure and backpressure-related errors: ```js const fs = require('node:fs'); const { pipeline } = require('node:stream'); const { pipeline: pipelinePromise } = require('node:stream/promises'); const writable = fs.createWriteStream('./file'); const ac = new AbortController(); const signal = ac.signal; const iterator = createIterator({ signal }); // Callback Pattern pipeline(iterator, writable, (err, value) => { if (err) { console.error(err); } else { console.log(value, 'value returned'); } }).on('close', () => { ac.abort(); }); // Promise Pattern pipelinePromise(iterator, writable) .then((value) => { console.log(value, 'value returned'); }) .catch((err) => { console.error(err); ac.abort(); }); ``` ### Compatibility with older Node.js versions Prior to Node.js 0.10, the `Readable` stream interface was simpler, but also less powerful and less useful. \* Rather than waiting for calls to the [`stream.read()`][stream-read] method, [`'data'`][] events would begin emitting immediately. Applications that would need to perform some amount of work to decide how to handle data were required to store read data into buffers so the data would not be lost. \* The [`stream.pause()`][stream-pause] method was advisory, rather than guaranteed. This meant that it was still necessary to be prepared to receive [`'data'`][] events \_even when the stream was in a paused state\_. In Node.js 0.10, the [`Readable`][] class was added. For backward compatibility with older Node.js programs, `Readable` streams switch into "flowing mode" when a [`'data'`][] event handler is added, or when the [`stream.resume()`][stream-resume] method is called. The effect is that, even when not using the new [`stream.read()`][stream-read] method and [`'readable'`][] event, it is no longer necessary to worry about losing [`'data'`][] chunks. While most applications will continue to function normally, this introduces an edge case in the following conditions: \* No [`'data'`][] event listener is added. \* The [`stream.resume()`][stream-resume] method is never called. \* The stream is not piped to any writable destination. For example, consider the following code: ```js // WARNING! BROKEN! net.createServer((socket) => { // We add an 'end' listener, but never consume the data. socket.on('end', () => { // It will never get here. socket.end('The message was received but was not processed.\n'); }); }).listen(1337); ``` Prior to Node.js 0.10, the incoming message data would be simply discarded. However, in Node.js 0.10 and beyond, the socket remains paused forever. The workaround in this situation is to call the [`stream.resume()`][stream-resume] method to begin the flow of data: ```js // Workaround. net.createServer((socket) => { socket.on('end', () => { | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.11197518557310104,
0.008929313160479069,
-0.04857314005494118,
0.08719390630722046,
0.0547308623790741,
-0.02977711707353592,
-0.0517137311398983,
0.032658226788043976,
0.01751670613884926,
-0.08562050014734268,
-0.07313267141580582,
0.059362009167671204,
-0.07223998755216599,
-0.013833305798470974,
0.007230496034026146,
-0.033878687769174576,
-0.012612857855856419,
0.05944055691361427,
-0.023006949573755264,
-0.09936074912548065,
0.01327454298734665,
-0.05596555396914482,
-0.020887019112706184,
0.013410059735178947,
-0.008170027285814285,
-0.006250810343772173,
-0.06525080651044846,
-0.08667946606874466,
0.06500636041164398,
-0.007617176044732332,
0.041027870029211044,
-0.09559319168329239,
-0.12162869423627853,
0.025666143745183945,
-0.12448262423276901,
0.1126127541065216,
0.027677437290549278,
-0.06902052462100983,
-0.031585775315761566,
-0.01981612667441368,
0.08426659554243088,
0.07565630972385406,
-0.09672113507986069,
-0.029050055891275406,
0.012801073491573334,
-0.015892306342720985,
-0.07620090991258621,
-0.02388647198677063,
-0.09920141100883484,
0.03316471725702286,
-0.08148346096277237,
0.01544478815048933,
-0.03659326583147049,
0.05386783927679062,
-0.03566394001245499,
-0.010011146776378155,
-0.015353080816566944,
0.025534039363265038,
-0.002178552094846964,
0.03408578038215637,
-0.018272140994668007,
-0.07968654483556747,
0.004033223260194063,
0.004866961855441332,
0.05795978382229805,
-0.031058238819241524,
-0.005523361265659332,
0.07233503460884094,
0.10094089806079865,
0.01992424950003624,
-0.027776051312685013,
0.04123464971780777,
-0.004025047644972801,
0.018448099493980408,
-0.03634357824921608,
-0.0699516236782074,
0.056596916168928146,
0.04022004082798958,
-0.05416196957230568,
0.06007318198680878,
-0.050532080233097076,
-0.00659966142848134,
0.006488935090601444,
-0.04219489172101021,
-0.024307692423462868,
0.10905732214450836,
-0.018269436433911324,
0.013956987299025059,
0.014921525493264198,
0.042602501809597015,
-0.09729114174842834,
0.003938683774322271,
-0.04202912747859955,
0.04765263944864273,
0.057772643864154816,
0.08732292801141739,
0.06808936595916748,
0.006391050294041634,
-0.02346954494714737,
-0.04431574419140816,
-0.007134128361940384,
0.054454874247312546,
0.05907393619418144,
-0.016668502241373062,
0.04825686290860176,
-0.09033438563346863,
-0.010373516008257866,
-0.005397271364927292,
-0.001958788139745593,
-0.047360967844724655,
-0.02547593228518963,
0.06126048043370247,
0.007650141604244709,
-0.005254934076219797,
-0.0314958319067955,
-0.005653442814946175,
-0.00368057400919497,
-0.08216314762830734,
0.13403047621250153,
0.15450672805309296,
0.10361697524785995,
0.05443483963608742,
0.002655814867466688,
0.029145218431949615,
0.09414150565862656,
-0.008022849448025227,
0.038783036172389984,
8.878712339220224e-33,
-0.014502977952361107,
-0.04437572881579399,
-0.000801466463599354,
0.08340197056531906,
-0.0002656166616361588,
-0.015128009021282196,
0.04427666962146759,
-0.029416901990771294,
-0.07462364435195923,
-0.025210915133357048,
-0.006538987625390291,
-0.028098110109567642,
-0.021256988868117332,
0.00392384035512805,
0.034797511994838715,
-0.09201762825250626,
0.03274446353316307,
-0.05738270655274391,
0.022403214126825333,
0.022126976400613785,
0.03888818621635437,
-0.012844323180615902,
-0.0006842631264589727,
-0.010871010832488537,
-0.015897277742624283,
-0.053620144724845886,
-0.015365089289844036,
0.03199320286512375,
-0.059289515018463135,
0.023212922737002373,
0.019173944368958473,
0.0015121549367904663,
-0.08359746634960175,
0.03623935207724571,
0.03429001569747925,
-0.04667722061276436,
-0.0017911987379193306,
-0.04724111407995224,
-0.054680947214365005,
-0.010868938639760017,
-0.022284025326371193,
0.011282237246632576,
-0.03943246230483055,
-0.003491421928629279,
-0.09565968811511993,
-0.08118676394224167,
-0.027386168017983437,
-0.01699058711528778,
0.01687706634402275,
-0.028905684128403664,
-0.028979212045669556,
0.09663321822881699,
0.005194473545998335,
-0.037931766360998154,
0.11784230917692184,
0.011934395879507065,
0.027704499661922455,
-0.0427849143743515,
-0.0014341255882754922,
0.08659888058900833,
0.08163511753082275,
0.012222490273416042,
-0.03776552900671959,
0.04097496718168259,
-0.0016205130377784371,
-0.003182806773111224,
-0.02695521153509617,
0.0039029663894325495,
0.033968035131692886,
-0.06699245423078537,
-0.054808683693408966,
-0.027025099843740463,
-0.06493599712848663,
0.04512304812669754,
0.02838214300572872,
0.03568036109209061,
-0.04641451686620712,
-0.025369325652718544,
0.029849901795387268,
-0.05308673530817032,
0.011319548822939396,
0.021923217922449112,
-0.0220929104834795,
0.16177049279212952,
-0.0011879511876031756,
0.04558674618601799,
-0.01938430778682232,
-0.06009147688746452,
0.058316681534051895,
-0.014532550238072872,
-0.01630568690598011,
-0.030034182593226433,
0.08942851424217224,
-0.14137011766433716,
-0.0002074549556709826,
-1.0407841675859919e-32,
-0.025813249871134758,
-0.03524843603372574,
-0.0828431099653244,
0.08594202995300293,
0.019857952371239662,
0.002446431200951338,
-0.012326611205935478,
-0.022048862650990486,
0.06860845535993576,
0.032632820308208466,
-0.102725550532341,
0.06995640695095062,
-0.05510011687874794,
0.017337815836071968,
0.00005773599696112797,
-0.021254800260066986,
0.022971993312239647,
-0.10589597374200821,
0.06869319081306458,
-0.06232183054089546,
-0.020473193377256393,
-0.022603482007980347,
0.047469448298215866,
-0.026945319026708603,
-0.024041639640927315,
0.021956326439976692,
-0.02544030174612999,
0.018786652013659477,
-0.021339176222682,
-0.04572213068604469,
-0.00981263816356659,
0.023910293355584145,
0.032837625592947006,
0.00604124553501606,
0.054618533700704575,
-0.018409429118037224,
0.03222686052322388,
0.07748031616210938,
-0.02444298565387726,
-0.02908647432923317,
0.06921491771936417,
-0.007243779022246599,
0.01991507224738598,
-0.04331709444522858,
0.03446650505065918,
0.018323374912142754,
-0.06390830874443054,
0.02963913604617119,
-0.04792046546936035,
0.04548099264502525,
-0.004043736029416323,
-0.0017356394091621041,
-0.0434887558221817,
0.028037048876285553,
-0.03134264796972275,
-0.07269677519798279,
0.05004993826150894,
0.005328739527612925,
0.07790655642747879,
-0.013323694467544556,
-0.01196556631475687,
-0.06664404273033142,
0.006794857792556286,
-0.07601665705442429,
0.0040100193582475185,
-0.05092290788888931,
-0.03363894671201706,
-0.05071708932518959,
0.04119566082954407,
0.05000859498977661,
0.025944503024220467,
-0.044225241988897324,
-0.025506623089313507,
0.01047458779066801,
0.019363531842827797,
-0.0341583751142025,
-0.028932858258485794,
-0.07316778600215912,
0.0006292912876233459,
0.05104559659957886,
-0.0162140391767025,
0.09443928301334381,
-0.00741287088021636,
0.04468594118952751,
0.10750146210193634,
0.001747178379446268,
0.06677435338497162,
-0.05512946471571922,
-0.02520187944173813,
-0.032346874475479126,
0.07898294180631638,
-0.015073190443217754,
-0.13974308967590332,
0.04659592732787132,
-0.010534967295825481,
-5.235711597606496e-8,
-0.04273148253560066,
-0.022818677127361298,
-0.09177201986312866,
0.010987699963152409,
-0.0002581220760475844,
-0.020527878776192665,
-0.004656427074223757,
0.004831455182284117,
0.06206230819225311,
-0.0012350539909675717,
-0.022711150348186493,
-0.04218582436442375,
0.1423095315694809,
-0.06619669497013092,
0.008198373951017857,
-0.0031874491833150387,
0.0521634966135025,
0.007622701581567526,
-0.011554688215255737,
0.017177116125822067,
-0.0061027370393276215,
0.03487906605005264,
-0.08567312359809875,
0.038821667432785034,
0.006545651704072952,
0.03706294670701027,
0.1193665936589241,
0.039221297949552536,
0.03964652121067047,
-0.07086621969938278,
-0.04429164528846741,
0.09900898486375809,
0.05838298797607422,
0.028195705264806747,
-0.00707177584990859,
0.013554844073951244,
0.021960502490401268,
0.006648713257163763,
0.010446838103234768,
0.07577085494995117,
0.06399157643318176,
0.004465134814381599,
0.009840143844485283,
0.05196442827582359,
-0.06511412560939789,
-0.001976810395717621,
-0.020567620173096657,
-0.0293705016374588,
-0.02160736173391342,
0.04034500569105148,
0.004189212340861559,
-0.007238190621137619,
-0.03731998801231384,
0.056653790175914764,
0.022270288318395615,
-0.04442428797483444,
-0.003417395520955324,
-0.16360723972320557,
-0.06446187198162079,
0.010427971370518208,
0.056214217096567154,
0.055254172533750534,
0.05685583874583244,
0.010407956317067146
] | 0.095874 |
Prior to Node.js 0.10, the incoming message data would be simply discarded. However, in Node.js 0.10 and beyond, the socket remains paused forever. The workaround in this situation is to call the [`stream.resume()`][stream-resume] method to begin the flow of data: ```js // Workaround. net.createServer((socket) => { socket.on('end', () => { socket.end('The message was received but was not processed.\n'); }); // Start the flow of data, discarding it. socket.resume(); }).listen(1337); ``` In addition to new `Readable` streams switching into flowing mode, pre-0.10 style streams can be wrapped in a `Readable` class using the [`readable.wrap()`][`stream.wrap()`] method. ### `readable.read(0)` There are some cases where it is necessary to trigger a refresh of the underlying readable stream mechanisms, without actually consuming any data. In such cases, it is possible to call `readable.read(0)`, which will always return `null`. If the internal read buffer is below the `highWaterMark`, and the stream is not currently reading, then calling `stream.read(0)` will trigger a low-level [`stream.\_read()`][stream-\_read] call. While most applications will almost never need to do this, there are situations within Node.js where this is done, particularly in the `Readable` stream class internals. ### `readable.push('')` Use of `readable.push('')` is not recommended. Pushing a zero-byte {string}, {Buffer}, {TypedArray} or {DataView} to a stream that is not in object mode has an interesting side effect. Because it \_is\_ a call to [`readable.push()`][stream-push], the call will end the reading process. However, because the argument is an empty string, no data is added to the readable buffer so there is nothing for a user to consume. ### `highWaterMark` discrepancy after calling `readable.setEncoding()` The use of `readable.setEncoding()` will change the behavior of how the `highWaterMark` operates in non-object mode. Typically, the size of the current buffer is measured against the `highWaterMark` in \_bytes\_. However, after `setEncoding()` is called, the comparison function will begin to measure the buffer's size in \_characters\_. This is not a problem in common cases with `latin1` or `ascii`. But it is advised to be mindful about this behavior when working with strings that could contain multi-byte characters. [API for stream consumers]: #api-for-stream-consumers [API for stream implementers]: #api-for-stream-implementers [Compatibility]: #compatibility-with-older-nodejs-versions [HTTP requests, on the client]: http.md#class-httpclientrequest [HTTP responses, on the server]: http.md#class-httpserverresponse [TCP sockets]: net.md#class-netsocket [Three states]: #three-states [`'data'`]: #event-data [`'drain'`]: #event-drain [`'end'`]: #event-end [`'finish'`]: #event-finish [`'readable'`]: #event-readable [`Duplex`]: #class-streamduplex [`EventEmitter`]: events.md#class-eventemitter [`Readable`]: #class-streamreadable [`Symbol.hasInstance`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Symbol/hasInstance [`Transform`]: #class-streamtransform [`Writable`]: #class-streamwritable [`fs.createReadStream()`]: fs.md#fscreatereadstreampath-options [`fs.createWriteStream()`]: fs.md#fscreatewritestreampath-options [`net.Socket`]: net.md#class-netsocket [`process.stderr`]: process.md#processstderr [`process.stdin`]: process.md#processstdin [`process.stdout`]: process.md#processstdout [`readable.\_read()`]: #readable\_readsize [`readable.compose(stream)`]: #readablecomposestream-options [`readable.map`]: #readablemapfn-options [`readable.push('')`]: #readablepush [`readable.setEncoding()`]: #readablesetencodingencoding [`stream.Readable.from()`]: #streamreadablefromiterable-options [`stream.addAbortSignal()`]: #streamaddabortsignalsignal-stream [`stream.compose(...streams)`]: #streamcomposestreams [`stream.cork()`]: #writablecork [`stream.duplexPair()`]: #streamduplexpairoptions [`stream.finished()`]: #streamfinishedstream-options-callback [`stream.pipe()`]: #readablepipedestination-options [`stream.pipeline()`]: #streampipelinesource-transforms-destination-callback [`stream.uncork()`]: #writableuncork [`stream.unpipe()`]: #readableunpipedestination [`stream.wrap()`]: #readablewrapstream [`writable.\_final()`]: #writable\_finalcallback [`writable.\_write()`]: #writable\_writechunk-encoding-callback [`writable.\_writev()`]: #writable\_writevchunks-callback [`writable.cork()`]: #writablecork [`writable.end()`]: #writableendchunk-encoding-callback [`writable.uncork()`]: #writableuncork [`writable.writableFinished`]: #writablewritablefinished [`zlib.createDeflate()`]: zlib.md#zlibcreatedeflateoptions [child process stdin]: child\_process.md#subprocessstdin [child process stdout and stderr]: child\_process.md#subprocessstdout [crypto]: crypto.md [fs read streams]: fs.md#class-fsreadstream [fs write streams]: fs.md#class-fswritestream [http-incoming-message]: http.md#class-httpincomingmessage [hwm-gotcha]: #highwatermark-discrepancy-after-calling-readablesetencoding [object-mode]: #object-mode [readable-\_construct]: #readable\_constructcallback [readable-\_destroy]: #readable\_destroyerr-callback [readable-destroy]: #readabledestroyerror [stream-\_final]: #writable\_finalcallback [stream-\_flush]: #transform\_flushcallback [stream-\_read]: #readable\_readsize [stream-\_transform]: #transform\_transformchunk-encoding-callback [stream-\_write]: #writable\_writechunk-encoding-callback [stream-\_writev]: #writable\_writevchunks-callback [stream-end]: #writableendchunk-encoding-callback [stream-finished]: #streamfinishedstream-options-callback [stream-finished-promise]: #streamfinishedstream-options [stream-pause]: #readablepause [stream-pipeline]: #streampipelinesource-transforms-destination-callback [stream-pipeline-promise]: #streampipelinesource-transforms-destination-options [stream-push]: #readablepushchunk-encoding [stream-read]: #readablereadsize [stream-resume]: #readableresume [stream-uncork]: #writableuncork [stream-write]: #writablewritechunk-encoding-callback [writable-\_construct]: #writable\_constructcallback [writable-\_destroy]: #writable\_destroyerr-callback [writable-destroy]: #writabledestroyerror [writable-new]: #new-streamwritableoptions [zlib]: zlib.md | https://github.com/nodejs/node/blob/main//doc/api/stream.md | main | nodejs | [
-0.05690647289156914,
-0.024674242362380028,
0.012350312434136868,
0.059882402420043945,
0.03232305124402046,
-0.021262699738144875,
-0.03557209670543671,
-0.045449066907167435,
0.017446473240852356,
0.02295686863362789,
-0.04468753561377525,
0.1370241641998291,
-0.08500628918409348,
-0.009487943723797798,
-0.0589183084666729,
-0.014397392980754375,
0.06660988926887512,
-0.016653966158628464,
0.008240366354584694,
-0.03382520005106926,
-0.02651110664010048,
0.009729444980621338,
0.018934600055217743,
-0.0017084002029150724,
-0.005555885843932629,
0.017823923379182816,
-0.014485416002571583,
-0.03929239138960838,
0.04037204757332802,
0.059327807277441025,
-0.012451965361833572,
-0.04482099413871765,
-0.0850299820303917,
0.03665435314178467,
-0.07872733473777771,
0.1005568578839302,
0.04469851776957512,
0.02040944993495941,
-0.12295505404472351,
0.05298423767089844,
0.0959998369216919,
-0.021260635927319527,
-0.060785360634326935,
-0.002007152885198593,
0.04359264299273491,
-0.016522327437996864,
-0.04231640323996544,
-0.0478108711540699,
-0.02609364502131939,
0.005220914725214243,
-0.03929348662495613,
0.010840900242328644,
-0.02587972767651081,
0.07959640026092529,
0.08670920133590698,
-0.022782687097787857,
-0.028579004108905792,
0.02049477957189083,
-0.04633572697639465,
0.005254861433058977,
-0.04160340130329132,
-0.021820442751049995,
0.009881787933409214,
-0.004976293072104454,
-0.027195371687412262,
0.0849117785692215,
-0.026369795203208923,
0.019256602972745895,
0.04875471442937851,
0.019958656281232834,
0.016654163599014282,
0.04334175959229469,
-0.11156731098890305,
0.007556844502687454,
-0.047175828367471695,
-0.05328111723065376,
0.019748469814658165,
-0.007184210233390331,
-0.058737680315971375,
0.11062674224376678,
-0.006791037507355213,
-0.10383063554763794,
-0.011926454491913319,
0.032939646393060684,
-0.08481963723897934,
0.11360130459070206,
0.018752165138721466,
0.01255914568901062,
-0.0003071470418944955,
0.043724436312913895,
-0.1235460713505745,
0.046818267554044724,
-0.003532927017658949,
0.09562386572360992,
-0.011261912994086742,
0.022103678435087204,
0.03733401373028755,
0.054440561681985855,
-0.030880793929100037,
-0.03059067577123642,
0.06452462822198868,
0.041736844927072525,
-0.04080111160874367,
-0.014753530733287334,
0.000877534446772188,
-0.09285085648298264,
0.015897026285529137,
0.06057567521929741,
-0.06007548049092293,
0.0008952895877882838,
0.02870851568877697,
0.03949952870607376,
-0.010637333616614342,
0.026921778917312622,
-0.017186343669891357,
0.021513493731617928,
-0.01964707486331463,
-0.021304242312908173,
0.005650187376886606,
0.12224460393190384,
0.10297717899084091,
-0.0012062990572303534,
-0.031056566163897514,
-0.03495805710554123,
0.055111318826675415,
-0.0054786731489002705,
0.0741138681769371,
-8.960386605070318e-34,
-0.09012170135974884,
-0.047475505620241165,
-0.025579901412129402,
0.07218531519174576,
0.026472004130482674,
-0.01662166230380535,
0.02518882043659687,
0.021758565679192543,
-0.023838892579078674,
0.0004909464041702449,
-0.05010242015123367,
-0.010129377245903015,
0.03662964329123497,
-0.0014454550109803677,
0.012900982983410358,
-0.06307070702314377,
0.043051812797784805,
0.0027838631067425013,
0.07544605433940887,
0.020536035299301147,
0.04169173538684845,
-0.09521948546171188,
-0.02459532953798771,
0.00938453059643507,
-0.03464636951684952,
-0.004621722269803286,
-0.06058793514966965,
0.03549443557858467,
0.009233150631189346,
-0.006440537981688976,
-0.06659512221813202,
0.03801502659916878,
0.029032450169324875,
-0.011884065344929695,
-0.01166410930454731,
-0.060652878135442734,
0.05950745940208435,
-0.027157368138432503,
-0.019620778039097786,
-0.0344482958316803,
0.030784787610173225,
0.03831338509917259,
-0.09127557277679443,
0.037545111030340195,
-0.039036937057971954,
-0.144181028008461,
-0.10186735540628433,
0.0027690937276929617,
0.015181070193648338,
-0.016559714451432228,
0.03733493387699127,
0.09188477694988251,
0.017150618135929108,
-0.005641182418912649,
-0.022579330950975418,
-0.004509480204433203,
0.04267530515789986,
0.02627135068178177,
-0.07219430804252625,
0.07089024037122726,
0.047780733555555344,
0.025224365293979645,
0.021633002907037735,
-0.04052454233169556,
0.09966368228197098,
0.031779877841472626,
-0.046229634433984756,
-0.02756938897073269,
-0.05022531747817993,
-0.08699897676706314,
-0.05022240802645683,
-0.020152630284428596,
-0.034058328717947006,
0.047679536044597626,
0.018547864630818367,
0.08139465004205704,
-0.04113001376390457,
0.004614314995706081,
0.029378782957792282,
-0.01725044660270214,
0.07236196845769882,
-0.030155757442116737,
0.019558465108275414,
0.028150854632258415,
0.05821913108229637,
0.01219989638775587,
-0.04491046443581581,
-0.046547938138246536,
-0.00798812322318554,
0.00250883842818439,
-0.013914886862039566,
0.042683131992816925,
0.12311584502458572,
-0.06593023985624313,
-0.025003528222441673,
-5.001798257725913e-34,
-0.021251501515507698,
0.008564157411456108,
-0.18156257271766663,
0.06282816082239151,
-0.02583690918982029,
-0.0012160750338807702,
-0.01652173511683941,
0.035439539700746536,
0.0016475614393129945,
-0.039425745606422424,
0.016544116660952568,
0.0004388336092233658,
-0.004171097185462713,
0.051778439432382584,
-0.034282881766557693,
-0.0585717149078846,
-0.010672280564904213,
-0.0328671932220459,
0.009072151966392994,
0.017656734213232994,
-0.013851339928805828,
-0.060771647840738297,
0.029515452682971954,
-0.058133289217948914,
-0.09424662590026855,
0.06824390590190887,
-0.0395655632019043,
0.0018307574791833758,
-0.0750843733549118,
-0.032300133258104324,
0.011964189819991589,
-0.037017617374658585,
0.028250979259610176,
-0.044845983386039734,
0.0018122026231139898,
-0.001990057760849595,
-0.003961223643273115,
0.00029316454310901463,
0.06374971568584442,
0.029478715732693672,
0.16925695538520813,
0.020038781687617302,
-0.07099468261003494,
-0.008440690115094185,
0.06255412846803665,
0.011130196042358875,
-0.07272087782621384,
-0.0052306014113128185,
-0.057010676711797714,
0.026329422369599342,
0.0002697352028917521,
0.05052795261144638,
0.07800952345132828,
0.05055559054017067,
0.012553992681205273,
0.010301073081791401,
0.054945651441812515,
-0.001566279330290854,
0.06773228943347931,
-0.06529689580202103,
0.08050137013196945,
-0.11622113734483719,
-0.05258176848292351,
-0.021604100242257118,
0.09782643616199493,
0.026317447423934937,
0.02916679158806801,
0.0033557494170963764,
0.04387524351477623,
-0.07783275097608566,
0.01525263860821724,
0.019352171570062637,
-0.06433405727148056,
0.004754869267344475,
0.024808231741189957,
0.0418122261762619,
-0.025457391515374184,
-0.045334551483392715,
-0.012558532878756523,
0.08067213743925095,
-0.06311661005020142,
0.11732565611600876,
-0.09300552308559418,
0.027359556406736374,
0.11245734244585037,
-0.01225915364921093,
-0.03783927112817764,
-0.09174754470586777,
0.02798241749405861,
-0.04641926661133766,
0.008904162794351578,
0.028766155242919922,
-0.12479715049266815,
0.025109825655817986,
-0.020337719470262527,
-4.611760573425272e-8,
-0.048285990953445435,
-0.01987561210989952,
-0.046097900718450546,
0.037071458995342255,
0.05250004678964615,
0.0034765126183629036,
-0.046568140387535095,
-0.02591567486524582,
0.05298589542508125,
0.0542261116206646,
-0.029076598584651947,
-0.01750383898615837,
0.05697678402066231,
-0.06865956634283066,
0.07665735483169556,
0.023820290341973305,
0.03866038843989372,
-0.06118352711200714,
-0.0035072958562523127,
-0.03626975044608116,
0.060873765498399734,
0.031218742951750755,
-0.08097301423549652,
0.0430280975997448,
-0.02394740842282772,
-0.05623017996549606,
0.15609140694141388,
0.020914897322654724,
-0.05320722237229347,
-0.058636028319597244,
-0.11149527877569199,
0.010444048792123795,
0.060725048184394836,
0.043855465948581696,
-0.021784551441669464,
0.032350730150938034,
0.0059122308157384396,
0.01987474225461483,
0.04650013893842697,
0.04652829468250275,
0.0505981482565403,
-0.018495894968509674,
-0.0711204782128334,
0.01795852929353714,
-0.004604170098900795,
0.013108018785715103,
0.01786474511027336,
0.0850076824426651,
-0.011512970551848412,
0.060682665556669235,
-0.004821629263460636,
0.027655567973852158,
-0.035736046731472015,
-0.044833071529865265,
0.024013465270400047,
-0.06969469785690308,
-0.01493446622043848,
-0.07299569994211197,
-0.06884582340717316,
0.01622195355594158,
0.043077755719423294,
0.05634572356939316,
-0.050861526280641556,
-0.015054306015372276
] | 0.057785 |
# Asynchronous context tracking > Stability: 2 - Stable ## Introduction These classes are used to associate state and propagate it throughout callbacks and promise chains. They allow storing data throughout the lifetime of a web request or any other asynchronous duration. It is similar to thread-local storage in other languages. The `AsyncLocalStorage` and `AsyncResource` classes are part of the `node:async\_hooks` module: ```mjs import { AsyncLocalStorage, AsyncResource } from 'node:async\_hooks'; ``` ```cjs const { AsyncLocalStorage, AsyncResource } = require('node:async\_hooks'); ``` ## Class: `AsyncLocalStorage` This class creates stores that stay coherent through asynchronous operations. While you can create your own implementation on top of the `node:async\_hooks` module, `AsyncLocalStorage` should be preferred as it is a performant and memory safe implementation that involves significant optimizations that are non-obvious to implement. The following example uses `AsyncLocalStorage` to build a simple logger that assigns IDs to incoming HTTP requests and includes them in messages logged within each request. ```mjs import http from 'node:http'; import { AsyncLocalStorage } from 'node:async\_hooks'; const asyncLocalStorage = new AsyncLocalStorage(); function logWithId(msg) { const id = asyncLocalStorage.getStore(); console.log(`${id !== undefined ? id : '-'}:`, msg); } let idSeq = 0; http.createServer((req, res) => { asyncLocalStorage.run(idSeq++, () => { logWithId('start'); // Imagine any chain of async operations here setImmediate(() => { logWithId('finish'); res.end(); }); }); }).listen(8080); http.get('http://localhost:8080'); http.get('http://localhost:8080'); // Prints: // 0: start // 0: finish // 1: start // 1: finish ``` ```cjs const http = require('node:http'); const { AsyncLocalStorage } = require('node:async\_hooks'); const asyncLocalStorage = new AsyncLocalStorage(); function logWithId(msg) { const id = asyncLocalStorage.getStore(); console.log(`${id !== undefined ? id : '-'}:`, msg); } let idSeq = 0; http.createServer((req, res) => { asyncLocalStorage.run(idSeq++, () => { logWithId('start'); // Imagine any chain of async operations here setImmediate(() => { logWithId('finish'); res.end(); }); }); }).listen(8080); http.get('http://localhost:8080'); http.get('http://localhost:8080'); // Prints: // 0: start // 0: finish // 1: start // 1: finish ``` Each instance of `AsyncLocalStorage` maintains an independent storage context. Multiple instances can safely exist simultaneously without risk of interfering with each other's data. ### `new AsyncLocalStorage([options])` \* `options` {Object} \* `defaultValue` {any} The default value to be used when no store is provided. \* `name` {string} A name for the `AsyncLocalStorage` value. Creates a new instance of `AsyncLocalStorage`. Store is only provided within a `run()` call or after an `enterWith()` call. ### Static method: `AsyncLocalStorage.bind(fn)` \* `fn` {Function} The function to bind to the current execution context. \* Returns: {Function} A new function that calls `fn` within the captured execution context. Binds the given function to the current execution context. ### Static method: `AsyncLocalStorage.snapshot()` \* Returns: {Function} A new function with the signature `(fn: (...args) : R, ...args) : R`. Captures the current execution context and returns a function that accepts a function as an argument. Whenever the returned function is called, it calls the function passed to it within the captured context. ```js const asyncLocalStorage = new AsyncLocalStorage(); const runInAsyncScope = asyncLocalStorage.run(123, () => AsyncLocalStorage.snapshot()); const result = asyncLocalStorage.run(321, () => runInAsyncScope(() => asyncLocalStorage.getStore())); console.log(result); // returns 123 ``` AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple async context tracking purposes, for example: ```js class Foo { #runInAsyncScope = AsyncLocalStorage.snapshot(); get() { return this.#runInAsyncScope(() => asyncLocalStorage.getStore()); } } const foo = asyncLocalStorage.run(123, () => new Foo()); console.log(asyncLocalStorage.run(321, () => foo.get())); // returns 123 ``` ### `asyncLocalStorage.disable()` > Stability: 1 - Experimental Disables the instance of `AsyncLocalStorage`. All subsequent calls to `asyncLocalStorage.getStore()` will return `undefined` until `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again. When calling `asyncLocalStorage.disable()`, all current contexts linked to the instance will be exited. Calling `asyncLocalStorage.disable()` is required before the `asyncLocalStorage` can be garbage collected. This does not | https://github.com/nodejs/node/blob/main//doc/api/async_context.md | main | nodejs | [
-0.12447480112314224,
0.04581790789961815,
-0.06367533653974533,
0.11791470646858215,
-0.02267284318804741,
-0.038013141602277756,
0.03451845422387123,
-0.0008479335810989141,
0.019958999007940292,
-0.05886002629995346,
-0.03258824720978737,
0.024251636117696762,
-0.012060933746397495,
-0.05031821131706238,
-0.008156577125191689,
0.056420158594846725,
0.042828142642974854,
0.05909882113337517,
-0.06330852955579758,
-0.022930359467864037,
0.028741352260112762,
-0.04393806308507919,
0.0870119035243988,
0.031127268448472023,
-0.025057248771190643,
-0.02031756192445755,
-0.06765403598546982,
-0.06947987526655197,
0.0891578420996666,
-0.022895382717251778,
0.03674093633890152,
-0.004880690015852451,
-0.09314091503620148,
0.045965682715177536,
-0.06891210377216339,
0.13380172848701477,
-0.06382645666599274,
-0.07065945863723755,
-0.05626951530575752,
-0.017961231991648674,
0.0483742319047451,
0.09924376755952835,
-0.05339222773909569,
-0.007775869686156511,
0.02263842150568962,
-0.03972748667001724,
-0.02544780820608139,
0.028964174911379814,
-0.0741417184472084,
-0.013291163370013237,
0.004848704673349857,
0.03528008610010147,
-0.1017894446849823,
-0.012964467518031597,
-0.02711927331984043,
0.06519665569067001,
0.06714434176683426,
0.05035392940044403,
-0.02852424792945385,
0.04697910696268082,
0.05409931391477585,
-0.033215057104825974,
0.02393699437379837,
0.01964605785906315,
0.02436685375869274,
0.03863205388188362,
-0.004597077611833811,
0.05932298302650452,
0.04957519844174385,
0.021294983103871346,
-0.01041991077363491,
-0.021906312555074692,
0.024008719250559807,
0.036697808653116226,
-0.0062600369565188885,
-0.03076956793665886,
0.003303263336420059,
0.008607420139014721,
-0.05013572424650192,
0.05273780599236488,
0.013844850473105907,
-0.06233203411102295,
0.05467214807868004,
-0.025882314890623093,
0.01121476199477911,
0.020579829812049866,
-0.033970169723033905,
-0.0137647008523345,
0.019931327551603317,
-0.0025190722662955523,
-0.03987859562039375,
-0.024365032091736794,
-0.0860583558678627,
-0.009366009384393692,
-0.0025016916915774345,
0.008019071072340012,
0.046454738825559616,
0.04327959567308426,
-0.011590713635087013,
-0.011033240705728531,
0.032906413078308105,
0.020986754447221756,
0.009115546941757202,
0.049405377358198166,
0.04091319441795349,
-0.05689758062362671,
-0.02878773957490921,
-0.04118693992495537,
-0.03985026851296425,
-0.032393213361501694,
-0.010017112828791142,
0.04792361333966255,
-0.02377632074058056,
0.03681905195116997,
-0.007668221369385719,
0.022119730710983276,
0.06523855030536652,
-0.02706991322338581,
0.12392260879278183,
0.12357532978057861,
0.09940534830093384,
0.02100890316069126,
-0.015108933672308922,
-0.11762622743844986,
0.030745569616556168,
0.005607822444289923,
-0.02479524537920952,
7.004673123582099e-33,
-0.012353790923953056,
-0.05640484765172005,
-0.02628297545015812,
0.022092079743742943,
0.008155706338584423,
0.03554993495345116,
0.05516267940402031,
-0.0471963956952095,
-0.07535869628190994,
-0.04661738872528076,
0.04886241629719734,
0.02588765323162079,
-0.029861627146601677,
-0.013907461427152157,
0.005143586080521345,
-0.08460072427988052,
0.04262382537126541,
-0.042339663952589035,
0.11494415998458862,
0.002235843101516366,
0.01162221934646368,
0.04392334446310997,
-0.007955103181302547,
-0.03156975284218788,
0.05368625745177269,
-0.05104963853955269,
0.0005131328944116831,
0.06100758537650108,
-0.07378780096769333,
0.011921600438654423,
0.02145911380648613,
0.06391822546720505,
-0.07049832493066788,
0.0008048010058701038,
0.021999523043632507,
-0.04347069934010506,
-0.05354613438248634,
-0.029327750205993652,
-0.06392107903957367,
-0.10984911769628525,
-0.0379699170589447,
0.06774410605430603,
-0.06351875513792038,
0.027158236131072044,
-0.09684807062149048,
-0.13087818026542664,
-0.05101581662893295,
0.017187438905239105,
0.029810354113578796,
-0.018435005098581314,
0.013360792770981789,
0.01996479742228985,
-0.01574992761015892,
-0.08663234114646912,
0.033056456595659256,
0.012844338081777096,
0.032386284321546555,
-0.023519759997725487,
-0.039257075637578964,
0.05742659792304039,
0.036705873906612396,
-0.1124953106045723,
-0.062025442719459534,
-0.006161501165479422,
0.00696633430197835,
0.04720722511410713,
-0.0759192556142807,
0.04508088156580925,
-0.006426225882023573,
-0.005936755798757076,
-0.01437542773783207,
0.014821008779108524,
-0.039940040558576584,
0.030001496896147728,
0.007897518575191498,
0.04179462790489197,
-0.10037519037723541,
0.005195655394345522,
-0.059800609946250916,
-0.09261694550514221,
0.08091717958450317,
-0.05194505304098129,
-0.06321855634450912,
0.13685838878154755,
-0.0037675797939300537,
0.008960548788309097,
0.0004928797134198248,
-0.06822517514228821,
0.0636342465877533,
0.04386136308312416,
-0.028030887246131897,
-0.05703112110495567,
0.061137232929468155,
-0.053444620221853256,
-0.10164695978164673,
-9.065300026894184e-33,
0.034319911152124405,
-0.037164852023124695,
-0.0931890532374382,
0.090142622590065,
0.0077092708088457584,
0.01860305666923523,
-0.02084537222981453,
-0.010120048187673092,
-0.09777913242578506,
-0.017239421606063843,
-0.03847772628068924,
0.03074134886264801,
0.020436109974980354,
0.08645632117986679,
0.049529630690813065,
0.018597932532429695,
0.015143410302698612,
-0.05848730728030205,
0.06316088885068893,
-0.001206877175718546,
0.024650005623698235,
-0.009839368984103203,
0.007598490454256535,
0.019048744812607765,
-0.06783980876207352,
-0.020931784063577652,
-0.09806382656097412,
-0.0320737287402153,
0.013482259586453438,
-0.04361492022871971,
-0.06714283674955368,
-0.030846593901515007,
-0.008796504698693752,
-0.023683592677116394,
-0.02562440186738968,
-0.025698881596326828,
-0.0017892447067424655,
0.04476652666926384,
-0.032571882009506226,
-0.024851981550455093,
0.0998644158244133,
0.028215765953063965,
-0.02614053711295128,
-0.0057038613595068455,
0.02231285348534584,
-0.006934597622603178,
-0.0549769289791584,
0.04834536463022232,
-0.03849619999527931,
-0.00863953959196806,
-0.07973192632198334,
-0.04672940820455551,
-0.030789773911237717,
0.02172214910387993,
-0.05869610607624054,
0.037118539214134216,
0.04859248548746109,
-0.042714886367321014,
0.10594194382429123,
0.007683216128498316,
0.01486082561314106,
-0.11055140942335129,
0.0026597552932798862,
-0.031097304075956345,
0.04851847141981125,
0.01796945556998253,
-0.014039572328329086,
-0.09094449877738953,
0.0369141660630703,
0.06530117988586426,
0.07435236871242523,
0.03192729502916336,
-0.033872876316308975,
0.004035541322082281,
-0.026075540110468864,
-0.014765544794499874,
-0.004950102884322405,
-0.1279330551624298,
0.06755255162715912,
0.04968005046248436,
-0.10173844546079636,
0.026110703125596046,
0.024100346490740776,
0.04166289418935776,
-0.009907425381243229,
-0.032283324748277664,
-0.014063822105526924,
0.05408681929111481,
0.02942587621510029,
-0.004823353607207537,
0.02056465484201908,
0.028346214443445206,
-0.17966803908348083,
-0.02453305386006832,
0.007278169505298138,
-5.356392307476199e-8,
-0.07403761148452759,
-0.004916382022202015,
-0.06314451992511749,
0.06324887275695801,
0.022515306249260902,
-0.03343723714351654,
0.01321333460509777,
-0.019188527017831802,
0.09558930993080139,
0.027473296970129013,
0.030649349093437195,
-0.003852213267236948,
0.06760765612125397,
-0.08671830594539642,
-0.06012508273124695,
0.0625518262386322,
0.02004288323223591,
0.019925730302929878,
0.01380657684057951,
0.04408060759305954,
0.021728502586483955,
-0.007687554229050875,
0.0074270800687372684,
0.09085717797279358,
0.004386340267956257,
-0.018519362434744835,
0.09566155076026917,
0.17319898307323456,
0.03236600384116173,
0.0022403064649552107,
-0.04497000575065613,
0.00352684548124671,
0.05651113763451576,
-0.030085895210504532,
-0.02989448420703411,
0.01438029296696186,
-0.025768360123038292,
-0.04377666860818863,
0.100375697016716,
0.05490611493587494,
0.0445658378303051,
-0.03906939923763275,
-0.03490752726793289,
0.08867904543876648,
0.05290776863694191,
0.04526548832654953,
-0.0008940838160924613,
-0.020802810788154602,
-0.0055543226189911366,
0.027565648779273033,
-0.003847333136945963,
-0.07924303412437439,
-0.047717101871967316,
0.07778751850128174,
0.0015887346817180514,
-0.038877423852682114,
0.0491521842777729,
-0.02690364420413971,
0.0005309777334332466,
0.023432357236742973,
-0.023486267775297165,
0.00008513429929735139,
0.05093943700194359,
-0.05641905590891838
] | 0.13704 |
1 - Experimental Disables the instance of `AsyncLocalStorage`. All subsequent calls to `asyncLocalStorage.getStore()` will return `undefined` until `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again. When calling `asyncLocalStorage.disable()`, all current contexts linked to the instance will be exited. Calling `asyncLocalStorage.disable()` is required before the `asyncLocalStorage` can be garbage collected. This does not apply to stores provided by the `asyncLocalStorage`, as those objects are garbage collected along with the corresponding async resources. Use this method when the `asyncLocalStorage` is not in use anymore in the current process. ### `asyncLocalStorage.getStore()` \* Returns: {any} Returns the current store. If called outside of an asynchronous context initialized by calling `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()`, it returns `undefined`. ### `asyncLocalStorage.enterWith(store)` > Stability: 1 - Experimental \* `store` {any} Transitions into the context for the remainder of the current synchronous execution and then persists the store through any following asynchronous calls. Example: ```js const store = { id: 1 }; // Replaces previous store with the given store object asyncLocalStorage.enterWith(store); asyncLocalStorage.getStore(); // Returns the store object someAsyncOperation(() => { asyncLocalStorage.getStore(); // Returns the same object }); ``` This transition will continue for the \_entire\_ synchronous execution. This means that if, for example, the context is entered within an event handler subsequent event handlers will also run within that context unless specifically bound to another context with an `AsyncResource`. That is why `run()` should be preferred over `enterWith()` unless there are strong reasons to use the latter method. ```js const store = { id: 1 }; emitter.on('my-event', () => { asyncLocalStorage.enterWith(store); }); emitter.on('my-event', () => { asyncLocalStorage.getStore(); // Returns the same object }); asyncLocalStorage.getStore(); // Returns undefined emitter.emit('my-event'); asyncLocalStorage.getStore(); // Returns the same object ``` ### `asyncLocalStorage.name` \* Type: {string} The name of the `AsyncLocalStorage` instance if provided. ### `asyncLocalStorage.run(store, callback[, ...args])` \* `store` {any} \* `callback` {Function} \* `...args` {any} Runs a function synchronously within a context and returns its return value. The store is not accessible outside of the callback function. The store is accessible to any asynchronous operations created within the callback. The optional `args` are passed to the callback function. If the callback function throws an error, the error is thrown by `run()` too. The stacktrace is not impacted by this call and the context is exited. Example: ```js const store = { id: 2 }; try { asyncLocalStorage.run(store, () => { asyncLocalStorage.getStore(); // Returns the store object setTimeout(() => { asyncLocalStorage.getStore(); // Returns the store object }, 200); throw new Error(); }); } catch (e) { asyncLocalStorage.getStore(); // Returns undefined // The error will be caught here } ``` ### `asyncLocalStorage.exit(callback[, ...args])` > Stability: 1 - Experimental \* `callback` {Function} \* `...args` {any} Runs a function synchronously outside of a context and returns its return value. The store is not accessible within the callback function or the asynchronous operations created within the callback. Any `getStore()` call done within the callback function will always return `undefined`. The optional `args` are passed to the callback function. If the callback function throws an error, the error is thrown by `exit()` too. The stacktrace is not impacted by this call and the context is re-entered. Example: ```js // Within a call to run try { asyncLocalStorage.getStore(); // Returns the store object or value asyncLocalStorage.exit(() => { asyncLocalStorage.getStore(); // Returns undefined throw new Error(); }); } catch (e) { asyncLocalStorage.getStore(); // Returns the same object or value // The error will be caught here } ``` ### Usage with `async/await` If, within an async function, only one `await` call is to run within a context, the following pattern should be used: ```js async function fn() { await asyncLocalStorage.run(new Map(), () => | https://github.com/nodejs/node/blob/main//doc/api/async_context.md | main | nodejs | [
-0.07551515102386475,
0.051314521580934525,
-0.0924014151096344,
0.12512344121932983,
-0.007937654852867126,
-0.06916199624538422,
0.007516087964177132,
-0.04407404363155365,
0.005750061944127083,
-0.04250003769993782,
0.03715159744024277,
0.0675201267004013,
-0.009836630895733833,
-0.044710323214530945,
-0.01273479126393795,
0.035649873316287994,
0.10210545361042023,
-0.03499915823340416,
-0.049953047186136246,
0.043947733938694,
-0.001305156503804028,
-0.07989081740379333,
0.03918019309639931,
0.057987287640571594,
-0.015049988403916359,
-0.049902964383363724,
-0.10745419561862946,
-0.11242243647575378,
0.08213174343109131,
-0.0025612320750951767,
0.032378021627664566,
-0.02138122357428074,
-0.0755491703748703,
0.03126688301563263,
0.06982192397117615,
0.06606678664684296,
-0.028365351259708405,
-0.030389530584216118,
-0.04278591275215149,
0.007435554172843695,
0.06928244978189468,
0.05313831567764282,
-0.1442192643880844,
0.049469493329524994,
-0.028285609558224678,
-0.03856096789240837,
-0.04241776466369629,
-0.031337618827819824,
-0.06646914035081863,
-0.030096232891082764,
-0.009838486090302467,
0.13781343400478363,
-0.049639008939266205,
-0.012601870112121105,
0.038208190351724625,
0.0912952870130539,
0.09207191318273544,
0.04492264613509178,
-0.014526757411658764,
0.07604297250509262,
0.07878605276346207,
-0.031213194131851196,
-0.06662553548812866,
-0.011085156351327896,
-0.03827367722988129,
0.045621417462825775,
0.05672258883714676,
0.005116685759276152,
0.05865800753235817,
-0.04936351999640465,
0.005184181034564972,
0.01311265118420124,
0.02815156802535057,
0.018668662756681442,
0.04827389866113663,
0.05092081055045128,
-0.015889767557382584,
-0.026740897446870804,
-0.00713312765583396,
-0.05430866405367851,
0.02408294379711151,
-0.1009906455874443,
0.006112208589911461,
-0.044238705188035965,
-0.03334337845444679,
0.015908997505903244,
0.025416487827897072,
-0.0643727257847786,
0.0594077929854393,
0.024996832013130188,
0.00735974358394742,
0.0077172815799713135,
0.02521607279777527,
0.047783032059669495,
0.0593859888613224,
0.046973176300525665,
0.06603474169969559,
-0.015319504775106907,
-0.05824173614382744,
-0.0054689631797373295,
0.04378203675150871,
0.04397546872496605,
0.036154672503471375,
0.05326112359762192,
-0.01347300224006176,
-0.05516019091010094,
-0.013898052275180817,
-0.08144627511501312,
-0.05010996386408806,
-0.008457333780825138,
-0.0387788787484169,
0.04205100238323212,
0.001213637413457036,
0.1035819724202156,
-0.061276014894247055,
0.028030788525938988,
-0.010047804564237595,
-0.011955530382692814,
0.0341777540743351,
0.11540333181619644,
0.08552373945713043,
0.04924948886036873,
0.07272166758775711,
-0.056822896003723145,
-0.03374297544360161,
0.03445557504892349,
-0.016292324289679527,
9.826580290529437e-33,
-0.043805185705423355,
-0.09994685649871826,
-0.0467851497232914,
-0.003155031241476536,
-0.010582192800939083,
-0.009571552276611328,
0.029448816552758217,
0.021606890484690666,
-0.04562687873840332,
-0.04105028882622719,
0.03443952277302742,
0.010816413909196854,
-0.03774942830204964,
-0.028996823355555534,
0.06615515053272247,
-0.03374546393752098,
0.05258822813630104,
-0.025037946179509163,
0.06660047918558121,
0.025614755228161812,
0.03894227743148804,
0.04946671798825264,
-0.06167154386639595,
0.00038022559601813555,
-0.011778749525547028,
-0.05922824144363403,
-0.07545579969882965,
0.033779680728912354,
-0.03098486363887787,
0.04301866516470909,
-0.01291167363524437,
0.00952653493732214,
-0.0953604131937027,
0.0496840626001358,
0.020062705501914024,
-0.0036063429433852434,
-0.047822508960962296,
-0.004536656197160482,
-0.09595074504613876,
-0.11663303524255753,
-0.044140588492155075,
0.03460441529750824,
-0.04372447356581688,
0.03331674635410309,
-0.05950937047600746,
-0.11741378158330917,
-0.05055103823542595,
-0.02508535236120224,
-0.015931177884340286,
0.06386484205722809,
-0.044689226895570755,
0.0465087965130806,
-0.03414244204759598,
-0.025603294372558594,
-0.008057435043156147,
-0.04927093908190727,
0.027157196775078773,
-0.06806385517120361,
0.04206645116209984,
0.041559457778930664,
-0.009894240647554398,
-0.05262568220496178,
-0.053950145840644836,
0.004542279522866011,
-0.01973740942776203,
-0.026380838826298714,
-0.0508672334253788,
-0.07923576235771179,
-0.08728237450122833,
-0.006641073618084192,
-0.04207492992281914,
0.02561727911233902,
-0.004731557331979275,
0.014264981262385845,
-0.0026984806172549725,
-0.034297049045562744,
-0.04719253256917,
0.03527645021677017,
-0.10520898550748825,
-0.1094362661242485,
0.10399111360311508,
-0.02470521628856659,
-0.013577757403254509,
0.10594196617603302,
-0.04990747943520546,
0.05305495485663414,
0.010718462988734245,
-0.0179628636687994,
0.10910230129957199,
0.016685476526618004,
0.08584955334663391,
-0.05603940412402153,
0.02390185184776783,
-0.06488877534866333,
-0.016390595585107803,
-1.0003966796172336e-32,
0.04769829660654068,
-0.050942324101924896,
-0.07042230665683746,
0.015183055773377419,
0.0006477412534877658,
-0.005381153430789709,
-0.004188166465610266,
0.0187513530254364,
-0.07891945540904999,
-0.10333750396966934,
-0.021140020340681076,
0.05951574817299843,
0.046332862228155136,
0.027818730100989342,
0.010872459970414639,
-0.007610279601067305,
0.06752599030733109,
-0.07549767196178436,
0.03773852810263634,
0.032888349145650864,
0.005156896077096462,
-0.00308240600861609,
0.02915186993777752,
0.04083646088838577,
-0.0649474486708641,
-0.017550086602568626,
-0.0667647272348404,
-0.0019519292982295156,
0.014544875361025333,
-0.05117231234908104,
0.03692805394530296,
0.04285126179456711,
-0.013873263262212276,
-0.020077619701623917,
-0.024654913693666458,
-0.033878106623888016,
-0.016093922778964043,
0.033557258546352386,
-0.07484452426433563,
-0.0682879239320755,
0.1072760671377182,
0.0640767440199852,
-0.028060872107744217,
0.00003985392686445266,
0.11547274887561798,
0.020498180761933327,
-0.014133893884718418,
0.026045504957437515,
0.03940240666270256,
-0.026957549154758453,
-0.04026282578706741,
-0.019579460844397545,
0.03126783296465874,
0.006318291649222374,
-0.020881731063127518,
0.03922177106142044,
0.13457246124744415,
0.002273985417559743,
0.07923005521297455,
-0.02340165339410305,
0.07259193062782288,
-0.03136986494064331,
-0.03137630224227905,
-0.020662719383835793,
-0.009917473420500755,
-0.03275584429502487,
-0.009805697947740555,
0.024953359737992287,
0.06971631944179535,
0.017208989709615707,
0.02953927218914032,
0.031117476522922516,
-0.04321271926164627,
-0.030358297750353813,
0.008102305233478546,
0.06360729783773422,
-0.0541781410574913,
-0.12027083337306976,
0.026438524946570396,
-0.006180603988468647,
-0.11841724812984467,
0.07437176257371902,
0.010154466144740582,
-0.013473904691636562,
0.0045384131371974945,
-0.10178302973508835,
-0.009184161201119423,
0.023679131641983986,
-0.03322729095816612,
-0.012208801694214344,
0.025373946875333786,
-0.026739003136754036,
-0.14066749811172485,
0.07370471209287643,
0.04143799841403961,
-5.8314022055583337e-8,
-0.012010186910629272,
0.0026940125972032547,
0.013465210795402527,
0.07164259999990463,
0.087554931640625,
-0.0354841984808445,
0.049400992691516876,
0.05081036314368248,
0.09461341798305511,
0.004391949158161879,
-0.05975067988038063,
-0.007056990172713995,
-0.02388928271830082,
-0.01740257255733013,
-0.018806200474500656,
0.07293698191642761,
0.039589520543813705,
0.02270483411848545,
-0.008494176901876926,
-0.004625825211405754,
-0.027821611613035202,
-0.02990972250699997,
-0.005134407430887222,
0.02615213766694069,
-0.020183684304356575,
0.009161276742815971,
0.15933968126773834,
0.10767999291419983,
0.02910563163459301,
-0.029302101582288742,
0.0000767373203416355,
0.010008199140429497,
0.05599910393357277,
-0.052163418382406235,
-0.057964079082012177,
0.06096072122454643,
0.026071038097143173,
0.024005647748708725,
0.08274775743484497,
0.028495723381638527,
0.006341562140733004,
-0.02550514228641987,
-0.006041025277227163,
0.05328710377216339,
0.011801411397755146,
0.033860933035612106,
-0.016613448038697243,
0.012157062068581581,
0.04195483401417732,
0.004328821785748005,
-0.04486628249287605,
-0.05628136172890663,
-0.06896766275167465,
0.06834828108549118,
-0.016718760132789612,
-0.018593259155750275,
0.02528223767876625,
-0.049099281430244446,
-0.00013471647980622947,
0.0012299296213313937,
0.011324163526296616,
-0.02990175038576126,
0.01660102978348732,
-0.0009583838982507586
] | 0.033362 |
Returns the same object or value // The error will be caught here } ``` ### Usage with `async/await` If, within an async function, only one `await` call is to run within a context, the following pattern should be used: ```js async function fn() { await asyncLocalStorage.run(new Map(), () => { asyncLocalStorage.getStore().set('key', value); return foo(); // The return value of foo will be awaited }); } ``` In this example, the store is only available in the callback function and the functions called by `foo`. Outside of `run`, calling `getStore` will return `undefined`. ### Troubleshooting: Context loss In most cases, `AsyncLocalStorage` works without issues. In rare situations, the current store is lost in one of the asynchronous operations. If your code is callback-based, it is enough to promisify it with [`util.promisify()`][] so it starts working with native promises. If you need to use a callback-based API or your code assumes a custom thenable implementation, use the [`AsyncResource`][] class to associate the asynchronous operation with the correct execution context. Find the function call responsible for the context loss by logging the content of `asyncLocalStorage.getStore()` after the calls you suspect are responsible for the loss. When the code logs `undefined`, the last callback called is probably responsible for the context loss. ## Class: `AsyncResource` The class `AsyncResource` is designed to be extended by the embedder's async resources. Using this, users can easily trigger the lifetime events of their own resources. The `init` hook will trigger when an `AsyncResource` is instantiated. The following is an overview of the `AsyncResource` API. ```mjs import { AsyncResource, executionAsyncId } from 'node:async\_hooks'; // AsyncResource() is meant to be extended. Instantiating a // new AsyncResource() also triggers init. If triggerAsyncId is omitted then // async\_hook.executionAsyncId() is used. const asyncResource = new AsyncResource( type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false }, ); // Run a function in the execution context of the resource. This will // \* establish the context of the resource // \* trigger the AsyncHooks before callbacks // \* call the provided function `fn` with the supplied arguments // \* trigger the AsyncHooks after callbacks // \* restore the original execution context asyncResource.runInAsyncScope(fn, thisArg, ...args); // Call AsyncHooks destroy callbacks. asyncResource.emitDestroy(); // Return the unique ID assigned to the AsyncResource instance. asyncResource.asyncId(); // Return the trigger ID for the AsyncResource instance. asyncResource.triggerAsyncId(); ``` ```cjs const { AsyncResource, executionAsyncId } = require('node:async\_hooks'); // AsyncResource() is meant to be extended. Instantiating a // new AsyncResource() also triggers init. If triggerAsyncId is omitted then // async\_hook.executionAsyncId() is used. const asyncResource = new AsyncResource( type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false }, ); // Run a function in the execution context of the resource. This will // \* establish the context of the resource // \* trigger the AsyncHooks before callbacks // \* call the provided function `fn` with the supplied arguments // \* trigger the AsyncHooks after callbacks // \* restore the original execution context asyncResource.runInAsyncScope(fn, thisArg, ...args); // Call AsyncHooks destroy callbacks. asyncResource.emitDestroy(); // Return the unique ID assigned to the AsyncResource instance. asyncResource.asyncId(); // Return the trigger ID for the AsyncResource instance. asyncResource.triggerAsyncId(); ``` ### `new AsyncResource(type[, options])` \* `type` {string} The type of async event. \* `options` {Object} \* `triggerAsyncId` {number} The ID of the execution context that created this async event. \*\*Default:\*\* `executionAsyncId()`. \* `requireManualDestroy` {boolean} If set to `true`, disables `emitDestroy` when the object is garbage collected. This usually does not need to be set (even if `emitDestroy` is called manually), unless the resource's `asyncId` is retrieved and the sensitive API's `emitDestroy` is called with it. When set to `false`, the `emitDestroy` call on garbage collection | https://github.com/nodejs/node/blob/main//doc/api/async_context.md | main | nodejs | [
-0.07539411634206772,
0.034932442009449005,
-0.07463320344686508,
0.1171450987458229,
-0.04737767204642296,
-0.014916489832103252,
-0.00816156342625618,
0.02986362762749195,
0.06554034352302551,
-0.033308159559965134,
0.024681352078914642,
-0.0017168994527310133,
-0.03382464498281479,
-0.04361698403954506,
0.07708489149808884,
-0.018604673445224762,
0.018918463960289955,
-0.021627934649586678,
-0.07712104171514511,
0.014956356026232243,
0.02312346175312996,
-0.06279705464839935,
0.03774671629071236,
0.029716605320572853,
-0.021350998431444168,
-0.039510179311037064,
-0.09926546365022659,
-0.09696805477142334,
0.02061549946665764,
-0.0031495150178670883,
0.08760102093219757,
-0.0088677192106843,
-0.07161317020654678,
0.031773895025253296,
0.012335640378296375,
0.11853083968162537,
-0.03954052925109863,
-0.06732512265443802,
0.0399944931268692,
-0.002971756737679243,
0.057652492076158524,
0.08523505926132202,
-0.11055612564086914,
0.03088643215596676,
0.046533454209566116,
-0.07574902474880219,
-0.02406988851726055,
0.02778424508869648,
-0.026780275627970695,
0.007843437604606152,
0.01756885275244713,
0.09187937527894974,
-0.09012839943170547,
0.03111611120402813,
-0.022327668964862823,
0.08916370570659637,
0.04123314097523689,
0.020602239295840263,
-0.0072419773787260056,
0.03497713804244995,
0.03369801118969917,
-0.09442803263664246,
0.013609759509563446,
-0.0017631285591050982,
0.022579461336135864,
-0.00034589326241984963,
-0.013547535985708237,
-0.05714298039674759,
0.030089734122157097,
-0.019348105415701866,
0.05263873189687729,
-0.021854810416698456,
0.058356381952762604,
-0.017148131504654884,
-0.0007552611059509218,
-0.004876736085861921,
0.017248990014195442,
-0.02849644236266613,
-0.04893188551068306,
-0.00321013736538589,
0.00021022850705776364,
-0.049958471208810806,
-0.005922053940594196,
-0.047270987182855606,
0.022878894582390785,
0.031946685165166855,
-0.01693311147391796,
-0.01434742659330368,
0.03472624346613884,
0.03488294407725334,
-0.052782490849494934,
-0.042427342385053635,
-0.03339330106973648,
0.02895481325685978,
0.06854825466871262,
0.032267745584249496,
0.061239782720804214,
0.012358983047306538,
-0.005081656388938427,
-0.047584258019924164,
0.030935779213905334,
0.04188753291964531,
0.06538033485412598,
-0.04057398810982704,
0.00808692816644907,
-0.026142757385969162,
-0.06713785976171494,
-0.08312603086233139,
-0.0683852955698967,
-0.01056588627398014,
-0.06305237114429474,
0.04851381480693817,
0.05036412551999092,
0.0662810429930687,
-0.05169378221035004,
0.03743564337491989,
0.007256013341248035,
-0.0489264577627182,
0.04618963599205017,
0.11049099266529083,
0.09008648991584778,
0.058155354112386703,
0.10782283544540405,
-0.007353537250310183,
-0.039519909769296646,
0.03190735727548599,
-0.029671315103769302,
3.285823359339046e-33,
-0.06794442236423492,
-0.08151103556156158,
-0.01627003774046898,
0.015530815348029137,
0.019637946039438248,
-0.0061005596071481705,
0.05350739136338234,
-0.009450692683458328,
-0.05914657935500145,
-0.008779272437095642,
-0.013795328326523304,
0.05203847214579582,
-0.09375476837158203,
-0.045814063400030136,
0.01648128777742386,
0.004729364067316055,
0.06547638028860092,
-0.04248806834220886,
-0.01711001805961132,
0.045469895005226135,
0.02686450071632862,
0.009814470075070858,
-0.021804042160511017,
-0.017064115032553673,
0.028517872095108032,
-0.039861831814050674,
-0.04250016808509827,
0.08653293550014496,
-0.010727315209805965,
-0.007279302924871445,
0.04221636429429054,
0.01853654719889164,
-0.012482223100960255,
0.02295333333313465,
0.07008581608533859,
0.02333381213247776,
-0.018398674204945564,
0.026874728500843048,
-0.12813717126846313,
-0.12486331164836884,
-0.06487873941659927,
0.013569439761340618,
-0.008712494745850563,
0.023668671026825905,
-0.027874590829014778,
-0.15281862020492554,
-0.044218674302101135,
-0.001110694371163845,
0.044625796377658844,
0.08625469356775284,
-0.008641118183732033,
0.05367417261004448,
-0.05232662707567215,
-0.008088089525699615,
0.04477868229150772,
-0.080738864839077,
-0.0005525447195395827,
-0.057898640632629395,
0.006217679474502802,
0.03487828001379967,
0.0165049210190773,
-0.10641200095415115,
-0.06301172077655792,
0.019152460619807243,
-0.04366336762905121,
-0.003147601615637541,
-0.02933802455663681,
0.0043803369626402855,
-0.08318544924259186,
0.01172652468085289,
0.014683655463159084,
-0.012814800255000591,
-0.001211216440424323,
0.035220179706811905,
0.028082028031349182,
0.018080532550811768,
-0.08561842143535614,
-0.009050421416759491,
-0.053939953446388245,
-0.13934415578842163,
0.05404267832636833,
-0.007280861958861351,
-0.07805520296096802,
0.17724576592445374,
-0.06556856632232666,
0.12058793008327484,
0.007244347594678402,
-0.03185116499662399,
0.0925254300236702,
0.06414047628641129,
0.01385809388011694,
-0.03178943693637848,
-0.005790139082819223,
-0.05957049876451492,
0.01331618893891573,
-5.546195405530639e-33,
0.06829199939966202,
-0.09007169306278229,
-0.07289238274097443,
0.03428182005882263,
-0.014243890531361103,
-0.010322878137230873,
0.02630612812936306,
-0.0011082796845585108,
-0.04494167119264603,
-0.030985429883003235,
-0.05913930386304855,
0.03391597792506218,
0.04947059601545334,
0.10295135527849197,
0.005616370122879744,
0.03845348209142685,
0.09340227395296097,
-0.07170519232749939,
0.09772758185863495,
-0.0006349739269353449,
0.029833152890205383,
-0.02413557469844818,
-0.03687531501054764,
0.06849288940429688,
-0.07543546706438065,
0.033506348729133606,
-0.0499604158103466,
-0.043763600289821625,
-0.05510023608803749,
-0.03301098942756653,
-0.011412793770432472,
-0.028475208207964897,
-0.006255213171243668,
-0.010425366461277008,
0.05152131989598274,
-0.08107651025056839,
0.025768309831619263,
-0.01480209268629551,
-0.06554842740297318,
-0.021749222651124,
0.04411482810974121,
-0.01150976587086916,
0.003600404132157564,
-0.05891363322734833,
0.05383554846048355,
-0.013897336088120937,
0.02926541306078434,
0.00825613271445036,
0.07862252742052078,
-0.012479059398174286,
0.03392228111624718,
-0.012894506566226482,
-0.045828238129615784,
-0.03026212751865387,
-0.04752856492996216,
-0.010678205639123917,
-0.009227986447513103,
-0.047892507165670395,
0.08790343254804611,
-0.003170860931277275,
-0.003837261814624071,
-0.060169804841279984,
0.03170192241668701,
0.0007030281703919172,
-0.04461267963051796,
-0.05624546855688095,
-0.02438356913626194,
-0.046896182000637054,
0.10200546681880951,
0.04958617314696312,
0.05957911163568497,
-0.020034730434417725,
-0.035981226712465286,
-0.010164537467062473,
-0.013080147095024586,
0.009491749107837677,
-0.0835702046751976,
-0.09125377237796783,
0.09932384639978409,
0.07261709123849869,
-0.023364108055830002,
-0.0006978079909458756,
0.06179498881101608,
-0.0051568946801126,
-0.00138759333640337,
0.020220790058374405,
0.07328765094280243,
0.013635306619107723,
-0.06010834872722626,
-0.03478537127375603,
0.0591605119407177,
0.004928231239318848,
-0.1762908548116684,
-0.004830732010304928,
0.04588860645890236,
-5.2795304128494536e-8,
-0.03894314542412758,
0.05627167969942093,
-0.024593587964773178,
0.024657567963004112,
-0.009207521565258503,
-0.038641296327114105,
0.08118744194507599,
-0.07634007930755615,
0.02506524696946144,
-0.006128924433141947,
-0.0713701993227005,
-0.028754761442542076,
0.06517753005027771,
-0.029053999111056328,
-0.02255871146917343,
0.018459370359778404,
0.043023064732551575,
0.019719330593943596,
0.023456433787941933,
0.01668792963027954,
-0.025098081678152084,
0.025361711159348488,
0.0324009507894516,
-0.021728485822677612,
-0.021744918078184128,
0.0055820825509727,
0.10614202916622162,
0.1042294129729271,
0.044282156974077225,
-0.015680532902479172,
-0.011100959032773972,
0.01889577880501747,
0.10066042095422745,
-0.008683497086167336,
-0.04306967556476593,
-0.011311208829283714,
0.06927032768726349,
-0.00940710585564375,
0.08799736946821213,
0.10292019695043564,
0.039970964193344116,
-0.027232902124524117,
-0.0031627181451767683,
0.039374008774757385,
-0.04519404470920563,
0.06434216350317001,
0.08881407976150513,
0.03308184817433357,
-0.00035067228600382805,
-0.025812435895204544,
-0.00245798472315073,
-0.03837983310222626,
-0.07405205070972443,
0.034356631338596344,
-0.0006774061475880444,
-0.02890986017882824,
-0.014402744360268116,
-0.036009613424539566,
-0.019272392615675926,
-0.026265250518918037,
0.005038782022893429,
-0.08262849599123001,
-0.019220367074012756,
0.00897164549678564
] | 0.012718 |
set to `true`, disables `emitDestroy` when the object is garbage collected. This usually does not need to be set (even if `emitDestroy` is called manually), unless the resource's `asyncId` is retrieved and the sensitive API's `emitDestroy` is called with it. When set to `false`, the `emitDestroy` call on garbage collection will only take place if there is at least one active `destroy` hook. \*\*Default:\*\* `false`. Example usage: ```js class DBQuery extends AsyncResource { constructor(db) { super('DBQuery'); this.db = db; } getInfo(query, callback) { this.db.get(query, (err, data) => { this.runInAsyncScope(callback, null, err, data); }); } close() { this.db = null; this.emitDestroy(); } } ``` ### Static method: `AsyncResource.bind(fn[, type[, thisArg]])` \* `fn` {Function} The function to bind to the current execution context. \* `type` {string} An optional name to associate with the underlying `AsyncResource`. \* `thisArg` {any} Binds the given function to the current execution context. ### `asyncResource.bind(fn[, thisArg])` \* `fn` {Function} The function to bind to the current `AsyncResource`. \* `thisArg` {any} Binds the given function to execute to this `AsyncResource`'s scope. ### `asyncResource.runInAsyncScope(fn[, thisArg, ...args])` \* `fn` {Function} The function to call in the execution context of this async resource. \* `thisArg` {any} The receiver to be used for the function call. \* `...args` {any} Optional arguments to pass to the function. Call the provided function with the provided arguments in the execution context of the async resource. This will establish the context, trigger the AsyncHooks before callbacks, call the function, trigger the AsyncHooks after callbacks, and then restore the original execution context. ### `asyncResource.emitDestroy()` \* Returns: {AsyncResource} A reference to `asyncResource`. Call all `destroy` hooks. This should only ever be called once. An error will be thrown if it is called more than once. This \*\*must\*\* be manually called. If the resource is left to be collected by the GC then the `destroy` hooks will never be called. ### `asyncResource.asyncId()` \* Returns: {number} The unique `asyncId` assigned to the resource. ### `asyncResource.triggerAsyncId()` \* Returns: {number} The same `triggerAsyncId` that is passed to the `AsyncResource` constructor. ### Using `AsyncResource` for a `Worker` thread pool The following example shows how to use the `AsyncResource` class to properly provide async tracking for a [`Worker`][] pool. Other resource pools, such as database connection pools, can follow a similar model. Assuming that the task is adding two numbers, using a file named `task\_processor.js` with the following content: ```mjs import { parentPort } from 'node:worker\_threads'; parentPort.on('message', (task) => { parentPort.postMessage(task.a + task.b); }); ``` ```cjs const { parentPort } = require('node:worker\_threads'); parentPort.on('message', (task) => { parentPort.postMessage(task.a + task.b); }); ``` a Worker pool around it could use the following structure: ```mjs import { AsyncResource } from 'node:async\_hooks'; import { EventEmitter } from 'node:events'; import { Worker } from 'node:worker\_threads'; const kTaskInfo = Symbol('kTaskInfo'); const kWorkerFreedEvent = Symbol('kWorkerFreedEvent'); class WorkerPoolTaskInfo extends AsyncResource { constructor(callback) { super('WorkerPoolTaskInfo'); this.callback = callback; } done(err, result) { this.runInAsyncScope(this.callback, null, err, result); this.emitDestroy(); // `TaskInfo`s are used only once. } } export default class WorkerPool extends EventEmitter { constructor(numThreads) { super(); this.numThreads = numThreads; this.workers = []; this.freeWorkers = []; this.tasks = []; for (let i = 0; i < numThreads; i++) this.addNewWorker(); // Any time the kWorkerFreedEvent is emitted, dispatch // the next task pending in the queue, if any. this.on(kWorkerFreedEvent, () => { if (this.tasks.length > 0) { const { task, callback } = this.tasks.shift(); this.runTask(task, callback); } }); } addNewWorker() { const worker = new Worker(new URL('task\_processor.js', import.meta.url)); worker.on('message', (result) => { // In case of success: Call the callback that was passed to `runTask`, // remove the `TaskInfo` associated with the Worker, and mark it as | https://github.com/nodejs/node/blob/main//doc/api/async_context.md | main | nodejs | [
-0.023352326825261116,
0.03111192397773266,
-0.07263199239969254,
0.11765429377555847,
-0.035308755934238434,
-0.04654772952198982,
0.06521569937467575,
-0.018015198409557343,
0.09356196224689484,
-0.022776130586862564,
-0.02040478214621544,
0.017524054273962975,
-0.0019405317725613713,
-0.04189125448465347,
-0.01473237480968237,
0.0289190411567688,
0.04737159609794617,
-0.04761731997132301,
-0.07042789459228516,
-0.017775535583496094,
0.05252746120095253,
-0.009772260673344135,
0.07403317838907242,
0.00632275128737092,
0.019295113161206245,
-0.10767760872840881,
0.030017653480172157,
-0.1503894031047821,
0.03510138392448425,
-0.04329748824238777,
0.02838148921728134,
-0.035098593682050705,
-0.1570701003074646,
-0.007440726738423109,
-0.04407856613397598,
0.02253369800746441,
-0.019692834466695786,
-0.06588166207075119,
0.002150201704353094,
-0.018000952899456024,
0.031178751960396767,
0.05022450536489487,
-0.11967997252941132,
-0.06422247737646103,
0.005477734375745058,
-0.019103456288576126,
-0.07871644198894501,
-0.024624193087220192,
-0.032680314034223557,
-0.03522318974137306,
0.04879806563258171,
0.06887426227331161,
-0.015552227385342121,
0.0414184145629406,
0.0265132337808609,
0.0013621104881167412,
0.01915331743657589,
0.06287099421024323,
-0.06533677130937576,
0.0575382336974144,
0.020495887845754623,
-0.034622326493263245,
0.00024219251645263284,
0.021297164261341095,
0.04712550342082977,
-0.009721904061734676,
0.060486361384391785,
-0.024061651900410652,
0.05770740658044815,
0.04203828051686287,
-0.05004303902387619,
-0.052427224814891815,
-0.023442937061190605,
0.016509514302015305,
0.04123411327600479,
0.061483923345804214,
-0.01167258433997631,
-0.047214265912771225,
-0.038546543568372726,
0.005935505498200655,
0.010097775608301163,
-0.0682203620672226,
-0.015835577622056007,
-0.021082350984215736,
0.01010066270828247,
0.10963496565818787,
0.01674167811870575,
-0.046148959547281265,
0.02717074379324913,
0.05136958882212639,
-0.059911973774433136,
0.05881519988179207,
0.019888153299689293,
0.06873016804456711,
-0.03754955902695656,
0.04295091703534126,
0.0676577165722847,
-0.012070131488144398,
0.016043785959482193,
0.026912663131952286,
0.03125949203968048,
0.03176475316286087,
-0.017254909500479698,
0.0713067352771759,
-0.03464054688811302,
-0.08123404532670975,
-0.00511782243847847,
-0.057130102068185806,
-0.07160432636737823,
-0.013703737407922745,
0.03602242097258568,
0.023740451782941818,
0.010875189676880836,
-0.016138538718223572,
-0.05255662649869919,
0.11152402311563492,
0.05356917530298233,
-0.0034832896199077368,
-0.05648105591535568,
0.013869519345462322,
0.036555711179971695,
0.041782718151807785,
-0.0294807106256485,
0.0026451125741004944,
0.016440320760011673,
0.004136291332542896,
0.02372884377837181,
3.8896986845854565e-33,
0.048131316900253296,
-0.05491385981440544,
0.028128035366535187,
-0.030965248122811317,
0.013451188802719116,
0.03214876353740692,
-0.004580344073474407,
0.09918269515037537,
0.012441875413060188,
0.04435456544160843,
0.0914158746600151,
-0.0768137201666832,
-0.004342752508819103,
-0.05917991325259209,
0.0554206483066082,
0.00979413278400898,
0.01595141552388668,
-0.05800175666809082,
0.02824942022562027,
0.017484765499830246,
0.024194160476326942,
0.008936606347560883,
-0.0352175310254097,
0.013539155013859272,
0.015571469441056252,
0.003711073426529765,
-0.06162898987531662,
0.11046774685382843,
-0.13483914732933044,
0.016653094440698624,
-0.0021913351956754923,
0.030007436871528625,
-0.11473556607961655,
0.05091339722275734,
-0.008084763772785664,
-0.022268222644925117,
-0.09021774679422379,
0.04071754962205887,
-0.040544889867305756,
-0.08094373345375061,
0.032385531812906265,
0.04734259843826294,
-0.12873013317584991,
0.030458781868219376,
-0.03979725018143654,
-0.07727638632059097,
0.006875945255160332,
-0.04500563070178032,
0.03913586214184761,
0.00039458140963688493,
-0.0413663312792778,
0.030585722997784615,
0.06727439165115356,
0.03316221758723259,
0.11034081131219864,
0.06201542541384697,
0.06867069005966187,
-0.04321035370230675,
0.016363127157092094,
0.03717174008488655,
0.013817287981510162,
-0.08137363195419312,
-0.02393019199371338,
-0.02157435193657875,
0.010979734361171722,
0.06031351909041405,
-0.0019963120575994253,
0.008489617146551609,
-0.03136713430285454,
-0.11453026533126831,
-0.013655067421495914,
0.010714099742472172,
0.06348253041505814,
-0.0387287363409996,
0.0026162925641983747,
-0.04356662556529045,
-0.06738235056400299,
0.051091790199279785,
-0.028378738090395927,
-0.026912527158856392,
0.07203016430139542,
-0.05231810361146927,
-0.048028118908405304,
0.029503684490919113,
-0.03269849345088005,
0.05959446355700493,
-0.03244790807366371,
-0.0218338742852211,
0.021265532821416855,
0.15112188458442688,
-0.011733155697584152,
0.023741725832223892,
0.03146668151021004,
-0.032113250344991684,
-0.05616497993469238,
-5.769031665564112e-33,
0.04798441007733345,
0.0011438836809247732,
-0.09122941642999649,
0.056081634014844894,
-0.03103652037680149,
-0.0481577105820179,
-0.06595181673765182,
0.04028819501399994,
-0.060729194432497025,
-0.040946174412965775,
0.0304506067186594,
0.04555448144674301,
-0.0007636584923602641,
0.02248227596282959,
-0.004565140698105097,
0.018001725897192955,
0.02915349043905735,
-0.08198023587465286,
-0.05931960791349411,
0.047582875937223434,
0.01041108462959528,
0.0835459753870964,
0.05700932443141937,
-0.025851678103208542,
-0.06692591309547424,
-0.030515063554048538,
-0.04797227308154106,
-0.021223127841949463,
-0.014964557252824306,
0.01125337928533554,
0.00298508838750422,
0.007844770327210426,
-0.03605034574866295,
-0.008646863512694836,
-0.0161532424390316,
-0.11496175080537796,
0.016408396884799004,
0.11229091137647629,
-0.039607323706150055,
-0.045587826520204544,
0.004913829732686281,
0.034605417400598526,
-0.04685909301042557,
0.040309563279151917,
0.024302512407302856,
-0.08945155888795853,
-0.044143445789813995,
0.03690808266401291,
0.054339710623025894,
0.022437362000346184,
0.001308361766859889,
-0.06433778256177902,
0.01216514315456152,
0.0972115695476532,
0.021724741905927658,
-0.010324247181415558,
0.05338520184159279,
-0.062127381563186646,
0.1109289675951004,
0.029516784474253654,
0.0037461838219314814,
-0.05329161509871483,
-0.03249563276767731,
-0.005733406636863947,
0.013311036862432957,
-0.02094363048672676,
-0.0054465695284307,
0.06250573694705963,
0.12843698263168335,
0.009267924353480339,
0.014102841727435589,
0.03686651960015297,
-0.004030091222375631,
-0.0026286381762474775,
0.022565213963389397,
0.017786594107747078,
-0.03988915681838989,
-0.1292186975479126,
0.02752799540758133,
0.011826553381979465,
-0.035691920667886734,
-0.011560929007828236,
-0.027909856289625168,
-0.03800633177161217,
0.020317796617746353,
-0.059227097779512405,
-0.14825721085071564,
-0.02893446572124958,
-0.03881609067320824,
0.028475506231188774,
-0.028588885441422462,
-0.038358304649591446,
-0.07540373504161835,
-0.007864785380661488,
-0.005937215872108936,
-5.1515531396262304e-8,
-0.054345887154340744,
0.03479475900530815,
-0.0024640217889100313,
0.03106340952217579,
0.06632478535175323,
-0.13070718944072723,
0.03558396175503731,
0.1048736497759819,
0.016890108585357666,
-0.02244146354496479,
-0.0034154357854276896,
0.026576612144708633,
0.089305080473423,
0.026478677988052368,
0.041344355791807175,
-0.0781024694442749,
0.021062398329377174,
-0.0011194227263331413,
-0.042533911764621735,
-0.007938685826957226,
-0.07760469615459442,
-0.0667712390422821,
-0.045344121754169464,
0.007154533639550209,
0.07108331471681595,
0.008142451755702496,
0.11488562077283859,
0.07897136360406876,
0.02918272279202938,
0.009588631801307201,
-0.0662103220820427,
0.016246812418103218,
0.07015211880207062,
0.016709527000784874,
-0.10087171196937561,
0.014838790521025658,
0.035183586180210114,
-0.022077031433582306,
0.009899364784359932,
0.076654814183712,
0.03154634311795235,
-0.013059796765446663,
-0.03746756538748741,
0.05765290930867195,
-0.05668840557336807,
0.05296267196536064,
0.0383940152823925,
0.06474839150905609,
0.03230265900492668,
0.05588735267519951,
-0.03140219300985336,
-0.05473797768354416,
-0.024233317002654076,
-0.019645458087325096,
-0.0524451769888401,
-0.058503035455942154,
0.07798315584659576,
-0.0021586394868791103,
0.02532365918159485,
0.054223861545324326,
0.06933806836605072,
-0.03199565410614014,
0.030139783397316933,
-0.06560824811458588
] | 0.063938 |
const { task, callback } = this.tasks.shift(); this.runTask(task, callback); } }); } addNewWorker() { const worker = new Worker(new URL('task\_processor.js', import.meta.url)); worker.on('message', (result) => { // In case of success: Call the callback that was passed to `runTask`, // remove the `TaskInfo` associated with the Worker, and mark it as free // again. worker[kTaskInfo].done(null, result); worker[kTaskInfo] = null; this.freeWorkers.push(worker); this.emit(kWorkerFreedEvent); }); worker.on('error', (err) => { // In case of an uncaught exception: Call the callback that was passed to // `runTask` with the error. if (worker[kTaskInfo]) worker[kTaskInfo].done(err, null); else this.emit('error', err); // Remove the worker from the list and start a new Worker to replace the // current one. this.workers.splice(this.workers.indexOf(worker), 1); this.addNewWorker(); }); this.workers.push(worker); this.freeWorkers.push(worker); this.emit(kWorkerFreedEvent); } runTask(task, callback) { if (this.freeWorkers.length === 0) { // No free threads, wait until a worker thread becomes free. this.tasks.push({ task, callback }); return; } const worker = this.freeWorkers.pop(); worker[kTaskInfo] = new WorkerPoolTaskInfo(callback); worker.postMessage(task); } close() { for (const worker of this.workers) worker.terminate(); } } ``` ```cjs const { AsyncResource } = require('node:async\_hooks'); const { EventEmitter } = require('node:events'); const path = require('node:path'); const { Worker } = require('node:worker\_threads'); const kTaskInfo = Symbol('kTaskInfo'); const kWorkerFreedEvent = Symbol('kWorkerFreedEvent'); class WorkerPoolTaskInfo extends AsyncResource { constructor(callback) { super('WorkerPoolTaskInfo'); this.callback = callback; } done(err, result) { this.runInAsyncScope(this.callback, null, err, result); this.emitDestroy(); // `TaskInfo`s are used only once. } } class WorkerPool extends EventEmitter { constructor(numThreads) { super(); this.numThreads = numThreads; this.workers = []; this.freeWorkers = []; this.tasks = []; for (let i = 0; i < numThreads; i++) this.addNewWorker(); // Any time the kWorkerFreedEvent is emitted, dispatch // the next task pending in the queue, if any. this.on(kWorkerFreedEvent, () => { if (this.tasks.length > 0) { const { task, callback } = this.tasks.shift(); this.runTask(task, callback); } }); } addNewWorker() { const worker = new Worker(path.resolve(\_\_dirname, 'task\_processor.js')); worker.on('message', (result) => { // In case of success: Call the callback that was passed to `runTask`, // remove the `TaskInfo` associated with the Worker, and mark it as free // again. worker[kTaskInfo].done(null, result); worker[kTaskInfo] = null; this.freeWorkers.push(worker); this.emit(kWorkerFreedEvent); }); worker.on('error', (err) => { // In case of an uncaught exception: Call the callback that was passed to // `runTask` with the error. if (worker[kTaskInfo]) worker[kTaskInfo].done(err, null); else this.emit('error', err); // Remove the worker from the list and start a new Worker to replace the // current one. this.workers.splice(this.workers.indexOf(worker), 1); this.addNewWorker(); }); this.workers.push(worker); this.freeWorkers.push(worker); this.emit(kWorkerFreedEvent); } runTask(task, callback) { if (this.freeWorkers.length === 0) { // No free threads, wait until a worker thread becomes free. this.tasks.push({ task, callback }); return; } const worker = this.freeWorkers.pop(); worker[kTaskInfo] = new WorkerPoolTaskInfo(callback); worker.postMessage(task); } close() { for (const worker of this.workers) worker.terminate(); } } module.exports = WorkerPool; ``` Without the explicit tracking added by the `WorkerPoolTaskInfo` objects, it would appear that the callbacks are associated with the individual `Worker` objects. However, the creation of the `Worker`s is not associated with the creation of the tasks and does not provide information about when tasks were scheduled. This pool could be used as follows: ```mjs import WorkerPool from './worker\_pool.js'; import os from 'node:os'; const pool = new WorkerPool(os.availableParallelism()); let finished = 0; for (let i = 0; i < 10; i++) { pool.runTask({ a: 42, b: 100 }, (err, result) => { console.log(i, err, result); if (++finished === 10) pool.close(); }); } ``` ```cjs const WorkerPool = require('./worker\_pool.js'); const os = require('node:os'); const pool = new WorkerPool(os.availableParallelism()); let finished = 0; for (let i = 0; i < 10; i++) { pool.runTask({ a: 42, b: 100 }, (err, result) => { console.log(i, err, result); if (++finished === 10) pool.close(); }); } ``` ### Integrating `AsyncResource` with | https://github.com/nodejs/node/blob/main//doc/api/async_context.md | main | nodejs | [
-0.08510802686214447,
0.04953237250447273,
-0.0009263730607926846,
0.07246863842010498,
0.017817825078964233,
-0.03379422426223755,
-0.009673028253018856,
0.025421738624572754,
0.07444286346435547,
-0.025610079988837242,
-0.027460400015115738,
-0.008527515456080437,
-0.06440545618534088,
-0.015539164654910564,
0.034388378262519836,
-0.0571347139775753,
0.049749184399843216,
-0.025837909430265427,
-0.04766598343849182,
-0.0787370428442955,
0.0508807934820652,
-0.04126895219087601,
0.04760485142469406,
0.018928317353129387,
-0.008145460858941078,
-0.050647664815187454,
0.032469574362039566,
-0.0562901496887207,
0.018018819391727448,
0.048936180770397186,
0.01319781132042408,
-0.09799014031887054,
-0.09719394892454147,
0.004840226843953133,
0.01072173286229372,
0.140272319316864,
-0.07844501733779907,
0.0019042801577597857,
-0.05977024510502815,
-0.019906053319573402,
0.031831078231334686,
-0.00902553554624319,
-0.1196260154247284,
-0.04859953746199608,
-0.013510814867913723,
-0.06958596408367157,
-0.06916776299476624,
-0.08500729501247406,
0.007369271479547024,
-0.011679442599415779,
0.012019110843539238,
0.0033207349479198456,
0.010447691194713116,
0.0818525105714798,
0.04608828201889992,
0.03129991888999939,
0.020433973520994186,
-0.007901270873844624,
-0.0007882878417149186,
0.021114632487297058,
0.053874652832746506,
-0.11670585721731186,
0.03454151004552841,
-0.04740368202328682,
0.0711318626999855,
-0.004293719306588173,
-0.04775997996330261,
-0.025889357551932335,
-0.019420139491558075,
-0.020464720204472542,
-0.029444627463817596,
0.008755887858569622,
0.014979399740695953,
0.021936651319265366,
-0.027598213404417038,
-0.055870745331048965,
-0.0428847074508667,
-0.0259078536182642,
-0.06958409398794174,
-0.022174371406435966,
0.034867700189352036,
-0.05393371731042862,
-0.043629758059978485,
0.05226739123463631,
0.09116168320178986,
0.04934220761060715,
-0.04932203143835068,
0.0058647687546908855,
0.10210225731134415,
-0.10420065373182297,
-0.02346137724816799,
-0.012403665110468864,
-0.06460388004779816,
0.04010319337248802,
0.01182967983186245,
-0.046525511890649796,
0.007522472646087408,
0.06445016711950302,
-0.05813797935843468,
0.06714840978384018,
0.008793555200099945,
-0.039327364414930344,
0.04619511589407921,
-0.014744505286216736,
0.010657157748937607,
-0.01203029602766037,
-0.047178950160741806,
-0.018745504319667816,
-0.05965128913521767,
-0.039586033672094345,
0.02614174596965313,
0.03695330396294594,
0.04195268079638481,
0.046361811459064484,
-0.01997680962085724,
-0.033681388944387436,
0.010196725837886333,
-0.014065712690353394,
0.003150248434394598,
0.06710314005613327,
0.09947645664215088,
-0.002656839555129409,
0.004961211234331131,
-0.02596781589090824,
0.020193301141262054,
-0.0397765152156353,
0.04221300035715103,
-3.470314167129231e-34,
0.030100489035248756,
0.022712048143148422,
0.05189688503742218,
-0.00006130211113486439,
0.12755559384822845,
-0.06251214444637299,
0.018560776486992836,
0.02563411183655262,
0.01537628099322319,
-0.04205385223031044,
0.014134738594293594,
-0.004336625337600708,
0.07237443327903748,
-0.027582980692386627,
-0.032444920390844345,
-0.039635080844163895,
0.034823257476091385,
-0.014517686329782009,
0.05676289647817612,
0.05961299315094948,
0.08861994743347168,
-0.06572317332029343,
-0.05936228856444359,
0.04542836919426918,
0.03908807411789894,
-0.023981250822544098,
-0.025732291862368584,
-0.0394146628677845,
-0.0934508815407753,
0.007758387364447117,
0.02936689555644989,
0.04529748111963272,
-0.04358769580721855,
0.06314948201179504,
-0.0904555395245552,
-0.00696677528321743,
-0.03700990229845047,
0.017262829467654228,
-0.07313854992389679,
-0.07510191202163696,
0.06747236102819443,
-0.01276612188667059,
-0.04806628078222275,
0.017646638676524162,
-0.008378146216273308,
-0.0845632255077362,
-0.06465911120176315,
-0.008504558354616165,
0.14190331101417542,
0.007573449984192848,
0.03260756656527519,
-0.00601164298132062,
0.08359066396951675,
-0.03519264981150627,
0.06816692650318146,
0.056132473051548004,
0.04580723121762276,
-0.024366991594433784,
0.030197080224752426,
-0.015865949913859367,
0.022954007610678673,
-0.07159709185361862,
-0.1058727279305458,
0.08906585723161697,
-0.00617698859423399,
0.00490919454023242,
-0.05405084788799286,
-0.005849645007401705,
-0.048723842948675156,
-0.08355990797281265,
-0.03171997144818306,
0.028223512694239616,
0.019024955108761787,
0.08800476789474487,
-0.028694432228803635,
0.08688264340162277,
-0.08193451166152954,
-0.05711264908313751,
-0.13550464808940887,
-0.0305585078895092,
0.031012052670121193,
-0.0742383524775505,
-0.06525439769029617,
-0.014373020268976688,
0.08563476800918579,
0.07569710165262222,
-0.11114919930696487,
-0.02757071517407894,
0.032090380787849426,
0.11066052317619324,
-0.05241696536540985,
0.0015410595806315541,
-0.06381657719612122,
0.053388845175504684,
-0.0636267364025116,
-2.033019683799054e-33,
0.006169773638248444,
0.010037388652563095,
-0.0686926394701004,
0.04047813266515732,
0.06624788790941238,
0.09206017106771469,
0.019311828538775444,
-0.018121030181646347,
-0.07463257014751434,
0.03789123147726059,
-0.05153030902147293,
0.024436524137854576,
-0.012947723269462585,
0.05109327659010887,
0.014006108045578003,
0.06723190099000931,
-0.05295800790190697,
0.028397683054208755,
-0.04761110618710518,
0.02509230375289917,
0.010546192526817322,
0.07154287397861481,
0.03202573210000992,
0.003953561186790466,
-0.017394276335835457,
0.04267515987157822,
-0.0087852468714118,
0.01968787983059883,
-0.024890070781111717,
-0.05081180855631828,
-0.08975948393344879,
-0.05503159761428833,
-0.022049274295568466,
0.02458629384636879,
0.10892986506223679,
-0.023955216631293297,
-0.024218443781137466,
0.03539913892745972,
-0.014554310590028763,
0.02617032453417778,
0.11108290404081345,
-0.015536082908511162,
-0.03534023091197014,
0.044306084513664246,
-0.018090002238750458,
-0.02953815832734108,
-0.019466158002614975,
-0.06324544548988342,
-0.029685817658901215,
-0.027536261826753616,
0.05082995072007179,
-0.01578027941286564,
-0.036528345197439194,
0.0456509105861187,
0.012450382113456726,
0.016890056431293488,
0.058571089059114456,
-0.09941340237855911,
-0.0227374080568552,
0.016424987465143204,
-0.009775863960385323,
-0.16797854006290436,
0.1075044795870781,
0.004810727201402187,
0.025659389793872833,
-0.024248043075203896,
-0.019897788763046265,
0.023918500170111656,
0.1429353505373001,
0.04316459596157074,
-0.029784345999360085,
0.06680703908205032,
-0.01550632156431675,
-0.012082239612936974,
0.07392154633998871,
0.015228726901113987,
-0.019789204001426697,
-0.09139726310968399,
-0.017575981095433235,
0.013201285153627396,
0.011665347032248974,
-0.06267189234495163,
0.03748521953821182,
-0.06996026635169983,
0.03667203336954117,
0.03037578985095024,
0.006167169660329819,
0.08730431646108627,
-0.03340127691626549,
-0.05449254438281059,
0.004764540120959282,
0.0015937767457216978,
-0.014339616522192955,
0.008861146867275238,
-0.012071280740201473,
-5.307470374305012e-8,
0.009908366948366165,
-0.009002749808132648,
-0.046111054718494415,
-0.02785247005522251,
0.002059078775346279,
-0.1165342926979065,
-0.004305957816541195,
-0.08609052002429962,
-0.002697249874472618,
-0.01769723743200302,
-0.029708046466112137,
-0.03888162225484848,
0.10363021492958069,
0.10396572947502136,
0.056551381945610046,
-0.015873627737164497,
0.025368941947817802,
0.08956339955329895,
-0.00017315529112238437,
-0.02843271754682064,
0.046125587075948715,
0.02670064941048622,
0.028170745819807053,
0.033131860196590424,
0.033525336533784866,
0.023613430559635162,
0.026984894648194313,
0.053746163845062256,
-0.00803306046873331,
0.018665330484509468,
-0.08912096172571182,
0.035304389894008636,
-0.015763932839035988,
0.05230187624692917,
-0.057358209043741226,
0.01592779904603958,
0.008031567558646202,
-0.05322280153632164,
0.05425757169723511,
0.014374169521033764,
0.0976138561964035,
0.048237524926662445,
-0.04243151471018791,
0.035057999193668365,
0.023132992908358574,
0.007164244540035725,
-0.09862098097801208,
-0.02900412492454052,
0.037681907415390015,
-0.004000126849859953,
-0.06656499952077866,
-0.018387051299214363,
0.011240367777645588,
0.023579280823469162,
-0.017976978793740273,
0.019670046865940094,
0.017717022448778152,
-0.08801926672458649,
-0.029854651540517807,
-0.010217029601335526,
0.10619059205055237,
0.011322996579110622,
0.007655973546206951,
-0.0036366479471325874
] | 0.142216 |
= require('./worker\_pool.js'); const os = require('node:os'); const pool = new WorkerPool(os.availableParallelism()); let finished = 0; for (let i = 0; i < 10; i++) { pool.runTask({ a: 42, b: 100 }, (err, result) => { console.log(i, err, result); if (++finished === 10) pool.close(); }); } ``` ### Integrating `AsyncResource` with `EventEmitter` Event listeners triggered by an [`EventEmitter`][] may be run in a different execution context than the one that was active when `eventEmitter.on()` was called. The following example shows how to use the `AsyncResource` class to properly associate an event listener with the correct execution context. The same approach can be applied to a [`Stream`][] or a similar event-driven class. ```mjs import { createServer } from 'node:http'; import { AsyncResource, executionAsyncId } from 'node:async\_hooks'; const server = createServer((req, res) => { req.on('close', AsyncResource.bind(() => { // Execution context is bound to the current outer scope. })); req.on('close', () => { // Execution context is bound to the scope that caused 'close' to emit. }); res.end(); }).listen(3000); ``` ```cjs const { createServer } = require('node:http'); const { AsyncResource, executionAsyncId } = require('node:async\_hooks'); const server = createServer((req, res) => { req.on('close', AsyncResource.bind(() => { // Execution context is bound to the current outer scope. })); req.on('close', () => { // Execution context is bound to the scope that caused 'close' to emit. }); res.end(); }).listen(3000); ``` [`AsyncResource`]: #class-asyncresource [`EventEmitter`]: events.md#class-eventemitter [`Stream`]: stream.md#stream [`Worker`]: worker\_threads.md#class-worker [`util.promisify()`]: util.md#utilpromisifyoriginal | https://github.com/nodejs/node/blob/main//doc/api/async_context.md | main | nodejs | [
-0.06569556891918182,
0.04007228463888168,
0.023845965042710304,
0.0863913893699646,
0.03337162360548973,
-0.0720013752579689,
0.07043133676052094,
-0.000652571558021009,
0.05155015364289284,
-0.06495990604162216,
-0.09719076007604599,
0.008131048642098904,
-0.08104679733514786,
0.03476680442690849,
0.000505307805724442,
-0.008622894994914532,
0.055467039346694946,
-0.010475855320692062,
-0.0298693235963583,
-0.0487961545586586,
0.03750557079911232,
-0.0701582282781601,
-0.005692753475159407,
-0.03734152391552925,
-0.03425539284944534,
-0.019096586853265762,
-0.03527918830513954,
-0.08317215740680695,
0.05706134811043739,
0.0352625772356987,
0.021761415526270866,
-0.0810016319155693,
-0.05010749772191048,
-0.005300904158502817,
0.009843460284173489,
0.09170524775981903,
-0.0637904480099678,
-0.09388257563114166,
-0.09094495326280594,
0.006997032556682825,
0.1304856240749359,
0.04670991376042366,
-0.09290316700935364,
0.0005877234507352114,
0.010436753742396832,
-0.01904853992164135,
-0.10607189685106277,
-0.0031752544455230236,
-0.05677890405058861,
0.07265070825815201,
0.0252713430672884,
0.0016513618174940348,
0.005107120145112276,
-0.02319435589015484,
0.03018122911453247,
0.028189878910779953,
0.04687374457716942,
-0.02468571811914444,
0.01482233963906765,
-0.015956144779920578,
0.02161453478038311,
-0.08068769425153732,
0.0011176556581631303,
-0.014045068062841892,
0.056228797882795334,
-0.03853102773427963,
0.012604872696101665,
0.06700249761343002,
0.046773187816143036,
0.01817389391362667,
0.03023197501897812,
0.07666737586259842,
0.016792964190244675,
0.01702083647251129,
-0.022845959290862083,
-0.09035322815179825,
0.005731455981731415,
-0.004642589949071407,
-0.09048920124769211,
0.03291909024119377,
-0.03450361639261246,
-0.08458729833364487,
0.016889825463294983,
0.013179831206798553,
-0.0023585092276334763,
0.04910501465201378,
-0.08639287948608398,
-0.02064906619489193,
0.07229255884885788,
0.0400233194231987,
-0.14008589088916779,
0.030760830268263817,
-0.09117630869150162,
0.02552872523665428,
0.05836709216237068,
0.0578995943069458,
-0.005109579302370548,
0.04560697078704834,
-0.031094206497073174,
0.03096306137740612,
-0.017965523526072502,
0.03602094575762749,
0.030844153836369514,
0.009356017224490643,
0.06951580941677094,
-0.019562993198633194,
-0.10670235008001328,
-0.0000510009158460889,
-0.052286550402641296,
-0.016376899555325508,
0.05475751310586929,
0.022661807015538216,
0.05870332941412926,
0.02261393703520298,
-0.0031227050349116325,
0.08072680234909058,
0.054225895553827286,
-0.015472790226340294,
0.019399235025048256,
0.1429997980594635,
0.12285344302654266,
0.04738245904445648,
-0.07301071286201477,
-0.012923323549330235,
0.05662359669804573,
0.008588151074945927,
0.03602693974971771,
3.3807599565313006e-33,
0.03244056925177574,
-0.11298110336065292,
-0.015719711780548096,
0.034462668001651764,
0.053846485912799835,
0.03360743075609207,
0.04262053966522217,
-0.04104364663362503,
-0.036843862384557724,
-0.01065619383007288,
-0.03033655695617199,
0.02341521717607975,
-0.00889856368303299,
-0.11731109023094177,
0.014498085714876652,
-0.07893010973930359,
0.049522195011377335,
-0.0033175679855048656,
0.06298436969518661,
0.05447957292199135,
0.023652130737900734,
-0.0011154994135722518,
-0.07654013484716415,
0.021401207894086838,
-0.005311641376465559,
-0.07510029524564743,
-0.02617434225976467,
-0.0006849450874142349,
-0.0029194483067840338,
0.021175386384129524,
0.038714613765478134,
0.05857520550489426,
-0.053812358528375626,
0.003309959080070257,
-0.034491680562496185,
-0.007255691569298506,
-0.0206582173705101,
0.015595635399222374,
-0.08178525418043137,
-0.08774290978908539,
-0.04699001833796501,
0.06616883724927902,
-0.08632300049066544,
-0.018131215125322342,
-0.07253122329711914,
-0.12076705694198608,
0.015797249972820282,
-0.03314654156565666,
0.08820701390504837,
-0.010416137054562569,
0.0069261095486581326,
0.009144090116024017,
0.09087888896465302,
-0.028443826362490654,
0.0642700269818306,
0.05451355502009392,
0.05593709275126457,
0.020096011459827423,
-0.0257820263504982,
0.04138613119721413,
0.08057790249586105,
-0.010820760391652584,
-0.07100989669561386,
0.01159694418311119,
0.020496942102909088,
0.018230851739645004,
0.028211073949933052,
-0.023238763213157654,
0.0043505472131073475,
-0.01255070697516203,
-0.040708206593990326,
0.046941112726926804,
-0.04810590669512749,
0.023438408970832825,
0.026084961369633675,
0.06501168012619019,
-0.03744450584053993,
0.010013115592300892,
-0.12799786031246185,
-0.03627985715866089,
0.08685898035764694,
-0.011829700320959091,
-0.010802912525832653,
0.08201800286769867,
0.00827208161354065,
0.07898541539907455,
-0.028390252962708473,
0.018760742619633675,
-0.0020004825200885534,
0.025662221014499664,
0.0259346105158329,
-0.034501977264881134,
0.04747139662504196,
-0.08239678293466568,
-0.0731186717748642,
-4.5456458381794016e-33,
-0.024668950587511063,
-0.04041310399770737,
-0.07642586529254913,
0.06206624209880829,
0.042468924075365067,
0.015444887802004814,
0.0019817636348307133,
-0.07338807731866837,
-0.10067389905452728,
0.03726765513420105,
-0.04576382040977478,
0.060031067579984665,
-0.010642691515386105,
0.03343231976032257,
-0.03431999683380127,
0.0696215033531189,
-0.028812307864427567,
0.016215231269598007,
0.046706270426511765,
0.022499047219753265,
0.0021973459515720606,
0.06610308587551117,
0.09489089250564575,
-0.00930897518992424,
-0.05458100512623787,
-0.023042596876621246,
-0.020525509491562843,
-0.04678348824381828,
-0.03674548119306564,
-0.06786150485277176,
-0.06273399293422699,
-0.03015051782131195,
-0.006037438288331032,
0.03979363664984703,
0.0517813079059124,
-0.047151170670986176,
0.011626532301306725,
0.04956561326980591,
0.03652351722121239,
-0.0473751425743103,
0.10520206391811371,
-0.033017054200172424,
-0.03969723731279373,
-0.019742140546441078,
-0.02432403340935707,
0.0236104354262352,
-0.03917109966278076,
0.019911907613277435,
-0.03289596736431122,
0.010265445336699486,
-0.08649969846010208,
-0.050228770822286606,
-0.023664677515625954,
0.09629694372415543,
-0.054398201406002045,
-0.04198808968067169,
0.05785324424505234,
-0.03949526697397232,
-0.011226366274058819,
0.06340809166431427,
0.03639185056090355,
-0.06823402643203735,
0.028306344524025917,
-0.01392314862459898,
0.007396246772259474,
-0.014852470718324184,
-0.06625973433256149,
0.02706286869943142,
0.07878946512937546,
0.017350250855088234,
-0.03472575545310974,
0.07812095433473587,
-0.06182347238063812,
-0.0025292467325925827,
-0.003004786092787981,
0.022367091849446297,
-0.009598850272595882,
-0.08529765158891678,
0.02998497150838375,
0.050446685403585434,
-0.11416404694318771,
0.09112296253442764,
-0.01086849719285965,
0.04024122655391693,
0.0640215128660202,
0.05693124607205391,
0.04889456182718277,
0.01764972321689129,
-0.013681083917617798,
0.0004656391392927617,
-0.009840563870966434,
-0.045030541718006134,
-0.10696716606616974,
0.015588932670652866,
-0.037121184170246124,
-5.598989716304459e-8,
-0.02766256034374237,
0.04630788788199425,
-0.041095275431871414,
-0.00930706411600113,
0.040295373648405075,
-0.06526681035757065,
-0.012237478978931904,
0.0015741684474050999,
0.018390091136097908,
0.05360821262001991,
-0.04050293192267418,
-0.04079963639378548,
0.12917594611644745,
-0.024270163848996162,
0.0836184173822403,
-0.018798816949129105,
0.0743056982755661,
0.0229333508759737,
-0.041935794055461884,
-0.006195977330207825,
0.0768633708357811,
0.009913099929690361,
-0.044352319091558456,
0.09191492944955826,
-0.02945902943611145,
-0.015502087771892548,
0.05108639970421791,
0.00777839869260788,
0.02375124581158161,
-0.09349201619625092,
-0.08961863070726395,
0.004222049377858639,
-0.026065928861498833,
-0.03544311225414276,
-0.032081324607133865,
0.02922205626964569,
-0.03234599903225899,
-0.07459975779056549,
0.10364113748073578,
0.04097393527626991,
0.014082060195505619,
0.020012756809592247,
0.0021810370963066816,
0.08126192539930344,
-0.016025181859731674,
0.023910289630293846,
-0.02107900194823742,
0.010942797176539898,
0.02297169342637062,
0.06705741584300995,
-0.018905943259596825,
-0.01740587130188942,
-0.07602817565202713,
0.020867541432380676,
0.01605604961514473,
-0.006367677357047796,
0.018602347001433372,
-0.11466427147388458,
-0.029001299291849136,
-0.011283822357654572,
0.07734888046979904,
0.03329603001475334,
-0.047881755977869034,
-0.01729545369744301
] | 0.108342 |
# Test runner > Stability: 2 - Stable The `node:test` module facilitates the creation of JavaScript tests. To access it: ```mjs import test from 'node:test'; ``` ```cjs const test = require('node:test'); ``` This module is only available under the `node:` scheme. Tests created via the `test` module consist of a single function that is processed in one of three ways: 1. A synchronous function that is considered failing if it throws an exception, and is considered passing otherwise. 2. A function that returns a `Promise` that is considered failing if the `Promise` rejects, and is considered passing if the `Promise` fulfills. 3. A function that receives a callback function. If the callback receives any truthy value as its first argument, the test is considered failing. If a falsy value is passed as the first argument to the callback, the test is considered passing. If the test function receives a callback function and also returns a `Promise`, the test will fail. The following example illustrates how tests are written using the `test` module. ```js test('synchronous passing test', (t) => { // This test passes because it does not throw an exception. assert.strictEqual(1, 1); }); test('synchronous failing test', (t) => { // This test fails because it throws an exception. assert.strictEqual(1, 2); }); test('asynchronous passing test', async (t) => { // This test passes because the Promise returned by the async // function is settled and not rejected. assert.strictEqual(1, 1); }); test('asynchronous failing test', async (t) => { // This test fails because the Promise returned by the async // function is rejected. assert.strictEqual(1, 2); }); test('failing test using Promises', (t) => { // Promises can be used directly as well. return new Promise((resolve, reject) => { setImmediate(() => { reject(new Error('this will cause the test to fail')); }); }); }); test('callback passing test', (t, done) => { // done() is the callback function. When the setImmediate() runs, it invokes // done() with no arguments. setImmediate(done); }); test('callback failing test', (t, done) => { // When the setImmediate() runs, done() is invoked with an Error object and // the test fails. setImmediate(() => { done(new Error('callback failure')); }); }); ``` If any tests fail, the process exit code is set to `1`. ## Subtests The test context's `test()` method allows subtests to be created. It allows you to structure your tests in a hierarchical manner, where you can create nested tests within a larger test. This method behaves identically to the top level `test()` function. The following example demonstrates the creation of a top level test with two subtests. ```js test('top level test', async (t) => { await t.test('subtest 1', (t) => { assert.strictEqual(1, 1); }); await t.test('subtest 2', (t) => { assert.strictEqual(2, 2); }); }); ``` > \*\*Note:\*\* `beforeEach` and `afterEach` hooks are triggered > between each subtest execution. In this example, `await` is used to ensure that both subtests have completed. This is necessary because tests do not wait for their subtests to complete, unlike tests created within suites. Any subtests that are still outstanding when their parent finishes are cancelled and treated as failures. Any subtest failures cause the parent test to fail. ## Skipping tests Individual tests can be skipped by passing the `skip` option to the test, or by calling the test context's `skip()` method as shown in the following example. ```js // The skip option is used, but no message is provided. test('skip option', { skip: true }, (t) => { // This code is never executed. }); // The skip option is used, and a message is provided. test('skip option with message', { skip: 'this | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.11503232270479202,
0.008515949361026287,
-0.005958080291748047,
0.11243806034326553,
0.0567578487098217,
-0.0558910146355629,
-0.045724641531705856,
0.04339301213622093,
0.01071004755795002,
-0.03699905425310135,
-0.012330036610364914,
0.06870049983263016,
0.018259935081005096,
-0.047464799135923386,
0.019754178822040558,
-0.02100369520485401,
0.0020725515205413103,
0.02465691976249218,
-0.013748690485954285,
-0.02048863098025322,
0.016846586018800735,
-0.0770023912191391,
0.025523509830236435,
-0.023062868043780327,
-0.05977366864681244,
-0.0248394925147295,
-0.05789300799369812,
-0.027681075036525726,
0.04378831014037132,
-0.01006243284791708,
0.030421162024140358,
-0.020331427454948425,
-0.07225290685892105,
0.07767066359519958,
-0.06658380478620529,
0.09332757443189621,
-0.006355675403028727,
-0.06635428965091705,
-0.008521202951669693,
0.019967984408140182,
-0.0017349709523841739,
0.03580677881836891,
-0.028412548825144768,
-0.060628440231084824,
0.08105669170618057,
-0.02648484706878662,
-0.042448874562978745,
0.02822992019355297,
-0.13767662644386292,
-0.015644624829292297,
-0.03380661830306053,
-0.013198630884289742,
-0.06530711054801941,
0.014792087487876415,
-0.004539448767900467,
0.030571063980460167,
-0.005020626820623875,
0.007754138670861721,
0.026543457061052322,
0.07853711396455765,
0.032911304384469986,
-0.036690693348646164,
0.03707220032811165,
0.019545558840036392,
0.11861570179462433,
-0.04947969317436218,
-0.021841412410140038,
-0.023465391248464584,
0.0372270867228508,
0.04650339111685753,
-0.03866703063249588,
0.010750336572527885,
-0.00708183366805315,
0.024416053667664528,
0.0075020198710262775,
-0.012108341790735722,
-0.011017276905477047,
-0.036675453186035156,
-0.00778303062543273,
0.0550069697201252,
-0.05199045687913895,
-0.08398106694221497,
-0.05843406170606613,
-0.008314001373946667,
0.01642872951924801,
0.11180368810892105,
0.06864632666110992,
-0.001149556366726756,
0.017105169594287872,
0.008388850837945938,
0.010815178044140339,
-0.02987064979970455,
-0.11214689165353775,
0.0911279246211052,
0.023027831688523293,
-0.003821243764832616,
0.0754559338092804,
0.015320692211389542,
-0.004512613173574209,
-0.030102023854851723,
0.05759569630026817,
0.007386942394077778,
0.12112704664468765,
-0.032187096774578094,
-0.008596406318247318,
-0.037639912217855453,
-0.0018838453106582165,
-0.1178634837269783,
0.021300621330738068,
0.00019936662283726037,
-0.0070778070949018,
0.01899619773030281,
0.031723752617836,
0.00530111463740468,
-0.026919875293970108,
-0.037105511873960495,
-0.025083033367991447,
0.0023999069817364216,
0.05217834562063217,
0.08954482525587082,
0.07428373396396637,
0.06191132962703705,
0.06157805025577545,
-0.07367368787527084,
0.04765532165765762,
-0.005895184352993965,
0.03435152769088745,
-1.360846391895442e-34,
-0.015854807570576668,
-0.09667236357927322,
-0.015884431079030037,
0.07215452194213867,
0.03449029102921486,
-0.004859593231230974,
0.014073902741074562,
0.017438799142837524,
-0.1335156261920929,
0.023168066516518593,
0.0475224107503891,
0.014973768033087254,
0.0037275112699717283,
0.013677263632416725,
0.0245994720607996,
0.03342955932021141,
0.031143181025981903,
-0.09140373766422272,
0.04444563761353493,
0.06354448199272156,
0.07287998497486115,
-0.017635975033044815,
0.021551042795181274,
-0.014303791336715221,
0.01601279526948929,
-0.035362280905246735,
0.03387894481420517,
0.059559907764196396,
-0.061823707073926926,
0.008922915905714035,
-0.07228235900402069,
0.04334401339292526,
-0.08515403419733047,
0.07840961217880249,
0.02749442867934704,
0.01347169280052185,
-0.06868358701467514,
-0.025082044303417206,
-0.10320157557725906,
-0.00896719191223383,
-0.08953675627708435,
0.04286930337548256,
-0.03398817405104637,
0.030716706067323685,
0.02788630872964859,
-0.13226690888404846,
-0.04308469220995903,
0.006608870811760426,
0.09332838654518127,
-0.02500608004629612,
-0.037647269666194916,
0.03736444190144539,
0.019316725432872772,
-0.0447930209338665,
0.04861248657107353,
0.05555111542344093,
0.05367172881960869,
-0.04194338247179985,
-0.07472045719623566,
0.059408172965049744,
0.06506972759962082,
-0.08658560365438461,
-0.09517174959182739,
0.023152507841587067,
-0.05833856016397476,
0.037360094487667084,
-0.07765859365463257,
-0.04333530738949776,
0.02116059884428978,
0.07263954728841782,
0.029534539207816124,
0.02032468467950821,
-0.08156115561723709,
0.03485791012644768,
0.00841435231268406,
-0.018132969737052917,
-0.09253339469432831,
0.01958397589623928,
0.0012929339427500963,
-0.05560673028230667,
0.06638171523809433,
-0.08415835350751877,
-0.05780285969376564,
0.07263895869255066,
-0.0039968290366232395,
0.005016501527279615,
-0.06682608276605606,
-0.03341255709528923,
0.043241262435913086,
-0.06744277477264404,
0.03854844346642494,
0.017103664577007294,
-0.00226039276458323,
-0.04825370013713837,
-0.009699814021587372,
-2.74995074962969e-33,
-0.007580208126455545,
0.0655171200633049,
-0.07479646801948547,
0.17986884713172913,
-0.02118588611483574,
-0.06135210767388344,
0.00628258241340518,
-0.04140051454305649,
-0.007447993382811546,
0.008179296739399433,
-0.05094139650464058,
0.0015882868319749832,
0.015860335901379585,
0.06286820024251938,
-0.013298628851771355,
0.020486004650592804,
-0.06382845342159271,
-0.06720352917909622,
-0.01175029668956995,
-0.02549058012664318,
-0.00695551373064518,
0.05175643041729927,
0.03175579756498337,
-0.004865487106144428,
-0.12107475101947784,
0.024918628856539726,
-0.0541977696120739,
-0.03035169653594494,
0.026071177795529366,
-0.021410686895251274,
0.03812817484140396,
0.014438516460359097,
-0.038680944591760635,
0.05137303099036217,
0.07374164462089539,
-0.04619186744093895,
0.04247237741947174,
0.001049816026352346,
0.009573230519890785,
-0.008024480193853378,
0.10259642452001572,
0.07498932629823685,
0.051150429993867874,
-0.015998926013708115,
0.027554716914892197,
0.05851755291223526,
0.024337032809853554,
0.019260019063949585,
-0.006823638454079628,
-0.055804815143346786,
-0.047659747302532196,
-0.038581542670726776,
-0.01575879007577896,
0.05691942200064659,
-0.034925203770399094,
-0.023254796862602234,
-0.04598784074187279,
0.03321826830506325,
0.03899765759706497,
0.043049950152635574,
-0.025636957958340645,
-0.02809312380850315,
0.03052458167076111,
0.06401735544204712,
-0.0687166154384613,
-0.014353180304169655,
-0.10313649475574493,
-0.004732361063361168,
0.12070026993751526,
0.05693868175148964,
-0.002039352897554636,
0.03267982229590416,
0.007319588679820299,
-0.022628305479884148,
-0.023964524269104004,
-0.0010023928480222821,
-0.0629272386431694,
-0.11077422648668289,
0.05996048450469971,
0.030427688732743263,
-0.028910748660564423,
0.013712993822991848,
-0.018843332305550575,
0.026694662868976593,
-0.040467340499162674,
0.028378885239362717,
0.03595534712076187,
0.05022680014371872,
-0.010463301092386246,
-0.0021562373731285334,
0.0739048421382904,
0.05043567717075348,
-0.11995526403188705,
-0.038829270750284195,
-0.02189830131828785,
-5.2302368658274645e-8,
-0.04489915072917938,
-0.06056187301874161,
-0.08439835160970688,
-0.01824735477566719,
-0.04667521268129349,
-0.028235098347067833,
0.06180659309029579,
-0.04638119786977768,
0.06065365672111511,
0.03359539806842804,
-0.001203336170874536,
0.02559231035411358,
-0.012995125725865364,
-0.015417875722050667,
-0.014872861094772816,
0.05506576970219612,
-0.03751042112708092,
0.05258293077349663,
0.006501185707747936,
-0.015123063698410988,
-0.0516740120947361,
0.016429871320724487,
0.008263131603598595,
0.1242852658033371,
-0.03181307017803192,
0.04056479409337044,
0.07820708304643631,
0.12544941902160645,
-0.02904254011809826,
-0.01262129470705986,
0.002342870458960533,
0.03111856058239937,
0.02248668670654297,
-0.04076581820845604,
-0.04905508831143379,
0.07693229615688324,
0.0041146352887153625,
0.003848913125693798,
0.10640649497509003,
0.0684645026922226,
0.0038184714503586292,
0.03594019263982773,
-0.02789994329214096,
0.023555941879749298,
-0.02223369851708412,
-0.06003356724977493,
-0.030209491029381752,
-0.042382266372442245,
-0.05712747946381569,
-0.0967736542224884,
-0.0013895489973947406,
-0.03663835674524307,
-0.10868676751852036,
0.007124047260731459,
0.011885889805853367,
0.005691242404282093,
-0.015322331339120865,
-0.04441821575164795,
-0.0760369673371315,
-0.04758346825838089,
0.06792695075273514,
0.0303453728556633,
0.11872493475675583,
-0.056959398090839386
] | 0.158815 |
in the following example. ```js // The skip option is used, but no message is provided. test('skip option', { skip: true }, (t) => { // This code is never executed. }); // The skip option is used, and a message is provided. test('skip option with message', { skip: 'this is skipped' }, (t) => { // This code is never executed. }); test('skip() method', (t) => { // Make sure to return here as well if the test contains additional logic. t.skip(); }); test('skip() method with message', (t) => { // Make sure to return here as well if the test contains additional logic. t.skip('this is skipped'); }); ``` ## Rerunning failed tests The test runner supports persisting the state of the run to a file, allowing the test runner to rerun failed tests without having to re-run the entire test suite. Use the [`--test-rerun-failures`][] command-line option to specify a file path where the state of the run is stored. if the state file does not exist, the test runner will create it. the state file is a JSON file that contains an array of run attempts. Each run attempt is an object mapping successful tests to the attempt they have passed in. The key identifying a test in this map is the test file path, with the line and column where the test is defined. in a case where a test defined in a specific location is run multiple times, for example within a function or a loop, a counter will be appended to the key, to disambiguate the test runs. note changing the order of test execution or the location of a test can lead the test runner to consider tests as passed on a previous attempt, meaning `--test-rerun-failures` should be used when tests run in a deterministic order. example of a state file: ```json [ { "test.js:10:5": { "passed\_on\_attempt": 0, "name": "test 1" } }, { "test.js:10:5": { "passed\_on\_attempt": 0, "name": "test 1" }, "test.js:20:5": { "passed\_on\_attempt": 1, "name": "test 2" } } ] ``` in this example, there are two run attempts, with two tests defined in `test.js`, the first test succeeded on the first attempt, and the second test succeeded on the second attempt. When the `--test-rerun-failures` option is used, the test runner will only run tests that have not yet passed. ```bash node --test-rerun-failures /path/to/state/file ``` ## TODO tests Individual tests can be marked as flaky or incomplete by passing the `todo` option to the test, or by calling the test context's `todo()` method, as shown in the following example. These tests represent a pending implementation or bug that needs to be fixed. TODO tests are executed, but are not treated as test failures, and therefore do not affect the process exit code. If a test is marked as both TODO and skipped, the TODO option is ignored. ```js // The todo option is used, but no message is provided. test('todo option', { todo: true }, (t) => { // This code is executed, but not treated as a failure. throw new Error('this does not fail the test'); }); // The todo option is used, and a message is provided. test('todo option with message', { todo: 'this is a todo test' }, (t) => { // This code is executed. }); test('todo() method', (t) => { t.todo(); }); test('todo() method with message', (t) => { t.todo('this is a todo test and is not treated as a failure'); throw new Error('this does not fail the test'); }); ``` ## Expecting tests to fail This flips the pass/fail reporting for a specific test or suite: | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.029382510110735893,
0.06625095754861832,
0.05588700249791145,
0.08110252022743225,
0.0710849016904831,
-0.05627009645104408,
-0.025190452113747597,
-0.04076866805553436,
0.07588277012109756,
-0.04359716922044754,
0.06815757602453232,
0.03840721771121025,
-0.011600030586123466,
-0.01273304782807827,
0.06975472718477249,
-0.047288041561841965,
0.0020576443057507277,
0.01788921281695366,
0.03049602545797825,
-0.10328810662031174,
0.018075186759233475,
0.009834947064518929,
0.034082330763339996,
0.04699978977441788,
-0.06269418448209763,
-0.0342218391597271,
-0.03192640841007233,
0.007360178045928478,
0.017087776213884354,
-0.00876876711845398,
0.021310530602931976,
-0.03444267064332962,
-0.09199456870555878,
0.03239933028817177,
-0.024789758026599884,
0.07254482805728912,
0.009589416906237602,
0.020636877045035362,
-0.05396861210465431,
0.02246067300438881,
-0.05364200845360756,
-0.0008813669555820525,
-0.08748967200517654,
-0.0024054076056927443,
0.032265208661556244,
-0.11526847630739212,
-0.10689594596624374,
-0.03708344325423241,
-0.0863228514790535,
-0.03362575173377991,
0.01582983136177063,
0.013412977568805218,
-0.01953008584678173,
0.012829040177166462,
0.07487509399652481,
0.004016264341771603,
-0.032906051725149155,
0.013487027026712894,
0.02922605723142624,
0.025062501430511475,
-0.001629220205359161,
-0.06160628795623779,
-0.02473963052034378,
0.023624295368790627,
0.020388063043355942,
0.018416596576571465,
0.0002140859724022448,
-0.006746174767613411,
0.02974635548889637,
0.12853345274925232,
-0.02810671739280224,
0.001212168950587511,
-0.009790226817131042,
0.07309241592884064,
-0.027117790654301643,
0.025324055925011635,
0.029692836105823517,
-0.023453732952475548,
-0.014378690160810947,
-0.000051188322686357424,
-0.08741757273674011,
-0.13773636519908905,
-0.04164724797010422,
0.08601825684309006,
0.0008089753682725132,
0.12834936380386353,
0.003890367690473795,
0.00177358603104949,
0.050331663340330124,
-0.053511131554841995,
0.03857053443789482,
-0.07346698641777039,
-0.056767914444208145,
0.0664878562092781,
0.045429080724716187,
0.03427179157733917,
0.0028241602703928947,
-0.0136491060256958,
-0.030816033482551575,
0.024520419538021088,
0.09544500708580017,
-0.015342188067734241,
0.06699083000421524,
-0.047798119485378265,
-0.005294527858495712,
-0.04820931330323219,
0.0365399494767189,
-0.08508200198411942,
-0.022757625207304955,
0.02547210454940796,
-0.018582340329885483,
0.035046711564064026,
0.0845843181014061,
0.005295472219586372,
-0.07212916016578674,
-0.009345445781946182,
0.05300049111247063,
-0.0022339383140206337,
0.000323278596624732,
0.09988798201084137,
0.08081676810979843,
0.05326151102781296,
0.05597912520170212,
-0.035551294684410095,
0.09076745808124542,
0.01999652571976185,
0.05733710527420044,
1.3207601978224788e-33,
0.017846927046775818,
-0.06682999432086945,
-0.036291878670454025,
0.001955319195985794,
-0.003606335027143359,
0.04028845950961113,
0.03574977442622185,
0.04094640165567398,
-0.07841374725103378,
0.0548698753118515,
-0.011977327056229115,
-0.09614326804876328,
0.04006234183907509,
-0.018708698451519012,
0.005314479116350412,
0.025155015289783478,
0.055696941912174225,
-0.03638004511594772,
0.01786726526916027,
0.04201175644993782,
0.04331875964999199,
-0.025970809161663055,
-0.028646547347307205,
0.03943919762969017,
-0.045376475900411606,
0.00831903237849474,
0.02492661215364933,
-0.0024923556484282017,
-0.03424862027168274,
0.00780112948268652,
-0.05681772530078888,
0.01027572900056839,
-0.014551537111401558,
0.10429776459932327,
0.03476792201399803,
0.03358295187354088,
-0.023245012387633324,
-0.006818980909883976,
-0.06670833379030228,
-0.028417907655239105,
-0.04070901870727539,
-0.026233147829771042,
-0.06614029407501221,
0.0018588757375255227,
-0.021286698058247566,
-0.12264640629291534,
0.0022878015879541636,
0.010485494509339333,
0.10633204877376556,
0.021878335624933243,
0.06335616111755371,
0.13378772139549255,
0.06161045283079147,
-0.03912841156125069,
0.06296241283416748,
-0.008191804401576519,
-0.005316502880305052,
-0.030818941071629524,
-0.019948750734329224,
0.017835460603237152,
0.0013505194801837206,
-0.06848351657390594,
-0.06281320005655289,
0.08654851466417313,
-0.03885785862803459,
0.010827779769897461,
-0.07958470284938812,
-0.11091060191392899,
0.005142906680703163,
-0.05224180221557617,
0.008775907568633556,
-0.03805602341890335,
-0.013078986667096615,
0.04096166044473648,
0.04138682410120964,
-0.06323332339525223,
-0.02711724303662777,
0.026887984946370125,
0.06165385618805885,
-0.09433504939079285,
0.05684969574213028,
-0.11348018795251846,
-0.10362275689840317,
0.03356874734163284,
0.05095485970377922,
-0.004462522454559803,
0.017120512202382088,
-0.020045869052410126,
0.013188290409743786,
-0.09000816941261292,
0.010763110592961311,
-0.010272889398038387,
-0.02578868716955185,
-0.02325211837887764,
0.08201328665018082,
-2.9333322764617826e-33,
0.04830939695239067,
0.03388810530304909,
-0.01794460415840149,
0.06092977523803711,
-0.017297973856329918,
-0.017111018300056458,
0.07069801539182663,
-0.04168998822569847,
0.011560878716409206,
-0.07064348459243774,
-0.013551044277846813,
-0.03447920083999634,
0.01998651772737503,
0.04087047278881073,
-0.06692661345005035,
0.09245513379573822,
-0.10453091561794281,
-0.1376023292541504,
0.027876127511262894,
-0.013435742817819118,
0.013531874865293503,
0.03667886555194855,
0.021444234997034073,
0.02444772981107235,
-0.14140908420085907,
-0.010393823496997356,
-0.018748367205262184,
0.03854023665189743,
0.00883741769939661,
-0.06043040007352829,
0.07567311823368073,
0.04779496788978577,
-0.026809321716427803,
-0.00824988353997469,
0.09122515469789505,
-0.021404555067420006,
0.07906437665224075,
0.1509387195110321,
-0.035128261893987656,
0.09351063519716263,
0.08807332813739777,
0.025482503697276115,
-0.001407494070008397,
-0.01779106818139553,
0.0019149917643517256,
0.1264031082391739,
0.01933778077363968,
-0.048282019793987274,
-0.03814655542373657,
-0.004272583872079849,
-0.053737446665763855,
-0.03965255245566368,
-0.023210590705275536,
0.06475456058979034,
0.018986564129590988,
-0.032338641583919525,
-0.038625165820121765,
-0.007130716927349567,
-0.06613077968358994,
0.07860950380563736,
-0.01761033944785595,
-0.0843522772192955,
0.08223440498113632,
-0.018225086852908134,
-0.002684432314708829,
-0.01323284488171339,
-0.02023419737815857,
0.06311047822237015,
0.101002037525177,
0.03205365687608719,
-0.0497087761759758,
0.04353102669119835,
-0.03331713378429413,
-0.06931649893522263,
0.09401816129684448,
0.015037773177027702,
-0.044988684356212616,
-0.1379883587360382,
0.031416140496730804,
-0.021799826994538307,
0.056906476616859436,
-0.00553144933655858,
-0.05333040654659271,
0.03279367461800575,
-0.03781495615839958,
0.058095622807741165,
-0.07706427574157715,
0.04642114415764809,
-0.016542918980121613,
0.0036698405165225267,
0.05179893225431442,
0.019860563799738884,
0.006970497779548168,
0.005511964671313763,
-0.02057226188480854,
-5.553753013032292e-8,
-0.04759809374809265,
-0.08409757912158966,
0.010103095322847366,
-0.01909210905432701,
-0.0040825833566486835,
-0.006868002004921436,
0.006769475061446428,
-0.004025187809020281,
-0.003030718769878149,
-0.025626923888921738,
-0.011356583796441555,
0.026072606444358826,
0.023258643224835396,
-0.0022524583619087934,
-0.003191824071109295,
-0.062129512429237366,
0.02743532508611679,
0.025408394634723663,
0.0008655913989059627,
-0.02945917285978794,
-0.028526360169053078,
0.028006212785840034,
-0.01064895186573267,
0.031083326786756516,
-0.029802760109305382,
0.02806827239692211,
0.07349520176649094,
0.03460029140114784,
-0.038965579122304916,
-0.08277159184217453,
-0.040695130825042725,
0.04245557636022568,
0.026241593062877655,
-0.044594019651412964,
-0.08682044595479965,
0.0948885977268219,
0.05391645431518555,
0.03137757629156113,
0.05088353157043457,
0.03836274892091751,
0.016946803778409958,
-0.04489696025848389,
-0.01838727295398712,
-0.03088301233947277,
-0.07768058031797409,
-0.06773924082517624,
-0.0656132847070694,
-0.023462336510419846,
0.010005845688283443,
-0.062167663127183914,
-0.043945882469415665,
-0.019101550802588463,
-0.057869281619787216,
0.011870584450662136,
0.009914030320942402,
-0.02641770988702774,
0.05843773111701012,
-0.04624543339014053,
-0.05772608891129494,
0.005892580840736628,
0.07748855650424957,
-0.011829573661088943,
0.04781410098075867,
-0.04794393479824066
] | 0.072823 |
(t) => { t.todo(); }); test('todo() method with message', (t) => { t.todo('this is a todo test and is not treated as a failure'); throw new Error('this does not fail the test'); }); ``` ## Expecting tests to fail This flips the pass/fail reporting for a specific test or suite: A flagged test/test-case must throw in order to "pass"; a test/test-case that does not throw, fails. In the following, `doTheThing()` returns \_currently\_ `false` (`false` does not equal `true`, causing `strictEqual` to throw, so the test-case passes). ```js it.expectFailure('should do the thing', () => { assert.strictEqual(doTheThing(), true); }); it('should do the thing', { expectFailure: true }, () => { assert.strictEqual(doTheThing(), true); }); ``` `skip` and/or `todo` are mutually exclusive to `expectFailure`, and `skip` or `todo` will "win" when both are applied (`skip` wins against both, and `todo` wins against `expectFailure`). These tests will be skipped (and not run): ```js it.expectFailure('should do the thing', { skip: true }, () => { assert.strictEqual(doTheThing(), true); }); it.skip('should do the thing', { expectFailure: true }, () => { assert.strictEqual(doTheThing(), true); }); ``` These tests will be marked "todo" (silencing errors): ```js it.expectFailure('should do the thing', { todo: true }, () => { assert.strictEqual(doTheThing(), true); }); it.todo('should do the thing', { expectFailure: true }, () => { assert.strictEqual(doTheThing(), true); }); ``` ## `describe()` and `it()` aliases Suites and tests can also be written using the `describe()` and `it()` functions. [`describe()`][] is an alias for [`suite()`][], and [`it()`][] is an alias for [`test()`][]. ```js describe('A thing', () => { it('should work', () => { assert.strictEqual(1, 1); }); it('should be ok', () => { assert.strictEqual(2, 2); }); describe('a nested thing', () => { it('should work', () => { assert.strictEqual(3, 3); }); }); }); ``` `describe()` and `it()` are imported from the `node:test` module. ```mjs import { describe, it } from 'node:test'; ``` ```cjs const { describe, it } = require('node:test'); ``` ## `only` tests If Node.js is started with the [`--test-only`][] command-line option, or test isolation is disabled, it is possible to skip all tests except for a selected subset by passing the `only` option to the tests that should run. When a test with the `only` option is set, all subtests are also run. If a suite has the `only` option set, all tests within the suite are run, unless it has descendants with the `only` option set, in which case only those tests are run. When using [subtests][] within a `test()`/`it()`, it is required to mark all ancestor tests with the `only` option to run only a selected subset of tests. The test context's `runOnly()` method can be used to implement the same behavior at the subtest level. Tests that are not executed are omitted from the test runner output. ```js // Assume Node.js is run with the --test-only command-line option. // The suite's 'only' option is set, so these tests are run. test('this test is run', { only: true }, async (t) => { // Within this test, all subtests are run by default. await t.test('running subtest'); // The test context can be updated to run subtests with the 'only' option. t.runOnly(true); await t.test('this subtest is now skipped'); await t.test('this subtest is run', { only: true }); // Switch the context back to execute all tests. t.runOnly(false); await t.test('this subtest is now run'); // Explicitly do not run these tests. await t.test('skipped subtest 3', { only: false }); await t.test('skipped subtest 4', { skip: true }); }); // The 'only' option is not set, so this test is skipped. test('this test is not run', () => { // This code is not run. throw new | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.06418342143297195,
0.05116208270192146,
0.09452960640192032,
0.010872979648411274,
0.05338168889284134,
-0.05465751141309738,
-0.018215123564004898,
0.0293843075633049,
-0.05320751294493675,
0.008029070682823658,
-0.016685601323843002,
-0.04672708362340927,
0.029758740216493607,
0.057381995022296906,
0.050946805626153946,
-0.022522112354636192,
0.010973477736115456,
-0.007247371133416891,
0.032685864716768265,
-0.0205916166305542,
0.05236333981156349,
0.0004894146113656461,
0.07007627189159393,
0.03568786010146141,
-0.09255413711071014,
-0.03311404585838318,
0.015237495303153992,
-0.05597613379359245,
-0.035336367785930634,
-0.006589807569980621,
0.0120913190767169,
0.03679646551609039,
-0.12870101630687714,
-0.0022262686397880316,
-0.009693621657788754,
0.0602942518889904,
-0.05288846418261528,
-0.04964487627148628,
0.020420469343662262,
-0.0069382693618535995,
-0.03126929700374603,
0.008097120560705662,
-0.04322858527302742,
-0.05957989767193794,
0.09383980184793472,
-0.027763474732637405,
-0.04543650150299072,
0.033604420721530914,
-0.02462795190513134,
-0.05412685498595238,
-0.0049798148684203625,
0.037015706300735474,
0.02924075350165367,
-0.011606348678469658,
-0.05862874537706375,
0.011094982735812664,
0.01821461133658886,
0.03446417674422264,
-0.007452123332768679,
-0.021569889038801193,
0.020441250875592232,
-0.06990589201450348,
0.05494716018438339,
0.010456833988428116,
0.08792068064212799,
0.03335433080792427,
-0.016244910657405853,
0.0158573929220438,
-0.05091360956430435,
0.12423840165138245,
-0.007562349550426006,
0.03439180925488472,
0.01156505849212408,
0.057161588221788406,
0.033516332507133484,
-0.011302130296826363,
0.016302868723869324,
-0.005920756608247757,
-0.029492374509572983,
0.009967905469238758,
-0.12502740323543549,
-0.09983363002538681,
-0.025966061279177666,
-0.01740655116736889,
0.0018705608090385795,
0.07404139637947083,
0.014475218951702118,
-0.013644212856888771,
0.034215617924928665,
-0.025011124089360237,
0.04947829991579056,
-0.05035354569554329,
-0.1109146773815155,
0.11036388576030731,
0.05669041723012924,
0.02434236742556095,
-0.0014326919335871935,
0.00873180665075779,
-0.02365167625248432,
0.02900589071214199,
0.06579465419054031,
-0.010751379653811455,
0.07320494204759598,
-0.04338109493255615,
0.06470425426959991,
-0.028769781813025475,
-0.014097009785473347,
-0.11123962700366974,
0.008695608004927635,
-0.015203426592051983,
0.031873662024736404,
0.024708472192287445,
0.09609512984752655,
-0.013150842860341072,
-0.05507238581776619,
-0.04364636540412903,
0.006053005810827017,
0.05644473060965538,
-0.007361157331615686,
0.08633270859718323,
0.11541647464036942,
0.07607017457485199,
0.0024517113342881203,
-0.0012205041712149978,
0.06664001941680908,
0.06219664588570595,
0.010611330159008503,
2.168608916404574e-33,
0.06089714542031288,
-0.056405194103717804,
-0.018169773742556572,
-0.008025813847780228,
0.009088922291994095,
0.02220645733177662,
-0.04079607129096985,
0.06405744701623917,
-0.06387848407030106,
0.00028061773627996445,
0.028663719072937965,
-0.058875806629657745,
0.013880578801035881,
-0.028363987803459167,
-0.011188524775207043,
0.03989097848534584,
-0.015969138592481613,
-0.07477040588855743,
-0.02419482357800007,
0.07418254017829895,
0.0596354603767395,
-0.05090862140059471,
-0.0027041188441216946,
0.006997479125857353,
-0.08575724810361862,
-0.0004933835589326918,
0.016485050320625305,
0.053044211119413376,
-0.09227179735898972,
-0.0003833897062577307,
-0.034808337688446045,
-0.04445914179086685,
-0.036913976073265076,
0.11632043123245239,
-0.01597200334072113,
0.004550084937363863,
-0.0944368839263916,
0.03576769307255745,
-0.07715058326721191,
-0.08491445332765579,
-0.015478729270398617,
-0.005886057857424021,
-0.033502593636512756,
0.015185014344751835,
0.029730666428804398,
-0.15399442613124847,
-0.009052478708326817,
-0.00468417489901185,
0.13801459968090057,
0.016813021153211594,
0.06295228749513626,
0.004725867882370949,
0.05782381072640419,
-0.0482601672410965,
0.04697411134839058,
0.017324797809123993,
0.03791835159063339,
-0.005405016243457794,
0.0034288428723812103,
0.008169571869075298,
0.048466119915246964,
-0.09804624319076538,
-0.09964170306921005,
-0.010245151817798615,
-0.05006680637598038,
0.05284659191966057,
-0.0012508018407970667,
-0.07759308815002441,
0.01145560946315527,
-0.07257715612649918,
-0.01735675148665905,
-0.027186624705791473,
-0.12062742561101913,
0.13212022185325623,
0.00913580134510994,
-0.05953264981508255,
0.03773270919919014,
0.04340232163667679,
0.037470243871212006,
-0.10105197876691818,
0.04590209200978279,
-0.0631200298666954,
-0.03437908738851547,
0.10014240443706512,
0.027647586539387703,
0.06946160644292831,
-0.0214663278311491,
-0.06822172552347183,
-0.05914836376905441,
-0.0369100458920002,
0.033342353999614716,
0.01029624417424202,
-0.03505614772439003,
0.00010020870831795037,
0.060984816402196884,
-5.525425522377563e-33,
-0.0008437334327027202,
0.06841136515140533,
-0.031434737145900726,
0.06361723691225052,
-0.020195910707116127,
-0.04221025109291077,
0.05722516030073166,
-0.047402724623680115,
-0.014763825573027134,
-0.01679723896086216,
-0.04243398830294609,
-0.026618795469403267,
0.007472713477909565,
0.05151769518852234,
-0.08108817785978317,
-0.0054923719726502895,
0.03184647485613823,
-0.02176813781261444,
-0.017291713505983353,
-0.06316863745450974,
0.023708557710051537,
0.09217648208141327,
0.008542121388018131,
0.004827816504985094,
-0.12427762895822525,
-0.019480016082525253,
-0.011171786114573479,
0.0024117042776197195,
0.013993204571306705,
-0.05427196994423866,
0.018185153603553772,
0.016191858798265457,
-0.005671689752489328,
0.08781230449676514,
0.11180049926042557,
-0.04710322618484497,
0.08207370340824127,
0.028666270896792412,
-0.014638323336839676,
0.07383179664611816,
0.04245498776435852,
0.007689261808991432,
0.02958417870104313,
-0.014823516830801964,
-0.013328000903129578,
0.0693952739238739,
0.0027905763126909733,
-0.058513473719358444,
0.0009600532939657569,
-0.019330529496073723,
-0.016660965979099274,
-0.03134016692638397,
0.008917026221752167,
0.051070112735033035,
-0.016707487404346466,
-0.011486738920211792,
-0.08375437557697296,
-0.07268914580345154,
-0.03911710903048515,
0.04074583575129509,
-0.037410009652376175,
-0.010503244586288929,
0.06584236770868301,
0.051983825862407684,
-0.02104654535651207,
-0.028512971475720406,
-0.03668159991502762,
0.007321120239794254,
0.11626216769218445,
0.06491781026124954,
0.04790102317929268,
0.02400106005370617,
-0.028126996010541916,
-0.14290210604667664,
0.08437787741422653,
0.00930783525109291,
-0.0813697949051857,
-0.08170296996831894,
0.036706410348415375,
-0.03972158953547478,
0.023245172575116158,
-0.0691113993525505,
-0.008510183542966843,
-0.0025757402181625366,
-0.01765136420726776,
0.0016221372643485665,
-0.008730039931833744,
0.02636699564754963,
-0.05199935659766197,
0.05597661808133125,
0.05343980714678764,
0.01959485560655594,
0.013268651440739632,
-0.0096179423853755,
0.026640553027391434,
-6.517921491422385e-8,
-0.008830981329083443,
-0.07029169797897339,
-0.05981670692563057,
-0.053495775908231735,
-0.017187416553497314,
0.008162121288478374,
-0.014995051547884941,
-0.07675124704837799,
-0.03662336990237236,
0.006933669559657574,
-0.08223606646060944,
-0.017356103286147118,
-0.019868947565555573,
-0.028705140575766563,
-0.026577645912766457,
-0.062458015978336334,
-0.07292432337999344,
0.06333499401807785,
-0.04724331945180893,
-0.0015340244863182306,
-0.04650620371103287,
-0.011278796941041946,
-0.0721731036901474,
0.004540819209069014,
0.022761434316635132,
0.030617760494351387,
0.07935485243797302,
0.07189434766769409,
-0.029865574091672897,
-0.06286929547786713,
-0.006189290899783373,
-0.006811358034610748,
0.04111224785447121,
-0.09126142412424088,
-0.10820917785167694,
0.04297007992863655,
0.05546095594763756,
0.019847607240080833,
0.0900920182466507,
0.049477312713861465,
0.019082631915807724,
0.008847326040267944,
0.014681740663945675,
0.022663269191980362,
-0.0684577077627182,
-0.04635152593255043,
-0.053195592015981674,
0.001816341420635581,
-0.013017753139138222,
-0.08653820306062698,
-0.0006318699452094734,
0.026857711374759674,
-0.06666316837072372,
0.0040946099907159805,
-0.015140777453780174,
0.0023729216773062944,
0.06850962340831757,
-0.034757714718580246,
-0.0383431501686573,
-0.03066309355199337,
0.13966885209083557,
0.038592394441366196,
0.09163977950811386,
-0.01682724617421627
] | 0.08237 |
do not run these tests. await t.test('skipped subtest 3', { only: false }); await t.test('skipped subtest 4', { skip: true }); }); // The 'only' option is not set, so this test is skipped. test('this test is not run', () => { // This code is not run. throw new Error('fail'); }); describe('a suite', () => { // The 'only' option is set, so this test is run. it('this test is run', { only: true }, () => { // This code is run. }); it('this test is not run', () => { // This code is not run. throw new Error('fail'); }); }); describe.only('a suite', () => { // The 'only' option is set, so this test is run. it('this test is run', () => { // This code is run. }); it('this test is run', () => { // This code is run. }); }); ``` ## Filtering tests by name The [`--test-name-pattern`][] command-line option can be used to only run tests whose name matches the provided pattern, and the [`--test-skip-pattern`][] option can be used to skip tests whose name matches the provided pattern. Test name patterns are interpreted as JavaScript regular expressions. The `--test-name-pattern` and `--test-skip-pattern` options can be specified multiple times in order to run nested tests. For each test that is executed, any corresponding test hooks, such as `beforeEach()`, are also run. Tests that are not executed are omitted from the test runner output. Given the following test file, starting Node.js with the `--test-name-pattern="test [1-3]"` option would cause the test runner to execute `test 1`, `test 2`, and `test 3`. If `test 1` did not match the test name pattern, then its subtests would not execute, despite matching the pattern. The same set of tests could also be executed by passing `--test-name-pattern` multiple times (e.g. `--test-name-pattern="test 1"`, `--test-name-pattern="test 2"`, etc.). ```js test('test 1', async (t) => { await t.test('test 2'); await t.test('test 3'); }); test('Test 4', async (t) => { await t.test('Test 5'); await t.test('test 6'); }); ``` Test name patterns can also be specified using regular expression literals. This allows regular expression flags to be used. In the previous example, starting Node.js with `--test-name-pattern="/test [4-5]/i"` (or `--test-skip-pattern="/test [4-5]/i"`) would match `Test 4` and `Test 5` because the pattern is case-insensitive. To match a single test with a pattern, you can prefix it with all its ancestor test names separated by space, to ensure it is unique. For example, given the following test file: ```js describe('test 1', (t) => { it('some test'); }); describe('test 2', (t) => { it('some test'); }); ``` Starting Node.js with `--test-name-pattern="test 1 some test"` would match only `some test` in `test 1`. Test name patterns do not change the set of files that the test runner executes. If both `--test-name-pattern` and `--test-skip-pattern` are supplied, tests must satisfy \*\*both\*\* requirements in order to be executed. ## Extraneous asynchronous activity Once a test function finishes executing, the results are reported as quickly as possible while maintaining the order of the tests. However, it is possible for the test function to generate asynchronous activity that outlives the test itself. The test runner handles this type of activity, but does not delay the reporting of test results in order to accommodate it. In the following example, a test completes with two `setImmediate()` operations still outstanding. The first `setImmediate()` attempts to create a new subtest. Because the parent test has already finished and output its results, the new subtest is immediately marked as failed, and reported later to the {TestsStream}. The second `setImmediate()` creates an `uncaughtException` event. `uncaughtException` and `unhandledRejection` events originating from a completed | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.03887820616364479,
0.10669399797916412,
0.027822846546769142,
0.06549163907766342,
0.05561712756752968,
-0.018582923337817192,
-0.028565963730216026,
-0.015572436153888702,
0.03255762159824371,
-0.035620253533124924,
0.010287933051586151,
-0.045389510691165924,
-0.013587288558483124,
-0.01765855960547924,
0.06546889245510101,
-0.03695199638605118,
-0.015424889512360096,
-0.02263108268380165,
0.043818868696689606,
-0.07325305044651031,
0.05957672744989395,
-0.013868942856788635,
0.0716552808880806,
0.025798838585615158,
-0.07135730981826782,
-0.002401794074103236,
-0.019251074641942978,
-0.026600830256938934,
-0.0055417632684111595,
-0.01786813512444496,
-0.004131487105041742,
0.017877046018838882,
-0.10493987798690796,
0.042436178773641586,
-0.007825062610208988,
-0.01542256586253643,
-0.05153471976518631,
0.03329768404364586,
0.019604578614234924,
0.007865604013204575,
-0.02252461574971676,
0.001975333085283637,
-0.04903148114681244,
-0.01452129427343607,
0.029018325731158257,
-0.10927360504865646,
-0.09112106263637543,
-0.06238717585802078,
-0.06685591489076614,
-0.02338494546711445,
-0.005809471011161804,
-0.01439929474145174,
0.029153937473893166,
-0.004511745180934668,
0.02362009324133396,
0.03187252953648567,
0.008800758980214596,
-0.026202091947197914,
0.013706585392355919,
-0.011386321857571602,
0.0509892962872982,
-0.04674486815929413,
0.020499030128121376,
0.04524455592036247,
0.029302965849637985,
0.05320659652352333,
-0.009911961853504181,
0.01223517581820488,
0.010846832767128944,
0.09898387640714645,
-0.015337086282670498,
0.01879950426518917,
0.052142541855573654,
0.031247274950146675,
-0.013724331744015217,
0.023842275142669678,
0.030085895210504532,
-0.047570209950208664,
0.011944414116442204,
-0.006107162218540907,
-0.10018361359834671,
-0.09644963592290878,
-0.06997112184762955,
0.03508433327078819,
-0.009830858558416367,
0.15401840209960938,
0.0790291428565979,
-0.0218815840780735,
-0.047687746584415436,
-0.0640963613986969,
-0.026487288996577263,
-0.034706201404333115,
-0.06348095089197159,
0.074090376496315,
0.06821491569280624,
0.048785626888275146,
-0.01812707632780075,
-0.012658038176596165,
-0.05274682492017746,
0.015865474939346313,
0.08259715139865875,
-0.03666283190250397,
0.09414712339639664,
0.013396002352237701,
-0.032361481338739395,
-0.06377330422401428,
0.027381528168916702,
-0.09938707947731018,
0.04327806085348129,
0.023451004177331924,
-0.013168654404580593,
0.036915577948093414,
0.04739687219262123,
-0.01708688773214817,
-0.06558634340763092,
0.010312884114682674,
0.02333436906337738,
0.043168410658836365,
-0.043128952383995056,
0.14273543655872345,
0.06454549729824066,
0.08015692979097366,
0.08429671823978424,
-0.03409178927540779,
0.0835806131362915,
-0.019020531326532364,
0.02454448863863945,
-1.4671179688719886e-33,
0.08529157936573029,
-0.052439410239458084,
-0.028174616396427155,
0.016648700460791588,
0.03465129807591438,
0.019510921090841293,
0.0282317902892828,
0.07541903853416443,
-0.08942138403654099,
0.08361132442951202,
-0.01278344914317131,
-0.10063029825687408,
0.004819935187697411,
-0.019027305766940117,
0.0034056100994348526,
-0.009092018008232117,
0.0946791023015976,
-0.07468736916780472,
0.025072863325476646,
-0.0017132925568148494,
0.03759049251675606,
0.020964672788977623,
-0.0642174631357193,
-0.03157695755362511,
-0.043654415756464005,
-0.048485249280929565,
-0.013264683075249195,
0.03852521628141403,
-0.07231777906417847,
0.011900866404175758,
-0.027914926409721375,
-0.00040933239506557584,
-0.03749401867389679,
0.12835317850112915,
0.02896825596690178,
-0.031617674976587296,
-0.051710255444049835,
0.018276793882250786,
-0.06936918199062347,
-0.05335896089673042,
-0.045649509876966476,
-0.060832101851701736,
-0.026477009057998657,
-0.026149310171604156,
0.019123069941997528,
-0.08476177603006363,
0.023274816572666168,
-0.04362432286143303,
0.07683291286230087,
0.00013483954535331577,
0.034406039863824844,
0.09404458105564117,
-0.006847138050943613,
-0.0008467991719953716,
0.12155403196811676,
-0.0019935420714318752,
-0.025861123576760292,
0.016000600531697273,
0.003093164646998048,
-0.004933497402817011,
0.0010523098753765225,
-0.1423599123954773,
-0.12883612513542175,
0.03564039245247841,
-0.06148367375135422,
0.04001365602016449,
-0.07213403284549713,
-0.12252555787563324,
0.03252340853214264,
-0.046918969601392746,
-0.009365743957459927,
-0.05807140842080116,
-0.03232146054506302,
0.055649422109127045,
0.023399116471409798,
-0.02449541725218296,
0.02465628832578659,
0.0746101662516594,
0.004562955349683762,
-0.07174834609031677,
0.032968249171972275,
-0.0927577093243599,
-0.08138902485370636,
0.0809619203209877,
-0.025743480771780014,
0.05901753529906273,
0.047662343829870224,
0.009669370017945766,
0.009900274686515331,
-0.04249376058578491,
-0.0316455252468586,
-0.0019031371921300888,
-0.04070228338241577,
-0.05473696440458298,
0.06492281705141068,
-1.116617787715934e-33,
0.0277695432305336,
0.04951130226254463,
-0.03344997391104698,
0.0204334519803524,
0.010126730427145958,
-0.05072189122438431,
0.0786016657948494,
-0.02819247357547283,
-0.031469136476516724,
-0.0004492861626204103,
0.06436953693628311,
-0.021590441465377808,
-0.015363818034529686,
0.01807684451341629,
-0.08838656544685364,
0.06953020393848419,
0.005618092138320208,
-0.11195074021816254,
0.02590068057179451,
0.03302568569779396,
0.0046394928358495235,
0.08265383541584015,
0.0022015119902789593,
0.010913645848631859,
-0.08413669466972351,
0.016113735735416412,
-0.014223551377654076,
0.0423722118139267,
-0.005956178531050682,
-0.056957609951496124,
0.07243011891841888,
0.05226357653737068,
-0.025721289217472076,
0.07084950059652328,
0.08273183554410934,
-0.05987275391817093,
0.061696119606494904,
0.07622624188661575,
-0.050902772694826126,
0.06630689650774002,
0.053756266832351685,
-0.002042467473074794,
0.00956498458981514,
-0.028498336672782898,
0.022330190986394882,
0.02889815904200077,
0.06298541277647018,
-0.060922130942344666,
-0.05860724672675133,
0.011844360269606113,
-0.0318572111427784,
-0.032860130071640015,
-0.03451762720942497,
0.041672997176647186,
0.042914554476737976,
-0.057581257075071335,
-0.03389216959476471,
-0.0746273323893547,
0.023889092728495598,
0.052414942532777786,
0.023625953122973442,
-0.009446985088288784,
0.08040541410446167,
0.07075291872024536,
-0.01807224191725254,
-0.038304317742586136,
-0.10538597404956818,
0.08539411425590515,
0.06852121651172638,
0.05625100061297417,
-0.054299261420965195,
0.042586881667375565,
-0.0633150264620781,
-0.0860854759812355,
0.060085467994213104,
-0.08219031244516373,
-0.08953725546598434,
-0.10506462305784225,
0.06698711961507797,
-0.02170337177813053,
0.01586228422820568,
-0.055116016417741776,
-0.028190232813358307,
-0.0019905243534594774,
-0.012117358855903149,
0.05727629363536835,
-0.03248382359743118,
0.0815742164850235,
-0.009502450935542583,
0.012856998480856419,
0.010129661299288273,
0.042437270283699036,
-0.012158282101154327,
-0.009708006866276264,
-0.013346637599170208,
-5.581864925829905e-8,
-0.027603158727288246,
-0.029629984870553017,
0.0037457270082086325,
-0.022796105593442917,
-0.01112334430217743,
-0.03222739323973656,
0.023305462673306465,
-0.0742783397436142,
-0.0151147972792387,
-0.007639269810169935,
-0.03929907828569412,
0.05037904158234596,
0.001834301045164466,
0.016316870227456093,
-0.0018541510216891766,
-0.07580948621034622,
-0.021161193028092384,
0.044335611164569855,
0.02303488552570343,
-0.015384726226329803,
-0.03773920610547066,
0.05229843035340309,
-0.025303807109594345,
0.035149168223142624,
0.012817088514566422,
0.06704538315534592,
0.07468490302562714,
-0.08782465755939484,
0.02482404001057148,
0.03858250752091408,
-0.049788713455200195,
0.06214916706085205,
0.024139005690813065,
-0.04541786387562752,
-0.06399814784526825,
0.10249192267656326,
0.01438349299132824,
0.034875884652137756,
0.04624628275632858,
0.10427002608776093,
0.047537438571453094,
-0.019797250628471375,
-0.012353846803307533,
-0.004148149397224188,
-0.06249067559838295,
-0.07331132888793945,
-0.04632563143968582,
-0.04199070483446121,
0.027687234804034233,
-0.07881253957748413,
-0.019514350220561028,
0.012993386015295982,
-0.05638086423277855,
0.05675322562456131,
-0.00595433684065938,
0.022194212302565575,
0.0303843691945076,
-0.024699069559574127,
-0.08026709407567978,
-0.04539903625845909,
0.062237050384283066,
-0.06907571852207184,
0.056844789534807205,
-0.0031455561984330416
] | 0.063969 |
outstanding. The first `setImmediate()` attempts to create a new subtest. Because the parent test has already finished and output its results, the new subtest is immediately marked as failed, and reported later to the {TestsStream}. The second `setImmediate()` creates an `uncaughtException` event. `uncaughtException` and `unhandledRejection` events originating from a completed test are marked as failed by the `test` module and reported as diagnostic warnings at the top level by the {TestsStream}. ```js test('a test that creates asynchronous activity', (t) => { setImmediate(() => { t.test('subtest that is created too late', (t) => { throw new Error('error1'); }); }); setImmediate(() => { throw new Error('error2'); }); // The test finishes after this line. }); ``` ## Watch mode > Stability: 1 - Experimental The Node.js test runner supports running in watch mode by passing the `--watch` flag: ```bash node --test --watch ``` In watch mode, the test runner will watch for changes to test files and their dependencies. When a change is detected, the test runner will rerun the tests affected by the change. The test runner will continue to run until the process is terminated. ## Global setup and teardown > Stability: 1.0 - Early development The test runner supports specifying a module that will be evaluated before all tests are executed and can be used to setup global state or fixtures for tests. This is useful for preparing resources or setting up shared state that is required by multiple tests. This module can export any of the following: \* A `globalSetup` function which runs once before all tests start \* A `globalTeardown` function which runs once after all tests complete The module is specified using the `--test-global-setup` flag when running tests from the command line. ```cjs // setup-module.js async function globalSetup() { // Setup shared resources, state, or environment console.log('Global setup executed'); // Run servers, create files, prepare databases, etc. } async function globalTeardown() { // Clean up resources, state, or environment console.log('Global teardown executed'); // Close servers, remove files, disconnect from databases, etc. } module.exports = { globalSetup, globalTeardown }; ``` ```mjs // setup-module.mjs export async function globalSetup() { // Setup shared resources, state, or environment console.log('Global setup executed'); // Run servers, create files, prepare databases, etc. } export async function globalTeardown() { // Clean up resources, state, or environment console.log('Global teardown executed'); // Close servers, remove files, disconnect from databases, etc. } ``` If the global setup function throws an error, no tests will be run and the process will exit with a non-zero exit code. The global teardown function will not be called in this case. ## Running tests from the command line The Node.js test runner can be invoked from the command line by passing the [`--test`][] flag: ```bash node --test ``` By default, Node.js will run all files matching these patterns: \* `\*\*/\*.test.{cjs,mjs,js}` \* `\*\*/\*-test.{cjs,mjs,js}` \* `\*\*/\*\_test.{cjs,mjs,js}` \* `\*\*/test-\*.{cjs,mjs,js}` \* `\*\*/test.{cjs,mjs,js}` \* `\*\*/test/\*\*/\*.{cjs,mjs,js}` Unless [`--no-strip-types`][] is supplied, the following additional patterns are also matched: \* `\*\*/\*.test.{cts,mts,ts}` \* `\*\*/\*-test.{cts,mts,ts}` \* `\*\*/\*\_test.{cts,mts,ts}` \* `\*\*/test-\*.{cts,mts,ts}` \* `\*\*/test.{cts,mts,ts}` \* `\*\*/test/\*\*/\*.{cts,mts,ts}` Alternatively, one or more glob patterns can be provided as the final argument(s) to the Node.js command, as shown below. Glob patterns follow the behavior of [`glob(7)`][]. The glob patterns should be enclosed in double quotes on the command line to prevent shell expansion, which can reduce portability across systems. ```bash node --test "\*\*/\*.test.js" "\*\*/\*.spec.js" ``` Matching files are executed as test files. More information on the test file execution can be found in the [test runner execution model][] section. ### Test runner execution model When process-level test isolation is enabled, each matching test file is executed in | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.023775408044457436,
-0.007700735237449408,
0.015744220465421677,
0.11310292780399323,
0.09711746871471405,
-0.0024590801913291216,
-0.027622241526842117,
0.054148007184267044,
0.01500598806887865,
-0.016292918473482132,
-0.014869773760437965,
0.010894188657402992,
0.041636738926172256,
0.009376546368002892,
-0.0347251370549202,
-0.048725951462984085,
0.006968069821596146,
-0.04294204339385033,
-0.007717804983258247,
-0.011327807791531086,
0.05350363999605179,
-0.051203448325395584,
0.08870219439268112,
0.02582290954887867,
-0.039772339165210724,
-0.045056771486997604,
-0.05587167292833328,
-0.036190178245306015,
0.007836936041712761,
0.020759256556630135,
0.017809854820370674,
-0.07325058430433273,
-0.09708903729915619,
-0.00007785860361764207,
-0.013981406576931477,
0.05829152464866638,
0.011520922183990479,
-0.043174777179956436,
-0.04693830385804176,
-0.008057892322540283,
0.09103870391845703,
0.008032410405576229,
-0.03928355127573013,
-0.025027506053447723,
0.008935193531215191,
-0.08169581741094589,
-0.053732577711343765,
-0.03279499337077141,
-0.08678951114416122,
0.02039564959704876,
-0.016603102907538414,
-0.04481394961476326,
0.0395863801240921,
0.0026394613087177277,
0.021396297961473465,
0.03264493867754936,
0.015872586518526077,
0.016168266534805298,
0.023219959810376167,
0.04216672480106354,
0.019333675503730774,
-0.048759955912828445,
-0.04625961184501648,
-0.03285331651568413,
0.07548771798610687,
0.02077546715736389,
0.001635949476622045,
0.030492516234517097,
0.05695845186710358,
0.05066649988293648,
0.006495664827525616,
0.05029672011733055,
0.01075347326695919,
0.05827389657497406,
-0.035751309245824814,
0.008563412353396416,
-0.04216299206018448,
-0.03127484396100044,
-0.057146042585372925,
-0.026103537529706955,
-0.05944536253809929,
-0.1049547791481018,
-0.04721039906144142,
0.023343458771705627,
0.017319679260253906,
0.11702416837215424,
0.06785443425178528,
-0.0331251323223114,
-0.000010548003956500906,
0.0008836689521558583,
-0.05108458176255226,
-0.010208960622549057,
-0.08498873561620712,
0.09767492860555649,
0.011713027954101562,
0.03385614976286888,
0.047487929463386536,
0.021605446934700012,
0.0423935130238533,
-0.011689689010381699,
0.09582889080047607,
0.06216229125857353,
0.04547770693898201,
0.03259135037660599,
0.009042572230100632,
-0.051485899835824966,
-0.027293948456645012,
-0.06095664203166962,
0.006986037362366915,
0.014875019900500774,
0.02873322181403637,
0.01144418679177761,
0.07742232829332352,
-0.001376281725242734,
0.00045706258970312774,
0.07604000717401505,
-0.02293814718723297,
0.05320169776678085,
-0.017671359702944756,
0.1373278796672821,
0.11382550746202469,
0.03469536080956459,
0.03786340355873108,
-0.05548160895705223,
0.13953416049480438,
-0.023072542622685432,
0.03417722135782242,
1.0139792229673974e-33,
0.04878880828619003,
-0.09490159898996353,
-0.052490536123514175,
0.09401612728834152,
0.05476982519030571,
0.03591858968138695,
-0.006900612730532885,
0.03558744117617607,
-0.07391136884689331,
0.014481956139206886,
0.03860350325703621,
-0.09935811907052994,
-0.0024838531389832497,
-0.002402037847787142,
-0.01532821636646986,
-0.00312267174012959,
0.05550024285912514,
-0.0770992860198021,
0.0419965498149395,
0.03525876998901367,
-0.005861647427082062,
-0.04004937782883644,
-0.039841074496507645,
-0.07988394796848297,
-0.05541453883051872,
-0.024932589381933212,
-0.011649549007415771,
0.06158105656504631,
-0.007630820386111736,
0.01470071543008089,
-0.03837422654032707,
0.04356205463409424,
-0.056799352169036865,
0.07891266793012619,
-0.01329036708921194,
-0.027079787105321884,
-0.06309440732002258,
-0.0028442256152629852,
-0.07319219410419464,
-0.01575736328959465,
-0.06557776778936386,
0.031578708440065384,
-0.07323325425386429,
-0.03697914630174637,
0.04825899377465248,
-0.15279726684093475,
-0.06780146807432175,
-0.00026052139583043754,
0.07987172901630402,
0.018262239173054695,
-0.02647996135056019,
0.07611077278852463,
0.0676167830824852,
-0.08303836733102798,
0.019505023956298828,
0.05327768251299858,
0.06625913828611374,
-0.07101642340421677,
-0.05192470923066139,
0.015481296926736832,
0.05060312896966934,
-0.01655043289065361,
-0.07737033814191818,
0.043364912271499634,
-0.002219907706603408,
0.011310975067317486,
-0.01512348186224699,
-0.07825016975402832,
-0.028595197945833206,
-0.03369520232081413,
-0.057334497570991516,
-0.039802733808755875,
-0.023685811087489128,
0.0686408057808876,
0.004945040680468082,
-0.03313819691538811,
0.00346531649120152,
0.0421726293861866,
-0.0060332161374390125,
-0.09836339205503464,
0.06154264509677887,
-0.08013589680194855,
0.0033790746238082647,
0.054944247007369995,
-0.08528002351522446,
0.004125416744500399,
-0.05518795922398567,
-0.02781686559319496,
-0.026617227122187614,
0.03427070006728172,
0.06069805473089218,
0.049771904945373535,
0.034972403198480606,
-0.08150380104780197,
0.0067476131953299046,
-2.5087012889455473e-33,
-0.021506138145923615,
0.023510979488492012,
-0.08213689923286438,
0.04589783772826195,
0.08168423175811768,
-0.09979551285505295,
0.047734566032886505,
-0.022026341408491135,
-0.029331235215067863,
0.025643132627010345,
-0.03420630097389221,
-0.044972602277994156,
-0.06608385592699051,
0.004056663252413273,
-0.12030123174190521,
0.0026681101880967617,
0.007471871562302113,
-0.05264921486377716,
0.05540326237678528,
-0.03915245085954666,
0.04420550912618637,
0.05830378457903862,
0.1039961725473404,
0.007573398295789957,
-0.026596534997224808,
0.006846535485237837,
0.01795368082821369,
0.005463432054966688,
-0.07324133813381195,
-0.0537969172000885,
0.0696600154042244,
0.06861348450183868,
0.03946179524064064,
0.10210413485765457,
0.13581450283527374,
-0.036681052297353745,
0.08806181699037552,
-0.024395769461989403,
0.00027472496731206775,
0.005752920173108578,
0.07636260241270065,
0.08521208167076111,
0.0523325651884079,
-0.024780385196208954,
0.07677755504846573,
0.06351424753665924,
-0.027410389855504036,
0.0003310551692266017,
-0.020390285179018974,
-0.030685480684041977,
-0.0662602111697197,
-0.03104332834482193,
-0.015690263360738754,
0.05663994699716568,
0.0333973728120327,
-0.02765970304608345,
-0.0031249348539859056,
0.01335584744811058,
0.00816136971116066,
0.05889985337853432,
0.006492855958640575,
-0.013026385568082333,
-0.04041510820388794,
0.036480922251939774,
0.014090846292674541,
-0.01618736796081066,
-0.06091748923063278,
0.05982175096869469,
0.1267005056142807,
0.06949352473020554,
-0.037038177251815796,
0.041686128824949265,
-0.0688638910651207,
-0.08976417779922485,
0.03143194690346718,
-0.027852725237607956,
-0.0824308693408966,
-0.06934120506048203,
-0.0044181146658957005,
-0.022934189066290855,
0.004927614703774452,
0.04453670606017113,
-0.06359785050153732,
0.0011134903179481626,
0.03306795284152031,
0.08772287517786026,
0.007097302004694939,
0.046887774020433426,
-0.01449978444725275,
-0.02107745222747326,
0.021936915814876556,
0.01713922619819641,
-0.11377695947885513,
0.0037033443804830313,
-0.00251585990190506,
-5.454624130152297e-8,
-0.032480161637067795,
-0.006869974080473185,
-0.08288456499576569,
-0.03229330852627754,
-0.01185253169387579,
-0.09716014564037323,
-0.036932285875082016,
-0.026818228885531425,
0.002229696838185191,
0.009475593455135822,
-0.066676564514637,
-0.010056516155600548,
0.023762285709381104,
0.019352592527866364,
0.025780795142054558,
-0.12617063522338867,
0.010493867099285126,
0.06862267106771469,
-0.05885559692978859,
-0.010851352475583553,
0.06629202514886856,
0.03596300631761551,
-0.025271054357290268,
0.042318619787693024,
-0.03897897154092789,
-0.018777886405587196,
0.06752993911504745,
0.0560331754386425,
-0.0037514499854296446,
-0.05407588556408882,
-0.04517607018351555,
0.031902655959129333,
0.04282035306096077,
-0.036745913326740265,
-0.027608852833509445,
0.08252420276403427,
0.02092563547194004,
-0.010015026666224003,
0.05668485537171364,
0.06399549543857574,
0.042185552418231964,
0.004966941196471453,
0.020892834290862083,
0.031061654910445213,
-0.02820340357720852,
-0.08945579826831818,
-0.030583443120121956,
0.030986521393060684,
0.04538802057504654,
-0.05832068249583244,
-0.031125910580158234,
-0.02509922720491886,
-0.0308969896286726,
-0.029345102608203888,
0.03251789137721062,
-0.0014873744221404195,
0.018267977982759476,
-0.06746145337820053,
-0.08429796993732452,
-0.029459796845912933,
0.1404370218515396,
0.032180942595005035,
0.03487781435251236,
-0.022372771054506302
] | 0.090191 |
across systems. ```bash node --test "\*\*/\*.test.js" "\*\*/\*.spec.js" ``` Matching files are executed as test files. More information on the test file execution can be found in the [test runner execution model][] section. ### Test runner execution model When process-level test isolation is enabled, each matching test file is executed in a separate child process. The maximum number of child processes running at any time is controlled by the [`--test-concurrency`][] flag. If the child process finishes with an exit code of 0, the test is considered passing. Otherwise, the test is considered to be a failure. Test files must be executable by Node.js, but are not required to use the `node:test` module internally. Each test file is executed as if it was a regular script. That is, if the test file itself uses `node:test` to define tests, all of those tests will be executed within a single application thread, regardless of the value of the `concurrency` option of [`test()`][]. When process-level test isolation is disabled, each matching test file is imported into the test runner process. Once all test files have been loaded, the top level tests are executed with a concurrency of one. Because the test files are all run within the same context, it is possible for tests to interact with each other in ways that are not possible when isolation is enabled. For example, if a test relies on global state, it is possible for that state to be modified by a test originating from another file. #### Child process option inheritance When running tests in process isolation mode (the default), spawned child processes inherit Node.js options from the parent process, including those specified in [configuration files][]. However, certain flags are filtered out to enable proper test runner functionality: \* `--test` - Prevented to avoid recursive test execution \* `--experimental-test-coverage` - Managed by the test runner \* `--watch` - Watch mode is handled at the parent level \* `--experimental-default-config-file` - Config file loading is handled by the parent \* `--test-reporter` - Reporting is managed by the parent process \* `--test-reporter-destination` - Output destinations are controlled by the parent \* `--experimental-config-file` - Config file paths are managed by the parent All other Node.js options from command line arguments, environment variables, and configuration files are inherited by the child processes. ## Collecting code coverage > Stability: 1 - Experimental When Node.js is started with the [`--experimental-test-coverage`][] command-line flag, code coverage is collected and statistics are reported once all tests have completed. If the [`NODE\_V8\_COVERAGE`][] environment variable is used to specify a code coverage directory, the generated V8 coverage files are written to that directory. Node.js core modules and files within `node\_modules/` directories are, by default, not included in the coverage report. However, they can be explicitly included via the [`--test-coverage-include`][] flag. By default all the matching test files are excluded from the coverage report. Exclusions can be overridden by using the [`--test-coverage-exclude`][] flag. If coverage is enabled, the coverage report is sent to any [test reporters][] via the `'test:coverage'` event. Coverage can be disabled on a series of lines using the following comment syntax: ```js /\* node:coverage disable \*/ if (anAlwaysFalseCondition) { // Code in this branch will never be executed, but the lines are ignored for // coverage purposes. All lines following the 'disable' comment are ignored // until a corresponding 'enable' comment is encountered. console.log('this is never executed'); } /\* node:coverage enable \*/ ``` Coverage can also be disabled for a specified number of lines. After the specified number of lines, coverage will be automatically reenabled. If the number of lines is not explicitly provided, a single line | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.03804146870970726,
-0.03117540292441845,
-0.030411247164011,
0.05900036543607712,
0.09068571031093597,
-0.05560947582125664,
-0.052245207130908966,
0.0031250184401869774,
0.0422530472278595,
0.019077250733971596,
-0.027634086087346077,
0.07279045879840851,
-0.02556515485048294,
-0.020845692604780197,
0.05380428954958916,
-0.01924183778464794,
0.0280100479722023,
-0.02275785058736801,
0.023084130138158798,
-0.005609628278762102,
-0.02457347884774208,
-0.018988097086548805,
0.07779067754745483,
-0.02385740354657173,
-0.06781410425901413,
-0.006995931267738342,
-0.056029416620731354,
-0.046588752418756485,
-0.00042226543882861733,
0.0013449813704937696,
0.06883072108030319,
-0.04061589017510414,
-0.048576295375823975,
0.05250919610261917,
0.0000829874406917952,
0.05932335928082466,
0.032404061406850815,
-0.0854765996336937,
-0.0916486382484436,
0.04145272448658943,
0.0688076764345169,
0.06235729157924652,
-0.07504779100418091,
-0.0779246911406517,
0.07848336547613144,
-0.04549257457256317,
-0.14529086649417877,
-0.03192366659641266,
-0.08285867422819138,
-0.006400886923074722,
0.017839478328824043,
-0.035699907690286636,
0.00007038855255814269,
0.005435504950582981,
-0.05745815485715866,
0.0029683334287256002,
0.05849362164735794,
-0.04546818137168884,
0.07097288966178894,
0.11146629601716995,
-0.006980598904192448,
-0.037504833191633224,
0.005934074055403471,
-0.019586147740483284,
0.08761492371559143,
0.03552905470132828,
-0.02678806148469448,
-0.045333851128816605,
0.051615625619888306,
0.016746271401643753,
-0.0039114197716116905,
0.038460493087768555,
0.0012199676129966974,
0.004365768749266863,
-0.04516267031431198,
0.009649098850786686,
-0.03922427445650101,
-0.041557155549526215,
-0.035117097198963165,
-0.011756048537790775,
-0.09630561619997025,
-0.08168814331293106,
-0.01912614330649376,
-0.05297819525003433,
-0.0343468002974987,
0.13973656296730042,
0.03142808377742767,
0.003880611388012767,
0.012250917963683605,
0.048719797283411026,
-0.03503064066171646,
0.01233491487801075,
-0.06193162128329277,
0.08064822107553482,
0.07373664528131485,
0.016780586913228035,
-0.005835676100105047,
0.0486551932990551,
0.014042206108570099,
-0.055772848427295685,
0.07078998535871506,
-0.034785494208335876,
0.07576209306716919,
-0.0030959134455770254,
0.0044428324326872826,
0.011245335452258587,
-0.017171412706375122,
-0.10383656620979309,
0.011280185543000698,
-0.034346893429756165,
0.03677976503968239,
-0.0036083825398236513,
0.05635872483253479,
0.01834576018154621,
-0.06109590083360672,
-0.012419484555721283,
0.07068421691656113,
-0.014703151769936085,
0.017040275037288666,
0.20459774136543274,
0.0475597158074379,
0.06439967453479767,
-0.015942098572850227,
-0.025376692414283752,
0.025361347943544388,
-0.012849045917391777,
0.017782485112547874,
3.563326351499495e-33,
-0.005748106632381678,
-0.09496720135211945,
0.01961023174226284,
0.05173559486865997,
0.01659390889108181,
-0.002289645839482546,
0.009449029341340065,
0.03950989618897438,
-0.1049795001745224,
0.041788242757320404,
-0.006021969486027956,
-0.039937958121299744,
0.029310042038559914,
-0.023033687844872475,
0.0322820320725441,
0.05705605447292328,
0.057428862899541855,
-0.04997245594859123,
0.02442580834031105,
0.03811280056834221,
0.06597264111042023,
-0.0338863879442215,
-0.07102830708026886,
0.02388969250023365,
-0.03432552516460419,
-0.01917286217212677,
0.016545617952942848,
0.0177011676132679,
-0.010752332396805286,
0.007564818486571312,
-0.03644812852144241,
0.03062133863568306,
-0.06330005824565887,
0.09553903341293335,
-0.0018111274112015963,
0.05899796634912491,
-0.00970643013715744,
0.03283453732728958,
-0.05218806490302086,
0.036020729690790176,
-0.0802207887172699,
-0.006789550185203552,
-0.02906237728893757,
0.03403782472014427,
-0.02249203622341156,
-0.10451333969831467,
-0.059877824038267136,
-0.010903805494308472,
0.06128740310668945,
0.028752053156495094,
0.0003697150095831603,
0.03649049252271652,
0.03773971647024155,
-0.0820654109120369,
0.03884704038500786,
0.06263122707605362,
0.024449380114674568,
-0.08584361523389816,
-0.01306017767637968,
0.07188817113637924,
0.05440983176231384,
-0.06167256087064743,
-0.09674758464097977,
0.04656582325696945,
-0.03499549254775047,
0.013908083550632,
-0.015029960311949253,
-0.05051276832818985,
-0.008613521233201027,
0.07071664929389954,
-0.01019330695271492,
0.007258121389895678,
-0.044957634061574936,
-0.01879912056028843,
0.03428622707724571,
-0.024754125624895096,
0.019116250798106194,
0.014812519773840904,
-0.035114798694849014,
-0.0050036427564918995,
0.048578839749097824,
-0.0040089963003993034,
-0.04476580396294594,
0.016342023387551308,
0.010714502073824406,
-0.00429933425039053,
-0.07478383183479309,
-0.013813277706503868,
-0.011720518581569195,
-0.08769319951534271,
0.13230150938034058,
0.01313889678567648,
-0.03711547330021858,
-0.07395577430725098,
-0.00879858247935772,
-4.852744839357678e-33,
-0.006406026892364025,
0.05088822916150093,
-0.10193853825330734,
0.10631387680768967,
0.020924707874655724,
-0.07017554342746735,
-0.008226629346609116,
-0.08800451457500458,
-0.04311932995915413,
0.053232595324516296,
-0.06146344915032387,
-0.002976306714117527,
0.009106436744332314,
0.04804594814777374,
-0.06241348385810852,
-0.019344041123986244,
-0.022750159725546837,
-0.03540533408522606,
0.07824510335922241,
-0.04155058413743973,
-0.002354099415242672,
0.024159740656614304,
0.09977076947689056,
-0.017164764925837517,
-0.08184279501438141,
-0.07076264172792435,
-0.045732609927654266,
-0.05884125456213951,
0.029552750289440155,
-0.017273036763072014,
0.01803293637931347,
0.034488093107938766,
-0.000726891215890646,
0.10720194876194,
0.07308966666460037,
-0.05353229120373726,
-0.03047691285610199,
0.0188729427754879,
0.09914980083703995,
-0.01487981341779232,
0.014277591370046139,
0.051484767347574234,
0.008417711593210697,
0.012436015531420708,
0.03382791951298714,
0.08087319135665894,
0.01733746938407421,
-0.02368728630244732,
-0.06951171159744263,
-0.03594648465514183,
-0.07640990614891052,
0.02984374761581421,
0.005627473816275597,
0.0889451652765274,
-0.05357056111097336,
-0.055408526211977005,
-0.055482279509305954,
0.048728540539741516,
-0.025004668161273003,
0.014170440845191479,
0.10352127254009247,
0.017786089330911636,
-0.029280168935656548,
0.08323173969984055,
-0.06176478788256645,
-0.05115693062543869,
-0.042110610753297806,
-0.02684435248374939,
0.045999109745025635,
0.01135710347443819,
-0.02810123935341835,
0.06750544905662537,
-0.01899489015340805,
0.024419020861387253,
-0.055246539413928986,
0.00027513669920153916,
-0.049966491758823395,
-0.08448661118745804,
-0.006976007483899593,
0.03151385113596916,
-0.07294996082782745,
0.0643642246723175,
-0.07562627643346786,
0.01508371252566576,
0.009565138258039951,
0.026683302596211433,
0.0009217874612659216,
0.028508959338068962,
-0.008900493383407593,
0.026667559519410133,
0.09704837203025818,
0.0022797510027885437,
-0.06612347811460495,
-0.11265867203474045,
-0.042030006647109985,
-5.3987172066172207e-8,
0.01677621714770794,
0.027858640998601913,
-0.08272156119346619,
-0.011110462248325348,
-0.05577072501182556,
-0.015181069262325764,
0.07141958177089691,
-0.015811510384082794,
0.055579401552677155,
0.12751129269599915,
-0.005813946481794119,
-0.014287833124399185,
0.004385704640299082,
0.038169749081134796,
0.0005230826791375875,
0.01687328889966011,
0.05033155903220177,
0.03497439995408058,
0.03401969000697136,
0.046906087547540665,
-0.027973201125860214,
0.07760889083147049,
-0.011535617522895336,
0.12484800815582275,
-0.06074295565485954,
0.031666141003370285,
0.10139628499746323,
0.045896194875240326,
-0.05031406879425049,
-0.047797080129384995,
-0.027394643053412437,
-0.01328659150749445,
-0.03409678861498833,
-0.023671485483646393,
-0.05664996802806854,
0.06867170333862305,
-0.016995863988995552,
0.07935250550508499,
0.08655530959367752,
0.06120011582970619,
-0.06145867332816124,
0.0037525277584791183,
0.029521947726607323,
0.019739050418138504,
-0.028278706595301628,
-0.049908071756362915,
-0.04737918823957443,
0.022759830579161644,
-0.031208783388137817,
-0.06620035320520401,
0.04235830530524254,
-0.03421500325202942,
-0.08549420535564423,
-0.006837585009634495,
0.019481390714645386,
0.04173988476395607,
0.02873593010008335,
-0.09252482652664185,
-0.07226897776126862,
-0.01602073200047016,
0.08078542351722717,
-0.0006075271521694958,
0.014578476548194885,
-0.043028444051742554
] | 0.072549 |
a corresponding 'enable' comment is encountered. console.log('this is never executed'); } /\* node:coverage enable \*/ ``` Coverage can also be disabled for a specified number of lines. After the specified number of lines, coverage will be automatically reenabled. If the number of lines is not explicitly provided, a single line is ignored. ```js /\* node:coverage ignore next \*/ if (anAlwaysFalseCondition) { console.log('this is never executed'); } /\* node:coverage ignore next 3 \*/ if (anAlwaysFalseCondition) { console.log('this is never executed'); } ``` ### Coverage reporters The tap and spec reporters will print a summary of the coverage statistics. There is also an lcov reporter that will generate an lcov file which can be used as an in depth coverage report. ```bash node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info ``` \* No test results are reported by this reporter. \* This reporter should ideally be used alongside another reporter. ## Mocking The `node:test` module supports mocking during testing via a top-level `mock` object. The following example creates a spy on a function that adds two numbers together. The spy is then used to assert that the function was called as expected. ```mjs import assert from 'node:assert'; import { mock, test } from 'node:test'; test('spies on a function', () => { const sum = mock.fn((a, b) => { return a + b; }); assert.strictEqual(sum.mock.callCount(), 0); assert.strictEqual(sum(3, 4), 7); assert.strictEqual(sum.mock.callCount(), 1); const call = sum.mock.calls[0]; assert.deepStrictEqual(call.arguments, [3, 4]); assert.strictEqual(call.result, 7); assert.strictEqual(call.error, undefined); // Reset the globally tracked mocks. mock.reset(); }); ``` ```cjs 'use strict'; const assert = require('node:assert'); const { mock, test } = require('node:test'); test('spies on a function', () => { const sum = mock.fn((a, b) => { return a + b; }); assert.strictEqual(sum.mock.callCount(), 0); assert.strictEqual(sum(3, 4), 7); assert.strictEqual(sum.mock.callCount(), 1); const call = sum.mock.calls[0]; assert.deepStrictEqual(call.arguments, [3, 4]); assert.strictEqual(call.result, 7); assert.strictEqual(call.error, undefined); // Reset the globally tracked mocks. mock.reset(); }); ``` The same mocking functionality is also exposed on the [`TestContext`][] object of each test. The following example creates a spy on an object method using the API exposed on the `TestContext`. The benefit of mocking via the test context is that the test runner will automatically restore all mocked functionality once the test finishes. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add.mock.callCount(), 0); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.callCount(), 1); const call = number.add.mock.calls[0]; assert.deepStrictEqual(call.arguments, [3]); assert.strictEqual(call.result, 8); assert.strictEqual(call.target, undefined); assert.strictEqual(call.this, number); }); ``` ### Timers Mocking timers is a technique commonly used in software testing to simulate and control the behavior of timers, such as `setInterval` and `setTimeout`, without actually waiting for the specified time intervals. Refer to the [`MockTimers`][] class for a full list of methods and features. This allows developers to write more reliable and predictable tests for time-dependent functionality. The example below shows how to mock `setTimeout`. Using `.enable({ apis: ['setTimeout'] });` it will mock the `setTimeout` functions in the [node:timers](./timers.md) and [node:timers/promises](./timers.md#timers-promises-api) modules, as well as from the Node.js global context. \*\*Note:\*\* Destructuring functions such as `import { setTimeout } from 'node:timers'` is currently not supported by this API. ```mjs import assert from 'node:assert'; import { mock, test } from 'node:test'; test('mocks setTimeout to be executed synchronously without having to actually wait for it', () => { const fn = mock.fn(); // Optionally choose what to mock mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(fn, 9999); assert.strictEqual(fn.mock.callCount(), 0); // Advance in time mock.timers.tick(9999); assert.strictEqual(fn.mock.callCount(), 1); // Reset the globally tracked mocks. mock.timers.reset(); // If you call reset mock instance, it will also reset timers instance mock.reset(); }); ``` ```cjs const assert = require('node:assert'); const { mock, test } | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.06097825616598129,
0.0431862510740757,
-0.050303202122449875,
0.09497939050197601,
0.07552853971719742,
-0.04001680389046669,
-0.015523645095527172,
0.0020315737929195166,
-0.01997830905020237,
0.03457239642739296,
-0.005798755679279566,
0.05208057165145874,
0.01778949424624443,
0.0046115354634821415,
-0.019962409511208534,
0.0068636429496109486,
0.03024119697511196,
-0.05783207714557648,
-0.043051909655332565,
-0.07737638056278229,
-0.022781213745474815,
-0.025265173986554146,
0.03895164281129837,
0.015845322981476784,
-0.0258512943983078,
-0.019705208018422127,
-0.050776176154613495,
0.010345663875341415,
-0.014023947529494762,
0.0386398620903492,
-0.03169384226202965,
-0.01631207950413227,
-0.04392678290605545,
0.08838367462158203,
0.01726396009325981,
-0.015115962363779545,
-0.026557160541415215,
-0.028194138780236244,
-0.06643850356340408,
0.04020867124199867,
-0.019444916397333145,
0.016695041209459305,
-0.07446303963661194,
-0.033141810446977615,
0.05956251174211502,
-0.08133941143751144,
-0.1236395388841629,
-0.01295208279043436,
-0.031613897532224655,
0.014982128515839577,
-0.003121394896879792,
-0.0011756331659853458,
-0.004412149544805288,
-0.09297799319028854,
0.02458220347762108,
0.03742251545190811,
-0.02063041180372238,
-0.03569435328245163,
0.03694121539592743,
0.03018488734960556,
-0.019758420065045357,
-0.050334520637989044,
-0.03232266381382942,
0.002849641488865018,
0.00973217748105526,
0.06174015626311302,
-0.03199402615427971,
0.06306678056716919,
0.03772544488310814,
0.09525640308856964,
-0.011000706814229488,
0.053971923887729645,
-0.003820672631263733,
0.0004011689161416143,
0.03879120200872421,
0.046175479888916016,
-0.032184891402721405,
0.009744817391037941,
-0.0006151907728053629,
-0.055959828197956085,
-0.04644545540213585,
-0.1331709921360016,
-0.024361805990338326,
0.07680555433034897,
-0.033298857510089874,
0.12135839462280273,
0.06398799270391464,
-0.014043858274817467,
0.05198654159903526,
-0.014345480129122734,
-0.023355217650532722,
-0.022012464702129364,
-0.06792698055505753,
0.037159763276576996,
-0.008431876078248024,
0.05469431355595589,
0.009905410930514336,
-0.07998659461736679,
0.007777472026646137,
0.04744579270482063,
0.023316172882914543,
-0.04295950382947922,
0.06675916165113449,
-0.0017484836280345917,
-0.055195122957229614,
-0.04471130296587944,
0.0639948919415474,
-0.05442705377936363,
-0.07137516140937805,
-0.0014412919990718365,
0.08435987681150436,
0.028982192277908325,
0.03858783096075058,
-0.0011356653412804008,
0.026487741619348526,
-0.01961354911327362,
0.06175931170582771,
-0.02119366265833378,
0.015875818207859993,
0.10097536444664001,
0.16777965426445007,
0.02697521075606346,
0.0026559042744338512,
0.015489875338971615,
0.12677159905433655,
0.024669712409377098,
0.08355505764484406,
5.086805601073566e-33,
0.0534566231071949,
-0.07517321407794952,
-0.013439511880278587,
0.05808379128575325,
0.03766622021794319,
0.06829240173101425,
-0.010240595787763596,
-0.005446343217045069,
-0.05768847465515137,
0.06008324772119522,
-0.002052860101684928,
-0.004204083699733019,
0.03562205284833908,
-0.05826307833194733,
0.004120647441595793,
0.045969367027282715,
0.09611532092094421,
-0.00010669960465747863,
-0.029207997024059296,
0.07354619354009628,
0.0639786347746849,
-0.0640311911702156,
-0.046950601041316986,
0.046701714396476746,
0.013679985888302326,
-0.008108452893793583,
-0.028338683769106865,
0.03437119349837303,
-0.05015163496136665,
0.034927453845739365,
-0.022510668262839317,
0.038955945521593094,
-0.02190038003027439,
0.11857425421476364,
-0.04459556192159653,
0.030853625386953354,
-0.10155526548624039,
-0.024882441386580467,
-0.024906570091843605,
0.06062634661793709,
-0.02167561836540699,
-0.013628097251057625,
-0.019862892106175423,
-0.0369347520172596,
-0.008087404072284698,
-0.08062934875488281,
-0.1317547857761383,
-0.03893278166651726,
0.021575162187218666,
-0.026157204061746597,
-0.017606984823942184,
0.1255083531141281,
0.054511260241270065,
-0.0849565789103508,
0.0499316044151783,
0.010709330439567566,
-0.013974027708172798,
-0.06430332362651825,
-0.03245033696293831,
0.05509028211236,
0.034510478377342224,
-0.017306501045823097,
-0.09835605323314667,
0.0025510485284030437,
0.017523448914289474,
-0.0002581964945420623,
-0.05219949036836624,
-0.03176487237215042,
0.02831185795366764,
0.014782251790165901,
-0.06085190176963806,
0.021258505061268806,
0.08654633164405823,
0.04791681841015816,
-0.021983930841088295,
-0.05498281866312027,
-0.04636569321155548,
0.06703317165374756,
-0.010832642205059528,
-0.040695954114198685,
0.04942087456583977,
-0.08607661724090576,
-0.010301979258656502,
0.03336581960320473,
0.1239825114607811,
-0.04562737047672272,
-0.04911774769425392,
0.00906633585691452,
-0.062291111797094345,
-0.022090911865234375,
0.07501653581857681,
0.012861276976764202,
-0.02744382806122303,
-0.10051579028367996,
-0.04750876873731613,
-6.820591442927298e-33,
0.005914872046560049,
0.08347926288843155,
-0.03287867084145546,
0.01615455374121666,
-0.0713890790939331,
-0.009952591732144356,
-0.03687533363699913,
-0.04909197613596916,
0.046855054795742035,
0.025071831420063972,
0.05104751139879227,
0.02494804747402668,
0.007324131205677986,
-0.05502720922231674,
-0.015783147886395454,
0.054914090782403946,
-0.12358293682336807,
-0.0829249694943428,
-0.0015513042453676462,
0.03934333473443985,
0.041027478873729706,
-0.05086422711610794,
0.097958505153656,
0.027745338156819344,
-0.09700196981430054,
-0.059492938220500946,
0.008926392532885075,
0.02354598231613636,
0.021281234920024872,
-0.0633740946650505,
-0.011439216323196888,
0.05318767949938774,
-0.02788429893553257,
0.016673551872372627,
0.04621800780296326,
-0.07088011503219604,
0.037795815616846085,
0.06100618094205856,
-0.012986918911337852,
0.007153178099542856,
0.09278455376625061,
0.03634965792298317,
-0.03293873369693756,
-0.008403368294239044,
0.0037876395508646965,
0.0508723184466362,
0.04385511949658394,
-0.00026452462770976126,
0.0014269861858338118,
-0.0477558858692646,
-0.08842568099498749,
-0.04104791209101677,
0.0763261541724205,
0.0863986387848854,
-0.05338120087981224,
-0.07179798930883408,
-0.0014010800514370203,
-0.024624770507216454,
-0.06498437374830246,
0.11189126968383789,
0.0666418969631195,
-0.07232696563005447,
-0.042608194053173065,
0.01486419327557087,
0.013782106339931488,
-0.04658832773566246,
-0.021383684128522873,
0.04305317625403404,
0.07984460890293121,
0.010733137838542461,
0.0455641895532608,
0.019666779786348343,
-0.032331645488739014,
-0.09714081883430481,
0.08990738540887833,
0.053051408380270004,
-0.0784495621919632,
-0.13367101550102234,
-0.009223604574799538,
0.08399838954210281,
-0.015609183348715305,
0.03467472642660141,
-0.09348340332508087,
0.02749648503959179,
0.08330144733190536,
-0.004089577589184046,
-0.04333670437335968,
0.08051346242427826,
0.028817877173423767,
0.00459296302869916,
-0.006299514789134264,
0.006972972769290209,
-0.0734378919005394,
-0.05979602783918381,
-0.0077562518417835236,
-5.42489573263083e-8,
-0.05688583478331566,
-0.03865201026201248,
-0.0705261304974556,
-0.03187401220202446,
0.08318348973989487,
-0.038184359669685364,
0.004143091384321451,
0.0010931759607046843,
-0.05000517889857292,
-0.0037217603530734777,
0.0072161369025707245,
0.050150543451309204,
0.005995056591928005,
0.0016180315287783742,
0.01680227741599083,
-0.026587221771478653,
0.0001535190240247175,
0.028116067871451378,
-0.05509267374873161,
-0.0249930489808321,
-0.06446216255426407,
0.011942354030907154,
-0.028613105416297913,
0.07163571566343307,
-0.040828026831150055,
-0.01532785128802061,
0.021156975999474525,
0.023235255852341652,
-0.034056443721055984,
0.016722403466701508,
-0.07794557511806488,
-0.029624292626976967,
-0.00008226657519116998,
-0.06837224960327148,
-0.08635379374027252,
0.03808428719639778,
0.11564743518829346,
0.010554241016507149,
0.06911087036132812,
-0.011367362923920155,
-0.005565176252275705,
0.028536420315504074,
-0.02102227695286274,
0.05589485913515091,
-0.015403669327497482,
-0.07506690919399261,
-0.015567255206406116,
-0.03053593635559082,
0.019120480865240097,
-0.09064297378063202,
-0.004781956318765879,
-0.0024628511164337397,
-0.012010208331048489,
0.016361352056264877,
-0.03777126222848892,
0.031633712351322174,
0.060229744762182236,
-0.08713706582784653,
-0.02161642163991928,
0.08458687365055084,
0.052485156804323196,
-0.01004258543252945,
0.04240512102842331,
-0.03573441877961159
] | 0.094716 |
to mock mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(fn, 9999); assert.strictEqual(fn.mock.callCount(), 0); // Advance in time mock.timers.tick(9999); assert.strictEqual(fn.mock.callCount(), 1); // Reset the globally tracked mocks. mock.timers.reset(); // If you call reset mock instance, it will also reset timers instance mock.reset(); }); ``` ```cjs const assert = require('node:assert'); const { mock, test } = require('node:test'); test('mocks setTimeout to be executed synchronously without having to actually wait for it', () => { const fn = mock.fn(); // Optionally choose what to mock mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(fn, 9999); assert.strictEqual(fn.mock.callCount(), 0); // Advance in time mock.timers.tick(9999); assert.strictEqual(fn.mock.callCount(), 1); // Reset the globally tracked mocks. mock.timers.reset(); // If you call reset mock instance, it will also reset timers instance mock.reset(); }); ``` The same mocking functionality is also exposed in the mock property on the [`TestContext`][] object of each test. The benefit of mocking via the test context is that the test runner will automatically restore all mocked timers functionality once the test finishes. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => { const fn = context.mock.fn(); // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(fn, 9999); assert.strictEqual(fn.mock.callCount(), 0); // Advance in time context.mock.timers.tick(9999); assert.strictEqual(fn.mock.callCount(), 1); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => { const fn = context.mock.fn(); // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(fn, 9999); assert.strictEqual(fn.mock.callCount(), 0); // Advance in time context.mock.timers.tick(9999); assert.strictEqual(fn.mock.callCount(), 1); }); ``` ### Dates The mock timers API also allows the mocking of the `Date` object. This is a useful feature for testing time-dependent functionality, or to simulate internal calendar functions such as `Date.now()`. The dates implementation is also part of the [`MockTimers`][] class. Refer to it for a full list of methods and features. \*\*Note:\*\* Dates and timers are dependent when mocked together. This means that if you have both the `Date` and `setTimeout` mocked, advancing the time will also advance the mocked date as they simulate a single internal clock. The example below show how to mock the `Date` object and obtain the current `Date.now()` value. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('mocks the Date object', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['Date'] }); // If not specified, the initial date will be based on 0 in the UNIX epoch assert.strictEqual(Date.now(), 0); // Advance in time will also advance the date context.mock.timers.tick(9999); assert.strictEqual(Date.now(), 9999); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('mocks the Date object', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['Date'] }); // If not specified, the initial date will be based on 0 in the UNIX epoch assert.strictEqual(Date.now(), 0); // Advance in time will also advance the date context.mock.timers.tick(9999); assert.strictEqual(Date.now(), 9999); }); ``` If there is no initial epoch set, the initial date will be based on 0 in the Unix epoch. This is January 1st, 1970, 00:00:00 UTC. You can set an initial date by passing a `now` property to the `.enable()` method. This value will be used as the initial date for the mocked `Date` object. It can either be a positive integer, or another Date object. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('mocks the Date object with initial time', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['Date'], now: 100 }); assert.strictEqual(Date.now(), 100); // Advance in time will also advance | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.07285000383853912,
-0.008423248305916786,
-0.01281069777905941,
0.07780620455741882,
-0.031122051179409027,
-0.009940804913640022,
-0.050493836402893066,
0.011410283856093884,
0.06032496690750122,
-0.019396154209971428,
-0.011835874058306217,
0.0050605302676558495,
-0.04125922545790672,
-0.01301361434161663,
-0.0076644085347652435,
-0.10259930044412613,
0.016354156658053398,
0.022669320926070213,
0.017666764557361603,
-0.04881956800818443,
0.013223538175225258,
-0.06614543497562408,
0.08493002504110336,
0.03777529299259186,
-0.06801176071166992,
-0.10062612593173981,
-0.03304484859108925,
-0.0518975593149662,
0.026248127222061157,
0.03764525428414345,
0.060478728264570236,
-0.02025141753256321,
-0.09243091195821762,
0.02515508607029915,
-0.02750409208238125,
0.052074532955884933,
-0.03745488077402115,
-0.0158295389264822,
0.01440884917974472,
0.0037869412917643785,
0.027384424582123756,
0.012562463991343975,
-0.04275145009160042,
-0.05476565659046173,
0.11039125919342041,
0.017156239598989487,
0.01642485521733761,
0.05022387579083443,
-0.055018339306116104,
0.05743343010544777,
0.0676485002040863,
0.016101686283946037,
-0.014939715154469013,
-0.0656762570142746,
0.024094942957162857,
0.024209341034293175,
0.088384710252285,
0.0253417007625103,
0.046793289482593536,
0.07891452312469482,
0.021741248667240143,
-0.07442205399274826,
0.0426577590405941,
-0.010324923321604729,
0.014342619106173515,
0.06040424853563309,
0.0021861374843865633,
0.021125834435224533,
0.055299099534749985,
0.051362838596105576,
0.052407220005989075,
0.07425817847251892,
0.057999104261398315,
0.027041759341955185,
-0.08389034122228622,
0.017942525446414948,
-0.06485974043607712,
-0.03933042287826538,
0.027977148070931435,
0.04627297446131706,
-0.0458032451570034,
-0.04640071466565132,
-0.0407697819173336,
-0.016802087426185608,
-0.06088258698582649,
0.014008146710693836,
0.1394565850496292,
0.05558455362915993,
-0.0029849696438759565,
-0.07075845450162888,
0.010032646358013153,
0.020328465849161148,
-0.1379236876964569,
0.04718490317463875,
-0.02630588971078396,
-0.030337369069457054,
0.11145003139972687,
0.07364746928215027,
0.03125857189297676,
0.006793014705181122,
0.04549483209848404,
-0.07170294225215912,
0.0071271187625825405,
0.026309700682759285,
-0.043206047266721725,
0.007119893096387386,
0.0017666771309450269,
-0.07853357493877411,
-0.02059662900865078,
0.025760464370250702,
0.04876866564154625,
0.04079451784491539,
0.03983556106686592,
0.00953974761068821,
0.013450432568788528,
0.012733455747365952,
0.00933796726167202,
-0.03300825506448746,
0.06833164393901825,
0.07314632087945938,
0.07165690511465073,
0.062935009598732,
0.036802999675273895,
-0.09573204815387726,
0.03222622349858284,
0.06873182207345963,
0.04365914687514305,
2.0724683558576884e-33,
-0.013011854141950607,
-0.02664061076939106,
-0.005078108981251717,
0.014581970870494843,
0.1250830888748169,
0.004831700585782528,
0.036822542548179626,
0.03514008969068527,
-0.07859262079000473,
-0.03755590319633484,
0.06427101045846939,
-0.07789919525384903,
-0.011671232059597969,
-0.04057399928569794,
-0.03253619000315666,
0.02672397345304489,
0.07906155288219452,
-0.038085538893938065,
0.06485366076231003,
-0.008736529387533665,
0.07227835804224014,
-0.10150414705276489,
-0.0390436090528965,
-0.023697439581155777,
-0.013030793517827988,
-0.06743352860212326,
-0.025837454944849014,
0.04388519376516342,
-0.049753326922655106,
-0.016039349138736725,
0.05792844668030739,
0.08042876422405243,
-0.10303030908107758,
0.1264858841896057,
-0.026248378679156303,
-0.049735866487026215,
0.01917377859354019,
0.0627376139163971,
-0.08956807851791382,
-0.03555210307240486,
-0.000030207396775949746,
0.0037391018122434616,
-0.02797894924879074,
-0.0019089790293946862,
0.009848481975495815,
-0.09894673526287079,
-0.029304100200533867,
-0.05545224994421005,
0.08229049295186996,
0.012718389742076397,
0.05062783882021904,
0.09145735204219818,
-0.0024838608223944902,
-0.13575616478919983,
0.038537219166755676,
0.012971045449376106,
0.04641459137201309,
-0.08259187638759613,
-0.09524545818567276,
0.049958012998104095,
0.07228932529687881,
-0.0881802886724472,
-0.08763889223337173,
-0.014374232850968838,
-0.051137618720531464,
0.053798574954271317,
-0.011125311255455017,
0.015260064043104649,
-0.004165373742580414,
0.0531284399330616,
0.0326978974044323,
0.008605310693383217,
-0.027657154947519302,
-0.018191419541835785,
-0.06459188461303711,
0.02303757146000862,
0.08359439671039581,
0.0011035468196496367,
-0.08287099748849869,
0.005420011933892965,
0.09563615918159485,
-0.05812494829297066,
-0.05624468997120857,
0.05098981410264969,
0.013665096834301949,
-0.07427967339754105,
-0.008256311528384686,
0.01007299404591322,
0.05454274266958237,
-0.055235449224710464,
-0.0016921834321692586,
0.030569422990083694,
0.042271096259355545,
-0.052615225315093994,
-0.09329938888549805,
-3.090521217763662e-33,
0.05066636577248573,
0.009114209562540054,
-0.013793278485536575,
0.14847776293754578,
0.08009625971317291,
-0.025153938680887222,
-0.05419749766588211,
0.04216140881180763,
-0.05591064691543579,
-0.005017617717385292,
0.024967946112155914,
-0.06664063781499863,
0.0006297208019532263,
0.005180279724299908,
-0.05821977183222771,
-0.0005886052967980504,
0.03895628824830055,
-0.04743783175945282,
-0.004028834402561188,
0.022272275760769844,
0.05530910566449165,
-0.0363752581179142,
0.03300761058926582,
-0.05741851031780243,
-0.034052666276693344,
0.005247899331152439,
-0.08346927165985107,
-0.010738134384155273,
0.042745042592287064,
-0.02512815035879612,
-0.026795603334903717,
-0.013014332391321659,
0.028014184907078743,
0.035802535712718964,
0.09663358330726624,
-0.004924351349473,
0.050010114908218384,
0.07559723407030106,
0.04363447427749634,
-0.0007635005167685449,
0.0528290793299675,
0.0013512062141671777,
-0.025805089622735977,
-0.03529166802763939,
-0.021228093653917313,
0.06161234900355339,
-0.011089485138654709,
-0.002078547142446041,
-0.06819956004619598,
-0.013419725000858307,
-0.029133256524801254,
-0.07163942605257034,
0.030450597405433655,
0.05823841318488121,
0.021864386275410652,
-0.0510065034031868,
-0.032632507383823395,
-0.06317944079637527,
0.07090892642736435,
0.045646343380212784,
-0.011746407486498356,
-0.0888858363032341,
-0.031453050673007965,
0.09240060299634933,
-0.009587361477315426,
-0.004849449265748262,
-0.10154668986797333,
0.00706927664577961,
0.03996514528989792,
0.035484131425619125,
-0.014042612165212631,
0.07936613261699677,
-0.07781625539064407,
-0.03060983121395111,
-0.0017205382464453578,
0.011943412944674492,
-0.09562323242425919,
-0.06367692351341248,
0.007790901232510805,
0.008727069944143295,
0.010022536851465702,
-0.015524759888648987,
-0.03690190985798836,
-0.03133625164628029,
-0.020507117733359337,
0.08620882034301758,
-0.007971355691552162,
0.06575513631105423,
0.04303397238254547,
0.0665263682603836,
0.0169790331274271,
0.03335297480225563,
-0.061280298978090286,
-0.029392635449767113,
-0.0407346710562706,
-4.762942040770213e-8,
-0.023974593728780746,
0.00510930921882391,
0.003797774203121662,
-0.0018857151735574007,
0.005208432208746672,
-0.02029416337609291,
0.058094292879104614,
-0.04868103936314583,
0.03630513325333595,
0.013583422638475895,
-0.00963023491203785,
-0.004838150925934315,
0.07556438446044922,
0.0005256388685666025,
-0.011459063738584518,
-0.051409974694252014,
-0.04971329867839813,
-0.03778187930583954,
0.048503998667001724,
0.033527351915836334,
-0.08072225004434586,
0.03233104944229126,
0.0693230926990509,
-0.008546730503439903,
-0.03815258666872978,
0.04586438834667206,
0.08580279350280762,
0.06213977187871933,
0.0328231155872345,
0.026380155235528946,
-0.12458845227956772,
0.011728467419743538,
-0.06081553176045418,
-0.01958433724939823,
-0.03645605221390724,
-0.020293761044740677,
-0.09606904536485672,
0.03085830807685852,
0.044367507100105286,
0.057929784059524536,
-0.0010378127917647362,
-0.03135869279503822,
-0.06196886673569679,
-0.00883329939097166,
0.028969865292310715,
-0.133828803896904,
-0.07572296261787415,
0.01290577556937933,
-0.000958427379373461,
-0.05501747876405716,
-0.017970483750104904,
0.027704229578375816,
-0.06294846534729004,
-0.019880007952451706,
-0.03290092945098877,
0.00561803812161088,
0.020082946866750717,
-0.07764976471662521,
-0.07055795192718506,
0.023674344643950462,
0.03031027503311634,
0.01986238919198513,
-0.048557981848716736,
-0.047423381358385086
] | 0.051596 |
be a positive integer, or another Date object. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('mocks the Date object with initial time', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['Date'], now: 100 }); assert.strictEqual(Date.now(), 100); // Advance in time will also advance the date context.mock.timers.tick(200); assert.strictEqual(Date.now(), 300); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('mocks the Date object with initial time', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['Date'], now: 100 }); assert.strictEqual(Date.now(), 100); // Advance in time will also advance the date context.mock.timers.tick(200); assert.strictEqual(Date.now(), 300); }); ``` You can use the `.setTime()` method to manually move the mocked date to another time. This method only accepts a positive integer. \*\*Note:\*\* This method will \*\*not\*\* execute any mocked timers that are in the past from the new time. In the below example we are setting a new time for the mocked date. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('sets the time of a date object', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['Date'], now: 100 }); assert.strictEqual(Date.now(), 100); // Advance in time will also advance the date context.mock.timers.setTime(1000); context.mock.timers.tick(200); assert.strictEqual(Date.now(), 1200); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('sets the time of a date object', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['Date'], now: 100 }); assert.strictEqual(Date.now(), 100); // Advance in time will also advance the date context.mock.timers.setTime(1000); context.mock.timers.tick(200); assert.strictEqual(Date.now(), 1200); }); ``` Timers scheduled in the past will \*\*not\*\* run when you call `setTime()`. To execute those timers, you can use the `.tick()` method to move forward from the new time. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('setTime does not execute timers', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); const fn = context.mock.fn(); setTimeout(fn, 1000); context.mock.timers.setTime(800); // Timer is not executed as the time is not yet reached assert.strictEqual(fn.mock.callCount(), 0); assert.strictEqual(Date.now(), 800); context.mock.timers.setTime(1200); // Timer is still not executed assert.strictEqual(fn.mock.callCount(), 0); // Advance in time to execute the timer context.mock.timers.tick(0); assert.strictEqual(fn.mock.callCount(), 1); assert.strictEqual(Date.now(), 1200); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('runs timers as setTime passes ticks', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); const fn = context.mock.fn(); setTimeout(fn, 1000); context.mock.timers.setTime(800); // Timer is not executed as the time is not yet reached assert.strictEqual(fn.mock.callCount(), 0); assert.strictEqual(Date.now(), 800); context.mock.timers.setTime(1200); // Timer is executed as the time is now reached assert.strictEqual(fn.mock.callCount(), 1); assert.strictEqual(Date.now(), 1200); }); ``` Using `.runAll()` will execute all timers that are currently in the queue. This will also advance the mocked date to the time of the last timer that was executed as if the time has passed. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('runs timers as setTime passes ticks', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); const fn = context.mock.fn(); setTimeout(fn, 1000); setTimeout(fn, 2000); setTimeout(fn, 3000); context.mock.timers.runAll(); // All timers are executed as the time is now reached assert.strictEqual(fn.mock.callCount(), 3); assert.strictEqual(Date.now(), 3000); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('runs timers as setTime passes ticks', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); const fn = context.mock.fn(); setTimeout(fn, 1000); setTimeout(fn, 2000); setTimeout(fn, 3000); context.mock.timers.runAll(); // All timers are executed as the time is now reached assert.strictEqual(fn.mock.callCount(), 3); assert.strictEqual(Date.now(), 3000); }); ``` ## Snapshot testing Snapshot tests allow arbitrary values to be | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.05706596374511719,
0.06600672006607056,
0.030470170080661774,
0.0684647262096405,
-0.012550922110676765,
0.006039234343916178,
-0.05547156184911728,
0.014750714413821697,
0.02710632048547268,
0.02158108353614807,
0.004536681342869997,
-0.029047513380646706,
0.0041164616122841835,
0.043163079768419266,
0.05816396698355675,
-0.06922584027051926,
0.015135403722524643,
0.020949089899659157,
0.041174959391355515,
-0.045174792408943176,
0.03978882357478142,
-0.08415551483631134,
0.04900356009602547,
0.01673557236790657,
-0.037499960511922836,
-0.1015113815665245,
-0.02298729494214058,
-0.025984564796090126,
0.10155186802148819,
0.031008580699563026,
0.005823146551847458,
0.037470363080501556,
-0.09985527396202087,
0.004279780201613903,
-0.036143772304058075,
0.05063334479928017,
0.011774325743317604,
-0.04303092136979103,
0.015390302054584026,
0.009664819575846195,
-0.0028376493137329817,
0.016601411625742912,
0.012568186968564987,
-0.06884505599737167,
0.07752106338739395,
-0.009240861050784588,
0.04850491136312485,
0.10273087024688721,
-0.060231152921915054,
0.05678335577249527,
-0.0036001892294734716,
0.019516145810484886,
-0.06437832862138748,
-0.09208939969539642,
-0.007968474179506302,
0.0716090053319931,
0.02969292178750038,
0.018479999154806137,
0.045778777450323105,
0.05801459774374962,
0.007893276400864124,
-0.06456444412469864,
0.07034165412187576,
-0.032440170645713806,
0.030297718942165375,
-0.010134436190128326,
-0.004269717261195183,
0.06275961548089981,
0.06806854903697968,
0.07090627402067184,
0.05676956847310066,
-0.0033130631782114506,
0.04257838428020477,
0.031494155526161194,
-0.034977059811353683,
0.017325101420283318,
-0.019000908359885216,
-0.008461211808025837,
0.05934150144457817,
0.006463337689638138,
-0.06490213423967361,
-0.04113655909895897,
-0.04035627469420433,
-0.018201246857643127,
-0.03337809443473816,
0.01632087491452694,
0.08997707068920135,
0.12180721759796143,
-0.017988359555602074,
-0.061309803277254105,
0.018346622586250305,
0.009280713275074959,
-0.1348634660243988,
0.06801837682723999,
0.05794582515954971,
-0.03546774387359619,
0.05397501587867737,
0.07869584113359451,
0.04206477105617523,
0.06511922925710678,
0.009030480869114399,
-0.03139592707157135,
-0.0405074842274189,
0.0296145249158144,
0.07978992909193039,
-0.027121270075440407,
-0.016186991706490517,
-0.11107516288757324,
-0.04380469396710396,
0.026088083162903786,
0.04249013215303421,
0.06724413484334946,
0.03977890685200691,
-0.02048715204000473,
0.005125327967107296,
-0.0009432277292944491,
0.021793609485030174,
-0.00003462502718321048,
0.08601755648851395,
0.023147430270910263,
0.06606283038854599,
0.026325808838009834,
0.003290582448244095,
-0.08860322088003159,
0.05123544856905937,
0.0673496425151825,
0.08475378900766373,
3.424962217542065e-33,
-0.006922324188053608,
-0.06046342849731445,
0.03692135959863663,
0.01925680786371231,
0.03620879724621773,
0.03384016454219818,
0.03505193814635277,
0.01826521009206772,
-0.06037640571594238,
-0.06550668179988861,
0.040637820959091187,
-0.07935437560081482,
-0.025919873267412186,
-0.08204811066389084,
-0.03241685777902603,
-0.008516479283571243,
0.08219320327043533,
-0.0627785325050354,
0.104672871530056,
-0.0006135428557172418,
0.05050992593169212,
-0.1539475917816162,
-0.07501605898141861,
-0.06365787237882614,
0.017624221742153168,
-0.0658002570271492,
-0.00554525014013052,
0.021444600075483322,
-0.0850716084241867,
-0.04011451452970505,
0.04066333547234535,
0.03702474385499954,
-0.11353646218776703,
0.13610999286174774,
0.017980895936489105,
-0.016056014224886894,
-0.013852589763700962,
0.04672845080494881,
-0.08398972451686859,
-0.05314583331346512,
-0.05007866770029068,
-0.000870323448907584,
-0.02361098863184452,
-0.04611136391758919,
0.03610530123114586,
-0.06897503137588501,
-0.01621382124722004,
-0.05346430093050003,
0.09012389183044434,
0.030935415998101234,
0.0143578527495265,
0.08972294628620148,
0.005165622103959322,
-0.09541845321655273,
-0.005209980998188257,
0.008451619185507298,
0.0680372416973114,
0.0005436642095446587,
-0.03540221229195595,
0.009155388921499252,
0.03265630826354027,
-0.0995636135339737,
-0.04938078299164772,
-0.0056266156025230885,
-0.07568538933992386,
0.03937505558133125,
-0.03971189260482788,
0.00937678199261427,
0.04408937692642212,
0.08195246756076813,
0.04029140621423721,
-0.016197307035326958,
-0.04748477786779404,
-0.03158028423786163,
-0.08055432885885239,
-0.006897323299199343,
0.10803665965795517,
0.03819515183568001,
-0.03274044767022133,
-0.046624116599559784,
0.11926279962062836,
-0.02959148772060871,
-0.05013962835073471,
0.07857343554496765,
0.02211620844900608,
-0.026235306635499,
-0.018216248601675034,
0.03631757199764252,
0.08268951624631882,
-0.06643250584602356,
-0.04183293506503105,
0.04267481714487076,
0.04723390191793442,
0.0095407385379076,
-0.05807364359498024,
-3.2444202442511776e-33,
0.09258448332548141,
0.031138824298977852,
-0.00637592189013958,
0.13827292621135712,
0.04849652945995331,
-0.09220805764198303,
-0.0038489445578306913,
0.04495701566338539,
-0.051767248660326004,
0.019933048635721207,
0.07530098408460617,
-0.0691685602068901,
0.04419822618365288,
-0.006287723779678345,
-0.05608700215816498,
-0.010053318925201893,
0.007256486918777227,
-0.050624094903469086,
0.025129908695816994,
0.008376008830964565,
-0.01939522661268711,
0.01442706398665905,
0.0032007659319788218,
-0.054929204285144806,
-0.009687181562185287,
0.024838794022798538,
-0.045996446162462234,
-0.008930826559662819,
-0.021754346787929535,
-0.014683442190289497,
-0.06422767043113708,
-0.011243242770433426,
0.0076173520646989346,
-0.00780476164072752,
0.0570385567843914,
-0.01988505758345127,
0.06280844658613205,
0.006600432563573122,
0.04916008934378624,
0.017122654244303703,
0.01696750335395336,
0.02021046355366707,
-0.017756635323166847,
-0.024790136143565178,
-0.02478049136698246,
0.10151058435440063,
0.07060802727937698,
-0.03175334632396698,
-0.017815906554460526,
0.003593021770939231,
-0.020023714751005173,
-0.08964595198631287,
0.0037625995464622974,
0.031258683651685715,
0.0025976919569075108,
-0.0777689516544342,
-0.03708049654960632,
-0.0887485221028328,
0.0876629427075386,
0.05672549828886986,
-0.03227836266160011,
-0.07252611219882965,
-0.03154512494802475,
0.026440631598234177,
-0.03779718652367592,
-0.04688258841633797,
-0.07039031386375427,
-0.0086746821179986,
0.05376817658543587,
0.0014194867108017206,
0.0328153595328331,
0.10514234751462936,
-0.06727515906095505,
-0.030949797481298447,
-0.024771861732006073,
-0.015295312739908695,
-0.012118828482925892,
0.02477605640888214,
0.02958824299275875,
-0.015379859134554863,
-0.03587474673986435,
0.012232964858412743,
-0.06693194061517715,
0.03850002586841583,
-0.09445377439260483,
0.07622820883989334,
-0.021051457151770592,
0.040266409516334534,
0.0028009414672851562,
0.04547801613807678,
-0.029559772461652756,
0.01685120165348053,
-0.10231702029705048,
0.0068232156336307526,
0.005835483781993389,
-5.104072542394533e-8,
-0.04870302230119705,
-0.015321568585932255,
-0.04152325168251991,
-0.01752794347703457,
0.007498048711568117,
-0.0086707454174757,
0.015371022745966911,
-0.06388266384601593,
0.06057893484830856,
0.0029669618234038353,
0.0708603486418724,
-0.022043608129024506,
0.043418627232313156,
-0.05751049518585205,
0.019597670063376427,
-0.01534647773951292,
-0.09358202666044235,
-0.03289199620485306,
0.007702244445681572,
0.02980927936732769,
-0.005635625217109919,
0.0014334478182718158,
0.10944591462612152,
0.006742764264345169,
-0.008985599502921104,
0.06981734931468964,
0.05605500563979149,
0.08587431907653809,
0.05402354151010513,
0.0743674486875534,
-0.11696667224168777,
0.01364237442612648,
-0.031096599996089935,
-0.04339207708835602,
-0.06854686886072159,
-0.01684536598622799,
-0.08024761825799942,
0.04885484650731087,
0.004134366754442453,
0.046892039477825165,
-0.0075086443684995174,
-0.020805031061172485,
-0.07505922764539719,
-0.0025257482193410397,
-0.027243798598647118,
-0.10902310907840729,
-0.028593456372618675,
-0.015780339017510414,
-0.023716246709227562,
-0.0343753956258297,
0.005810221657156944,
0.015195661224424839,
0.0019060575868934393,
-0.031179774552583694,
-0.0468510165810585,
0.03254404291510582,
0.0031729848124086857,
-0.049856036901474,
-0.08506398648023605,
-0.0011592969531193376,
0.042464479804039,
0.028043927624821663,
0.00599843030795455,
-0.07916481792926788
] | 0.041047 |
{ // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); const fn = context.mock.fn(); setTimeout(fn, 1000); setTimeout(fn, 2000); setTimeout(fn, 3000); context.mock.timers.runAll(); // All timers are executed as the time is now reached assert.strictEqual(fn.mock.callCount(), 3); assert.strictEqual(Date.now(), 3000); }); ``` ## Snapshot testing Snapshot tests allow arbitrary values to be serialized into string values and compared against a set of known good values. The known good values are known as snapshots, and are stored in a snapshot file. Snapshot files are managed by the test runner, but are designed to be human readable to aid in debugging. Best practice is for snapshot files to be checked into source control along with your test files. Snapshot files are generated by starting Node.js with the [`--test-update-snapshots`][] command-line flag. A separate snapshot file is generated for each test file. By default, the snapshot file has the same name as the test file with a `.snapshot` file extension. This behavior can be configured using the `snapshot.setResolveSnapshotPath()` function. Each snapshot assertion corresponds to an export in the snapshot file. An example snapshot test is shown below. The first time this test is executed, it will fail because the corresponding snapshot file does not exist. ```js // test.js suite('suite of snapshot tests', () => { test('snapshot test', (t) => { t.assert.snapshot({ value1: 1, value2: 2 }); t.assert.snapshot(5); }); }); ``` Generate the snapshot file by running the test file with `--test-update-snapshots`. The test should pass, and a file named `test.js.snapshot` is created in the same directory as the test file. The contents of the snapshot file are shown below. Each snapshot is identified by the full name of test and a counter to differentiate between snapshots in the same test. ```js exports[`suite of snapshot tests > snapshot test 1`] = ` { "value1": 1, "value2": 2 } `; exports[`suite of snapshot tests > snapshot test 2`] = ` 5 `; ``` Once the snapshot file is created, run the tests again without the `--test-update-snapshots` flag. The tests should pass now. ## Test reporters The `node:test` module supports passing [`--test-reporter`][] flags for the test runner to use a specific reporter. The following built-reporters are supported: \* `spec` The `spec` reporter outputs the test results in a human-readable format. This is the default reporter. \* `tap` The `tap` reporter outputs the test results in the [TAP][] format. \* `dot` The `dot` reporter outputs the test results in a compact format, where each passing test is represented by a `.`, and each failing test is represented by a `X`. \* `junit` The junit reporter outputs test results in a jUnit XML format \* `lcov` The `lcov` reporter outputs test coverage when used with the [`--experimental-test-coverage`][] flag. The exact output of these reporters is subject to change between versions of Node.js, and should not be relied on programmatically. If programmatic access to the test runner's output is required, use the events emitted by the {TestsStream}. The reporters are available via the `node:test/reporters` module: ```mjs import { tap, spec, dot, junit, lcov } from 'node:test/reporters'; ``` ```cjs const { tap, spec, dot, junit, lcov } = require('node:test/reporters'); ``` ### Custom reporters [`--test-reporter`][] can be used to specify a path to custom reporter. A custom reporter is a module that exports a value accepted by [stream.compose][]. Reporters should transform events emitted by a {TestsStream} Example of a custom reporter using {stream.Transform}: ```mjs import { Transform } from 'node:stream'; const customReporter = new Transform({ writableObjectMode: true, transform(event, encoding, callback) { switch (event.type) { case 'test:dequeue': callback(null, `test ${event.data.name} dequeued`); break; case 'test:enqueue': callback(null, `test ${event.data.name} enqueued`); break; case 'test:watch:drained': callback(null, 'test watch queue | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.07728090137243271,
0.05733015388250351,
-0.01832924410700798,
0.04732858017086983,
-0.00827572401612997,
-0.041092921048402786,
-0.06254971772432327,
0.05883076414465904,
0.028721870854496956,
-0.012347519397735596,
-0.012674668803811073,
0.015208776108920574,
0.006932445336133242,
-0.04752768948674202,
0.0042605591006577015,
-0.08315882831811905,
-0.026572175323963165,
0.0064896694384515285,
0.005707473959773779,
0.004929521586745977,
0.017362728714942932,
-0.08300770819187164,
0.0534551665186882,
-0.001393647980876267,
0.019659267738461494,
-0.04769742116332054,
-0.047303132712841034,
-0.05194313824176788,
0.047682370990514755,
0.0374893955886364,
0.08531314134597778,
0.043694887310266495,
-0.03110310807824135,
0.005186190828680992,
0.0041817170567810535,
0.103805311024189,
0.002534450963139534,
-0.03155788406729698,
-0.01939213089644909,
-0.0007232764037325978,
0.015209246426820755,
0.04121125862002373,
-0.02986324205994606,
-0.040239326655864716,
0.06224673241376877,
0.006358006037771702,
0.029351215809583664,
0.03138834238052368,
-0.04334256052970886,
0.049742892384529114,
-0.02819276787340641,
0.038881924003362656,
-0.03519827872514725,
-0.04793069139122963,
0.010345607064664364,
0.07957705855369568,
0.04103714972734451,
-0.0017666349885985255,
0.039159126579761505,
0.09835100919008255,
0.002788618439808488,
-0.054694484919309616,
-0.009382389485836029,
-0.020347455516457558,
0.05042174085974693,
0.05922025069594383,
0.06281113624572754,
0.024354921653866768,
0.06750257313251495,
0.013318579643964767,
0.024926189333200455,
0.08831500262022018,
0.001989144366234541,
0.03160049393773079,
-0.06353504955768585,
0.015425827354192734,
-0.026998842135071754,
-0.04873380810022354,
0.0201936736702919,
-0.00021404765720944852,
-0.009952649474143982,
-0.06948164105415344,
-0.006411664187908173,
-0.016677122563123703,
-0.053385406732559204,
0.05713804066181183,
0.12443161010742188,
0.03929762914776802,
-0.010785599239170551,
-0.010686488822102547,
-0.013124112971127033,
-0.027357636019587517,
-0.07041358202695847,
0.06411908566951752,
0.032332196831703186,
0.006662370637059212,
0.06682071089744568,
0.09050691872835159,
0.036329206079244614,
0.01893574930727482,
0.0060848151333630085,
-0.06575740873813629,
0.03925640508532524,
-0.0333947017788887,
0.008658717386424541,
0.004503175616264343,
0.022126665338873863,
-0.09917411208152771,
-0.027652766555547714,
0.046041324734687805,
0.07102472335100174,
0.08329273015260696,
0.012690761126577854,
-0.004623488988727331,
0.043045882135629654,
-0.019788501784205437,
0.003419039072468877,
-0.0633428618311882,
0.047660451382398605,
0.06324408948421478,
0.10820815712213516,
0.07335466146469116,
0.0021777786314487457,
-0.058049168437719345,
0.0020081994589418173,
0.047277454286813736,
0.08842916786670685,
5.552561442124311e-33,
0.01639055646955967,
-0.038097452372312546,
0.046865314245224,
0.07508084177970886,
0.07383041828870773,
0.006932670250535011,
0.023140935227274895,
0.01871418207883835,
-0.04271700605750084,
-0.020305899903178215,
0.04749206081032753,
-0.03776996582746506,
-0.005657486151903868,
-0.07382674515247345,
0.005571110174059868,
-0.001414733356796205,
0.0017267221119254827,
-0.06024966016411781,
0.11328716576099396,
0.042300526052713394,
0.04616041108965874,
-0.14921267330646515,
-0.052521683275699615,
-0.035574719309806824,
-0.01889081858098507,
-0.06577889621257782,
0.03663361445069313,
0.036445245146751404,
-0.05752062425017357,
-0.029404044151306152,
0.0429961159825325,
0.04860257729887962,
-0.08317650854587555,
0.09790825843811035,
0.06034737825393677,
-0.06570333242416382,
0.01744627021253109,
0.04668676480650902,
-0.11865141242742538,
-0.02403733693063259,
-0.044365961104631424,
0.03038623370230198,
-0.06314954161643982,
0.015235895290970802,
0.002634040778502822,
-0.1561616063117981,
-0.025063686072826385,
-0.03208138048648834,
0.08724053204059601,
0.06808550655841827,
0.03856261819601059,
0.085873544216156,
0.04400448501110077,
-0.10785191506147385,
-0.013582374900579453,
-0.00007593138434458524,
0.07491248100996017,
-0.09538871794939041,
-0.03820805251598358,
0.09823616594076157,
0.035426065325737,
-0.07190929353237152,
-0.01477820985019207,
0.001148483483120799,
-0.040990520268678665,
0.07330843806266785,
-0.07547929137945175,
-0.013884218409657478,
0.04446687549352646,
0.04080392047762871,
0.008476370014250278,
-0.04334389045834541,
-0.07660352438688278,
-0.006821784656494856,
-0.050934288650751114,
-0.02208106964826584,
0.05415801703929901,
0.07494700700044632,
-0.08263959735631943,
-0.02744559571146965,
0.13898959755897522,
-0.014042477123439312,
-0.07015933841466904,
0.044897645711898804,
-0.001063906354829669,
-0.0571475513279438,
-0.05228429287672043,
-0.04642355814576149,
0.043038684874773026,
-0.06833161413669586,
-0.01900153048336506,
-0.01106590311974287,
0.015118172392249107,
-0.04657522588968277,
-0.03893951326608658,
-5.3098031242382924e-33,
0.05141786113381386,
-0.009058806113898754,
-0.05187283828854561,
0.16808807849884033,
0.05529700219631195,
-0.06303161382675171,
-0.0019003469496965408,
0.0644579827785492,
-0.055296145379543304,
0.04268059507012367,
0.014846980571746826,
-0.04484960436820984,
-0.0031920650508254766,
-0.06495515257120132,
-0.06682224571704865,
-0.01974840834736824,
0.06129204109311104,
-0.15443667769432068,
0.01102015282958746,
-0.04190623760223389,
0.03894085809588432,
-0.02117091231048107,
0.05731545761227608,
0.007855233736336231,
-0.06882969290018082,
0.036260634660720825,
-0.05317303538322449,
-0.042374733835458755,
0.05925367400050163,
-0.059107083827257156,
-0.019328221678733826,
0.005239581689238548,
0.029355105012655258,
0.018248682841658592,
0.05487147718667984,
-0.04597926884889603,
0.06221451982855797,
0.0701710507273674,
0.035408567637205124,
-0.03735098987817764,
0.04790406674146652,
0.02998899482190609,
-0.0005520954728126526,
-0.0121008837595582,
-0.02505495399236679,
0.1004694402217865,
0.0369558148086071,
-0.03858048841357231,
-0.036257077008485794,
-0.01936710998415947,
-0.008539939299225807,
-0.08556213229894638,
0.007984613068401814,
0.08094459772109985,
0.023868629708886147,
-0.13107611238956451,
-0.016774410381913185,
-0.07666125148534775,
0.061707232147455215,
0.07403785735368729,
0.026119422167539597,
-0.05604302138090134,
-0.030801916494965553,
0.02851521223783493,
-0.02226732298731804,
-0.05304913967847824,
-0.1018311157822609,
0.0016960224602371454,
0.020892972126603127,
0.008644447661936283,
-0.024054164066910744,
0.020529113709926605,
-0.0012959514278918505,
-0.03790390118956566,
-0.02423654869198799,
-0.010930580087006092,
-0.03137172758579254,
-0.05475729703903198,
0.04594787210226059,
0.02046097256243229,
-0.005639012902975082,
0.01000184752047062,
-0.07622420787811279,
0.021608030423521996,
-0.04513794556260109,
0.0613582618534565,
-0.013536742888391018,
0.05038127675652504,
0.04170011356472969,
0.046690650284290314,
-0.03478528559207916,
0.030300574377179146,
-0.1053839847445488,
-0.014429171569645405,
0.027362247928977013,
-5.3434497715443285e-8,
-0.026032965630292892,
0.04188137501478195,
-0.007365630008280277,
0.004896076396107674,
-0.03265876695513725,
-0.0160868801176548,
0.023616962134838104,
-0.01810886710882187,
0.07380306720733643,
0.003247881308197975,
0.046701133251190186,
-0.01650923490524292,
0.01916506700217724,
-0.04416840523481369,
0.0007544411346316338,
-0.03772297501564026,
-0.01028452254831791,
0.0069171651266515255,
0.00427132798358798,
0.06347891688346863,
-0.025081856176257133,
-0.0014384661335498095,
0.051629744470119476,
0.017910117283463478,
-0.03249254822731018,
0.02826366201043129,
0.07948005944490433,
0.08116292953491211,
0.03755543753504753,
0.00011116248060716316,
-0.11875272542238235,
0.04110381752252579,
-0.019639097154140472,
-0.09698113799095154,
-0.10805677622556686,
0.028997037559747696,
-0.04866847023367882,
0.03768986091017723,
0.04052892327308655,
0.04874936863780022,
-0.06710022687911987,
-0.008977553807199001,
-0.0780213326215744,
-0.015791568905115128,
-0.07684878259897232,
-0.09892069548368454,
-0.03704940900206566,
0.052407100796699524,
-0.01557542011141777,
-0.015840543434023857,
0.011933209374547005,
-0.03280331566929817,
-0.05091140791773796,
-0.025966539978981018,
-0.05424138158559799,
-0.012475593015551567,
0.010144458152353764,
-0.07190782576799393,
0.0018385212169960141,
0.009331953711807728,
0.046026166528463364,
-0.030755678191781044,
-0.06289747357368469,
0.00814206525683403
] | 0.059048 |
a {TestsStream} Example of a custom reporter using {stream.Transform}: ```mjs import { Transform } from 'node:stream'; const customReporter = new Transform({ writableObjectMode: true, transform(event, encoding, callback) { switch (event.type) { case 'test:dequeue': callback(null, `test ${event.data.name} dequeued`); break; case 'test:enqueue': callback(null, `test ${event.data.name} enqueued`); break; case 'test:watch:drained': callback(null, 'test watch queue drained'); break; case 'test:watch:restarted': callback(null, 'test watch restarted due to file change'); break; case 'test:start': callback(null, `test ${event.data.name} started`); break; case 'test:pass': callback(null, `test ${event.data.name} passed`); break; case 'test:fail': callback(null, `test ${event.data.name} failed`); break; case 'test:plan': callback(null, 'test plan'); break; case 'test:diagnostic': case 'test:stderr': case 'test:stdout': callback(null, event.data.message); break; case 'test:coverage': { const { totalLineCount } = event.data.summary.totals; callback(null, `total line count: ${totalLineCount}\n`); break; } } }, }); export default customReporter; ``` ```cjs const { Transform } = require('node:stream'); const customReporter = new Transform({ writableObjectMode: true, transform(event, encoding, callback) { switch (event.type) { case 'test:dequeue': callback(null, `test ${event.data.name} dequeued`); break; case 'test:enqueue': callback(null, `test ${event.data.name} enqueued`); break; case 'test:watch:drained': callback(null, 'test watch queue drained'); break; case 'test:watch:restarted': callback(null, 'test watch restarted due to file change'); break; case 'test:start': callback(null, `test ${event.data.name} started`); break; case 'test:pass': callback(null, `test ${event.data.name} passed`); break; case 'test:fail': callback(null, `test ${event.data.name} failed`); break; case 'test:plan': callback(null, 'test plan'); break; case 'test:diagnostic': case 'test:stderr': case 'test:stdout': callback(null, event.data.message); break; case 'test:coverage': { const { totalLineCount } = event.data.summary.totals; callback(null, `total line count: ${totalLineCount}\n`); break; } } }, }); module.exports = customReporter; ``` Example of a custom reporter using a generator function: ```mjs export default async function \* customReporter(source) { for await (const event of source) { switch (event.type) { case 'test:dequeue': yield `test ${event.data.name} dequeued\n`; break; case 'test:enqueue': yield `test ${event.data.name} enqueued\n`; break; case 'test:watch:drained': yield 'test watch queue drained\n'; break; case 'test:watch:restarted': yield 'test watch restarted due to file change\n'; break; case 'test:start': yield `test ${event.data.name} started\n`; break; case 'test:pass': yield `test ${event.data.name} passed\n`; break; case 'test:fail': yield `test ${event.data.name} failed\n`; break; case 'test:plan': yield 'test plan\n'; break; case 'test:diagnostic': case 'test:stderr': case 'test:stdout': yield `${event.data.message}\n`; break; case 'test:coverage': { const { totalLineCount } = event.data.summary.totals; yield `total line count: ${totalLineCount}\n`; break; } } } } ``` ```cjs module.exports = async function \* customReporter(source) { for await (const event of source) { switch (event.type) { case 'test:dequeue': yield `test ${event.data.name} dequeued\n`; break; case 'test:enqueue': yield `test ${event.data.name} enqueued\n`; break; case 'test:watch:drained': yield 'test watch queue drained\n'; break; case 'test:watch:restarted': yield 'test watch restarted due to file change\n'; break; case 'test:start': yield `test ${event.data.name} started\n`; break; case 'test:pass': yield `test ${event.data.name} passed\n`; break; case 'test:fail': yield `test ${event.data.name} failed\n`; break; case 'test:plan': yield 'test plan\n'; break; case 'test:diagnostic': case 'test:stderr': case 'test:stdout': yield `${event.data.message}\n`; break; case 'test:coverage': { const { totalLineCount } = event.data.summary.totals; yield `total line count: ${totalLineCount}\n`; break; } } } }; ``` The value provided to `--test-reporter` should be a string like one used in an `import()` in JavaScript code, or a value provided for [`--import`][]. ### Multiple reporters The [`--test-reporter`][] flag can be specified multiple times to report test results in several formats. In this situation it is required to specify a destination for each reporter using [`--test-reporter-destination`][]. Destination can be `stdout`, `stderr`, or a file path. Reporters and destinations are paired according to the order they were specified. In the following example, the `spec` reporter will output to `stdout`, and the `dot` reporter will output to `file.txt`: ```bash node --test-reporter=spec --test-reporter=dot --test-reporter-destination=stdout --test-reporter-destination=file.txt ``` When a single reporter is specified, the destination will default to `stdout`, unless a destination is explicitly provided. ## `run([options])` \* `options` {Object} Configuration options for running tests. The following properties are supported: \* `concurrency` {number|boolean} If a | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.08349958062171936,
0.04468346759676933,
-0.01785101182758808,
0.06444721668958664,
0.012929409742355347,
-0.017008362337946892,
-0.021924087777733803,
0.06688977777957916,
0.07845035940408707,
0.04414989426732063,
0.009286136366426945,
0.036405712366104126,
-0.05729874595999718,
0.041657984256744385,
-0.00029826865647919476,
-0.040334586054086685,
-0.0013228913303464651,
0.0028864024206995964,
-0.06776615977287292,
-0.04330700635910034,
0.010095070116221905,
-0.03802618384361267,
-0.01543854083865881,
-0.00945499911904335,
-0.027073485776782036,
-0.059116266667842865,
-0.003023957833647728,
0.02363041788339615,
0.07554944604635239,
-0.04274845868349075,
0.030421661213040352,
-0.009975685738027096,
-0.12964759767055511,
-0.008719168603420258,
0.019008811563253403,
0.07515846192836761,
-0.004243490286171436,
-0.06674109399318695,
-0.08117633312940598,
-0.011143514886498451,
0.15070155262947083,
0.056276850402355194,
0.008443440310657024,
-0.046477142721414566,
0.023154692724347115,
-0.04355289414525032,
0.004071117844432592,
0.003169878153130412,
-0.09031360596418381,
0.07202330231666565,
-0.01096447091549635,
-0.030265094712376595,
-0.057285942137241364,
0.0865747332572937,
0.029168786481022835,
0.030779125168919563,
-0.0071853226982057095,
-0.027224931865930557,
0.031074540689587593,
0.0017941140104085207,
-0.001215228927321732,
-0.026056503877043724,
0.010039842687547207,
-0.05575677007436752,
-0.020439647138118744,
0.03154319152235985,
-0.019665047526359558,
0.06870632618665695,
0.019720204174518585,
0.013977697119116783,
-0.07655265182256699,
0.04336215555667877,
0.041363127529621124,
0.01678159087896347,
-0.010337622836232185,
-0.09175948798656464,
-0.031044716015458107,
-0.030410772189497948,
-0.023354679346084595,
0.01806512475013733,
0.005561659578233957,
-0.0911640077829361,
0.013233410194516182,
0.023630933836102486,
0.042679160833358765,
0.07157761603593826,
0.013376469723880291,
-0.03343481570482254,
0.008814642205834389,
0.003033634275197983,
-0.08714762330055237,
-0.01533226203173399,
-0.008363776840269566,
0.010090570896863937,
-0.04918390139937401,
0.05678531900048256,
0.011637704446911812,
0.06102950498461723,
0.05070653185248375,
0.006359096150845289,
0.04618769884109497,
0.01348100882023573,
0.028244558721780777,
-0.0006910688825882971,
0.0014682126929983497,
-0.0712108388543129,
-0.005970777943730354,
-0.022766003385186195,
-0.05379512906074524,
0.03556637093424797,
0.02040010504424572,
0.08056952804327011,
0.009820849634706974,
-0.12527243793010712,
0.04456076771020889,
0.055919863283634186,
-0.09564819186925888,
0.02634039707481861,
-0.06115875393152237,
0.06871502101421356,
0.08968522399663925,
0.002786358818411827,
-0.09705120325088501,
0.008931020274758339,
0.11246010661125183,
0.09686266630887985,
0.09124914556741714,
6.815440573618789e-33,
0.05631755292415619,
-0.009523713029921055,
-0.04188164323568344,
0.09535219520330429,
0.053278740495443344,
0.04794500395655632,
0.04183610901236534,
0.0034465764183551073,
-0.0671691820025444,
-0.034946147352457047,
-0.0049959407187998295,
0.009910311549901962,
-0.02066907286643982,
-0.05723584443330765,
-0.07069561630487442,
0.007042147684842348,
-0.026496125385165215,
0.008499734103679657,
0.005634115543216467,
0.01926160417497158,
0.04484928026795387,
-0.0080115282908082,
-0.07114726305007935,
-0.027628561481833458,
-0.019122738391160965,
-0.011973002925515175,
-0.040652673691511154,
0.031960710883140564,
-0.044063352048397064,
-0.023528799414634705,
0.0002458432281855494,
0.06332330405712128,
-0.010675851255655289,
0.03339226916432381,
0.055136557668447495,
-0.07871925830841064,
-0.014971256256103516,
-0.029950805008411407,
-0.13828514516353607,
0.019251471385359764,
0.018521709367632866,
0.04234791919589043,
-0.12459522485733032,
-0.04456967115402222,
-0.020345084369182587,
-0.10298185050487518,
-0.04540388286113739,
-0.06903586536645889,
0.03221027925610542,
-0.12913842499256134,
-0.001105336588807404,
0.1207003965973854,
-0.004935372155159712,
-0.04107115790247917,
0.07310282438993454,
0.08442825078964233,
0.0479520708322525,
0.005380763206630945,
-0.003740257816389203,
0.02445008046925068,
-0.03747188299894333,
0.06938374787569046,
0.020502179861068726,
0.03145598992705345,
0.05731759965419769,
-0.004440142773091793,
0.0002828077122103423,
-0.04540252313017845,
0.046826593577861786,
-0.08183623105287552,
-0.023226222023367882,
0.006041939370334148,
-0.008174923248589039,
0.015578783117234707,
0.03410172834992409,
-0.0033938551787286997,
-0.04571722447872162,
0.02760433219373226,
-0.0034903862979263067,
-0.065035380423069,
-0.012681801803410053,
-0.03026643954217434,
-0.003774885321035981,
0.08427301794290543,
0.03186054155230522,
-0.013177093118429184,
-0.0815739780664444,
-0.08319776505231857,
-0.017491957172751427,
0.0004453543515410274,
-0.002207470592111349,
0.058652330189943314,
0.022705819457769394,
-0.09301668405532837,
-0.03440215066075325,
-7.697779857657445e-33,
-0.06300093978643417,
0.03502783551812172,
-0.0600760392844677,
0.0602438747882843,
-0.032293327152729034,
-0.04057225212454796,
0.045927274972200394,
0.07199565321207047,
0.026290060952305794,
0.034788813441991806,
-0.04589945077896118,
-0.08855180442333221,
-0.055099353194236755,
0.033192794770002365,
-0.055255401879549026,
0.0068992553278803825,
-0.057322908192873,
-0.11214610934257507,
-0.011933320201933384,
-0.11392050981521606,
0.05769632011651993,
0.06223486736416817,
0.0608624666929245,
0.053951460868120193,
-0.08777229487895966,
-0.0018352967454120517,
-0.029383333399891853,
0.025854283943772316,
0.06086277961730957,
-0.04757276922464371,
-0.009566579014062881,
0.0061857071705162525,
-0.024356218054890633,
0.05993523821234703,
0.0038632431533187628,
-0.041955649852752686,
0.03685012832283974,
0.0721505880355835,
0.028689727187156677,
0.01819017343223095,
0.05014900863170624,
0.02210947498679161,
-0.02973211742937565,
0.010186216793954372,
0.005720161832869053,
-0.0045231543481349945,
0.011562743224203587,
0.023379890248179436,
0.04607907682657242,
-0.03891120105981827,
-0.08982083201408386,
-0.0494627021253109,
-0.02753235585987568,
0.0681062787771225,
0.0037252013571560383,
-0.03416392579674721,
0.05752751603722572,
-0.0990372747182846,
-0.04203876107931137,
0.0800294503569603,
0.07250747829675674,
-0.08345101028680801,
0.054421309381723404,
-0.08311185240745544,
0.025351079180836678,
0.01807829923927784,
-0.001667591044679284,
0.014670505188405514,
0.10398189723491669,
0.0403982438147068,
-0.007148554548621178,
-0.004499049391597509,
-0.0039048558101058006,
-0.07212100178003311,
0.1284170001745224,
0.013907210901379585,
-0.010714913718402386,
-0.047449201345443726,
0.02214731089770794,
0.06697461754083633,
-0.09334990382194519,
0.005803252570331097,
-0.05736648663878441,
0.04526670277118683,
0.0828491672873497,
0.024534346535801888,
0.04598470404744148,
0.05799975246191025,
0.03074089251458645,
-0.027668243274092674,
-0.009097607806324959,
0.013071342371404171,
-0.10998432338237762,
0.005573607981204987,
0.0051284898072481155,
-5.85297428301601e-8,
-0.14796552062034607,
-0.03477989509701729,
-0.09018607437610626,
0.02866516076028347,
-0.04208841174840927,
-0.08261136710643768,
0.0038614696823060513,
-0.028691090643405914,
0.015002473257482052,
-0.0007467156392522156,
-0.046578217297792435,
-0.06939755380153656,
0.005559833720326424,
0.03893384709954262,
0.04726207256317139,
-0.06329982727766037,
0.013236810453236103,
0.02331547997891903,
-0.04889877140522003,
-0.018114617094397545,
-0.018922047689557076,
0.02121010050177574,
-0.04845194146037102,
0.06191963702440262,
-0.028191102668642998,
0.03305833786725998,
0.10242662578821182,
-0.0018904826138168573,
-0.01416719052940607,
-0.03529778867959976,
-0.0455181784927845,
0.08078549057245255,
0.034941788762807846,
0.031443774700164795,
-0.08855409920215607,
0.03161149099469185,
0.10358071327209473,
0.03283444046974182,
0.04764330014586449,
0.029230762273073196,
0.09150754660367966,
0.006568928249180317,
-0.08994869887828827,
0.08641676604747772,
-0.042424965649843216,
-0.022057628259062767,
0.013455824926495552,
-0.01156555488705635,
0.011229441501200199,
-0.003944150637835264,
-0.0032022125087678432,
-0.06538617610931396,
0.01353363785892725,
0.007057671435177326,
0.043204084038734436,
0.006348890718072653,
0.06636849790811539,
-0.04960976541042328,
-0.045563798397779465,
0.009061687625944614,
0.09285274893045425,
-0.020497601479291916,
-0.013307997025549412,
0.005503632593899965
] | 0.106964 |
reporter will output to `file.txt`: ```bash node --test-reporter=spec --test-reporter=dot --test-reporter-destination=stdout --test-reporter-destination=file.txt ``` When a single reporter is specified, the destination will default to `stdout`, unless a destination is explicitly provided. ## `run([options])` \* `options` {Object} Configuration options for running tests. The following properties are supported: \* `concurrency` {number|boolean} If a number is provided, then that many test processes would run in parallel, where each process corresponds to one test file. If `true`, it would run `os.availableParallelism() - 1` test files in parallel. If `false`, it would only run one test file at a time. \*\*Default:\*\* `false`. \* `cwd` {string} Specifies the current working directory to be used by the test runner. Serves as the base path for resolving files as if [running tests from the command line][] from that directory. \*\*Default:\*\* `process.cwd()`. \* `files` {Array} An array containing the list of files to run. \*\*Default:\*\* Same as [running tests from the command line][]. \* `forceExit` {boolean} Configures the test runner to exit the process once all known tests have finished executing even if the event loop would otherwise remain active. \*\*Default:\*\* `false`. \* `globPatterns` {Array} An array containing the list of glob patterns to match test files. This option cannot be used together with `files`. \*\*Default:\*\* Same as [running tests from the command line][]. \* `inspectPort` {number|Function} Sets inspector port of test child process. This can be a number, or a function that takes no arguments and returns a number. If a nullish value is provided, each process gets its own port, incremented from the primary's `process.debugPort`. This option is ignored if the `isolation` option is set to `'none'` as no child processes are spawned. \*\*Default:\*\* `undefined`. \* `isolation` {string} Configures the type of test isolation. If set to `'process'`, each test file is run in a separate child process. If set to `'none'`, all test files run in the current process. \*\*Default:\*\* `'process'`. \* `only` {boolean} If truthy, the test context will only run tests that have the `only` option set \* `setup` {Function} A function that accepts the `TestsStream` instance and can be used to setup listeners before any tests are run. \*\*Default:\*\* `undefined`. \* `execArgv` {Array} An array of CLI flags to pass to the `node` executable when spawning the subprocesses. This option has no effect when `isolation` is `'none`'. \*\*Default:\*\* `[]` \* `argv` {Array} An array of CLI flags to pass to each test file when spawning the subprocesses. This option has no effect when `isolation` is `'none'`. \*\*Default:\*\* `[]`. \* `signal` {AbortSignal} Allows aborting an in-progress test execution. \* `testNamePatterns` {string|RegExp|Array} A String, RegExp or a RegExp Array, that can be used to only run tests whose name matches the provided pattern. Test name patterns are interpreted as JavaScript regular expressions. For each test that is executed, any corresponding test hooks, such as `beforeEach()`, are also run. \*\*Default:\*\* `undefined`. \* `testSkipPatterns` {string|RegExp|Array} A String, RegExp or a RegExp Array, that can be used to exclude running tests whose name matches the provided pattern. Test name patterns are interpreted as JavaScript regular expressions. For each test that is executed, any corresponding test hooks, such as `beforeEach()`, are also run. \*\*Default:\*\* `undefined`. \* `timeout` {number} A number of milliseconds the test execution will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. \* `watch` {boolean} Whether to run in watch mode or not. \*\*Default:\*\* `false`. \* `shard` {Object} Running tests in a specific shard. \*\*Default:\*\* `undefined`. \* `index` {number} is a positive integer between 1 and `` that specifies the index of the shard to run. This option is \_required\_. \* `total` {number} | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.008065040223300457,
-0.018759461119771004,
-0.08838266134262085,
0.11804840713739395,
0.05036161094903946,
-0.0613856315612793,
-0.025136776268482208,
0.01670515164732933,
0.008239050395786762,
0.054897185415029526,
0.036035288125276566,
0.04768938571214676,
0.023607978597283363,
-0.05570494383573532,
0.01506628468632698,
-0.08988192677497864,
-0.022830257192254066,
-0.004994451068341732,
-0.013035307638347149,
-0.06817597150802612,
0.04583503678441048,
0.02278786711394787,
0.07714463025331497,
0.015565929003059864,
-0.042948272079229355,
-0.0038299669977277517,
-0.05050995573401451,
-0.04801072180271149,
-0.029478302225470543,
-0.020482081919908524,
0.017452199012041092,
0.0184849351644516,
-0.06603843718767166,
0.044434502720832825,
0.0978926494717598,
0.02303875982761383,
0.040141761302948,
-0.030713655054569244,
-0.11965782940387726,
0.0308128222823143,
0.09865016490221024,
0.022878162562847137,
-0.05265970155596733,
-0.08522282540798187,
-0.02357029914855957,
-0.07305897772312164,
-0.09793725609779358,
0.005228217225521803,
-0.07644922286272049,
-0.022845525294542313,
-0.02091517485678196,
-0.0845121294260025,
-0.02075793221592903,
-0.020868944004178047,
0.0013270869385451078,
0.026924951002001762,
0.03881935402750969,
-0.020186547189950943,
-0.023769637569785118,
0.015275116078555584,
-0.0027494183741509914,
-0.05734875053167343,
-0.04070137441158295,
-0.042727794498205185,
0.07377305626869202,
0.0038327383808791637,
-0.0026966878212988377,
0.04503782466053963,
0.015287172049283981,
-0.0034349048510193825,
-0.02940146066248417,
0.030847841873764992,
-0.01662704534828663,
0.00529578747227788,
0.017564555630087852,
0.01874210499227047,
0.044089287519454956,
0.024432959035038948,
-0.031061772257089615,
-0.0655830129981041,
-0.01679496094584465,
-0.08839625120162964,
0.01710587926208973,
-0.04426887631416321,
-0.08123214542865753,
0.0634508728981018,
0.02829882502555847,
0.02523842453956604,
-0.00791882909834385,
0.040086716413497925,
-0.04065262898802757,
-0.014245888218283653,
-0.037211790680885315,
0.010885575786232948,
-0.012927372939884663,
0.054380420595407486,
0.014275187626481056,
0.11405833810567856,
0.0811748057603836,
-0.001956809312105179,
0.0986403301358223,
-0.04318319633603096,
0.09011971205472946,
-0.03222522884607315,
0.03247745335102081,
-0.032594967633485794,
0.03340180590748787,
-0.06297898292541504,
0.03668930381536484,
-0.015503240749239922,
0.07455899566411972,
0.010091994889080524,
0.04633617773652077,
-0.007457206025719643,
-0.021884428337216377,
0.004919678438454866,
-0.023367052897810936,
0.05461400747299194,
-0.046197351068258286,
0.13329191505908966,
0.03556354343891144,
0.01738530769944191,
-0.02265067771077156,
0.02424003556370735,
0.047208722680807114,
-0.03077998198568821,
0.050036996603012085,
3.240232912968358e-33,
0.012408615089952946,
-0.10605749487876892,
-0.012691620737314224,
0.008213303983211517,
0.03193078935146332,
0.04501725733280182,
-0.016731705516576767,
0.006213611923158169,
-0.11039519309997559,
0.0218171626329422,
-0.038957737386226654,
-0.031756479293107986,
-0.006517471745610237,
0.018588334321975708,
-0.052089765667915344,
0.009129084646701813,
0.02948017604649067,
0.031291794031858444,
-0.008658329956233501,
0.04241747036576271,
0.10240069031715393,
-0.02228989265859127,
-0.12543782591819763,
-0.0035699051804840565,
-0.029081624001264572,
-0.07332468032836914,
-0.0003804231819231063,
-0.043702781200408936,
-0.04846465587615967,
-0.005023492034524679,
-0.08159109205007553,
0.02885511890053749,
0.032636068761348724,
0.09759650379419327,
-0.02136661671102047,
0.021100223064422607,
-0.03882596641778946,
-0.011006454937160015,
-0.04063573107123375,
0.013570667244493961,
-0.04532032832503319,
0.0041671451181173325,
-0.022588076069951057,
0.03832380101084709,
0.03553129360079765,
-0.06640064716339111,
-0.1438453644514084,
0.00400775158777833,
0.016333144158124924,
-0.006575079634785652,
0.07290923595428467,
0.06870172917842865,
0.059281911700963974,
-0.04643808305263519,
0.05779848247766495,
0.05326960235834122,
0.014596736989915371,
-0.08823086321353912,
0.0404522605240345,
0.11642162501811981,
0.03277365118265152,
0.003978553228080273,
-0.07105623185634613,
0.03993241861462593,
0.02586568519473076,
-0.002746916376054287,
0.04164521023631096,
-0.060244012624025345,
0.02134380303323269,
0.09346942603588104,
-0.07353449612855911,
0.022927582263946533,
-0.05158941075205803,
-0.048531968146562576,
0.046526335179805756,
0.012348925694823265,
0.03645141050219536,
-0.005440011154860258,
-0.05715738236904144,
-0.010879259556531906,
-0.0021472065709531307,
0.006221049465239048,
-0.06804104149341583,
-0.0274925846606493,
0.05432991310954094,
-0.025002596899867058,
-0.06915778666734695,
-0.032684821635484695,
0.005797103047370911,
-0.10334011912345886,
0.09991677105426788,
0.012332333251833916,
-0.003436060855165124,
-0.06949319690465927,
0.020435847342014313,
-3.765617174332502e-33,
0.041631173342466354,
0.07286973297595978,
-0.0662921741604805,
0.09009432792663574,
-0.02529522404074669,
-0.017723074182868004,
0.0023904202971607447,
-0.12378773093223572,
-0.06524641811847687,
-0.018388453871011734,
-0.07391331344842911,
-0.05552879348397255,
-0.0015947326319292188,
0.014800124801695347,
-0.043294839560985565,
-0.010740464553236961,
0.02727905660867691,
-0.03983829542994499,
0.03708052635192871,
-0.01645568013191223,
0.02943047694861889,
-0.022112615406513214,
0.1264370232820511,
0.011909198015928268,
-0.03939785063266754,
-0.08608059585094452,
-0.008287009783089161,
-0.01493688765913248,
-0.032068729400634766,
-0.02699229307472706,
0.04191010072827339,
0.03027116321027279,
-0.014054924249649048,
0.015154250897467136,
0.07050395756959915,
-0.022093862295150757,
0.0018499717116355896,
0.031223494559526443,
0.08842571079730988,
0.11459801346063614,
0.045638490468263626,
0.018141964450478554,
-0.0122685506939888,
0.029052313417196274,
0.031268779188394547,
0.09919070452451706,
0.023768020793795586,
0.009154765866696835,
-0.04346448928117752,
-0.04180227965116501,
-0.011456673964858055,
-0.009360475465655327,
-0.017208725214004517,
0.09648120403289795,
-0.020458407700061798,
-0.08282814174890518,
-0.0521441288292408,
-0.028325434774160385,
-0.10698973387479782,
0.040022753179073334,
0.07886888831853867,
-0.02240508422255516,
-0.030319543555378914,
0.0701686292886734,
-0.05294759199023247,
-0.013708853162825108,
0.01154093537479639,
-0.049088701605796814,
0.05258490517735481,
0.029138976708054543,
-0.007682317867875099,
0.037059955298900604,
-0.031480737030506134,
0.035141222178936005,
0.01847110129892826,
0.007842005230486393,
-0.0431506372988224,
-0.07690265774726868,
-0.007424527779221535,
0.1306464523077011,
-0.06602370738983154,
0.07560848444700241,
-0.04335580766201019,
0.010757374577224255,
0.010539866983890533,
0.036407120525836945,
0.014094130136072636,
0.09885159879922867,
0.05577116459608078,
0.044344790279865265,
0.06367655843496323,
0.03913131728768349,
-0.032774586230516434,
-0.08719178289175034,
-0.03232491388916969,
-5.849044981687257e-8,
-0.003914650063961744,
-0.02891393192112446,
-0.07636678218841553,
0.08911803364753723,
-0.003224320709705353,
0.0078110587783157825,
-0.00332826841622591,
-0.059821873903274536,
0.033036474138498306,
0.08696682006120682,
-0.05233971029520035,
-0.044173505157232285,
-0.03867426887154579,
0.0009942885953933,
0.06471158564090729,
0.02846330776810646,
0.07000821828842163,
-0.04077094420790672,
-0.012770410627126694,
-0.023057036101818085,
0.055101629346609116,
0.0444970540702343,
-0.007103343494236469,
0.1318921148777008,
-0.08725284785032272,
0.015163274481892586,
0.10579919070005417,
0.0638299360871315,
-0.057184524834156036,
-0.0362556129693985,
0.00667895283550024,
-0.05806810408830643,
-0.06917782872915268,
-0.0408586710691452,
-0.010317732580006123,
0.010126937180757523,
0.029941663146018982,
0.08269187062978745,
0.09953982383012772,
0.04852832481265068,
-0.0562300942838192,
0.03984867408871651,
-0.0038118937518447638,
0.03666497766971588,
-0.05175318568944931,
-0.058108773082494736,
-0.009162255562841892,
-0.0038097675424069166,
-0.056286439299583435,
-0.09222165495157242,
-0.018170231953263283,
-0.018879786133766174,
0.03655526041984558,
0.09539276361465454,
-0.015461500734090805,
0.05853132903575897,
0.05479193478822708,
-0.0647488459944725,
-0.0350327305495739,
0.022672589868307114,
0.04891827702522278,
-0.04630105569958687,
0.03306549787521362,
-0.03718705475330353
] | 0.111074 |
`watch` {boolean} Whether to run in watch mode or not. \*\*Default:\*\* `false`. \* `shard` {Object} Running tests in a specific shard. \*\*Default:\*\* `undefined`. \* `index` {number} is a positive integer between 1 and `` that specifies the index of the shard to run. This option is \_required\_. \* `total` {number} is a positive integer that specifies the total number of shards to split the test files to. This option is \_required\_. \* `rerunFailuresFilePath` {string} A file path where the test runner will store the state of the tests to allow rerunning only the failed tests on a next run. see \[Rerunning failed tests]\[] for more information. \*\*Default:\*\* `undefined`. \* `coverage` {boolean} enable [code coverage][] collection. \*\*Default:\*\* `false`. \* `coverageExcludeGlobs` {string|Array} Excludes specific files from code coverage using a glob pattern, which can match both absolute and relative file paths. This property is only applicable when `coverage` was set to `true`. If both `coverageExcludeGlobs` and `coverageIncludeGlobs` are provided, files must meet \*\*both\*\* criteria to be included in the coverage report. \*\*Default:\*\* `undefined`. \* `coverageIncludeGlobs` {string|Array} Includes specific files in code coverage using a glob pattern, which can match both absolute and relative file paths. This property is only applicable when `coverage` was set to `true`. If both `coverageExcludeGlobs` and `coverageIncludeGlobs` are provided, files must meet \*\*both\*\* criteria to be included in the coverage report. \*\*Default:\*\* `undefined`. \* `lineCoverage` {number} Require a minimum percent of covered lines. If code coverage does not reach the threshold specified, the process will exit with code `1`. \*\*Default:\*\* `0`. \* `branchCoverage` {number} Require a minimum percent of covered branches. If code coverage does not reach the threshold specified, the process will exit with code `1`. \*\*Default:\*\* `0`. \* `functionCoverage` {number} Require a minimum percent of covered functions. If code coverage does not reach the threshold specified, the process will exit with code `1`. \*\*Default:\*\* `0`. \* `env` {Object} Specify environment variables to be passed along to the test process. This options is not compatible with `isolation='none'`. These variables will override those from the main process, and are not merged with `process.env`. \* Returns: {TestsStream} \*\*Note:\*\* `shard` is used to horizontally parallelize test running across machines or processes, ideal for large-scale executions across varied environments. It's incompatible with `watch` mode, tailored for rapid code iteration by automatically rerunning tests on file changes. ```mjs import { tap } from 'node:test/reporters'; import { run } from 'node:test'; import process from 'node:process'; import path from 'node:path'; run({ files: [path.resolve('./tests/test.js')] }) .on('test:fail', () => { process.exitCode = 1; }) .compose(tap) .pipe(process.stdout); ``` ```cjs const { tap } = require('node:test/reporters'); const { run } = require('node:test'); const path = require('node:path'); run({ files: [path.resolve('./tests/test.js')] }) .on('test:fail', () => { process.exitCode = 1; }) .compose(tap) .pipe(process.stdout); ``` ## `suite([name][, options][, fn])` \* `name` {string} The name of the suite, which is displayed when reporting test results. \*\*Default:\*\* The `name` property of `fn`, or `''` if `fn` does not have a name. \* `options` {Object} Optional configuration options for the suite. This supports the same options as `test([name][, options][, fn])`. \* `fn` {Function|AsyncFunction} The suite function declaring nested tests and suites. The first argument to this function is a [`SuiteContext`][] object. \*\*Default:\*\* A no-op function. \* Returns: {Promise} Immediately fulfilled with `undefined`. The `suite()` function is imported from the `node:test` module. ## `suite.skip([name][, options][, fn])` Shorthand for skipping a suite. This is the same as [`suite([name], { skip: true }[, fn])`][suite options]. ## `suite.todo([name][, options][, fn])` Shorthand for marking a suite as `TODO`. This is the same as [`suite([name], { todo: true }[, fn])`][suite options]. ## `suite.only([name][, options][, fn])` Shorthand for marking a suite as | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
0.036886535584926605,
0.00048618382425047457,
-0.03199157118797302,
0.06571712344884872,
0.008486458100378513,
0.007153905928134918,
-0.013027548789978027,
-0.03176978975534439,
0.018387839198112488,
-0.002122277393937111,
0.00033396450453437865,
0.004381047561764717,
0.04510582610964775,
0.0064584179781377316,
-0.05786954239010811,
-0.06256090849637985,
0.008951234631240368,
-0.02437048964202404,
-0.04373015835881233,
0.023517079651355743,
0.019486986100673676,
-0.046584926545619965,
0.04727616906166077,
0.027661094442009926,
-0.0873652994632721,
-0.06419649720191956,
-0.03429962694644928,
-0.064072385430336,
-0.04215594381093979,
0.004319389350712299,
0.027841348201036453,
-0.05490347743034363,
-0.06163456663489342,
-0.01134277693927288,
0.09149067103862762,
0.03686617314815521,
0.011740644462406635,
-0.05065910518169403,
-0.11267086863517761,
-0.00042710808338597417,
0.029995309188961983,
-0.028075018897652626,
-0.10909970849752426,
-0.038623031228780746,
-0.01988452672958374,
-0.05910711735486984,
-0.052628424018621445,
-0.03145170956850052,
-0.018314825370907784,
-0.0028884403873234987,
-0.037582170218229294,
-0.06575775891542435,
0.0030998471193015575,
-0.023444710299372673,
0.07611306011676788,
-0.0056072105653584,
0.0192835945636034,
0.0081331180408597,
-0.001745687797665596,
-0.01403779350221157,
0.07709115743637085,
-0.04792620241641998,
-0.019819431006908417,
-0.01739574782550335,
0.032271675765514374,
0.009765098802745342,
0.040697645395994186,
0.021466543897986412,
0.02783025987446308,
-0.01608191430568695,
-0.09984295070171356,
0.0774991437792778,
-0.008199860341846943,
0.02742600254714489,
0.033222440630197525,
0.07954148948192596,
-0.008677548728883266,
-0.03292008489370346,
-0.0028215725906193256,
-0.06493210792541504,
-0.14300021529197693,
-0.1362723410129547,
0.00792164821177721,
0.02020358294248581,
0.018067186698317528,
0.03148357942700386,
0.03885742276906967,
-0.021567391231656075,
0.037728551775217056,
-0.0075712804682552814,
0.03583785891532898,
0.02550247684121132,
0.04351597651839256,
0.006915656849741936,
0.0960002914071083,
0.0468781553208828,
-0.01202690601348877,
0.10742761939764023,
0.07135844975709915,
-0.01600770093500614,
-0.013728841207921505,
-0.05552179366350174,
0.03351182863116264,
-0.031401317566633224,
0.03132897987961769,
-0.025899626314640045,
-0.019637830555438995,
-0.045066867023706436,
0.01779181696474552,
-0.033325325697660446,
0.07139530032873154,
-0.01582169346511364,
0.0823630839586258,
-0.0482792928814888,
0.07248532027006149,
0.08693903684616089,
0.00595985958352685,
0.05708368867635727,
-0.07926128059625626,
0.11926834285259247,
0.08759751170873642,
0.007113161496818066,
0.07749740034341812,
-0.005907434970140457,
0.0680198073387146,
-0.00934646651148796,
-0.003536071628332138,
2.3553815607677964e-33,
0.10189281404018402,
-0.08862437307834625,
-0.0054885935969650745,
0.03819894418120384,
0.0843324363231659,
0.004819305147975683,
0.03113376721739769,
0.0793173685669899,
-0.03688535466790199,
0.06103796884417534,
-0.030749788507819176,
0.03856541961431503,
-0.00574934296309948,
-0.06690050661563873,
0.05029064044356346,
-0.031755346804857254,
0.06172275170683861,
0.0016034104628488421,
-0.030441734939813614,
-0.002799371024593711,
0.05664605647325516,
-0.08125926554203033,
-0.022939283400774002,
-0.045154981315135956,
-0.029886728152632713,
-0.05420306697487831,
0.011176330968737602,
-0.05877656117081642,
-0.006259319372475147,
0.01864180713891983,
0.0025396107230335474,
-0.05362055078148842,
-0.00893799215555191,
0.080438032746315,
-0.03924137353897095,
0.02994130365550518,
-0.0768555998802185,
0.03609605133533478,
-0.03923126682639122,
-0.05677490308880806,
0.05251558870077133,
-0.04724421352148056,
0.04110495746135712,
-0.025332564488053322,
-0.046525467187166214,
-0.07979653775691986,
-0.05886842682957649,
0.00219689030200243,
-0.010759980417788029,
-0.012483508326113224,
0.05406684800982475,
0.08286639302968979,
0.013140041381120682,
-0.019588692113757133,
0.0340428426861763,
0.001682145637460053,
-0.022741494700312614,
-0.0633658841252327,
-0.014351064339280128,
0.033882025629282,
0.01350127998739481,
0.03498207405209541,
-0.016963407397270203,
0.11884013563394547,
-0.016795363277196884,
-0.06821254640817642,
0.06300865113735199,
-0.016399042680859566,
0.02289843186736107,
0.06014399230480194,
-0.07485125958919525,
0.015095933340489864,
-0.0333835668861866,
-0.004746721126139164,
-0.009534688666462898,
-0.09899399429559708,
0.02500190958380699,
-0.026661165058612823,
-0.08327864110469818,
-0.057588864117860794,
0.024247344583272934,
-0.08753540366888046,
-0.01726236194372177,
-0.055032528936862946,
-0.06625697761774063,
0.05925358831882477,
-0.02455896884202957,
-0.05872633308172226,
-0.003915131092071533,
-0.1397549957036972,
0.0251535065472126,
-0.07902461290359497,
-0.028377007693052292,
-0.09916134178638458,
-0.013607031665742397,
-4.282243268099051e-33,
0.1264396756887436,
-0.03902548924088478,
0.014761451631784439,
-0.010020019486546516,
0.04784814268350601,
-0.015136134810745716,
0.03260421380400658,
-0.03083942085504532,
-0.021226556971669197,
-0.04231664538383484,
-0.022173669189214706,
-0.06906981766223907,
0.03151239827275276,
0.0436687134206295,
-0.07104324549436569,
0.042678385972976685,
-0.05313659831881523,
-0.13302868604660034,
0.01598498225212097,
-0.010288123972713947,
-0.04698869585990906,
0.009035714901983738,
0.06540907174348831,
0.03781145066022873,
-0.06954127550125122,
0.0008645099005661905,
0.01667775586247444,
-0.05135562643408775,
-0.009430411271750927,
0.036193206906318665,
0.026182234287261963,
0.03787782043218613,
-0.08290574699640274,
-0.012832827866077423,
-0.05509442463517189,
-0.0498788021504879,
0.054908398538827896,
0.005511546973139048,
0.006769599858671427,
0.11608552932739258,
0.12379590421915054,
0.03864370286464691,
-0.026623545214533806,
0.002729651750996709,
-0.024926619604229927,
0.06691954284906387,
0.049841538071632385,
0.041151225566864014,
-0.0559198372066021,
-0.054070282727479935,
-0.006401246879249811,
-0.0572664737701416,
0.03715512529015541,
0.12100548297166824,
0.0052715810015797615,
0.07436949014663696,
-0.012915398925542831,
0.03649052605032921,
-0.13835972547531128,
0.09961502254009247,
0.005910106468945742,
-0.0073674083687365055,
-0.010358592495322227,
0.025706199929118156,
-0.08078107237815857,
0.03492880240082741,
-0.031305745244026184,
-0.004550066310912371,
0.019556622952222824,
-0.0475221611559391,
-0.045897968113422394,
0.039673954248428345,
-0.05343903973698616,
-0.006228905636817217,
0.0017795769963413477,
-0.010548396036028862,
-0.03498433902859688,
-0.05550343915820122,
0.01092332974076271,
0.10747157037258148,
0.008787453174591064,
0.02486582286655903,
-0.027869634330272675,
0.027001308277249336,
0.039902109652757645,
-0.06131153926253319,
0.006487153470516205,
0.08097437024116516,
-0.03518477827310562,
-0.01178766880184412,
-0.03111649677157402,
0.03194041550159454,
0.03958023339509964,
-0.03989836573600769,
0.045623768121004105,
-4.934855724059162e-8,
-0.02421082742512226,
0.0508546307682991,
-0.038946524262428284,
0.032875798642635345,
0.04185006394982338,
-0.02963043935596943,
-0.032688770443201065,
-0.01568847894668579,
-0.05823061615228653,
-0.002462443895637989,
-0.0020037852227687836,
-0.015784410759806633,
-0.029317582026124,
0.023217003792524338,
-0.03723624348640442,
-0.0466402992606163,
0.022824373096227646,
0.06605029851198196,
-0.012341195717453957,
-0.0165005624294281,
0.01511166151612997,
-0.002744268625974655,
0.013049675151705742,
0.08483520895242691,
-0.0062698544934391975,
0.05935538187623024,
0.06534864008426666,
-0.012826133519411087,
0.006550131365656853,
0.05300851911306381,
0.003253810340538621,
-0.006421415600925684,
0.05016481876373291,
-0.07841445505619049,
-0.04848148301243782,
0.138274148106575,
-0.021502625197172165,
0.025982024148106575,
0.07453673332929611,
0.08042286336421967,
0.018546264618635178,
0.0533168651163578,
0.011399256065487862,
0.0187842920422554,
-0.04602289944887161,
-0.14719396829605103,
-0.045573264360427856,
0.037459854036569595,
0.003022590186446905,
-0.024335606023669243,
-0.018966805189847946,
0.04472823441028595,
0.0633893758058548,
0.04827304184436798,
0.003509084926918149,
0.09271078556776047,
0.06759727746248245,
-0.025399988517165184,
-0.07011829316616058,
0.04898720607161522,
0.14051103591918945,
-0.09035931527614594,
-0.006056610029190779,
-0.05263938009738922
] | 0.037113 |
Shorthand for skipping a suite. This is the same as [`suite([name], { skip: true }[, fn])`][suite options]. ## `suite.todo([name][, options][, fn])` Shorthand for marking a suite as `TODO`. This is the same as [`suite([name], { todo: true }[, fn])`][suite options]. ## `suite.only([name][, options][, fn])` Shorthand for marking a suite as `only`. This is the same as [`suite([name], { only: true }[, fn])`][suite options]. ## `test([name][, options][, fn])` \* `name` {string} The name of the test, which is displayed when reporting test results. \*\*Default:\*\* The `name` property of `fn`, or `''` if `fn` does not have a name. \* `options` {Object} Configuration options for the test. The following properties are supported: \* `concurrency` {number|boolean} If a number is provided, then that many tests would run asynchronously (they are still managed by the single-threaded event loop). If `true`, all scheduled asynchronous tests run concurrently within the thread. If `false`, only one test runs at a time. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `false`. \* `only` {boolean} If truthy, and the test context is configured to run `only` tests, then this test will be run. Otherwise, the test is skipped. \*\*Default:\*\* `false`. \* `signal` {AbortSignal} Allows aborting an in-progress test. \* `skip` {boolean|string} If truthy, the test is skipped. If a string is provided, that string is displayed in the test results as the reason for skipping the test. \*\*Default:\*\* `false`. \* `todo` {boolean|string} If truthy, the test marked as `TODO`. If a string is provided, that string is displayed in the test results as the reason why the test is `TODO`. \*\*Default:\*\* `false`. \* `timeout` {number} A number of milliseconds the test will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. \* `plan` {number} The number of assertions and subtests expected to be run in the test. If the number of assertions run in the test does not match the number specified in the plan, the test will fail. \*\*Default:\*\* `undefined`. \* `fn` {Function|AsyncFunction} The function under test. The first argument to this function is a [`TestContext`][] object. If the test uses callbacks, the callback function is passed as the second argument. \*\*Default:\*\* A no-op function. \* Returns: {Promise} Fulfilled with `undefined` once the test completes, or immediately if the test runs within a suite. The `test()` function is the value imported from the `test` module. Each invocation of this function results in reporting the test to the {TestsStream}. The `TestContext` object passed to the `fn` argument can be used to perform actions related to the current test. Examples include skipping the test, adding additional diagnostic information, or creating subtests. `test()` returns a `Promise` that fulfills once the test completes. if `test()` is called within a suite, it fulfills immediately. The return value can usually be discarded for top level tests. However, the return value from subtests should be used to prevent the parent test from finishing first and cancelling the subtest as shown in the following example. ```js test('top level test', async (t) => { // The setTimeout() in the following subtest would cause it to outlive its // parent test if 'await' is removed on the next line. Once the parent test // completes, it will cancel any outstanding subtests. await t.test('longer running subtest', async (t) => { return new Promise((resolve, reject) => { setTimeout(resolve, 1000); }); }); }); ``` The `timeout` option can be used to fail the test if it takes longer than `timeout` milliseconds to complete. However, it is not a reliable mechanism for canceling tests because a running test might block the application thread and thus prevent | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.03756476193666458,
0.09274027496576309,
0.02618853747844696,
0.10003163665533066,
0.004358631558716297,
-0.03866308927536011,
0.10674645751714706,
0.00419874582439661,
-0.02711966447532177,
-0.06420518457889557,
0.021811719983816147,
-0.01622852124273777,
0.012593189254403114,
-0.009492462500929832,
0.06283891201019287,
0.009651963599026203,
-0.020000839605927467,
-0.0032327582594007254,
0.005533494986593723,
-0.07485830783843994,
0.01916268654167652,
0.030321218073368073,
-0.0712604969739914,
-0.02394842356443405,
-0.01611105538904667,
0.005055658984929323,
-0.04986628144979477,
0.04138878732919693,
0.01608518324792385,
0.01853489875793457,
-0.022571809589862823,
0.08355841785669327,
-0.002122831530869007,
0.07822666317224503,
0.05391569063067436,
0.06371533870697021,
-0.04839492216706276,
0.010448364540934563,
0.03177732601761818,
-0.05137960612773895,
0.0008250104729086161,
-0.016564613208174706,
-0.0317252092063427,
-0.018069125711917877,
-0.026560893282294273,
-0.046560872346162796,
-0.058330632746219635,
-0.05058009549975395,
-0.03624272346496582,
-0.007683528121560812,
0.017340919002890587,
0.00021790653408970684,
-0.03429150953888893,
-0.005455671809613705,
0.06805461645126343,
0.04879160597920418,
-0.05563101917505264,
-0.04962857812643051,
-0.005890170112252235,
-0.019378283992409706,
-0.0032844077795743942,
-0.029019948095083237,
-0.04817822948098183,
0.03200999274849892,
0.026612164452672005,
0.019371304661035538,
-0.004577732644975185,
0.03654231131076813,
-0.0010343955364078283,
0.07362431287765503,
-0.040689900517463684,
0.034084346145391464,
0.028318025171756744,
0.0518636479973793,
0.06678398698568344,
-0.010591520927846432,
0.03099139593541622,
0.024967243894934654,
-0.017162946984171867,
-0.01622665859758854,
-0.10319095104932785,
-0.11338898539543152,
-0.050438292324543,
0.044264454394578934,
-0.04600956290960312,
0.08505596220493317,
-0.01004880666732788,
-0.059095170348882675,
0.0766371414065361,
0.002659982070326805,
-0.07855410873889923,
-0.14068138599395752,
0.0275063905864954,
0.0035716015845537186,
0.048183709383010864,
0.042330462485551834,
-0.011195466853678226,
-0.020639494061470032,
-0.0631243884563446,
0.04099917784333229,
0.0335514172911644,
-0.01384508516639471,
0.11817874759435654,
0.004241331480443478,
0.025647811591625214,
-0.031120970845222473,
-0.010038181208074093,
-0.09253685176372528,
0.046658530831336975,
-0.015009564347565174,
-0.051042135804891586,
0.07748518884181976,
0.062363117933273315,
-0.08300422132015228,
-0.1349414885044098,
-0.057405900210142136,
-0.05160709097981453,
0.014038855209946632,
0.02718539908528328,
0.10718518495559692,
0.12832136452198029,
0.04765797406435013,
-0.0015632673166692257,
-0.05255178362131119,
-0.00021128103253431618,
0.08128348737955093,
0.006949188653379679,
-1.37830542174103e-33,
0.03383743390440941,
-0.05368335172533989,
-0.018434125930070877,
-0.03615128993988037,
0.08477827161550522,
0.04203282669186592,
0.013474450446665287,
0.06527501344680786,
-0.049261558800935745,
0.07707227766513824,
0.010034001432359219,
-0.011946205981075764,
0.006347878836095333,
0.026705967262387276,
0.017396215349435806,
0.025513049215078354,
0.09838584065437317,
0.03183358907699585,
-0.015431799925863743,
0.009674625471234322,
0.023016735911369324,
0.053409378975629807,
-0.017771413549780846,
0.03138617053627968,
-0.022955600172281265,
0.005539733450859785,
0.006567815318703651,
-0.017995379865169525,
-0.02967863529920578,
0.010658694431185722,
-0.07697971165180206,
-0.030764244496822357,
0.057491037994623184,
0.13577044010162354,
0.09123490005731583,
0.01123963762074709,
-0.03881154581904411,
-0.036759018898010254,
-0.08596839010715485,
-0.01784018985927105,
-0.010655349120497704,
-0.0325026772916317,
-0.06000840291380882,
0.013057190924882889,
-0.019811218604445457,
-0.10804063081741333,
-0.028006358072161674,
0.0169327761977911,
0.1313076913356781,
0.03144867345690727,
0.01714053936302662,
0.05277134105563164,
-0.006486027967184782,
-0.012074857018887997,
0.0015545100905001163,
-0.05318959429860115,
-0.022109271958470345,
0.045802343636751175,
-0.04986224323511124,
-0.022737011313438416,
-0.07650989294052124,
-0.034343112260103226,
-0.018248168751597404,
0.0705861896276474,
-0.04909878596663475,
0.021407676860690117,
-0.023461591452360153,
-0.039811570197343826,
0.06942689418792725,
-0.026159577071666718,
-0.0164114348590374,
-0.015492689795792103,
-0.037716783583164215,
0.019966626539826393,
0.07186208665370941,
-0.05874150991439819,
0.01903388276696205,
-0.023805851116776466,
0.02088535577058792,
-0.03032965026795864,
0.0010764282196760178,
-0.04417373985052109,
-0.10050301253795624,
0.04982471093535423,
-0.015092262998223305,
0.01876387931406498,
0.00017670785018708557,
-0.045046113431453705,
-0.02408180572092533,
-0.18889561295509338,
-0.08382923156023026,
-0.009295535273849964,
-0.14267636835575104,
-0.054707590490579605,
0.017592357471585274,
-1.8983932545352545e-33,
0.09111578017473221,
0.002465368015691638,
-0.008931930176913738,
0.011017273180186749,
-0.0324845016002655,
-0.056306980550289154,
0.05063021928071976,
-0.05022251978516579,
0.019726118072867393,
-0.05809411779046059,
0.04534374922513962,
-0.001660237438045442,
-0.03338185325264931,
-0.050087083131074905,
-0.030896052718162537,
0.0837554782629013,
-0.07159686088562012,
-0.13747353851795197,
0.006060784216970205,
0.021110203117132187,
-0.02816827967762947,
-0.018001718446612358,
-0.03501240909099579,
0.061165500432252884,
-0.05535953864455223,
-0.0748581811785698,
0.03529580309987068,
-0.02345188334584236,
0.0294486116617918,
0.012108244001865387,
0.0708196759223938,
0.09912846982479095,
-0.08325544744729996,
0.04644247516989708,
0.05420609936118126,
-0.039056941866874695,
0.08011938631534576,
0.12333209812641144,
-0.013988778926432133,
0.06294160336256027,
0.0737009197473526,
0.0245159063488245,
0.04362447187304497,
0.04337065666913986,
0.0020606694743037224,
0.08487100154161453,
-0.010737244971096516,
-0.04923533648252487,
-0.007737141568213701,
0.033002130687236786,
-0.016707034781575203,
-0.05614517256617546,
-0.09333877265453339,
-0.006840911693871021,
-0.046734921634197235,
-0.07955511659383774,
-0.05542211979627609,
-0.06178909167647362,
-0.007155826780945063,
0.036833256483078,
0.06272698193788528,
-0.009888650849461555,
0.04867899790406227,
0.05790996924042702,
-0.01967780292034149,
0.025064649060368538,
-0.08381729573011398,
0.055770061910152435,
-0.037436436861753464,
-0.025139404460787773,
0.01519625261425972,
-0.025961782783269882,
-0.010855513624846935,
-0.08353867381811142,
0.007183350622653961,
-0.00298212468624115,
-0.01186236273497343,
-0.08937180787324905,
0.038206297904253006,
0.00933008175343275,
0.007984541356563568,
-0.05962267518043518,
-0.05522787570953369,
0.055238574743270874,
-0.09330464154481888,
-0.026550889015197754,
-0.034653440117836,
0.09211769700050354,
-0.02899886481463909,
0.011378672905266285,
0.07694236189126968,
0.04735609516501427,
0.026538079604506493,
0.0534549243748188,
-0.11598889529705048,
-5.214161902244996e-8,
-0.06114373356103897,
-0.05625114217400551,
-0.0717308521270752,
-0.05322130769491196,
0.0148154990747571,
0.036982566118240356,
-0.01897587440907955,
0.002672733971849084,
0.016483386978507042,
-0.007964015938341618,
0.0551903173327446,
0.01987927034497261,
-0.05838616564869881,
-0.028827300295233727,
0.01780370995402336,
-0.05138945206999779,
0.0010289405472576618,
0.07457033544778824,
-0.04008958861231804,
0.021819420158863068,
-0.015060362406075,
0.024967940524220467,
-0.042997173964977264,
-0.02895459160208702,
0.003217636374756694,
0.01494708750396967,
0.04534895718097687,
0.02906329743564129,
0.016577595844864845,
0.041887011379003525,
0.03210122883319855,
0.07468350231647491,
0.03352140635251999,
-0.009328135289251804,
-0.022235514596104622,
0.08697223663330078,
0.05008422210812569,
0.0146276094019413,
0.04380973428487778,
0.11081570386886597,
0.017143836244940758,
-0.022991841658949852,
-0.020161902531981468,
-0.018487246707081795,
-0.09427476674318314,
-0.022601155564188957,
-0.00477051455527544,
0.017327329143881798,
0.07835780829191208,
-0.07000415027141571,
0.0003398007247596979,
0.018498597666621208,
-0.005615623202174902,
0.06940563768148422,
-0.04877576604485512,
0.03397086635231972,
0.09331176429986954,
-0.014255025424063206,
-0.0008082751301117241,
-0.005152652971446514,
0.0019813699182122946,
-0.04048287868499756,
0.06323066353797913,
0.04446746036410332
] | 0.11886 |
reject) => { setTimeout(resolve, 1000); }); }); }); ``` The `timeout` option can be used to fail the test if it takes longer than `timeout` milliseconds to complete. However, it is not a reliable mechanism for canceling tests because a running test might block the application thread and thus prevent the scheduled cancellation. ## `test.skip([name][, options][, fn])` Shorthand for skipping a test, same as [`test([name], { skip: true }[, fn])`][it options]. ## `test.todo([name][, options][, fn])` Shorthand for marking a test as `TODO`, same as [`test([name], { todo: true }[, fn])`][it options]. ## `test.only([name][, options][, fn])` Shorthand for marking a test as `only`, same as [`test([name], { only: true }[, fn])`][it options]. ## `describe([name][, options][, fn])` Alias for [`suite()`][]. The `describe()` function is imported from the `node:test` module. ## `describe.skip([name][, options][, fn])` Shorthand for skipping a suite. This is the same as [`describe([name], { skip: true }[, fn])`][describe options]. ## `describe.todo([name][, options][, fn])` Shorthand for marking a suite as `TODO`. This is the same as [`describe([name], { todo: true }[, fn])`][describe options]. ## `describe.only([name][, options][, fn])` Shorthand for marking a suite as `only`. This is the same as [`describe([name], { only: true }[, fn])`][describe options]. ## `it([name][, options][, fn])` Alias for [`test()`][]. The `it()` function is imported from the `node:test` module. ## `it.skip([name][, options][, fn])` Shorthand for skipping a test, same as [`it([name], { skip: true }[, fn])`][it options]. ## `it.todo([name][, options][, fn])` Shorthand for marking a test as `TODO`, same as [`it([name], { todo: true }[, fn])`][it options]. ## `it.only([name][, options][, fn])` Shorthand for marking a test as `only`, same as [`it([name], { only: true }[, fn])`][it options]. ## `before([fn][, options])` \* `fn` {Function|AsyncFunction} The hook function. If the hook uses callbacks, the callback function is passed as the second argument. \*\*Default:\*\* A no-op function. \* `options` {Object} Configuration options for the hook. The following properties are supported: \* `signal` {AbortSignal} Allows aborting an in-progress hook. \* `timeout` {number} A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. This function creates a hook that runs before executing a suite. ```js describe('tests', async () => { before(() => console.log('about to run some test')); it('is a subtest', () => { // Some relevant assertions here }); }); ``` ## `after([fn][, options])` \* `fn` {Function|AsyncFunction} The hook function. If the hook uses callbacks, the callback function is passed as the second argument. \*\*Default:\*\* A no-op function. \* `options` {Object} Configuration options for the hook. The following properties are supported: \* `signal` {AbortSignal} Allows aborting an in-progress hook. \* `timeout` {number} A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. This function creates a hook that runs after executing a suite. ```js describe('tests', async () => { after(() => console.log('finished running tests')); it('is a subtest', () => { // Some relevant assertion here }); }); ``` \*\*Note:\*\* The `after` hook is guaranteed to run, even if tests within the suite fail. ## `beforeEach([fn][, options])` \* `fn` {Function|AsyncFunction} The hook function. If the hook uses callbacks, the callback function is passed as the second argument. \*\*Default:\*\* A no-op function. \* `options` {Object} Configuration options for the hook. The following properties are supported: \* `signal` {AbortSignal} Allows aborting an in-progress hook. \* `timeout` {number} A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. This function creates a hook that runs before each test in the current suite. ```js describe('tests', async () => { beforeEach(() => console.log('about to run a test')); it('is a subtest', | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.060254327952861786,
0.1303129494190216,
0.014101585373282433,
0.08885445445775986,
0.008522122167050838,
-0.08942671120166779,
0.004573339130729437,
-0.010747980326414108,
0.03856252133846283,
-0.03310265392065048,
-0.00956854596734047,
0.02860971726477146,
-0.003472131211310625,
-0.028117194771766663,
-0.022405482828617096,
-0.028050513938069344,
-0.03617872670292854,
0.047939904034137726,
0.006425155326724052,
-0.03622099384665489,
0.036359988152980804,
0.032523587346076965,
0.028315730392932892,
0.04710254445672035,
-0.053275082260370255,
-0.050548005849123,
-0.03741685673594475,
-0.048797205090522766,
0.009065374732017517,
0.027353568002581596,
0.032438430935144424,
0.015628574416041374,
-0.05117560550570488,
0.016639968380331993,
-0.007420140318572521,
0.04028584808111191,
-0.010282224975526333,
0.0370684415102005,
-0.009456144645810127,
-0.05645285174250603,
0.03794972971081734,
0.025692306458950043,
-0.03719700127840042,
-0.0635886937379837,
0.0043752542696893215,
-0.037159763276576996,
-0.030908387154340744,
-0.06865455210208893,
-0.04782009869813919,
0.03926548734307289,
0.009788197465240955,
0.014726758003234863,
-0.040570277720689774,
-0.022787174209952354,
0.05368981137871742,
0.02287597768008709,
0.002180821029469371,
-0.00404431764036417,
-0.0403832383453846,
0.07255551964044571,
-0.01709173433482647,
-0.0739852786064148,
-0.08403682708740234,
0.034979574382305145,
0.09333014488220215,
0.09618772566318512,
0.06606528908014297,
-0.03830559551715851,
0.07206854224205017,
0.11884952336549759,
-0.029155848547816277,
0.03168113902211189,
0.0010684606386348605,
0.04995886608958244,
0.008803799748420715,
0.04479995369911194,
-0.043534357100725174,
-0.03960637003183365,
0.01215808279812336,
0.01267622597515583,
-0.08871214091777802,
-0.11920023709535599,
-0.009351725690066814,
0.003707786090672016,
-0.04442187398672104,
0.0663059651851654,
0.10738230496644974,
0.03961685299873352,
0.07182760536670685,
-0.06437250971794128,
-0.03419607877731323,
-0.03220568597316742,
-0.015509474091231823,
0.049195196479558945,
0.04467185214161873,
0.033735133707523346,
0.05641628056764603,
-0.017933035269379616,
-0.05713941901922226,
0.018214508891105652,
0.06736963987350464,
-0.015879889950156212,
-0.03028799034655094,
-0.068424291908741,
0.014409773983061314,
-0.03832332417368889,
-0.00332693406380713,
-0.066419318318367,
-0.007226722780615091,
-0.011984318494796753,
0.00977774802595377,
0.01406885962933302,
0.09894208610057831,
0.024528518319129944,
-0.05473219230771065,
0.04550743103027344,
0.05895571410655975,
0.03686925023794174,
0.015940453857183456,
0.03703450784087181,
0.09915050119161606,
0.09762537479400635,
0.018163571134209633,
-0.1373162716627121,
0.04075372591614723,
0.07309062033891678,
0.041993897408246994,
1.5030511781376951e-33,
-0.037268079817295074,
-0.08884747326374054,
-0.03828558698296547,
-0.039192672818899155,
0.06215537339448929,
0.00639698700979352,
0.028510259464383125,
0.07203808426856995,
-0.028698720037937164,
0.02197124995291233,
0.02703278884291649,
-0.12005022168159485,
0.002934760181233287,
-0.03981586918234825,
0.025341827422380447,
-0.009190521202981472,
0.11807810515165329,
0.007725991308689117,
0.04270738735795021,
0.05403156951069832,
0.1361379772424698,
-0.08077627420425415,
-0.02800891175866127,
-0.01387697085738182,
-0.029686791822314262,
-0.018833834677934647,
-0.04893897473812103,
0.003551926463842392,
-0.025183813646435738,
-0.0070229750126600266,
-0.032587744295597076,
0.018348559737205505,
-0.07229215651750565,
0.11726649850606918,
0.04859064146876335,
-0.06842884421348572,
-0.04039089009165764,
-0.00011874933261424303,
-0.007935519330203533,
-0.04017147421836853,
-0.05178499594330788,
-0.018986225128173828,
-0.12248796224594116,
0.0697910413146019,
0.02178538218140602,
-0.12648284435272217,
-0.019498074427247047,
-0.07310035824775696,
0.06239743158221245,
0.03736970201134682,
0.053493402898311615,
0.06284821778535843,
0.0053590890020132065,
-0.0749770924448967,
0.013194415718317032,
-0.018430080264806747,
0.017193565145134926,
-0.014383431524038315,
-0.043168019503355026,
0.0371084101498127,
0.034261107444763184,
-0.07411061227321625,
-0.06372007727622986,
0.04447174817323685,
-0.06801403313875198,
0.04109394922852516,
-0.04693104326725006,
-0.10348983108997345,
-0.007113171741366386,
-0.05529531463980675,
-0.004202301148325205,
0.0007213142816908658,
-0.03575761988759041,
0.021070845425128937,
-0.021129339933395386,
-0.08479755371809006,
0.04008842259645462,
0.02449686825275421,
-0.0016024067299440503,
-0.028087977319955826,
0.12664376199245453,
-0.04495907574892044,
-0.09908654540777206,
-0.02761019952595234,
0.04994841665029526,
-0.04553249478340149,
-0.010947439819574356,
-0.06655911356210709,
-0.009350566193461418,
-0.10183904320001602,
-0.08434733748435974,
0.040380846709012985,
-0.034303128719329834,
-0.08521395176649094,
0.04168151691555977,
-1.9772202526624663e-33,
0.05737213417887688,
-0.055926986038684845,
-0.02102513611316681,
0.12246167659759521,
0.019807256758213043,
-0.04066338762640953,
0.024566037580370903,
-0.005210706032812595,
0.01086615864187479,
-0.05275190621614456,
0.0436578094959259,
-0.02653622068464756,
0.027910618111491203,
-0.019854582846164703,
-0.07619073241949081,
0.012167821638286114,
0.042210888117551804,
-0.08968247473239899,
-0.041873253881931305,
-0.01111439149826765,
-0.019010402262210846,
-0.010086121037602425,
0.01964706741273403,
-0.018333740532398224,
-0.08504899591207504,
-0.01427366491407156,
-0.06134922802448273,
0.018777333199977875,
0.04059819132089615,
-0.05502237379550934,
0.016461847350001335,
0.059615347534418106,
-0.03421785682439804,
0.00837517250329256,
0.09138830006122589,
-0.014356945641338825,
0.0636897012591362,
0.13730721175670624,
-0.03216592222452164,
0.09500060230493546,
0.14191843569278717,
0.025559427216649055,
0.0008119103731587529,
0.021685266867280006,
0.021335158497095108,
0.11271600425243378,
-0.010415741242468357,
-0.040585875511169434,
-0.03726718947291374,
0.01598074473440647,
-0.011059429496526718,
-0.026627067476511,
0.02384895645081997,
0.07657985389232635,
0.04975320026278496,
-0.06888813525438309,
0.023278716951608658,
-0.08418887108564377,
0.01242086198180914,
0.060488298535346985,
0.00803232379257679,
-0.04554472118616104,
0.11163521558046341,
0.08817879855632782,
0.05293235555291176,
0.060012318193912506,
-0.05052468180656433,
0.09652836620807648,
0.042424947023391724,
0.053700175136327744,
0.04315066710114479,
0.011482635512948036,
-0.051511798053979874,
-0.006441520992666483,
0.0763314887881279,
0.035334110260009766,
-0.06435904651880264,
-0.09558113664388657,
0.021240852773189545,
-0.006991712376475334,
0.010312551632523537,
0.021154962480068207,
-0.07088552415370941,
0.03943827003240585,
-0.011287955567240715,
0.022174304351210594,
-0.06522852927446365,
0.09570694714784622,
0.0018827574094757438,
0.0421912781894207,
0.06370516866445541,
0.0012359835673123598,
0.0014367165276780725,
0.009152792394161224,
-0.041560426354408264,
-4.9417575809229675e-8,
-0.012511140666902065,
-0.0639299601316452,
0.0005524681764654815,
-0.03784756362438202,
-0.019765669479966164,
-0.006277356296777725,
-0.025648899376392365,
-0.00620630569756031,
0.02304660528898239,
-0.008447869680821896,
0.05656294524669647,
0.0050734831020236015,
0.03387262672185898,
0.03232095390558243,
-0.03303409367799759,
-0.07684211432933807,
-0.012222173623740673,
0.030275393277406693,
0.001507556182332337,
0.0022901485208421946,
-0.06544972956180573,
-0.05384734645485878,
-0.052866484969854355,
0.015176733955740929,
-0.009403382427990437,
0.015047051012516022,
0.10563399642705917,
0.06732505559921265,
-0.012905879877507687,
-0.02162974327802658,
-0.05393475294113159,
0.007527462672442198,
0.010991336777806282,
0.023422500118613243,
-0.06600133329629898,
0.04307430237531662,
-0.008681009523570538,
0.014576503075659275,
0.028363266959786415,
0.09494289010763168,
0.0024814398493617773,
-0.02851508930325508,
-0.025947121903300285,
-0.0005517483805306256,
-0.005519637372344732,
-0.03005402721464634,
-0.05717325210571289,
-0.008734630420804024,
-0.0031863260082900524,
-0.052260637283325195,
-0.016724877059459686,
0.028894629329442978,
0.0029029299039393663,
-0.008600116707384586,
-0.011490886099636555,
-0.012223739176988602,
0.053598977625370026,
-0.09144388884305954,
-0.0498085543513298,
0.02750140242278576,
0.060991160571575165,
-0.027853960171341896,
0.0009663650416769087,
0.013687817379832268
] | 0.08882 |
A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. This function creates a hook that runs before each test in the current suite. ```js describe('tests', async () => { beforeEach(() => console.log('about to run a test')); it('is a subtest', () => { // Some relevant assertion here }); }); ``` ## `afterEach([fn][, options])` \* `fn` {Function|AsyncFunction} The hook function. If the hook uses callbacks, the callback function is passed as the second argument. \*\*Default:\*\* A no-op function. \* `options` {Object} Configuration options for the hook. The following properties are supported: \* `signal` {AbortSignal} Allows aborting an in-progress hook. \* `timeout` {number} A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. This function creates a hook that runs after each test in the current suite. The `afterEach()` hook is run even if the test fails. ```js describe('tests', async () => { afterEach(() => console.log('finished running a test')); it('is a subtest', () => { // Some relevant assertion here }); }); ``` ## `assert` An object whose methods are used to configure available assertions on the `TestContext` objects in the current process. The methods from `node:assert` and snapshot testing functions are available by default. It is possible to apply the same configuration to all files by placing common configuration code in a module preloaded with `--require` or `--import`. ### `assert.register(name, fn)` Defines a new assertion function with the provided name and function. If an assertion already exists with the same name, it is overwritten. ## `snapshot` An object whose methods are used to configure default snapshot settings in the current process. It is possible to apply the same configuration to all files by placing common configuration code in a module preloaded with `--require` or `--import`. ### `snapshot.setDefaultSnapshotSerializers(serializers)` \* `serializers` {Array} An array of synchronous functions used as the default serializers for snapshot tests. This function is used to customize the default serialization mechanism used by the test runner. By default, the test runner performs serialization by calling `JSON.stringify(value, null, 2)` on the provided value. `JSON.stringify()` does have limitations regarding circular structures and supported data types. If a more robust serialization mechanism is required, this function should be used. ### `snapshot.setResolveSnapshotPath(fn)` \* `fn` {Function} A function used to compute the location of the snapshot file. The function receives the path of the test file as its only argument. If the test is not associated with a file (for example in the REPL), the input is undefined. `fn()` must return a string specifying the location of the snapshot snapshot file. This function is used to customize the location of the snapshot file used for snapshot testing. By default, the snapshot filename is the same as the entry point filename with a `.snapshot` file extension. ## Class: `MockFunctionContext` The `MockFunctionContext` class is used to inspect or manipulate the behavior of mocks created via the [`MockTracker`][] APIs. ### `ctx.calls` \* Type: {Array} A getter that returns a copy of the internal array used to track calls to the mock. Each entry in the array is an object with the following properties. \* `arguments` {Array} An array of the arguments passed to the mock function. \* `error` {any} If the mocked function threw then this property contains the thrown value. \*\*Default:\*\* `undefined`. \* `result` {any} The value returned by the mocked function. \* `stack` {Error} An `Error` object whose stack can be used to determine the callsite of the mocked function invocation. \* `target` {Function|undefined} If the mocked function is a constructor, this field contains | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.06279740482568741,
0.015150933526456356,
-0.005164889618754387,
0.11196360737085342,
-0.007631583139300346,
-0.038695257157087326,
-0.07947147637605667,
0.01595422811806202,
0.0429263710975647,
-0.07229345291852951,
-0.011083160527050495,
0.053394824266433716,
-0.07697711139917374,
-0.012308336794376373,
-0.008348013274371624,
0.027481773868203163,
-0.006667815614491701,
-0.027461662888526917,
-0.060571059584617615,
-0.043710727244615555,
0.03313785418868065,
-0.04804014787077904,
0.011410732753574848,
0.005878587253391743,
-0.06461777538061142,
-0.06006055325269699,
-0.0708509087562561,
-0.07228019088506699,
0.024004867300391197,
0.017414310947060585,
0.0068599143996834755,
-0.03650176525115967,
0.011676495894789696,
0.02923409454524517,
-0.0182328000664711,
0.05705082044005394,
-0.012859114445745945,
0.03448135778307915,
-0.011920412071049213,
0.01313591655343771,
0.01603241078555584,
0.004797357600182295,
-0.047949355095624924,
-0.03690062835812569,
0.07378679513931274,
-0.040362607687711716,
-0.02792888693511486,
-0.1093105673789978,
-0.07020188868045807,
0.08225974440574646,
0.04059663787484169,
0.04286397248506546,
0.004732598550617695,
0.011703994125127792,
0.012308979406952858,
-0.01188652403652668,
0.042565904557704926,
-0.014348520897328854,
-0.0038989719469100237,
0.038173429667949677,
-0.007172437850385904,
-0.06759168207645416,
-0.08102121204137802,
0.01584578864276409,
0.08242372423410416,
0.03534787893295288,
0.0423777736723423,
-0.05566910654306412,
0.00029286390054039657,
0.10720080137252808,
0.000019404691556701437,
0.0339529849588871,
-0.03092890791594982,
0.06705597788095474,
0.049169089645147324,
0.08631053566932678,
-0.008902211673557758,
0.030932296067476273,
0.022100627422332764,
-0.07521390914916992,
-0.001668829470872879,
-0.050943199545145035,
-0.057292766869068146,
-0.053162284195423126,
-0.012474476359784603,
0.1251903623342514,
0.08663245290517807,
0.01702587492763996,
-0.037843458354473114,
-0.03188687562942505,
-0.07897362112998962,
-0.02873622067272663,
-0.15744002163410187,
0.05993242189288139,
-0.03040263243019581,
0.019950242713093758,
0.02786610834300518,
-0.05366970971226692,
0.025281524285674095,
-0.0010335143888369203,
0.028418786823749542,
0.029863109812140465,
0.04346713423728943,
0.012851398438215256,
0.04615461081266403,
-0.03243444859981537,
0.003660299349576235,
-0.06070272624492645,
0.025080624967813492,
0.027228016406297684,
0.02266174927353859,
-0.025392599403858185,
0.11207487434148788,
-0.007604469079524279,
0.0011759293265640736,
0.07207852602005005,
0.05884123966097832,
0.016522686928510666,
0.05413743853569031,
0.04192367568612099,
0.13898687064647675,
0.09475716948509216,
0.05342338979244232,
-0.050011906772851944,
0.04378874972462654,
0.08774126321077347,
0.006140479817986488,
3.961047518260523e-33,
-0.012865670956671238,
-0.09274591505527496,
0.008767248131334782,
0.08419549465179443,
0.012919018045067787,
-0.03695010021328926,
0.05628955736756325,
0.04280926659703255,
-0.04686299338936806,
0.07481600344181061,
-0.012935924343764782,
-0.06484836339950562,
0.03173552080988884,
-0.049198031425476074,
0.0009898135904222727,
0.006126823835074902,
0.09479983896017075,
-0.09879978001117706,
0.013647089712321758,
0.08850333839654922,
0.03617741912603378,
-0.11392316222190857,
-0.02960926853120327,
-0.009887367486953735,
-0.027517132461071014,
-0.0332617312669754,
-0.0027159994933754206,
0.06625687330961227,
-0.062410127371549606,
0.003137471852824092,
-0.049354858696460724,
0.0508207269012928,
-0.06402171403169632,
0.0450388640165329,
0.02053341083228588,
-0.08319240063428879,
0.01563589833676815,
-0.023511668667197227,
-0.05875752866268158,
0.023249708116054535,
-0.05445217713713646,
-0.009009246714413166,
-0.11579551547765732,
0.0028272545896470547,
0.020521454513072968,
-0.16632620990276337,
-0.029956664890050888,
-0.002202019328251481,
0.08308534324169159,
0.05544184520840645,
0.031077662482857704,
0.10327127575874329,
0.008162152953445911,
-0.05025171861052513,
0.06727700680494308,
0.06654440611600876,
-0.0032294318079948425,
-0.030719323083758354,
-0.012318680062890053,
0.06776221841573715,
0.017013460397720337,
-0.10525121539831161,
-0.028990058228373528,
0.057295456528663635,
-0.07764436304569244,
0.02088921144604683,
-0.03948890417814255,
-0.02298320271074772,
-0.03392830863595009,
-0.023093001917004585,
0.007951956242322922,
-0.012967189773917198,
-0.09533656388521194,
0.015920134261250496,
-0.0018283477984368801,
-0.022504225373268127,
0.010928742587566376,
0.044324278831481934,
0.026728663593530655,
-0.047711826860904694,
0.13079331815242767,
-0.02763763815164566,
-0.041646793484687805,
0.007742390502244234,
0.04516254737973213,
-0.002852483419701457,
0.001213807612657547,
-0.13658767938613892,
-0.011562826111912727,
-0.035837702453136444,
-0.046114422380924225,
0.00801883079111576,
0.020456690341234207,
-0.07933212071657181,
0.03929372504353523,
-5.9581856043427114e-33,
0.11188627034425735,
-0.021113811060786247,
-0.08325376361608505,
0.0890408456325531,
0.022854384034872055,
-0.061683665961027145,
0.007326540071517229,
0.038721852004528046,
-0.05499934032559395,
0.004997855983674526,
0.015316850505769253,
-0.026429329067468643,
0.023607974871993065,
-0.0016607696888968349,
-0.036723773926496506,
0.04935556277632713,
0.0005473840865306556,
-0.13374778628349304,
0.08120043575763702,
0.05998116359114647,
0.11596012860536575,
-0.051365211606025696,
0.01937403529882431,
0.005672869738191366,
-0.07478891313076019,
-0.014868387952446938,
-0.010617642663419247,
-0.021420713514089584,
0.0013282825239002705,
-0.049420490860939026,
0.00967819057404995,
0.03936973586678505,
-0.002262766705825925,
0.08671898394823074,
0.10789266973733902,
-0.01911596767604351,
0.09649734944105148,
0.06915657222270966,
-0.014989715069532394,
-0.003674374660477042,
0.07123292982578278,
0.027759412303566933,
-0.017296211794018745,
-0.04377476125955582,
0.0073339203372597694,
0.025720685720443726,
0.006762960460036993,
-0.053928621113300323,
-0.04626474529504776,
0.014212560839951038,
-0.057928089052438736,
-0.028434602543711662,
0.02105507254600525,
0.07654475420713425,
-0.04848933592438698,
-0.052221428602933884,
-0.0377274714410305,
-0.05046864598989487,
0.026432376354932785,
0.09854527562856674,
-0.000007702435141254682,
-0.044681817293167114,
0.06993837654590607,
-0.009336558170616627,
0.017822273075580597,
0.020300406962633133,
-0.005603872239589691,
0.038607846945524216,
0.052923981100320816,
0.04258325695991516,
0.04596097022294998,
-0.025629792362451553,
-0.09321393817663193,
0.0014948040479794145,
-0.018139485269784927,
0.021701565012335777,
-0.010192865505814552,
-0.14750516414642334,
0.06005271151661873,
0.009785759262740612,
-0.052997563034296036,
-0.02346511371433735,
-0.04519110172986984,
0.03940311819314957,
-0.013834819197654724,
0.07139559090137482,
-0.006348821800202131,
0.09466458112001419,
-0.008877425454556942,
-0.07784998416900635,
0.030657010152935982,
0.021608874201774597,
-0.0688546746969223,
-0.05590766295790672,
-0.017352692782878876,
-5.834671767956934e-8,
-0.026225939393043518,
-0.005786695517599583,
-0.056822214275598526,
-0.012568105012178421,
0.002212967723608017,
-0.031640686094760895,
-0.003833525814116001,
-0.04170210659503937,
-0.01775587536394596,
-0.0404014028608799,
0.03197430074214935,
0.06759210675954819,
0.09404034167528152,
0.029069971293210983,
-0.07265132665634155,
-0.06311008334159851,
-0.008559082634747028,
-0.020500315353274345,
0.01638154685497284,
-0.0009887826163321733,
-0.07826555520296097,
0.037162743508815765,
0.021472319960594177,
-0.04148126766085625,
-0.03517918661236763,
-0.02415499836206436,
0.07395200431346893,
0.09634105116128922,
-0.008766272105276585,
-0.017932316288352013,
-0.05335560441017151,
0.015836074948310852,
-0.03999079018831253,
0.015576832927763462,
-0.03645102679729462,
0.015994342043995857,
0.06516003608703613,
0.011652039363980293,
0.05334005504846573,
0.052242182195186615,
0.03465316444635391,
0.0042472900822758675,
-0.02369844540953636,
-0.028266020119190216,
-0.033230651170015335,
-0.04299450293183327,
-0.09060860425233841,
0.025391332805156708,
-0.010663118213415146,
-0.010090322233736515,
-0.033945634961128235,
0.03060462884604931,
-0.04118579626083374,
0.014241384342312813,
0.010089844465255737,
-0.05175070837140083,
0.018503518775105476,
-0.05805814638733864,
-0.026184579357504845,
0.0023428406566381454,
0.016097040846943855,
-0.03663817048072815,
0.024189094081521034,
-0.03161916509270668
] | 0.056701 |
property contains the thrown value. \*\*Default:\*\* `undefined`. \* `result` {any} The value returned by the mocked function. \* `stack` {Error} An `Error` object whose stack can be used to determine the callsite of the mocked function invocation. \* `target` {Function|undefined} If the mocked function is a constructor, this field contains the class being constructed. Otherwise this will be `undefined`. \* `this` {any} The mocked function's `this` value. ### `ctx.callCount()` \* Returns: {integer} The number of times that this mock has been invoked. This function returns the number of times that this mock has been invoked. This function is more efficient than checking `ctx.calls.length` because `ctx.calls` is a getter that creates a copy of the internal call tracking array. ### `ctx.mockImplementation(implementation)` \* `implementation` {Function|AsyncFunction} The function to be used as the mock's new implementation. This function is used to change the behavior of an existing mock. The following example creates a mock function using `t.mock.fn()`, calls the mock function, and then changes the mock implementation to a different function. ```js test('changes a mock behavior', (t) => { let cnt = 0; function addOne() { cnt++; return cnt; } function addTwo() { cnt += 2; return cnt; } const fn = t.mock.fn(addOne); assert.strictEqual(fn(), 1); fn.mock.mockImplementation(addTwo); assert.strictEqual(fn(), 3); assert.strictEqual(fn(), 5); }); ``` ### `ctx.mockImplementationOnce(implementation[, onCall])` \* `implementation` {Function|AsyncFunction} The function to be used as the mock's implementation for the invocation number specified by `onCall`. \* `onCall` {integer} The invocation number that will use `implementation`. If the specified invocation has already occurred then an exception is thrown. \*\*Default:\*\* The number of the next invocation. This function is used to change the behavior of an existing mock for a single invocation. Once invocation `onCall` has occurred, the mock will revert to whatever behavior it would have used had `mockImplementationOnce()` not been called. The following example creates a mock function using `t.mock.fn()`, calls the mock function, changes the mock implementation to a different function for the next invocation, and then resumes its previous behavior. ```js test('changes a mock behavior once', (t) => { let cnt = 0; function addOne() { cnt++; return cnt; } function addTwo() { cnt += 2; return cnt; } const fn = t.mock.fn(addOne); assert.strictEqual(fn(), 1); fn.mock.mockImplementationOnce(addTwo); assert.strictEqual(fn(), 3); assert.strictEqual(fn(), 4); }); ``` ### `ctx.resetCalls()` Resets the call history of the mock function. ### `ctx.restore()` Resets the implementation of the mock function to its original behavior. The mock can still be used after calling this function. ## Class: `MockModuleContext` > Stability: 1.0 - Early development The `MockModuleContext` class is used to manipulate the behavior of module mocks created via the [`MockTracker`][] APIs. ### `ctx.restore()` Resets the implementation of the mock module. ## Class: `MockPropertyContext` The `MockPropertyContext` class is used to inspect or manipulate the behavior of property mocks created via the [`MockTracker`][] APIs. ### `ctx.accesses` \* Type: {Array} A getter that returns a copy of the internal array used to track accesses (get/set) to the mocked property. Each entry in the array is an object with the following properties: \* `type` {string} Either `'get'` or `'set'`, indicating the type of access. \* `value` {any} The value that was read (for `'get'`) or written (for `'set'`). \* `stack` {Error} An `Error` object whose stack can be used to determine the callsite of the mocked function invocation. ### `ctx.accessCount()` \* Returns: {integer} The number of times that the property was accessed (read or written). This function returns the number of times that the property was accessed. This function is more efficient than checking `ctx.accesses.length` because `ctx.accesses` is a getter that creates a copy of the internal access tracking array. ### `ctx.mockImplementation(value)` \* `value` {any} The | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.11112307012081146,
0.01352023333311081,
-0.030385367572307587,
0.050170689821243286,
-0.06852998584508896,
-0.07524394989013672,
0.08165240287780762,
0.014826332218945026,
0.035042017698287964,
-0.03744648024439812,
-0.01990392804145813,
-0.03444821015000343,
0.0001687326584942639,
-0.06393306702375412,
0.025232236832380295,
-0.058438740670681,
0.038464587181806564,
-0.08466102927923203,
-0.029756786301732063,
-0.01071684155613184,
0.06827253848314285,
-0.009299196302890778,
0.03526390343904495,
0.01070153247565031,
-0.00036365073174238205,
-0.04268171638250351,
-0.11869297921657562,
-0.09706462919712067,
0.0808505266904831,
0.00692168902605772,
0.0592133104801178,
0.07099305093288422,
-0.04640154913067818,
0.0009959293529391289,
-0.024782078340649605,
0.0329027995467186,
0.004748822655528784,
-0.009948449209332466,
-0.0318664088845253,
0.053098540753126144,
0.012614578008651733,
0.04106917977333069,
-0.059099260717630386,
-0.010919882915914059,
0.06455553323030472,
0.020219137892127037,
0.06450595706701279,
-0.011637184768915176,
-0.02981756068766117,
0.03780268132686615,
0.029887696728110313,
0.08912675082683563,
0.0067750513553619385,
0.020795194432139397,
0.018550332635641098,
0.04951910302042961,
0.03231339529156685,
-0.04418531432747841,
0.007104808464646339,
0.03457930311560631,
0.008675015531480312,
-0.03822927549481392,
0.032980117946863174,
0.02389834076166153,
0.019406447187066078,
-0.04525163769721985,
-0.06118359416723251,
-0.0354667529463768,
0.06168543919920921,
-0.02311318926513195,
0.006903831847012043,
0.05219185724854469,
0.09673621505498886,
0.09540648013353348,
0.05660560354590416,
0.06851354986429214,
-0.0027926922775804996,
-0.07798312604427338,
0.04485538229346275,
0.040125127881765366,
0.003561175661161542,
-0.06923151761293411,
-0.01803470216691494,
-0.021952377632260323,
0.044853322207927704,
0.07398690283298492,
0.056906525045633316,
0.010334792546927929,
0.02106170542538166,
-0.00256637972779572,
0.023305542767047882,
-0.026395048946142197,
-0.16285988688468933,
0.09539469331502914,
0.030051900073885918,
-0.04805980250239372,
0.07352284342050552,
-0.05890389159321785,
-0.006506586913019419,
0.0004758451832458377,
-0.03146814927458763,
-0.025362785905599594,
0.08641182631254196,
-0.021930459886789322,
-0.037350550293922424,
-0.012311727739870548,
-0.04807119816541672,
-0.16461418569087982,
-0.0006172677385620773,
0.03166332468390465,
-0.028012651950120926,
-0.015011557377874851,
0.00937220361083746,
0.006319653708487749,
0.05138300731778145,
-0.012154175899922848,
-0.04946085810661316,
-0.06451878696680069,
0.06633970141410828,
0.013582412153482437,
0.0764337107539177,
0.025418303906917572,
0.006829286925494671,
0.04393348842859268,
0.042645413428545,
0.051037512719631195,
-0.028204603120684624,
2.8311730011676946e-33,
-0.024988193064928055,
0.031451914459466934,
-0.012642381712794304,
0.05964791029691696,
0.06364861130714417,
-0.01735757105052471,
0.0540122389793396,
-0.022994335740804672,
-0.09673067927360535,
-0.013959182426333427,
0.04031715914607048,
0.040139537304639816,
0.05750667303800583,
0.035071808844804764,
0.006448687054216862,
0.02806979790329933,
0.029713807627558708,
-0.06559627503156662,
-0.03764091059565544,
0.0013874599244445562,
0.056819211691617966,
0.05936135724186897,
-0.03129895031452179,
0.0035848605912178755,
-0.008984885178506374,
-0.04998769238591194,
-0.05059155821800232,
0.05015713721513748,
-0.1194787546992302,
-0.008451089262962341,
-0.061227958649396896,
0.020024269819259644,
-0.01418710220605135,
0.10140397399663925,
0.047030530869960785,
-0.019221870228648186,
0.0017303717322647572,
-0.01418750174343586,
-0.10939185321331024,
-0.0033365245908498764,
-0.014096783474087715,
-0.04832311347126961,
-0.029771713539958,
0.01883050613105297,
-0.043292466551065445,
-0.14685013890266418,
-0.032160431146621704,
-0.014215605333447456,
0.08888297528028488,
-0.009819835424423218,
0.047364335507154465,
0.06580312550067902,
0.009829632006585598,
0.001174872973933816,
0.0554695725440979,
-0.004132429137825966,
0.06723012030124664,
0.015880439430475235,
0.014952318742871284,
0.017497019842267036,
0.03203795477747917,
-0.08256279677152634,
-0.058855265378952026,
0.030602389946579933,
-0.06280151754617691,
0.08796565234661102,
0.0013576233759522438,
-0.04458656907081604,
0.057851146906614304,
0.034443099051713943,
0.011723433621227741,
0.052073635160923004,
-0.10468471050262451,
0.04756392911076546,
0.02593986690044403,
-0.0412498414516449,
-0.014088639989495277,
-0.02080116793513298,
-0.03558167442679405,
0.005816836375743151,
0.042338039726018906,
0.01043835747987032,
-0.05159997567534447,
0.10417479276657104,
-0.040777940303087234,
-0.040866669267416,
0.0418703593313694,
-0.05008374899625778,
0.027522461488842964,
-0.05525180324912071,
-0.0015701501397415996,
-0.04993535578250885,
-0.07649809122085571,
-0.027189364656805992,
-0.05543733015656471,
-5.513713557881542e-33,
0.0032022586092352867,
0.05811912193894386,
-0.03537704423069954,
0.09762328863143921,
-0.020551104098558426,
-0.040472280234098434,
0.020329726859927177,
-0.016507873311638832,
-0.016428858041763306,
-0.10482979565858841,
0.01424503605812788,
-0.025813791900873184,
-0.027191441506147385,
0.03536699339747429,
0.04825156182050705,
0.028874292969703674,
-0.011211695149540901,
-0.1315828263759613,
-0.058311138302087784,
-0.040215011686086655,
0.07216623425483704,
-0.03293698653578758,
0.014765805564820766,
0.024986054748296738,
-0.14636528491973877,
-0.014292174018919468,
-0.023182544857263565,
-0.05183181166648865,
0.12620830535888672,
-0.07635948061943054,
-0.014073287136852741,
0.0018822728889063,
-0.011107709258794785,
0.013373960740864277,
0.0467691496014595,
0.0012383501743897796,
0.12289994955062866,
0.06410723179578781,
0.01946701668202877,
-0.06220412999391556,
0.11807669699192047,
-0.02555488422513008,
0.08679544925689697,
-0.014950677752494812,
-0.010061361826956272,
0.022072684019804,
0.026623280718922615,
0.015080972574651241,
0.007950641214847565,
-0.03048710711300373,
0.06583044677972794,
-0.08606690168380737,
-0.014030015096068382,
0.11448333412408829,
-0.013141773641109467,
0.027372607961297035,
-0.02589420974254608,
-0.045356813818216324,
0.08778006583452225,
0.0315224789083004,
0.012205583043396473,
0.0070897978730499744,
-0.08216695487499237,
0.04857203736901283,
-0.06753487884998322,
0.030112769454717636,
-0.0506107434630394,
-0.058145854622125626,
0.05696934089064598,
0.032826635986566544,
-0.01047097984701395,
0.055169738829135895,
-0.04194299131631851,
-0.07581780105829239,
-0.013925296254456043,
0.015480810776352882,
-0.06998416781425476,
0.000649871479254216,
0.07244524359703064,
0.04121606796979904,
-0.0071570551954209805,
-0.07225219160318375,
0.06990573555231094,
-0.037965722382068634,
-0.0075732264667749405,
0.010787229984998703,
0.032947614789009094,
0.07504814863204956,
-0.03492026403546333,
-0.03370322287082672,
0.04795999452471733,
-0.03009740076959133,
-0.0610482357442379,
0.012575716711580753,
0.008865930140018463,
-5.880046671791206e-8,
-0.045185379683971405,
-0.02781861461699009,
-0.052219465374946594,
-0.033841587603092194,
0.0036235773004591465,
0.02335040271282196,
0.04458271712064743,
-0.07531657814979553,
0.04325419291853905,
-0.03687477856874466,
0.01966533251106739,
-0.006714902818202972,
0.0461934395134449,
-0.0076866233721375465,
-0.03127573803067207,
0.011813751421868801,
-0.06111918017268181,
-0.02081783302128315,
0.03039991855621338,
0.029226355254650116,
-0.03521434962749481,
-0.05126382037997246,
0.03708542883396149,
-0.02711712196469307,
-0.08529351651668549,
0.08308901637792587,
0.0437568798661232,
0.11958961188793182,
-0.014235683716833591,
0.02055087685585022,
-0.047569211572408676,
0.012000113725662231,
-0.04591739922761917,
-0.015998493880033493,
-0.06947623193264008,
0.05491042882204056,
0.003584120189771056,
0.024097438901662827,
0.05729522556066513,
0.07658129930496216,
-0.0015663211233913898,
-0.035109441727399826,
-0.05894274264574051,
-0.009584221057593822,
-0.0055502490140497684,
-0.02682160958647728,
-0.09797859936952591,
-0.09959165751934052,
0.03227955475449562,
-0.08828062564134598,
0.0014664713526144624,
0.053271155804395676,
-0.06462893635034561,
0.02909226343035698,
-0.12396243959665298,
0.013618349097669125,
-0.04523191601037979,
-0.053666017949581146,
-0.05872345715761185,
-0.0010587333235889673,
-0.00040969575638882816,
-0.011454420164227486,
0.03316618874669075,
-0.009793215431272984
] | 0.093194 |
times that the property was accessed (read or written). This function returns the number of times that the property was accessed. This function is more efficient than checking `ctx.accesses.length` because `ctx.accesses` is a getter that creates a copy of the internal access tracking array. ### `ctx.mockImplementation(value)` \* `value` {any} The new value to be set as the mocked property value. This function is used to change the value returned by the mocked property getter. ### `ctx.mockImplementationOnce(value[, onAccess])` \* `value` {any} The value to be used as the mock's implementation for the invocation number specified by `onAccess`. \* `onAccess` {integer} The invocation number that will use `value`. If the specified invocation has already occurred then an exception is thrown. \*\*Default:\*\* The number of the next invocation. This function is used to change the behavior of an existing mock for a single invocation. Once invocation `onAccess` has occurred, the mock will revert to whatever behavior it would have used had `mockImplementationOnce()` not been called. The following example creates a mock function using `t.mock.property()`, calls the mock property, changes the mock implementation to a different value for the next invocation, and then resumes its previous behavior. ```js test('changes a mock behavior once', (t) => { const obj = { foo: 1 }; const prop = t.mock.property(obj, 'foo', 5); assert.strictEqual(obj.foo, 5); prop.mock.mockImplementationOnce(25); assert.strictEqual(obj.foo, 25); assert.strictEqual(obj.foo, 5); }); ``` #### Caveat For consistency with the rest of the mocking API, this function treats both property gets and sets as accesses. If a property set occurs at the same access index, the "once" value will be consumed by the set operation, and the mocked property value will be changed to the "once" value. This may lead to unexpected behavior if you intend the "once" value to only be used for a get operation. ### `ctx.resetAccesses()` Resets the access history of the mocked property. ### `ctx.restore()` Resets the implementation of the mock property to its original behavior. The mock can still be used after calling this function. ## Class: `MockTracker` The `MockTracker` class is used to manage mocking functionality. The test runner module provides a top level `mock` export which is a `MockTracker` instance. Each test also provides its own `MockTracker` instance via the test context's `mock` property. ### `mock.fn([original[, implementation]][, options])` \* `original` {Function|AsyncFunction} An optional function to create a mock on. \*\*Default:\*\* A no-op function. \* `implementation` {Function|AsyncFunction} An optional function used as the mock implementation for `original`. This is useful for creating mocks that exhibit one behavior for a specified number of calls and then restore the behavior of `original`. \*\*Default:\*\* The function specified by `original`. \* `options` {Object} Optional configuration options for the mock function. The following properties are supported: \* `times` {integer} The number of times that the mock will use the behavior of `implementation`. Once the mock function has been called `times` times, it will automatically restore the behavior of `original`. This value must be an integer greater than zero. \*\*Default:\*\* `Infinity`. \* Returns: {Proxy} The mocked function. The mocked function contains a special `mock` property, which is an instance of [`MockFunctionContext`][], and can be used for inspecting and changing the behavior of the mocked function. This function is used to create a mock function. The following example creates a mock function that increments a counter by one on each invocation. The `times` option is used to modify the mock behavior such that the first two invocations add two to the counter instead of one. ```js test('mocks a counting function', (t) => { let cnt = 0; function addOne() { cnt++; return cnt; } function addTwo() { cnt += 2; return | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.0570237897336483,
0.053333576768636703,
-0.030886683613061905,
0.06033530831336975,
-0.0634523332118988,
-0.07555247098207474,
0.0948454812169075,
-0.009935162961483002,
-0.0040453714318573475,
0.018357092514634132,
-0.031005991622805595,
-0.02569286711513996,
0.028265034779906273,
-0.08435826003551483,
0.004293797537684441,
-0.04249431937932968,
0.06636121869087219,
-0.06064935773611069,
-0.05402734503149986,
0.00135255407076329,
0.04713950678706169,
-0.03879239782691002,
0.012711024843156338,
-0.02692364901304245,
-0.03289090469479561,
-0.06318029016256332,
-0.1298397034406662,
-0.06443788856267929,
0.07536295056343079,
0.019843637943267822,
0.029794881120324135,
0.0776945948600769,
-0.04005967825651169,
-0.022986210882663727,
0.05291930213570595,
-0.04458277300000191,
0.02647342160344124,
0.03958384692668915,
-0.005057743284851313,
0.0662548691034317,
-0.011488266289234161,
0.0425504632294178,
0.013054018840193748,
0.013303050771355629,
0.01121619064360857,
-0.017563596367836,
0.07637109607458115,
-0.034731946885585785,
-0.03330665081739426,
0.043758682906627655,
-0.00040825700853019953,
0.039188776165246964,
0.017736904323101044,
0.025735322386026382,
0.0018691435689106584,
0.022116389125585556,
0.018462199717760086,
-0.028705453500151634,
0.01653878018260002,
0.04428333044052124,
-0.028337543830275536,
-0.033692263066768646,
-0.0003870435757562518,
0.036954376846551895,
0.01755824312567711,
-0.039995595812797546,
-0.012776187621057034,
-0.028522135689854622,
0.04031869396567345,
-0.07130808383226395,
0.016897736117243767,
0.05544142797589302,
0.05374946817755699,
0.08884729444980621,
0.06895890086889267,
0.08605634421110153,
-0.005618360824882984,
-0.09109305590391159,
0.08457500487565994,
-0.08143442869186401,
-0.010570213198661804,
-0.02946343459188938,
-0.044034864753484726,
-0.006723410915583372,
0.016254864633083344,
0.050666313618421555,
0.06648542732000351,
0.004910685122013092,
0.10459631681442261,
0.07134288549423218,
0.08050843328237534,
0.0034016065765172243,
-0.09639181941747665,
0.09166338294744492,
0.07747101783752441,
-0.04449453204870224,
0.08496969938278198,
-0.027421830222010612,
0.009564412757754326,
0.05023243650794029,
0.009649241343140602,
0.030303267762064934,
0.046867307275533676,
-0.002977788681164384,
0.009081538766622543,
-0.055876389145851135,
0.015349780209362507,
-0.125106543302536,
-0.022917460650205612,
0.02506393939256668,
-0.0007182403351180255,
0.024011868983507156,
0.029259352013468742,
0.022011345252394676,
0.02549838460981846,
0.0004207475867588073,
-0.025498531758785248,
-0.06287510693073273,
0.04357539489865303,
-0.01978617161512375,
0.07508889585733414,
-0.02302578277885914,
0.006905490532517433,
0.001466156099922955,
0.01174387987703085,
0.032804008573293686,
-0.027919694781303406,
5.401166953288016e-33,
-0.07544157654047012,
0.014567431062459946,
0.019159512594342232,
0.043100371956825256,
0.0294455848634243,
-0.05546531453728676,
0.06634537875652313,
-0.001502526574768126,
-0.0705888643860817,
-0.06489656865596771,
0.044703200459480286,
0.09635964035987854,
0.008830434642732143,
-0.013180768117308617,
0.01566968858242035,
0.05415976420044899,
0.055895283818244934,
0.034273695200681686,
-0.03875502198934555,
0.03640640527009964,
0.07836154848337173,
-0.010642972774803638,
-0.007010638248175383,
-0.000013634026799991261,
0.005470907315611839,
-0.04406087473034859,
-0.07088234275579453,
0.08014386892318726,
-0.055838096886873245,
-0.0030175289139151573,
0.01113145425915718,
0.017565859481692314,
-0.017268002033233643,
0.11915191262960434,
0.03586902469396591,
-0.017724348232150078,
0.08487164974212646,
-0.01945171318948269,
-0.03782240301370621,
0.026257885619997978,
-0.06627906113862991,
-0.09242197126150131,
0.03575434163212776,
-0.020852355286478996,
-0.06840830296278,
-0.1720050573348999,
-0.08986791968345642,
-0.02354663424193859,
0.05658673495054245,
0.03572394698858261,
0.04252537339925766,
0.10736332088708878,
-0.033163491636514664,
-0.04635724425315857,
0.010305861942470074,
-0.03147286921739578,
0.03036421351134777,
-0.019376615062355995,
0.03932150453329086,
0.061750587075948715,
0.010105600580573082,
0.016570834442973137,
0.012301720678806305,
0.025315767154097557,
-0.08699995279312134,
0.05198488011956215,
0.014755948446691036,
-0.11688756197690964,
0.058014970272779465,
-0.0035637738183140755,
-0.049856506288051605,
0.013227958232164383,
-0.09849153459072113,
-0.04408615455031395,
0.02002144791185856,
-0.07331392914056778,
-0.0007230761111713946,
0.020791122689843178,
-0.03435615077614784,
-0.004418236203491688,
0.03407200053334236,
-0.0023369435220956802,
-0.04934588819742203,
0.14880849421024323,
-0.0814579501748085,
-0.08830956369638443,
0.0026113062631338835,
-0.04475511237978935,
0.02094474993646145,
-0.12133712321519852,
0.03405589982867241,
-0.029852958396077156,
-0.06671607494354248,
-0.06423281878232956,
-0.003816665383055806,
-5.7958347734727836e-33,
0.021563338115811348,
0.01033102348446846,
-0.009017182514071465,
0.09980586171150208,
-0.04646534472703934,
-0.0953328087925911,
-0.018546251580119133,
-0.012693434022367,
-0.002988077700138092,
-0.12064614146947861,
0.04223952814936638,
-0.03581342101097107,
-0.057067256420850754,
-0.0250758845359087,
0.02224348857998848,
-0.016757559031248093,
0.04103204235434532,
-0.15156391263008118,
-0.02671467512845993,
-0.01140235923230648,
0.08375829458236694,
-0.0020495483186095953,
0.0531984306871891,
-0.011580288410186768,
-0.12590420246124268,
-0.003786792978644371,
-0.03217049688100815,
-0.07505480200052261,
0.05972763150930405,
-0.040820442140102386,
-0.051366452127695084,
0.033594921231269836,
-0.024358028545975685,
0.02313949726521969,
0.010797621682286263,
-0.027198603376746178,
0.10793953388929367,
0.0771104246377945,
-0.028415856882929802,
0.02547750249505043,
0.08638481050729752,
0.015297628939151764,
0.10036526620388031,
0.014505811035633087,
0.013660790398716927,
0.053451940417289734,
-0.018933691084384918,
-0.006105991080403328,
0.045493245124816895,
-0.016598103567957878,
0.1533280462026596,
-0.060364559292793274,
0.011312047950923443,
0.07398010045289993,
0.022108228877186775,
0.0373673178255558,
-0.016279736533761024,
-0.051760509610176086,
0.04525357484817505,
0.0054923659190535545,
0.030548319220542908,
0.03538241982460022,
-0.12531784176826477,
0.08618723601102829,
-0.05731876939535141,
0.03709109500050545,
-0.041557129472494125,
-0.0626089945435524,
0.014434061013162136,
-0.0013424213975667953,
0.00942711066454649,
-0.05312859266996384,
-0.03796405717730522,
-0.052268318831920624,
0.01862386241555214,
0.022467127069830894,
-0.02645120397210121,
-0.04358702525496483,
0.026741987094283104,
0.07037629932165146,
-0.058691080659627914,
-0.055075790733098984,
0.03740765526890755,
-0.03573237359523773,
-0.036297354847192764,
-0.005487395916134119,
-0.024776063859462738,
0.011874322779476643,
0.01000202726572752,
0.028564948588609695,
0.0008327214745804667,
-0.00900881178677082,
-0.04468073695898056,
0.020482927560806274,
-0.02947458252310753,
-5.5780471797106657e-8,
-0.03987044841051102,
-0.045096490532159805,
-0.02402936853468418,
0.02111809514462948,
0.02684633992612362,
0.029849179089069366,
-0.009156561456620693,
-0.012757558375597,
0.051850300282239914,
0.004026832990348339,
0.06370276212692261,
0.01413740124553442,
0.0612146221101284,
-0.02992146834731102,
-0.021555999293923378,
-0.011736464686691761,
-0.05426133796572685,
-0.08268676698207855,
-0.0030597313307225704,
0.023420926183462143,
-0.03562457486987114,
0.015841001644730568,
0.0255130548030138,
-0.01768789254128933,
-0.016157951205968857,
0.08517549186944962,
0.05584409460425377,
0.08798294514417648,
-0.03591831028461456,
0.05303474888205528,
-0.057673756033182144,
0.008584714494645596,
0.0011943104909732938,
-0.002395475981757045,
-0.029333217069506645,
0.08093246072530746,
-0.03629526123404503,
0.06320168823003769,
0.06738042831420898,
0.04659010469913483,
-0.021894818171858788,
-0.042314060032367706,
-0.016573918983340263,
0.002393106697127223,
-0.009854747913777828,
-0.0450211800634861,
-0.0821378082036972,
0.0035186726599931717,
0.050723228603601456,
-0.12445574998855591,
-0.024755515158176422,
0.03024768829345703,
-0.04785469174385071,
0.018419435247778893,
-0.13532361388206482,
0.02253963239490986,
-0.010199799202382565,
-0.05416968837380409,
-0.03684128448367119,
0.012701294384896755,
0.009507413022220135,
-0.007730904500931501,
-0.023403093218803406,
-0.011726988479495049
] | 0.069943 |
The `times` option is used to modify the mock behavior such that the first two invocations add two to the counter instead of one. ```js test('mocks a counting function', (t) => { let cnt = 0; function addOne() { cnt++; return cnt; } function addTwo() { cnt += 2; return cnt; } const fn = t.mock.fn(addOne, addTwo, { times: 2 }); assert.strictEqual(fn(), 2); assert.strictEqual(fn(), 4); assert.strictEqual(fn(), 5); assert.strictEqual(fn(), 6); }); ``` ### `mock.getter(object, methodName[, implementation][, options])` This function is syntax sugar for [`MockTracker.method`][] with `options.getter` set to `true`. ### `mock.method(object, methodName[, implementation][, options])` \* `object` {Object} The object whose method is being mocked. \* `methodName` {string|symbol} The identifier of the method on `object` to mock. If `object[methodName]` is not a function, an error is thrown. \* `implementation` {Function|AsyncFunction} An optional function used as the mock implementation for `object[methodName]`. \*\*Default:\*\* The original method specified by `object[methodName]`. \* `options` {Object} Optional configuration options for the mock method. The following properties are supported: \* `getter` {boolean} If `true`, `object[methodName]` is treated as a getter. This option cannot be used with the `setter` option. \*\*Default:\*\* false. \* `setter` {boolean} If `true`, `object[methodName]` is treated as a setter. This option cannot be used with the `getter` option. \*\*Default:\*\* false. \* `times` {integer} The number of times that the mock will use the behavior of `implementation`. Once the mocked method has been called `times` times, it will automatically restore the original behavior. This value must be an integer greater than zero. \*\*Default:\*\* `Infinity`. \* Returns: {Proxy} The mocked method. The mocked method contains a special `mock` property, which is an instance of [`MockFunctionContext`][], and can be used for inspecting and changing the behavior of the mocked method. This function is used to create a mock on an existing object method. The following example demonstrates how a mock is created on an existing object method. ```js test('spies on an object method', (t) => { const number = { value: 5, subtract(a) { return this.value - a; }, }; t.mock.method(number, 'subtract'); assert.strictEqual(number.subtract.mock.callCount(), 0); assert.strictEqual(number.subtract(3), 2); assert.strictEqual(number.subtract.mock.callCount(), 1); const call = number.subtract.mock.calls[0]; assert.deepStrictEqual(call.arguments, [3]); assert.strictEqual(call.result, 2); assert.strictEqual(call.error, undefined); assert.strictEqual(call.target, undefined); assert.strictEqual(call.this, number); }); ``` ### `mock.module(specifier[, options])` > Stability: 1.0 - Early development \* `specifier` {string|URL} A string identifying the module to mock. \* `options` {Object} Optional configuration options for the mock module. The following properties are supported: \* `cache` {boolean} If `false`, each call to `require()` or `import()` generates a new mock module. If `true`, subsequent calls will return the same module mock, and the mock module is inserted into the CommonJS cache. \*\*Default:\*\* false. \* `defaultExport` {any} An optional value used as the mocked module's default export. If this value is not provided, ESM mocks do not include a default export. If the mock is a CommonJS or builtin module, this setting is used as the value of `module.exports`. If this value is not provided, CJS and builtin mocks use an empty object as the value of `module.exports`. \* `namedExports` {Object} An optional object whose keys and values are used to create the named exports of the mock module. If the mock is a CommonJS or builtin module, these values are copied onto `module.exports`. Therefore, if a mock is created with both named exports and a non-object default export, the mock will throw an exception when used as a CJS or builtin module. \* Returns: {MockModuleContext} An object that can be used to manipulate the mock. This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON modules, and Node.js builtin modules. Any references to the original module prior to mocking are not impacted. | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.059458307921886444,
-0.054624393582344055,
0.006206830497831106,
0.023087169975042343,
-0.08218668401241302,
0.006696495693176985,
0.001957744127139449,
0.0389394536614418,
0.026009758934378624,
-0.013004119507968426,
0.012320807203650475,
-0.011683209799230099,
-0.022493012249469757,
-0.0075989291071891785,
0.039256758987903595,
-0.03643759340047836,
-0.05506352707743645,
-0.04241170734167099,
0.015618964098393917,
-0.0986296609044075,
0.0719539001584053,
-0.0771387442946434,
0.0452035628259182,
-0.00908974464982748,
-0.019182289019227028,
-0.10645364969968796,
-0.10067035257816315,
-0.026366323232650757,
0.056165911257267,
-0.018644969910383224,
0.07408268004655838,
0.044485945254564285,
-0.05035165324807167,
0.016355032101273537,
-0.038048747926950455,
-0.024079665541648865,
-0.019315600395202637,
-0.02181369438767433,
0.0011974666267633438,
0.018704822286963463,
-0.03874695673584938,
0.025997912511229515,
-0.03237216919660568,
-0.06136535108089447,
0.07639262825250626,
0.06814563274383545,
0.01906903088092804,
0.041959498077631,
-0.03199683874845505,
0.0348900705575943,
0.036639291793107986,
0.1172490045428276,
-0.044236525893211365,
-0.017806315794587135,
0.055216338485479355,
-0.019213128834962845,
0.02874106355011463,
-0.025258056819438934,
0.025895364582538605,
0.06708857417106628,
0.0004793248081114143,
-0.035583872348070145,
0.009700163267552853,
-0.006929643917828798,
0.06750135123729706,
-0.032564565539360046,
-0.01992487907409668,
0.04170753061771393,
-0.016603391617536545,
0.15161068737506866,
0.032844312489032745,
0.038754627108573914,
0.08933897316455841,
0.015200035646557808,
-0.010093051008880138,
0.013078754767775536,
-0.062369052320718765,
0.002776490291580558,
0.024733630940318108,
0.005597434472292662,
-0.025585131719708443,
-0.07957302033901215,
-0.016441505402326584,
-0.011874774470925331,
-0.046230826526880264,
0.015594350174069405,
0.0315142385661602,
0.009998926892876625,
0.04779529571533203,
-0.03541547432541847,
0.02185770869255066,
0.01663750596344471,
-0.13821497559547424,
0.07451187819242477,
0.01573481783270836,
-0.056884538382291794,
0.0842367559671402,
0.08939619362354279,
0.00895474012941122,
0.049998294562101364,
-0.002439542207866907,
-0.07099593430757523,
0.029304539784789085,
-0.041501905769109726,
-0.001990959979593754,
-0.026361975818872452,
0.01715976744890213,
-0.11157628148794174,
-0.012355930171906948,
0.026041865348815918,
0.04657266288995743,
0.0682978555560112,
0.055258046835660934,
0.03063274547457695,
-0.01596160978078842,
-0.022380368784070015,
0.003437543287873268,
-0.025077171623706818,
0.06953907757997513,
-0.0062063997611403465,
0.10015013068914413,
0.10012608021497726,
0.08021019399166107,
-0.022311929613351822,
0.000036562963941833004,
0.07875750958919525,
0.027391809970140457,
1.2799573195374987e-33,
0.0013430934632197022,
-0.06028738245368004,
0.04240350425243378,
0.04273546114563942,
0.043095663189888,
0.04300592839717865,
-0.007130438461899757,
0.03867735713720322,
-0.059262074530124664,
0.014824988320469856,
0.07817472517490387,
-0.046672139316797256,
0.02918245457112789,
-0.0027278263587504625,
0.009155628271400928,
0.050577569752931595,
0.03198607638478279,
-0.05937056243419647,
0.024390308186411858,
0.00781410001218319,
0.08760572224855423,
-0.07652916014194489,
-0.02150038070976734,
0.04176679626107216,
-0.025660013779997826,
-0.017799168825149536,
0.0023583192378282547,
0.026657287031412125,
-0.0752517506480217,
-0.01344960369169712,
0.048285022377967834,
0.032410070300102234,
-0.07919815182685852,
0.10271713137626648,
0.05790473893284798,
-0.04939817264676094,
0.07919634133577347,
0.04483136534690857,
-0.10006209462881088,
-0.03280000388622284,
-0.02769424021244049,
-0.06300908327102661,
-0.04489880055189133,
0.010322529822587967,
0.01520571205765009,
-0.09780077636241913,
-0.007249918300658464,
-0.02161656878888607,
0.09493786096572876,
0.060757946223020554,
-0.01572933793067932,
0.040971577167510986,
0.055058080703020096,
-0.06300198286771774,
0.02040102332830429,
0.0019816753920167685,
0.08954204618930817,
-0.017720501869916916,
0.010350789874792099,
0.07774456590414047,
-0.012463505379855633,
-0.03500683233141899,
-0.06808960437774658,
-0.008798682130873203,
-0.07266166806221008,
0.07104411721229553,
-0.019330555573105812,
-0.006681834347546101,
0.09241359680891037,
0.042734529823064804,
-0.018017083406448364,
0.005662481766194105,
-0.07992731034755707,
-0.01657593995332718,
-0.05248665064573288,
-0.09053540974855423,
-0.00400962121784687,
0.00419132923707366,
-0.04395885393023491,
-0.051290180534124374,
0.05737023428082466,
0.004268556367605925,
-0.0441947877407074,
0.07131785154342651,
-0.03612508624792099,
-0.05141792446374893,
-0.041758228093385696,
-0.03430281579494476,
0.04765165224671364,
-0.035743292421102524,
0.01223434042185545,
-0.011145533062517643,
0.025555264204740524,
-0.020125264301896095,
-0.01076589711010456,
-3.807036452467695e-33,
-0.022973986342549324,
0.030848700553178787,
-0.0012050953228026628,
0.16413350403308868,
0.06840579211711884,
-0.04666612669825554,
-0.010757233016192913,
0.008333934471011162,
0.05390356853604317,
-0.05098852515220642,
0.019224684685468674,
-0.005394848063588142,
0.011585468426346779,
-0.037587784230709076,
0.03317725285887718,
-0.019313108175992966,
-0.059310801327228546,
-0.051115941256284714,
0.0267464742064476,
0.02721698395907879,
0.04682086780667305,
-0.032695259898900986,
0.062065768986940384,
-0.059123773127794266,
-0.039656393229961395,
0.044996947050094604,
-0.012395569123327732,
-0.04449182748794556,
0.08403759449720383,
-0.03903232514858246,
0.017795545980334282,
-0.015065062791109085,
0.022877415642142296,
0.012483980506658554,
0.11005053669214249,
-0.061063531786203384,
0.11003413051366806,
0.09176044911146164,
0.0065455203875899315,
-0.017596684396266937,
-0.004937394056469202,
-0.04197310283780098,
0.03223931044340134,
-0.031642839312553406,
-0.040730737149715424,
0.08007928729057312,
-0.036771152168512344,
0.0176953487098217,
0.013011317700147629,
-0.0845697820186615,
0.06668941676616669,
-0.09443017095327377,
-0.10903578996658325,
0.09554004669189453,
0.010911996476352215,
-0.06884115934371948,
-0.06299606710672379,
-0.06354779750108719,
0.12696903944015503,
0.06017058342695236,
-0.04407802224159241,
-0.053360775113105774,
-0.047345343977212906,
0.014126594178378582,
-0.013727325014770031,
-0.02395949698984623,
-0.10247991979122162,
-0.024455228820443153,
0.06851939857006073,
0.061602942645549774,
-0.0200791098177433,
-0.006485018413513899,
-0.06995260715484619,
-0.08184123784303665,
-0.00924061331897974,
0.024933241307735443,
-0.055399008095264435,
-0.04629546403884888,
0.02449002116918564,
0.03699472174048424,
-0.029533598572015762,
-0.07244955003261566,
-0.004079815931618214,
-0.02019173838198185,
-0.07225264608860016,
0.007699294947087765,
0.05904696136713028,
0.10499493032693863,
-0.03408987447619438,
0.029620064422488213,
0.052652716636657715,
0.05597816780209541,
-0.04013284668326378,
-0.013996959663927555,
-0.047604553401470184,
-5.018209137119811e-8,
0.002998319687321782,
-0.09691661596298218,
-0.040635980665683746,
-0.020366283133625984,
-0.010903884656727314,
-0.07703420519828796,
-0.010342718102037907,
0.00474501820281148,
0.03258160874247551,
-0.019571974873542786,
0.03705040365457535,
0.05308984965085983,
0.08417187631130219,
-0.02381342463195324,
0.0008108405745588243,
-0.08220764994621277,
-0.051298342645168304,
0.009741525165736675,
-0.017061863094568253,
0.060863472521305084,
-0.08878690749406815,
0.001826206804253161,
0.07193993031978607,
-0.06353521347045898,
-0.04515620693564415,
0.08328929543495178,
0.04056341201066971,
0.0344843827188015,
0.016841348260641098,
0.04664053022861481,
-0.02497490867972374,
0.036321550607681274,
-0.05515550449490547,
-0.0070688240230083466,
-0.04877388849854469,
0.012785726226866245,
-0.0715593546628952,
0.047728847712278366,
0.05894935876131058,
0.040660519152879715,
-0.05885203182697296,
-0.09245507419109344,
-0.05083038657903671,
0.01872866041958332,
-0.004913785494863987,
-0.09942439198493958,
-0.06298109143972397,
-0.03610964119434357,
-0.03279541805386543,
-0.09146815538406372,
-0.030594823881983757,
0.02515960857272148,
-0.010806405916810036,
-0.03606805577874184,
-0.07665764540433884,
0.06569604575634003,
-0.005160605534911156,
-0.107333242893219,
-0.04590138420462608,
0.028233805671334267,
0.03527858108282089,
-0.019671162590384483,
0.000020029565348522738,
-0.01912429742515087
] | 0.031733 |
as a CJS or builtin module. \* Returns: {MockModuleContext} An object that can be used to manipulate the mock. This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON modules, and Node.js builtin modules. Any references to the original module prior to mocking are not impacted. In order to enable module mocking, Node.js must be started with the [`--experimental-test-module-mocks`][] command-line flag. The following example demonstrates how a mock is created for a module. ```js test('mocks a builtin module in both module systems', async (t) => { // Create a mock of 'node:readline' with a named export named 'fn', which // does not exist in the original 'node:readline' module. const mock = t.mock.module('node:readline', { namedExports: { fn() { return 42; } }, }); let esmImpl = await import('node:readline'); let cjsImpl = require('node:readline'); // cursorTo() is an export of the original 'node:readline' module. assert.strictEqual(esmImpl.cursorTo, undefined); assert.strictEqual(cjsImpl.cursorTo, undefined); assert.strictEqual(esmImpl.fn(), 42); assert.strictEqual(cjsImpl.fn(), 42); mock.restore(); // The mock is restored, so the original builtin module is returned. esmImpl = await import('node:readline'); cjsImpl = require('node:readline'); assert.strictEqual(typeof esmImpl.cursorTo, 'function'); assert.strictEqual(typeof cjsImpl.cursorTo, 'function'); assert.strictEqual(esmImpl.fn, undefined); assert.strictEqual(cjsImpl.fn, undefined); }); ``` ### `mock.property(object, propertyName[, value])` \* `object` {Object} The object whose value is being mocked. \* `propertyName` {string|symbol} The identifier of the property on `object` to mock. \* `value` {any} An optional value used as the mock value for `object[propertyName]`. \*\*Default:\*\* The original property value. \* Returns: {Proxy} A proxy to the mocked object. The mocked object contains a special `mock` property, which is an instance of [`MockPropertyContext`][], and can be used for inspecting and changing the behavior of the mocked property. Creates a mock for a property value on an object. This allows you to track and control access to a specific property, including how many times it is read (getter) or written (setter), and to restore the original value after mocking. ```js test('mocks a property value', (t) => { const obj = { foo: 42 }; const prop = t.mock.property(obj, 'foo', 100); assert.strictEqual(obj.foo, 100); assert.strictEqual(prop.mock.accessCount(), 1); assert.strictEqual(prop.mock.accesses[0].type, 'get'); assert.strictEqual(prop.mock.accesses[0].value, 100); obj.foo = 200; assert.strictEqual(prop.mock.accessCount(), 2); assert.strictEqual(prop.mock.accesses[1].type, 'set'); assert.strictEqual(prop.mock.accesses[1].value, 200); prop.mock.restore(); assert.strictEqual(obj.foo, 42); }); ``` ### `mock.reset()` This function restores the default behavior of all mocks that were previously created by this `MockTracker` and disassociates the mocks from the `MockTracker` instance. Once disassociated, the mocks can still be used, but the `MockTracker` instance can no longer be used to reset their behavior or otherwise interact with them. After each test completes, this function is called on the test context's `MockTracker`. If the global `MockTracker` is used extensively, calling this function manually is recommended. ### `mock.restoreAll()` This function restores the default behavior of all mocks that were previously created by this `MockTracker`. Unlike `mock.reset()`, `mock.restoreAll()` does not disassociate the mocks from the `MockTracker` instance. ### `mock.setter(object, methodName[, implementation][, options])` This function is syntax sugar for [`MockTracker.method`][] with `options.setter` set to `true`. ## Class: `MockTimers` Mocking timers is a technique commonly used in software testing to simulate and control the behavior of timers, such as `setInterval` and `setTimeout`, without actually waiting for the specified time intervals. MockTimers is also able to mock the `Date` object. The [`MockTracker`][] provides a top-level `timers` export which is a `MockTimers` instance. ### `timers.enable([enableOptions])` Enables timer mocking for the specified timers. \* `enableOptions` {Object} Optional configuration options for enabling timer mocking. The following properties are supported: \* `apis` {Array} An optional array containing the timers to mock. The currently supported timer values are `'setInterval'`, `'setTimeout'`, `'setImmediate'`, and `'Date'`. \*\*Default:\*\* `['setInterval', 'setTimeout', 'setImmediate', 'Date']`. If no array is provided, all time related APIs (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, `'clearTimeout'`, `'setImmediate'`, `'clearImmediate'`, and `'Date'`) will be | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.09400658309459686,
-0.046512529253959656,
-0.02039914019405842,
0.059520281851291656,
0.06522616744041443,
-0.039447858929634094,
-0.044722266495227814,
0.04303520545363426,
-0.005167096387594938,
-0.029694223776459694,
-0.001110435463488102,
-0.0028462905902415514,
-0.0011819102801382542,
-0.02054695039987564,
0.09342420101165771,
-0.05263978987932205,
0.08082088828086853,
0.019569460302591324,
0.008099118247628212,
-0.035643935203552246,
0.009111820720136166,
-0.06361448764801025,
0.052501194179058075,
-0.004384408704936504,
-0.06566362828016281,
-0.04466726630926132,
-0.054657891392707825,
0.0342315249145031,
-0.010986477136611938,
-0.0400678887963295,
0.02879810519516468,
0.05230918526649475,
-0.02210274711251259,
-0.004530282225459814,
0.004588430747389793,
0.041038013994693756,
0.011140892282128334,
-0.07566168159246445,
-0.009383995085954666,
-0.07416540384292603,
-0.010873550549149513,
0.10944563895463943,
-0.01723923534154892,
-0.06226281076669693,
0.09468842297792435,
-0.06331337988376617,
0.021844254806637764,
0.025028172880411148,
-0.07189568877220154,
0.07791837304830551,
0.016228940337896347,
0.022252872586250305,
-0.030688561499118805,
-0.0221162848174572,
-0.0011272280244156718,
0.009642095305025578,
-0.006892244331538677,
-0.04820600524544716,
0.05045474320650101,
0.0703439712524414,
0.0010179139208048582,
0.002567675430327654,
0.06990160793066025,
-0.02654324844479561,
0.012341193854808807,
-0.0051900227554142475,
-0.012047269381582737,
0.03045772947371006,
0.07157790660858154,
-0.00497993640601635,
0.0016778975259512663,
-0.007453063502907753,
0.1000596284866333,
0.05506494641304016,
0.015087551437318325,
0.02180382050573826,
-0.027915876358747482,
-0.006975196301937103,
0.05371635779738426,
0.043051447719335556,
-0.08603981882333755,
-0.01598932594060898,
-0.05691102147102356,
-0.012431162409484386,
-0.11057081073522568,
0.07119908928871155,
0.012656260281801224,
0.033568233251571655,
0.03333977237343788,
0.005212794523686171,
0.014420771040022373,
-0.09602616727352142,
-0.16065287590026855,
0.09418369829654694,
0.021739887073636055,
-0.05582858994603157,
0.02986694499850273,
0.09428205341100693,
-0.022681260481476784,
-0.0034179645590484142,
0.01645558513700962,
0.0356280691921711,
0.07865534722805023,
0.024096550419926643,
0.031179727986454964,
-0.0009429242345504463,
0.05065246671438217,
-0.10167334228754044,
0.012590024620294571,
-0.002001202432438731,
-0.008223537355661392,
0.0328751876950264,
0.008366250433027744,
-0.031295038759708405,
-0.04970451071858406,
-0.0572810173034668,
0.03204058110713959,
-0.06367683410644531,
0.07965990155935287,
0.09949297457933426,
0.10458457469940186,
0.0452052541077137,
0.058977968990802765,
0.021019935607910156,
0.09336421638727188,
0.021853994578123093,
0.030535755679011345,
2.3310376237752437e-33,
-0.016088755801320076,
-0.02404988743364811,
0.024315323680639267,
0.1415797770023346,
0.0678974986076355,
0.0020671195816248655,
0.07212314754724503,
0.018705353140830994,
-0.1326669156551361,
-0.08009131252765656,
0.03795943781733513,
0.06948001682758331,
0.06713288277387619,
0.04724821820855141,
-0.028279155492782593,
0.049092743545770645,
0.0007447340176440775,
-0.10638953745365143,
0.006956043187528849,
0.03162382170557976,
0.03849798068404198,
0.008188934065401554,
0.02740444242954254,
0.004906800575554371,
-0.007105226628482342,
-0.0478367805480957,
-0.06338091194629669,
0.032344698905944824,
-0.0022029546089470387,
0.03712198883295059,
-0.03171525523066521,
0.05028317868709564,
-0.02692689187824726,
0.09151434898376465,
-0.008245092816650867,
0.01778499409556389,
0.04168905317783356,
0.03367430344223976,
-0.14422187209129333,
0.03993786498904228,
-0.02473345398902893,
0.0313277542591095,
-0.08022268116474152,
0.029134012758731842,
-0.036567725241184235,
-0.17687836289405823,
-0.02594817243516445,
-0.05462390556931496,
0.11535884439945221,
-0.057837653905153275,
-0.029496371746063232,
0.014176384545862675,
0.06793578714132309,
-0.09269745647907257,
0.08211372047662735,
0.013947179540991783,
0.08590179681777954,
-0.05035353824496269,
-0.0095853041857481,
0.003637302201241255,
0.009112335741519928,
-0.04942192882299423,
-0.04822404310107231,
0.0905398279428482,
0.01562004629522562,
0.07473757117986679,
-0.024449659511446953,
-0.056791145354509354,
-0.011558332480490208,
-0.002935305703431368,
0.02427103742957115,
-0.008670829236507416,
-0.09773031622171402,
0.06809470802545547,
-0.036186959594488144,
0.024871595203876495,
-0.02917063795030117,
0.030001750215888023,
-0.0054541644640266895,
0.01796397753059864,
0.0715298131108284,
0.008522490970790386,
-0.06816846877336502,
0.0638713464140892,
0.02055385150015354,
-0.049632344394922256,
-0.045835528522729874,
0.005985498894006014,
0.10961738973855972,
-0.11011258512735367,
0.055140506476163864,
0.0007163574919104576,
-0.04033759608864784,
-0.03973841294646263,
-0.02785433456301689,
-4.429203204496869e-33,
-0.004044133238494396,
0.06528022140264511,
-0.04714621976017952,
0.11646930873394012,
-0.07199225574731827,
-0.021269530057907104,
-0.02877757139503956,
-0.06583945453166962,
0.01625891402363777,
0.03793616220355034,
0.003091583028435707,
-0.09199199825525284,
-0.0013684608275070786,
0.011934086680412292,
0.02705313079059124,
0.012542588636279106,
-0.0570051483809948,
-0.03713072091341019,
0.02569393441081047,
-0.015811435878276825,
0.03235328197479248,
-0.02232583984732628,
0.0571092814207077,
-0.0181435476988554,
-0.08490851521492004,
-0.02193780615925789,
-0.08670340478420258,
-0.03566056117415428,
-0.018986495211720467,
-0.09533045440912247,
-0.04545537754893303,
0.04876238852739334,
-0.010740939527750015,
0.008679128251969814,
0.07006099820137024,
0.020549900829792023,
0.0281587652862072,
0.0797216072678566,
0.013678768649697304,
-0.09932182729244232,
0.033392637968063354,
0.07706688344478607,
-0.03025083616375923,
-0.03454964980483055,
0.022465113550424576,
0.04512668401002884,
-0.00008863726543495432,
-0.004062154795974493,
0.05393390357494354,
-0.05413653329014778,
-0.011986265890300274,
-0.045320410281419754,
-0.037901971489191055,
-0.018723009154200554,
-0.025049304589629173,
-0.07097536325454712,
-0.004867324605584145,
0.058584824204444885,
0.05285545811057091,
0.04208382964134216,
0.051467858254909515,
-0.09911736845970154,
-0.08741433173418045,
-0.03985350951552391,
-0.03144947066903114,
-0.02882099337875843,
-0.06368353217840195,
-0.004993560258299112,
0.15060316026210785,
-0.03522532433271408,
-0.0033016568049788475,
0.01656101457774639,
-0.031681422144174576,
-0.003416130319237709,
0.007916250266134739,
0.047922730445861816,
-0.035281091928482056,
-0.05512731522321701,
0.01939806155860424,
0.025514116510748863,
0.003182058921083808,
-0.013043771497905254,
-0.029575243592262268,
0.005362065974622965,
0.03996088728308678,
-0.004119867458939552,
-0.00933500099927187,
0.056009817868471146,
-0.026422975584864616,
0.011712747626006603,
0.03896693140268326,
-0.051898445934057236,
-0.05574094131588936,
-0.003764641471207142,
-0.02757597528398037,
-5.5608538218621106e-8,
-0.034738343209028244,
0.012971421703696251,
-0.09346271306276321,
0.011871998198330402,
-0.02347387932240963,
0.03460114449262619,
0.023963039740920067,
-0.04612986743450165,
0.07553167641162872,
0.031747691333293915,
-0.0009262179373763502,
0.030399128794670105,
0.028047019615769386,
-0.025790560990571976,
-0.018388213589787483,
0.025633299723267555,
-0.01299541536718607,
0.027393339201807976,
0.040199097245931625,
0.0376887321472168,
-0.01862139254808426,
0.06303764134645462,
0.013227580115199089,
0.06501919031143188,
-0.03358246386051178,
0.06107410043478012,
0.09796115010976791,
0.06716669350862503,
-0.02090614289045334,
-0.0064414613880217075,
-0.08457159250974655,
-0.047643035650253296,
-0.04365118592977524,
-0.049985505640506744,
-0.05350238457322121,
-0.0224721971899271,
0.0392458513379097,
0.007313362788408995,
0.036913394927978516,
0.05327226221561432,
-0.02743147499859333,
0.017858564853668213,
-0.07217243313789368,
-0.04500116407871246,
-0.023034600540995598,
-0.024412084370851517,
-0.05027630180120468,
0.03232059255242348,
-0.0729009211063385,
-0.08418184518814087,
0.02738417126238346,
-0.03183756023645401,
-0.06129860877990723,
-0.010319586843252182,
-0.08827179670333862,
-0.0022035986185073853,
-0.004201445262879133,
-0.04130043089389801,
-0.022732041776180267,
-0.029393868520855904,
0.03965333104133606,
0.015493681654334068,
0.0374777652323246,
-0.0738694816827774
] | 0.131953 |
following properties are supported: \* `apis` {Array} An optional array containing the timers to mock. The currently supported timer values are `'setInterval'`, `'setTimeout'`, `'setImmediate'`, and `'Date'`. \*\*Default:\*\* `['setInterval', 'setTimeout', 'setImmediate', 'Date']`. If no array is provided, all time related APIs (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, `'clearTimeout'`, `'setImmediate'`, `'clearImmediate'`, and `'Date'`) will be mocked by default. \* `now` {number | Date} An optional number or Date object representing the initial time (in milliseconds) to use as the value for `Date.now()`. \*\*Default:\*\* `0`. \*\*Note:\*\* When you enable mocking for a specific timer, its associated clear function will also be implicitly mocked. \*\*Note:\*\* Mocking `Date` will affect the behavior of the mocked timers as they use the same internal clock. Example usage without setting initial time: ```mjs import { mock } from 'node:test'; mock.timers.enable({ apis: ['setInterval'] }); ``` ```cjs const { mock } = require('node:test'); mock.timers.enable({ apis: ['setInterval'] }); ``` The above example enables mocking for the `setInterval` timer and implicitly mocks the `clearInterval` function. Only the `setInterval` and `clearInterval` functions from [node:timers](./timers.md), [node:timers/promises](./timers.md#timers-promises-api), and `globalThis` will be mocked. Example usage with initial time set ```mjs import { mock } from 'node:test'; mock.timers.enable({ apis: ['Date'], now: 1000 }); ``` ```cjs const { mock } = require('node:test'); mock.timers.enable({ apis: ['Date'], now: 1000 }); ``` Example usage with initial Date object as time set ```mjs import { mock } from 'node:test'; mock.timers.enable({ apis: ['Date'], now: new Date() }); ``` ```cjs const { mock } = require('node:test'); mock.timers.enable({ apis: ['Date'], now: new Date() }); ``` Alternatively, if you call `mock.timers.enable()` without any parameters: All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, `'clearTimeout'`, `'setImmediate'`, and `'clearImmediate'`) will be mocked. The `setInterval`, `clearInterval`, `setTimeout`, `clearTimeout`, `setImmediate`, and `clearImmediate` functions from `node:timers`, `node:timers/promises`, and `globalThis` will be mocked. As well as the global `Date` object. ### `timers.reset()` This function restores the default behavior of all mocks that were previously created by this `MockTimers` instance and disassociates the mocks from the `MockTracker` instance. \*\*Note:\*\* After each test completes, this function is called on the test context's `MockTracker`. ```mjs import { mock } from 'node:test'; mock.timers.reset(); ``` ```cjs const { mock } = require('node:test'); mock.timers.reset(); ``` ### `timers[Symbol.dispose]()` Calls `timers.reset()`. ### `timers.tick([milliseconds])` Advances time for all mocked timers. \* `milliseconds` {number} The amount of time, in milliseconds, to advance the timers. \*\*Default:\*\* `1`. \*\*Note:\*\* This diverges from how `setTimeout` in Node.js behaves and accepts only positive numbers. In Node.js, `setTimeout` with negative numbers is only supported for web compatibility reasons. The following example mocks a `setTimeout` function and by using `.tick` advances in time triggering all pending timers. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => { const fn = context.mock.fn(); context.mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(fn, 9999); assert.strictEqual(fn.mock.callCount(), 0); // Advance in time context.mock.timers.tick(9999); assert.strictEqual(fn.mock.callCount(), 1); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => { const fn = context.mock.fn(); context.mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(fn, 9999); assert.strictEqual(fn.mock.callCount(), 0); // Advance in time context.mock.timers.tick(9999); assert.strictEqual(fn.mock.callCount(), 1); }); ``` Alternatively, the `.tick` function can be called many times ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => { const fn = context.mock.fn(); context.mock.timers.enable({ apis: ['setTimeout'] }); const nineSecs = 9000; setTimeout(fn, nineSecs); const threeSeconds = 3000; context.mock.timers.tick(threeSeconds); context.mock.timers.tick(threeSeconds); context.mock.timers.tick(threeSeconds); assert.strictEqual(fn.mock.callCount(), 1); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('mocks setTimeout to be executed synchronously without having to actually | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.08684439957141876,
0.03237330541014671,
-0.05078573897480965,
0.07466185092926025,
-0.08564724028110504,
0.009119195863604546,
0.014511308632791042,
0.010698182508349419,
-0.007384235505014658,
-0.0023435649927705526,
-0.01787901110947132,
-0.04969031736254692,
-0.011068210005760193,
0.039569467306137085,
0.07857611775398254,
-0.04489169642329216,
-0.009145261719822884,
-0.07238011807203293,
-0.012029056437313557,
-0.04934384301304817,
0.07920357584953308,
-0.023745495826005936,
0.03522658348083496,
0.03737972304224968,
-0.03703004866838455,
-0.10911564528942108,
-0.027667278423905373,
-0.04326079040765762,
0.0727115049958229,
0.030888721346855164,
0.023534834384918213,
0.0334894023835659,
-0.10992594808340073,
-0.03129143267869949,
0.023813389241695404,
0.008138070814311504,
0.052001576870679855,
-0.0006397794932126999,
0.012588533572852612,
0.028066178783774376,
0.08761986345052719,
-0.02627740427851677,
-0.06366366893053055,
-0.08659528195858002,
0.03483138978481293,
0.0008971058996394277,
0.03453558310866356,
-0.001060188515111804,
-0.10410167276859283,
0.0954984650015831,
-0.021412072703242302,
0.024849651381373405,
0.02306835539638996,
-0.07815784960985184,
0.07928674668073654,
0.054609473794698715,
0.011866419576108456,
0.020271342247724533,
0.012050864286720753,
0.04784252867102623,
0.014661351218819618,
-0.06940780580043793,
-0.019138827919960022,
0.00528967659920454,
0.003189195180311799,
0.027881504967808723,
-0.042741503566503525,
0.007409568410366774,
0.10569789260625839,
-0.0742674395442009,
-0.045070141553878784,
0.03303859755396843,
0.0248189065605402,
0.03454926609992981,
-0.017335209995508194,
0.022860737517476082,
-0.014076845720410347,
-0.043169841170310974,
0.04429914802312851,
-0.05323190987110138,
-0.03884517773985863,
-0.08213984221220016,
-0.021132521331310272,
0.008714203722774982,
-0.02982446551322937,
0.008763792924582958,
0.08486352115869522,
0.0923130139708519,
0.006622409913688898,
-0.06348320841789246,
0.013642626814544201,
-0.0030586242210119963,
-0.09018808603286743,
0.07108242809772491,
0.003445751965045929,
0.01867620460689068,
0.04113326594233513,
0.005631112493574619,
0.0011248240480199456,
0.0708124116063118,
0.010518091730773449,
-0.06390077620744705,
-0.022013140842318535,
0.02087230794131756,
0.06003241986036301,
0.020530255511403084,
0.002303723245859146,
-0.0597912035882473,
-0.011336584575474262,
0.03132931888103485,
-0.005907394457608461,
0.04271470382809639,
0.044545453041791916,
-0.05496569722890854,
0.02731306105852127,
0.025796564295887947,
-0.022601017728447914,
-0.016477519646286964,
0.0837722048163414,
0.02369661070406437,
0.11160388588905334,
0.04855396971106529,
-0.02103235572576523,
-0.05931452661752701,
0.05893069505691528,
0.05638858303427696,
0.08120261132717133,
5.208523265655413e-33,
-0.0026215962134301662,
-0.0883263573050499,
-0.0010866530938073993,
0.014060195535421371,
0.11792480200529099,
0.010092254728078842,
0.04736977815628052,
0.053610868752002716,
-0.00939219444990158,
-0.05998893827199936,
0.04433257505297661,
-0.06438517570495605,
-0.055097565054893494,
-0.011093576438724995,
-0.055789753794670105,
-0.001517138327471912,
0.024480145424604416,
-0.009049272164702415,
0.13628257811069489,
-0.011463763192296028,
0.07071981579065323,
-0.05840124562382698,
-0.05430690571665764,
-0.03333134576678276,
-0.013935795053839684,
-0.020210085436701775,
-0.035381022840738297,
-0.003385682124644518,
-0.041523393243551254,
-0.0018702393863350153,
0.02497067116200924,
0.009179770946502686,
-0.06975024193525314,
0.09238030016422272,
0.049120377749204636,
-0.014725751243531704,
-0.049934953451156616,
0.034652937203645706,
-0.08136250823736191,
-0.02146132104098797,
-0.027126818895339966,
-0.05837392061948776,
-0.054120056331157684,
-0.0009746616706252098,
0.00001004751175059937,
-0.1607004851102829,
-0.019810786470770836,
0.03334308788180351,
0.0866771787405014,
0.013965405523777008,
0.02727091871201992,
0.10406695306301117,
-0.0110625596717,
-0.11331641674041748,
0.027654334902763367,
-0.020660126581788063,
0.04089009761810303,
0.02799253910779953,
-0.0038953893817961216,
-0.012969386763870716,
-0.02001604437828064,
-0.019930485635995865,
-0.02696426585316658,
-0.06384853273630142,
-0.06194185093045235,
0.05111612752079964,
0.06720981001853943,
-0.013336400501430035,
0.043654464185237885,
0.01087411493062973,
0.009794434532523155,
0.06826794892549515,
-0.06511422246694565,
0.03503308445215225,
-0.09833931177854538,
-0.04530554264783859,
0.1422806829214096,
-0.0014718439197167754,
-0.03413030132651329,
0.009431105107069016,
0.14198878407478333,
-0.03927939012646675,
-0.06533798575401306,
0.06975465267896652,
0.002545880153775215,
-0.11150353401899338,
0.03211888670921326,
0.00889224000275135,
0.004820883274078369,
-0.14182744920253754,
-0.023941366001963615,
0.01138936635106802,
0.014541218057274818,
-0.05603501573204994,
-0.04804122447967529,
-6.540216938472982e-33,
0.12462747097015381,
-0.007835897617042065,
-0.02141512744128704,
0.13731808960437775,
0.03976409509778023,
-0.08165224641561508,
0.058287229388952255,
0.07284010201692581,
0.008226077072322369,
0.010147207416594028,
0.05268492549657822,
-0.06401143223047256,
-0.00519303185865283,
-0.07948414236307144,
-0.027704669162631035,
0.003303274977952242,
-0.021211648359894753,
-0.10593879967927933,
0.0400363989174366,
-0.013691646046936512,
0.023930519819259644,
0.0212389063090086,
-0.044706281274557114,
-0.01456295233219862,
-0.002902593929320574,
-0.01574980840086937,
-0.0072914911434054375,
-0.014036175794899464,
-0.018455184996128082,
0.033734481781721115,
-0.0016780141741037369,
-0.01457246020436287,
-0.036574095487594604,
-0.0326034277677536,
0.030942978337407112,
-0.018738172948360443,
0.1070275828242302,
0.015300171449780464,
-0.027638396248221397,
0.013022363185882568,
0.06368869543075562,
0.001343266572803259,
-0.02952885627746582,
-0.04381372034549713,
-0.026591433212161064,
0.1025267019867897,
0.006387996952980757,
-0.030875373631715775,
-0.027246791869401932,
-0.021992279216647148,
0.031830012798309326,
-0.14383378624916077,
0.0034856947604566813,
0.06610464304685593,
0.028016744181513786,
-0.057207345962524414,
-0.008563664741814137,
-0.10851927101612091,
0.004376594442874193,
0.05875596031546593,
-0.04509466513991356,
-0.0688425600528717,
-0.032442376017570496,
0.02230958268046379,
-0.020443366840481758,
-0.01864689774811268,
-0.04509972035884857,
-0.05142270028591156,
-0.009443186223506927,
-0.0711570456624031,
0.08908741176128387,
-0.016483716666698456,
-0.04179432988166809,
-0.01583363488316536,
-0.04102253168821335,
-0.00019377506396267563,
-0.0070400661788880825,
0.02512519620358944,
-0.008031047880649567,
0.05084986239671707,
-0.04210284724831581,
0.005245962645858526,
0.007432038430124521,
0.01193015556782484,
-0.06790246814489365,
0.012120109982788563,
-0.007373798172920942,
0.11197470873594284,
0.008985059335827827,
0.049550678580999374,
-0.03158789500594139,
0.0409596785902977,
-0.009022919461131096,
0.05910467356443405,
0.008926518261432648,
-6.081156556092537e-8,
-0.040315356105566025,
0.01616884209215641,
-0.0015717650530859828,
-0.0047543649561703205,
-0.06848414242267609,
-0.022877905517816544,
0.0030327076092362404,
-0.06499268114566803,
0.035806357860565186,
-0.020753877237439156,
0.08791804313659668,
0.006973401643335819,
0.028777239844202995,
-0.02630026265978813,
0.01079475600272417,
-0.04115744307637215,
-0.06608808785676956,
0.009694118984043598,
-0.00256375502794981,
-0.008344112895429134,
0.00097962177824229,
0.0067104315385222435,
0.08433344960212708,
-0.10920216143131256,
0.004539425950497389,
0.11135105043649673,
-0.020920636132359505,
0.09647131711244583,
0.031017446890473366,
0.07592232525348663,
-0.014746280387043953,
-0.008042428642511368,
0.003966620657593012,
-0.03461207449436188,
-0.06666392087936401,
-0.03242173790931702,
-0.08400262147188187,
0.048734426498413086,
-0.042691633105278015,
0.032479967921972275,
0.0188209880143404,
-0.018980184569954872,
-0.1407536268234253,
-0.009860223159193993,
0.05398361757397652,
-0.09196166694164276,
-0.08823464065790176,
-0.030636006966233253,
-0.010736499913036823,
-0.03756897523999214,
-0.017958514392375946,
0.03967621549963951,
0.022811293601989746,
0.01813865639269352,
-0.049403805285692215,
0.032298456877470016,
0.03066108748316765,
-0.04946053773164749,
-0.041789256036281586,
0.004707221873104572,
0.02881566807627678,
0.04498719051480293,
-0.003346784505993128,
-0.021635962650179863
] | 0.102038 |
it', (context) => { const fn = context.mock.fn(); context.mock.timers.enable({ apis: ['setTimeout'] }); const nineSecs = 9000; setTimeout(fn, nineSecs); const threeSeconds = 3000; context.mock.timers.tick(threeSeconds); context.mock.timers.tick(threeSeconds); context.mock.timers.tick(threeSeconds); assert.strictEqual(fn.mock.callCount(), 1); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => { const fn = context.mock.fn(); context.mock.timers.enable({ apis: ['setTimeout'] }); const nineSecs = 9000; setTimeout(fn, nineSecs); const threeSeconds = 3000; context.mock.timers.tick(threeSeconds); context.mock.timers.tick(threeSeconds); context.mock.timers.tick(threeSeconds); assert.strictEqual(fn.mock.callCount(), 1); }); ``` Advancing time using `.tick` will also advance the time for any `Date` object created after the mock was enabled (if `Date` was also set to be mocked). ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => { const fn = context.mock.fn(); context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); setTimeout(fn, 9999); assert.strictEqual(fn.mock.callCount(), 0); assert.strictEqual(Date.now(), 0); // Advance in time context.mock.timers.tick(9999); assert.strictEqual(fn.mock.callCount(), 1); assert.strictEqual(Date.now(), 9999); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => { const fn = context.mock.fn(); context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); setTimeout(fn, 9999); assert.strictEqual(fn.mock.callCount(), 0); assert.strictEqual(Date.now(), 0); // Advance in time context.mock.timers.tick(9999); assert.strictEqual(fn.mock.callCount(), 1); assert.strictEqual(Date.now(), 9999); }); ``` #### Using clear functions As mentioned, all clear functions from timers (`clearTimeout`, `clearInterval`,and `clearImmediate`) are implicitly mocked. Take a look at this example using `setTimeout`: ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => { const fn = context.mock.fn(); // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout'] }); const id = setTimeout(fn, 9999); // Implicitly mocked as well clearTimeout(id); context.mock.timers.tick(9999); // As that setTimeout was cleared the mock function will never be called assert.strictEqual(fn.mock.callCount(), 0); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => { const fn = context.mock.fn(); // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout'] }); const id = setTimeout(fn, 9999); // Implicitly mocked as well clearTimeout(id); context.mock.timers.tick(9999); // As that setTimeout was cleared the mock function will never be called assert.strictEqual(fn.mock.callCount(), 0); }); ``` #### Working with Node.js timers modules Once you enable mocking timers, [node:timers](./timers.md), [node:timers/promises](./timers.md#timers-promises-api) modules, and timers from the Node.js global context are enabled: \*\*Note:\*\* Destructuring functions such as `import { setTimeout } from 'node:timers'` is currently not supported by this API. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; import nodeTimers from 'node:timers'; import nodeTimersPromises from 'node:timers/promises'; test('mocks setTimeout to be executed synchronously without having to actually wait for it', async (context) => { const globalTimeoutObjectSpy = context.mock.fn(); const nodeTimerSpy = context.mock.fn(); const nodeTimerPromiseSpy = context.mock.fn(); // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(globalTimeoutObjectSpy, 9999); nodeTimers.setTimeout(nodeTimerSpy, 9999); const promise = nodeTimersPromises.setTimeout(9999).then(nodeTimerPromiseSpy); // Advance in time context.mock.timers.tick(9999); assert.strictEqual(globalTimeoutObjectSpy.mock.callCount(), 1); assert.strictEqual(nodeTimerSpy.mock.callCount(), 1); await promise; assert.strictEqual(nodeTimerPromiseSpy.mock.callCount(), 1); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); const nodeTimers = require('node:timers'); const nodeTimersPromises = require('node:timers/promises'); test('mocks setTimeout to be executed synchronously without having to actually wait for it', async (context) => { const globalTimeoutObjectSpy = context.mock.fn(); const nodeTimerSpy = context.mock.fn(); const nodeTimerPromiseSpy = context.mock.fn(); // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(globalTimeoutObjectSpy, 9999); nodeTimers.setTimeout(nodeTimerSpy, 9999); const promise = nodeTimersPromises.setTimeout(9999).then(nodeTimerPromiseSpy); // Advance in time context.mock.timers.tick(9999); assert.strictEqual(globalTimeoutObjectSpy.mock.callCount(), 1); assert.strictEqual(nodeTimerSpy.mock.callCount(), 1); await promise; assert.strictEqual(nodeTimerPromiseSpy.mock.callCount(), 1); }); ``` In Node.js, `setInterval` from [node:timers/promises](./timers.md#timers-promises-api) is an `AsyncGenerator` and is also supported by this API: ```mjs import assert | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.059768155217170715,
0.013888622634112835,
-0.03868354484438896,
0.05933408439159393,
-0.020035969093441963,
-0.005011158064007759,
-0.03439585119485855,
0.01984110288321972,
0.06967537850141525,
-0.040675319731235504,
0.0033714775927364826,
-0.03173523023724556,
-0.04903799295425415,
-0.037168025970458984,
0.043513283133506775,
-0.08199979364871979,
-0.004111767280846834,
-0.01316637359559536,
-0.02517661638557911,
-0.04573890566825867,
0.0335058718919754,
-0.06556954234838486,
0.07573156803846359,
0.007958494126796722,
-0.04713432118296623,
-0.08640261739492416,
-0.0730181485414505,
-0.07601004093885422,
0.06265749037265778,
0.05677025765180588,
0.05970711633563042,
-0.012902386486530304,
-0.07608567178249359,
0.012471746653318405,
-0.025187691673636436,
0.06111971288919449,
-0.03751567378640175,
-0.04632648825645447,
-0.0053122565150260925,
0.010784344747662544,
0.015526757575571537,
0.03576606139540672,
-0.04526551812887192,
-0.060560472309589386,
0.09555700421333313,
0.01967976987361908,
0.0021616185549646616,
0.04103553667664528,
-0.037190984934568405,
0.044321294873952866,
0.022062039002776146,
0.04429646581411362,
-0.025521866977214813,
-0.06283768266439438,
0.033270496875047684,
0.037982065230607986,
0.05700422450900078,
0.03895699977874756,
0.0446385033428669,
0.09277602285146713,
0.020246971398591995,
-0.08651918172836304,
0.021215444430708885,
-0.011454430408775806,
0.0491505041718483,
0.026891987770795822,
0.0045051658526062965,
-0.006253346800804138,
0.03995421901345253,
0.05855012685060501,
0.021500715985894203,
0.062014609575271606,
0.037177253514528275,
0.04592438414692879,
-0.048572130501270294,
0.014793165028095245,
-0.023202886804938316,
-0.02975950948894024,
0.04225081950426102,
-0.01729070395231247,
-0.022071147337555885,
-0.04028041288256645,
-0.0404658168554306,
0.008947531692683697,
-0.05733533948659897,
0.037209801375865936,
0.12280102074146271,
0.04664287343621254,
-0.035275448113679886,
-0.05195636302232742,
0.004095563665032387,
0.023563280701637268,
-0.1526496857404709,
0.05657670646905899,
0.017547115683555603,
-0.004541780333966017,
0.07089652121067047,
0.05964978039264679,
-0.02149016037583351,
0.021852347999811172,
0.05079052597284317,
-0.06349679827690125,
0.0035311279352754354,
0.021261658519506454,
-0.038972970098257065,
0.009902864694595337,
0.00051252415869385,
-0.043623048812150955,
-0.050700388848781586,
0.02895377390086651,
0.049855418503284454,
0.07186171412467957,
0.0495157353579998,
0.013906328938901424,
-0.0263054296374321,
0.0053369104862213135,
0.009623358957469463,
-0.0536552257835865,
0.13112273812294006,
0.0633467361330986,
0.1110643520951271,
0.02430480159819126,
0.013299656100571156,
-0.12214772403240204,
0.004566896241158247,
0.019907135516405106,
0.06558423489332199,
5.3512547284681325e-33,
-0.021991420537233353,
-0.053526196628808975,
0.0036835907958447933,
0.005530603229999542,
0.10411866009235382,
-0.004281866364181042,
0.017388304695487022,
0.020914295688271523,
-0.11390172690153122,
-0.012261839583516121,
0.04726697877049446,
-0.0876319631934166,
0.008025146089494228,
-0.0295961145311594,
-0.019718468189239502,
-0.025545179843902588,
0.1043170616030693,
-0.061732709407806396,
0.07928921282291412,
-0.007062044460326433,
0.09581968933343887,
-0.10856495052576065,
-0.04449126496911049,
-0.010600192472338676,
-0.031395524740219116,
-0.024863632395863533,
-0.029677636921405792,
0.05103854462504387,
-0.05376720055937767,
-0.006697495002299547,
0.05250275135040283,
0.07449598610401154,
-0.12384205311536789,
0.09316959232091904,
0.01745014823973179,
-0.05271526798605919,
0.01694256253540516,
0.04010063409805298,
-0.08978726714849472,
-0.03638806194067001,
-0.033906567841768265,
-0.009731766767799854,
-0.02525368332862854,
0.021223634481430054,
-0.015939505770802498,
-0.1073082908987999,
-0.0237059835344553,
-0.033809859305620193,
0.08019869029521942,
0.04219816252589226,
0.05845044180750847,
0.09639502316713333,
0.023168005049228668,
-0.10422305762767792,
0.06588701903820038,
0.00797697901725769,
0.07246366143226624,
-0.039136163890361786,
-0.07035516947507858,
0.06791940331459045,
0.02807009406387806,
-0.0995250716805458,
-0.0759480744600296,
0.019309306517243385,
-0.030480995774269104,
0.04653457924723625,
-0.0502622090280056,
-0.000014621032278228085,
0.01545338612049818,
0.04711431264877319,
0.01227125059813261,
0.007214533165097237,
-0.020956015214323997,
-0.006131326779723167,
-0.07907754182815552,
-0.002461374271661043,
0.04730349779129028,
0.031962502747774124,
-0.09458144754171371,
-0.02007855847477913,
0.10601870715618134,
-0.013672232627868652,
-0.05356048047542572,
0.06532943993806839,
0.00210188259370625,
-0.06313755363225937,
-0.030999042093753815,
-0.004051252268254757,
0.046361446380615234,
-0.05011200159788132,
-0.008351393043994904,
0.01324890460819006,
0.04116272181272507,
-0.0689781904220581,
-0.09999534487724304,
-5.809750422534612e-33,
0.0559171661734581,
0.0005773445009253919,
-0.020357975736260414,
0.12203185260295868,
0.08191391080617905,
-0.03441823273897171,
-0.03784501552581787,
0.05348509922623634,
-0.07126128673553467,
0.015003645792603493,
0.045666925609111786,
-0.06032346189022064,
0.011230455711483955,
-0.014139804057776928,
-0.04339289292693138,
0.010792764835059643,
0.04211979731917381,
-0.05274246633052826,
0.013731720857322216,
0.00015181310300249606,
0.06791131943464279,
-0.00807976070791483,
0.021800782531499863,
-0.016712218523025513,
-0.0804060846567154,
-0.0002479228423908353,
-0.10648276656866074,
-0.021928098052740097,
0.003015165915712714,
-0.0355217345058918,
-0.049969375133514404,
-0.0252719484269619,
-0.005756741389632225,
0.04636664316058159,
0.07639308273792267,
-0.027691751718521118,
0.06077254191040993,
0.08563078194856644,
0.0014086365699768066,
-0.01916855201125145,
0.06858854740858078,
0.010055161081254482,
0.0044933706521987915,
-0.0337739959359169,
-0.0064971777610480785,
0.08550966531038284,
0.008574348874390125,
-0.03844817355275154,
-0.056566089391708374,
0.029296303167939186,
-0.00991799682378769,
-0.08646532893180847,
-0.005610539577901363,
0.06669241189956665,
0.02623528055846691,
-0.0722137913107872,
-0.01995670795440674,
-0.09255332499742508,
0.11503811925649643,
0.054904744029045105,
0.020208876579999924,
-0.08612193167209625,
-0.00042815555934794247,
0.0680992379784584,
0.05783378332853317,
0.004576362669467926,
-0.1075722724199295,
0.03415246680378914,
0.07609637081623077,
0.030123714357614517,
-0.0023734671995043755,
0.05874829366803169,
-0.0711032971739769,
-0.04258634150028229,
-0.020286159589886665,
0.014936389401555061,
-0.07245641201734543,
-0.045229263603687286,
0.008365770801901817,
0.05005549639463425,
0.017117591574788094,
-0.005307325161993504,
-0.04729362949728966,
-0.00024839024990797043,
-0.016683265566825867,
0.06576228886842728,
-0.003505260683596134,
0.07702063769102097,
0.03222631290555,
0.05178017541766167,
0.025192823261022568,
0.0606856644153595,
-0.06132102385163307,
-0.0007583657279610634,
-0.0006841497961431742,
-5.248708134786284e-8,
-0.027717601507902145,
0.00010950001160381362,
-0.029832830652594566,
-0.027643093839287758,
-0.0025607263669371605,
-0.0021587852388620377,
0.053722482174634933,
-0.06565362960100174,
0.010054415091872215,
0.019365226849913597,
0.008992988616228104,
-0.026479028165340424,
0.07910171151161194,
-0.02315044216811657,
-0.00003141312481602654,
-0.0516420416533947,
-0.06609327346086502,
-0.017343536019325256,
0.033897582441568375,
0.027529943734407425,
-0.07232494652271271,
0.01557138655334711,
0.09002779424190521,
-0.007265544030815363,
-0.027250858023762703,
0.029112594202160835,
0.0969986617565155,
0.07432530075311661,
0.018735243007540703,
0.03291681781411171,
-0.14779534935951233,
0.02155332826077938,
-0.057065896689891815,
-0.05365737900137901,
-0.06609737873077393,
-0.021708622574806213,
-0.06796165555715561,
0.03230941668152809,
0.062277067452669144,
0.04826908931136131,
0.0033557077404111624,
-0.02913104183971882,
-0.07292147725820541,
0.013593637384474277,
0.02579360455274582,
-0.09211324155330658,
-0.0749393031001091,
0.05295485258102417,
0.014012744650244713,
-0.038278739899396896,
-0.019958939403295517,
-0.004131596069782972,
-0.05127432197332382,
-0.04060114920139313,
-0.03507844731211662,
-0.038835685700178146,
0.00047362130135297775,
-0.04490387439727783,
-0.04350538179278374,
0.02511090785264969,
0.03642788529396057,
0.024922512471675873,
-0.024349233135581017,
-0.05111747980117798
] | 0.090981 |
Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(globalTimeoutObjectSpy, 9999); nodeTimers.setTimeout(nodeTimerSpy, 9999); const promise = nodeTimersPromises.setTimeout(9999).then(nodeTimerPromiseSpy); // Advance in time context.mock.timers.tick(9999); assert.strictEqual(globalTimeoutObjectSpy.mock.callCount(), 1); assert.strictEqual(nodeTimerSpy.mock.callCount(), 1); await promise; assert.strictEqual(nodeTimerPromiseSpy.mock.callCount(), 1); }); ``` In Node.js, `setInterval` from [node:timers/promises](./timers.md#timers-promises-api) is an `AsyncGenerator` and is also supported by this API: ```mjs import assert from 'node:assert'; import { test } from 'node:test'; import nodeTimersPromises from 'node:timers/promises'; test('should tick five times testing a real use case', async (context) => { context.mock.timers.enable({ apis: ['setInterval'] }); const expectedIterations = 3; const interval = 1000; const startedAt = Date.now(); async function run() { const times = []; for await (const time of nodeTimersPromises.setInterval(interval, startedAt)) { times.push(time); if (times.length === expectedIterations) break; } return times; } const r = run(); context.mock.timers.tick(interval); context.mock.timers.tick(interval); context.mock.timers.tick(interval); const timeResults = await r; assert.strictEqual(timeResults.length, expectedIterations); for (let it = 1; it < expectedIterations; it++) { assert.strictEqual(timeResults[it - 1], startedAt + (interval \* it)); } }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); const nodeTimersPromises = require('node:timers/promises'); test('should tick five times testing a real use case', async (context) => { context.mock.timers.enable({ apis: ['setInterval'] }); const expectedIterations = 3; const interval = 1000; const startedAt = Date.now(); async function run() { const times = []; for await (const time of nodeTimersPromises.setInterval(interval, startedAt)) { times.push(time); if (times.length === expectedIterations) break; } return times; } const r = run(); context.mock.timers.tick(interval); context.mock.timers.tick(interval); context.mock.timers.tick(interval); const timeResults = await r; assert.strictEqual(timeResults.length, expectedIterations); for (let it = 1; it < expectedIterations; it++) { assert.strictEqual(timeResults[it - 1], startedAt + (interval \* it)); } }); ``` ### `timers.runAll()` Triggers all pending mocked timers immediately. If the `Date` object is also mocked, it will also advance the `Date` object to the furthest timer's time. The example below triggers all pending timers immediately, causing them to execute without any delay. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('runAll functions following the given order', (context) => { context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); const results = []; setTimeout(() => results.push(1), 9999); // Notice that if both timers have the same timeout, // the order of execution is guaranteed setTimeout(() => results.push(3), 8888); setTimeout(() => results.push(2), 8888); assert.deepStrictEqual(results, []); context.mock.timers.runAll(); assert.deepStrictEqual(results, [3, 2, 1]); // The Date object is also advanced to the furthest timer's time assert.strictEqual(Date.now(), 9999); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('runAll functions following the given order', (context) => { context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); const results = []; setTimeout(() => results.push(1), 9999); // Notice that if both timers have the same timeout, // the order of execution is guaranteed setTimeout(() => results.push(3), 8888); setTimeout(() => results.push(2), 8888); assert.deepStrictEqual(results, []); context.mock.timers.runAll(); assert.deepStrictEqual(results, [3, 2, 1]); // The Date object is also advanced to the furthest timer's time assert.strictEqual(Date.now(), 9999); }); ``` \*\*Note:\*\* The `runAll()` function is specifically designed for triggering timers in the context of timer mocking. It does not have any effect on real-time system clocks or actual timers outside of the mocking environment. ### `timers.setTime(milliseconds)` Sets the current Unix timestamp that will be used as reference for any mocked `Date` objects. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('runAll functions following the given order', (context) => { const now = Date.now(); const setTime = 1000; // Date.now is not mocked assert.deepStrictEqual(Date.now(), now); context.mock.timers.enable({ apis: ['Date'] }); context.mock.timers.setTime(setTime); // Date.now is now 1000 assert.strictEqual(Date.now(), setTime); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('setTime replaces current time', (context) => { const now = Date.now(); const setTime = 1000; // Date.now is not mocked assert.deepStrictEqual(Date.now(), now); context.mock.timers.enable({ apis: ['Date'] }); context.mock.timers.setTime(setTime); | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.11651265621185303,
0.010827324353158474,
-0.009040886536240578,
0.07084944099187851,
-0.01603325828909874,
-0.020131006836891174,
-0.056083936244249344,
0.0453052744269371,
0.04102743789553642,
-0.009567064233124256,
-0.014405136927962303,
-0.016456924378871918,
0.0012005524476990104,
0.020137585699558258,
0.04396741837263107,
-0.056804265826940536,
0.02248983643949032,
0.02533194236457348,
0.022068023681640625,
-0.06354312598705292,
0.04194514453411102,
-0.062604159116745,
0.07026868313550949,
0.020676124840974808,
-0.017199791967868805,
-0.0957460105419159,
-0.11013343185186386,
-0.08311022073030472,
0.07296637445688248,
0.058882936835289,
0.05942470207810402,
0.017873411998152733,
-0.08999144285917282,
-0.0031410648953169584,
-0.03678813949227333,
0.06937677413225174,
-0.01747369021177292,
-0.023817894980311394,
-0.009450300596654415,
0.005717486143112183,
0.0686868354678154,
0.06564434617757797,
-0.04450302571058273,
-0.06473094969987869,
0.09440308809280396,
0.025286903604865074,
0.04786496236920357,
0.034717582166194916,
-0.09576969593763351,
0.06374919414520264,
0.02206055261194706,
0.05354604870080948,
-0.05150540918111801,
-0.05965008586645126,
-0.011461738497018814,
0.04785719886422157,
0.08787205070257187,
0.040079280734062195,
0.04979307949542999,
0.06986328214406967,
0.014539826661348343,
-0.08521095663309097,
0.02423693612217903,
-0.03193099424242973,
0.009301319718360901,
0.05136922746896744,
-0.005251575727015734,
-0.001536481431685388,
0.07250567525625229,
0.03498891368508339,
0.0413721464574337,
0.009710744023323059,
0.03144484758377075,
0.04411287233233452,
-0.05847138538956642,
0.017802732065320015,
-0.002382358768954873,
-0.0054769194684922695,
0.030441833660006523,
0.00824062991887331,
-0.0108914440497756,
-0.027367154136300087,
-0.004571152850985527,
-0.042488109320402145,
-0.1024603322148323,
0.023171937093138695,
0.08808515965938568,
0.051845673471689224,
-0.01940113678574562,
-0.024101201444864273,
-0.009222249500453472,
-0.029169565066695213,
-0.15203137695789337,
0.05204790085554123,
0.0030743430834263563,
-0.050206854939460754,
0.07408789545297623,
0.030398797243833542,
0.02902575023472309,
0.004687222186475992,
0.030574452131986618,
-0.10626079142093658,
-0.028467779979109764,
-0.003360200207680464,
0.01418040320277214,
0.016896896064281464,
0.009869721718132496,
-0.10103819519281387,
-0.009530682116746902,
0.06609746068716049,
0.04981711134314537,
0.05313733592629433,
0.054502781480550766,
0.019852513447403908,
0.027655456215143204,
0.018811095505952835,
0.027611708268523216,
-0.034394584596157074,
0.12931182980537415,
0.08981632441282272,
0.06379463523626328,
0.06450717896223068,
0.0674160048365593,
-0.06296049803495407,
0.02736232802271843,
0.03715093061327934,
0.049586161971092224,
4.7160344790150614e-33,
-0.01447613537311554,
-0.05514378473162651,
0.06135158613324165,
0.012716727331280708,
0.09222868084907532,
0.04432111978530884,
0.05114932358264923,
0.014156876131892204,
-0.04213568568229675,
-0.08286821842193604,
0.032341789454221725,
-0.09387769550085068,
-0.006824122741818428,
-0.04658222571015358,
-0.016483210027217865,
0.009308845736086369,
0.03686502203345299,
-0.06147982180118561,
0.0960979014635086,
0.010361968539655209,
0.0430673286318779,
-0.09056466072797775,
-0.043580953031778336,
-0.014640280045568943,
-0.024194644764065742,
-0.1074988916516304,
-0.02477387897670269,
0.010060731321573257,
-0.017154071480035782,
-0.013959287665784359,
0.019043952226638794,
0.07199785113334656,
-0.12310688197612762,
0.10394248366355896,
0.010337136685848236,
-0.02133418247103691,
0.005130323115736246,
-0.004892340395599604,
-0.12036167085170746,
-0.0642421618103981,
-0.08925814181566238,
0.023942073807120323,
-0.03131205961108208,
0.031987059861421585,
0.005397758446633816,
-0.16264651715755463,
-0.022867081686854362,
-0.05716051161289215,
0.075879767537117,
0.046148717403411865,
0.025922073051333427,
0.06672022491693497,
0.031069673597812653,
-0.131430983543396,
0.035251684486866,
0.01454239897429943,
0.09296314418315887,
-0.02513597533106804,
-0.04340842738747597,
0.05097239091992378,
0.049954015761613846,
-0.13357628881931305,
-0.08024890720844269,
-0.05893635004758835,
-0.02506949007511139,
0.04679689183831215,
-0.012124285101890564,
-0.0038970557507127523,
-0.01861490309238434,
0.04434391111135483,
0.04230460152029991,
0.002130198525264859,
-0.03755918890237808,
0.02915443666279316,
-0.08011899143457413,
-0.011431130580604076,
0.08242499828338623,
0.02704550139605999,
-0.06343785673379898,
0.007563645951449871,
0.0488831028342247,
0.008217093534767628,
-0.043666351586580276,
0.04154675826430321,
-0.02783205546438694,
-0.032426174730062485,
0.030092408880591393,
0.003774952609091997,
0.10827624052762985,
-0.05623045563697815,
-0.0249986220151186,
0.0009072140674106777,
0.03425924479961395,
-0.02114494889974594,
-0.08191639930009842,
-4.880299896308891e-33,
0.043276991695165634,
-0.005016516428440809,
-0.0033769772853702307,
0.16264621913433075,
0.07235023379325867,
-0.08098884671926498,
-0.023604802787303925,
0.050642043352127075,
-0.03340772166848183,
0.024209730327129364,
0.025410935282707214,
-0.04252353310585022,
0.049007873982191086,
-0.03372853621840477,
-0.04262511432170868,
-0.013972104527056217,
0.06146188825368881,
-0.0571170300245285,
0.03828997537493706,
0.005865558981895447,
0.08819770812988281,
-0.03964368253946304,
0.007630819454789162,
-0.012975898571312428,
-0.06187523156404495,
-0.0062309144996106625,
-0.09459147602319717,
-0.0004906148533336818,
0.027436863631010056,
-0.04027180001139641,
-0.02681765705347061,
0.007098297122865915,
-0.018786830827593803,
0.00022978539345785975,
0.08539067953824997,
-0.02501215785741806,
0.015858642756938934,
0.0626225620508194,
-0.0023103058338165283,
-0.03565632551908493,
0.0616428479552269,
-0.0039354367181658745,
-0.007648571394383907,
-0.03281516581773758,
-0.013333156704902649,
0.0394132137298584,
-0.00214571226388216,
-0.008463847450911999,
-0.01908615417778492,
-0.004442079458385706,
-0.01768944412469864,
-0.07491084933280945,
-0.005215195007622242,
0.09671632945537567,
0.011681252159178257,
-0.09712047874927521,
-0.0013685963349416852,
-0.05472048372030258,
0.08251466602087021,
0.025089114904403687,
0.018505604937672615,
-0.05231057107448578,
-0.003993741702288389,
0.03441653773188591,
0.009506994858384132,
0.020847009494900703,
-0.06808406859636307,
-0.02814922109246254,
0.03709446266293526,
0.032974157482385635,
0.021461285650730133,
0.039117008447647095,
-0.08251859992742538,
-0.0349818579852581,
0.0025677147787064314,
-0.001570159918628633,
-0.05267475172877312,
-0.060901835560798645,
0.009547579102218151,
-0.020055411383509636,
-0.022252678871154785,
0.02784143015742302,
-0.01822773739695549,
0.006280328147113323,
-0.011483240872621536,
0.06549021601676941,
0.010369847528636456,
0.08389769494533539,
0.018223825842142105,
0.07944048941135406,
0.01672353781759739,
0.012444321066141129,
-0.06626737117767334,
-0.044430237263441086,
0.00417951587587595,
-5.084030618718316e-8,
-0.031243955716490746,
0.03261136636137962,
-0.027437670156359673,
-0.006663638167083263,
-0.03917090967297554,
-0.029599063098430634,
0.016991298645734787,
-0.0183523278683424,
0.06434381753206253,
0.0364394448697567,
0.022650228813290596,
-0.037909604609012604,
0.09638791531324387,
-0.02180652879178524,
0.03519151359796524,
-0.010075347498059273,
-0.025293607264757156,
-0.04229867458343506,
0.03875122591853142,
0.015915635973215103,
-0.07101507484912872,
0.026236018165946007,
0.07545233517885208,
-0.03824808448553085,
-0.055367253720760345,
0.06393736600875854,
0.0752793624997139,
0.10409717261791229,
0.03068854659795761,
-0.00030636327574029565,
-0.13270695507526398,
0.0069145262241363525,
-0.07453873008489609,
-0.03481133654713631,
-0.046139877289533615,
-0.015187101438641548,
-0.04094204306602478,
0.03715107962489128,
0.02776086889207363,
0.06609723716974258,
-0.02958555892109871,
-0.038919467478990555,
-0.06031334027647972,
0.019414406269788742,
0.0261213481426239,
-0.08524464815855026,
-0.049392037093639374,
0.056360866874456406,
-0.02612479031085968,
-0.02502306178212166,
0.0010443534702062607,
-0.011233515106141567,
-0.05540332570672035,
-0.025672055780887604,
-0.029987968504428864,
-0.010232647880911827,
0.010155502706766129,
-0.0861305221915245,
-0.013660930097103119,
0.027026286348700523,
0.010094034485518932,
-0.008035180158913136,
-0.005088746547698975,
-0.056226857006549835
] | 0.046743 |
['Date'] }); context.mock.timers.setTime(setTime); // Date.now is now 1000 assert.strictEqual(Date.now(), setTime); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('setTime replaces current time', (context) => { const now = Date.now(); const setTime = 1000; // Date.now is not mocked assert.deepStrictEqual(Date.now(), now); context.mock.timers.enable({ apis: ['Date'] }); context.mock.timers.setTime(setTime); // Date.now is now 1000 assert.strictEqual(Date.now(), setTime); }); ``` #### Dates and Timers working together Dates and timer objects are dependent on each other. If you use `setTime()` to pass the current time to the mocked `Date` object, the set timers with `setTimeout` and `setInterval` will \*\*not\*\* be affected. However, the `tick` method \*\*will\*\* advance the mocked `Date` object. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('runAll functions following the given order', (context) => { context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); const results = []; setTimeout(() => results.push(1), 9999); assert.deepStrictEqual(results, []); context.mock.timers.setTime(12000); assert.deepStrictEqual(results, []); // The date is advanced but the timers don't tick assert.strictEqual(Date.now(), 12000); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('runAll functions following the given order', (context) => { context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); const results = []; setTimeout(() => results.push(1), 9999); assert.deepStrictEqual(results, []); context.mock.timers.setTime(12000); assert.deepStrictEqual(results, []); // The date is advanced but the timers don't tick assert.strictEqual(Date.now(), 12000); }); ``` ## Class: `TestsStream` \* Extends {Readable} A successful call to [`run()`][] method will return a new {TestsStream} object, streaming a series of events representing the execution of the tests. `TestsStream` will emit events, in the order of the tests definition Some of the events are guaranteed to be emitted in the same order as the tests are defined, while others are emitted in the order that the tests execute. ### Event: `'test:coverage'` \* `data` {Object} \* `summary` {Object} An object containing the coverage report. \* `files` {Array} An array of coverage reports for individual files. Each report is an object with the following schema: \* `path` {string} The absolute path of the file. \* `totalLineCount` {number} The total number of lines. \* `totalBranchCount` {number} The total number of branches. \* `totalFunctionCount` {number} The total number of functions. \* `coveredLineCount` {number} The number of covered lines. \* `coveredBranchCount` {number} The number of covered branches. \* `coveredFunctionCount` {number} The number of covered functions. \* `coveredLinePercent` {number} The percentage of lines covered. \* `coveredBranchPercent` {number} The percentage of branches covered. \* `coveredFunctionPercent` {number} The percentage of functions covered. \* `functions` {Array} An array of functions representing function coverage. \* `name` {string} The name of the function. \* `line` {number} The line number where the function is defined. \* `count` {number} The number of times the function was called. \* `branches` {Array} An array of branches representing branch coverage. \* `line` {number} The line number where the branch is defined. \* `count` {number} The number of times the branch was taken. \* `lines` {Array} An array of lines representing line numbers and the number of times they were covered. \* `line` {number} The line number. \* `count` {number} The number of times the line was covered. \* `thresholds` {Object} An object containing whether or not the coverage for each coverage type. \* `function` {number} The function coverage threshold. \* `branch` {number} The branch coverage threshold. \* `line` {number} The line coverage threshold. \* `totals` {Object} An object containing a summary of coverage for all files. \* `totalLineCount` {number} The total number of lines. \* `totalBranchCount` {number} The total number of branches. \* `totalFunctionCount` {number} The total number of functions. \* `coveredLineCount` {number} The number of covered lines. \* `coveredBranchCount` {number} The number of covered branches. \* `coveredFunctionCount` {number} The number of | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.057359009981155396,
0.026835311204195023,
0.023206109181046486,
0.05453750863671303,
-0.033335041254758835,
-0.0017243438633158803,
-0.03955839201807976,
0.023709958419203758,
0.03577575832605362,
-0.00008727699605515227,
-0.011600956320762634,
-0.02111097425222397,
-0.020433083176612854,
0.01742589846253395,
0.023531513288617134,
-0.07827109098434448,
0.028503190726041794,
0.009342673234641552,
-0.021485839039087296,
-0.04740744084119797,
0.02996700257062912,
-0.10465268790721893,
0.04109339416027069,
0.019891731441020966,
-0.03093305230140686,
-0.09656669199466705,
-0.03460472449660301,
-0.05744332820177078,
0.07189519703388214,
0.01794886402785778,
0.026517510414123535,
0.02243896946310997,
-0.12553763389587402,
0.0095461905002594,
-0.04413926973938942,
0.034564726054668427,
-0.021464139223098755,
-0.05781086906790733,
0.009898991324007511,
-0.00021998646843712777,
0.02005508542060852,
0.02830664813518524,
0.002427048282697797,
-0.03287559375166893,
0.08278094232082367,
0.06298411637544632,
0.038032688200473785,
0.10293947905302048,
-0.054154593497514725,
0.046838872134685516,
-0.012493621557950974,
0.016363143920898438,
0.003788215573877096,
-0.08908385038375854,
0.013894429430365562,
0.09857745468616486,
0.053368330001831055,
0.051809024065732956,
0.0565200075507164,
0.07915887981653214,
0.030110299587249756,
-0.06398946791887283,
0.052139706909656525,
-0.01782562956213951,
0.011154256761074066,
-0.002101154765114188,
0.008031758479773998,
0.0314953587949276,
0.06800316274166107,
0.016899121925234795,
0.022074030712246895,
0.05207870900630951,
0.06355040520429611,
0.020611921325325966,
-0.04143894463777542,
0.0008709907997399569,
-0.018061529844999313,
-0.007557556498795748,
0.08257424086332321,
-0.04443912208080292,
-0.02655489556491375,
-0.019489027559757233,
-0.01877990923821926,
-0.0467323437333107,
-0.02293371967971325,
-0.003094159299507737,
0.10471726953983307,
0.06254171580076218,
-0.04538961127400398,
-0.06385120749473572,
0.046097882091999054,
-0.047847285866737366,
-0.11249992996454239,
0.07596372812986374,
0.016636617481708527,
-0.06260678917169571,
0.07919804751873016,
0.10017414391040802,
0.037818651646375656,
0.05474671348929405,
0.03151780366897583,
-0.036193426698446274,
-0.03145438805222511,
0.014384141191840172,
0.04347500205039978,
-0.0018414375372231007,
-0.01551823876798153,
-0.08026536554098129,
-0.022976411506533623,
0.04270225018262863,
0.061091892421245575,
0.05238574743270874,
0.055886559188365936,
-0.00893349852412939,
0.009654497727751732,
-0.02002714015543461,
0.0017370086861774325,
-0.03688560798764229,
0.0554131455719471,
0.05515499413013458,
0.013852844014763832,
0.037948574870824814,
0.011293577961623669,
-0.09507402777671814,
0.016901597380638123,
0.0839211717247963,
0.061956655234098434,
1.3233057859404822e-33,
-0.005820045247673988,
-0.06761839240789413,
-0.0032759655732661486,
0.01738022267818451,
0.049281276762485504,
0.018169965595006943,
0.040127143263816833,
0.04923383146524429,
-0.0528387576341629,
-0.07073359936475754,
0.03853875771164894,
-0.08503670245409012,
-0.028623197227716446,
-0.054880741983652115,
-0.022431837394833565,
0.029416097328066826,
0.05430927500128746,
-0.079949289560318,
0.09301362186670303,
-0.018057404085993767,
0.06503711640834808,
-0.08350472897291183,
-0.052529819309711456,
-0.09125577658414841,
-0.012451346032321453,
-0.07398909330368042,
-0.012371411547064781,
0.033447206020355225,
-0.08485563844442368,
-0.04366389662027359,
0.04028695821762085,
0.036068130284547806,
-0.09424081444740295,
0.18084190785884857,
0.029700394719839096,
-0.03403099998831749,
0.03555799648165703,
0.04279401898384094,
-0.08242152631282806,
-0.05783097818493843,
-0.016257865354418755,
-0.00030223920475691557,
0.006986719556152821,
-0.045731887221336365,
0.032479315996170044,
-0.12965409457683563,
-0.05094275251030922,
-0.019797684624791145,
0.0876540020108223,
0.04071004316210747,
0.031621869653463364,
0.08655668050050735,
0.006648982409387827,
-0.09744465351104736,
0.002324044704437256,
0.025579780340194702,
0.05913306400179863,
-0.026022421196103096,
-0.02974393218755722,
0.04518783837556839,
0.04811937361955643,
-0.06824851036071777,
-0.05445479229092598,
0.008702922612428665,
-0.049424659460783005,
0.09509266167879105,
-0.003281287383288145,
-0.00020472741744015366,
0.03504963219165802,
0.03392672911286354,
0.023756425827741623,
-0.023699505254626274,
-0.07172848284244537,
0.018874142318964005,
-0.09150092303752899,
-0.025438949465751648,
0.10417570173740387,
0.02252057194709778,
-0.07637649774551392,
0.008518465794622898,
0.1074533611536026,
0.012417927384376526,
-0.05846647173166275,
0.07902712374925613,
-0.014973033219575882,
-0.06736020743846893,
-0.004113518167287111,
-0.0019179807277396321,
0.10103285312652588,
-0.043099138885736465,
-0.0071436818689107895,
0.03533000126481056,
0.04399160295724869,
-0.006848471704870462,
-0.04398359730839729,
-1.7928856570512462e-33,
0.07590071856975555,
0.0356433279812336,
-0.04056568816304207,
0.15762047469615936,
0.0940578281879425,
-0.09549962729215622,
-0.03664594888687134,
0.03578593581914902,
-0.06620215624570847,
0.048214446753263474,
0.07909616082906723,
-0.053042296320199966,
0.021058952435851097,
-0.036020677536726,
-0.039583172649145126,
-0.03453525900840759,
0.04062201827764511,
-0.09386889636516571,
-0.01312564592808485,
-0.030387436971068382,
0.0133450822904706,
0.010114887729287148,
-0.015554448589682579,
-0.05137475207448006,
-0.023966943845152855,
0.006688759662210941,
-0.03018995188176632,
0.005516285076737404,
0.0057100774720311165,
0.004520651418715715,
-0.03954770416021347,
-0.003898724215105176,
-0.022937310859560966,
0.019531039521098137,
0.0858856812119484,
-0.022388629615306854,
0.06911758333444595,
0.009514323435723782,
0.028035178780555725,
-0.04508107528090477,
0.005927786231040955,
0.014957769773900509,
-0.0461561344563961,
-0.023298004642128944,
-0.0010670889168977737,
0.10777873545885086,
0.024382153525948524,
-0.05393320694565773,
0.009704514406621456,
0.004104401916265488,
0.045746687799692154,
-0.12690787017345428,
0.03172529116272926,
0.05330182984471321,
0.015363391488790512,
-0.09378334134817123,
-0.06857014447450638,
-0.08896996825933456,
0.07124458253383636,
0.04961451143026352,
-0.02504616603255272,
-0.04691348597407341,
-0.04634428024291992,
0.06210372969508171,
-0.031691379845142365,
-0.006794638000428677,
-0.09164484590291977,
0.016528384760022163,
0.0769265815615654,
-0.0018484548199921846,
0.018067670986056328,
0.07374554127454758,
-0.07075712829828262,
-0.050727467983961105,
-0.037380728870630264,
0.021659741178154945,
-0.03173287585377693,
0.02766038104891777,
0.01415383629500866,
-0.012361809611320496,
-0.018640754744410515,
-0.01481937151402235,
-0.045128125697374344,
-0.003940435126423836,
-0.049692146480083466,
0.09876884520053864,
-0.0016387205105274916,
0.0659460574388504,
-0.021396741271018982,
0.058189839124679565,
-0.012891472317278385,
0.01073194295167923,
-0.08932488411664963,
-0.019024336710572243,
0.00218302384018898,
-4.521022489711868e-8,
-0.004305156879127026,
0.031147971749305725,
-0.04447109252214432,
0.0010656161466613412,
-0.03205690160393715,
-0.033776577562093735,
0.04801124706864357,
-0.05650869384407997,
0.019653193652629852,
0.015617288649082184,
0.05506986379623413,
-0.0030960729345679283,
0.048723798245191574,
-0.04847284033894539,
0.023085396736860275,
-0.04693352058529854,
-0.05962043255567551,
-0.0441722497344017,
0.020130719989538193,
0.028539787977933884,
-0.04277621582150459,
0.005543275736272335,
0.08816628903150558,
-0.0003961645415984094,
-0.02606395073235035,
0.06644795089960098,
0.0581718310713768,
0.08543899655342102,
0.033682290464639664,
0.07396883517503738,
-0.07554055005311966,
0.039144065231084824,
-0.05261913686990738,
-0.044478993862867355,
-0.03780587390065193,
-0.03381739556789398,
-0.07961107045412064,
0.06283698976039886,
0.0030496802646666765,
0.07508343458175659,
-0.040890518575906754,
-0.014573290012776852,
-0.07797171175479889,
0.016434036195278168,
-0.024214990437030792,
-0.12842261791229248,
-0.038573767989873886,
-0.012865902855992317,
-0.018987592309713364,
-0.05228681117296219,
-0.0016464863438159227,
0.03918098285794258,
-0.015015183947980404,
-0.055527929216623306,
-0.024968646466732025,
0.0007092306041158736,
0.020230861380696297,
-0.05011339485645294,
-0.06721226871013641,
0.00837376806885004,
0.006381926592439413,
0.003690560581162572,
-0.012816107831895351,
-0.02178402803838253
] | 0.054572 |
coverage for all files. \* `totalLineCount` {number} The total number of lines. \* `totalBranchCount` {number} The total number of branches. \* `totalFunctionCount` {number} The total number of functions. \* `coveredLineCount` {number} The number of covered lines. \* `coveredBranchCount` {number} The number of covered branches. \* `coveredFunctionCount` {number} The number of covered functions. \* `coveredLinePercent` {number} The percentage of lines covered. \* `coveredBranchPercent` {number} The percentage of branches covered. \* `coveredFunctionPercent` {number} The percentage of functions covered. \* `workingDirectory` {string} The working directory when code coverage began. This is useful for displaying relative path names in case the tests changed the working directory of the Node.js process. \* `nesting` {number} The nesting level of the test. Emitted when code coverage is enabled and all tests have completed. ### Event: `'test:complete'` \* `data` {Object} \* `column` {number|undefined} The column number where the test is defined, or `undefined` if the test was run through the REPL. \* `details` {Object} Additional execution metadata. \* `passed` {boolean} Whether the test passed or not. \* `duration\_ms` {number} The duration of the test in milliseconds. \* `error` {Error|undefined} An error wrapping the error thrown by the test if it did not pass. \* `cause` {Error} The actual error thrown by the test. \* `type` {string|undefined} The type of the test, used to denote whether this is a suite. \* `file` {string|undefined} The path of the test file, `undefined` if test was run through the REPL. \* `line` {number|undefined} The line number where the test is defined, or `undefined` if the test was run through the REPL. \* `name` {string} The test name. \* `nesting` {number} The nesting level of the test. \* `testNumber` {number} The ordinal number of the test. \* `todo` {string|boolean|undefined} Present if [`context.todo`][] is called \* `skip` {string|boolean|undefined} Present if [`context.skip`][] is called Emitted when a test completes its execution. This event is not emitted in the same order as the tests are defined. The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`. ### Event: `'test:dequeue'` \* `data` {Object} \* `column` {number|undefined} The column number where the test is defined, or `undefined` if the test was run through the REPL. \* `file` {string|undefined} The path of the test file, `undefined` if test was run through the REPL. \* `line` {number|undefined} The line number where the test is defined, or `undefined` if the test was run through the REPL. \* `name` {string} The test name. \* `nesting` {number} The nesting level of the test. \* `type` {string} The test type. Either `'suite'` or `'test'`. Emitted when a test is dequeued, right before it is executed. This event is not guaranteed to be emitted in the same order as the tests are defined. The corresponding declaration ordered event is `'test:start'`. ### Event: `'test:diagnostic'` \* `data` {Object} \* `column` {number|undefined} The column number where the test is defined, or `undefined` if the test was run through the REPL. \* `file` {string|undefined} The path of the test file, `undefined` if test was run through the REPL. \* `line` {number|undefined} The line number where the test is defined, or `undefined` if the test was run through the REPL. \* `message` {string} The diagnostic message. \* `nesting` {number} The nesting level of the test. \* `level` {string} The severity level of the diagnostic message. Possible values are: \* `'info'`: Informational messages. \* `'warn'`: Warnings. \* `'error'`: Errors. Emitted when [`context.diagnostic`][] is called. This event is guaranteed to be emitted in the same order as the tests are defined. ### Event: `'test:enqueue'` \* `data` {Object} \* `column` {number|undefined} The column number where the test is defined, or `undefined` if the test | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.030677203088998795,
0.05775359272956848,
-0.024587053805589676,
0.06641822308301926,
0.008043418638408184,
-0.04445480555295944,
0.003573087975382805,
0.07684658467769623,
-0.012258214876055717,
0.05527028441429138,
-0.005771303083747625,
0.01977890357375145,
0.01422212179750204,
-0.02487773634493351,
-0.0045044864527881145,
0.006106134504079819,
-0.09852650761604309,
-0.005159469787031412,
-0.03706643730401993,
-0.05619752034544945,
0.0069946665316820145,
0.049386583268642426,
0.04419681802392006,
-0.04971140995621681,
0.0013806348433718085,
-0.033186204731464386,
-0.047850944101810455,
-0.0018452436197549105,
-0.0009866900509223342,
-0.011363008990883827,
-0.04257488250732422,
0.019136611372232437,
0.028740013018250465,
0.04614058881998062,
0.06205562874674797,
0.009088603779673576,
-0.027867615222930908,
-0.08012902736663818,
-0.039850592613220215,
0.049333397299051285,
0.02576061151921749,
0.11667265743017197,
-0.008319319225847721,
-0.05642363056540489,
0.032787393778562546,
-0.03548593446612358,
-0.09374882280826569,
-0.0022241156548261642,
-0.026851708069443703,
0.0457836352288723,
0.016913756728172302,
-0.026382505893707275,
-0.056806530803442,
-0.012848153710365295,
0.022080209106206894,
-0.026666708290576935,
0.037177328020334244,
-0.08901939541101456,
-0.015853701159358025,
0.05181967094540596,
0.013107731938362122,
-0.027229003608226776,
-0.02524659037590027,
-0.05293472483754158,
0.017591675743460655,
0.015486433170735836,
-0.030938973650336266,
0.07976482808589935,
0.01845020055770874,
0.019946342334151268,
-0.015917552635073662,
0.09801457077264786,
-0.018629640340805054,
-0.008141220547258854,
0.03726217523217201,
0.02404513768851757,
-0.02089865878224373,
0.07888951152563095,
0.024766819551587105,
-0.1464831531047821,
-0.002974515547975898,
-0.11912833154201508,
0.011873189359903336,
0.03177763894200325,
-0.022665323689579964,
0.14479728043079376,
0.05170125514268875,
-0.01129200216382742,
0.016522932797670364,
-0.030657630413770676,
-0.017033327370882034,
-0.040270525962114334,
-0.04304717108607292,
0.02892381325364113,
-0.09572096914052963,
0.06989743560552597,
-0.026199638843536377,
0.04168136790394783,
0.06569099426269531,
0.0019357905257493258,
-0.025128278881311417,
-0.05681166425347328,
0.15096479654312134,
-0.044991061091423035,
-0.06977883726358414,
0.02855580486357212,
0.0764165073633194,
-0.008224902674555779,
-0.003883330849930644,
-0.06571612507104874,
0.04149862006306648,
0.008750643581151962,
-0.009255790151655674,
0.00706684123724699,
0.01853235252201557,
-0.08944911509752274,
0.09755422919988632,
-0.010130696929991245,
0.07508200407028198,
0.16609683632850647,
0.1734621673822403,
0.043195176869630814,
0.01839005947113037,
-0.0070702433586120605,
0.060121797025203705,
0.006899276748299599,
0.05419009551405907,
7.454370242432673e-33,
0.05089612677693367,
-0.07175424695014954,
0.04811966419219971,
0.09076111018657684,
0.09186775237321854,
-0.0007806941284798086,
0.07182495296001434,
0.044225964695215225,
-0.022720785811543465,
0.13672274351119995,
-0.07811994850635529,
0.01582864485681057,
-0.003382059745490551,
-0.07245746999979019,
-0.034573014825582504,
-0.020979462191462517,
-0.00036018871469423175,
-0.019140906631946564,
-0.0702538713812828,
0.08576393872499466,
-0.0011590983485803008,
-0.03253347799181938,
-0.007170206401497126,
-0.004348748363554478,
0.03159450367093086,
-0.04152427241206169,
0.04088202491402626,
0.010739549994468689,
-0.05081230774521828,
0.0077515775337815285,
0.06458887457847595,
0.004269019700586796,
0.013437684625387192,
0.09180789440870285,
0.008312026038765907,
0.10468744486570358,
0.011010977439582348,
0.0005985080497339368,
-0.05266880616545677,
0.03455453738570213,
-0.09551176428794861,
-0.03607555478811264,
-0.027074666693806648,
0.01234501600265503,
-0.03359033539891243,
-0.08202256262302399,
-0.03148859739303589,
-0.041968271136283875,
0.048474278301000595,
0.008747091516852379,
-0.04687876999378204,
0.07111401855945587,
0.020627649500966072,
-0.04948762431740761,
0.020347964018583298,
-0.01797526143491268,
-0.0021003414876759052,
-0.020593341439962387,
-0.01958460360765457,
0.05729828402400017,
-0.016954384744167328,
0.004353968892246485,
-0.056930504739284515,
-0.016319746151566505,
-0.005358794238418341,
-0.028025329113006592,
0.016127515584230423,
-0.06889045238494873,
0.04353003576397896,
0.030175592750310898,
-0.05279611796140671,
0.02907518669962883,
0.02922329679131508,
0.04228093475103378,
-0.01950027607381344,
0.009891070425510406,
-0.023811213672161102,
0.013107415288686752,
-0.04697767645120621,
-0.007442606147378683,
0.01058199629187584,
-0.06627490371465683,
-0.021929705515503883,
-0.0157119520008564,
0.0883721336722374,
0.007663789205253124,
0.002260119654238224,
-0.00879407674074173,
-0.012827751226723194,
-0.12322469055652618,
0.07494637370109558,
-0.014664382673799992,
-0.031143423169851303,
-0.09903145581483841,
-0.026043863967061043,
-8.315735768516783e-33,
-0.005510745570063591,
0.06540263444185257,
0.008193936198949814,
-0.014971989206969738,
-0.05133659392595291,
-0.017000140622258186,
-0.0290912427008152,
-0.0787874311208725,
0.004842628259211779,
0.015932831913232803,
-0.012064388953149319,
0.05416390299797058,
-0.02114398404955864,
-0.0304962620139122,
-0.010009570978581905,
0.034565698355436325,
-0.11089010536670685,
-0.07383926957845688,
0.04224870353937149,
-0.011486116796731949,
-0.01807449758052826,
0.026179620996117592,
0.04383457824587822,
0.061914559453725815,
-0.087991863489151,
-0.03649855777621269,
0.003311967011541128,
-0.025868749246001244,
0.11371492594480515,
-0.019763395190238953,
0.03235398977994919,
-0.02363767847418785,
-0.05844467505812645,
0.014783622696995735,
-0.04270496219396591,
-0.14967720210552216,
0.04584140703082085,
0.06344548612833023,
0.05698856711387634,
0.0044455090537667274,
0.03631804510951042,
-0.0007988761644810438,
0.024567868560552597,
-0.03830581158399582,
0.010345852933824062,
0.02780955471098423,
0.015222142450511456,
-0.01796739175915718,
-0.08430776000022888,
-0.07206374406814575,
-0.04341608285903931,
-0.006277086678892374,
-0.028514713048934937,
0.05196702480316162,
-0.026510588824748993,
0.008623555302619934,
-0.05252712965011597,
-0.013787128031253815,
-0.04299834370613098,
0.05345803499221802,
0.01317168865352869,
0.005230201408267021,
0.01766929030418396,
-0.03356922045350075,
-0.0689692422747612,
-0.04674115031957626,
-0.07328551262617111,
-0.03053921088576317,
0.007105202879756689,
-0.02194826677441597,
-0.11058269441127777,
-0.0007096540066413581,
-0.07852774858474731,
-0.04173743724822998,
-0.030945762991905212,
0.025257209315896034,
-0.010564693249762058,
-0.09904548525810242,
0.07739362865686417,
0.15674519538879395,
-0.022913401946425438,
0.029046181589365005,
-0.09805405884981155,
0.033369243144989014,
0.018443703651428223,
-0.025847826153039932,
0.008860318921506405,
0.09260118752717972,
-0.002868265612050891,
-0.036618273705244064,
-0.016602573916316032,
0.06123633310198784,
-0.04221254959702492,
-0.04886679723858833,
-0.04061419516801834,
-5.607155628695182e-8,
-0.05437188968062401,
0.0418001227080822,
-0.053587134927511215,
-0.05546703562140465,
0.040898360311985016,
-0.02958454005420208,
-0.004957857076078653,
0.08673717081546783,
-0.021521298214793205,
0.01495836116373539,
0.04121077433228493,
0.07074931263923645,
-0.04048094153404236,
-0.001216781442053616,
-0.04448103532195091,
-0.028014404699206352,
0.009477426297962666,
0.07297136634588242,
-0.032960131764411926,
0.04541994258761406,
-0.014660798944532871,
0.0377398282289505,
-0.022064384073019028,
0.02388462983071804,
-0.023154888302087784,
-0.002886268077418208,
0.0496479831635952,
0.0756346583366394,
-0.021192079409956932,
-0.004170560277998447,
-0.007701782044023275,
0.0016041421331465244,
-0.03440241888165474,
-0.07739602774381638,
-0.035547997802495956,
0.018403491005301476,
0.08168191462755203,
-0.02200591191649437,
0.08855773508548737,
0.09348547458648682,
0.022932687774300575,
-0.000025386918423464522,
0.04663443937897682,
0.08389899879693985,
0.0029275857377797365,
-0.12896065413951874,
-0.04637548699975014,
0.00720833707600832,
0.011054486967623234,
-0.13163621723651886,
-0.04967014864087105,
-0.026380687952041626,
-0.062038060277700424,
0.04411580041050911,
-0.0371435284614563,
0.05474153533577919,
0.02651693858206272,
-0.04642617329955101,
-0.04259153828024864,
0.05650312080979347,
-0.00640060193836689,
-0.02876642718911171,
0.008985686115920544,
-0.01819906383752823
] | 0.048872 |
messages. \* `'warn'`: Warnings. \* `'error'`: Errors. Emitted when [`context.diagnostic`][] is called. This event is guaranteed to be emitted in the same order as the tests are defined. ### Event: `'test:enqueue'` \* `data` {Object} \* `column` {number|undefined} The column number where the test is defined, or `undefined` if the test was run through the REPL. \* `file` {string|undefined} The path of the test file, `undefined` if test was run through the REPL. \* `line` {number|undefined} The line number where the test is defined, or `undefined` if the test was run through the REPL. \* `name` {string} The test name. \* `nesting` {number} The nesting level of the test. \* `type` {string} The test type. Either `'suite'` or `'test'`. Emitted when a test is enqueued for execution. ### Event: `'test:fail'` \* `data` {Object} \* `column` {number|undefined} The column number where the test is defined, or `undefined` if the test was run through the REPL. \* `details` {Object} Additional execution metadata. \* `duration\_ms` {number} The duration of the test in milliseconds. \* `error` {Error} An error wrapping the error thrown by the test. \* `cause` {Error} The actual error thrown by the test. \* `type` {string|undefined} The type of the test, used to denote whether this is a suite. \* `attempt` {number|undefined} The attempt number of the test run, present only when using the [`--test-rerun-failures`][] flag. \* `file` {string|undefined} The path of the test file, `undefined` if test was run through the REPL. \* `line` {number|undefined} The line number where the test is defined, or `undefined` if the test was run through the REPL. \* `name` {string} The test name. \* `nesting` {number} The nesting level of the test. \* `testNumber` {number} The ordinal number of the test. \* `todo` {string|boolean|undefined} Present if [`context.todo`][] is called \* `skip` {string|boolean|undefined} Present if [`context.skip`][] is called Emitted when a test fails. This event is guaranteed to be emitted in the same order as the tests are defined. The corresponding execution ordered event is `'test:complete'`. ### Event: `'test:pass'` \* `data` {Object} \* `column` {number|undefined} The column number where the test is defined, or `undefined` if the test was run through the REPL. \* `details` {Object} Additional execution metadata. \* `duration\_ms` {number} The duration of the test in milliseconds. \* `type` {string|undefined} The type of the test, used to denote whether this is a suite. \* `attempt` {number|undefined} The attempt number of the test run, present only when using the [`--test-rerun-failures`][] flag. \* `passed\_on\_attempt` {number|undefined} The attempt number the test passed on, present only when using the [`--test-rerun-failures`][] flag. \* `file` {string|undefined} The path of the test file, `undefined` if test was run through the REPL. \* `line` {number|undefined} The line number where the test is defined, or `undefined` if the test was run through the REPL. \* `name` {string} The test name. \* `nesting` {number} The nesting level of the test. \* `testNumber` {number} The ordinal number of the test. \* `todo` {string|boolean|undefined} Present if [`context.todo`][] is called \* `skip` {string|boolean|undefined} Present if [`context.skip`][] is called Emitted when a test passes. This event is guaranteed to be emitted in the same order as the tests are defined. The corresponding execution ordered event is `'test:complete'`. ### Event: `'test:plan'` \* `data` {Object} \* `column` {number|undefined} The column number where the test is defined, or `undefined` if the test was run through the REPL. \* `file` {string|undefined} The path of the test file, `undefined` if test was run through the REPL. \* `line` {number|undefined} The line number where the test is defined, or `undefined` if the test was run through the REPL. \* `nesting` {number} The nesting level | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.08248637616634369,
0.026248525828123093,
-0.08504434674978256,
0.09914422780275345,
0.010144425556063652,
-0.07001958787441254,
0.044305283576250076,
0.013958272524178028,
0.05999738350510597,
-0.012039465829730034,
0.06686268746852875,
0.006410721689462662,
0.055604904890060425,
0.03980770334601402,
-0.01953638345003128,
0.019590964540839195,
-0.06969212740659714,
-0.05486711859703064,
-0.028723279014229774,
-0.0458795540034771,
0.030034562572836876,
0.028046125546097755,
-0.029877912253141403,
0.061118703335523605,
-0.004203808028250933,
0.0007304677274078131,
-0.05615696310997009,
0.04704331234097481,
-0.007207813672721386,
-0.04484880715608597,
-0.005635164678096771,
-0.0009985052747651935,
-0.04577485844492912,
0.05602142587304115,
0.09164987504482269,
0.08326634019613266,
0.03398098051548004,
-0.04261065647006035,
-0.06674590706825256,
0.04002819210290909,
0.07636167854070663,
-0.00302144605666399,
-0.05817592144012451,
-0.0434168316423893,
0.02973075397312641,
-0.09293632209300995,
-0.015572459436953068,
-0.052810195833444595,
-0.12417543679475784,
-0.022436250001192093,
0.01826063171029091,
0.04194944351911545,
-0.0022299729753285646,
-0.011364422738552094,
-0.009503008797764778,
-0.02329258620738983,
0.009526761248707771,
-0.018169596791267395,
0.03140364587306976,
0.020263105630874634,
-0.02632235549390316,
-0.07798020541667938,
-0.010850025340914726,
-0.041268374770879745,
-0.02741127274930477,
-0.026828523725271225,
-0.058306194841861725,
0.035753894597291946,
0.06804594397544861,
0.012932651676237583,
-0.07259668409824371,
0.03281574696302414,
-0.0004767300852108747,
0.038271162658929825,
0.006997280288487673,
0.009227510541677475,
-0.007972108200192451,
-0.050716646015644073,
0.02675420418381691,
-0.06425851583480835,
-0.047173477709293365,
-0.12248126417398453,
-0.014831476844847202,
-0.01309632696211338,
0.01129117514938116,
0.04053027555346489,
0.0694250836968422,
-0.025599954649806023,
0.0015843880828469992,
0.023688089102506638,
-0.009572240523993969,
-0.08550234138965607,
-0.006079450715333223,
0.11721986532211304,
0.05167040601372719,
0.025446198880672455,
-0.021727025508880615,
-0.052675504237413406,
0.03867149353027344,
0.0108645623549819,
0.01146689709275961,
-0.016631916165351868,
0.06567486375570297,
0.035114362835884094,
0.017269790172576904,
0.000047781642933841795,
0.00029212416848167777,
-0.05516231060028076,
-0.02141956053674221,
-0.024009330198168755,
0.04210679233074188,
-0.025916632264852524,
0.0739099532365799,
-0.06289387494325638,
0.0000038161933844094165,
0.04067423194646835,
-0.05930585041642189,
0.019853824749588966,
-0.04760048910975456,
0.052935291081666946,
0.12769745290279388,
-0.03224659711122513,
-0.016656676307320595,
-0.01724810153245926,
0.057858988642692566,
0.06514840573072433,
0.10582208633422852,
4.9940249339891164e-33,
0.01805030182003975,
-0.04970192909240723,
-0.03768899291753769,
0.1291002631187439,
0.06897997111082077,
0.05673806369304657,
0.008926989510655403,
0.05868453159928322,
-0.05435674637556076,
0.03473269194364548,
-0.0003435776452533901,
0.056956931948661804,
-0.0016206663567572832,
-0.04061240330338478,
-0.0284658782184124,
0.0716567412018776,
0.02121630869805813,
-0.007835760712623596,
-0.045606497675180435,
0.04087277874350548,
0.015417511574923992,
-0.02357572689652443,
-0.07145287841558456,
-0.05357551574707031,
-0.01906723901629448,
0.032837849110364914,
0.004945047665387392,
-0.03467942029237747,
-0.02996310591697693,
-0.03245162218809128,
-0.0005520204431377351,
-0.031417567282915115,
0.03686986863613129,
0.1391572207212448,
0.06496356427669525,
0.03406187891960144,
0.03559061512351036,
0.046862587332725525,
-0.062296777963638306,
0.0030278312042355537,
0.01496477797627449,
-0.01097567193210125,
-0.06523030996322632,
0.02119673416018486,
-0.015092463232576847,
-0.13395008444786072,
-0.036033835262060165,
0.06312938034534454,
0.0843837633728981,
-0.05993030592799187,
0.005599657539278269,
0.11829984188079834,
0.10337739437818527,
0.0224734116345644,
0.09862572699785233,
0.01278664544224739,
0.020975187420845032,
-0.023070015013217926,
-0.004312429111450911,
-0.04639172926545143,
-0.0026054279878735542,
-0.005785354878753424,
-0.038906123489141464,
-0.020544225350022316,
0.025324879214167595,
-0.022683035582304,
-0.04307713732123375,
-0.040630243718624115,
0.029704181477427483,
0.03416848182678223,
-0.029442377388477325,
0.04249152913689613,
-0.0014512315392494202,
0.03508775681257248,
0.020998738706111908,
-0.04297636076807976,
-0.04274211823940277,
0.07318142801523209,
0.014689329080283642,
-0.009828953072428703,
0.028708910569548607,
-0.06806717067956924,
-0.0334746390581131,
0.04221666604280472,
-0.04264213517308235,
0.02151835896074772,
-0.03582672402262688,
-0.0666898638010025,
-0.05344029515981674,
-0.06999997794628143,
0.07127462327480316,
-0.011640409007668495,
0.022533223032951355,
-0.028778601437807083,
-0.004814325366169214,
-7.090353437445597e-33,
0.05230091139674187,
0.06706894189119339,
-0.06189568340778351,
0.02361285872757435,
0.04329943656921387,
-0.04128199815750122,
0.03475821763277054,
0.031181542202830315,
-0.0067657651379704475,
0.010669946670532227,
-0.027926385402679443,
0.017433734610676765,
0.05501914769411087,
0.05192909389734268,
0.04943380877375603,
0.05748749151825905,
-0.14968416094779968,
-0.044831469655036926,
-0.03658001497387886,
-0.0666060522198677,
0.03028835728764534,
0.03783874213695526,
0.04940510913729668,
0.08312806487083435,
-0.08673229068517685,
-0.01562558487057686,
0.08969124406576157,
-0.08656095713376999,
-0.03565170243382454,
0.005323529243469238,
0.02822507731616497,
0.042304567992687225,
-0.08225004374980927,
0.07748612016439438,
-0.0038684203755110502,
-0.1015014722943306,
0.07444673776626587,
0.00221564550884068,
-0.007792647462338209,
0.0007153054466471076,
0.05290563777089119,
0.12523318827152252,
-0.040911052376031876,
-0.0516044907271862,
0.02768527902662754,
0.006019813008606434,
0.08969200402498245,
0.031978171318769455,
-0.04067210480570793,
-0.04006658494472504,
-0.04351796582341194,
-0.031070230528712273,
-0.01635049656033516,
0.026825688779354095,
-0.07596954703330994,
0.002180705079808831,
-0.006171013694256544,
0.04414962977170944,
-0.08069583773612976,
0.08804180473089218,
-0.026677535846829414,
-0.0071936845779418945,
0.00028073860448785126,
0.02327452041208744,
-0.07973199337720871,
-0.026293110102415085,
-0.08087863028049469,
-0.04662562906742096,
0.08742532134056091,
-0.05490173026919365,
-0.006537475157529116,
-0.05832221731543541,
-0.0798572525382042,
-0.06247074529528618,
0.04406140372157097,
0.05189443379640579,
-0.03981941565871239,
-0.02920454554259777,
0.028493203222751617,
0.0403122752904892,
-0.02674812078475952,
-0.038716744631528854,
0.04747074469923973,
0.08753596991300583,
-0.018061047419905663,
-0.008143804036080837,
-0.002137842122465372,
0.10996749252080917,
-0.038890983909368515,
0.015300733968615532,
0.0526282824575901,
-0.03826179727911949,
-0.040522895753383636,
0.008803938515484333,
0.041377339512109756,
-6.069746660841702e-8,
-0.08374816924333572,
-0.016491670161485672,
-0.08730335533618927,
-0.06824833154678345,
-0.003361193463206291,
0.00841298047453165,
0.01810098998248577,
-0.0167815163731575,
0.012751736678183079,
-0.0003567242529243231,
-0.03595329076051712,
0.01988314464688301,
-0.0510452464222908,
0.005324407946318388,
-0.027182800695300102,
0.023256439715623856,
-0.03142416849732399,
0.00676931394264102,
-0.030848611146211624,
-0.03801728039979935,
0.025184452533721924,
-0.001169894589111209,
-0.040482569485902786,
0.06079825386404991,
-0.0465034618973732,
-0.018209178000688553,
0.07382513582706451,
0.12871785461902618,
-0.0634676143527031,
-0.05049636960029602,
0.030036887153983116,
0.00997717771679163,
-0.030944986268877983,
-0.06375660002231598,
-0.049222368746995926,
0.12451466172933578,
0.15191741287708282,
-0.030949696898460388,
0.036231085658073425,
0.05063994228839874,
0.008998974226415157,
0.010686754249036312,
-0.03770316019654274,
-0.0071782604791224,
-0.09914186596870422,
-0.050202690064907074,
-0.080275759100914,
-0.021635927259922028,
0.016766509041190147,
-0.0645841434597969,
-0.029225455597043037,
0.01292537059634924,
-0.06615583598613739,
0.00841446965932846,
-0.06762529909610748,
0.02290130965411663,
0.035513851791620255,
0.017300065606832504,
-0.05831358954310417,
0.0034175992477685213,
0.1429528146982193,
-0.057012833654880524,
0.05513196811079979,
-0.07809222489595413
] | 0.042484 |
test was run through the REPL. \* `file` {string|undefined} The path of the test file, `undefined` if test was run through the REPL. \* `line` {number|undefined} The line number where the test is defined, or `undefined` if the test was run through the REPL. \* `nesting` {number} The nesting level of the test. \* `count` {number} The number of subtests that have ran. Emitted when all subtests have completed for a given test. This event is guaranteed to be emitted in the same order as the tests are defined. ### Event: `'test:start'` \* `data` {Object} \* `column` {number|undefined} The column number where the test is defined, or `undefined` if the test was run through the REPL. \* `file` {string|undefined} The path of the test file, `undefined` if test was run through the REPL. \* `line` {number|undefined} The line number where the test is defined, or `undefined` if the test was run through the REPL. \* `name` {string} The test name. \* `nesting` {number} The nesting level of the test. Emitted when a test starts reporting its own and its subtests status. This event is guaranteed to be emitted in the same order as the tests are defined. The corresponding execution ordered event is `'test:dequeue'`. ### Event: `'test:stderr'` \* `data` {Object} \* `file` {string} The path of the test file. \* `message` {string} The message written to `stderr`. Emitted when a running test writes to `stderr`. This event is only emitted if `--test` flag is passed. This event is not guaranteed to be emitted in the same order as the tests are defined. ### Event: `'test:stdout'` \* `data` {Object} \* `file` {string} The path of the test file. \* `message` {string} The message written to `stdout`. Emitted when a running test writes to `stdout`. This event is only emitted if `--test` flag is passed. This event is not guaranteed to be emitted in the same order as the tests are defined. ### Event: `'test:summary'` \* `data` {Object} \* `counts` {Object} An object containing the counts of various test results. \* `cancelled` {number} The total number of cancelled tests. \* `failed` {number} The total number of failed tests. \* `passed` {number} The total number of passed tests. \* `skipped` {number} The total number of skipped tests. \* `suites` {number} The total number of suites run. \* `tests` {number} The total number of tests run, excluding suites. \* `todo` {number} The total number of TODO tests. \* `topLevel` {number} The total number of top level tests and suites. \* `duration\_ms` {number} The duration of the test run in milliseconds. \* `file` {string|undefined} The path of the test file that generated the summary. If the summary corresponds to multiple files, this value is `undefined`. \* `success` {boolean} Indicates whether or not the test run is considered successful or not. If any error condition occurs, such as a failing test or unmet coverage threshold, this value will be set to `false`. Emitted when a test run completes. This event contains metrics pertaining to the completed test run, and is useful for determining if a test run passed or failed. If process-level test isolation is used, a `'test:summary'` event is generated for each test file in addition to a final cumulative summary. ### Event: `'test:watch:drained'` Emitted when no more tests are queued for execution in watch mode. ### Event: `'test:watch:restarted'` Emitted when one or more tests are restarted due to a file change in watch mode. ## Class: `TestContext` An instance of `TestContext` is passed to each test function in order to interact with the test runner. However, the `TestContext` constructor is not exposed as part | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.1052926629781723,
-0.0010310375364497304,
-0.04595039784908295,
0.0991373360157013,
0.01875009760260582,
-0.06511451303958893,
-0.05355197191238403,
0.005600443575531244,
0.08026625216007233,
0.011084911413490772,
0.054289188235998154,
0.048109736293554306,
0.005362389143556356,
0.01618410460650921,
-0.045562367886304855,
0.006933830678462982,
-0.08993969112634659,
-0.03943626955151558,
-0.04209485277533531,
-0.08182316273450851,
0.03911775350570679,
-0.008765870705246925,
-0.035217173397541046,
0.013420200906693935,
0.0019940969068557024,
0.03465057164430618,
-0.058299124240875244,
0.023273441940546036,
0.04959411546587944,
-0.048141900449991226,
0.015411298722028732,
-0.04202429577708244,
-0.026841532438993454,
0.061368077993392944,
0.11077284067869186,
0.04418863728642464,
0.015483290888369083,
-0.08470265567302704,
-0.03471042960882187,
0.07366693019866943,
0.08863089233636856,
0.006395411211997271,
-0.04657937213778496,
-0.03954243287444115,
0.036303892731666565,
-0.02476467378437519,
-0.03970671445131302,
-0.08043383061885834,
-0.1444810926914215,
0.00691251689568162,
0.02746974490582943,
0.02123696729540825,
-0.01721741445362568,
0.03779105097055435,
0.004811116959899664,
-0.026671333238482475,
0.04598857834935188,
-0.03903830796480179,
0.04531180486083031,
0.048821836709976196,
-0.045835670083761215,
-0.07881025224924088,
-0.009402144700288773,
-0.04623778536915779,
0.010123898275196552,
0.004751265514642,
-0.06159152463078499,
0.01301748026162386,
0.08422325551509857,
0.041811853647232056,
-0.041186507791280746,
0.07909112423658371,
0.028559669852256775,
-0.003524400293827057,
0.01434105820953846,
0.019310664385557175,
-0.05218089744448662,
-0.03379078954458237,
0.026550179347395897,
-0.10523968189954758,
-0.05179877579212189,
-0.11951993405818939,
-0.0406816229224205,
-0.027272380888462067,
0.013792897574603558,
0.04479943588376045,
0.10664563626050949,
-0.03155441954731941,
-0.015661997720599174,
0.01576005294919014,
-0.05520881712436676,
-0.04907078668475151,
-0.034209877252578735,
0.10526959598064423,
0.02338356152176857,
0.0230831578373909,
0.030905505642294884,
-0.0200132355093956,
0.07788005471229553,
-0.012097061611711979,
-0.007523557171225548,
0.037588514387607574,
0.05601298809051514,
0.04035179689526558,
0.00797298178076744,
-0.015278918668627739,
-0.031847454607486725,
-0.06355545669794083,
-0.021269438788294792,
-0.0027804949786514044,
0.04974594712257385,
0.0002263389906147495,
0.08815556019544601,
-0.05405369773507118,
0.005466165952384472,
0.023912739008665085,
0.01597871072590351,
0.040023792535066605,
-0.04715891554951668,
0.05258508026599884,
0.13210491836071014,
-0.007246342487633228,
0.037397660315036774,
-0.005093696527183056,
0.043952640146017075,
0.03891736641526222,
0.08189252018928528,
6.46629818027343e-33,
0.022011645138263702,
-0.10695049166679382,
-0.030803948640823364,
0.108561672270298,
0.07013213634490967,
0.023136602714657784,
0.024779699742794037,
0.08429301530122757,
-0.04067341238260269,
0.10735427588224411,
-0.030912823975086212,
0.02467801235616207,
0.013069580309092999,
-0.06438738852739334,
0.007213979959487915,
0.03524123504757881,
0.023076016455888748,
-0.043559134006500244,
-0.10318906605243683,
0.06698211282491684,
0.0474107451736927,
-0.04771637171506882,
-0.06857036054134369,
-0.036843378096818924,
-0.0008227119105868042,
0.016992688179016113,
-0.025516699999570847,
-0.0029850397258996964,
-0.07550743967294693,
-0.025828039273619652,
0.017991501837968826,
-0.021544840186834335,
-0.009160516783595085,
0.12677645683288574,
0.00851930771023035,
0.01587984524667263,
0.04971442371606827,
-0.0023013241589069366,
-0.03463076055049896,
0.01803404465317726,
0.03464470058679581,
-0.0353534072637558,
-0.055124249309301376,
-0.034147344529628754,
-0.054951414465904236,
-0.1678004264831543,
-0.053545255213975906,
0.011024908162653446,
0.07752519845962524,
-0.04075847938656807,
0.012328117154538631,
0.11335854977369308,
0.09372253715991974,
-0.03909750282764435,
0.062131334096193314,
-0.010576706379652023,
-0.05063294619321823,
-0.02564963325858116,
0.01159601379185915,
0.027751633897423744,
0.004095840733498335,
0.016902592033147812,
-0.06169640272855759,
0.04853525012731552,
-0.026360495015978813,
-0.0016382279573008418,
-0.017431583255529404,
-0.05574703589081764,
0.05666905641555786,
0.03439007326960564,
-0.014135805889964104,
0.05576710030436516,
-0.03855796530842781,
0.0016625946154817939,
0.009014606475830078,
-0.0259578637778759,
-0.0264617707580328,
0.06860610842704773,
-0.0026907918509095907,
-0.0072154994122684,
0.04836313799023628,
-0.05931009352207184,
-0.0059631941840052605,
0.04205308482050896,
-0.008722149766981602,
0.025779088959097862,
-0.05546138808131218,
-0.09268905967473984,
-0.08952223509550095,
-0.10071095824241638,
0.07339363545179367,
-0.038242191076278687,
0.02248915284872055,
-0.07921580225229263,
0.020376643165946007,
-7.041586584933796e-33,
0.09084643423557281,
0.08314996212720871,
-0.05318671092391014,
0.03403107821941376,
0.05871344730257988,
-0.04883459210395813,
0.00799830723553896,
0.004383507184684277,
-0.0331166610121727,
0.04343049228191376,
-0.01840747520327568,
0.03232578560709953,
0.021764451637864113,
0.041478272527456284,
0.01929366961121559,
0.054772425442934036,
-0.13651703298091888,
-0.047961845993995667,
0.002567222574725747,
-0.03616053983569145,
0.038255635648965836,
0.058942846953868866,
0.05530944839119911,
0.03300165385007858,
-0.05847712606191635,
0.026624029502272606,
0.08707362413406372,
-0.0318046435713768,
-0.001335218083113432,
0.00313148507848382,
0.029052147641777992,
0.042092807590961456,
-0.07210128754377365,
0.07750549167394638,
0.010473216883838177,
-0.08773894608020782,
0.07590027898550034,
0.030211832374334335,
0.019664164632558823,
0.02090580388903618,
0.05605897679924965,
0.10311880707740784,
-0.04278308525681496,
-0.008790086954832077,
0.022913649678230286,
0.024197179824113846,
0.06551476567983627,
0.05639703571796417,
-0.04993430897593498,
-0.0708453580737114,
-0.06849589943885803,
0.024423209950327873,
-0.03164125978946686,
0.058556389063596725,
-0.0731697529554367,
-0.0033302609808743,
-0.013996676541864872,
0.03954272344708443,
-0.06269361078739166,
0.08135495334863663,
-0.012643157504498959,
0.0010510858846828341,
0.029565580189228058,
0.03953426703810692,
-0.04492083191871643,
-0.003592654364183545,
-0.07107062637805939,
-0.03744979575276375,
0.08369335532188416,
-0.05626579001545906,
0.0000915988493943587,
-0.002302806358784437,
-0.06748465448617935,
-0.03311712294816971,
0.008874984458088875,
0.0441836416721344,
-0.04311902076005936,
-0.014117050915956497,
0.05901431292295456,
0.025655359029769897,
-0.07734901458024979,
-0.03264883533120155,
-0.010244122706353664,
0.04613924026489258,
-0.004970896989107132,
0.016562990844249725,
0.0005253629060462117,
0.10192263871431351,
-0.018233772367239,
0.005848786793649197,
0.020894713699817657,
-0.04440909996628761,
-0.027128126472234726,
-0.0066517796367406845,
0.014784256927669048,
-5.501462752022235e-8,
-0.061598680913448334,
-0.02219391241669655,
-0.06436413526535034,
-0.020986806601285934,
0.028339866548776627,
0.026847070083022118,
0.010477310977876186,
0.011751451529562473,
-0.014296995475888252,
-0.030541982501745224,
-0.008267106488347054,
0.0345105342566967,
-0.03559068962931633,
0.028636978939175606,
-0.05027634650468826,
0.02084280364215374,
0.01024877279996872,
-0.008005506359040737,
-0.03547191992402077,
0.0036302004009485245,
-0.026922784745693207,
0.03280216082930565,
-0.011913825757801533,
0.06159551814198494,
-0.03520878776907921,
-0.003065922763198614,
0.07661398500204086,
0.12749743461608887,
-0.046231988817453384,
-0.07164319604635239,
0.03856990113854408,
0.05000893399119377,
-0.0326235368847847,
-0.021788811311125755,
-0.06770572066307068,
0.10173622518777847,
0.08346753567457199,
0.004735441412776709,
0.009686870500445366,
0.016918253153562546,
0.007003063336014748,
-0.007653077132999897,
-0.013148831203579903,
0.02748364582657814,
-0.07414665073156357,
-0.052641503512859344,
-0.1280069202184677,
-0.040549974888563156,
0.021375099197030067,
-0.09667911380529404,
-0.03716336190700531,
-0.0003376411332283169,
-0.06627894937992096,
0.008605314418673515,
-0.058316607028245926,
0.050311584025621414,
0.04099244996905327,
-0.015293007716536522,
-0.04931839182972908,
0.018877509981393814,
0.1320781707763672,
-0.07564746588468552,
0.02258964069187641,
-0.061428721994161606
] | 0.033399 |
mode. ### Event: `'test:watch:restarted'` Emitted when one or more tests are restarted due to a file change in watch mode. ## Class: `TestContext` An instance of `TestContext` is passed to each test function in order to interact with the test runner. However, the `TestContext` constructor is not exposed as part of the API. ### `context.before([fn][, options])` \* `fn` {Function|AsyncFunction} The hook function. The first argument to this function is a [`TestContext`][] object. If the hook uses callbacks, the callback function is passed as the second argument. \*\*Default:\*\* A no-op function. \* `options` {Object} Configuration options for the hook. The following properties are supported: \* `signal` {AbortSignal} Allows aborting an in-progress hook. \* `timeout` {number} A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. This function is used to create a hook running before subtest of the current test. ### `context.beforeEach([fn][, options])` \* `fn` {Function|AsyncFunction} The hook function. The first argument to this function is a [`TestContext`][] object. If the hook uses callbacks, the callback function is passed as the second argument. \*\*Default:\*\* A no-op function. \* `options` {Object} Configuration options for the hook. The following properties are supported: \* `signal` {AbortSignal} Allows aborting an in-progress hook. \* `timeout` {number} A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. This function is used to create a hook running before each subtest of the current test. ```js test('top level test', async (t) => { t.beforeEach((t) => t.diagnostic(`about to run ${t.name}`)); await t.test( 'This is a subtest', (t) => { // Some relevant assertion here }, ); }); ``` ### `context.after([fn][, options])` \* `fn` {Function|AsyncFunction} The hook function. The first argument to this function is a [`TestContext`][] object. If the hook uses callbacks, the callback function is passed as the second argument. \*\*Default:\*\* A no-op function. \* `options` {Object} Configuration options for the hook. The following properties are supported: \* `signal` {AbortSignal} Allows aborting an in-progress hook. \* `timeout` {number} A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. This function is used to create a hook that runs after the current test finishes. ```js test('top level test', async (t) => { t.after((t) => t.diagnostic(`finished running ${t.name}`)); // Some relevant assertion here }); ``` ### `context.afterEach([fn][, options])` \* `fn` {Function|AsyncFunction} The hook function. The first argument to this function is a [`TestContext`][] object. If the hook uses callbacks, the callback function is passed as the second argument. \*\*Default:\*\* A no-op function. \* `options` {Object} Configuration options for the hook. The following properties are supported: \* `signal` {AbortSignal} Allows aborting an in-progress hook. \* `timeout` {number} A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. This function is used to create a hook running after each subtest of the current test. ```js test('top level test', async (t) => { t.afterEach((t) => t.diagnostic(`finished running ${t.name}`)); await t.test( 'This is a subtest', (t) => { // Some relevant assertion here }, ); }); ``` ### `context.assert` An object containing assertion methods bound to `context`. The top-level functions from the `node:assert` module are exposed here for the purpose of creating test plans. ```js test('test', (t) => { t.plan(1); t.assert.strictEqual(true, true); }); ``` #### `context.assert.fileSnapshot(value, path[, options])` \* `value` {any} A value to serialize to a string. If Node.js was started with the [`--test-update-snapshots`][] flag, the serialized value is written to `path`. Otherwise, the serialized value is compared to the contents of the existing | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.07534071803092957,
0.01327434927225113,
-0.07527373731136322,
0.1138768121600151,
0.052163321524858475,
0.004088700748980045,
0.016155516728758812,
-0.004182382952421904,
0.020077012479305267,
-0.02833801880478859,
-0.012545935809612274,
0.029128916561603546,
-0.055825501680374146,
0.017883913591504097,
0.011749185621738434,
0.003412386868149042,
0.04734506458044052,
-0.029586758464574814,
-0.07215314358472824,
-0.013043725863099098,
0.03263993188738823,
-0.02162245288491249,
0.08757780492305756,
0.015730196610093117,
-0.07094881683588028,
-0.09938246011734009,
-0.03324614092707634,
-0.06362934410572052,
0.048893801867961884,
0.05609457567334175,
-0.028151368722319603,
0.007007347885519266,
-0.05081811547279358,
-0.00895211286842823,
-0.02690357342362404,
0.02857906185090542,
0.01328935194760561,
-0.014645340852439404,
-0.010548045858740807,
0.04907090589404106,
0.04317391291260719,
-0.013975151814520359,
-0.059735920280218124,
-0.04459710791707039,
0.03509039059281349,
-0.02243897132575512,
0.019293740391731262,
-0.04958275705575943,
-0.08017601072788239,
0.024394579231739044,
0.025226715952157974,
0.046113960444927216,
-0.021943990141153336,
-0.03480887785553932,
0.0630689337849617,
-0.026298731565475464,
0.06962859630584717,
-0.011888048611581326,
-0.013541700318455696,
0.048465169966220856,
-0.01501427311450243,
-0.06824284046888351,
-0.06172768771648407,
0.014628092758357525,
0.010898265056312084,
0.07122097164392471,
-0.03070199489593506,
-0.005670799408107996,
0.08211403340101242,
-0.016246402636170387,
-0.012005554512143135,
0.03523216396570206,
0.05142689868807793,
0.0018092384561896324,
0.07433632016181946,
0.05547503009438515,
0.0226510688662529,
0.02192690037190914,
0.020424382761120796,
-0.09258195757865906,
-0.005158986430615187,
-0.0747026577591896,
-0.02192557603120804,
0.03238537162542343,
-0.007217051461338997,
0.09785918146371841,
0.08604826778173447,
-0.062243666499853134,
-0.016811378300189972,
0.017678240314126015,
-0.0228223018348217,
-0.020385276526212692,
-0.11702623218297958,
0.05877656862139702,
-0.01961280219256878,
-0.02655988745391369,
0.002855716273188591,
0.0026816928293555975,
0.023700736463069916,
-0.008619139902293682,
0.05552105978131294,
-0.0024912513326853514,
0.022656874731183052,
0.053614698350429535,
0.0034301248379051685,
-0.026412514969706535,
-0.007666158489882946,
-0.06925910711288452,
-0.00424641277641058,
0.03819887712597847,
0.06287278234958649,
0.013415924273431301,
0.07640012353658676,
-0.022199703380465508,
-0.021266257390379906,
0.0781351774930954,
-0.007799132261425257,
0.02726338431239128,
0.02334645390510559,
0.11478915810585022,
0.11691716313362122,
0.049044445157051086,
0.01832222193479538,
-0.08951966464519501,
0.07018443942070007,
0.01176618505269289,
-0.0024232016876339912,
4.2846545008861754e-33,
0.0389949195086956,
-0.08985818922519684,
-0.012055356986820698,
0.09146853536367416,
0.021336985751986504,
0.005452821962535381,
0.05143376439809799,
0.021177858114242554,
-0.023499254137277603,
0.055922266095876694,
0.009173265658318996,
-0.023037448525428772,
-0.006578264757990837,
-0.013563359156250954,
0.06776071339845657,
-0.005512104369699955,
-0.0021076456177979708,
-0.08086074143648148,
0.005179422441869974,
0.07050566375255585,
0.04509567469358444,
-0.02883237786591053,
-0.06626810133457184,
-0.09330017119646072,
-0.03145795315504074,
0.002245640615001321,
-0.02971516363322735,
0.03283200412988663,
-0.08244875073432922,
0.0320226214826107,
-0.05498873069882393,
0.012623258866369724,
0.00667123356834054,
0.06572882831096649,
-0.044668182730674744,
-0.05160290375351906,
-0.06048436090350151,
0.008572599850594997,
-0.10748731344938278,
-0.02036825567483902,
0.01072188001126051,
0.024915488436818123,
-0.09691189229488373,
-0.038012661039829254,
-0.038912929594516754,
-0.18027788400650024,
-0.04620591551065445,
0.0637594610452652,
0.09209839254617691,
-0.0030784280970692635,
0.06482328474521637,
0.11012081056833267,
0.06451805680990219,
-0.07655312865972519,
0.09028748422861099,
0.07066534459590912,
-0.0055888039059937,
-0.04658898338675499,
-0.024731982499361038,
0.04468667879700661,
-0.00805957056581974,
-0.07061801850795746,
-0.006499574054032564,
0.11935386806726456,
-0.0518580861389637,
0.012700719758868217,
0.023592378944158554,
-0.0938858613371849,
-0.027150647714734077,
-0.009312322363257408,
-0.03196853771805763,
0.006907195318490267,
-0.14430204033851624,
0.028990203514695168,
0.019365448504686356,
-0.008464721031486988,
-0.011729204095900059,
0.060838326811790466,
0.026867398992180824,
-0.06609318405389786,
0.1253483146429062,
-0.04247003793716431,
0.00637603597715497,
0.01805928535759449,
-0.05730143189430237,
-0.002713716821745038,
-0.06245110183954239,
-0.13933861255645752,
0.024790314957499504,
-0.09270816296339035,
0.02472509816288948,
-0.052060116082429886,
0.014663081616163254,
-0.09076852351427078,
0.0021006325259804726,
-6.188845513964876e-33,
0.08423366397619247,
-0.05624110624194145,
-0.07624465972185135,
-0.002875259146094322,
0.024935076013207436,
-0.0532492995262146,
0.044190917164087296,
-0.019261233508586884,
-0.03892521932721138,
0.033744264394044876,
0.016390783712267876,
-0.03647038713097572,
-0.016822336241602898,
0.03752116858959198,
0.001714919926598668,
0.010336605831980705,
-0.06286108493804932,
-0.09903810918331146,
0.06308060884475708,
-0.007943738251924515,
0.052758995443582535,
-0.06691127270460129,
0.0997103601694107,
-0.07195109874010086,
-0.06420738250017166,
-0.028128884732723236,
-0.02350967936217785,
0.015848537907004356,
0.06607713550329208,
-0.04723675921559334,
-0.00939340703189373,
0.04184776172041893,
-0.012348689138889313,
0.09319896996021271,
0.020853452384471893,
-0.008181932382285595,
0.10422264039516449,
0.02064189314842224,
-0.016214895993471146,
-0.0038209445774555206,
0.12132269144058228,
0.11390252411365509,
0.03300387039780617,
-0.023190589621663094,
-0.004098913166671991,
0.07056527584791183,
0.02316754125058651,
-0.012300688773393631,
-0.05625301972031593,
-0.03622950613498688,
-0.04748258367180824,
-0.05606449395418167,
0.0204135961830616,
0.042669568210840225,
-0.06897293776273727,
0.00898692011833191,
0.027773266658186913,
-0.05454511195421219,
-0.03661377727985382,
0.08476400375366211,
0.07508919388055801,
-0.07849414646625519,
-0.01642964780330658,
0.0628458634018898,
0.018438806757330894,
0.05316837131977081,
-0.007297269534319639,
0.018515726551413536,
0.03360802307724953,
0.021701108664274216,
0.03478199243545532,
-0.037381574511528015,
-0.07347997277975082,
-0.006016859319061041,
-0.013852132484316826,
0.05740603059530258,
-0.016356967389583588,
-0.11790531128644943,
0.025817129760980606,
0.022938910871744156,
-0.0421358123421669,
-0.08184917271137238,
-0.02421204373240471,
0.05188274011015892,
0.018199680373072624,
0.03562314435839653,
-0.03243891894817352,
0.13846270740032196,
0.055968981236219406,
-0.016240321099758148,
-0.03792407736182213,
0.018668323755264282,
-0.0994272232055664,
-0.007446035277098417,
-0.0008407657733187079,
-6.323079304593193e-8,
-0.07585620135068893,
0.016789106652140617,
-0.07958819717168808,
0.04230479896068573,
-0.035045865923166275,
-0.025372814387083054,
-0.02800525166094303,
-0.04035499691963196,
-0.01608746312558651,
-0.0005274860886856914,
-0.03319086506962776,
0.03912419080734253,
0.053049515932798386,
0.005517441779375076,
-0.037478458136320114,
-0.04459160938858986,
-0.019991831853985786,
0.01925010234117508,
0.004068605601787567,
-0.01601540856063366,
-0.02702621929347515,
0.030921809375286102,
-0.010281112045049667,
0.015192084014415741,
-0.018525300547480583,
0.0248090922832489,
0.08288417756557465,
0.10017209500074387,
0.03825289011001587,
-0.005396151915192604,
-0.029453415423631668,
0.01508033275604248,
-0.03338474780321121,
-0.019587598741054535,
-0.11866068840026855,
0.06818041205406189,
0.046308424323797226,
-0.03674374893307686,
0.07254769653081894,
0.04205729067325592,
0.05838579684495926,
-0.03470536321401596,
-0.05783694609999657,
0.010504218749701977,
0.004029285628348589,
-0.05098443850874901,
-0.06542869657278061,
-0.0026817230973392725,
0.006637039128690958,
-0.003840566612780094,
-0.07652707397937775,
0.041479628533124924,
-0.016542913392186165,
0.007324980106204748,
0.03306444734334946,
-0.01786256954073906,
0.005014360416680574,
-0.010664205066859722,
-0.03627847880125046,
-0.007439416367560625,
0.02352968417108059,
-0.023497864603996277,
0.05778256058692932,
-0.061149898916482925
] | 0.13026 |
test('test', (t) => { t.plan(1); t.assert.strictEqual(true, true); }); ``` #### `context.assert.fileSnapshot(value, path[, options])` \* `value` {any} A value to serialize to a string. If Node.js was started with the [`--test-update-snapshots`][] flag, the serialized value is written to `path`. Otherwise, the serialized value is compared to the contents of the existing snapshot file. \* `path` {string} The file where the serialized `value` is written. \* `options` {Object} Optional configuration options. The following properties are supported: \* `serializers` {Array} An array of synchronous functions used to serialize `value` into a string. `value` is passed as the only argument to the first serializer function. The return value of each serializer is passed as input to the next serializer. Once all serializers have run, the resulting value is coerced to a string. \*\*Default:\*\* If no serializers are provided, the test runner's default serializers are used. This function serializes `value` and writes it to the file specified by `path`. ```js test('snapshot test with default serialization', (t) => { t.assert.fileSnapshot({ value1: 1, value2: 2 }, './snapshots/snapshot.json'); }); ``` This function differs from `context.assert.snapshot()` in the following ways: \* The snapshot file path is explicitly provided by the user. \* Each snapshot file is limited to a single snapshot value. \* No additional escaping is performed by the test runner. These differences allow snapshot files to better support features such as syntax highlighting. #### `context.assert.snapshot(value[, options])` \* `value` {any} A value to serialize to a string. If Node.js was started with the [`--test-update-snapshots`][] flag, the serialized value is written to the snapshot file. Otherwise, the serialized value is compared to the corresponding value in the existing snapshot file. \* `options` {Object} Optional configuration options. The following properties are supported: \* `serializers` {Array} An array of synchronous functions used to serialize `value` into a string. `value` is passed as the only argument to the first serializer function. The return value of each serializer is passed as input to the next serializer. Once all serializers have run, the resulting value is coerced to a string. \*\*Default:\*\* If no serializers are provided, the test runner's default serializers are used. This function implements assertions for snapshot testing. ```js test('snapshot test with default serialization', (t) => { t.assert.snapshot({ value1: 1, value2: 2 }); }); test('snapshot test with custom serialization', (t) => { t.assert.snapshot({ value3: 3, value4: 4 }, { serializers: [(value) => JSON.stringify(value)], }); }); ``` ### `context.diagnostic(message)` \* `message` {string} Message to be reported. This function is used to write diagnostics to the output. Any diagnostic information is included at the end of the test's results. This function does not return a value. ```js test('top level test', (t) => { t.diagnostic('A diagnostic message'); }); ``` ### `context.filePath` The absolute path of the test file that created the current test. If a test file imports additional modules that generate tests, the imported tests will return the path of the root test file. ### `context.fullName` The name of the test and each of its ancestors, separated by `>`. ### `context.name` The name of the test. ### `context.passed` \* Type: {boolean} `false` before the test is executed, e.g. in a `beforeEach` hook. Indicated whether the test succeeded. ### `context.error` \* Type: {Error|null} The failure reason for the test/case; wrapped and available via `context.error.cause`. ### `context.attempt` \* Type: {number} Number of times the test has been attempted. ### `context.plan(count[,options])` \* `count` {number} The number of assertions and subtests that are expected to run. \* `options` {Object} Additional options for the plan. \* `wait` {boolean|number} The wait time for the plan: \* If `true`, the plan waits indefinitely for all assertions and subtests to run. \* | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.041860535740852356,
0.09952278435230255,
0.002145243575796485,
0.049105461686849594,
0.022581465542316437,
-0.05557827651500702,
-0.07135125249624252,
0.028783446177840233,
0.0045160348527133465,
0.011201758868992329,
-0.009243401698768139,
0.0705583244562149,
0.0028641419485211372,
-0.021539075300097466,
0.03318093717098236,
-0.05389627814292908,
-0.053611207753419876,
0.01903550885617733,
-0.014216464012861252,
0.00969903264194727,
-0.010251021943986416,
-0.028684182092547417,
0.00033733490272425115,
-0.03115508332848549,
0.06126797944307327,
0.017664583399891853,
-0.01420322060585022,
0.016834232956171036,
0.02257666178047657,
0.012057268992066383,
0.058456309139728546,
0.05013290047645569,
-0.03560887649655342,
0.011193359270691872,
0.05443655326962471,
0.09534598886966705,
0.01785319671034813,
-0.07359898090362549,
-0.021295949816703796,
0.0020312219858169556,
0.08585388213396072,
0.03652849420905113,
-0.1171707883477211,
-0.045955508947372437,
-0.023609519004821777,
-0.06327743083238602,
-0.006972009316086769,
0.009016243740916252,
-0.11213099956512451,
-0.008737511932849884,
-0.0451691597700119,
-0.014106612652540207,
-0.048584409058094025,
0.027291566133499146,
-0.022041548043489456,
0.02653568610548973,
0.017832281067967415,
0.006017227657139301,
0.057152993977069855,
0.02772824652493,
-0.018439020961523056,
-0.03725773096084595,
0.0005745352245867252,
-0.01643168367445469,
0.08531878888607025,
0.050053611397743225,
0.02516443282365799,
-0.0030680675990879536,
0.030155042186379433,
0.00028391837258823216,
0.034516070038080215,
0.04140905290842056,
-0.029178084805607796,
-0.002135213930159807,
-0.03620146960020065,
0.017046820372343063,
0.0016852114349603653,
0.017170468345284462,
-0.020125580951571465,
0.0018123142654076219,
0.007196062710136175,
-0.16175413131713867,
-0.037827879190444946,
0.0020516738295555115,
-0.05414878949522972,
0.10835065692663193,
-0.029215747490525246,
0.01249055564403534,
0.0032289542723447084,
0.05145466327667236,
-0.06265837699174881,
-0.07525046914815903,
-0.03699338436126709,
0.01774606667459011,
0.0003324442368466407,
0.03157825395464897,
-0.03158269822597504,
0.042539212852716446,
0.04523028805851936,
-0.04106849804520607,
-0.0009344238205812871,
-0.01888359524309635,
0.09559233486652374,
-0.056837741285562515,
0.035397276282310486,
-0.012760506011545658,
0.037680454552173615,
-0.1227678656578064,
0.00004776021887664683,
0.04613259807229042,
0.031458817422389984,
0.0923936739563942,
0.0018113568658009171,
-0.036682821810245514,
-0.003392654936760664,
-0.008441997691988945,
-0.0042029437609016895,
0.015433404594659805,
-0.02352401241660118,
0.10576680302619934,
0.12057837098836899,
0.007692007813602686,
-0.004677644465118647,
0.026498906314373016,
0.0073999930173158646,
-0.06285843253135681,
0.03600386157631874,
2.423264890159845e-33,
0.009743363596498966,
-0.020745214074850082,
0.05117176100611687,
0.06026230379939079,
0.0337049700319767,
-0.01046167965978384,
0.029636744409799576,
-0.006846992298960686,
-0.03757581487298012,
-0.008738832548260689,
-0.0648055374622345,
0.04561305791139603,
-0.008925664238631725,
0.034842681139707565,
0.01057934109121561,
-0.010593332350254059,
-0.049052320420742035,
-0.024017643183469772,
0.04256618022918701,
0.09031356871128082,
0.04969772323966026,
0.03192734718322754,
-0.04403534159064293,
-0.02280540205538273,
-0.03129982948303223,
-0.0590677447617054,
0.036858443170785904,
-0.018299512565135956,
-0.045858193188905716,
-0.023921063169836998,
-0.03542788699269295,
0.029046066105365753,
0.05400371551513672,
0.09085528552532196,
0.06195923686027527,
0.013391194865107536,
0.00505959615111351,
-0.009932775981724262,
-0.13755767047405243,
0.021492524072527885,
0.02904246561229229,
0.02967202663421631,
-0.10778459906578064,
0.07807383686304092,
-0.03300586715340614,
-0.14577768743038177,
-0.051977258175611496,
0.001526951207779348,
0.0859047919511795,
0.004016817081719637,
0.025485271587967873,
0.06182806193828583,
0.026098959147930145,
-0.08980081975460052,
-0.015112824738025665,
-0.03511926904320717,
0.03613794967532158,
-0.11928856372833252,
-0.011305087246000767,
0.021900972351431847,
0.06606480479240417,
-0.030451644212007523,
0.016849631443619728,
0.01989654265344143,
0.010115288197994232,
0.09001921862363815,
-0.007562371902167797,
-0.05055822804570198,
0.04972822964191437,
0.02587142586708069,
-0.04386650025844574,
0.018953539431095123,
-0.090672068297863,
-0.01668570376932621,
0.01738232932984829,
-0.01887473277747631,
-0.0554501935839653,
0.06261049211025238,
-0.007158045191317797,
-0.032341402024030685,
-0.0030775810591876507,
-0.04084143787622452,
-0.09325855225324631,
0.0729915201663971,
0.021783441305160522,
-0.0019036262528970838,
-0.05602240934967995,
-0.020609579980373383,
0.016455549746751785,
-0.06747982650995255,
0.09979094564914703,
-0.019357861950993538,
-0.10806798189878464,
-0.05655709281563759,
0.0198103878647089,
-4.846044521557991e-33,
0.05182349681854248,
0.01678537391126156,
-0.06219680979847908,
0.15275397896766663,
-0.020568445324897766,
-0.03633299842476845,
0.02708304487168789,
0.0163450725376606,
-0.051645636558532715,
-0.007218821905553341,
-0.08354413509368896,
-0.012323244474828243,
-0.05147196352481842,
-0.021399065852165222,
-0.02779657021164894,
-0.012498518452048302,
-0.039557311683893204,
-0.14398114383220673,
0.022093668580055237,
-0.082438625395298,
0.024409310892224312,
-0.026204383000731468,
0.10925768315792084,
0.07660021632909775,
-0.041112855076789856,
-0.0272678229957819,
-0.006390705704689026,
-0.028812436386942863,
0.04532536864280701,
-0.0767558366060257,
0.012745648622512817,
0.04376884549856186,
0.02492649294435978,
0.031284578144550323,
0.03537602722644806,
0.0031437226571142673,
0.0766960009932518,
0.07581634819507599,
0.06603377312421799,
0.04977623000741005,
-0.0006665285909548402,
0.01664033718407154,
-0.04411661997437477,
0.057004548609256744,
0.02709248475730419,
0.06642689555883408,
0.042715854942798615,
0.000019639204765553586,
0.03317153826355934,
-0.07303643226623535,
0.07947802543640137,
0.004160982556641102,
-0.03387903422117233,
0.06809715181589127,
0.06018463894724846,
-0.10875817388296127,
-0.035106558352708817,
-0.07431373000144958,
0.005789237096905708,
0.05007248371839523,
0.041550543159246445,
-0.0024511234369128942,
-0.035289980471134186,
-0.00958999339491129,
-0.02761983871459961,
-0.03804108127951622,
-0.003160935128107667,
-0.07332047820091248,
-0.0414634570479393,
-0.044812705367803574,
-0.0033440690021961927,
-0.07263249158859253,
0.04802270606160164,
0.00926198624074459,
0.01585136540234089,
-0.05727405473589897,
-0.022112684324383736,
-0.09260332584381104,
0.057051993906497955,
0.012112533673644066,
-0.07195122539997101,
0.03210313618183136,
-0.06377509236335754,
0.08823781460523605,
-0.011834573931992054,
0.005764754954725504,
0.005721911787986755,
0.08644980937242508,
0.012649686075747013,
0.016591684892773628,
0.016072982922196388,
0.06345373392105103,
-0.12632650136947632,
-0.058714546263217926,
-0.0035563174169510603,
-6.034231603280205e-8,
-0.09174305200576782,
0.0062285009771585464,
-0.12891241908073425,
0.04737190902233124,
-0.048310719430446625,
0.003375452710315585,
0.025498555973172188,
-0.010280584916472435,
0.1227768138051033,
-0.034400422126054764,
0.03582416847348213,
-0.028509799391031265,
-0.007791469339281321,
-0.05743667483329773,
0.0056875478476285934,
-0.022739790380001068,
0.05207698419690132,
-0.0036657885648310184,
-0.003392928745597601,
0.0768299326300621,
0.004189433064311743,
0.007440380752086639,
-0.0683862492442131,
-0.008383152075111866,
0.035433944314718246,
0.021262114867568016,
0.007618870586156845,
0.0630742609500885,
0.012494136579334736,
-0.013860223814845085,
-0.03060026839375496,
-0.008777493610978127,
0.07124898582696915,
-0.029033347964286804,
-0.13844555616378784,
0.06291032582521439,
0.05738500878214836,
0.061702195554971695,
0.08034634590148926,
0.015393084846436977,
-0.018681732937693596,
0.019227851182222366,
-0.08329717814922333,
-0.008995886892080307,
-0.11954110860824585,
-0.04590985178947449,
-0.0119966771453619,
0.0518864281475544,
-0.053077634423971176,
-0.04243430867791176,
0.03261437267065048,
-0.04736689478158951,
-0.0009944470366463065,
0.029135895892977715,
-0.04623400792479515,
-0.052901770919561386,
0.015943478792905807,
-0.08199882507324219,
0.05910434201359749,
-0.00797929149121046,
0.12981952726840973,
-0.06211072951555252,
-0.014876823872327805,
-0.0006190393469296396
] | 0.051786 |
been attempted. ### `context.plan(count[,options])` \* `count` {number} The number of assertions and subtests that are expected to run. \* `options` {Object} Additional options for the plan. \* `wait` {boolean|number} The wait time for the plan: \* If `true`, the plan waits indefinitely for all assertions and subtests to run. \* If `false`, the plan performs an immediate check after the test function completes, without waiting for any pending assertions or subtests. Any assertions or subtests that complete after this check will not be counted towards the plan. \* If a number, it specifies the maximum wait time in milliseconds before timing out while waiting for expected assertions and subtests to be matched. If the timeout is reached, the test will fail. \*\*Default:\*\* `false`. This function is used to set the number of assertions and subtests that are expected to run within the test. If the number of assertions and subtests that run does not match the expected count, the test will fail. > Note: To make sure assertions are tracked, `t.assert` must be used instead of `assert` directly. ```js test('top level test', (t) => { t.plan(2); t.assert.ok('some relevant assertion here'); t.test('subtest', () => {}); }); ``` When working with asynchronous code, the `plan` function can be used to ensure that the correct number of assertions are run: ```js test('planning with streams', (t, done) => { function\* generate() { yield 'a'; yield 'b'; yield 'c'; } const expected = ['a', 'b', 'c']; t.plan(expected.length); const stream = Readable.from(generate()); stream.on('data', (chunk) => { t.assert.strictEqual(chunk, expected.shift()); }); stream.on('end', () => { done(); }); }); ``` When using the `wait` option, you can control how long the test will wait for the expected assertions. For example, setting a maximum wait time ensures that the test will wait for asynchronous assertions to complete within the specified timeframe: ```js test('plan with wait: 2000 waits for async assertions', (t) => { t.plan(1, { wait: 2000 }); // Waits for up to 2 seconds for the assertion to complete. const asyncActivity = () => { setTimeout(() => { t.assert.ok(true, 'Async assertion completed within the wait time'); }, 1000); // Completes after 1 second, within the 2-second wait time. }; asyncActivity(); // The test will pass because the assertion is completed in time. }); ``` Note: If a `wait` timeout is specified, it begins counting down only after the test function finishes executing. ### `context.runOnly(shouldRunOnlyTests)` \* `shouldRunOnlyTests` {boolean} Whether or not to run `only` tests. If `shouldRunOnlyTests` is truthy, the test context will only run tests that have the `only` option set. Otherwise, all tests are run. If Node.js was not started with the [`--test-only`][] command-line option, this function is a no-op. ```js test('top level test', (t) => { // The test context can be set to run subtests with the 'only' option. t.runOnly(true); return Promise.all([ t.test('this subtest is now skipped'), t.test('this subtest is run', { only: true }), ]); }); ``` ### `context.signal` \* Type: {AbortSignal} Can be used to abort test subtasks when the test has been aborted. ```js test('top level test', async (t) => { await fetch('some/uri', { signal: t.signal }); }); ``` ### `context.skip([message])` \* `message` {string} Optional skip message. This function causes the test's output to indicate the test as skipped. If `message` is provided, it is included in the output. Calling `skip()` does not terminate execution of the test function. This function does not return a value. ```js test('top level test', (t) => { // Make sure to return here as well if the test contains additional logic. t.skip('this is skipped'); }); ``` ### `context.todo([message])` \* `message` {string} Optional `TODO` message. This function adds | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.09980763494968414,
0.04267478361725807,
-0.019440600648522377,
0.09315406531095505,
0.02925410307943821,
-0.04413576051592827,
-0.0029819367919117212,
-0.009703397750854492,
0.011663359589874744,
-0.008418676443397999,
-0.013484184630215168,
-0.052439212799072266,
0.022683946415781975,
0.009164594113826752,
0.032235197722911835,
-0.010804053395986557,
-0.053907059133052826,
-0.052587445825338364,
0.00007983390241861343,
0.0014312153216451406,
0.020023398101329803,
0.0073144324123859406,
-0.0031687794253230095,
-0.033285271376371384,
-0.01580454781651497,
-0.02318394184112549,
-0.03314553201198578,
-0.03749560937285423,
0.07606057077646255,
0.028877543285489082,
-0.00047984099364839494,
0.049908705055713654,
0.018892841413617134,
-0.0038130616303533316,
0.08729816973209381,
0.040481239557266235,
-0.022596992552280426,
-0.03258122131228447,
-0.04193403571844101,
0.045153770595788956,
-0.00822044350206852,
-0.03466232866048813,
-0.05048518627882004,
-0.023763475939631462,
0.007159480359405279,
0.030876869335770607,
-0.04186834767460823,
0.01335868053138256,
-0.09097791463136673,
-0.005424856208264828,
-0.04219936579465866,
0.03256233409047127,
-0.027529437094926834,
-0.046174727380275726,
0.04736433923244476,
0.010624473914504051,
0.07021202147006989,
-0.047487419098615646,
0.0077990153804421425,
0.039930280297994614,
-0.04033379629254341,
-0.11490746587514877,
-0.0369010753929615,
0.0008395041804760695,
0.013941891491413116,
0.08509422838687897,
-0.024264002218842506,
-0.0007161670946516097,
0.06663098931312561,
0.1028553918004036,
-0.05312691628932953,
0.052696339786052704,
-0.04658631235361099,
0.08751945197582245,
0.047722265124320984,
0.06000892072916031,
0.046069275587797165,
-0.04054369777441025,
0.07782521843910217,
-0.1262831687927246,
-0.07274749875068665,
-0.0730024129152298,
-0.046198662370443344,
0.03352021053433418,
0.028127608820796013,
0.023526132106781006,
0.07897038757801056,
0.012214569374918938,
0.010939295403659344,
-0.013529246672987938,
0.047486189752817154,
-0.045268911868333817,
-0.05233669653534889,
0.04292985424399376,
0.019035832956433296,
0.04628486558794975,
-0.04419856518507004,
-0.08762314915657043,
-0.004778834525495768,
-0.0038566223811358213,
-0.0027651728596538305,
-0.002453689929097891,
0.0826311782002449,
-0.07433703541755676,
0.002565896138548851,
-0.029323602095246315,
0.09663711488246918,
-0.052783310413360596,
0.03492813557386398,
-0.03034094162285328,
0.0644993856549263,
-0.011769412085413933,
0.10716801136732101,
-0.007627399638295174,
-0.031633131206035614,
0.05080276355147362,
0.022962765768170357,
0.04406670853495598,
0.04983390122652054,
0.05525166541337967,
0.08514408767223358,
0.056731998920440674,
0.03452260419726372,
-0.08110272884368896,
0.0010312082013115287,
-0.003782490035519004,
0.0042164199985563755,
6.0456045478194725e-33,
-0.015119839459657669,
-0.09882985800504684,
0.017613481730222702,
0.06334558129310608,
0.012649605050683022,
-0.04464679956436157,
0.027067113667726517,
0.05670321732759476,
-0.0827210322022438,
0.10306434333324432,
-0.04032392427325249,
-0.008910917676985264,
-0.03411662578582764,
0.04760585352778435,
0.05582781881093979,
-0.05540544167160988,
0.06561660766601562,
-0.02544080838561058,
-0.04462803527712822,
0.028482697904109955,
0.10390254855155945,
-0.14511972665786743,
-0.03328552097082138,
-0.050308410078287125,
0.009088762104511261,
0.033759601414203644,
0.006977258250117302,
-0.04432469978928566,
-0.031007466837763786,
0.01378469355404377,
-0.0641704723238945,
0.02943744696676731,
-0.07608923316001892,
0.14240369200706482,
0.019064541906118393,
0.03355829045176506,
-0.01953010819852352,
-0.05093250423669815,
-0.013562312349677086,
-0.03682124242186546,
-0.1177930161356926,
-0.04787059128284454,
-0.03140877187252045,
0.018312033265829086,
-0.02931717038154602,
-0.1619383990764618,
-0.06749549508094788,
0.02160121686756611,
0.0830928161740303,
0.07742615044116974,
0.08128849416971207,
0.10615778714418411,
-0.025204025208950043,
-0.04594166949391365,
0.012321204878389835,
-0.03344046697020531,
-0.0407264307141304,
0.05169893801212311,
0.07790534943342209,
0.08794858306646347,
0.03567299246788025,
-0.03936239331960678,
-0.06941953301429749,
0.027656476944684982,
-0.03731854259967804,
0.09463729709386826,
-0.11761536449193954,
-0.11489073187112808,
0.06320112943649292,
-0.024774938821792603,
-0.0024725855328142643,
0.049040988087654114,
-0.024275721982121468,
0.009116741828620434,
-0.047751057893037796,
-0.03911972418427467,
0.03398118540644646,
0.06141442060470581,
-0.03745702654123306,
-0.022368410602211952,
0.09240899235010147,
-0.02098945528268814,
-0.045600976794958115,
-0.03899357467889786,
0.020538272336125374,
-0.004940037149935961,
0.012554376386106014,
-0.057874906808137894,
-0.04633522406220436,
-0.09400702267885208,
0.011620980687439442,
-0.006471904460340738,
-0.02410801500082016,
-0.049685802310705185,
-0.055237285792827606,
-7.131774184948728e-33,
0.06331449747085571,
0.016581537202000618,
-0.002043966669589281,
0.03970448300242424,
0.05036268010735512,
-0.09397578984498978,
0.07438084483146667,
0.0016398463631048799,
-0.039550937712192535,
-0.04981661215424538,
0.0026606281753629446,
-0.012508433312177658,
0.011655381880700588,
-0.019190043210983276,
-0.0010846816003322601,
0.0008068738388828933,
-0.012187132611870766,
-0.10596181452274323,
0.005059042014181614,
0.057964205741882324,
0.04436570033431053,
-0.0006091974792070687,
-0.0890725627541542,
0.015490209683775902,
-0.08527356386184692,
0.05022085830569267,
-0.019414085894823074,
-0.028497323393821716,
0.04674292728304863,
0.012138397432863712,
0.04612915217876434,
0.032353613525629044,
-0.052308231592178345,
0.019475610926747322,
0.09270191937685013,
-0.08892760425806046,
0.12642902135849,
0.06551051884889603,
-0.0209011510014534,
0.014279523864388466,
0.1269744336605072,
-0.00007555587217211723,
0.0569719523191452,
0.0007046562968753278,
0.014386381022632122,
0.08298550546169281,
0.07364228367805481,
-0.03889106959104538,
-0.06753028184175491,
-0.04802226647734642,
-0.015528293326497078,
-0.007401036564260721,
-0.018944382667541504,
0.08056921511888504,
-0.01524475309997797,
-0.03662645444273949,
-0.045837242156267166,
-0.0918102040886879,
-0.019969571381807327,
0.028687894344329834,
-0.04119154438376427,
-0.0031177708879113197,
0.07259321957826614,
0.02456764504313469,
0.03398182988166809,
0.052656203508377075,
-0.062440622597932816,
-0.01387493871152401,
0.04672570526599884,
-0.03186121582984924,
0.0031338876578956842,
-0.012565955519676208,
-0.10398201644420624,
-0.02199934795498848,
-0.0035713769029825926,
0.026621311902999878,
-0.021306004375219345,
-0.054058752954006195,
0.02794816344976425,
0.06330956518650055,
-0.03561614826321602,
-0.008886469528079033,
-0.08762883394956589,
0.07045692205429077,
-0.04229653999209404,
0.0466436967253685,
0.019755717366933823,
0.0932442843914032,
-0.021700184792280197,
0.04814312607049942,
-0.06378402560949326,
0.036316681653261185,
-0.002739350078627467,
0.018096746876835823,
0.009241178631782532,
-6.044310651986962e-8,
-0.041229985654354095,
-0.020398221909999847,
0.03305847942829132,
-0.026244668290019035,
0.029413703829050064,
0.033597737550735474,
-0.014150728471577168,
-0.11501355469226837,
-0.01856764405965805,
-0.006754900794476271,
0.02328306809067726,
0.03302924335002899,
-0.011275687254965305,
-0.03230965510010719,
-0.04681095853447914,
-0.023594612255692482,
0.010277295485138893,
0.001869509113021195,
0.024979248642921448,
-0.012403145432472229,
-0.014655398204922676,
-0.0058997576124966145,
-0.023022031411528587,
0.02987130917608738,
-0.03440799191594124,
0.028283433988690376,
0.04616573080420494,
0.059480778872966766,
0.001137031358666718,
-0.040712546557188034,
-0.03132782131433487,
0.04651626944541931,
-0.03984310105443001,
0.0012090523960068822,
-0.045128658413887024,
0.08741271495819092,
0.006104045547544956,
0.027583781629800797,
0.05884242057800293,
0.022580018267035484,
-0.02617788501083851,
-0.002731854794546962,
-0.07806037366390228,
-0.0029025415424257517,
-0.023054620251059532,
-0.06679625064134598,
-0.08267699182033539,
-0.06914093345403671,
-0.05402662605047226,
-0.10545816272497177,
-0.0393809899687767,
0.02258712612092495,
-0.04182594269514084,
0.07552944123744965,
-0.011249488219618797,
0.0321928933262825,
0.019962815567851067,
-0.08834417164325714,
-0.013959753327071667,
0.05112345889210701,
0.05588304251432419,
-0.01782381907105446,
0.02843398042023182,
-0.05201055109500885
] | 0.142567 |
terminate execution of the test function. This function does not return a value. ```js test('top level test', (t) => { // Make sure to return here as well if the test contains additional logic. t.skip('this is skipped'); }); ``` ### `context.todo([message])` \* `message` {string} Optional `TODO` message. This function adds a `TODO` directive to the test's output. If `message` is provided, it is included in the output. Calling `todo()` does not terminate execution of the test function. This function does not return a value. ```js test('top level test', (t) => { // This test is marked as `TODO` t.todo('this is a todo'); }); ``` ### `context.test([name][, options][, fn])` \* `name` {string} The name of the subtest, which is displayed when reporting test results. \*\*Default:\*\* The `name` property of `fn`, or `''` if `fn` does not have a name. \* `options` {Object} Configuration options for the subtest. The following properties are supported: \* `concurrency` {number|boolean|null} If a number is provided, then that many tests would run asynchronously (they are still managed by the single-threaded event loop). If `true`, it would run all subtests in parallel. If `false`, it would only run one test at a time. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `null`. \* `only` {boolean} If truthy, and the test context is configured to run `only` tests, then this test will be run. Otherwise, the test is skipped. \*\*Default:\*\* `false`. \* `signal` {AbortSignal} Allows aborting an in-progress test. \* `skip` {boolean|string} If truthy, the test is skipped. If a string is provided, that string is displayed in the test results as the reason for skipping the test. \*\*Default:\*\* `false`. \* `todo` {boolean|string} If truthy, the test marked as `TODO`. If a string is provided, that string is displayed in the test results as the reason why the test is `TODO`. \*\*Default:\*\* `false`. \* `timeout` {number} A number of milliseconds the test will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. \* `plan` {number} The number of assertions and subtests expected to be run in the test. If the number of assertions run in the test does not match the number specified in the plan, the test will fail. \*\*Default:\*\* `undefined`. \* `fn` {Function|AsyncFunction} The function under test. The first argument to this function is a [`TestContext`][] object. If the test uses callbacks, the callback function is passed as the second argument. \*\*Default:\*\* A no-op function. \* Returns: {Promise} Fulfilled with `undefined` once the test completes. This function is used to create subtests under the current test. This function behaves in the same fashion as the top level [`test()`][] function. ```js test('top level test', async (t) => { await t.test( 'This is a subtest', { only: false, skip: false, concurrency: 1, todo: false, plan: 1 }, (t) => { t.assert.ok('some relevant assertion here'); }, ); }); ``` ### `context.waitFor(condition[, options])` \* `condition` {Function|AsyncFunction} An assertion function that is invoked periodically until it completes successfully or the defined polling timeout elapses. Successful completion is defined as not throwing or rejecting. This function does not accept any arguments, and is allowed to return any value. \* `options` {Object} An optional configuration object for the polling operation. The following properties are supported: \* `interval` {number} The number of milliseconds to wait after an unsuccessful invocation of `condition` before trying again. \*\*Default:\*\* `50`. \* `timeout` {number} The poll timeout in milliseconds. If `condition` has not succeeded by the time this elapses, an error occurs. \*\*Default:\*\* `1000`. \* Returns: {Promise} Fulfilled with the value returned by `condition`. This method polls a `condition` function until that function either | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.038221873342990875,
0.07987402379512787,
0.06238091364502907,
0.06401970982551575,
0.08461810648441315,
-0.0881313681602478,
0.03215930983424187,
0.018342100083827972,
0.010138417594134808,
-0.019374456256628036,
0.013013003394007683,
-0.006595151498913765,
-0.04113755375146866,
0.02689593844115734,
0.056033775210380554,
-0.016016000881791115,
0.017249293625354767,
-0.010066972114145756,
-0.011403115466237068,
-0.1080300435423851,
0.04632651433348656,
0.04998520016670227,
0.07507812976837158,
0.03929877281188965,
-0.02149711363017559,
-0.017277948558330536,
-0.026738302782177925,
-0.03688053414225578,
0.004814580082893372,
0.024083808064460754,
0.06324736773967743,
-0.009008506312966347,
-0.02832106687128544,
-0.004243746399879456,
-0.04309845343232155,
0.08716904371976852,
-0.02452990971505642,
-0.0478287898004055,
0.02291911467909813,
-0.012956562452018261,
-0.030205154791474342,
0.026602575555443764,
-0.11192646622657776,
-0.04607224464416504,
0.11538407951593399,
-0.037333328276872635,
-0.06894371658563614,
0.012881072238087654,
-0.06912177801132202,
0.0006404509767889977,
0.017614319920539856,
0.019381826743483543,
-0.036246247589588165,
0.004418560769408941,
0.020767826586961746,
0.0386764258146286,
0.03661921247839928,
-0.03086637146770954,
0.01244402676820755,
0.018993539735674858,
-0.05490673705935478,
-0.09108149260282516,
-0.04311666265130043,
-0.008297988213598728,
0.12674015760421753,
-0.031624238938093185,
-0.007890814915299416,
-0.014354896731674671,
-0.025636380538344383,
0.055103104561567307,
-0.006424190942198038,
-0.015677835792303085,
0.06240483745932579,
0.03676658496260643,
0.03564231097698212,
0.02000194974243641,
-0.023835517466068268,
0.01357624027878046,
-0.009447405114769936,
0.007037859410047531,
-0.06790640950202942,
-0.11543991416692734,
-0.01758393459022045,
0.015080997720360756,
-0.00511546153575182,
0.05998419225215912,
0.03803308680653572,
0.02692512236535549,
0.009552046656608582,
-0.005814600270241499,
0.004767577163875103,
-0.04426128789782524,
-0.09952161461114883,
0.07204245775938034,
0.03371221199631691,
0.010651820339262486,
0.0059513612650334835,
-0.0013153995387256145,
-0.023468928411602974,
0.018365584313869476,
0.05050937458872795,
-0.02794867381453514,
0.03867068886756897,
-0.04843582957983017,
0.024262188002467155,
-0.02052295207977295,
-0.026962921023368835,
-0.05540404096245766,
0.02844507247209549,
-0.012445654720067978,
-0.031102599576115608,
0.018354879692196846,
0.07094764709472656,
0.018398966640233994,
-0.047120921313762665,
-0.05021539330482483,
0.05191224813461304,
0.04575926437973976,
-0.025480106472969055,
0.12173666059970856,
0.1335981786251068,
0.023969534784555435,
-0.01992436870932579,
-0.020402779802680016,
0.039817191660404205,
0.07600509375333786,
0.0691794753074646,
6.009345230706909e-34,
-0.03524790704250336,
-0.06999813765287399,
-0.008013671264052391,
0.00951515045017004,
0.049673765897750854,
0.025155745446681976,
-0.049692552536726,
0.06407329440116882,
-0.059692759066820145,
0.054692644625902176,
-0.01960902474820614,
-0.03915606439113617,
0.0026695160195231438,
-0.04287557303905487,
0.04911484941840172,
-0.0036067264154553413,
0.06967291980981827,
-0.06399454176425934,
-0.04937642067670822,
0.07463056594133377,
0.08152029663324356,
-0.039303116500377655,
-0.006148430984467268,
-0.016108978539705276,
-0.06888138502836227,
0.03594411164522171,
-0.01616632007062435,
-0.0403226837515831,
-0.1010853573679924,
-0.010436189360916615,
-0.09384611994028091,
0.014181180857121944,
-0.01798992045223713,
0.10067417472600937,
0.022506900131702423,
-0.030299915000796318,
-0.03360677883028984,
-0.0009946924401447177,
-0.11783583462238312,
-0.07820523530244827,
-0.02807970717549324,
-0.009147414937615395,
-0.061528198421001434,
0.044797059148550034,
-0.022484267130494118,
-0.1801755428314209,
-0.007157627958804369,
0.07536876201629639,
0.12817418575286865,
0.06049060821533203,
0.015800995752215385,
0.029303384944796562,
0.05568978190422058,
-0.06579555571079254,
0.0632515549659729,
0.06590629369020462,
0.021270591765642166,
-0.03648838773369789,
-0.03079143352806568,
-0.019187580794095993,
0.01434872206300497,
-0.08272942155599594,
-0.05889713764190674,
0.05346805602312088,
-0.09889914840459824,
-0.016444915905594826,
-0.03367244452238083,
-0.04443172737956047,
0.05203261598944664,
-0.0166540015488863,
0.009440729394555092,
0.029049912467598915,
-0.047597452998161316,
0.1326388418674469,
0.022126605734229088,
-0.007089630234986544,
-0.04683148115873337,
0.03238605335354805,
0.04973673075437546,
-0.04861488565802574,
0.14168618619441986,
-0.030222197994589806,
-0.027336014434695244,
0.013921345584094524,
0.1262420117855072,
0.025778518989682198,
-0.060591600835323334,
-0.08110027015209198,
-0.0024652087595313787,
-0.03421346843242645,
-0.024846848100423813,
0.0014662450412288308,
-0.045707326382398605,
-0.06028979644179344,
0.03251579403877258,
-2.6684063391711634e-33,
0.0599333755671978,
0.048738665878772736,
-0.0944133847951889,
0.030304869636893272,
-0.006157234776765108,
-0.07520200312137604,
0.042935144156217575,
-0.020458301529288292,
-0.02709057927131653,
0.024041088297963142,
0.02536400593817234,
-0.029740847647190094,
0.03669779747724533,
0.05734069272875786,
-0.03961363807320595,
0.09895160794258118,
-0.018814075738191605,
-0.09161660075187683,
0.004759857431054115,
-0.0896172970533371,
-0.019380545243620872,
0.038787033408880234,
0.04792708158493042,
-0.010858722031116486,
-0.1441025286912918,
-0.027915026992559433,
-0.035881176590919495,
0.00212731771171093,
0.04747657850384712,
0.02434770204126835,
0.025732051581144333,
0.05072488635778427,
0.01883593387901783,
0.06393007934093475,
0.09813889116048813,
-0.033612001687288284,
0.09262972325086594,
0.016961414366960526,
-0.04093547537922859,
0.05740562453866005,
0.0889986902475357,
0.0322730615735054,
0.08157646656036377,
-0.02810230292379856,
0.010066289454698563,
0.062190424650907516,
0.02907705120742321,
0.016932502388954163,
-0.04960380867123604,
-0.04253096505999565,
-0.015371289104223251,
-0.03688104450702667,
0.0022004502825438976,
0.07064104080200195,
-0.01812826097011566,
-0.05143982544541359,
-0.08905943483114243,
-0.051675934344530106,
-0.02359960414469242,
0.012873752973973751,
0.03972872719168663,
0.0035446383990347385,
0.06106827035546303,
0.05099552124738693,
-0.0036169879604130983,
-0.029964834451675415,
-0.016424838453531265,
0.0490693524479866,
0.06769037991762161,
0.010805467143654823,
-0.016484349966049194,
0.00039237557211890817,
-0.025602225214242935,
-0.0926671102643013,
0.037397146224975586,
0.06032327562570572,
-0.0603482760488987,
-0.10018045455217361,
0.061805788427591324,
-0.07238315045833588,
0.013568094000220299,
-0.027065468952059746,
-0.08460216224193573,
0.016339493915438652,
-0.006875054910778999,
-0.03332469239830971,
-0.0783354640007019,
0.06494747847318649,
-0.023400379344820976,
0.0049675158224999905,
0.10751531273126602,
-0.03268342837691307,
0.006714447867125273,
-0.015448459424078465,
0.00484823202714324,
-5.1907409925888714e-8,
-0.05254971981048584,
-0.07290323823690414,
-0.09472016245126724,
-0.07539397478103638,
-0.0475580170750618,
-0.001507098088040948,
-0.005732960067689419,
0.01569879800081253,
0.023124083876609802,
0.009020603261888027,
-0.015998149290680885,
-0.018321789801120758,
-0.01863858476281166,
-0.013940579257905483,
-0.047475192695856094,
-0.049759358167648315,
0.02178422547876835,
0.0606381818652153,
0.02591392584145069,
-0.017853993922472,
-0.011018238961696625,
-0.002193629276007414,
-0.05457945913076401,
-0.003091719700023532,
0.009414800442755222,
-0.002474562730640173,
0.03751068934798241,
0.07645545154809952,
-0.011315888725221157,
-0.09810098260641098,
0.018525049090385437,
0.010955998674035072,
-0.008504390716552734,
-0.016362296417355537,
-0.07405608892440796,
0.04493769630789757,
0.07518740743398666,
0.04117530956864357,
0.07927180826663971,
0.0833863615989685,
0.050712402909994125,
0.03615953400731087,
-0.009083114564418793,
0.009154184721410275,
-0.04684773087501526,
-0.011122744530439377,
-0.0382540263235569,
0.02661428600549698,
0.0378708578646183,
-0.03694276139140129,
-0.007266711443662643,
0.02596115507185459,
-0.05045520141720772,
-0.047738637775182724,
-0.024529606103897095,
-0.03126195818185806,
0.056721970438957214,
-0.010971425101161003,
-0.05486534163355827,
-0.03319399803876877,
0.12954996526241302,
0.02054808847606182,
0.04280239716172218,
-0.06506878137588501
] | 0.120759 |
of `condition` before trying again. \*\*Default:\*\* `50`. \* `timeout` {number} The poll timeout in milliseconds. If `condition` has not succeeded by the time this elapses, an error occurs. \*\*Default:\*\* `1000`. \* Returns: {Promise} Fulfilled with the value returned by `condition`. This method polls a `condition` function until that function either returns successfully or the operation times out. ## Class: `SuiteContext` An instance of `SuiteContext` is passed to each suite function in order to interact with the test runner. However, the `SuiteContext` constructor is not exposed as part of the API. ### `context.filePath` The absolute path of the test file that created the current suite. If a test file imports additional modules that generate suites, the imported suites will return the path of the root test file. ### `context.fullName` The name of the suite and each of its ancestors, separated by `>`. ### `context.name` The name of the suite. ### `context.signal` \* Type: {AbortSignal} Can be used to abort test subtasks when the test has been aborted. [TAP]: https://testanything.org/ [`--experimental-test-coverage`]: cli.md#--experimental-test-coverage [`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks [`--import`]: cli.md#--importmodule [`--no-strip-types`]: cli.md#--no-strip-types [`--test-concurrency`]: cli.md#--test-concurrency [`--test-coverage-exclude`]: cli.md#--test-coverage-exclude [`--test-coverage-include`]: cli.md#--test-coverage-include [`--test-name-pattern`]: cli.md#--test-name-pattern [`--test-only`]: cli.md#--test-only [`--test-reporter-destination`]: cli.md#--test-reporter-destination [`--test-reporter`]: cli.md#--test-reporter [`--test-rerun-failures`]: cli.md#--test-rerun-failures [`--test-skip-pattern`]: cli.md#--test-skip-pattern [`--test-update-snapshots`]: cli.md#--test-update-snapshots [`--test`]: cli.md#--test [`MockFunctionContext`]: #class-mockfunctioncontext [`MockPropertyContext`]: #class-mockpropertycontext [`MockTimers`]: #class-mocktimers [`MockTracker.method`]: #mockmethodobject-methodname-implementation-options [`MockTracker`]: #class-mocktracker [`NODE\_V8\_COVERAGE`]: cli.md#node\_v8\_coveragedir [`SuiteContext`]: #class-suitecontext [`TestContext`]: #class-testcontext [`context.diagnostic`]: #contextdiagnosticmessage [`context.skip`]: #contextskipmessage [`context.todo`]: #contexttodomessage [`describe()`]: #describename-options-fn [`glob(7)`]: https://man7.org/linux/man-pages/man7/glob.7.html [`it()`]: #itname-options-fn [`run()`]: #runoptions [`suite()`]: #suitename-options-fn [`test()`]: #testname-options-fn [code coverage]: #collecting-code-coverage [configuration files]: cli.md#--experimental-config-fileconfig [describe options]: #describename-options-fn [it options]: #testname-options-fn [running tests from the command line]: #running-tests-from-the-command-line [stream.compose]: stream.md#streamcomposestreams [subtests]: #subtests [suite options]: #suitename-options-fn [test reporters]: #test-reporters [test runner execution model]: #test-runner-execution-model | https://github.com/nodejs/node/blob/main//doc/api/test.md | main | nodejs | [
-0.09500541538000107,
0.08250033855438232,
-0.024200057610869408,
0.05949122831225395,
0.007436799351125956,
-0.0035586347803473473,
-0.03999942168593407,
0.016901172697544098,
-0.006983743514865637,
-0.01885446347296238,
0.02478518895804882,
-0.047021880745887756,
0.06284774839878082,
-0.026177601888775826,
0.14494341611862183,
-0.03571134805679321,
0.03921185061335564,
-0.058437529951334,
-0.05196328088641167,
-0.0003133243299089372,
0.040652260184288025,
0.009814703837037086,
0.005356489215046167,
-0.011436914093792439,
-0.04407668486237526,
-0.05672740936279297,
-0.05314907431602478,
-0.06920517235994339,
0.0797884538769722,
0.0800086110830307,
0.016734404489398003,
0.10435355454683304,
-0.08219564706087112,
0.03189798444509506,
0.0792219340801239,
0.06147331744432449,
-0.031217673793435097,
-0.08150830119848251,
-0.03501122444868088,
-0.008658083155751228,
0.059318907558918,
-0.011562183499336243,
0.0051940931007266045,
-0.05937898904085159,
0.04748803749680519,
-0.0695079118013382,
-0.01123335026204586,
0.006955347023904324,
-0.03418728709220886,
0.02199317328631878,
-0.019081829115748405,
0.02288956567645073,
0.03087129257619381,
-0.0657867044210434,
0.045351628214120865,
0.08644596487283707,
-0.01718447357416153,
-0.002334441989660263,
-0.015603006817400455,
0.036144718527793884,
0.0032874676398932934,
-0.10319890826940536,
-0.05340335890650749,
-0.009669214487075806,
-0.01799617148935795,
0.002508970210328698,
-0.0007553340401500463,
-0.010062449611723423,
0.05119602754712105,
0.019710984081029892,
-0.06458643823862076,
0.03192465752363205,
-0.02986307069659233,
0.04493836686015129,
0.033790260553359985,
0.1034918949007988,
0.033095307648181915,
-0.03395640850067139,
0.012274815700948238,
-0.10170986503362656,
-0.003960706759244204,
-0.08217217028141022,
-0.018932277336716652,
0.010831915773451328,
-0.00538167217746377,
0.033126577734947205,
0.09834685176610947,
-0.018830234184861183,
0.021963482722640038,
-0.004321414511650801,
-0.030969811603426933,
-0.09667405486106873,
-0.14839325845241547,
0.0635143294930458,
0.05952874571084976,
0.007816658355295658,
-0.04291326925158501,
0.04649006202816963,
-0.025949202477931976,
0.01819472946226597,
0.017308427020907402,
0.008332480676472187,
0.040943168103694916,
-0.00021692847076337785,
-0.0024532871320843697,
-0.023443344980478287,
-0.0019211024045944214,
-0.030408820137381554,
-0.008635001257061958,
-0.04117714241147041,
0.07365003228187561,
-0.0009736458887346089,
0.1202859953045845,
-0.04969102144241333,
-0.01023635733872652,
-0.03140048310160637,
-0.038859885185956955,
0.029824871569871902,
0.027743369340896606,
0.11975008249282837,
0.10707264393568039,
0.048034947365522385,
-0.000014668302355858032,
-0.104304239153862,
0.042862750589847565,
-0.011456914246082306,
0.09535807371139526,
2.2888489478532395e-33,
0.02886642888188362,
-0.11470761895179749,
-0.015810362994670868,
0.11560755968093872,
0.07741177827119827,
0.05775613337755203,
0.025968827307224274,
0.03069184720516205,
-0.0012456172844395041,
0.02714402787387371,
0.0258425772190094,
-0.034272339195013046,
-0.07262475043535233,
0.005819176789373159,
0.0009876365074887872,
0.02159610576927662,
0.05783689394593239,
-0.026594214141368866,
0.04162786900997162,
0.05402345955371857,
0.06941952556371689,
-0.050518497824668884,
-0.07572028040885925,
-0.036519866436719894,
-0.0065943216904997826,
0.007350281346589327,
0.006372536066919565,
-0.01396964117884636,
-0.03153008967638016,
0.032961081713438034,
-0.04779058322310448,
0.024467527866363525,
-0.036634672433137894,
0.08965432643890381,
0.04519323259592056,
0.07071930170059204,
-0.016717540100216866,
-0.012708895839750767,
-0.07773272693157196,
-0.03612217679619789,
-0.10290072858333588,
0.011160694062709808,
-0.05471795052289963,
0.05006467550992966,
-0.05229773744940758,
-0.17065580189228058,
-0.01112954318523407,
-0.01346356887370348,
0.1102202981710434,
-0.0032318339217454195,
-0.01870993711054325,
0.11499311029911041,
0.021286867558956146,
-0.02277102693915367,
0.05567607283592224,
-0.02333332784473896,
0.01686451956629753,
0.015601571649312973,
-0.04396766796708107,
0.026384497061371803,
-0.048865485936403275,
-0.041511647403240204,
-0.07109121233224869,
0.047591231763362885,
0.017252778634428978,
0.026214124634861946,
-0.052000220865011215,
-0.07087886333465576,
-0.01252685021609068,
0.007154717575758696,
0.035092536360025406,
-0.011015304364264011,
-0.10996829718351364,
0.010512098670005798,
0.04692884162068367,
-0.08659366518259048,
0.07901511341333389,
0.06540820002555847,
-0.06131003051996231,
-0.09927331656217575,
0.0354684554040432,
-0.02835792303085327,
-0.02550392784178257,
0.05406249314546585,
-0.016528230160474777,
0.024695608764886856,
0.030043400824069977,
-0.022949015721678734,
-0.01868579164147377,
-0.11140117049217224,
0.018857909366488457,
-0.007318604271858931,
-0.003505478845909238,
-0.01682501658797264,
0.014695432968437672,
-4.2240838483821954e-33,
0.04410192370414734,
-0.01547111477702856,
-0.03610784560441971,
0.0019749628845602274,
0.014720579609274864,
-0.05612420663237572,
0.08367433398962021,
0.006833044346421957,
-0.03461883217096329,
-0.012051509693264961,
0.04570280387997627,
0.03449614346027374,
0.033820610493421555,
-0.06309281289577484,
-0.09097684919834137,
0.054893266409635544,
-0.04037599638104439,
-0.1643555611371994,
0.04096422344446182,
0.031192023307085037,
0.03624982386827469,
-0.00444779871031642,
-0.003898109309375286,
0.037045467644929886,
-0.09076747298240662,
-0.014442473649978638,
-0.018547508865594864,
-0.04052155464887619,
-0.01146182045340538,
-0.030567295849323273,
0.05065233260393143,
0.018000196665525436,
-0.11205560714006424,
0.07427108287811279,
0.041046977043151855,
-0.029216820374131203,
0.020162587985396385,
0.07391492277383804,
-0.05477016419172287,
0.08108264952898026,
0.09319646656513214,
0.030903294682502747,
-0.017671998590230942,
-0.008116724900901318,
0.0056765275076031685,
0.041893430054187775,
0.06320656836032867,
-0.09537933021783829,
0.031157778576016426,
-0.001695195329375565,
0.02220924012362957,
-0.013576840050518513,
0.04380671679973602,
0.10059598088264465,
-0.0047309924848377705,
-0.07996992021799088,
-0.07673221081495285,
-0.06803831458091736,
-0.027187753468751907,
0.07197461277246475,
0.030908897519111633,
0.05652220919728279,
0.026748022064566612,
0.04249269515275955,
-0.03179587051272392,
-0.010450457222759724,
-0.0401584692299366,
0.041373323649168015,
0.04229060932993889,
0.06553763151168823,
0.03236754238605499,
0.012256495654582977,
-0.03206663951277733,
-0.034462153911590576,
-0.01766243577003479,
0.054542265832424164,
-0.06958333402872086,
-0.09466737508773804,
0.0330568328499794,
0.06096263602375984,
-0.019859613850712776,
-0.001584782381542027,
-0.056284401565790176,
0.027170509099960327,
-0.018537141382694244,
0.015309956856071949,
0.026660025119781494,
0.1153964027762413,
0.023569699376821518,
0.050502680242061615,
0.04156487435102463,
-0.002385778585448861,
-0.09857936948537827,
-0.054803039878606796,
-0.020100455731153488,
-6.430946797308934e-8,
-0.052004892379045486,
0.001244563958607614,
-0.06524913012981415,
-0.05800013616681099,
-0.004108581226319075,
-0.01383800059556961,
0.03778674453496933,
-0.03368141129612923,
0.004617698490619659,
0.009698945097625256,
0.014856572262942791,
0.05575143173336983,
0.009486045688390732,
-0.023625658825039864,
-0.03583395853638649,
-0.030340060591697693,
-0.02475525625050068,
0.029312441125512123,
-0.006537329405546188,
-0.031190715730190277,
-0.03566600754857063,
-0.014081544242799282,
0.01302376389503479,
-0.01417626440525055,
-0.026713764294981956,
0.043917447328567505,
0.09344422072172165,
0.020909735932946205,
0.019804779440164566,
0.01823120377957821,
-0.04900763928890228,
-0.006304712500423193,
-0.03555436059832573,
-0.06876563280820847,
-0.08959253132343292,
0.05605973303318024,
0.06557817757129669,
-0.0019275184022262692,
0.09787733852863312,
0.03844044357538223,
0.00006467012281063944,
0.03871985897421837,
-0.07153632491827011,
-0.0033635415602475405,
-0.028802789747714996,
-0.07556332647800446,
0.01166912168264389,
0.05898337811231613,
0.007132082711905241,
-0.04599757492542267,
-0.06413832306861877,
0.04188817739486694,
-0.09164915233850479,
0.042000677436590195,
0.01992419920861721,
-0.054114703088998795,
0.007738931570202112,
-0.0016673391219228506,
-0.011349029839038849,
-0.005372880958020687,
-0.03467877209186554,
-0.02630000002682209,
0.04566293582320213,
-0.029756469652056694
] | 0.049637 |
# Child process > Stability: 2 - Stable The `node:child\_process` module provides the ability to spawn subprocesses in a manner that is similar, but not identical, to popen(3). This capability is primarily provided by the [`child\_process.spawn()`][] function: ```cjs const { spawn } = require('node:child\_process'); const ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.stderr.on('data', (data) => { console.error(`stderr: ${data}`); }); ls.on('close', (code) => { console.log(`child process exited with code ${code}`); }); ``` ```mjs import { spawn } from 'node:child\_process'; import { once } from 'node:events'; const ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.stderr.on('data', (data) => { console.error(`stderr: ${data}`); }); const [code] = await once(ls, 'close'); console.log(`child process exited with code ${code}`); ``` By default, pipes for `stdin`, `stdout`, and `stderr` are established between the parent Node.js process and the spawned subprocess. These pipes have limited (and platform-specific) capacity. If the subprocess writes to stdout in excess of that limit without the output being captured, the subprocess blocks, waiting for the pipe buffer to accept more data. This is identical to the behavior of pipes in the shell. Use the `{ stdio: 'ignore' }` option if the output will not be consumed. The command lookup is performed using the `options.env.PATH` environment variable if `env` is in the `options` object. Otherwise, `process.env.PATH` is used. If `options.env` is set without `PATH`, lookup on Unix is performed on a default search path search of `/usr/bin:/bin` (see your operating system's manual for execvpe/execvp), on Windows the current processes environment variable `PATH` is used. On Windows, environment variables are case-insensitive. Node.js lexicographically sorts the `env` keys and uses the first one that case-insensitively matches. Only first (in lexicographic order) entry will be passed to the subprocess. This might lead to issues on Windows when passing objects to the `env` option that have multiple variants of the same key, such as `PATH` and `Path`. The [`child\_process.spawn()`][] method spawns the child process asynchronously, without blocking the Node.js event loop. The [`child\_process.spawnSync()`][] function provides equivalent functionality in a synchronous manner that blocks the event loop until the spawned process either exits or is terminated. For convenience, the `node:child\_process` module provides a handful of synchronous and asynchronous alternatives to [`child\_process.spawn()`][] and [`child\_process.spawnSync()`][]. Each of these alternatives are implemented on top of [`child\_process.spawn()`][] or [`child\_process.spawnSync()`][]. \* [`child\_process.exec()`][]: spawns a shell and runs a command within that shell, passing the `stdout` and `stderr` to a callback function when complete. \* [`child\_process.execFile()`][]: similar to [`child\_process.exec()`][] except that it spawns the command directly without first spawning a shell by default. \* [`child\_process.fork()`][]: spawns a new Node.js process and invokes a specified module with an IPC communication channel established that allows sending messages between parent and child. \* [`child\_process.execSync()`][]: a synchronous version of [`child\_process.exec()`][] that will block the Node.js event loop. \* [`child\_process.execFileSync()`][]: a synchronous version of [`child\_process.execFile()`][] that will block the Node.js event loop. For certain use cases, such as automating shell scripts, the [synchronous counterparts][] may be more convenient. In many cases, however, the synchronous methods can have significant impact on performance due to stalling the event loop while spawned processes complete. ## Asynchronous process creation The [`child\_process.spawn()`][], [`child\_process.fork()`][], [`child\_process.exec()`][], and [`child\_process.execFile()`][] methods all follow the idiomatic asynchronous programming pattern typical of other Node.js APIs. Each of the methods returns a [`ChildProcess`][] instance. These objects implement the Node.js [`EventEmitter`][] API, allowing the parent process to register listener functions that are called when certain events occur during the life cycle of the child process. The [`child\_process.exec()`][] and [`child\_process.execFile()`][] methods additionally allow for an optional `callback` function to be specified that is invoked when the | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.10885142534971237,
-0.047891765832901,
-0.04423139616847038,
0.018473103642463684,
0.06500328332185745,
-0.05254676192998886,
-0.044210035353899,
0.08340714871883392,
0.061456214636564255,
-0.04272766038775444,
-0.05346538871526718,
0.03093680925667286,
-0.009281718172132969,
-0.030405128374695778,
-0.0000741459007258527,
-0.007170455064624548,
0.015236749313771725,
0.017987681552767754,
0.016877418383955956,
-0.11871565133333206,
0.060668837279081345,
-0.01313634030520916,
0.022273311391472816,
0.009660327807068825,
-0.05074533447623253,
-0.006363128777593374,
-0.04412414878606796,
-0.03168744593858719,
0.08999515324831009,
-0.007580143865197897,
0.09747851639986038,
-0.003697102190926671,
-0.051419615745544434,
-0.03230924904346466,
0.0032745925709605217,
0.165133535861969,
-0.026875121518969536,
-0.13189741969108582,
-0.052334848791360855,
0.06473666429519653,
0.11090978980064392,
0.0734013170003891,
-0.10845790058374405,
-0.06936753541231155,
-0.0306291151791811,
-0.027857007458806038,
-0.11564110219478607,
0.0008319715852849185,
-0.10182514786720276,
-0.029147006571292877,
0.016664057970046997,
-0.03643098473548889,
-0.0014957822859287262,
0.04497034475207329,
-0.08539801836013794,
-0.01178792119026184,
0.006616296246647835,
-0.029235098510980606,
0.018739003688097,
0.03718801960349083,
-0.058474112302064896,
0.0696209967136383,
0.003862266195937991,
-0.00814227294176817,
0.0830569639801979,
-0.0021590502001345158,
-0.05184862017631531,
0.03468936309218407,
0.03351178765296936,
0.0661754310131073,
-0.004334720782935619,
-0.00007907567487563938,
-0.08330003172159195,
0.024555375799536705,
-0.04671672731637955,
-0.03294113650918007,
0.016115574166178703,
-0.013558640144765377,
-0.07432378083467484,
-0.039371248334646225,
-0.04752001911401749,
-0.03543947637081146,
-0.07284357398748398,
-0.03702915087342262,
-0.0493125282227993,
0.0673440545797348,
-0.004391732160001993,
0.01330461073666811,
0.05048806220293045,
0.04239857196807861,
-0.08684023469686508,
0.01834152825176716,
-0.06256819516420364,
0.09309481829404831,
-0.001946503878571093,
0.026612183079123497,
0.028558136895298958,
0.027226971462368965,
0.02401023544371128,
-0.025615017861127853,
-0.02324404940009117,
0.09672879427671432,
0.056939832866191864,
0.02408471331000328,
0.03947022184729576,
-0.027590010315179825,
-0.057295724749565125,
0.008088256232440472,
-0.026860088109970093,
-0.06029572710394859,
-0.032400548458099365,
0.021639864891767502,
0.013107798993587494,
0.006528922822326422,
0.013873415067791939,
0.003858060808852315,
0.03338634967803955,
-0.059172194451093674,
0.001141112414188683,
0.11604916304349899,
0.15143655240535736,
-0.0024680308997631073,
-0.008466273546218872,
-0.012118777260184288,
0.028641492128372192,
-0.11575152724981308,
-0.008736464194953442,
6.151898257150593e-34,
-0.013392001390457153,
-0.13941597938537598,
0.050036847591400146,
0.04288598895072937,
0.05680401250720024,
0.04944547265768051,
-0.02109147049486637,
0.003129746066406369,
-0.10206616669893265,
0.021395277231931686,
-0.019946468994021416,
-0.06486345082521439,
-0.03658723831176758,
-0.09435020387172699,
0.05481432378292084,
-0.03171371668577194,
0.08589688688516617,
0.003051940118893981,
0.006724079605191946,
0.05257300287485123,
0.03301212936639786,
0.0033900043927133083,
-0.07202649116516113,
0.026630226522684097,
0.11157692968845367,
0.007241859566420317,
-0.03763005882501602,
0.0009263265528716147,
0.0018612584099173546,
-0.016820091754198074,
-0.008438220247626305,
0.06439811736345291,
0.011745201423764229,
0.012130719609558582,
-0.025954950600862503,
-0.03839227557182312,
0.0068092732690274715,
0.0006832035724073648,
-0.04465654119849205,
-0.06156570091843605,
0.030632898211479187,
-0.011643240228295326,
-0.01652737520635128,
0.0171038880944252,
-0.05208151042461395,
-0.09403002262115479,
-0.05866888538002968,
-0.04355950653553009,
-0.019846539944410324,
-0.013945535756647587,
0.1360820233821869,
0.06788109987974167,
0.03318190574645996,
-0.07216864079236984,
0.051823265850543976,
0.05329640209674835,
-0.020647631958127022,
-0.04202500358223915,
-0.02459695003926754,
-0.004402896389365196,
0.02784864790737629,
0.007056673523038626,
-0.02995164692401886,
0.011884570121765137,
0.04861884191632271,
-0.06412060558795929,
0.040676768869161606,
0.042437296360731125,
0.0559539794921875,
0.01419437862932682,
-0.08085943013429642,
0.012298515066504478,
0.00682208314538002,
-0.04046477749943733,
0.0693187415599823,
0.030293967574834824,
0.004022873472422361,
-0.052127547562122345,
-0.0354364812374115,
-0.011943072080612183,
0.046126589179039,
-0.03520706668496132,
-0.05155725032091141,
0.0019474356668069959,
0.031863581389188766,
-0.016164828091859818,
-0.030551495030522346,
-0.0023317423183470964,
-0.008552003651857376,
0.03341800719499588,
-0.03229863569140434,
-0.046740513294935226,
0.024723052978515625,
-0.06275801360607147,
-0.1002926379442215,
-4.841212505092142e-33,
0.017208298668265343,
-0.041423071175813675,
-0.08383208513259888,
0.0849076434969902,
-0.04964165762066841,
-0.04395623132586479,
-0.006967923138290644,
-0.004041386302560568,
-0.048069752752780914,
0.02457503229379654,
-0.11424855887889862,
0.020619168877601624,
0.04258977621793747,
0.04565965384244919,
-0.007741519249975681,
0.03878778591752052,
-0.043443936854600906,
0.06210167333483696,
0.05082205682992935,
-0.004868439398705959,
0.0015675444155931473,
0.040513183921575546,
0.03107486292719841,
0.0400070883333683,
-0.031004713848233223,
-0.04199811443686485,
-0.052269138395786285,
0.026684090495109558,
-0.015936367213726044,
-0.026778224855661392,
-0.016385270282626152,
-0.02598869428038597,
0.033471692353487015,
0.06410376727581024,
-0.008146926760673523,
-0.05179833993315697,
0.016685642302036285,
0.07986237853765488,
0.10042168945074081,
-0.10338550060987473,
0.11050932854413986,
0.010632116347551346,
-0.00892586074769497,
-0.003733148332685232,
0.023536209017038345,
0.001446074340492487,
0.044770292937755585,
0.013717091642320156,
-0.03549959510564804,
0.019578229635953903,
-0.08474753051996231,
-0.013489394448697567,
-0.04090634360909462,
0.04590252414345741,
-0.006956901866942644,
0.0032637789845466614,
0.0234079472720623,
-0.040806327015161514,
-0.003060047747567296,
0.024015003815293312,
0.06489488482475281,
-0.08311530202627182,
-0.030310872942209244,
0.02376824989914894,
0.0037855457048863173,
-0.05581621453166008,
-0.10975399613380432,
-0.0008739378536120057,
0.12233386933803558,
-0.0404190830886364,
0.06499838083982468,
0.07976781576871872,
-0.033188797533512115,
0.02735220082104206,
-0.00235932320356369,
-0.02133195847272873,
-0.04189886152744293,
-0.11340833455324173,
0.01746821217238903,
0.03381935507059097,
-0.04985051974654198,
0.03691447526216507,
-0.013761311769485474,
-0.0081504350528121,
0.0293747391551733,
-0.04732867330312729,
0.02577853389084339,
0.02717592567205429,
0.011064818128943443,
-0.06250043958425522,
0.04210464656352997,
0.025555836036801338,
-0.06046472117304802,
-0.060488417744636536,
0.009251515381038189,
-4.7716358864136055e-8,
-0.0286267027258873,
-0.004860995337367058,
0.006595063488930464,
0.045080214738845825,
0.05542096123099327,
-0.08500081300735474,
-0.0004152703913860023,
-0.00997972022742033,
0.027794310823082924,
0.037188831716775894,
-0.05382940545678139,
-0.06401661783456802,
0.032393209636211395,
-0.07607121765613556,
0.09227309376001358,
0.025210661813616753,
0.03762856870889664,
0.007685148622840643,
0.01594517193734646,
0.02924794703722,
0.05630570277571678,
0.07708713412284851,
0.007658724207431078,
0.055501244962215424,
-0.08397768437862396,
-0.07226714491844177,
0.05042281374335289,
0.0559430830180645,
-0.09695027768611908,
-0.04373081400990486,
0.025088351219892502,
0.030016768723726273,
0.06517163664102554,
0.09255973249673843,
0.01996465027332306,
-0.05713402479887009,
-0.06024474650621414,
0.01751188561320305,
0.0772910863161087,
0.008481700904667377,
0.07359827309846878,
0.11123653501272202,
-0.04250592738389969,
0.027162158861756325,
-0.03082769736647606,
0.027486462146043777,
-0.01679660938680172,
-0.00320873549208045,
0.03014872968196869,
0.03499237075448036,
0.009336620569229126,
-0.02967696264386177,
-0.06804448366165161,
-0.020172717049717903,
0.1020367294549942,
-0.006338904611766338,
0.03318590298295021,
-0.03351028263568878,
-0.015909310430288315,
0.014170593582093716,
0.008751586079597473,
0.0682533010840416,
0.0926986113190651,
-0.0219434667378664
] | 0.032761 |
These objects implement the Node.js [`EventEmitter`][] API, allowing the parent process to register listener functions that are called when certain events occur during the life cycle of the child process. The [`child\_process.exec()`][] and [`child\_process.execFile()`][] methods additionally allow for an optional `callback` function to be specified that is invoked when the child process terminates. ### Spawning `.bat` and `.cmd` files on Windows The importance of the distinction between [`child\_process.exec()`][] and [`child\_process.execFile()`][] can vary based on platform. On Unix-type operating systems (Unix, Linux, macOS) [`child\_process.execFile()`][] can be more efficient because it does not spawn a shell by default. On Windows, however, `.bat` and `.cmd` files are not executable on their own without a terminal, and therefore cannot be launched using [`child\_process.execFile()`][]. When running on Windows, `.bat` and `.cmd` files can be invoked using [`child\_process.spawn()`][] with the `shell` option set, with [`child\_process.exec()`][], or by spawning `cmd.exe` and passing the `.bat` or `.cmd` file as an argument (which is what the `shell` option and [`child\_process.exec()`][] do). In any case, if the script filename contains spaces it needs to be quoted. ```cjs // OR... const { exec, spawn } = require('node:child\_process'); exec('my.bat', (err, stdout, stderr) => { if (err) { console.error(err); return; } console.log(stdout); }); // Script with spaces in the filename: const bat = spawn('"my script.cmd" a b', { shell: true }); // or: exec('"my script.cmd" a b', (err, stdout, stderr) => { // ... }); ``` ```mjs // OR... import { exec, spawn } from 'node:child\_process'; exec('my.bat', (err, stdout, stderr) => { if (err) { console.error(err); return; } console.log(stdout); }); // Script with spaces in the filename: const bat = spawn('"my script.cmd" a b', { shell: true }); // or: exec('"my script.cmd" a b', (err, stdout, stderr) => { // ... }); ``` ### `child\_process.exec(command[, options][, callback])` \* `command` {string} The command to run, with space-separated arguments. \* `options` {Object} \* `cwd` {string|URL} Current working directory of the child process. \*\*Default:\*\* `process.cwd()`. \* `env` {Object} Environment key-value pairs. \*\*Default:\*\* `process.env`. \* `encoding` {string} \*\*Default:\*\* `'utf8'` \* `shell` {string} Shell to execute the command with. See [Shell requirements][] and [Default Windows shell][]. \*\*Default:\*\* `'/bin/sh'` on Unix, `process.env.ComSpec` on Windows. \* `signal` {AbortSignal} allows aborting the child process using an AbortSignal. \* `timeout` {number} \*\*Default:\*\* `0` \* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated and any output is truncated. See caveat at [`maxBuffer` and Unicode][]. \*\*Default:\*\* `1024 \* 1024`. \* `killSignal` {string|integer} \*\*Default:\*\* `'SIGTERM'` \* `uid` {number} Sets the user identity of the process (see setuid(2)). \* `gid` {number} Sets the group identity of the process (see setgid(2)). \* `windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. \*\*Default:\*\* `false`. \* `callback` {Function} called with the output when process terminates. \* `error` {Error} \* `stdout` {string|Buffer} \* `stderr` {string|Buffer} \* Returns: {ChildProcess} Spawns a shell then executes the `command` within that shell, buffering any generated output. The `command` string passed to the exec function is processed directly by the shell and special characters (vary based on [shell](https://en.wikipedia.org/wiki/List\_of\_command-line\_interpreters)) need to be dealt with accordingly: ```cjs const { exec } = require('node:child\_process'); exec('"/path/to/test file/test.sh" arg1 arg2'); // Double quotes are used so that the space in the path is not interpreted as // a delimiter of multiple arguments. exec('echo "The \\$HOME variable is $HOME"'); // The $HOME variable is escaped in the first instance, but not in the second. ``` ```mjs import { exec } from 'node:child\_process'; exec('"/path/to/test file/test.sh" arg1 arg2'); // Double quotes are used so that the space in the path is not interpreted as // | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.07132501900196075,
-0.004339041654020548,
-0.028309158980846405,
0.047791384160518646,
0.04911917820572853,
-0.03805434703826904,
0.021844638511538506,
0.08380314707756042,
0.07599259912967682,
0.06270099431276321,
-0.01885751262307167,
0.04246768355369568,
-0.08302692323923111,
0.014715020544826984,
0.05417287349700928,
0.024271240457892418,
0.003717603161931038,
0.023172928020358086,
-0.027469495311379433,
-0.0029982328414916992,
0.014897642657160759,
0.0021181453485041857,
0.04241613298654556,
-0.01675994135439396,
-0.05478498339653015,
0.008377709425985813,
-0.0040484266355633736,
-0.061645444482564926,
0.0010655798250809312,
0.02178623527288437,
0.021732261404395103,
-0.03188928961753845,
0.008134890347719193,
-0.06219523772597313,
0.006576392333954573,
0.10437167435884476,
0.08897602558135986,
-0.0754811093211174,
-0.09265618026256561,
-0.08785123378038406,
0.09579227864742279,
0.11087580770254135,
-0.08988136798143387,
-0.05469169840216637,
-0.029515080153942108,
-0.037646517157554626,
-0.07993460446596146,
-0.03318697586655617,
-0.15321676433086395,
0.006261894945055246,
-0.003435960505157709,
0.01060802023857832,
-0.022550662979483604,
-0.01379750482738018,
-0.04055586829781532,
0.008004306815564632,
0.022955449298024178,
-0.0381171889603138,
0.07558717578649521,
0.07701697200536728,
-0.06367617100477219,
0.0017177315894514322,
-0.07531265914440155,
0.01858631521463394,
0.02016122080385685,
-0.014946945942938328,
-0.04288467392325401,
-0.03785502538084984,
0.06695067882537842,
-0.025795020163059235,
-0.03363305702805519,
0.008082965388894081,
-0.046607743948698044,
0.02323932945728302,
-0.07724770903587341,
-0.024389982223510742,
0.05071346089243889,
0.004659399390220642,
-0.09740453958511353,
-0.08776068687438965,
-0.03456329554319382,
-0.04500921815633774,
0.03711472824215889,
-0.04531353339552879,
0.01343928836286068,
0.09514880180358887,
-0.018957175314426422,
-0.014898030087351799,
0.0399833582341671,
0.10071323812007904,
-0.11072000116109848,
-0.013955465517938137,
-0.041029855608940125,
0.0549212321639061,
0.008256545290350914,
0.0067506334744393826,
0.031604018062353134,
0.0031993058510124683,
0.0015753257321193814,
-0.05061281844973564,
-0.01385299488902092,
0.024814628064632416,
0.014720913954079151,
0.017675340175628662,
0.08219348639249802,
-0.014872181229293346,
-0.06988205760717392,
-0.04348146915435791,
0.047050874680280685,
-0.051953066140413284,
-0.049364861100912094,
-0.007792773190885782,
0.006886755116283894,
0.007941204123198986,
-0.014747703447937965,
-0.0018210032721981406,
0.09347422420978546,
0.007100717630237341,
0.018836122006177902,
0.12044544517993927,
0.10642701387405396,
0.047773778438568115,
0.039186298847198486,
-0.03196102753281593,
0.013972301967442036,
-0.09741343557834625,
-0.004402791615575552,
1.4722253081553191e-33,
0.001897404552437365,
-0.14408934116363525,
0.004341555759310722,
0.04864804074168205,
0.08320193737745285,
0.041293710470199585,
0.010110258124768734,
-0.022172266617417336,
-0.005798449739813805,
0.005587944760918617,
-0.062310006469488144,
0.04358818382024765,
0.02765517123043537,
-0.06003942713141441,
0.08580662310123444,
0.03603760153055191,
0.005379390437155962,
0.00679003307595849,
0.07103341072797775,
0.03739256411790848,
0.006239194422960281,
0.061457376927137375,
-0.040694721043109894,
0.13682134449481964,
0.09326214343309402,
-0.002322329441085458,
-0.0287373885512352,
0.01664680987596512,
0.049152910709381104,
0.00361817074008286,
0.015750223770737648,
0.01757262460887432,
-0.057039253413677216,
-0.017463061958551407,
-0.022680306807160378,
0.027862466871738434,
-0.007850125432014465,
-0.014561012387275696,
-0.04028399661183357,
-0.08270186930894852,
-0.02561240829527378,
-0.009394238702952862,
-0.04560861364006996,
-0.004662728868424892,
-0.08544199168682098,
-0.10816261172294617,
-0.08760077506303787,
-0.024855459108948708,
0.06583559513092041,
0.0456913597881794,
0.03679441288113594,
0.017000481486320496,
0.11928115785121918,
0.021250881254673004,
0.02548314444720745,
0.041341233998537064,
-0.029229391366243362,
-0.028871411457657814,
-0.040538590401411057,
-0.018622523173689842,
0.09344421327114105,
-0.017107052728533745,
-0.07025932520627975,
0.005521770566701889,
-0.011718455702066422,
-0.07563857734203339,
0.03209904581308365,
-0.023491133004426956,
-0.003979732282459736,
0.050584111362695694,
-0.012480350211262703,
0.07979292422533035,
0.013348364271223545,
-0.06267397850751877,
0.032940685749053955,
0.009662328287959099,
0.007493389304727316,
-0.05680321156978607,
-0.049767132848501205,
0.021449480205774307,
0.016794942319393158,
0.028449222445487976,
-0.0670994371175766,
-0.04544467851519585,
0.059576891362667084,
-0.02290695160627365,
-0.09190072119235992,
-0.015585924498736858,
0.05544796213507652,
-0.010303580202162266,
0.062323760241270065,
-0.030843302607536316,
-0.042909421026706696,
0.012925437651574612,
-0.07337280362844467,
-4.972055679256217e-33,
0.06391691416501999,
0.02636936493217945,
-0.044539131224155426,
0.028852276504039764,
-0.07974174618721008,
0.018466411158442497,
-0.09830407798290253,
-0.1098550409078598,
-0.07313786447048187,
-0.05884316936135292,
-0.12471020966768265,
0.026474228128790855,
0.04125134274363518,
0.035695575177669525,
0.023516815155744553,
0.017415836453437805,
-0.024489788338541985,
-0.014247524552047253,
0.06430899351835251,
-0.062379900366067886,
0.011706850491464138,
0.0533149428665638,
0.028459401801228523,
0.026669830083847046,
0.02349306084215641,
-0.08710530400276184,
-0.08459552377462387,
-0.023249903693795204,
0.005617429502308369,
-0.03944874182343483,
-0.06710126250982285,
0.05640196427702904,
-0.016744013875722885,
0.030813343822956085,
0.047182995826005936,
-0.05373046174645424,
-0.02556505985558033,
0.03762209787964821,
0.10042908042669296,
-0.10775024443864822,
0.055982135236263275,
0.04132426530122757,
0.051771681755781174,
0.041601669043302536,
0.0034730625338852406,
0.07429610937833786,
0.010100445710122585,
0.07190179079771042,
-0.058199651539325714,
0.01796697825193405,
-0.037695202976465225,
-0.06188875064253807,
-0.0202784426510334,
0.04007645323872566,
-0.04527714103460312,
-0.05466882884502411,
0.056655894964933395,
-0.015549460425972939,
-0.012638883665204048,
0.03267037868499756,
0.10752959549427032,
-0.07727409154176712,
-0.035284675657749176,
-0.0497160479426384,
-0.11267520487308502,
0.020896047353744507,
-0.03986253961920738,
0.019320398569107056,
0.05190979316830635,
-0.06944403052330017,
0.04155266657471657,
0.0055614798329770565,
-0.05712449923157692,
0.008371050469577312,
-0.09374631196260452,
0.05546056851744652,
0.034712813794612885,
-0.12602517008781433,
-0.035317011177539825,
0.021166132763028145,
0.03038881905376911,
0.1196896880865097,
-0.0024309970904141665,
0.02532760053873062,
-0.0077672554180026054,
0.0017973323119804263,
-0.015873601660132408,
0.015092194080352783,
-0.020388729870319366,
0.0027188570238649845,
0.042525213211774826,
0.05606304109096527,
0.009492717683315277,
0.035631030797958374,
-0.03384372964501381,
-5.061369989789455e-8,
-0.013387459330260754,
-0.033681731671094894,
-0.051461927592754364,
-0.057382527738809586,
-0.037504833191633224,
0.021395113319158554,
0.01800701394677162,
0.007202493492513895,
0.06255502998828888,
0.0019906938541680574,
-0.0010432939743623137,
-0.05032820999622345,
0.02873069979250431,
-0.0082298768684268,
-0.003536086529493332,
0.055530816316604614,
0.059391312301158905,
0.03463027626276016,
0.01933947764337063,
0.053107306361198425,
0.017188090831041336,
0.05295844376087189,
-0.012946588918566704,
0.10862617939710617,
-0.11583729088306427,
-0.009594770148396492,
0.011760713532567024,
0.01971714198589325,
-0.12302538752555847,
-0.017242254689335823,
-0.02812894992530346,
0.027689369395375252,
0.04574695974588394,
0.09735275059938431,
-0.047588132321834564,
0.033580318093299866,
0.014270355924963951,
-0.011817065067589283,
-0.01932721585035324,
0.003234647447243333,
0.04262019693851471,
0.012001916766166687,
-0.033081699162721634,
0.014284596778452396,
-0.027744609862565994,
-0.01338149979710579,
-0.04075018689036369,
-0.0038072492461651564,
-0.005606167949736118,
0.01625964418053627,
-0.04304024577140808,
0.017143860459327698,
-0.01751386746764183,
0.011378823779523373,
0.005421906244009733,
0.09866570681333542,
0.008250287733972073,
-0.08242252469062805,
-0.006804702337831259,
0.08029118925333023,
0.010952690616250038,
0.02735300362110138,
0.04330078512430191,
0.019710185006260872
] | 0.147752 |
exec('echo "The \\$HOME variable is $HOME"'); // The $HOME variable is escaped in the first instance, but not in the second. ``` ```mjs import { exec } from 'node:child\_process'; exec('"/path/to/test file/test.sh" arg1 arg2'); // Double quotes are used so that the space in the path is not interpreted as // a delimiter of multiple arguments. exec('echo "The \\$HOME variable is $HOME"'); // The $HOME variable is escaped in the first instance, but not in the second. ``` \*\*Never pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.\*\* If a `callback` function is provided, it is called with the arguments `(error, stdout, stderr)`. On success, `error` will be `null`. On error, `error` will be an instance of [`Error`][]. The `error.code` property will be the exit code of the process. By convention, any exit code other than `0` indicates an error. `error.signal` will be the signal that terminated the process. The `stdout` and `stderr` arguments passed to the callback will contain the stdout and stderr output of the child process. By default, Node.js will decode the output as UTF-8 and pass strings to the callback. The `encoding` option can be used to specify the character encoding used to decode the stdout and stderr output. If `encoding` is `'buffer'`, or an unrecognized character encoding, `Buffer` objects will be passed to the callback instead. ```cjs const { exec } = require('node:child\_process'); exec('cat \*.js missing\_file | wc -l', (error, stdout, stderr) => { if (error) { console.error(`exec error: ${error}`); return; } console.log(`stdout: ${stdout}`); console.error(`stderr: ${stderr}`); }); ``` ```mjs import { exec } from 'node:child\_process'; exec('cat \*.js missing\_file | wc -l', (error, stdout, stderr) => { if (error) { console.error(`exec error: ${error}`); return; } console.log(`stdout: ${stdout}`); console.error(`stderr: ${stderr}`); }); ``` If `timeout` is greater than `0`, the parent process will send the signal identified by the `killSignal` property (the default is `'SIGTERM'`) if the child process runs longer than `timeout` milliseconds. Unlike the exec(3) POSIX system call, `child\_process.exec()` does not replace the existing process and uses a shell to execute the command. If this method is invoked as its [`util.promisify()`][]ed version, it returns a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned `ChildProcess` instance is attached to the `Promise` as a `child` property. In case of an error (including any error resulting in an exit code other than 0), a rejected promise is returned, with the same `error` object given in the callback, but with two additional properties `stdout` and `stderr`. ```cjs const util = require('node:util'); const exec = util.promisify(require('node:child\_process').exec); async function lsExample() { const { stdout, stderr } = await exec('ls'); console.log('stdout:', stdout); console.error('stderr:', stderr); } lsExample(); ``` ```mjs import { promisify } from 'node:util'; import child\_process from 'node:child\_process'; const exec = promisify(child\_process.exec); async function lsExample() { const { stdout, stderr } = await exec('ls'); console.log('stdout:', stdout); console.error('stderr:', stderr); } lsExample(); ``` If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except the error passed to the callback will be an `AbortError`: ```cjs const { exec } = require('node:child\_process'); const controller = new AbortController(); const { signal } = controller; const child = exec('grep ssh', { signal }, (error) => { console.error(error); // an AbortError }); controller.abort(); ``` ```mjs import { exec } from 'node:child\_process'; const controller = new AbortController(); const { signal } = controller; const child = exec('grep ssh', { signal }, (error) => { console.error(error); // an AbortError }); controller.abort(); ``` ### `child\_process.execFile(file[, args][, options][, callback])` \* `file` {string} The name or path of the executable | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.005698320455849171,
0.0210221316665411,
0.012757227756083012,
0.05840738117694855,
0.05073479935526848,
-0.0372324213385582,
0.04717092961072922,
0.052755728363990784,
0.013439704664051533,
0.03610176593065262,
0.024833012372255325,
-0.023102600127458572,
0.004653739742934704,
-0.01772165298461914,
0.10375833511352539,
0.022066373378038406,
0.02214033715426922,
-0.04140761122107506,
-0.022331850603222847,
-0.04917168617248535,
0.03213631734251976,
0.018947215750813484,
0.06958947330713272,
-0.00654583889991045,
-0.004827725701034069,
-0.04898080229759216,
-0.020654501393437386,
-0.01950152777135372,
-0.01193831767886877,
-0.010913465172052383,
0.05565616860985756,
-0.061243243515491486,
-0.05809829384088516,
-0.047730326652526855,
0.030563702806830406,
0.15753810107707977,
0.06768178194761276,
-0.052418433129787445,
-0.05750242620706558,
-0.05343180149793625,
0.0400468148291111,
0.03438055142760277,
-0.06699971854686737,
-0.08350128680467606,
0.01266337651759386,
-0.0134394820779562,
-0.08181768655776978,
-0.006965966895222664,
-0.10685891658067703,
0.026359427720308304,
-0.0070928786881268024,
-0.038454849272966385,
-0.05733421444892883,
-0.003471324685961008,
-0.009832354262471199,
0.036511439830064774,
-0.004884982481598854,
0.0615050382912159,
0.11380455642938614,
0.02248084731400013,
-0.02954787202179432,
0.0028401652816683054,
0.006364928092807531,
0.01957692578434944,
0.0883302316069603,
-0.12614654004573822,
-0.07341556251049042,
-0.03290540352463722,
-0.02438165992498398,
0.030504468828439713,
0.026373788714408875,
-0.034146640449762344,
-0.09440021216869354,
-0.032077815383672714,
-0.006110405083745718,
0.048420146107673645,
-0.017330262809991837,
0.035176049917936325,
-0.04608209803700447,
-0.03992960974574089,
0.014425940811634064,
-0.048992522060871124,
-0.06283877044916153,
-0.03540092706680298,
0.016019979491829872,
0.10449954867362976,
-0.012940854765474796,
-0.021698398515582085,
0.07800944894552231,
0.0336962454020977,
0.036250509321689606,
-0.0902358740568161,
-0.05490845441818237,
0.08432268351316452,
0.04531102254986763,
0.014846227131783962,
-0.09757453203201294,
0.01370139792561531,
-0.007237953133881092,
0.03666219115257263,
0.007339455187320709,
0.0006162052741274238,
0.04106590151786804,
0.0030276847537606955,
0.04225340113043785,
0.01822335459291935,
0.0007554494077339768,
-0.07970049977302551,
-0.004714991897344589,
-0.06541155278682709,
-0.06627658754587173,
-0.05489372834563255,
0.022854004055261612,
0.0024511003866791725,
0.011419730260968208,
-0.007078676950186491,
0.14079079031944275,
-0.055405519902706146,
0.047470442950725555,
0.1437520980834961,
0.05984793230891228,
0.01771358773112297,
0.06421840190887451,
0.013163970783352852,
0.09021368622779846,
-0.06258504837751389,
0.021369433030486107,
2.0689236893769823e-33,
-0.009487634524703026,
-0.06831648200750351,
-0.012249726802110672,
0.002137475647032261,
0.029968829825520515,
0.02976462058722973,
0.041963618248701096,
0.018371595069766045,
-0.03627843037247658,
0.08432237803936005,
-0.036454495042562485,
-0.018027685582637787,
0.014185799285769463,
0.019063934683799744,
0.024052120745182037,
0.13925674557685852,
0.020840199664235115,
-0.028514724224805832,
0.042910490185022354,
0.016917141154408455,
0.04829605296254158,
0.028310034424066544,
-0.04427473619580269,
0.06712274253368378,
-0.05878952145576477,
-0.04138663783669472,
-0.016405180096626282,
0.023086288943886757,
0.04634135216474533,
0.004885486792773008,
0.03499419242143631,
-0.0144800478592515,
0.017683062702417374,
0.02635158784687519,
-0.017554165795445442,
0.04794672131538391,
0.009619475342333317,
-0.009846130385994911,
-0.03247716650366783,
-0.03546672686934471,
-0.03395216539502144,
0.04095086455345154,
0.055247072130441666,
0.09135093539953232,
-0.02294989675283432,
-0.13723929226398468,
-0.1180935949087143,
0.006184722296893597,
0.0020562843419611454,
0.04608835652470589,
-0.0035110798198729753,
0.058943115174770355,
0.07767489552497864,
-0.019529832527041435,
0.05343237146735191,
0.03539585694670677,
-0.04152713343501091,
-0.07543623447418213,
-0.043357644230127335,
0.0006807614699937403,
0.0034736113157123327,
0.017860811203718185,
0.019919460639357567,
0.04776415973901749,
0.025395581498742104,
-0.0652499720454216,
0.03798523545265198,
0.04917818307876587,
-0.01945214346051216,
0.06450624763965607,
-0.033390481024980545,
0.00706757977604866,
-0.0005142218433320522,
-0.02641284465789795,
-0.0010497757466509938,
-0.04405118152499199,
-0.04325217381119728,
-0.06042150780558586,
-0.004254356026649475,
-0.018986539915204048,
0.034500040113925934,
-0.008487789891660213,
-0.0723348930478096,
0.04441246762871742,
0.0354149304330349,
0.03353239223361015,
-0.04522619768977165,
-0.04406600445508957,
0.06779778003692627,
0.023883266374468803,
0.12477842718362808,
-0.01786421798169613,
-0.06330827623605728,
-0.03259017691016197,
-0.09847715497016907,
-5.9746693412191015e-33,
0.03615335002541542,
0.1504361927509308,
-0.044524237513542175,
0.04007315635681152,
-0.04499809816479683,
-0.07129140198230743,
-0.0049146125093102455,
-0.061963919550180435,
-0.027765454724431038,
0.00433298060670495,
-0.17718607187271118,
0.07744310796260834,
0.05781721696257591,
0.07508518546819687,
0.03000406175851822,
-0.06091049313545227,
-0.04305129125714302,
-0.0719681903719902,
0.10581295937299728,
-0.08872222155332565,
-0.014919133856892586,
0.023569468408823013,
0.03296962007880211,
0.06997045129537582,
-0.043566491454839706,
-0.052968580275774,
-0.04091484844684601,
-0.0014933468773961067,
-0.030252011492848396,
0.07333239912986755,
-0.09846841543912888,
0.005089679267257452,
-0.053887344896793365,
0.17052693665027618,
-0.004996899515390396,
-0.02623116783797741,
-0.0356232188642025,
0.055127907544374466,
0.03887361288070679,
-0.041500523686409,
0.02528165653347969,
0.03839704021811485,
0.02624848298728466,
-0.0311559047549963,
-0.005590768996626139,
0.07623956352472305,
-0.012310757301747799,
0.037759751081466675,
-0.028894558548927307,
-0.05210866779088974,
-0.07312357425689697,
0.05899414047598839,
-0.05451350286602974,
0.05585671216249466,
-0.003299095667898655,
-0.07546589523553848,
0.011645698919892311,
-0.020424913614988327,
-0.07863312214612961,
0.06532156467437744,
0.034251924604177475,
0.004286372102797031,
-0.01757323555648327,
-0.03305217996239662,
-0.10211224108934402,
-0.043620020151138306,
-0.03203124552965164,
-0.02132990024983883,
0.05132226273417473,
-0.030740607529878616,
0.019886169582605362,
-0.021228458732366562,
-0.04685990884900093,
-0.05129043012857437,
-0.05511900782585144,
0.061061132699251175,
-0.02554471231997013,
-0.03796060010790825,
0.017320318147540092,
0.04166504740715027,
0.025306684896349907,
0.03669027239084244,
-0.030561957508325577,
0.017444875091314316,
-0.010525100864470005,
-0.06345749646425247,
-0.07714254409074783,
0.04475652799010277,
-0.04702794551849365,
0.004939450416713953,
0.09395240247249603,
0.038521334528923035,
-0.044862184673547745,
-0.05090782791376114,
-0.005973904859274626,
-5.5879876725839495e-8,
-0.0059188553132116795,
-0.01715751364827156,
-0.030625829473137856,
-0.03576173633337021,
-0.09499922394752502,
-0.0896548479795456,
-0.03739481046795845,
-0.048998747020959854,
0.03304719552397728,
0.03877397999167442,
-0.018044045194983482,
-0.01564292050898075,
0.045321669429540634,
-0.013141309842467308,
-0.09248565882444382,
0.016588576138019562,
-0.0002358887140871957,
0.0076343463733792305,
-0.00452087027952075,
0.021987542510032654,
-0.04703734442591667,
0.07683410495519638,
-0.06299608200788498,
-0.015832452103495598,
-0.045234229415655136,
0.014148339629173279,
-0.009469627402722836,
0.057485878467559814,
-0.15298865735530853,
-0.004642066545784473,
0.04962928593158722,
-0.011928637512028217,
0.030504312366247177,
0.029061900451779366,
-0.08915510773658752,
-0.018908433616161346,
0.014825447462499142,
-0.001069523161277175,
0.020290598273277283,
-0.015088106505572796,
-0.012701248750090599,
-0.016763387247920036,
-0.002460435265675187,
-0.04913240671157837,
-0.062087029218673706,
-0.020789725705981255,
0.05322017893195152,
-0.030615463852882385,
-0.021774813532829285,
-0.0297652967274189,
0.02262100763618946,
-0.02223537676036358,
-0.04271427541971207,
-0.03509262576699257,
0.07171630859375,
0.005066912155598402,
0.030031906440854073,
-0.07002990692853928,
-0.029398631304502487,
0.042431753128767014,
-0.002905274974182248,
0.06661730259656906,
0.0012135481229051948,
-0.03501540794968605
] | 0.04815 |
import { exec } from 'node:child\_process'; const controller = new AbortController(); const { signal } = controller; const child = exec('grep ssh', { signal }, (error) => { console.error(error); // an AbortError }); controller.abort(); ``` ### `child\_process.execFile(file[, args][, options][, callback])` \* `file` {string} The name or path of the executable file to run. \* `args` {string\[]} List of string arguments. \* `options` {Object} \* `cwd` {string|URL} Current working directory of the child process. \* `env` {Object} Environment key-value pairs. \*\*Default:\*\* `process.env`. \* `encoding` {string} \*\*Default:\*\* `'utf8'` \* `timeout` {number} \*\*Default:\*\* `0` \* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated and any output is truncated. See caveat at [`maxBuffer` and Unicode][]. \*\*Default:\*\* `1024 \* 1024`. \* `killSignal` {string|integer} \*\*Default:\*\* `'SIGTERM'` \* `uid` {number} Sets the user identity of the process (see setuid(2)). \* `gid` {number} Sets the group identity of the process (see setgid(2)). \* `windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. \*\*Default:\*\* `false`. \* `windowsVerbatimArguments` {boolean} No quoting or escaping of arguments is done on Windows. Ignored on Unix. \*\*Default:\*\* `false`. \* `shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses `'/bin/sh'` on Unix, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell requirements][] and [Default Windows shell][]. \*\*Default:\*\* `false` (no shell). \* `signal` {AbortSignal} allows aborting the child process using an AbortSignal. \* `callback` {Function} Called with the output when process terminates. \* `error` {Error} \* `stdout` {string|Buffer} \* `stderr` {string|Buffer} \* Returns: {ChildProcess} The `child\_process.execFile()` function is similar to [`child\_process.exec()`][] except that it does not spawn a shell by default. Rather, the specified executable `file` is spawned directly as a new process making it slightly more efficient than [`child\_process.exec()`][]. The same options as [`child\_process.exec()`][] are supported. Since a shell is not spawned, behaviors such as I/O redirection and file globbing are not supported. ```cjs const { execFile } = require('node:child\_process'); const child = execFile('node', ['--version'], (error, stdout, stderr) => { if (error) { throw error; } console.log(stdout); }); ``` ```mjs import { execFile } from 'node:child\_process'; const child = execFile('node', ['--version'], (error, stdout, stderr) => { if (error) { throw error; } console.log(stdout); }); ``` The `stdout` and `stderr` arguments passed to the callback will contain the stdout and stderr output of the child process. By default, Node.js will decode the output as UTF-8 and pass strings to the callback. The `encoding` option can be used to specify the character encoding used to decode the stdout and stderr output. If `encoding` is `'buffer'`, or an unrecognized character encoding, `Buffer` objects will be passed to the callback instead. If this method is invoked as its [`util.promisify()`][]ed version, it returns a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned `ChildProcess` instance is attached to the `Promise` as a `child` property. In case of an error (including any error resulting in an exit code other than 0), a rejected promise is returned, with the same `error` object given in the callback, but with two additional properties `stdout` and `stderr`. ```cjs const util = require('node:util'); const execFile = util.promisify(require('node:child\_process').execFile); async function getVersion() { const { stdout } = await execFile('node', ['--version']); console.log(stdout); } getVersion(); ``` ```mjs import { promisify } from 'node:util'; import child\_process from 'node:child\_process'; const execFile = promisify(child\_process.execFile); async function getVersion() { const { stdout } = await execFile('node', ['--version']); console.log(stdout); } getVersion(); ``` \*\*If the `shell` option is enabled, do not pass unsanitized user input to this function. Any input containing shell metacharacters may be used to | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.020719140768051147,
0.0169678945094347,
-0.0869608223438263,
-0.004289610777050257,
0.044901493936777115,
-0.022113995626568794,
0.014308069832623005,
0.10280443727970123,
0.019913606345653534,
0.06808526813983917,
0.009422478266060352,
-0.0012915042461827397,
-0.06925182789564133,
0.004229927901178598,
0.027449002489447594,
0.05636618658900261,
-0.009898493066430092,
-0.0010424634674564004,
0.04888034611940384,
-0.05399748310446739,
0.03640640899538994,
0.04824013635516167,
0.0350034236907959,
0.027640532702207565,
-0.08265528827905655,
-0.039091192185878754,
0.00475188298150897,
-0.06597321480512619,
-0.06801917403936386,
-0.0025753360241651535,
0.02710006758570671,
-0.04118186607956886,
-0.03964610397815704,
0.005678666289895773,
0.004621319938451052,
0.1633327752351761,
0.03663681447505951,
-0.07900384068489075,
-0.026397638022899628,
-0.0012704035034403205,
0.07899851351976395,
0.0799967423081398,
-0.0967637151479721,
-0.09338980168104172,
0.024420173838734627,
-0.016300154849886894,
-0.08030536025762558,
-0.07804505527019501,
-0.038231298327445984,
-0.04911821708083153,
-0.05827558413147926,
0.025866666808724403,
-0.029964547604322433,
-0.011239326559007168,
0.04495462775230408,
-0.03662891685962677,
0.008652483113110065,
0.005573132541030645,
0.05852218717336655,
0.044116001576185226,
-0.002368826884776354,
0.015909036621451378,
-0.052904464304447174,
-0.06881808489561081,
0.011402403935790062,
0.028688406571745872,
0.0195913165807724,
-0.04105081409215927,
0.014399642124772072,
0.013717584311962128,
-0.013270421884953976,
-0.003301356453448534,
-0.09443936496973038,
-0.010986238718032837,
-0.10592157393693924,
-0.016639189794659615,
-0.014560114592313766,
-0.020531974732875824,
-0.10161787271499634,
-0.04042325168848038,
-0.05234880372881889,
-0.08073113858699799,
-0.09417456388473511,
-0.01702106185257435,
-0.018357984721660614,
0.09896796941757202,
0.011042657308280468,
-0.04921434074640274,
0.09020375460386276,
0.01531866192817688,
-0.09879858046770096,
-0.05797608941793442,
-0.031315140426158905,
0.02209932915866375,
0.08611641824245453,
0.059684135019779205,
-0.08066989481449127,
-0.04227324575185776,
-0.03097711317241192,
-0.05587651580572128,
-0.02225828915834427,
-0.008199547417461872,
0.026538647711277008,
-0.0050789956003427505,
0.021237416192889214,
-0.01912641152739525,
0.032826393842697144,
0.035900603979825974,
-0.023621229454874992,
-0.07281970232725143,
-0.06202377378940582,
-0.00985594093799591,
0.030699536204338074,
0.0754207968711853,
0.02033654972910881,
0.04990308731794357,
0.11911694705486298,
0.009666635654866695,
-0.029837921261787415,
0.11171207576990128,
0.11129972338676453,
0.020170077681541443,
-0.02339167520403862,
0.12274244427680969,
-0.005527396220713854,
-0.0753609836101532,
0.08653342723846436,
3.417933496008117e-33,
-0.012511472217738628,
-0.12430814653635025,
0.007533362600952387,
0.07798699289560318,
0.12495320290327072,
0.05702460929751396,
0.03374827280640602,
-0.026183759793639183,
-0.05122918263077736,
0.10183453559875488,
-0.11972495168447495,
-0.0630779042840004,
0.04923204332590103,
-0.04261146858334541,
0.062994584441185,
-0.021112315356731415,
0.006433629430830479,
0.0022004484198987484,
0.0796578899025917,
0.009717876091599464,
0.05813918262720108,
-0.022566750645637512,
-0.07196061313152313,
0.03650224953889847,
0.007350895553827286,
-0.042245473712682724,
-0.05010262131690979,
0.0024644655641168356,
0.07961349934339523,
-0.04151969775557518,
0.09914001077413559,
0.020363591611385345,
-0.02023034542798996,
0.018000420182943344,
0.0069909472949802876,
-0.08657544106245041,
0.081764355301857,
0.05559314787387848,
-0.04505203664302826,
-0.03508111834526062,
0.04913566634058952,
0.0007694364176131785,
-0.06705878674983978,
0.09547457844018936,
-0.03928239643573761,
-0.07379240542650223,
-0.009033441543579102,
-0.07004956901073456,
0.07627268880605698,
0.030520537868142128,
0.04203789308667183,
0.028877977281808853,
0.035866931080818176,
-0.01099395751953125,
0.016448572278022766,
0.03244590386748314,
-0.058133408427238464,
-0.05482742190361023,
-0.01437163446098566,
-0.01111285574734211,
0.016253357753157616,
-0.010337946005165577,
-0.023483198136091232,
-0.025794172659516335,
0.027290096506476402,
-0.09194876998662949,
0.012464976869523525,
0.003721083514392376,
-0.0014699675375595689,
-0.0022933161817491055,
-0.0942569375038147,
-0.041056688874959946,
0.05085454881191254,
-0.06284036487340927,
0.01968170516192913,
-0.03287534415721893,
-0.0028037866577506065,
-0.006477610673755407,
-0.01965775154531002,
-0.025581493973731995,
0.02614717185497284,
-0.009551608934998512,
-0.06252371519804001,
-0.02391302026808262,
0.08212801069021225,
0.0249551422894001,
-0.09161759912967682,
-0.042088381946086884,
0.025711029767990112,
0.0042534940876066685,
-0.018660152330994606,
-0.029216531664133072,
-0.03158476576209068,
-0.02684721164405346,
-0.034529656171798706,
-7.014844823136558e-33,
0.0870782658457756,
-0.05005640536546707,
0.0195775106549263,
-0.013431364670395851,
0.0713493749499321,
-0.017943838611245155,
-0.02683871053159237,
-0.061098210513591766,
-0.017780378460884094,
0.03519793972373009,
-0.0801386907696724,
0.016696233302354813,
0.10041381418704987,
0.052349578589200974,
-0.0307833943516016,
-0.017000343650579453,
-0.07195323705673218,
-0.015248605981469154,
0.017884114757180214,
-0.05668595805764198,
0.008472616784274578,
-0.019639084115624428,
0.05954822897911072,
0.054757650941610336,
0.009838019497692585,
0.025889042764902115,
-0.007114232983440161,
0.030689924955368042,
-0.0466451421380043,
-0.02289609983563423,
-0.04716340824961662,
0.005197199061512947,
-0.02773088589310646,
0.12676109373569489,
0.003228801069781184,
-0.027734367176890373,
0.01897871308028698,
0.12753012776374817,
-0.01432063803076744,
-0.0010719123529270291,
0.1138518676161766,
0.03068424202501774,
0.001179286977276206,
0.02480264939367771,
0.022100867703557014,
0.034610647708177567,
0.06858709454536438,
0.03850405663251877,
-0.08398326486349106,
0.00904691219329834,
-0.028180278837680817,
0.019946211948990822,
-0.00023560691624879837,
0.020522333681583405,
0.028424980118870735,
-0.0014958931133151054,
0.04951360821723938,
-0.007100057788193226,
-0.01563441753387451,
0.015327263623476028,
0.08709681779146194,
-0.08445920795202255,
0.014362504705786705,
-0.03997717425227165,
-0.01586487703025341,
-0.050521064549684525,
-0.06731037050485611,
0.04306132346391678,
0.0682111456990242,
-0.016930844634771347,
-0.01672431267797947,
0.056434351950883865,
-0.06563662737607956,
0.022903194651007652,
-0.04704766348004341,
-0.033719275146722794,
-0.045673247426748276,
-0.07451929897069931,
0.03086548112332821,
0.09446901828050613,
0.061054423451423645,
0.06445522606372833,
-0.05532551556825638,
0.027723165228962898,
0.001342838048003614,
0.008604271337389946,
-0.0512574277818203,
0.07477045059204102,
-0.016259850934147835,
-0.026560602709650993,
0.020839404314756393,
0.004754651337862015,
0.04678233340382576,
-0.03592817857861519,
0.00015837566752452403,
-5.1044690252410874e-8,
0.006045908201485872,
-0.029478108510375023,
0.0052880519069731236,
-0.016748987138271332,
-0.014401519671082497,
-0.014257020317018032,
-0.00550055131316185,
-0.0471658892929554,
0.022134363651275635,
-0.031188523396849632,
-0.05074073001742363,
-0.004063197877258062,
0.006300910376012325,
0.059434182941913605,
-0.015156183391809464,
-0.06897541880607605,
0.029258158057928085,
0.025666924193501472,
0.05944204702973366,
0.016918936744332314,
0.06552045047283173,
-0.028850583359599113,
-0.03588687255978584,
0.10555825382471085,
-0.05418854206800461,
-0.021779322996735573,
0.04599041864275932,
0.010927095077931881,
-0.14561288058757782,
0.00898012425750494,
0.018143564462661743,
-0.026334431022405624,
0.020224180072546005,
0.06287557631731033,
-0.06446665525436401,
-0.010920101776719093,
-0.001440788502804935,
-0.00533329276368022,
-0.005418088752776384,
0.001539910794235766,
-0.012529207393527031,
0.13430480659008026,
-0.036593034863471985,
-0.0018816505325958133,
0.007999259047210217,
-0.04583301022648811,
-0.0021318665239959955,
0.000580182415433228,
0.03880532085895538,
0.08136902749538422,
0.013006379827857018,
-0.05099564418196678,
-0.060151319950819016,
0.022915257140994072,
-0.0034361633006483316,
0.007901784963905811,
-0.02225157991051674,
-0.1641148179769516,
-0.05287891998887062,
0.07106337696313858,
0.05599048361182213,
0.005570214707404375,
-0.019816037267446518,
0.0251290425658226
] | 0.078502 |
from 'node:util'; import child\_process from 'node:child\_process'; const execFile = promisify(child\_process.execFile); async function getVersion() { const { stdout } = await execFile('node', ['--version']); console.log(stdout); } getVersion(); ``` \*\*If the `shell` option is enabled, do not pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.\*\* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except the error passed to the callback will be an `AbortError`: ```cjs const { execFile } = require('node:child\_process'); const controller = new AbortController(); const { signal } = controller; const child = execFile('node', ['--version'], { signal }, (error) => { console.error(error); // an AbortError }); controller.abort(); ``` ```mjs import { execFile } from 'node:child\_process'; const controller = new AbortController(); const { signal } = controller; const child = execFile('node', ['--version'], { signal }, (error) => { console.error(error); // an AbortError }); controller.abort(); ``` ### `child\_process.fork(modulePath[, args][, options])` \* `modulePath` {string|URL} The module to run in the child. \* `args` {string\[]} List of string arguments. \* `options` {Object} \* `cwd` {string|URL} Current working directory of the child process. \* `detached` {boolean} Prepare child process to run independently of its parent process. Specific behavior depends on the platform (see [`options.detached`][]). \* `env` {Object} Environment key-value pairs. \*\*Default:\*\* `process.env`. \* `execPath` {string} Executable used to create the child process. \* `execArgv` {string\[]} List of string arguments passed to the executable. \*\*Default:\*\* `process.execArgv`. \* `gid` {number} Sets the group identity of the process (see setgid(2)). \* `serialization` {string} Specify the kind of serialization used for sending messages between processes. Possible values are `'json'` and `'advanced'`. See [Advanced serialization][] for more details. \*\*Default:\*\* `'json'`. \* `signal` {AbortSignal} Allows closing the child process using an AbortSignal. \* `killSignal` {string|integer} The signal value to be used when the spawned process will be killed by timeout or abort signal. \*\*Default:\*\* `'SIGTERM'`. \* `silent` {boolean} If `true`, stdin, stdout, and stderr of the child process will be piped to the parent process, otherwise they will be inherited from the parent process, see the `'pipe'` and `'inherit'` options for [`child\_process.spawn()`][]'s [`stdio`][] for more details. \*\*Default:\*\* `false`. \* `stdio` {Array|string} See [`child\_process.spawn()`][]'s [`stdio`][]. When this option is provided, it overrides `silent`. If the array variant is used, it must contain exactly one item with value `'ipc'` or an error will be thrown. For instance `[0, 1, 2, 'ipc']`. \* `uid` {number} Sets the user identity of the process (see setuid(2)). \* `windowsVerbatimArguments` {boolean} No quoting or escaping of arguments is done on Windows. Ignored on Unix. \*\*Default:\*\* `false`. \* `timeout` {number} In milliseconds the maximum amount of time the process is allowed to run. \*\*Default:\*\* `undefined`. \* Returns: {ChildProcess} The `child\_process.fork()` method is a special case of [`child\_process.spawn()`][] used specifically to spawn new Node.js processes. Like [`child\_process.spawn()`][], a [`ChildProcess`][] object is returned. The returned [`ChildProcess`][] will have an additional communication channel built-in that allows messages to be passed back and forth between the parent and child. See [`subprocess.send()`][] for details. Keep in mind that spawned Node.js child processes are independent of the parent with exception of the IPC communication channel that is established between the two. Each process has its own memory, with their own V8 instances. Because of the additional resource allocations required, spawning a large number of child Node.js processes is not recommended. By default, `child\_process.fork()` will spawn new Node.js instances using the [`process.execPath`][] of the parent process. The `execPath` property in the `options` object allows for an alternative execution path to be used. Node.js processes launched with a custom `execPath` will communicate with | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
0.014906764961779118,
0.025654831901192665,
-0.06803432106971741,
0.045266106724739075,
0.066661536693573,
-0.031989604234695435,
-0.03136610612273216,
0.10003844648599625,
-0.011044728569686413,
0.03323088586330414,
-0.0011709860991686583,
-0.01978326216340065,
-0.09289873391389847,
-0.02992389164865017,
-0.0023006496485322714,
0.005244399420917034,
0.02510771155357361,
-0.022296546027064323,
-0.0016492011491209269,
-0.07302650809288025,
-0.03225598484277725,
-0.022085484117269516,
0.07332884520292282,
0.02379644848406315,
-0.043004557490348816,
-0.05673160403966904,
-0.03915342316031456,
-0.06230271980166435,
-0.010796716436743736,
0.006168335676193237,
0.023081796243786812,
-0.037531450390815735,
-0.01696881838142872,
-0.017446601763367653,
-0.02719375491142273,
0.1637360155582428,
0.015123642981052399,
-0.07506868243217468,
-0.01912017911672592,
-0.03340855985879898,
0.03919209539890289,
0.07912290841341019,
-0.12135393917560577,
-0.06608147919178009,
0.04954789578914642,
-0.09081026911735535,
-0.16026723384857178,
-0.021331552416086197,
-0.07626228779554367,
0.02587694302201271,
-0.008909092284739017,
0.018148520961403847,
-0.05116153135895729,
-0.007722241338342428,
-0.011000399477779865,
-0.010020541958510876,
0.02060716040432453,
0.0053599681705236435,
0.05376965180039406,
0.01723722368478775,
-0.11578276008367538,
0.0021481444127857685,
-0.03008316084742546,
-0.06757964938879013,
0.050234369933605194,
0.04375265911221504,
0.021856900304555893,
-0.0880536139011383,
0.07418946921825409,
0.00441092811524868,
-0.02897878736257553,
-0.0439065657556057,
-0.03840646892786026,
-0.00848574098199606,
-0.07160433381795883,
0.04443081468343735,
0.03035491332411766,
0.01856459490954876,
-0.05011200159788132,
-0.04901957884430885,
-0.0385429821908474,
-0.036913175135850906,
-0.04154392331838608,
-0.005594239104539156,
-0.07615900039672852,
0.11349239200353622,
-0.0037504909560084343,
-0.02153758332133293,
0.09142293781042099,
0.02788429893553257,
-0.11259584128856659,
-0.04105158895254135,
-0.0029984540306031704,
0.022985363379120827,
0.009114852175116539,
0.06570962071418762,
-0.0374496765434742,
0.0009962179465219378,
-0.03913426771759987,
0.012801019474864006,
-0.005039777606725693,
-0.03244730830192566,
-0.009211885742843151,
-0.04935268685221672,
0.027681756764650345,
-0.046766769140958786,
0.019239485263824463,
-0.019148319959640503,
-0.006326232571154833,
-0.07151749730110168,
-0.04459536448121071,
0.009365048259496689,
-0.023120736703276634,
-0.010610713623464108,
-0.00838761031627655,
0.01901027373969555,
0.16353410482406616,
-0.010085306130349636,
0.03414271026849747,
0.06373977661132812,
0.15309876203536987,
0.0025904809590429068,
-0.002610530238598585,
0.07458806037902832,
0.026882996782660484,
-0.11191629618406296,
0.04835045710206032,
5.1509166956254286e-33,
-0.02079361118376255,
-0.08176840096712112,
0.03082858771085739,
0.06778977811336517,
0.09572862833738327,
0.07426543533802032,
0.043042995035648346,
-0.03257519751787186,
-0.08818336576223373,
0.0434999018907547,
-0.0730498880147934,
-0.07159172743558884,
-0.0019885043147951365,
-0.06694314628839493,
0.0847347155213356,
-0.035682983696460724,
0.029129059985280037,
-0.0324430838227272,
0.018737370148301125,
-0.0028380227740854025,
0.14347554743289948,
-0.017682833597064018,
-0.06493794173002243,
0.05693082511425018,
0.06096364185214043,
-0.05955010652542114,
-0.08789645880460739,
0.10493485629558563,
0.026444802060723305,
-0.018131259828805923,
0.03850368410348892,
-0.02466883696615696,
-0.010092423297464848,
0.019954195246100426,
-0.01918545365333557,
-0.054205842316150665,
0.004222298972308636,
0.05071289464831352,
-0.029324296861886978,
-0.023880332708358765,
0.009860390797257423,
-0.0023068164009600878,
-0.0634341612458229,
0.01485894899815321,
0.023167982697486877,
-0.10965844988822937,
-0.09972640126943588,
-0.025868941098451614,
0.0713810995221138,
-0.04347606375813484,
0.0535275936126709,
0.07682982087135315,
0.0334758386015892,
-0.060887809842824936,
0.05219476297497749,
0.06797613948583603,
0.020125798881053925,
-0.055322758853435516,
0.010949818417429924,
-0.030125301331281662,
0.11425802856683731,
-0.042275529354810715,
-0.05619019269943237,
0.007525973487645388,
-0.01991398259997368,
-0.019292425364255905,
-0.04642406105995178,
-0.03311464935541153,
0.019682718440890312,
0.0362163744866848,
-0.09944044053554535,
0.015005400404334068,
-0.008844802156090736,
-0.06365237385034561,
0.023420657962560654,
0.03162219375371933,
-0.03646053373813629,
-0.030617959797382355,
0.02516491338610649,
-0.007840193808078766,
0.0190042145550251,
-0.02893323451280594,
-0.06253687292337418,
0.027932586148381233,
0.12251162528991699,
-0.01950390450656414,
-0.07722955197095871,
0.006185060366988182,
0.03716004267334938,
-0.015587368048727512,
0.05322843790054321,
-0.02722807414829731,
-0.053798336535692215,
-0.04271838814020157,
-0.023997634649276733,
-8.880025954157268e-33,
0.03863350674510002,
0.05344920977950096,
-0.008212670683860779,
0.021559767425060272,
-0.03461445868015289,
-0.03715653344988823,
-0.034575629979372025,
-0.074643075466156,
-0.0756726861000061,
-0.0027572365943342447,
-0.07208295911550522,
0.05088082700967789,
0.03576626628637314,
0.09624940156936646,
-0.03942074254155159,
0.019795745611190796,
-0.0364692397415638,
-0.008337501436471939,
0.05391426011919975,
0.021284259855747223,
-0.037810493260622025,
-0.004537506960332394,
0.032746899873018265,
0.061926212161779404,
-0.03639094904065132,
-0.07277124375104904,
-0.015027720481157303,
0.025279106572270393,
-0.0019670124165713787,
-0.03650100901722908,
-0.05756446346640587,
0.03801896423101425,
-0.013651713728904724,
0.08356023579835892,
0.06518685072660446,
-0.043837547302246094,
0.007508171256631613,
0.08229115605354309,
0.005881279706954956,
0.02715526893734932,
0.08285139501094818,
-0.020283803343772888,
-0.028513433411717415,
0.004573960788547993,
0.0087922103703022,
0.0286223366856575,
0.03752245008945465,
0.06218107044696808,
-0.0471111461520195,
0.014962304383516312,
-0.004125841893255711,
0.00979640893638134,
-0.0016025553923100233,
0.03662071377038956,
-0.02167162112891674,
-0.04235885292291641,
0.020891588181257248,
-0.013501990586519241,
-0.02007889188826084,
0.027354983612895012,
0.040934477001428604,
-0.12071879953145981,
0.03710135817527771,
-0.06958221644163132,
0.012443656101822853,
-0.010331446304917336,
-0.07216141372919083,
0.05722447484731674,
0.08988111466169357,
0.019819745793938637,
0.09826870262622833,
0.032528363168239594,
-0.06430578231811523,
0.014246927574276924,
-0.02018211968243122,
-0.0341620109975338,
-0.039101313799619675,
-0.08486749976873398,
0.022692857310175896,
0.06448496133089066,
0.01860443875193596,
0.06742914766073227,
0.012162379920482635,
0.00801774300634861,
-0.012115869671106339,
-0.0017431718297302723,
-0.049722783267498016,
0.04859433323144913,
-0.009924874641001225,
-0.0013997351052239537,
0.04353083670139313,
-0.01511947251856327,
-0.05130293592810631,
-0.04394758492708206,
-0.011151365004479885,
-6.056379930896583e-8,
-0.05054810643196106,
0.020708875730633736,
-0.051683057099580765,
0.014127567410469055,
0.05271340161561966,
0.0038072322495281696,
-0.019721252843737602,
-0.14418213069438934,
0.03920741006731987,
0.0035984704736620188,
-0.05980130285024643,
-0.020384283736348152,
0.026171032339334488,
0.017216037958860397,
0.03310069441795349,
0.03895847499370575,
0.03431675583124161,
0.07944904267787933,
0.0526449978351593,
0.004043240565806627,
-0.03433871269226074,
0.039898671209812164,
0.001165810041129589,
0.044496145099401474,
-0.03234133496880531,
-0.08031987398862839,
0.02176740951836109,
0.08247022330760956,
-0.06407320499420166,
0.014497253112494946,
0.004167335573583841,
-0.00011957290553255007,
0.05059046670794487,
0.03400728106498718,
-0.02654891647398472,
-0.007944710552692413,
0.004798745736479759,
0.018045688048005104,
0.042120251804590225,
0.027968740090727806,
0.05199740454554558,
0.1382090449333191,
-0.06481161713600159,
0.027795815840363503,
-0.04819253832101822,
-0.022223522886633873,
0.037191204726696014,
-0.0352298878133297,
0.024410074576735497,
0.08346473425626755,
0.00015244843962136656,
-0.0147634856402874,
-0.05943393334746361,
0.01936437375843525,
-0.004961531143635511,
-0.007483257912099361,
-0.04702188819646835,
-0.09636054188013077,
-0.06491362303495407,
0.08799783885478973,
0.05011224374175072,
0.03831636533141136,
0.06817397475242615,
-0.03005622699856758
] | 0.091084 |
large number of child Node.js processes is not recommended. By default, `child\_process.fork()` will spawn new Node.js instances using the [`process.execPath`][] of the parent process. The `execPath` property in the `options` object allows for an alternative execution path to be used. Node.js processes launched with a custom `execPath` will communicate with the parent process using the file descriptor (fd) identified using the environment variable `NODE\_CHANNEL\_FD` on the child process. Unlike the fork(2) POSIX system call, `child\_process.fork()` does not clone the current process. The `shell` option available in [`child\_process.spawn()`][] is not supported by `child\_process.fork()` and will be ignored if set. If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except the error passed to the callback will be an `AbortError`: ```cjs const { fork } = require('node:child\_process'); const process = require('node:process'); if (process.argv[2] === 'child') { setTimeout(() => { console.log(`Hello from ${process.argv[2]}!`); }, 1\_000); } else { const controller = new AbortController(); const { signal } = controller; const child = fork(\_\_filename, ['child'], { signal }); child.on('error', (err) => { // This will be called with err being an AbortError if the controller aborts }); controller.abort(); // Stops the child process } ``` ```mjs import { fork } from 'node:child\_process'; import process from 'node:process'; if (process.argv[2] === 'child') { setTimeout(() => { console.log(`Hello from ${process.argv[2]}!`); }, 1\_000); } else { const controller = new AbortController(); const { signal } = controller; const child = fork(import.meta.url, ['child'], { signal }); child.on('error', (err) => { // This will be called with err being an AbortError if the controller aborts }); controller.abort(); // Stops the child process } ``` ### `child\_process.spawn(command[, args][, options])` \* `command` {string} The command to run. \* `args` {string\[]} List of string arguments. \* `options` {Object} \* `cwd` {string|URL} Current working directory of the child process. \* `env` {Object} Environment key-value pairs. \*\*Default:\*\* `process.env`. \* `argv0` {string} Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` if not specified. \* `stdio` {Array|string} Child's stdio configuration (see [`options.stdio`][`stdio`]). \* `detached` {boolean} Prepare child process to run independently of its parent process. Specific behavior depends on the platform (see [`options.detached`][]). \* `uid` {number} Sets the user identity of the process (see setuid(2)). \* `gid` {number} Sets the group identity of the process (see setgid(2)). \* `serialization` {string} Specify the kind of serialization used for sending messages between processes. Possible values are `'json'` and `'advanced'`. See [Advanced serialization][] for more details. \*\*Default:\*\* `'json'`. \* `shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses `'/bin/sh'` on Unix, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell requirements][] and [Default Windows shell][]. \*\*Default:\*\* `false` (no shell). \* `windowsVerbatimArguments` {boolean} No quoting or escaping of arguments is done on Windows. Ignored on Unix. This is set to `true` automatically when `shell` is specified and is CMD. \*\*Default:\*\* `false`. \* `windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. \*\*Default:\*\* `false`. \* `signal` {AbortSignal} allows aborting the child process using an AbortSignal. \* `timeout` {number} In milliseconds the maximum amount of time the process is allowed to run. \*\*Default:\*\* `undefined`. \* `killSignal` {string|integer} The signal value to be used when the spawned process will be killed by timeout or abort signal. \*\*Default:\*\* `'SIGTERM'`. \* Returns: {ChildProcess} The `child\_process.spawn()` method spawns a new process using the given `command`, with command-line arguments in `args`. If omitted, `args` defaults to an empty array. \*\*If the `shell` option is enabled, do not pass unsanitized user input to this | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.06309713423252106,
-0.06803356856107712,
-0.011996285058557987,
-0.025982361286878586,
0.0668126717209816,
-0.11892955750226974,
-0.03377866372466087,
0.11934884637594223,
0.04434608668088913,
0.08225999772548676,
-0.021778149530291557,
0.04786982759833336,
-0.05288064479827881,
-0.01314103975892067,
0.03518039733171463,
0.029633542522788048,
0.04049645736813545,
-0.0033218450844287872,
0.016808204352855682,
-0.046261440962553024,
0.048098061233758926,
0.0016672495985403657,
0.09308948367834091,
-0.019243283197283745,
-0.0223421398550272,
-0.04359469190239906,
-0.02743384800851345,
-0.04132045805454254,
0.01132797822356224,
-0.03971633315086365,
0.04232010245323181,
0.006516780238598585,
-0.05642760545015335,
-0.06569767743349075,
-0.020744429901242256,
0.17852041125297546,
0.04703884571790695,
-0.09188748151063919,
-0.05728032812476158,
-0.014981552958488464,
0.10174313187599182,
0.10961981862783432,
-0.07862453907728195,
-0.09322600811719894,
0.007758729625493288,
-0.006803958676755428,
-0.07444173842668533,
-0.041892293840646744,
-0.03861051797866821,
-0.030200170353055,
0.01673334836959839,
-0.012186598964035511,
0.004533607512712479,
0.010667233727872372,
-0.03526487573981285,
-0.04812457412481308,
0.056372202932834625,
-0.02075074054300785,
0.05360623449087143,
0.12651893496513367,
-0.04752803593873978,
0.05156179890036583,
-0.006651339586824179,
-0.013572928495705128,
0.055688511580228806,
0.03965242579579353,
-0.00175670615863055,
-0.06566119194030762,
0.017157480120658875,
0.004317818209528923,
0.049530815333127975,
0.011721393093466759,
-0.036033693701028824,
0.006536053027957678,
-0.04570752754807472,
-0.09015798568725586,
0.0015238909982144833,
0.012793469242751598,
-0.09596897661685944,
0.002506865421310067,
-0.0843006819486618,
-0.04215146228671074,
0.006555407308042049,
-0.04768029600381851,
-0.075166255235672,
0.06793022155761719,
-0.021879244595766068,
-0.043061863631010056,
0.059070415794849396,
0.09571746736764908,
-0.10055220872163773,
0.005398701410740614,
0.023056771606206894,
0.07225746661424637,
0.01711534522473812,
0.02044404298067093,
-0.028158197179436684,
0.028064822778105736,
-0.022514453157782555,
-0.05932694673538208,
-0.007403879426419735,
0.0027622312773019075,
0.022512609139084816,
0.027672434225678444,
0.011370387859642506,
-0.02766750194132328,
-0.06466294080018997,
0.011465055868029594,
-0.04958631843328476,
-0.060718655586242676,
-0.025105226784944534,
0.033482152968645096,
0.018942559137940407,
0.0774666965007782,
-0.006387247703969479,
-0.0017305390210822225,
0.08927693963050842,
-0.020374080166220665,
-0.001337895984761417,
0.12522931396961212,
0.10920090228319168,
0.04868420585989952,
0.007953658699989319,
0.04539032280445099,
0.01904018223285675,
-0.05161347985267639,
-0.006475783418864012,
1.805992602733907e-33,
-0.019339224323630333,
-0.04404006898403168,
0.05342136323451996,
0.04202491044998169,
0.08150539547204971,
0.03572297468781471,
-0.010735392570495605,
0.0248073972761631,
-0.08499378710985184,
0.026379114016890526,
-0.04995923116803169,
-0.0743776336312294,
0.011740924790501595,
-0.03477603197097778,
0.03604038432240486,
-0.057480715215206146,
0.034254129976034164,
-0.0036267531104385853,
0.06359618902206421,
0.03792282193899155,
0.053411759436130524,
0.025592859834432602,
-0.0582612007856369,
0.07933183759450912,
0.06127221882343292,
-0.01533556543290615,
-0.05424794927239418,
0.03070620261132717,
0.07730153948068619,
-0.01746649667620659,
-0.024580398574471474,
0.02873351238667965,
-0.022286372259259224,
-0.004535841289907694,
-0.013194900006055832,
-0.021596038714051247,
0.05102003365755081,
0.0320904403924942,
-0.07234586030244827,
-0.07014134526252747,
0.02157967910170555,
0.029543714597821236,
-0.08029145747423172,
0.01747400499880314,
-0.02965678833425045,
-0.07473970949649811,
-0.09255383908748627,
-0.0424627847969532,
0.033574216067790985,
0.055649690330028534,
0.0314115509390831,
-0.00674571143463254,
0.08400136977434158,
-0.009273244068026543,
0.002467711456120014,
0.043072715401649475,
-0.05940385162830353,
-0.06624588370323181,
-0.0008095355588011444,
0.02057577483355999,
0.11031390726566315,
-0.029574666172266006,
-0.04511048272252083,
0.03869929537177086,
0.027845200151205063,
0.018010636791586876,
0.0575944185256958,
0.02813573367893696,
0.02211836911737919,
0.033965207636356354,
-0.09583090245723724,
0.04016377404332161,
-0.002163756638765335,
-0.03074205107986927,
0.07334641367197037,
-0.05355152487754822,
0.0022472830023616552,
-0.07529038935899734,
-0.052925121039152145,
0.034931182861328125,
-0.0003811615752056241,
0.03336135298013687,
-0.06784987449645996,
-0.04169607162475586,
0.10171754658222198,
0.0005612961249426007,
-0.0732966735959053,
-0.014696306549012661,
-0.0032761546317487955,
0.022048676386475563,
0.05590243265032768,
-0.043975960463285446,
-0.0005634600529447198,
0.01450534537434578,
-0.08797240257263184,
-4.479114694632783e-33,
0.011673273518681526,
-0.04665730521082878,
-0.03490917384624481,
0.03930674120783806,
-0.024696165695786476,
-0.08020702749490738,
-0.03728305175900459,
-0.01672457344830036,
-0.055369023233652115,
-0.037399232387542725,
-0.09963945299386978,
0.013083591125905514,
0.024438414722681046,
0.07640570402145386,
-0.09901870787143707,
-0.007956420071423054,
0.009949778206646442,
0.032248854637145996,
0.07088040560483932,
-0.0394752137362957,
-0.0914449617266655,
0.03813203051686287,
0.023685935884714127,
-0.0017325937515124679,
-0.032289061695337296,
-0.034864697605371475,
-0.09954068809747696,
0.032126519829034805,
0.013616074807941914,
-0.03656177595257759,
-0.040880315005779266,
0.028857983648777008,
0.05020229145884514,
0.07380210608243942,
-0.00013504399976227432,
-0.006773287430405617,
-0.02051623910665512,
0.061548031866550446,
0.060247551649808884,
-0.10402095317840576,
0.06189713627099991,
-0.04378220811486244,
-0.014319336041808128,
-0.019281458109617233,
0.012622290290892124,
0.05109341815114021,
0.02353692427277565,
0.02856503240764141,
-0.09375601261854172,
0.004105313681066036,
-0.0034936796873807907,
0.06902074068784714,
0.04320915788412094,
0.07300709933042526,
0.021890752017498016,
-0.026315879076719284,
0.062022123485803604,
0.05704168602824211,
0.0556160993874073,
-0.030007783323526382,
0.13564428687095642,
-0.07358728349208832,
-0.06752819567918777,
0.002457371912896633,
-0.0032386528328061104,
-0.03246814385056496,
-0.05674002692103386,
0.02790973149240017,
0.06155865266919136,
-0.0001184181819553487,
0.008908393792808056,
0.0677541121840477,
-0.031242499127984047,
0.007955024018883705,
-0.07064260542392731,
0.018289659172296524,
-0.02116188406944275,
-0.09040449559688568,
-0.020943032577633858,
0.039618924260139465,
-0.06955874711275101,
0.09408525377511978,
-0.06043586507439613,
0.027265945449471474,
-0.01245869416743517,
-0.027443844825029373,
0.03932955861091614,
-0.017892181873321533,
-0.010268904268741608,
-0.01676761731505394,
0.025115441530942917,
-0.013527082279324532,
-0.04048333317041397,
-0.03494063392281532,
-0.02088889107108116,
-5.6743989063079425e-8,
0.06719687581062317,
0.05779849737882614,
-0.05735107138752937,
-0.001717537408694625,
0.022789431735873222,
-0.01890295371413231,
0.02913489378988743,
0.03444021940231323,
0.007363755721598864,
0.03985873609781265,
-0.07503361254930496,
0.036801230162382126,
0.019717885181307793,
0.008010211400687695,
0.0440957136452198,
0.013121290132403374,
0.03535535931587219,
0.03550475090742111,
0.03289608284831047,
-0.011575479991734028,
0.002161511452868581,
-0.009567039087414742,
-0.06684635579586029,
0.11876915395259857,
-0.12871244549751282,
-0.07826842367649078,
0.08065078407526016,
0.015618872828781605,
-0.07851378619670868,
-0.06859178096055984,
-0.06114508584141731,
-0.002494610147550702,
-0.006147813517600298,
0.08681163191795349,
-0.03657995164394379,
-0.013311523012816906,
-0.10821820050477982,
0.03716185316443443,
0.06478468328714371,
0.049933794885873795,
-0.00383964367210865,
0.05368240177631378,
-0.0073061129078269005,
-0.004782600793987513,
-0.03257225453853607,
0.03577156364917755,
-0.03892168775200844,
0.012347189709544182,
0.005258924327790737,
0.06347095221281052,
0.057378482073545456,
0.004024313297122717,
-0.05912843346595764,
-0.009936175309121609,
0.05079449340701103,
0.0739298015832901,
0.015972383320331573,
-0.09424706548452377,
-0.04803525283932686,
0.041960835456848145,
0.03299515321850777,
0.046430762857198715,
0.051062725484371185,
-0.04528643190860748
] | 0.053699 |
be killed by timeout or abort signal. \*\*Default:\*\* `'SIGTERM'`. \* Returns: {ChildProcess} The `child\_process.spawn()` method spawns a new process using the given `command`, with command-line arguments in `args`. If omitted, `args` defaults to an empty array. \*\*If the `shell` option is enabled, do not pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.\*\* A third argument may be used to specify additional options, with these defaults: ```js const defaults = { cwd: undefined, env: process.env, }; ``` Use `cwd` to specify the working directory from which the process is spawned. If not given, the default is to inherit the current working directory. If given, but the path does not exist, the child process emits an `ENOENT` error and exits immediately. `ENOENT` is also emitted when the command does not exist. Use `env` to specify environment variables that will be visible to the new process, the default is [`process.env`][]. `undefined` values in `env` will be ignored. Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the exit code: ```cjs const { spawn } = require('node:child\_process'); const ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.stderr.on('data', (data) => { console.error(`stderr: ${data}`); }); ls.on('close', (code) => { console.log(`child process exited with code ${code}`); }); ``` ```mjs import { spawn } from 'node:child\_process'; import { once } from 'node:events'; const ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.stderr.on('data', (data) => { console.error(`stderr: ${data}`); }); const [code] = await once(ls, 'close'); console.log(`child process exited with code ${code}`); ``` Example: A very elaborate way to run `ps ax | grep ssh` ```cjs const { spawn } = require('node:child\_process'); const ps = spawn('ps', ['ax']); const grep = spawn('grep', ['ssh']); ps.stdout.on('data', (data) => { grep.stdin.write(data); }); ps.stderr.on('data', (data) => { console.error(`ps stderr: ${data}`); }); ps.on('close', (code) => { if (code !== 0) { console.log(`ps process exited with code ${code}`); } grep.stdin.end(); }); grep.stdout.on('data', (data) => { console.log(data.toString()); }); grep.stderr.on('data', (data) => { console.error(`grep stderr: ${data}`); }); grep.on('close', (code) => { if (code !== 0) { console.log(`grep process exited with code ${code}`); } }); ``` ```mjs import { spawn } from 'node:child\_process'; const ps = spawn('ps', ['ax']); const grep = spawn('grep', ['ssh']); ps.stdout.on('data', (data) => { grep.stdin.write(data); }); ps.stderr.on('data', (data) => { console.error(`ps stderr: ${data}`); }); ps.on('close', (code) => { if (code !== 0) { console.log(`ps process exited with code ${code}`); } grep.stdin.end(); }); grep.stdout.on('data', (data) => { console.log(data.toString()); }); grep.stderr.on('data', (data) => { console.error(`grep stderr: ${data}`); }); grep.on('close', (code) => { if (code !== 0) { console.log(`grep process exited with code ${code}`); } }); ``` Example of checking for failed `spawn`: ```cjs const { spawn } = require('node:child\_process'); const subprocess = spawn('bad\_command'); subprocess.on('error', (err) => { console.error('Failed to start subprocess.'); }); ``` ```mjs import { spawn } from 'node:child\_process'; const subprocess = spawn('bad\_command'); subprocess.on('error', (err) => { console.error('Failed to start subprocess.'); }); ``` Certain platforms (macOS, Linux) will use the value of `argv[0]` for the process title while others (Windows, SunOS) will use `command`. Node.js overwrites `argv[0]` with `process.execPath` on startup, so `process.argv[0]` in a Node.js child process will not match the `argv0` parameter passed to `spawn` from the parent. Retrieve it with the `process.argv0` property instead. If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except the error passed to the callback will be an `AbortError`: ```cjs const { spawn } = require('node:child\_process'); const controller = new AbortController(); const { signal } = controller; const grep = spawn('grep', ['ssh'], { signal }); grep.on('error', (err) | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.07200358808040619,
0.0007246799068525434,
-0.035428404808044434,
0.04918592423200607,
0.03468116372823715,
-0.046479105949401855,
0.018539775162935257,
0.1072264015674591,
0.025003407150506973,
0.03274178504943848,
0.0031247891020029783,
-0.0039026166778057814,
-0.055617328733205795,
0.02297215536236763,
0.031173773109912872,
0.036243800073862076,
0.02586156129837036,
-0.04587528109550476,
0.029087118804454803,
-0.06807434558868408,
0.07248614728450775,
-0.048608556389808655,
0.054536912590265274,
-0.01956811733543873,
-0.048676714301109314,
-0.048799410462379456,
-0.022916657850146294,
-0.046140823513269424,
0.04645056650042534,
-0.03735992684960365,
0.06152421608567238,
0.015444197691977024,
-0.039580073207616806,
-0.04840168356895447,
0.009126697666943073,
0.147620290517807,
0.05077529326081276,
-0.05246751010417938,
-0.04084258899092674,
-0.002527681179344654,
0.07280731946229935,
0.06526199728250504,
-0.16831175982952118,
-0.04585486277937889,
-0.012626719661056995,
-0.015165288001298904,
-0.08603118360042572,
-0.06900801509618759,
-0.09916799515485764,
0.028439311310648918,
-0.03305451199412346,
0.0089934216812253,
-0.019874975085258484,
0.046076301485300064,
0.01117552537471056,
-0.033655088394880295,
0.022792743518948555,
-0.026697780936956406,
0.045176055282354355,
-0.0001310022926190868,
-0.05786585435271263,
0.005297528579831123,
-0.02634422481060028,
0.005614149384200573,
0.07200603187084198,
0.027489429339766502,
-0.008331820368766785,
-0.0655745193362236,
0.03959723189473152,
0.08266612142324448,
0.03441452234983444,
0.009668050333857536,
-0.1233399510383606,
0.04438561573624611,
-0.04940835386514664,
0.019743191078305244,
-0.0023026173003017902,
-0.005029527936130762,
-0.031695425510406494,
-0.034674208611249924,
-0.006345587316900492,
0.008301425725221634,
-0.024800244718790054,
-0.06399516016244888,
-0.015275057405233383,
0.09714466333389282,
0.03398621454834938,
-0.013746367767453194,
0.14882205426692963,
0.025728324428200722,
-0.09265358000993729,
-0.05862346664071083,
-0.01628037355840206,
0.049968041479587555,
0.02477709762752056,
0.04234118387103081,
-0.017602551728487015,
-0.004430381115525961,
-0.027980871498584747,
-0.04909693822264671,
0.018211448565125465,
-0.0063547249883413315,
0.01904415711760521,
-0.0008562437724322081,
0.044654980301856995,
-0.018415777012705803,
-0.042178675532341,
-0.009308495558798313,
-0.045012135058641434,
0.02691112644970417,
-0.036652084439992905,
-0.026960043236613274,
0.09325392544269562,
0.02704898826777935,
0.0011720010079443455,
0.09377238154411316,
0.09943093359470367,
0.009340043179690838,
0.06847301870584488,
0.12010597437620163,
0.13349774479866028,
0.018199393525719643,
-0.004150220192968845,
0.04479040578007698,
-0.010769234970211983,
-0.032093241810798645,
-0.011682074517011642,
5.406117621214901e-33,
0.028790060430765152,
-0.08332157880067825,
-0.036998867988586426,
0.05507417023181915,
0.04895518347620964,
0.04065472632646561,
-0.011671780608594418,
0.07723293453454971,
-0.038693029433488846,
0.04154708608984947,
0.0003290107997599989,
-0.07320919632911682,
-0.006507427431643009,
-0.04284780099987984,
0.05748135596513748,
-0.025120193138718605,
0.060892146080732346,
-0.00015222262300085276,
-0.0039308080449700356,
0.045440029352903366,
0.04658227786421776,
0.007794110104441643,
-0.08885690569877625,
0.05838612839579582,
0.052989400923252106,
-0.025194715708494186,
-0.11111990362405777,
0.059027355164289474,
0.001739059342071414,
-0.00699475547298789,
0.024502525106072426,
-0.004922162275761366,
-0.039944395422935486,
0.02089008502662182,
0.008322352543473244,
-0.058460019528865814,
-0.03188108280301094,
0.052835557609796524,
-0.05846365541219711,
-0.0688694640994072,
0.005039453040808439,
0.009918169118463993,
-0.10609132796525955,
0.04083726927638054,
-0.026877611875534058,
-0.1177065297961235,
-0.029533786699175835,
-0.0325344055891037,
0.04484645649790764,
0.023018483072519302,
0.04220518469810486,
0.03413412347435951,
0.040349919348955154,
-0.013788439333438873,
0.0208663959056139,
0.09014645218849182,
-0.024983059614896774,
-0.12196055054664612,
-0.04255018010735512,
-0.013025077059864998,
0.058777812868356705,
-0.019359305500984192,
-0.029562024399638176,
0.08390968292951584,
-0.0022145858965814114,
-0.09777389466762543,
0.019066648557782173,
-0.02538376860320568,
0.0021178489550948143,
0.02050558663904667,
-0.09576567262411118,
0.030342912301421165,
-0.03534552827477455,
-0.057636041194200516,
-0.030599525198340416,
-0.06076328828930855,
0.0202302448451519,
-0.06961285322904587,
-0.03518778085708618,
0.00884312205016613,
0.08383134752511978,
0.006975946482270956,
-0.12674908339977264,
-0.0029476352501660585,
0.09600114077329636,
-0.0285896398127079,
-0.06459003686904907,
-0.05569544807076454,
-0.03004991076886654,
0.0006232719169929624,
0.07665318250656128,
-0.03968832269310951,
-0.036759331822395325,
0.0031970934942364693,
-0.11854381859302521,
-8.968343783470423e-33,
0.08143880218267441,
-0.003652599174529314,
-0.028068039566278458,
0.04657300189137459,
-0.08734465390443802,
0.031748101115226746,
0.01727854460477829,
-0.027897272258996964,
-0.058736853301525116,
-0.06499845534563065,
-0.07410275936126709,
0.08439208567142487,
0.07265689224004745,
0.09907549619674683,
-0.04732842370867729,
0.026332935318350792,
-0.011656363494694233,
-0.0386078767478466,
0.02015400305390358,
0.020421607419848442,
0.01578393392264843,
-0.015691002830863,
-0.020288748666644096,
0.08249706029891968,
-0.008936134167015553,
-0.023122895509004593,
-0.020441804081201553,
0.030033787712454796,
-0.07604919373989105,
0.021713577210903168,
0.007109685335308313,
0.0250795166939497,
-0.02043338492512703,
0.02609855867922306,
-0.002271205186843872,
-0.04726862534880638,
0.021128304302692413,
0.12209165096282959,
0.03167077898979187,
-0.06976944208145142,
0.09862947463989258,
0.025259599089622498,
0.01703246496617794,
0.04759063571691513,
-0.022611794993281364,
0.038005318492650986,
0.03832438215613365,
-0.005894586909562349,
-0.04471627622842789,
0.013637545518577099,
-0.06324318051338196,
-0.05309519171714783,
-0.017739057540893555,
0.03378596156835556,
-0.017671527341008186,
-0.07476364821195602,
-0.04150066152215004,
-0.06517359614372253,
-0.026624595746397972,
0.04924537613987923,
0.06572815775871277,
-0.058422788977622986,
0.014119589701294899,
-0.04896315187215805,
-0.013510847464203835,
-0.02548259124159813,
-0.10185829550027847,
0.05779605358839035,
0.06526390463113785,
-0.03400146961212158,
0.11045286059379578,
0.06928405165672302,
-0.06927916407585144,
-0.023056313395500183,
-0.059432242065668106,
0.012494605034589767,
0.005112562328577042,
-0.15021590888500214,
-0.0037653723265975714,
0.025501606985926628,
0.010333362966775894,
0.045076120644807816,
-0.03538030385971069,
-0.02651078999042511,
-0.07436792552471161,
-0.04583398997783661,
-0.05930135399103165,
0.04967644810676575,
-0.016093462705612183,
-0.009610842913389206,
0.017384419217705727,
0.027242066338658333,
-0.04817013442516327,
-0.036131601780653,
-0.01494490634649992,
-6.603117697068228e-8,
-0.028547829017043114,
-0.010575667023658752,
-0.004961536731570959,
-0.011161388829350471,
0.022631820291280746,
-0.1143030971288681,
0.04140576347708702,
-0.024797063320875168,
0.038956452161073685,
-0.009297196753323078,
-0.016848379746079445,
0.03413453325629234,
0.019339730963110924,
0.04446624964475632,
0.05170261859893799,
0.03263651579618454,
0.038824766874313354,
0.07314981520175934,
0.005767850670963526,
-0.006172738503664732,
-0.027925563976168633,
0.0009513369877822697,
-0.01802930422127247,
0.03746559098362923,
-0.051021162420511246,
-0.07090658694505692,
0.057780809700489044,
0.016411608085036278,
-0.03967704623937607,
-0.025546107441186905,
-0.023506533354520798,
0.009321339428424835,
0.009032108820974827,
0.06891239434480667,
-0.07823129743337631,
-0.0015286228153854609,
-0.05997038632631302,
-0.02617548033595085,
0.044266361743211746,
0.009366936981678009,
0.06368649005889893,
0.13623054325580597,
-0.051467087119817734,
-0.026629170402884483,
-0.07970260828733444,
0.05682910233736038,
0.0006082719773985445,
-0.0005371902952902019,
-0.03761279955506325,
0.00780342984944582,
-0.014231989160180092,
0.019056061282753944,
-0.059669967740774155,
0.0585397407412529,
0.05302306264638901,
-0.0003475852427072823,
0.018575046211481094,
-0.05619322881102562,
-0.001330133294686675,
0.08485361188650131,
0.028065593913197517,
0.022685950621962547,
0.06456685811281204,
-0.018517736345529556
] | 0.184604 |
corresponding `AbortController` is similar to calling `.kill()` on the child process except the error passed to the callback will be an `AbortError`: ```cjs const { spawn } = require('node:child\_process'); const controller = new AbortController(); const { signal } = controller; const grep = spawn('grep', ['ssh'], { signal }); grep.on('error', (err) => { // This will be called with err being an AbortError if the controller aborts }); controller.abort(); // Stops the child process ``` ```mjs import { spawn } from 'node:child\_process'; const controller = new AbortController(); const { signal } = controller; const grep = spawn('grep', ['ssh'], { signal }); grep.on('error', (err) => { // This will be called with err being an AbortError if the controller aborts }); controller.abort(); // Stops the child process ``` #### `options.detached` On Windows, setting `options.detached` to `true` makes it possible for the child process to continue running after the parent exits. The child process will have its own console window. Once enabled for a child process, it cannot be disabled. On non-Windows platforms, if `options.detached` is set to `true`, the child process will be made the leader of a new process group and session. Child processes may continue running after the parent exits regardless of whether they are detached or not. See setsid(2) for more information. By default, the parent will wait for the detached child process to exit. To prevent the parent process from waiting for a given `subprocess` to exit, use the `subprocess.unref()` method. Doing so will cause the parent process' event loop to not include the child process in its reference count, allowing the parent process to exit independently of the child process, unless there is an established IPC channel between the child and the parent processes. When using the `detached` option to start a long-running process, the process will not stay running in the background after the parent exits unless it is provided with a `stdio` configuration that is not connected to the parent. If the parent process' `stdio` is inherited, the child process will remain attached to the controlling terminal. Example of a long-running process, by detaching and also ignoring its parent `stdio` file descriptors, in order to ignore the parent's termination: ```cjs const { spawn } = require('node:child\_process'); const process = require('node:process'); const subprocess = spawn(process.argv[0], ['child\_program.js'], { detached: true, stdio: 'ignore', }); subprocess.unref(); ``` ```mjs import { spawn } from 'node:child\_process'; import process from 'node:process'; const subprocess = spawn(process.argv[0], ['child\_program.js'], { detached: true, stdio: 'ignore', }); subprocess.unref(); ``` Alternatively one can redirect the child process' output into files: ```cjs const { openSync } = require('node:fs'); const { spawn } = require('node:child\_process'); const out = openSync('./out.log', 'a'); const err = openSync('./out.log', 'a'); const subprocess = spawn('prg', [], { detached: true, stdio: [ 'ignore', out, err ], }); subprocess.unref(); ``` ```mjs import { openSync } from 'node:fs'; import { spawn } from 'node:child\_process'; const out = openSync('./out.log', 'a'); const err = openSync('./out.log', 'a'); const subprocess = spawn('prg', [], { detached: true, stdio: [ 'ignore', out, err ], }); subprocess.unref(); ``` #### `options.stdio` The `options.stdio` option is used to configure the pipes that are established between the parent and child process. By default, the child's stdin, stdout, and stderr are redirected to corresponding [`subprocess.stdin`][], [`subprocess.stdout`][], and [`subprocess.stderr`][] streams on the [`ChildProcess`][] object. This is equivalent to setting the `options.stdio` equal to `['pipe', 'pipe', 'pipe']`. For convenience, `options.stdio` may be one of the following strings: \* `'pipe'`: equivalent to `['pipe', 'pipe', 'pipe']` (the default) \* `'overlapped'`: equivalent to `['overlapped', 'overlapped', 'overlapped']` \* `'ignore'`: equivalent to `['ignore', 'ignore', 'ignore']` \* `'inherit'`: equivalent to `['inherit', 'inherit', 'inherit']` or `[0, 1, 2]` Otherwise, | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.07071210443973541,
0.008035063743591309,
-0.034025829285383224,
-0.015954503789544106,
0.08720366656780243,
-0.010756133124232292,
0.04311056062579155,
0.07850637286901474,
0.05801740288734436,
0.04071592912077904,
0.02720377780497074,
0.027144799008965492,
-0.026749582961201668,
-0.009803938679397106,
-0.030490189790725708,
0.040942490100860596,
0.054634030908346176,
-0.009506330825388432,
0.017499640583992004,
-0.010798638686537743,
0.06427451223134995,
0.05795726552605629,
0.021206824108958244,
0.06696927547454834,
-0.09532362222671509,
-0.05385807529091835,
0.01926807314157486,
-0.050562381744384766,
0.016559869050979614,
-0.003229449037462473,
0.007180696818977594,
-0.03421863168478012,
-0.06437279284000397,
-0.016614792868494987,
-0.08248523622751236,
0.11939948052167892,
-0.004514444153755903,
-0.059864211827516556,
0.005496897269040346,
-0.01654859445989132,
0.0654895156621933,
0.08952462673187256,
-0.08623529970645905,
-0.05933002382516861,
0.0564558170735836,
-0.01396579947322607,
-0.11834010481834412,
-0.022431926801800728,
-0.05045275017619133,
-0.019289381802082062,
0.0014027126599103212,
0.03880878910422325,
-0.025057464838027954,
0.05939418822526932,
0.05377409607172012,
-0.0712311789393425,
0.002759144641458988,
-0.004437039606273174,
0.04580080136656761,
0.05079272389411926,
-0.035953108221292496,
0.05568563938140869,
-0.03328193351626396,
-0.05136895552277565,
0.06679099798202515,
-0.03965720161795616,
0.006726994179189205,
-0.057021427899599075,
0.04652504250407219,
0.05431649833917618,
0.012275136075913906,
-0.07390882074832916,
-0.041485585272312164,
0.00861638318747282,
-0.06954392045736313,
-0.03388942405581474,
0.0015469928039237857,
-0.016663871705532074,
-0.10637973248958588,
0.05301631987094879,
-0.09260551631450653,
-0.032836392521858215,
-0.026763061061501503,
-0.07038181275129318,
-0.043665237724781036,
0.04601168632507324,
0.013167276047170162,
-0.023083120584487915,
0.07642682641744614,
-0.047041021287441254,
-0.06599605083465576,
-0.053101345896720886,
-0.010730302892625332,
0.044829607009887695,
0.027058493345975876,
0.0030583608895540237,
-0.03970656171441078,
-0.09825699776411057,
-0.009339405223727226,
-0.04392194747924805,
-0.029153209179639816,
0.04339524731040001,
0.005878480616956949,
0.01603812724351883,
0.004643920809030533,
-0.008915859274566174,
-0.0751367136836052,
0.03220248594880104,
-0.015846451744437218,
-0.022044328972697258,
-0.07250594347715378,
-0.02707568183541298,
0.040736570954322815,
0.102787084877491,
0.031125115230679512,
0.05593958497047424,
0.10221724957227707,
0.02074187435209751,
0.03574591875076294,
0.08612998574972153,
0.07216247916221619,
0.004400684963911772,
0.007642432581633329,
0.022893531247973442,
0.019758639857172966,
-0.0562620535492897,
0.04152686148881912,
6.524938175141681e-34,
-0.010578511282801628,
-0.071102075278759,
-0.07439097762107849,
0.06867007166147232,
0.09016785025596619,
0.08434008806943893,
-0.023481465876102448,
0.028376422822475433,
-0.02022828720510006,
0.0534655898809433,
-0.04000237211585045,
-0.08748713880777359,
0.029629407450556755,
-0.028217190876603127,
0.0408046655356884,
-0.03488796949386597,
0.061943113803863525,
-0.045562803745269775,
0.04590428248047829,
0.0031937367748469114,
0.019149497151374817,
-0.007803796790540218,
-0.042920470237731934,
0.0047228350304067135,
0.07315707951784134,
-0.016752909868955612,
-0.08265490084886551,
0.07213418185710907,
0.021592378616333008,
-0.030760791152715683,
0.025798147544264793,
0.020481009036302567,
-0.022051004692912102,
-0.004482615739107132,
0.054470088332891464,
-0.09870867431163788,
0.03704453259706497,
0.04710446298122406,
-0.08325386792421341,
-0.09048101305961609,
-0.04564771428704262,
0.0024923039600253105,
-0.15042614936828613,
0.029469652101397514,
0.011877191253006458,
-0.14076218008995056,
0.02190985344350338,
-0.03120739571750164,
0.08133251219987869,
-0.004343762062489986,
0.05831947550177574,
-0.02185189165174961,
0.08080744743347168,
-0.006310230121016502,
-0.02961045876145363,
0.08705128729343414,
-0.004823675379157066,
-0.06355628371238708,
-0.015845559537410736,
-0.029061784967780113,
0.05046066641807556,
-0.08539093285799026,
-0.02977084368467331,
-0.00822087749838829,
0.009315135888755322,
-0.05587427318096161,
-0.03621519356966019,
0.007612395565956831,
0.03996436670422554,
-0.016039274632930756,
-0.0445898063480854,
0.0006651028525084257,
0.027847912162542343,
-0.055565156042575836,
0.009606617502868176,
-0.012665070593357086,
-0.04544723033905029,
-0.011446266435086727,
-0.0037208148278295994,
-0.017621919512748718,
0.07815588265657425,
0.013255874626338482,
-0.059845004230737686,
-0.018090659752488136,
0.009237058460712433,
0.039302170276641846,
-0.025346407666802406,
-0.021532421931624413,
-0.007858622819185257,
0.05928148701786995,
-0.05032399669289589,
-0.0008509770268574357,
-0.0035528012085705996,
-0.018111754208803177,
-0.045022450387477875,
-4.335117003999038e-33,
-0.0005797429475933313,
-0.044586580246686935,
-0.002850110176950693,
-0.004208681173622608,
0.03554354980587959,
-0.05318363755941391,
0.04175146669149399,
-0.041934944689273834,
-0.06891415268182755,
0.00266533182002604,
-0.07478949427604675,
0.0015437613474205136,
0.06827809661626816,
0.1300911009311676,
-0.07425784319639206,
-0.012877849861979485,
-0.01085994578897953,
-0.01709243655204773,
-0.047589004039764404,
-0.009336370043456554,
-0.038491085171699524,
-0.02273932471871376,
0.014197014272212982,
-0.04630965366959572,
-0.05837813392281532,
0.047135937958955765,
-0.04255669191479683,
0.03625267371535301,
-0.03994988650083542,
-0.0010413795243948698,
0.006369955837726593,
-0.030696578323841095,
0.024278055876493454,
0.11057006567716599,
0.02068541944026947,
-0.031743619590997696,
0.010410979390144348,
0.13659648597240448,
-0.07860611379146576,
-0.12711003422737122,
0.1143878847360611,
0.04432225227355957,
-0.011996014043688774,
0.006130102090537548,
0.047937002032995224,
-0.026074420660734177,
0.08321554213762283,
0.08041626214981079,
-0.0321163572371006,
-0.0004606481234077364,
-0.11629463732242584,
-0.009464235045015812,
-0.0064457799308001995,
0.06646799296140671,
-0.06875820457935333,
-0.01601994037628174,
0.062463875859975815,
-0.01595235988497734,
0.04294895380735397,
0.01499730721116066,
0.046226538717746735,
-0.05658259242773056,
0.0310016218572855,
0.034564319998025894,
0.04265281930565834,
-0.013298135250806808,
-0.038398873060941696,
0.06865984946489334,
0.1612863689661026,
0.010785804130136967,
0.017513418570160866,
0.12582208216190338,
-0.023292221128940582,
-0.005637302063405514,
-0.06268800795078278,
-0.04294409230351448,
-0.033618248999118805,
-0.0759478509426117,
0.03314139321446419,
-0.007373766507953405,
0.02910403348505497,
-0.00368988374248147,
-0.015708111226558685,
0.0698685422539711,
-0.06383608281612396,
-0.004851120058447123,
-0.025466687977313995,
0.0006911857635714114,
-0.03007618337869644,
-0.06754285097122192,
0.010059747844934464,
0.008729109540581703,
0.010632161982357502,
-0.02056296542286873,
-0.008388962596654892,
-4.4671363497172933e-8,
0.025330889970064163,
-0.006748529616743326,
0.015376918949186802,
-0.06262239068746567,
-0.004783838056027889,
-0.09466361999511719,
0.03207850456237793,
-0.07669058442115784,
0.0012006385950371623,
0.02750151790678501,
-0.09079752117395401,
-0.00022708484902977943,
-0.007349308580160141,
0.022786155343055725,
0.044862501323223114,
-0.023527611047029495,
0.04259619116783142,
0.02828492596745491,
0.0468185730278492,
0.019967220723628998,
0.006833049468696117,
-0.04177220165729523,
-0.015494219958782196,
0.09365799278020859,
-0.019751200452446938,
-0.02932634763419628,
0.030801810324192047,
0.08008747547864914,
-0.07965773344039917,
-0.015981268137693405,
0.00658225454390049,
0.056846123188734055,
0.06819933652877808,
0.10273709148168564,
-0.01347153726965189,
-0.0066545442678034306,
-0.02225254289805889,
0.02129393443465233,
0.025659261271357536,
0.030568895861506462,
0.0679292157292366,
0.13033336400985718,
-0.026166362687945366,
0.01936466060578823,
0.026620054617524147,
0.016133638098835945,
-0.010727002285420895,
-0.03013796918094158,
0.03062746487557888,
0.07969102263450623,
0.014208546839654446,
-0.07403037697076797,
-0.051888931542634964,
0.005972409620881081,
-0.005999590270221233,
-0.04118213802576065,
-0.02673857845366001,
-0.14994770288467407,
-0.03025668114423752,
0.02440117858350277,
0.10407698899507523,
0.05946876481175423,
0.04319528490304947,
-0.036306869238615036
] | 0.109257 |
equal to `['pipe', 'pipe', 'pipe']`. For convenience, `options.stdio` may be one of the following strings: \* `'pipe'`: equivalent to `['pipe', 'pipe', 'pipe']` (the default) \* `'overlapped'`: equivalent to `['overlapped', 'overlapped', 'overlapped']` \* `'ignore'`: equivalent to `['ignore', 'ignore', 'ignore']` \* `'inherit'`: equivalent to `['inherit', 'inherit', 'inherit']` or `[0, 1, 2]` Otherwise, the value of `options.stdio` is an array where each index corresponds to an fd in the child. The fds 0, 1, and 2 correspond to stdin, stdout, and stderr, respectively. Additional fds can be specified to create additional pipes between the parent and child. The value is one of the following: 1. `'pipe'`: Create a pipe between the child process and the parent process. The parent end of the pipe is exposed to the parent as a property on the `child\_process` object as [`subprocess.stdio[fd]`][`subprocess.stdio`]. Pipes created for fds 0, 1, and 2 are also available as [`subprocess.stdin`][], [`subprocess.stdout`][] and [`subprocess.stderr`][], respectively. These are not actual Unix pipes and therefore the child process can not use them by their descriptor files, e.g. `/dev/fd/2` or `/dev/stdout`. 2. `'overlapped'`: Same as `'pipe'` except that the `FILE\_FLAG\_OVERLAPPED` flag is set on the handle. This is necessary for overlapped I/O on the child process's stdio handles. See the [docs](https://docs.microsoft.com/en-us/windows/win32/fileio/synchronous-and-asynchronous-i-o) for more details. This is exactly the same as `'pipe'` on non-Windows systems. 3. `'ipc'`: Create an IPC channel for passing messages/file descriptors between parent and child. A [`ChildProcess`][] may have at most one IPC stdio file descriptor. Setting this option enables the [`subprocess.send()`][] method. If the child process is a Node.js instance, the presence of an IPC channel will enable [`process.send()`][] and [`process.disconnect()`][] methods, as well as [`'disconnect'`][] and [`'message'`][] events within the child process. Accessing the IPC channel fd in any way other than [`process.send()`][] or using the IPC channel with a child process that is not a Node.js instance is not supported. 4. `'ignore'`: Instructs Node.js to ignore the fd in the child. While Node.js will always open fds 0, 1, and 2 for the processes it spawns, setting the fd to `'ignore'` will cause Node.js to open `/dev/null` and attach it to the child's fd. 5. `'inherit'`: Pass through the corresponding stdio stream to/from the parent process. In the first three positions, this is equivalent to `process.stdin`, `process.stdout`, and `process.stderr`, respectively. In any other position, equivalent to `'ignore'`. 6. {Stream} object: Share a readable or writable stream that refers to a tty, file, socket, or a pipe with the child process. The stream's underlying file descriptor is duplicated in the child process to the fd that corresponds to the index in the `stdio` array. The stream must have an underlying descriptor (file streams do not start until the `'open'` event has occurred). \*\*NOTE:\*\* While it is technically possible to pass `stdin` as a writable or `stdout`/`stderr` as readable, it is not recommended. Readable and writable streams are designed with distinct behaviors, and using them incorrectly (e.g., passing a readable stream where a writable stream is expected) can lead to unexpected results or errors. This practice is discouraged as it may result in undefined behavior or dropped callbacks if the stream encounters errors. Always ensure that `stdin` is used as readable and `stdout`/`stderr` as writable to maintain the intended flow of data between the parent and child processes. 7. Positive integer: The integer value is interpreted as a file descriptor that is open in the parent process. It is shared with the child process, similar to how {Stream} objects can be shared. Passing sockets is not supported on Windows. 8. `null`, `undefined`: Use default value. For stdio fds 0, 1, and 2 (in | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
0.009188322350382805,
-0.004428916145116091,
-0.03668814152479172,
-0.03173485025763512,
-0.05177420377731323,
-0.08916285634040833,
0.043524350970983505,
0.10546760261058807,
-0.0406830869615078,
-0.025101587176322937,
-0.004867259878665209,
-0.03648108243942261,
-0.007794089615345001,
-0.013973686844110489,
-0.04300232604146004,
-0.04372372105717659,
-0.15220774710178375,
-0.03616919741034508,
-0.025354698300361633,
-0.10987521708011627,
0.01165782567113638,
0.04907706007361412,
-0.06924356520175934,
0.00388337392359972,
-0.014318770729005337,
0.048777785152196884,
-0.06996339559555054,
-0.012345969676971436,
0.041102685034275055,
0.03267182782292366,
0.04921529442071915,
0.030705925077199936,
0.05101665481925011,
-0.012019837275147438,
-0.019918592646718025,
0.015468001365661621,
0.06420063972473145,
-0.04088832065463066,
-0.05996694788336754,
0.061482302844524384,
-0.03646628186106682,
0.00943457055836916,
-0.023955082520842552,
-0.035481713712215424,
-0.0865757018327713,
0.06521464139223099,
-0.061679478734731674,
0.007960055954754353,
-0.10525935888290405,
0.010958855971693993,
-0.04176512733101845,
0.010636569000780582,
-0.07309220731258392,
0.11129885166883469,
0.09516628086566925,
-0.018365753814578056,
-0.01862505078315735,
-0.03899361193180084,
0.026359086856245995,
-0.02924000471830368,
-0.09388880431652069,
0.009459213353693485,
-0.02072472870349884,
0.050809383392333984,
0.007975319400429726,
-0.0004892753204330802,
-0.03635244444012642,
0.014592154882848263,
0.07301721721887589,
0.048481158912181854,
-0.1082233116030693,
-0.0005040123360231519,
-0.10571981966495514,
0.017617926001548767,
0.030545653775334358,
0.04193572327494621,
0.09171215444803238,
0.0007591214380227029,
-0.012810732237994671,
-0.03034544736146927,
-0.08605311065912247,
-0.015727559104561806,
-0.033217448741197586,
-0.0073491246439516544,
-0.09649273753166199,
0.06374238431453705,
-0.0685732290148735,
-0.020745476707816124,
0.09330468624830246,
0.0038745978381484747,
-0.0397195927798748,
-0.0700431615114212,
-0.03952651470899582,
0.01993480883538723,
0.04604705423116684,
-0.007178547326475382,
0.020510515198111534,
-0.033487096428871155,
-0.03463312238454819,
0.0256489310413599,
-0.05914683640003204,
-0.04067924618721008,
0.07792250066995621,
0.005767101421952248,
0.006879700347781181,
-0.038029562681913376,
-0.00978492759168148,
-0.0491834320127964,
-0.05245792493224144,
-0.08535384386777878,
-0.06156769022345543,
-0.039621058851480484,
-0.00450972281396389,
-0.030771145597100258,
-0.01816965453326702,
0.031007448211312294,
0.013316229917109013,
-0.016303222626447678,
0.03414898365736008,
0.0026484415866434574,
-0.00974165927618742,
0.0009306253050453961,
0.005463707726448774,
0.018805064260959625,
-0.019858820363879204,
-0.09256310760974884,
-0.06065451726317406,
-1.7044730535060556e-33,
-0.06648387759923935,
-0.03739338368177414,
0.004514206200838089,
-0.004975586198270321,
0.04638036713004112,
0.03776424005627632,
0.030535612255334854,
-0.0008342004148289561,
-0.047125883400440216,
0.070253387093544,
0.022847231477499008,
0.03935116156935692,
-0.018724003806710243,
0.05748477578163147,
0.03279887139797211,
-0.06202197074890137,
0.07205472141504288,
0.06132584065198898,
0.03919060155749321,
-0.023772036656737328,
0.046658582985401154,
0.09319190680980682,
-0.004171641543507576,
-0.009633217938244343,
0.09894617646932602,
-0.058593183755874634,
-0.015714727342128754,
-0.03805746138095856,
-0.0036606236826628447,
0.008904214017093182,
-0.057381272315979004,
0.025364257395267487,
0.052692241966724396,
-0.03938746079802513,
0.09444903582334518,
-0.007083039730787277,
-0.02612174116075039,
0.007980674505233765,
0.027864953503012657,
0.01881459541618824,
-0.035719700157642365,
-0.028636137023568153,
0.03479650616645813,
0.0390450693666935,
0.054216865450143814,
-0.06519973278045654,
-0.09298481792211533,
0.022887947037816048,
-0.011552814394235611,
0.057647500187158585,
0.09179282188415527,
0.06964506208896637,
0.05592432990670204,
0.030704913660883904,
0.02279146946966648,
-0.055912211537361145,
-0.037250276654958725,
0.001820760895498097,
-0.03521382436156273,
0.08505125343799591,
-0.0027841718401759863,
0.09332060813903809,
0.0066267820075154305,
0.02611159160733223,
0.002487864578142762,
0.023269306868314743,
0.00777079164981842,
0.052676569670438766,
0.1449567824602127,
0.006318030413240194,
-0.12103743851184845,
0.026109619066119194,
-0.01752806268632412,
0.041219618171453476,
-0.06779267638921738,
0.047048091888427734,
-0.005125751718878746,
-0.04008428752422333,
0.031037842854857445,
-0.01753770001232624,
-0.05562311038374901,
0.0336315780878067,
-0.07274580746889114,
-0.06593845784664154,
0.027445944026112556,
-0.07113079726696014,
-0.019721530377864838,
-0.052183136343955994,
-0.07823097705841064,
-0.10570825636386871,
-0.03290295600891113,
0.014094376936554909,
0.02293352596461773,
-0.04269230738282204,
0.017150186002254486,
-4.271826184098858e-33,
0.08920279890298843,
-0.010456249117851257,
-0.03774518519639969,
0.038113515824079514,
-0.06652262806892395,
-0.038289546966552734,
0.11025486886501312,
-0.0875006839632988,
0.07076556235551834,
-0.03595602512359619,
-0.0583299919962883,
0.11792021989822388,
0.0496399812400341,
-0.04915301129221916,
0.02815263718366623,
0.018307827413082123,
-0.07162978500127792,
-0.048640694469213486,
0.014636480249464512,
0.0028610914014279842,
0.004033531062304974,
-0.028406213968992233,
0.040667738765478134,
0.03385996073484421,
-0.015629395842552185,
-0.01644068770110607,
0.03399888426065445,
-0.0038394273724406958,
0.046545010060071945,
-0.012463556602597237,
-0.0003074287378694862,
-0.02899041958153248,
0.0250540804117918,
-0.018170902505517006,
0.027520213276147842,
-0.04127936437726021,
0.05976695939898491,
0.07657308131456375,
0.0776093453168869,
-0.11629083007574081,
0.07056331634521484,
0.06776131689548492,
0.08881542831659317,
0.038421567529439926,
-0.03678375855088234,
0.11550217866897583,
-0.00032517564250156283,
0.01063340250402689,
-0.03815921023488045,
-0.06182422861456871,
0.008286836557090282,
0.028606731444597244,
-0.01393789704889059,
0.06864700466394424,
-0.02883061394095421,
-0.02795676328241825,
0.029413750395178795,
0.017452366650104523,
-0.0786326676607132,
0.013800323940813541,
0.03181261196732521,
-0.04396254941821098,
0.022286728024482727,
0.02123049460351467,
-0.01516815833747387,
-0.041887663304805756,
-0.10642299801111221,
-0.09673820436000824,
-0.015387244522571564,
-0.06580264866352081,
0.02647762931883335,
-0.07466648519039154,
-0.03121761977672577,
-0.03795452043414116,
-0.06018359586596489,
0.0015670073917135596,
-0.003653267165645957,
-0.033852674067020416,
0.025547631084918976,
0.09530197083950043,
-0.07649222016334534,
0.04030311852693558,
-0.0040244110859930515,
0.14884567260742188,
-0.006992647890001535,
-0.05834922567009926,
0.015165402553975582,
-0.025433659553527832,
0.046554237604141235,
-0.0295221246778965,
0.022506067529320717,
0.04826359078288078,
-0.0944737046957016,
-0.05607021227478981,
0.022622203454375267,
-6.009994990563428e-8,
0.02668452449142933,
-0.06193425506353378,
-0.01873844861984253,
0.008423538878560066,
0.03929407522082329,
-0.04399222135543823,
-0.07834870368242264,
-0.032008811831474304,
-0.026271793991327286,
-0.043941374868154526,
0.025828512385487556,
0.06628450006246567,
-0.00020341083290986717,
-0.08630521595478058,
0.07938548922538757,
0.004612785764038563,
-0.05812234431505203,
-0.05127296224236488,
-0.019902730360627174,
0.00248849019408226,
-0.008916969411075115,
-0.01141358446329832,
-0.05164802446961403,
0.025288980454206467,
-0.06938682496547699,
-0.059882454574108124,
-0.0031549143604934216,
0.011796574108302593,
-0.07127124071121216,
0.013738921843469143,
0.1433328241109848,
-0.0067232390865683556,
0.028309902176260948,
-0.004562282469123602,
0.10847043246030807,
0.011882766149938107,
-0.04740796238183975,
0.007623085752129555,
-0.053804270923137665,
0.03970691189169884,
-0.007598965894430876,
-0.009377691894769669,
0.0025687881279736757,
0.011774593964219093,
-0.04054713621735573,
0.024680783972144127,
-0.03864921256899834,
0.05603359639644623,
-0.07574009150266647,
-0.0020076525397598743,
-0.004248466342687607,
0.10591720044612885,
0.014421217143535614,
0.030574176460504532,
0.015810757875442505,
0.040629561990499496,
-0.04740309342741966,
-0.015095436945557594,
-0.030790558084845543,
0.08363603800535202,
0.07254598289728165,
0.07066147774457932,
0.07324942946434021,
0.010756677016615868
] | 0.154064 |
value is interpreted as a file descriptor that is open in the parent process. It is shared with the child process, similar to how {Stream} objects can be shared. Passing sockets is not supported on Windows. 8. `null`, `undefined`: Use default value. For stdio fds 0, 1, and 2 (in other words, stdin, stdout, and stderr) a pipe is created. For fd 3 and up, the default is `'ignore'`. ```cjs const { spawn } = require('node:child\_process'); const process = require('node:process'); // Child will use parent's stdios. spawn('prg', [], { stdio: 'inherit' }); // Spawn child sharing only stderr. spawn('prg', [], { stdio: ['pipe', 'pipe', process.stderr] }); // Open an extra fd=4, to interact with programs presenting a // startd-style interface. spawn('prg', [], { stdio: ['pipe', null, null, null, 'pipe'] }); ``` ```mjs import { spawn } from 'node:child\_process'; import process from 'node:process'; // Child will use parent's stdios. spawn('prg', [], { stdio: 'inherit' }); // Spawn child sharing only stderr. spawn('prg', [], { stdio: ['pipe', 'pipe', process.stderr] }); // Open an extra fd=4, to interact with programs presenting a // startd-style interface. spawn('prg', [], { stdio: ['pipe', null, null, null, 'pipe'] }); ``` \_It is worth noting that when an IPC channel is established between the parent and child processes, and the child process is a Node.js instance, the child process is launched with the IPC channel unreferenced (using `unref()`) until the child process registers an event handler for the [`'disconnect'`][] event or the [`'message'`][] event. This allows the child process to exit normally without the process being held open by the open IPC channel.\_ See also: [`child\_process.exec()`][] and [`child\_process.fork()`][]. ## Synchronous process creation The [`child\_process.spawnSync()`][], [`child\_process.execSync()`][], and [`child\_process.execFileSync()`][] methods are synchronous and will block the Node.js event loop, pausing execution of any additional code until the spawned process exits. Blocking calls like these are mostly useful for simplifying general-purpose scripting tasks and for simplifying the loading/processing of application configuration at startup. ### `child\_process.execFileSync(file[, args][, options])` \* `file` {string} The name or path of the executable file to run. \* `args` {string\[]} List of string arguments. \* `options` {Object} \* `cwd` {string|URL} Current working directory of the child process. \* `input` {string|Buffer|TypedArray|DataView} The value which will be passed as stdin to the spawned process. If `stdio[0]` is set to `'pipe'`, Supplying this value will override `stdio[0]`. \* `stdio` {string|Array} Child's stdio configuration. See [`child\_process.spawn()`][]'s [`stdio`][]. `stderr` by default will be output to the parent process' stderr unless `stdio` is specified. \*\*Default:\*\* `'pipe'`. \* `env` {Object} Environment key-value pairs. \*\*Default:\*\* `process.env`. \* `uid` {number} Sets the user identity of the process (see setuid(2)). \* `gid` {number} Sets the group identity of the process (see setgid(2)). \* `timeout` {number} In milliseconds the maximum amount of time the process is allowed to run. \*\*Default:\*\* `undefined`. \* `killSignal` {string|integer} The signal value to be used when the spawned process will be killed. \*\*Default:\*\* `'SIGTERM'`. \* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated. See caveat at [`maxBuffer` and Unicode][]. \*\*Default:\*\* `1024 \* 1024`. \* `encoding` {string} The encoding used for all stdio inputs and outputs. \*\*Default:\*\* `'buffer'`. \* `windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. \*\*Default:\*\* `false`. \* `shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses `'/bin/sh'` on Unix, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell requirements][] and [Default Windows shell][]. \*\*Default:\*\* `false` (no shell). \* Returns: {Buffer|string} The stdout from the command. The `child\_process.execFileSync()` method is generally identical to [`child\_process.execFile()`][] with the | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.06826332956552505,
0.044546306133270264,
-0.09666091203689575,
0.018401237204670906,
-0.016229040920734406,
-0.007105543743818998,
0.018094662576913834,
0.13185925781726837,
0.026681985706090927,
-0.01160888746380806,
-0.06261669844388962,
-0.021503912284970284,
-0.07557401806116104,
0.024720529094338417,
-0.00479113170877099,
-0.004067818634212017,
-0.03237585723400116,
-0.04450368508696556,
0.027964675799012184,
-0.13809213042259216,
-0.01564742811024189,
-0.007762377616018057,
0.004232004750519991,
-0.03196042776107788,
-0.008019529283046722,
-0.029835550114512444,
-0.0027761731762439013,
-0.023046599701046944,
0.08553092926740646,
0.04724333435297012,
0.07123702019453049,
-0.047336284071207047,
-0.03810699284076691,
-0.004902480635792017,
-0.03128354251384735,
0.1794530600309372,
0.06808017939329147,
-0.11812447756528854,
-0.07179547101259232,
0.015574093908071518,
0.12006758153438568,
0.0839451402425766,
-0.11324287205934525,
-0.023656345903873444,
-0.053308334201574326,
0.027119169011712074,
-0.09283265471458435,
0.05676838755607605,
-0.07219584286212921,
-0.013476496562361717,
-0.020184235647320747,
-0.02836775965988636,
-0.015979284420609474,
0.037531059235334396,
-0.03468881547451019,
-0.026765357702970505,
0.03909360617399216,
-0.045647624880075455,
0.05743174999952316,
0.0015947195934131742,
-0.09963147342205048,
-0.02164306677877903,
0.06198640912771225,
0.0278176162391901,
0.06576105207204819,
-0.04219890758395195,
-0.07630693912506104,
0.02062341943383217,
-0.0011296476004645228,
-0.002324166940525174,
-0.02037443406879902,
0.043427079916000366,
-0.024700606241822243,
0.01426788978278637,
-0.0729416236281395,
-0.04274372756481171,
-0.03663072735071182,
0.03753524646162987,
-0.06722497195005417,
0.002829425036907196,
-0.045656923204660416,
-0.0034201350063085556,
-0.05851500481367111,
-0.04458467289805412,
-0.07497041672468185,
0.1168087050318718,
-0.03792949765920639,
-0.024073533713817596,
0.03174996003508568,
0.08371477574110031,
-0.12543976306915283,
0.020759213715791702,
-0.09724742919206619,
0.06594031304121017,
0.05042097344994545,
0.023757338523864746,
0.006677152588963509,
-0.03237270563840866,
-0.016807040199637413,
-0.02094339206814766,
-0.040800709277391434,
0.05115582048892975,
0.04679818078875542,
0.02983935922384262,
0.04754522442817688,
-0.03554446995258331,
-0.08772353082895279,
0.015726009383797646,
-0.035329580307006836,
-0.05023590475320816,
-0.06931290775537491,
0.04481986537575722,
0.027642440050840378,
0.01731148362159729,
0.015767784789204597,
-0.0006594586884602904,
0.061940282583236694,
-0.040466297417879105,
0.04032732918858528,
0.07726527750492096,
0.06976715475320816,
-0.023858163505792618,
-0.0687468945980072,
-0.0043746912851929665,
0.0049421051517128944,
-0.11420586705207825,
0.0025229344610124826,
-1.0990235760200013e-33,
0.027828175574541092,
-0.11244577169418335,
0.017630232498049736,
0.06351288408041,
0.06208544224500656,
0.01782803051173687,
-0.005923478398472071,
0.02278592437505722,
-0.07095218449831009,
0.0017659971490502357,
-0.034029603004455566,
-0.02234329655766487,
0.02468206360936165,
-0.055105891078710556,
0.031181538477540016,
-0.028919756412506104,
0.06907613575458527,
0.031330909579992294,
0.05716383457183838,
-0.010166752152144909,
0.047162484377622604,
0.03702380135655403,
-0.05283520370721817,
0.003885547397658229,
0.06707881391048431,
-0.01722690835595131,
-0.08035653084516525,
0.03228635713458061,
0.031749989837408066,
-0.047978807240724564,
0.05325053259730339,
0.04992381110787392,
-0.0013000475009903312,
-0.042483679950237274,
0.0009059971780516207,
-0.047176484018564224,
0.05841902270913124,
0.02808375284075737,
-0.07160195708274841,
-0.046706344932317734,
0.043220337480306625,
-0.04047933220863342,
-0.02845894731581211,
0.009167337790131569,
-0.02938544936478138,
-0.06592052429914474,
-0.09643109142780304,
-0.050059106200933456,
0.016150521114468575,
0.005985916126519442,
0.06027078256011009,
0.06951488554477692,
0.04981590807437897,
0.02855767495930195,
0.016202004626393318,
0.0283920057117939,
-0.03229071944952011,
-0.056277863681316376,
-0.056762125343084335,
0.012878966517746449,
0.02870556339621544,
0.08212421834468842,
-0.015114936977624893,
0.01804390177130699,
0.04526307061314583,
-0.06848520040512085,
0.03157844394445419,
0.00677777174860239,
0.049352262169122696,
0.022889910265803337,
-0.07637050002813339,
0.04530834034085274,
-0.0694713369011879,
-0.023660553619265556,
0.025598671287298203,
0.06513760983943939,
-0.012330438010394573,
-0.03847704827785492,
0.011737998574972153,
-0.012963795103132725,
-0.009726087562739849,
-0.004439569544047117,
-0.044368844479322433,
-0.00958203338086605,
0.033246416598558426,
-0.016722431406378746,
-0.06337419897317886,
-0.013441738672554493,
0.017064495012164116,
0.03156673535704613,
0.022662071511149406,
0.0011104169534519315,
0.017908703535795212,
-0.026062635704874992,
-0.025245051831007004,
-3.28016041530396e-33,
-0.00188742158934474,
0.0027902484871447086,
-0.07210326939821243,
0.04334411025047302,
0.01173686794936657,
-0.014708928763866425,
0.03620586916804314,
-0.08740479499101639,
-0.014455925673246384,
0.034923821687698364,
-0.10519099980592728,
0.0953601747751236,
0.037957772612571716,
0.11316479742527008,
-0.019003942608833313,
-0.007640286814421415,
-0.018748199567198753,
0.01430111937224865,
0.05685913935303688,
-0.01007126085460186,
-0.044314078986644745,
0.07660799473524094,
0.04935617372393608,
-0.013855251483619213,
-0.03137921914458275,
-0.006393276620656252,
-0.024383217096328735,
0.008504197001457214,
-0.06800933182239532,
0.0006584063521586359,
-0.006324409041553736,
0.009325601160526276,
0.026526223868131638,
0.05183856934309006,
-0.0007657114183530211,
-0.08331616222858429,
0.02715514600276947,
0.05537058413028717,
0.12004852294921875,
-0.07422108203172684,
0.1131594106554985,
-0.00399820925667882,
-0.03875841572880745,
0.013407215476036072,
-0.0028217926155775785,
0.0757070779800415,
0.042938292026519775,
0.012025830335915089,
-0.05332482233643532,
0.06298411637544632,
-0.03670071065425873,
0.00451601343229413,
0.007935860194265842,
0.013284933753311634,
-0.020589085295796394,
-0.01927960477769375,
0.051379211246967316,
-0.03955024108290672,
0.021016646176576614,
0.02990642748773098,
0.13333074748516083,
-0.06886216253042221,
-0.07906460762023926,
0.016426771879196167,
-0.03656836599111557,
-0.06873223185539246,
-0.06368286162614822,
0.02529779076576233,
0.07373418658971786,
-0.0884755328297615,
0.0108582628890872,
0.050404831767082214,
0.013035758398473263,
-0.008714530616998672,
-0.0462135449051857,
0.0135066919028759,
0.021536868065595627,
-0.04424696043133736,
0.010323467664420605,
0.07315795868635178,
-0.04571196064352989,
0.08128686994314194,
-0.007292518857866526,
0.039317719638347626,
0.03859610855579376,
-0.034644488245248795,
0.06092854589223862,
-0.06679560244083405,
-0.03126351907849312,
-0.014958594925701618,
-0.005510301794856787,
0.0719856470823288,
-0.08077985793352127,
-0.058524005115032196,
-0.009612501598894596,
-4.8344499958830056e-8,
-0.04033322259783745,
-0.03362632170319557,
-0.05759275332093239,
0.007374878507107496,
0.015612240880727768,
-0.05826412886381149,
-0.009087515994906425,
-0.056182995438575745,
-0.005418823100626469,
0.049810562282800674,
-0.09629006683826447,
-0.045326393097639084,
0.060012005269527435,
-0.060718830674886703,
0.0767136886715889,
0.007995687425136566,
0.011651837266981602,
-0.04114420711994171,
0.018516333773732185,
-0.012929754331707954,
0.04862160235643387,
0.0098507609218359,
-0.006748774088919163,
0.09491586685180664,
-0.07431303709745407,
-0.0765419527888298,
0.08439579606056213,
-0.013879545032978058,
-0.07914003729820251,
0.013820760883390903,
0.013007444329559803,
0.05679086223244667,
0.04478902742266655,
0.12540355324745178,
0.04517105966806412,
-0.008508827537298203,
-0.08019813895225525,
0.03606997802853584,
0.023587001487612724,
0.04722173139452934,
0.06624987721443176,
0.07321722060441971,
-0.0541343167424202,
-0.026131659746170044,
-0.08305400609970093,
0.09749899059534073,
-0.04482046887278557,
0.036496564745903015,
-0.03836459293961525,
0.023928476497530937,
-0.006557838525623083,
0.027335911989212036,
0.0020468831062316895,
0.004564644768834114,
0.07042998820543289,
0.00030118419090285897,
-0.008957047946751118,
-0.05699304863810539,
-0.06450031697750092,
0.05309218540787697,
0.01931985653936863,
0.08879682421684265,
0.046306759119033813,
-0.010163282044231892
] | 0.099675 |
inside of a shell. Uses `'/bin/sh'` on Unix, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell requirements][] and [Default Windows shell][]. \*\*Default:\*\* `false` (no shell). \* Returns: {Buffer|string} The stdout from the command. The `child\_process.execFileSync()` method is generally identical to [`child\_process.execFile()`][] with the exception that the method will not return until the child process has fully closed. When a timeout has been encountered and `killSignal` is sent, the method won't return until the process has completely exited. If the child process intercepts and handles the `SIGTERM` signal and does not exit, the parent process will still wait until the child process has exited. If the process times out or has a non-zero exit code, this method will throw an [`Error`][] that will include the full result of the underlying [`child\_process.spawnSync()`][]. \*\*If the `shell` option is enabled, do not pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.\*\* ```cjs const { execFileSync } = require('node:child\_process'); try { const stdout = execFileSync('my-script.sh', ['my-arg'], { // Capture stdout and stderr from child process. Overrides the // default behavior of streaming child stderr to the parent stderr stdio: 'pipe', // Use utf8 encoding for stdio pipes encoding: 'utf8', }); console.log(stdout); } catch (err) { if (err.code) { // Spawning child process failed console.error(err.code); } else { // Child was spawned but exited with non-zero exit code // Error contains any stdout and stderr from the child const { stdout, stderr } = err; console.error({ stdout, stderr }); } } ``` ```mjs import { execFileSync } from 'node:child\_process'; try { const stdout = execFileSync('my-script.sh', ['my-arg'], { // Capture stdout and stderr from child process. Overrides the // default behavior of streaming child stderr to the parent stderr stdio: 'pipe', // Use utf8 encoding for stdio pipes encoding: 'utf8', }); console.log(stdout); } catch (err) { if (err.code) { // Spawning child process failed console.error(err.code); } else { // Child was spawned but exited with non-zero exit code // Error contains any stdout and stderr from the child const { stdout, stderr } = err; console.error({ stdout, stderr }); } } ``` ### `child\_process.execSync(command[, options])` \* `command` {string} The command to run. \* `options` {Object} \* `cwd` {string|URL} Current working directory of the child process. \* `input` {string|Buffer|TypedArray|DataView} The value which will be passed as stdin to the spawned process. If `stdio[0]` is set to `'pipe'`, Supplying this value will override `stdio[0]`. \* `stdio` {string|Array} Child's stdio configuration. See [`child\_process.spawn()`][]'s [`stdio`][]. `stderr` by default will be output to the parent process' stderr unless `stdio` is specified. \*\*Default:\*\* `'pipe'`. \* `env` {Object} Environment key-value pairs. \*\*Default:\*\* `process.env`. \* `shell` {string} Shell to execute the command with. See [Shell requirements][] and [Default Windows shell][]. \*\*Default:\*\* `'/bin/sh'` on Unix, `process.env.ComSpec` on Windows. \* `uid` {number} Sets the user identity of the process. (See setuid(2)). \* `gid` {number} Sets the group identity of the process. (See setgid(2)). \* `timeout` {number} In milliseconds the maximum amount of time the process is allowed to run. \*\*Default:\*\* `undefined`. \* `killSignal` {string|integer} The signal value to be used when the spawned process will be killed. \*\*Default:\*\* `'SIGTERM'`. \* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated and any output is truncated. See caveat at [`maxBuffer` and Unicode][]. \*\*Default:\*\* `1024 \* 1024`. \* `encoding` {string} The encoding used for all stdio inputs and outputs. \*\*Default:\*\* `'buffer'`. \* `windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. \*\*Default:\*\* `false`. \* Returns: | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.015947163105010986,
0.011264093220233917,
-0.0920022651553154,
-0.002206866629421711,
0.05014699697494507,
-0.04155345261096954,
-0.021703826263546944,
0.08629561960697174,
0.0790090337395668,
0.07518403232097626,
-0.03477879986166954,
0.030010441318154335,
-0.04638402909040451,
-0.0506545715034008,
0.015694191679358482,
-0.03772386163473129,
0.02090376615524292,
-0.0174778550863266,
-0.029340088367462158,
-0.054204393178224564,
0.05628920719027519,
0.008477937430143356,
0.04418748617172241,
-0.013794037513434887,
-0.08378396183252335,
-0.03122899681329727,
-0.05152851343154907,
-0.10858065634965897,
-0.014999870210886002,
0.016218895092606544,
-0.029870159924030304,
0.004299345426261425,
-0.07384808361530304,
-0.06063398718833923,
0.05159955099225044,
0.14164452254772186,
0.09081608057022095,
-0.003203675616532564,
-0.04891287535429001,
-0.07272564619779587,
0.027377700433135033,
0.0825694352388382,
-0.12375124543905258,
-0.02215784788131714,
-0.0036714395973831415,
-0.03342335671186447,
-0.07433152943849564,
-0.05738797411322594,
-0.0701761469244957,
-0.024690574035048485,
-0.03966665267944336,
0.0141608826816082,
0.0042849634774029255,
0.06456853449344635,
-0.02215520478785038,
-0.05255138874053955,
0.055221077054739,
0.052112165838479996,
-0.03043033927679062,
0.032357536256313324,
-0.0355662927031517,
0.027956033125519753,
-0.12412643432617188,
0.0020931914914399385,
0.0826651006937027,
0.004494779743254185,
0.019779302179813385,
-0.09129059314727783,
0.03297950699925423,
-0.05064397305250168,
-0.07397198677062988,
-0.03713400289416313,
-0.0968727096915245,
0.09483153373003006,
-0.0385640487074852,
0.0445815771818161,
0.05603436008095741,
0.0056892274878919125,
-0.08060108125209808,
-0.04143145680427551,
-0.01248958520591259,
0.028456538915634155,
-0.03430214524269104,
-0.09763769805431366,
0.04683300852775574,
0.10769341886043549,
-0.003341004718095064,
-0.0039023153949528933,
0.06944534927606583,
0.07764163613319397,
-0.02279169298708439,
0.04439081251621246,
-0.036956727504730225,
0.06742731481790543,
0.08648175746202469,
0.004057153593748808,
-0.0031631633173674345,
0.031099941581487656,
-0.020819930359721184,
-0.03448321670293808,
0.008126731961965561,
-0.03859495371580124,
0.008059698157012463,
-0.019870880991220474,
0.060235846787691116,
-0.05090517923235893,
0.02265702188014984,
-0.003527470165863633,
0.03669894486665726,
-0.07865357398986816,
-0.06258765608072281,
-0.07619942724704742,
0.06535769253969193,
0.06356558203697205,
-0.01311320811510086,
0.04325512424111366,
0.051124490797519684,
0.04182758927345276,
0.03583042696118355,
0.01563865691423416,
0.10391441732645035,
0.0502229705452919,
0.05100196227431297,
-0.0349518284201622,
-0.0036748324055224657,
-0.05677558854222298,
0.022990915924310684,
4.138554879416366e-33,
-0.052578482776880264,
-0.13908343017101288,
0.009580941870808601,
0.07351301610469818,
0.04377378150820732,
-0.00228853989392519,
-0.02762247994542122,
0.05987684428691864,
0.03680909797549248,
0.048642147332429886,
-0.02964147739112377,
-0.12292708456516266,
0.060149967670440674,
-0.049985162913799286,
0.031322211027145386,
0.02918194606900215,
0.03962397947907448,
0.024890413507819176,
-0.02427930012345314,
0.025465138256549835,
0.030050139874219894,
0.013468178920447826,
-0.037417665123939514,
0.05052462965250015,
0.036140091717243195,
-0.013651255518198013,
-0.10173489898443222,
0.019410910084843636,
0.03396603837609291,
0.028891853988170624,
-0.035838671028614044,
0.0016840368043631315,
-0.03626827150583267,
-0.03376481309533119,
-0.005011787172406912,
-0.04298005998134613,
0.010278753936290741,
0.018096255138516426,
0.034672174602746964,
-0.05291762948036194,
-0.08628534525632858,
-0.060715433210134506,
-0.06913190335035324,
0.0974070131778717,
-0.005041459109634161,
-0.13953588902950287,
-0.07219890505075455,
0.01054669264703989,
-0.014936321415007114,
0.028668269515037537,
0.10483908653259277,
0.002209399826824665,
0.07091578096151352,
0.05037486180663109,
-0.01803714781999588,
0.122971311211586,
0.029994264245033264,
-0.07575299590826035,
-0.05004260316491127,
0.026441190391778946,
0.10587132722139359,
-0.011936688795685768,
-0.05778108909726143,
-0.0366903617978096,
-0.0007543893880210817,
-0.07868598401546478,
0.029857538640499115,
-0.027296707034111023,
-0.03859294205904007,
0.037442415952682495,
-0.06074715033173561,
0.03447733446955681,
-0.006433997768908739,
-0.014517392963171005,
0.021161476150155067,
-0.052319806069135666,
0.07763927429914474,
-0.049378328025341034,
-0.027548404410481453,
-0.014874616637825966,
0.08810968697071075,
0.028998788446187973,
-0.08286471664905548,
-0.1061779037117958,
-0.02204432338476181,
0.06572122871875763,
-0.039341412484645844,
-0.04657595977187157,
0.0013184761628508568,
-0.05559007450938225,
-0.012069555930793285,
-0.07021209597587585,
-0.05118417739868164,
0.04712590575218201,
-0.013912079855799675,
-6.829564138243919e-33,
0.09378737211227417,
-0.04615548253059387,
-0.03801644593477249,
-0.014409982599318027,
-0.004162708297371864,
-0.003621842712163925,
-0.04179151728749275,
-0.09398540109395981,
-0.04504026100039482,
-0.042562395334243774,
-0.036603059619665146,
0.01871430315077305,
0.006777644157409668,
0.09931068867444992,
0.009002729319036007,
-0.043796733021736145,
0.07504117488861084,
-0.008862417191267014,
0.042530130594968796,
0.007792275864630938,
0.0160507895052433,
-0.02733692154288292,
-0.024522867053747177,
0.004296921193599701,
-0.015581458806991577,
-0.04937239736318588,
-0.08813993632793427,
0.0345122329890728,
-0.02621397376060486,
-0.0001339329464826733,
0.04029971733689308,
-0.030370192602276802,
0.03484239801764488,
0.05511234328150749,
0.004549608565866947,
-0.006253494881093502,
-0.04210031032562256,
-0.013312929309904575,
0.050267137587070465,
-0.05347221717238426,
0.08409172296524048,
0.008063243702054024,
0.013085565529763699,
0.01316164806485176,
0.03718910738825798,
0.031285908073186874,
0.03013363853096962,
0.0073887938633561134,
-0.04097764566540718,
0.06829600036144257,
0.03966793417930603,
-0.00006470765947597101,
0.04970867186784744,
0.1173454150557518,
0.008823965676128864,
-0.01118735782802105,
0.0020095612853765488,
-0.010593714192509651,
-0.046677906066179276,
-0.015076933428645134,
0.061713773757219315,
0.003416819265112281,
0.016781039535999298,
0.03112606145441532,
-0.00005121795766171999,
0.04993768036365509,
-0.023496422916650772,
0.05357225239276886,
0.05816319212317467,
-0.02628910169005394,
0.12012150883674622,
0.059975333511829376,
-0.14808550477027893,
0.00951443612575531,
-0.09810362756252289,
0.05950929597020149,
-0.024507174268364906,
-0.11111719906330109,
-0.04893979802727699,
0.049227528274059296,
-0.018841268494725227,
0.06632807105779648,
-0.03034798987209797,
0.023760365322232246,
0.016991008073091507,
-0.029208576306700706,
-0.06435839086771011,
0.00275571271777153,
0.01883484423160553,
-0.04091400280594826,
0.04372381418943405,
-0.005391005426645279,
-0.003853073576465249,
0.020119652152061462,
0.024407239630818367,
-6.56470362514483e-8,
0.06085959076881409,
-0.018975989893078804,
0.01623426377773285,
-0.0338999405503273,
0.00775689585134387,
-0.009418354369699955,
0.006160389631986618,
-0.058622807264328,
0.009547059424221516,
0.026460448279976845,
-0.0689256489276886,
-0.06925377249717712,
0.0012395766098052263,
-0.02718396857380867,
0.02872404083609581,
-0.003845480503514409,
0.015839550644159317,
0.008668878115713596,
0.01807398349046707,
-0.03570191562175751,
0.010085010901093483,
-0.015168632380664349,
-0.00411605928093195,
0.026567036285996437,
-0.09280191361904144,
0.0029307061340659857,
0.06537817418575287,
0.03019821085035801,
-0.1363319605588913,
-0.03409871086478233,
-0.002312316093593836,
-0.017466535791754723,
0.04346563667058945,
0.09330511093139648,
-0.018317878246307373,
0.05482544004917145,
-0.007341914810240269,
0.05415954440832138,
0.008608336560428143,
0.0020733680576086044,
0.03459355980157852,
0.09188959747552872,
0.009618024341762066,
0.005883111152797937,
0.028778908774256706,
0.02183864265680313,
0.006720313802361488,
-0.0018357945373281837,
-0.014730668626725674,
0.03996191918849945,
-0.021700141951441765,
0.04959267005324364,
-0.06904004514217377,
0.07024382799863815,
0.0047022681683301926,
-0.015212803147733212,
-0.02359001152217388,
-0.061722125858068466,
-0.0020849427673965693,
0.12433997541666031,
-0.0018413979560136795,
0.03167464956641197,
0.0740085318684578,
0.021916067227721214
] | 0.130245 |
terminated and any output is truncated. See caveat at [`maxBuffer` and Unicode][]. \*\*Default:\*\* `1024 \* 1024`. \* `encoding` {string} The encoding used for all stdio inputs and outputs. \*\*Default:\*\* `'buffer'`. \* `windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. \*\*Default:\*\* `false`. \* Returns: {Buffer|string} The stdout from the command. The `child\_process.execSync()` method is generally identical to [`child\_process.exec()`][] with the exception that the method will not return until the child process has fully closed. When a timeout has been encountered and `killSignal` is sent, the method won't return until the process has completely exited. If the child process intercepts and handles the `SIGTERM` signal and doesn't exit, the parent process will wait until the child process has exited. If the process times out or has a non-zero exit code, this method will throw. The [`Error`][] object will contain the entire result from [`child\_process.spawnSync()`][]. \*\*Never pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.\*\* ### `child\_process.spawnSync(command[, args][, options])` \* `command` {string} The command to run. \* `args` {string\[]} List of string arguments. \* `options` {Object} \* `cwd` {string|URL} Current working directory of the child process. \* `input` {string|Buffer|TypedArray|DataView} The value which will be passed as stdin to the spawned process. If `stdio[0]` is set to `'pipe'`, Supplying this value will override `stdio[0]`. \* `argv0` {string} Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` if not specified. \* `stdio` {string|Array} Child's stdio configuration. See [`child\_process.spawn()`][]'s [`stdio`][]. \*\*Default:\*\* `'pipe'`. \* `env` {Object} Environment key-value pairs. \*\*Default:\*\* `process.env`. \* `uid` {number} Sets the user identity of the process (see setuid(2)). \* `gid` {number} Sets the group identity of the process (see setgid(2)). \* `timeout` {number} In milliseconds the maximum amount of time the process is allowed to run. \*\*Default:\*\* `undefined`. \* `killSignal` {string|integer} The signal value to be used when the spawned process will be killed. \*\*Default:\*\* `'SIGTERM'`. \* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated and any output is truncated. See caveat at [`maxBuffer` and Unicode][]. \*\*Default:\*\* `1024 \* 1024`. \* `encoding` {string} The encoding used for all stdio inputs and outputs. \*\*Default:\*\* `'buffer'`. \* `shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses `'/bin/sh'` on Unix, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell requirements][] and [Default Windows shell][]. \*\*Default:\*\* `false` (no shell). \* `windowsVerbatimArguments` {boolean} No quoting or escaping of arguments is done on Windows. Ignored on Unix. This is set to `true` automatically when `shell` is specified and is CMD. \*\*Default:\*\* `false`. \* `windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. \*\*Default:\*\* `false`. \* Returns: {Object} \* `pid` {number} Pid of the child process. \* `output` {Array} Array of results from stdio output. \* `stdout` {Buffer|string} The contents of `output[1]`. \* `stderr` {Buffer|string} The contents of `output[2]`. \* `status` {number|null} The exit code of the subprocess, or `null` if the subprocess terminated due to a signal. \* `signal` {string|null} The signal used to kill the subprocess, or `null` if the subprocess did not terminate due to a signal. \* `error` {Error} The error object if the child process failed or timed out. The `child\_process.spawnSync()` method is generally identical to [`child\_process.spawn()`][] with the exception that the function will not return until the child process has fully closed. When a timeout has been encountered and `killSignal` is sent, the method won't return until the process has completely | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
0.02819911204278469,
0.003941503819078207,
-0.08314937353134155,
0.04320762678980827,
-0.004996942821890116,
-0.009223202243447304,
-0.002621972933411598,
0.10736410319805145,
0.0605800561606884,
0.030859151855111122,
-0.03428884595632553,
-0.019663915038108826,
-0.05084776505827904,
-0.030300524085760117,
-0.08119004964828491,
-0.0026054223999381065,
-0.01825336366891861,
-0.04647029563784599,
-0.09136275947093964,
-0.11520500481128693,
0.026353178545832634,
-0.013833300210535526,
-0.022593971341848373,
0.02362840436398983,
-0.08670973777770996,
-0.007998076267540455,
-0.09405802190303802,
-0.07860212028026581,
0.025235408917069435,
0.0432855561375618,
-0.02194555662572384,
-0.05739948898553848,
0.022952167317271233,
-0.014716164208948612,
0.08281541615724564,
0.08448584377765656,
0.06253145635128021,
-0.03719032555818558,
-0.06643921881914139,
-0.05603324621915817,
0.015601391904056072,
0.044271476566791534,
-0.11616566777229309,
0.021410152316093445,
-0.008167148567736149,
0.04577075317502022,
-0.05130341649055481,
-0.048116058111190796,
-0.09237577021121979,
0.008840416558086872,
-0.02281629480421543,
0.06378334015607834,
0.018888473510742188,
0.03963206335902214,
-0.005593571811914444,
-0.07846260070800781,
0.013496951200067997,
0.05357414484024048,
-0.025129953399300575,
0.07631365209817886,
-0.06022510677576065,
0.010423972271382809,
-0.1282023787498474,
0.014873987063765526,
0.07331924885511398,
0.025932224467396736,
0.018565606325864792,
-0.07915432006120682,
-0.0016732387011870742,
-0.030635232105851173,
-0.1092485710978508,
-0.051776811480522156,
-0.10821977257728577,
0.07298297435045242,
-0.004127806052565575,
0.032353393733501434,
0.046873096376657486,
-0.012446442618966103,
-0.0517568476498127,
-0.10533207654953003,
0.054657772183418274,
-0.019798288121819496,
-0.08663100749254227,
-0.0442059189081192,
0.016304166987538338,
0.0664144828915596,
-0.04339059814810753,
-0.05148289352655411,
0.045163869857788086,
0.053572606295347214,
-0.01816886104643345,
-0.030542220920324326,
-0.03272369131445885,
0.06799843162298203,
0.06261676549911499,
0.011961443349719048,
0.009647969156503677,
0.010105568915605545,
-0.04399413615465164,
-0.027484524995088577,
-0.01969921961426735,
0.023441020399332047,
0.06275612860918045,
-0.0031794237438589334,
0.03288216516375542,
-0.030106011778116226,
0.020724037662148476,
0.05812692269682884,
0.011716240085661411,
-0.10275987535715103,
-0.03632263094186783,
-0.037502072751522064,
0.032689448446035385,
0.035554010421037674,
0.04814499244093895,
0.06703617423772812,
0.039700523018836975,
0.043561048805713654,
-0.04363979771733284,
0.010583078488707542,
0.051752783358097076,
0.047472599893808365,
-0.027081411331892014,
0.0010350365191698074,
-0.006948627531528473,
-0.024311400949954987,
0.04406214505434036,
2.2129094413962273e-33,
-0.0490371510386467,
-0.09389197081327438,
-0.022741859778761864,
0.00254442379809916,
0.05177595838904381,
0.04881279170513153,
0.00038907985435798764,
0.040879327803850174,
0.029858816415071487,
0.0771796926856041,
-0.03406919166445732,
-0.11404261738061905,
0.058758366852998734,
-0.022708594799041748,
0.060215771198272705,
0.005850955843925476,
0.10976092517375946,
0.03365864232182503,
-0.01963859051465988,
0.05571041628718376,
0.05733279883861542,
0.07148175686597824,
-0.02461836114525795,
-0.0023971227928996086,
0.037365902215242386,
-0.028135936707258224,
-0.10257918387651443,
0.008636245504021645,
-0.006769843865185976,
0.00862582866102457,
-0.09153304994106293,
0.08644859492778778,
-0.03910903260111809,
-0.05034322291612625,
-0.009096774272620678,
-0.08030781149864197,
0.06938286870718002,
-0.0077761076390743256,
0.07251469790935516,
0.02132466435432434,
-0.09105092287063599,
-0.029096553102135658,
-0.025536347180604935,
0.05965874716639519,
-0.0010400409810245037,
-0.1251654475927353,
-0.02757686749100685,
-0.006426451727747917,
-0.02490045875310898,
0.04799429327249527,
0.09609135240316391,
0.06367474794387817,
0.04141833633184433,
0.027699653059244156,
0.008222139440476894,
0.03439024090766907,
0.04813065007328987,
-0.06461100280284882,
-0.022964414209127426,
0.004961690865457058,
0.023746194317936897,
0.019794130697846413,
-0.02027791179716587,
-0.011362893506884575,
-0.05639071762561798,
-0.012381571345031261,
-0.006364831235259771,
0.002698509255424142,
-0.005372054874897003,
0.00495578208938241,
-0.0781223252415657,
0.05783693864941597,
0.043286703526973724,
0.011035174131393433,
-0.0038485571276396513,
0.015112435445189476,
0.06554102152585983,
-0.053148772567510605,
-0.015782887116074562,
0.006583004258573055,
0.06787125766277313,
0.07018259167671204,
-0.01661328598856926,
-0.10095810145139694,
0.02001858316361904,
0.006401131860911846,
-0.03508925437927246,
-0.05603557825088501,
0.012927680276334286,
-0.02909918501973152,
-0.0294300876557827,
-0.07453307509422302,
0.01374203059822321,
0.03414054214954376,
-0.00467855017632246,
-5.4594354735743076e-33,
0.09173785895109177,
0.01251762080937624,
-0.07210435718297958,
-0.033904291689395905,
-0.056496761739254,
-0.02318471111357212,
-0.05245693400502205,
-0.012039782479405403,
-0.06324273347854614,
-0.0425184927880764,
0.02133307233452797,
0.043849799782037735,
0.0032767702359706163,
0.09325528889894485,
-0.018945524469017982,
-0.02596895396709442,
0.0775553435087204,
0.038533736020326614,
0.04531006142497063,
-0.023326030001044273,
0.091084323823452,
-0.016432160511612892,
-0.06728912144899368,
0.0054216524586081505,
0.040750015527009964,
-0.024107199162244797,
-0.006149011198431253,
0.03081796132028103,
0.03679630905389786,
-0.010952982120215893,
0.06862933933734894,
-0.030746573582291603,
0.0034817359410226345,
0.04972393438220024,
0.01394652295857668,
-0.013006938621401787,
0.004704616963863373,
0.011573118157684803,
0.04786260426044464,
-0.03240523859858513,
0.11033233255147934,
0.020296627655625343,
0.03529459983110428,
0.0735175609588623,
0.033056069165468216,
0.05753832682967186,
0.012041343376040459,
-0.04384783282876015,
-0.020392414182424545,
0.01929498091340065,
0.056552547961473465,
-0.0110235083848238,
0.01534233521670103,
0.11600733548402786,
-0.03870770335197449,
-0.04276736080646515,
0.01061845850199461,
0.014215318486094475,
-0.09275992214679718,
-0.050845835357904434,
0.049536969512701035,
-0.014155098237097263,
-0.03465776517987251,
-0.01788000948727131,
0.027886277064681053,
0.03489900752902031,
-0.009975242428481579,
0.0507328175008297,
0.05186765640974045,
-0.07015177607536316,
0.08244971185922623,
-0.020625773817300797,
-0.11713556945323944,
0.045718442648649216,
-0.08872485160827637,
0.11196298152208328,
-0.032629720866680145,
-0.132348895072937,
-0.010530116967856884,
0.08600880205631256,
-0.049054428935050964,
0.01742066629230976,
-0.014436540193855762,
0.038252092897892,
0.02973359264433384,
-0.059449534863233566,
-0.09158408641815186,
0.020264698192477226,
-0.00912794005125761,
-0.02829863131046295,
0.06707513332366943,
-0.014634566381573677,
-0.017777156084775925,
0.003725707530975342,
0.03485296294093132,
-5.3836007651852924e-8,
0.08926588296890259,
-0.04036625847220421,
-0.031781572848558426,
-0.013938046991825104,
0.009646398946642876,
-0.0409625805914402,
-0.040218472480773926,
-0.08184969425201416,
-0.0019134951289743185,
0.01384037546813488,
-0.09102415293455124,
-0.057325731962919235,
-0.04547777771949768,
-0.046978745609521866,
0.04855640232563019,
-0.00783382449299097,
-0.008870851248502731,
-0.07106178253889084,
0.03341037034988403,
-0.03378384932875633,
0.0026461174711585045,
-0.011008198373019695,
-0.04674883931875229,
0.017830759286880493,
-0.14943388104438782,
-0.07685476541519165,
0.05966595932841301,
0.047735560685396194,
-0.15856395661830902,
-0.05732182785868645,
0.0580858439207077,
0.016674119979143143,
0.03152048960328102,
0.10260988771915436,
0.044425688683986664,
0.016110854223370552,
0.026429826393723488,
0.012280449271202087,
0.0013264684239402413,
0.0349847674369812,
-0.001351958024315536,
0.03700093924999237,
-0.021600738167762756,
0.03864159807562828,
0.022367436438798904,
0.04181857034564018,
-0.008040761575102806,
0.03326113149523735,
-0.033582497388124466,
0.046705543994903564,
0.01450869720429182,
0.03769666701555252,
-0.029945651069283485,
0.06041938439011574,
0.05047573894262314,
-0.027006447315216064,
-0.04525364190340042,
-0.01706540212035179,
-0.020865419879555702,
0.11246706545352936,
-0.00719971489161253,
0.016113489866256714,
0.03999541699886322,
-0.03581562265753746
] | 0.095505 |
the child process failed or timed out. The `child\_process.spawnSync()` method is generally identical to [`child\_process.spawn()`][] with the exception that the function will not return until the child process has fully closed. When a timeout has been encountered and `killSignal` is sent, the method won't return until the process has completely exited. If the process intercepts and handles the `SIGTERM` signal and doesn't exit, the parent process will wait until the child process has exited. \*\*If the `shell` option is enabled, do not pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.\*\* ## Class: `ChildProcess` \* Extends: {EventEmitter} Instances of the `ChildProcess` represent spawned child processes. Instances of `ChildProcess` are not intended to be created directly. Rather, use the [`child\_process.spawn()`][], [`child\_process.exec()`][], [`child\_process.execFile()`][], or [`child\_process.fork()`][] methods to create instances of `ChildProcess`. ### Event: `'close'` \* `code` {number} The exit code if the child process exited on its own, or `null` if the child process terminated due to a signal. \* `signal` {string} The signal by which the child process was terminated, or `null` if the child process did not terminated due to a signal. The `'close'` event is emitted after a process has ended \_and\_ the stdio streams of a child process have been closed. This is distinct from the [`'exit'`][] event, since multiple processes might share the same stdio streams. The `'close'` event will always emit after [`'exit'`][] was already emitted, or [`'error'`][] if the child process failed to spawn. If the process exited, `code` is the final exit code of the process, otherwise `null`. If the process terminated due to receipt of a signal, `signal` is the string name of the signal, otherwise `null`. One of the two will always be non-`null`. ```cjs const { spawn } = require('node:child\_process'); const ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.on('close', (code) => { console.log(`child process close all stdio with code ${code}`); }); ls.on('exit', (code) => { console.log(`child process exited with code ${code}`); }); ``` ```mjs import { spawn } from 'node:child\_process'; import { once } from 'node:events'; const ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.on('close', (code) => { console.log(`child process close all stdio with code ${code}`); }); ls.on('exit', (code) => { console.log(`child process exited with code ${code}`); }); const [code] = await once(ls, 'close'); console.log(`child process close all stdio with code ${code}`); ``` ### Event: `'disconnect'` The `'disconnect'` event is emitted after calling the [`subprocess.disconnect()`][] method in parent process or [`process.disconnect()`][] in child process. After disconnecting it is no longer possible to send or receive messages, and the [`subprocess.connected`][] property is `false`. ### Event: `'error'` \* `err` {Error} The error. The `'error'` event is emitted whenever: \* The process could not be spawned. \* The process could not be killed. \* Sending a message to the child process failed. \* The child process was aborted via the `signal` option. The `'exit'` event may or may not fire after an error has occurred. When listening to both the `'exit'` and `'error'` events, guard against accidentally invoking handler functions multiple times. See also [`subprocess.kill()`][] and [`subprocess.send()`][]. ### Event: `'exit'` \* `code` {number} The exit code if the child process exited on its own, or `null` if the child process terminated due to a signal. \* `signal` {string} The signal by which the child process was terminated, or `null` if the child process did not terminated due to a signal. The `'exit'` event is emitted after the child process ends. If the process exited, `code` is the final exit code of the process, | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.005721727851778269,
0.020149478688836098,
-0.08177157491445541,
0.023855866864323616,
0.032594945281744,
-0.05619485676288605,
-0.013025294058024883,
0.1283123940229416,
0.004420854151248932,
0.06582282483577728,
-0.0007631045882590115,
-0.03354866802692413,
-0.036780282855033875,
-0.022875577211380005,
0.013855213299393654,
0.009711090475320816,
0.005480291321873665,
-0.05844171345233917,
-0.04647523909807205,
-0.0699109435081482,
0.026850100606679916,
-0.022791339084506035,
0.022469010204076767,
0.012929876334965229,
-0.09903370589017868,
-0.03835824504494667,
-0.07572974264621735,
-0.053723353892564774,
0.03187401220202446,
0.043856848031282425,
0.03702733293175697,
-0.00197442970238626,
-0.055911362171173096,
-0.07050832360982895,
0.03288737311959267,
0.16495634615421295,
0.10907649248838425,
-0.007631637156009674,
-0.05787142738699913,
-0.0400782935321331,
0.05293137952685356,
0.0065395343117415905,
-0.11098697036504745,
-0.016248425468802452,
-0.0115619245916605,
-0.05150490626692772,
-0.06027686968445778,
-0.08339948952198029,
-0.04687289893627167,
0.012329447083175182,
-0.052883218973875046,
0.03951096907258034,
0.008070798590779305,
0.05603610351681709,
-0.023029446601867676,
-0.026442307978868484,
0.058811817318201065,
-0.015607962384819984,
0.004233027808368206,
-0.015289121307432652,
-0.09123566001653671,
0.034702666103839874,
-0.1377333402633667,
-0.01232942845672369,
0.05812464654445648,
0.04526159539818764,
-0.009594707749783993,
-0.13296113908290863,
0.053082793951034546,
0.01172850001603365,
0.002324634464457631,
-0.01099041011184454,
-0.1132068857550621,
0.11028783023357391,
-0.011062918230891228,
0.0673907920718193,
0.037174537777900696,
-0.03072945401072502,
-0.01288712676614523,
-0.09132888913154602,
0.00027387531008571386,
0.0174484234303236,
-0.03128030523657799,
-0.07403852045536041,
0.011449062265455723,
0.05192269757390022,
0.03439687564969063,
0.01977534405887127,
0.07864103466272354,
0.061838001012802124,
-0.05007079988718033,
0.04716815426945686,
0.0018908334895968437,
0.05522211641073227,
0.05443037301301956,
0.026973851025104523,
-0.008951060473918915,
-0.0239629615098238,
-0.06331381946802139,
-0.01294297631829977,
-0.0005821406375616789,
0.0374937430024147,
-0.028660571202635765,
-0.01836991310119629,
0.03501179814338684,
-0.0024349659215658903,
-0.05224369093775749,
-0.026374874636530876,
-0.00032498399377800524,
-0.03017505072057247,
-0.030308036133646965,
-0.0331992469727993,
0.06083026900887489,
0.04961742088198662,
0.04293995350599289,
0.09698885679244995,
0.05169478803873062,
0.020113402977585793,
0.034808047115802765,
0.04120723158121109,
0.1439836174249649,
0.0349433571100235,
-0.007527213077992201,
-0.02445671334862709,
0.039566025137901306,
-0.06827820837497711,
0.03265082836151123,
2.913847722912934e-33,
-0.03569142147898674,
-0.05399942398071289,
-0.025960586965084076,
0.0598716102540493,
0.06955210119485855,
0.0463334359228611,
-0.005917903035879135,
0.05070916563272476,
0.016994992271065712,
0.05361054465174675,
-0.041962720453739166,
-0.1506858766078949,
0.01437791995704174,
-0.07564461976289749,
0.06385308504104614,
0.004632080439478159,
0.07275404781103134,
0.0013903097715228796,
0.007915281690657139,
0.06744534522294998,
0.05134529992938042,
-0.0319385826587677,
-0.0445077084004879,
0.06260354816913605,
0.028786838054656982,
0.03881719708442688,
-0.13344401121139526,
0.08123435825109482,
0.05552813410758972,
0.029339300468564034,
-0.030710887163877487,
-0.003109897719696164,
-0.03532954677939415,
-0.00855240598320961,
-0.009247956797480583,
-0.0923556238412857,
0.011206491850316525,
0.0034224106930196285,
-0.01292642392218113,
-0.06440802663564682,
-0.050020597875118256,
-0.0638948604464531,
-0.0868285670876503,
0.0705719068646431,
-0.029001466929912567,
-0.14580707252025604,
-0.06482493877410889,
-0.005112832877784967,
0.04586699977517128,
-0.0024662709329277277,
0.06277354806661606,
0.028850330039858818,
0.03140652924776077,
0.004983787424862385,
-0.013754312880337238,
0.1084529235959053,
-0.049252890050411224,
-0.05349091812968254,
-0.03290135785937309,
-0.0348932258784771,
0.08696204423904419,
-0.03094124235212803,
-0.025157034397125244,
0.026381853967905045,
0.025443535298109055,
-0.07943716645240784,
0.01315197255462408,
-0.01752222329378128,
0.0025310309138149023,
0.021084656938910484,
-0.03817280754446983,
0.0537613183259964,
-0.04111199826002121,
-0.060332927852869034,
-0.01620715856552124,
-0.057992834597826004,
0.09795505553483963,
-0.10494514554738998,
-0.042697660624980927,
0.03595608472824097,
0.09351210296154022,
0.004989734850823879,
-0.09092264622449875,
-0.056106049567461014,
0.0011513460194692016,
-0.012815858237445354,
-0.022842293605208397,
-0.026036595925688744,
-0.06297673285007477,
-0.05907841771841049,
-0.04991094768047333,
-0.04828142374753952,
-0.013828067108988762,
-0.002659094985574484,
-0.052188362926244736,
-6.62088597298213e-33,
0.06847108900547028,
-0.04207342863082886,
-0.016155380755662918,
0.02011279948055744,
-0.010785366408526897,
-0.0471230074763298,
-0.00819393340498209,
-0.0313476026058197,
-0.07191278040409088,
-0.04384949803352356,
-0.03102538175880909,
0.022536227479577065,
-0.00949846487492323,
0.06210688129067421,
-0.039627958089113235,
-0.009983247146010399,
0.044078946113586426,
-0.006712429691106081,
0.05907342582941055,
0.044806286692619324,
0.023988213390111923,
-0.00042518042027950287,
-0.09419853985309601,
0.0624733529984951,
-0.023014968261122704,
-0.056884463876485825,
-0.011906729079782963,
0.005533261224627495,
-0.0014349273405969143,
0.03787977620959282,
0.05718456581234932,
0.04336327314376831,
0.032090649008750916,
0.11436440795660019,
0.0015140344621613622,
-0.01448068767786026,
0.0029361697379499674,
0.04043245315551758,
0.010561230592429638,
-0.013348876498639584,
0.1501285433769226,
0.0517672598361969,
-0.0012756382348015904,
-0.004907646216452122,
0.00484105572104454,
0.04392535984516144,
0.04162856936454773,
0.028703447431325912,
-0.03692943975329399,
0.06460580229759216,
-0.013453410007059574,
-0.03364070504903793,
-0.010555014945566654,
0.09208289533853531,
-0.016806453466415405,
-0.006467112340033054,
0.05411529913544655,
-0.05611889436841011,
-0.022615483030676842,
-0.040370259433984756,
0.011280782520771027,
-0.052272383123636246,
0.02817029319703579,
-0.014966864138841629,
0.026161111891269684,
0.03801250457763672,
-0.018007664009928703,
0.035444047302007675,
0.04477967694401741,
-0.0182329174131155,
0.16190341114997864,
0.08225533366203308,
-0.065815769135952,
-0.0028907759115099907,
-0.08462656289339066,
0.07776226103305817,
-0.04830396920442581,
-0.05025086924433708,
-0.044945135712623596,
0.04284506291151047,
0.04154001176357269,
0.029821766540408134,
-0.004804186522960663,
-0.016114169731736183,
-0.021846063435077667,
-0.04120824486017227,
-0.030135534703731537,
0.08264253288507462,
-0.01668243110179901,
-0.032985005527734756,
0.038427215069532394,
-0.0012427298352122307,
0.004113570787012577,
0.006303834728896618,
0.024967728182673454,
-5.921852519463755e-8,
0.01961563155055046,
-0.00820587482303381,
-0.011297831311821938,
-0.007372637744992971,
0.0009943291079252958,
-0.031470272690057755,
0.012460015714168549,
-0.10933680087327957,
-0.0017343353247269988,
0.0005461420514620841,
-0.09898840636014938,
-0.03573969006538391,
0.02792390063405037,
0.015695838257670403,
0.022322693839669228,
-0.0024020362179726362,
0.039513058960437775,
0.026473088189959526,
0.008393378928303719,
-0.05264146998524666,
-0.02093694917857647,
-0.014802245423197746,
0.004095062147825956,
-0.03160640224814415,
-0.10090479254722595,
-0.04124301299452782,
0.010058981366455555,
0.031246917322278023,
-0.10926289856433868,
-0.06495259702205658,
0.019631272181868553,
0.013816002756357193,
0.009199537336826324,
0.08860159665346146,
-0.04346834868192673,
0.0038784213829785585,
-0.04036540910601616,
0.012591499835252762,
0.020801590755581856,
-0.058932624757289886,
0.08596481382846832,
0.10187184065580368,
-0.042946670204401016,
-0.03452250361442566,
0.005776537582278252,
0.03156737610697746,
-0.014734333381056786,
0.0551527664065361,
-0.004341803956776857,
0.08057966083288193,
-0.014863839372992516,
0.03712891414761543,
-0.05703304335474968,
0.023304017260670662,
0.06776446849107742,
0.004482842516154051,
-0.004287650343030691,
-0.03587062656879425,
0.007090921048074961,
0.08761322498321533,
0.00040057094884105027,
0.049184709787368774,
0.04431750997900963,
-0.05620493367314339
] | 0.096 |
a signal. \* `signal` {string} The signal by which the child process was terminated, or `null` if the child process did not terminated due to a signal. The `'exit'` event is emitted after the child process ends. If the process exited, `code` is the final exit code of the process, otherwise `null`. If the process terminated due to receipt of a signal, `signal` is the string name of the signal, otherwise `null`. One of the two will always be non-`null`. When the `'exit'` event is triggered, child process stdio streams might still be open. Node.js establishes signal handlers for `SIGINT` and `SIGTERM` and Node.js processes will not terminate immediately due to receipt of those signals. Rather, Node.js will perform a sequence of cleanup actions and then will re-raise the handled signal. See waitpid(2). When `code` is `null` due to signal termination, you can use [`util.convertProcessSignalToExitCode()`][] to convert the signal to a POSIX exit code. ### Event: `'message'` \* `message` {Object} A parsed JSON object or primitive value. \* `sendHandle` {Handle|undefined} `undefined` or a [`net.Socket`][], [`net.Server`][], or [`dgram.Socket`][] object. The `'message'` event is triggered when a child process uses [`process.send()`][] to send messages. The message goes through serialization and parsing. The resulting message might not be the same as what is originally sent. If the `serialization` option was set to `'advanced'` used when spawning the child process, the `message` argument can contain data that JSON is not able to represent. See [Advanced serialization][] for more details. ### Event: `'spawn'` The `'spawn'` event is emitted once the child process has spawned successfully. If the child process does not spawn successfully, the `'spawn'` event is not emitted and the `'error'` event is emitted instead. If emitted, the `'spawn'` event comes before all other events and before any data is received via `stdout` or `stderr`. The `'spawn'` event will fire regardless of whether an error occurs \*\*within\*\* the spawned process. For example, if `bash some-command` spawns successfully, the `'spawn'` event will fire, though `bash` may fail to spawn `some-command`. This caveat also applies when using `{ shell: true }`. ### `subprocess.channel` \* Type: {Object} A pipe representing the IPC channel to the child process. The `subprocess.channel` property is a reference to the child's IPC channel. If no IPC channel exists, this property is `undefined`. #### `subprocess.channel.ref()` This method makes the IPC channel keep the event loop of the parent process running if `.unref()` has been called before. #### `subprocess.channel.unref()` This method makes the IPC channel not keep the event loop of the parent process running, and lets it finish even while the channel is open. ### `subprocess.connected` \* Type: {boolean} Set to `false` after `subprocess.disconnect()` is called. The `subprocess.connected` property indicates whether it is still possible to send and receive messages from a child process. When `subprocess.connected` is `false`, it is no longer possible to send or receive messages. ### `subprocess.disconnect()` Closes the IPC channel between parent and child processes, allowing the child process to exit gracefully once there are no other connections keeping it alive. After calling this method the `subprocess.connected` and `process.connected` properties in both the parent and child processes (respectively) will be set to `false`, and it will be no longer possible to pass messages between the processes. The `'disconnect'` event will be emitted when there are no messages in the process of being received. This will most often be triggered immediately after calling `subprocess.disconnect()`. When the child process is a Node.js instance (e.g. spawned using [`child\_process.fork()`][]), the `process.disconnect()` method can be invoked within the child process to close the IPC channel as well. ### `subprocess.exitCode` \* Type: {integer} The `subprocess.exitCode` | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.04245375469326973,
-0.016354024410247803,
-0.014830515719950199,
0.023933153599500656,
0.05446978285908699,
-0.025455068796873093,
-0.01842653751373291,
0.036567993462085724,
0.0876661017537117,
0.020301567390561104,
-0.028563039377331734,
0.014852691441774368,
-0.0819120854139328,
-0.05133504047989845,
-0.0029349541291594505,
0.011985225602984428,
-0.03659524396061897,
-0.0033905701711773872,
0.021264567971229553,
-0.11037691682577133,
0.011432318016886711,
-0.017944861203432083,
-0.001784909050911665,
-0.025052344426512718,
-0.06668732315301895,
0.07517028599977493,
0.0012525632046163082,
-0.04282807186245918,
0.05380336195230484,
-0.023520054295659065,
0.02118850126862526,
-0.05584602430462837,
-0.0005595080438069999,
-0.01528586633503437,
-0.005382771138101816,
0.16029702126979828,
0.010973529890179634,
-0.09604925662279129,
-0.10011976957321167,
0.00919492170214653,
0.06503279507160187,
0.04726660996675491,
-0.13469839096069336,
0.021025627851486206,
0.006132536102086306,
0.015161028131842613,
-0.09938623756170273,
-0.04349030926823616,
-0.09421047568321228,
-0.031050659716129303,
0.016363155096769333,
-0.010054878890514374,
-0.030963148921728134,
0.10117781162261963,
0.011052235029637814,
-0.001607663813047111,
0.033134087920188904,
-0.03566855937242508,
0.027559379115700722,
0.0489024892449379,
-0.06601116061210632,
0.013197571039199829,
-0.04232475161552429,
-0.034455135464668274,
0.049525316804647446,
0.07046843320131302,
0.00040550591074861586,
-0.07325411587953568,
0.07668806612491608,
0.01223266776651144,
-0.003485396970063448,
-0.04909482225775719,
-0.06454350799322128,
0.05816591903567314,
-0.04815095663070679,
-0.022128447890281677,
-0.00011882343096658587,
-0.02552945166826248,
-0.052771683782339096,
0.02634355053305626,
-0.04938994348049164,
-0.027481526136398315,
-0.06796567887067795,
-0.053601156920194626,
-0.04103365167975426,
0.13626185059547424,
-0.03637244552373886,
-0.05489974841475487,
0.05277322232723236,
0.09970075637102127,
-0.12809260189533234,
0.0057141478173434734,
-0.018328264355659485,
0.0634312555193901,
0.010896852239966393,
-0.008340859785676003,
0.013242503628134727,
0.020779596641659737,
-0.01614709571003914,
-0.03373979777097702,
0.03347758948802948,
0.026310713961720467,
-0.01846780814230442,
0.0004634195938706398,
0.01806553080677986,
-0.04143967851996422,
-0.0590846985578537,
0.008120766840875149,
-0.017730984836816788,
-0.020210888236761093,
-0.016349412500858307,
0.017366770654916763,
0.048334017395973206,
0.029511675238609314,
-0.036501575261354446,
0.08210171014070511,
0.06226499378681183,
0.044565003365278244,
0.04470859840512276,
0.0926516056060791,
0.08386903256177902,
0.022878417745232582,
-0.04874824732542038,
-0.004624850582331419,
-0.010644265450537205,
-0.0906209722161293,
0.018874354660511017,
9.792530076276954e-34,
-0.056427255272865295,
-0.05807692930102348,
-0.02124614268541336,
0.018864622339606285,
0.007021966855973005,
0.032504331320524216,
-0.035620417445898056,
0.005923794116824865,
0.011713605374097824,
0.04971929267048836,
-0.04404263570904732,
-0.08479513972997665,
0.004693655297160149,
-0.004705142695456743,
0.0781184509396553,
-0.018727432936429977,
0.07774744927883148,
-0.010407860390841961,
0.005290762986987829,
0.03381107375025749,
0.021575570106506348,
0.01336456835269928,
-0.06424891203641891,
0.07294441759586334,
0.0856078565120697,
0.02544449083507061,
-0.09119269251823425,
0.021055586636066437,
-0.02201416902244091,
0.0006519865128211677,
-0.03855106979608536,
0.01582169346511364,
0.01066772174090147,
-0.034408628940582275,
0.050848089158535004,
-0.04207960516214371,
0.03573979064822197,
0.017885899171233177,
-0.04036225378513336,
-0.044467899948358536,
-0.06661722809076309,
-0.012870104052126408,
-0.08213062584400177,
-0.006316106300801039,
0.006670528091490269,
-0.16690188646316528,
-0.0001624969154363498,
-0.026179593056440353,
0.05076470226049423,
-0.014829573221504688,
0.10368349403142929,
-0.020047565922141075,
0.06990707665681839,
0.04225343093276024,
-0.017431003972887993,
0.13238641619682312,
0.009955612942576408,
-0.08504658192396164,
-0.09858838468790054,
0.04330238327383995,
0.09776629507541656,
-0.007065365556627512,
0.005029069725424051,
-0.0068374574184417725,
0.015461018308997154,
0.03554834425449371,
-0.0023983879946172237,
-0.052054572850465775,
-0.011913923546671867,
-0.0343484953045845,
-0.060763321816921234,
0.028644923120737076,
-0.004534000996500254,
-0.02669600397348404,
0.01803450845181942,
0.0395975261926651,
-0.06792387366294861,
0.00323561392724514,
0.03561518341302872,
-0.012797072529792786,
0.12809991836547852,
-0.05009695515036583,
0.0024200754705816507,
0.00020137772662565112,
0.037374526262283325,
0.04886156693100929,
-0.01349628809839487,
-0.0797918438911438,
-0.05456518009305,
0.016906963661313057,
0.007848476991057396,
-0.018484851345419884,
0.014325815252959728,
0.02141079120337963,
-0.02597716450691223,
-4.86121721489123e-33,
-0.012125310488045216,
0.04695458337664604,
-0.08010007441043854,
-0.005972976330667734,
-0.06828293949365616,
-0.04091937467455864,
-0.018536977469921112,
-0.06724810600280762,
0.006579397711902857,
0.0508219413459301,
0.016332225874066353,
0.012400529347360134,
-0.011139536276459694,
0.06970725953578949,
-0.07041231542825699,
0.03196312487125397,
0.0348038449883461,
-0.008128635585308075,
-0.002025658031925559,
0.014391046017408371,
0.009512669406831264,
-0.019688647240400314,
-0.026201406493782997,
-0.060425955802202225,
0.036822378635406494,
-0.029352610930800438,
0.017305830493569374,
0.003825144376605749,
-0.055011503398418427,
-0.025592196732759476,
0.02140073850750923,
-0.009833680465817451,
0.0461435541510582,
0.08119691163301468,
0.07945163547992706,
-0.06238679587841034,
0.013047569431364536,
0.060312945395708084,
0.06700403988361359,
-0.09604630619287491,
0.12270069122314453,
0.0540744885802269,
0.09469547122716904,
0.022800780832767487,
-0.010619031265377998,
0.03474713861942291,
-0.03328283131122589,
0.07072269171476364,
-0.052420008927583694,
0.012525751255452633,
-0.04447520896792412,
0.051978178322315216,
0.03442898020148277,
0.0887717679142952,
-0.08773618191480637,
-0.0266497191041708,
0.00017453567124903202,
0.03785223141312599,
-0.004023916553705931,
-0.05302195996046066,
0.05743285268545151,
-0.0814417377114296,
-0.032903775572776794,
0.017442205920815468,
0.04537156596779823,
-0.040866732597351074,
-0.07509009540081024,
0.00561980064958334,
0.07166261970996857,
-0.09281425178050995,
0.03728882968425751,
0.08101129531860352,
-0.08489669859409332,
-0.02653547190129757,
-0.09103760868310928,
0.042654041200876236,
-0.0742107406258583,
-0.1332836151123047,
0.011208713054656982,
0.010951770469546318,
-0.012909919954836369,
0.06211497634649277,
-0.027472609654068947,
0.04290612041950226,
0.012382185086607933,
0.03060811571776867,
0.0026312486734241247,
-0.018002651631832123,
0.010451561771333218,
-0.017044642940163612,
0.0038437454495579004,
0.06731334328651428,
-0.10080821067094803,
-0.05713576450943947,
-0.03086329996585846,
-5.2679144602052475e-8,
-0.026240579783916473,
-0.021358510479331017,
-0.07503026723861694,
-0.01582183875143528,
0.052441854029893875,
-0.020589549094438553,
0.01984100043773651,
-0.021771302446722984,
0.041382718831300735,
0.04388672485947609,
-0.07027977705001831,
-0.01675492152571678,
-0.03502309322357178,
-0.04157620295882225,
0.05276406183838844,
0.0028218708466738462,
0.030800342559814453,
0.0012928679352626204,
0.04408074915409088,
-0.018590670078992844,
0.022710692137479782,
0.011901906691491604,
-0.05808716639876366,
0.0857260674238205,
-0.07056982070207596,
-0.06676386296749115,
0.10607638210058212,
0.060669247061014175,
-0.05522849038243294,
-0.028806207701563835,
0.04877637326717377,
0.05381433665752411,
0.028052132576704025,
0.02996872365474701,
-0.03232007473707199,
0.05843037739396095,
0.021052446216344833,
0.0024401401169598103,
0.042484477162361145,
0.07127507030963898,
0.02460705302655697,
0.11246589571237564,
-0.05314934626221657,
0.02345021441578865,
-0.05416687950491905,
0.037988048046827316,
0.06291046738624573,
0.01279652863740921,
0.018953189253807068,
0.0906481072306633,
0.043890807777643204,
-0.03873809054493904,
-0.08824215084314346,
-0.046237580478191376,
0.019026951864361763,
-0.055869363248348236,
-0.012105552479624748,
-0.07778775691986084,
-0.07321225851774216,
0.0898522287607193,
0.03513650968670845,
0.018292590975761414,
0.060242924839258194,
-0.054719697684049606
] | 0.147201 |
process of being received. This will most often be triggered immediately after calling `subprocess.disconnect()`. When the child process is a Node.js instance (e.g. spawned using [`child\_process.fork()`][]), the `process.disconnect()` method can be invoked within the child process to close the IPC channel as well. ### `subprocess.exitCode` \* Type: {integer} The `subprocess.exitCode` property indicates the exit code of the child process. If the child process is still running, the field will be `null`. When the child process is terminated by a signal, `subprocess.exitCode` will be `null` and [`subprocess.signalCode`][] will be set. To get the corresponding POSIX exit code, use [`util.convertProcessSignalToExitCode(subprocess.signalCode)`][`util.convertProcessSignalToExitCode()`]. ### `subprocess.kill([signal])` \* `signal` {number|string} \* Returns: {boolean} The `subprocess.kill()` method sends a signal to the child process. If no argument is given, the process will be sent the `'SIGTERM'` signal. See signal(7) for a list of available signals. This function returns `true` if kill(2) succeeds, and `false` otherwise. ```cjs const { spawn } = require('node:child\_process'); const grep = spawn('grep', ['ssh']); grep.on('close', (code, signal) => { console.log( `child process terminated due to receipt of signal ${signal}`); }); // Send SIGHUP to process. grep.kill('SIGHUP'); ``` ```mjs import { spawn } from 'node:child\_process'; const grep = spawn('grep', ['ssh']); grep.on('close', (code, signal) => { console.log( `child process terminated due to receipt of signal ${signal}`); }); // Send SIGHUP to process. grep.kill('SIGHUP'); ``` The [`ChildProcess`][] object may emit an [`'error'`][] event if the signal cannot be delivered. Sending a signal to a child process that has already exited is not an error but may have unforeseen consequences. Specifically, if the process identifier (PID) has been reassigned to another process, the signal will be delivered to that process instead which can have unexpected results. While the function is called `kill`, the signal delivered to the child process may not actually terminate the process. See kill(2) for reference. On Windows, where POSIX signals do not exist, the `signal` argument will be ignored except for `'SIGKILL'`, `'SIGTERM'`, `'SIGINT'` and `'SIGQUIT'`, and the process will always be killed forcefully and abruptly (similar to `'SIGKILL'`). See [Signal Events][] for more details. On Linux, child processes of child processes will not be terminated when attempting to kill their parent. This is likely to happen when running a new process in a shell or with the use of the `shell` option of `ChildProcess`: ```cjs const { spawn } = require('node:child\_process'); const subprocess = spawn( 'sh', [ '-c', `node -e "setInterval(() => { console.log(process.pid, 'is alive') }, 500);"`, ], { stdio: ['inherit', 'inherit', 'inherit'], }, ); setTimeout(() => { subprocess.kill(); // Does not terminate the Node.js process in the shell. }, 2000); ``` ```mjs import { spawn } from 'node:child\_process'; const subprocess = spawn( 'sh', [ '-c', `node -e "setInterval(() => { console.log(process.pid, 'is alive') }, 500);"`, ], { stdio: ['inherit', 'inherit', 'inherit'], }, ); setTimeout(() => { subprocess.kill(); // Does not terminate the Node.js process in the shell. }, 2000); ``` ### `subprocess[Symbol.dispose]()` Calls [`subprocess.kill()`][] with `'SIGTERM'`. ### `subprocess.killed` \* Type: {boolean} Set to `true` after `subprocess.kill()` is used to successfully send a signal to the child process. The `subprocess.killed` property indicates whether the child process successfully received a signal from `subprocess.kill()`. The `killed` property does not indicate that the child process has been terminated. ### `subprocess.pid` \* Type: {integer|undefined} Returns the process identifier (PID) of the child process. If the child process fails to spawn due to errors, then the value is `undefined` and `error` is emitted. ```cjs const { spawn } = require('node:child\_process'); const grep = spawn('grep', ['ssh']); console.log(`Spawned child pid: ${grep.pid}`); grep.stdin.end(); ``` ```mjs import { spawn } from 'node:child\_process'; const grep = spawn('grep', ['ssh']); console.log(`Spawned child pid: ${grep.pid}`); grep.stdin.end(); | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.05836378037929535,
0.009313330054283142,
-0.03074059821665287,
0.02647906169295311,
0.056454136967659,
-0.07877740263938904,
0.03125424310564995,
0.04841955378651619,
0.06855157017707825,
0.02369529940187931,
-0.057794053107500076,
0.010647423565387726,
-0.08168970793485641,
-0.05436934530735016,
-0.001832478679716587,
0.034327637404203415,
0.02829311229288578,
-0.01966717094182968,
-0.014535170048475266,
-0.09634099155664444,
0.027029413729906082,
0.059324730187654495,
0.06202824041247368,
-0.025037726387381554,
-0.04064609855413437,
-0.006493113469332457,
0.005391177721321583,
-0.002516884356737137,
0.060211148113012314,
-0.01710178516805172,
0.030020304024219513,
-0.0026512255426496267,
-0.06234772130846977,
-0.011925715953111649,
0.024782227352261543,
0.1282690465450287,
0.044802162796258926,
-0.07056602835655212,
-0.03959614783525467,
0.04257183149456978,
0.12539514899253845,
0.028183285146951675,
-0.1428307145833969,
-0.020365076139569283,
0.0020081736147403717,
-0.0030915813986212015,
-0.1144561767578125,
-0.06334033608436584,
-0.03195897117257118,
-0.029055308550596237,
0.03230776637792587,
0.027885979041457176,
0.011428752914071083,
0.12317920476198196,
-0.0038793880958110094,
-0.00674423947930336,
0.04157686233520508,
-0.03821813687682152,
0.010392841883003712,
0.07175640016794205,
-0.0816086158156395,
0.02392536960542202,
-0.06034080311655998,
-0.0011889544548466802,
0.05489415302872658,
0.049113065004348755,
-0.002725902944803238,
-0.05567459017038345,
0.09245780110359192,
-0.043444689363241196,
0.016617782413959503,
-0.012959330342710018,
-0.08750690519809723,
0.0011183390161022544,
-0.04860677570104599,
0.013673588633537292,
0.0025973704177886248,
-0.028991037979722023,
-0.07374976575374603,
-0.03682553395628929,
-0.028897281736135483,
-0.03649942949414253,
-0.06669913977384567,
0.0066636172123253345,
-0.02730783261358738,
0.030425887554883957,
0.02388654090464115,
-0.011479447595775127,
0.05407173931598663,
0.11448629200458527,
-0.1332067847251892,
0.019191905856132507,
-0.01552099920809269,
0.05234651640057564,
0.021915756165981293,
0.03171032294631004,
-0.015342163853347301,
-0.010035911574959755,
-0.03828985244035721,
-0.022403351962566376,
0.029568683356046677,
-0.023840991780161858,
-0.010518736205995083,
-0.02159537933766842,
0.031852155923843384,
-0.01901121996343136,
-0.06119585037231445,
0.024582628160715103,
0.04473605751991272,
0.03201108053326607,
-0.053868748247623444,
0.02109677717089653,
0.00134602515026927,
0.03867524862289429,
0.018937375396490097,
0.10605987161397934,
0.08837691694498062,
0.07150156050920486,
0.025628473609685898,
0.06841815263032913,
0.09469594061374664,
-0.015959879383444786,
-0.014545359648764133,
-0.0030324547551572323,
-0.03922519460320473,
-0.08595645427703857,
0.017932383343577385,
2.6502539513295826e-33,
-0.018607286736369133,
-0.09331034868955612,
-0.015341210179030895,
0.05414701625704765,
0.025644829496741295,
0.07098710536956787,
0.0045700399205088615,
0.03205998241901398,
-0.01965753175318241,
0.039960816502571106,
-0.08336780220270157,
-0.05747738108038902,
0.010122059844434261,
-0.07893542945384979,
0.02508343569934368,
-0.04669826477766037,
0.02495814673602581,
-0.01002165675163269,
0.01687510311603546,
0.043701305985450745,
0.09077651798725128,
0.03965442255139351,
-0.06296802312135696,
0.10041966289281845,
0.06742465496063232,
0.009931747801601887,
-0.1184312105178833,
0.0005016628419980407,
0.0015590449329465628,
0.009604507125914097,
-0.002758604707196355,
0.058425456285476685,
0.029278242960572243,
-0.0361429899930954,
0.003476503072306514,
-0.04349702596664429,
0.0327078141272068,
0.010241850279271603,
-0.04057469964027405,
-0.09498896449804306,
-0.018709901720285416,
-0.0681077316403389,
-0.10342245548963547,
-0.025391343981027603,
-0.026657365262508392,
-0.1776399463415146,
-0.025340231135487556,
0.012877537868916988,
0.06263474375009537,
0.019004998728632927,
0.07945773005485535,
-0.03932924196124077,
0.08633067458868027,
-0.04595427215099335,
0.03504897654056549,
0.03153562918305397,
-0.01124303974211216,
-0.02152099646627903,
-0.011195152997970581,
-0.01276018749922514,
0.08280402421951294,
0.03175553306937218,
-0.04882240295410156,
-0.010669412091374397,
0.01738569140434265,
0.030891351401805878,
-0.006420287303626537,
-0.04756796732544899,
-0.0416577085852623,
-0.011057217605412006,
-0.1122756227850914,
0.06787160038948059,
-0.08962763845920563,
-0.019720232114195824,
-0.01612541265785694,
-0.005067331716418266,
-0.0724463239312172,
-0.04817859083414078,
-0.012435659766197205,
0.04120456799864769,
0.08613534271717072,
0.03474847599864006,
-0.057516202330589294,
0.02025403082370758,
0.011452590115368366,
0.028660990297794342,
0.007971622049808502,
-0.010004131123423576,
-0.07682084292173386,
-0.00907117873430252,
0.011544007807970047,
-0.0400330051779747,
-0.014399262145161629,
0.020866844803094864,
-0.01969730667769909,
-5.8707982522766286e-33,
-0.001260644756257534,
-0.010607530362904072,
-0.11768195033073425,
-0.0005011842586100101,
-0.06217919662594795,
-0.09263630956411362,
0.07635344564914703,
0.018804898485541344,
-0.027144262567162514,
0.06347933411598206,
-0.005655825603753328,
-0.013253318145871162,
-0.014514856971800327,
0.05213679000735283,
-0.04460766166448593,
-0.02229590341448784,
-0.02093578688800335,
-0.01007506437599659,
0.056648287922143936,
0.03275495022535324,
-0.03745187819004059,
0.024929266422986984,
0.02304445020854473,
-0.04051787406206131,
-0.04753440245985985,
-0.05893748998641968,
0.001960023306310177,
0.02417696826159954,
-0.05094536021351814,
-0.0680369883775711,
0.008809058926999569,
0.031160535290837288,
0.006404017563909292,
0.11158604174852371,
-0.03529702499508858,
-0.008311837911605835,
-0.004825074225664139,
0.019097214564681053,
0.06845226883888245,
-0.06854826956987381,
0.10326005518436432,
0.02471837028861046,
-0.007195034064352512,
0.03453872352838516,
0.029169565066695213,
-0.005379332695156336,
-0.009835467673838139,
0.08891379088163376,
-0.07125398516654968,
-0.019551314413547516,
-0.016548847779631615,
0.056630246341228485,
0.03235779330134392,
0.12836121022701263,
-0.03351574391126633,
0.030700160190463066,
0.07350678741931915,
-0.0037373907398432493,
0.03973362594842911,
-0.08977804332971573,
0.07870300114154816,
-0.09451084583997726,
-0.00202268292196095,
0.043658431619405746,
0.021961580961942673,
-0.018727893009781837,
-0.03604578971862793,
0.03725235164165497,
0.042030174285173416,
-0.094606913626194,
0.05178504064679146,
0.06575363129377365,
-0.043387364596128464,
-0.010130255483090878,
-0.0481904111802578,
0.03590879216790199,
-0.05700782686471939,
-0.06036350876092911,
-0.003124536946415901,
0.02603977918624878,
-0.021568983793258667,
0.04361956566572189,
-0.07836734503507614,
0.012781349010765553,
0.006741284858435392,
-0.032403383404016495,
-0.005221021827310324,
0.04956020414829254,
0.01963178999722004,
-0.03853951022028923,
-0.029579004272818565,
0.02790416032075882,
-0.02731296978890896,
-0.017887013033032417,
-0.02769196778535843,
-5.2297746577778526e-8,
-0.033667679876089096,
0.011641363613307476,
-0.00003632956213550642,
0.010204865597188473,
0.04747342690825462,
0.014195050112903118,
-0.0025677199009805918,
-0.014754336327314377,
0.07444748282432556,
0.037919361144304276,
-0.02756831981241703,
-0.010050240904092789,
-0.008519631810486317,
0.015016049146652222,
0.041839007288217545,
0.027024604380130768,
0.06364040821790695,
0.02646375633776188,
0.07127111405134201,
-0.026648804545402527,
0.007407141849398613,
-0.07007212191820145,
-0.044102367013692856,
0.10256413370370865,
-0.08916483074426651,
-0.07893401384353638,
0.10436262935400009,
0.03895532339811325,
-0.09930070489645004,
-0.04485737904906273,
-0.00845577847212553,
0.020482409745454788,
0.05747631937265396,
0.04882391169667244,
-0.07237038761377335,
0.11944960057735443,
-0.05948746204376221,
0.04595652222633362,
0.046416766941547394,
0.0565381795167923,
-0.00033521419391036034,
0.05509694293141365,
-0.10819660872220993,
-0.013732141815125942,
0.003073653904721141,
0.0540638230741024,
0.00603587506338954,
0.06936230510473251,
0.0393068827688694,
0.09697812050580978,
0.019634105265140533,
-0.042773738503456116,
-0.08464005589485168,
-0.051920752972364426,
-0.003122559515759349,
-0.035617198795080185,
-0.011136351153254509,
-0.09538020193576813,
-0.056685954332351685,
0.0455591157078743,
-0.0003968495875597,
0.046443864703178406,
-0.009866691194474697,
-0.04905552789568901
] | 0.106203 |
fails to spawn due to errors, then the value is `undefined` and `error` is emitted. ```cjs const { spawn } = require('node:child\_process'); const grep = spawn('grep', ['ssh']); console.log(`Spawned child pid: ${grep.pid}`); grep.stdin.end(); ``` ```mjs import { spawn } from 'node:child\_process'; const grep = spawn('grep', ['ssh']); console.log(`Spawned child pid: ${grep.pid}`); grep.stdin.end(); ``` ### `subprocess.ref()` Calling `subprocess.ref()` after making a call to `subprocess.unref()` will restore the removed reference count for the child process, forcing the parent process to wait for the child process to exit before exiting itself. ```cjs const { spawn } = require('node:child\_process'); const process = require('node:process'); const subprocess = spawn(process.argv[0], ['child\_program.js'], { detached: true, stdio: 'ignore', }); subprocess.unref(); subprocess.ref(); ``` ```mjs import { spawn } from 'node:child\_process'; import process from 'node:process'; const subprocess = spawn(process.argv[0], ['child\_program.js'], { detached: true, stdio: 'ignore', }); subprocess.unref(); subprocess.ref(); ``` ### `subprocess.send(message[, sendHandle[, options]][, callback])` \* `message` {Object} \* `sendHandle` {Handle|undefined} `undefined`, or a [`net.Socket`][], [`net.Server`][], or [`dgram.Socket`][] object. \* `options` {Object} The `options` argument, if present, is an object used to parameterize the sending of certain types of handles. `options` supports the following properties: \* `keepOpen` {boolean} A value that can be used when passing instances of `net.Socket`. When `true`, the socket is kept open in the sending process. \*\*Default:\*\* `false`. \* `callback` {Function} \* Returns: {boolean} When an IPC channel has been established between the parent and child processes ( i.e. when using [`child\_process.fork()`][]), the `subprocess.send()` method can be used to send messages to the child process. When the child process is a Node.js instance, these messages can be received via the [`'message'`][] event. The message goes through serialization and parsing. The resulting message might not be the same as what is originally sent. For example, in the parent script: ```cjs const { fork } = require('node:child\_process'); const forkedProcess = fork(`${\_\_dirname}/sub.js`); forkedProcess.on('message', (message) => { console.log('PARENT got message:', message); }); // Causes the child to print: CHILD got message: { hello: 'world' } forkedProcess.send({ hello: 'world' }); ``` ```mjs import { fork } from 'node:child\_process'; const forkedProcess = fork(`${import.meta.dirname}/sub.js`); forkedProcess.on('message', (message) => { console.log('PARENT got message:', message); }); // Causes the child to print: CHILD got message: { hello: 'world' } forkedProcess.send({ hello: 'world' }); ``` And then the child script, `'sub.js'` might look like this: ```js process.on('message', (message) => { console.log('CHILD got message:', message); }); // Causes the parent to print: PARENT got message: { foo: 'bar', baz: null } process.send({ foo: 'bar', baz: NaN }); ``` Child Node.js processes will have a [`process.send()`][] method of their own that allows the child process to send messages back to the parent process. There is a special case when sending a `{cmd: 'NODE\_foo'}` message. Messages containing a `NODE\_` prefix in the `cmd` property are reserved for use within Node.js core and will not be emitted in the child's [`'message'`][] event. Rather, such messages are emitted using the `'internalMessage'` event and are consumed internally by Node.js. Applications should avoid using such messages or listening for `'internalMessage'` events as it is subject to change without notice. The optional `sendHandle` argument that may be passed to `subprocess.send()` is for passing a TCP server or socket object to the child process. The child process will receive the object as the second argument passed to the callback function registered on the [`'message'`][] event. Any data that is received and buffered in the socket will not be sent to the child. Sending IPC sockets is not supported on Windows. The optional `callback` is a function that is invoked after the message is sent but before the child process may have received it. The function is called with a single | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.07329542934894562,
0.009685919620096684,
0.017735106870532036,
0.008461441844701767,
0.057315561920404434,
-0.02250857464969158,
-0.01325959712266922,
0.0736420750617981,
0.06575489044189453,
0.02276630699634552,
-0.044021304696798325,
-0.04953924939036369,
0.0011377162300050259,
0.016826951876282692,
-0.016168810427188873,
-0.021138319745659828,
0.02151552028954029,
-0.02925720065832138,
0.06389730423688889,
-0.09639471024274826,
0.00723889097571373,
-0.006815754342824221,
0.030163010582327843,
0.009911340661346912,
0.0027743594255298376,
-0.051637422293424606,
-0.035867080092430115,
-0.056757669895887375,
0.05402068793773651,
0.014222392812371254,
0.01658562384545803,
0.027434848248958588,
-0.07714361697435379,
-0.011152194812893867,
0.026733610779047012,
0.18770189583301544,
0.02898266538977623,
-0.06581217795610428,
-0.016227377578616142,
0.036136750131845474,
0.09255203604698181,
0.0857759341597557,
-0.05860760062932968,
-0.039972517639398575,
0.05882693827152252,
0.005521204322576523,
-0.07903464883565903,
-0.02967667207121849,
-0.051722291857004166,
-0.029773352667689323,
0.0007565774139948189,
-0.0081406245008111,
-0.012372786179184914,
0.05553697422146797,
0.017609573900699615,
-0.01474586222320795,
0.06663726270198822,
-0.019822560250759125,
0.062175482511520386,
0.027251465246081352,
-0.05061378702521324,
0.005383333656936884,
0.009813004173338413,
-0.08554742485284805,
0.03252406418323517,
-0.04495706781744957,
-0.07762747257947922,
-0.016614630818367004,
0.0154647808521986,
0.0949215218424797,
0.02952413447201252,
0.0043861339800059795,
-0.06973862648010254,
0.025625647976994514,
-0.08593723177909851,
-0.04539964720606804,
0.0019280314445495605,
-0.010819543153047562,
-0.06764202564954758,
0.04218437150120735,
-0.08604742586612701,
-0.023154377937316895,
-0.06129445135593414,
-0.06076286360621452,
-0.020174358040094376,
0.03701619431376457,
0.06536094099283218,
-0.013927535153925419,
0.04829198122024536,
0.04949602484703064,
-0.0807042345404625,
-0.017647624015808105,
-0.07160262763500214,
0.04520654305815697,
0.05553365498781204,
0.03203555569052696,
-0.04702996090054512,
-0.04117931053042412,
0.016035787761211395,
-0.0614604651927948,
-0.01575447805225849,
0.06634415686130524,
0.05763759836554527,
0.03732744976878166,
0.0014002876123413444,
0.01136151421815157,
-0.040295157581567764,
0.010812969878315926,
-0.028724493458867073,
-0.012922149151563644,
-0.05348403751850128,
-0.00823625735938549,
0.06888221949338913,
0.08994560688734055,
0.06460190564393997,
0.05124994367361069,
0.09160017967224121,
-0.022783678025007248,
-0.008722038939595222,
0.13484551012516022,
0.08847425878047943,
0.01900334842503071,
0.03321295976638794,
0.04090375080704689,
-0.01938748173415661,
-0.0709017664194107,
0.01718714088201523,
1.1683939057658401e-33,
0.03204195946455002,
-0.0777285024523735,
-0.023953208699822426,
0.08387231826782227,
0.07588694989681244,
0.06591928005218506,
-0.034327514469623566,
0.004382931627333164,
-0.07973029464483261,
0.0044640712440013885,
-0.06135191768407822,
-0.02157214656472206,
0.006490250118076801,
-0.09276379644870758,
-0.009290186688303947,
-0.023780228570103645,
0.07614638656377792,
-0.019244104623794556,
0.02852555550634861,
0.010129053145647049,
-0.01200660690665245,
-0.042206771671772,
-0.041194282472133636,
-0.014188336208462715,
0.044119942933321,
-0.021183710545301437,
-0.07294510304927826,
0.045453991740942,
0.04528547078371048,
-0.045627396553754807,
0.024247264489531517,
0.05294284224510193,
0.014869268983602524,
-0.003423596266657114,
-0.022207995876669884,
-0.09492672979831696,
0.06336960941553116,
0.036077968776226044,
-0.09793543815612793,
-0.07903587818145752,
-0.007923179306089878,
0.02174932323396206,
-0.014142880216240883,
0.0024924883618950844,
-0.03472509980201721,
-0.11207111179828644,
-0.04070017859339714,
-0.04514848813414574,
0.021748686209321022,
0.006492557469755411,
0.048940420150756836,
0.04983755946159363,
0.03621218726038933,
-0.017737630754709244,
-0.04050489515066147,
0.041467439383268356,
-0.03848974034190178,
-0.07565908879041672,
-0.04625539854168892,
-0.03912222012877464,
0.054459355771541595,
0.03324808180332184,
-0.03722351789474487,
0.03234170377254486,
0.07082222402095795,
-0.07943934947252274,
-0.009046033024787903,
0.08204996585845947,
0.03516557812690735,
0.041086770594120026,
-0.023780234158039093,
-0.04513315483927727,
-0.0035404344089329243,
-0.03596842288970947,
0.04136309772729874,
-0.03792180120944977,
0.012440632097423077,
-0.06097499281167984,
-0.0427698940038681,
-0.009626179002225399,
0.06026732921600342,
0.023333238437771797,
-0.07887844741344452,
-0.02545841410756111,
-0.019944244995713234,
0.04275301471352577,
-0.011134110391139984,
-0.00041228707414120436,
-0.024334555491805077,
0.0639599934220314,
-0.041624609380960464,
-0.02568000927567482,
0.029976850375533104,
-0.0380123034119606,
-0.0963759571313858,
-5.375403790537838e-33,
0.019610406830906868,
-0.0135501055046916,
-0.05160947144031525,
-0.03134880214929581,
0.015565921552479267,
-0.03584551066160202,
0.04641107842326164,
-0.050421688705682755,
-0.041290033608675,
-0.008075019344687462,
-0.12600934505462646,
-0.0060792178846895695,
0.06028972193598747,
0.12992852926254272,
-0.06412427872419357,
-0.0016236909432336688,
-0.06472838670015335,
-0.010526279918849468,
0.024886518716812134,
-0.026735831052064896,
-0.011855348944664001,
0.04207577928900719,
0.019228406250476837,
0.043601375073194504,
-0.05719755217432976,
0.044299203902482986,
-0.004491494968533516,
0.021664666011929512,
-0.07202006876468658,
0.005400783382356167,
-0.02362825907766819,
-0.0020456889178603888,
-0.053759124130010605,
0.14914405345916748,
0.00855381041765213,
-0.07010544091463089,
0.0243682898581028,
0.0624154694378376,
0.03110819309949875,
-0.11261393129825592,
0.08988446742296219,
0.031123904511332512,
-0.007824440486729145,
-0.017398599535226822,
0.06467016041278839,
-0.011115520261228085,
0.09547987580299377,
0.07194115221500397,
-0.006920831277966499,
-0.02779727429151535,
-0.1071380004286766,
-0.025731178000569344,
-0.03746890276670456,
0.03285961598157883,
-0.05013113468885422,
-0.0015366892330348492,
0.01166477520018816,
-0.003861550707370043,
0.059216443449258804,
0.0005870076711289585,
0.0405019149184227,
-0.017642337828874588,
-0.0792703852057457,
-0.004130765330046415,
-0.016354940831661224,
-0.028336945921182632,
-0.07360777258872986,
0.046161383390426636,
0.09081321954727173,
-0.06888974457979202,
-0.012471800670027733,
0.14020153880119324,
0.006529301404953003,
-0.05336540937423706,
-0.07450855523347855,
0.03316214680671692,
-0.01912730373442173,
-0.046893805265426636,
0.04108930006623268,
0.02011725679039955,
0.010309798642992973,
0.07926265150308609,
-0.09569880366325378,
0.00907403789460659,
-0.0276422630995512,
-0.05976930260658264,
0.01620238460600376,
0.009738833643496037,
-0.020544234663248062,
-0.03044334426522255,
0.007616905495524406,
-0.017413107678294182,
-0.03992041200399399,
-0.04912314936518669,
0.033136993646621704,
-4.7461078622745845e-8,
0.003533441573381424,
-0.007373391650617123,
-0.03629826009273529,
-0.0048332917504012585,
0.05322464182972908,
-0.05056372657418251,
0.0016150539740920067,
-0.044580165296792984,
0.04685428366065025,
0.0064873103983700275,
-0.11531941592693329,
-0.07947125285863876,
0.034026067703962326,
0.05349899083375931,
0.022375378757715225,
0.008303814567625523,
0.010855389758944511,
0.02643565461039543,
0.049801599234342575,
-0.009427295066416264,
0.011853319592773914,
-0.02433176152408123,
-0.004057344980537891,
0.08493439853191376,
-0.1130758598446846,
-0.0812513455748558,
0.043698251247406006,
0.002413381589576602,
-0.1437947154045105,
-0.012096868827939034,
-0.008053725585341454,
0.040783144533634186,
0.04448568820953369,
0.07966956496238708,
0.04091142490506172,
-0.016157563775777817,
-0.013934927992522717,
0.0024346194695681334,
0.051188502460718155,
0.013545745052397251,
0.08068982511758804,
0.15850132703781128,
-0.03862778842449188,
-0.021366596221923828,
-0.06603994965553284,
-0.009626653045415878,
-0.03831474110484123,
0.0396287739276886,
0.012391187250614166,
0.06031997129321098,
0.051806721836328506,
-0.033675309270620346,
-0.026912879198789597,
-0.02415512129664421,
0.08786562085151672,
0.0034045884385704994,
0.015055570751428604,
-0.10182610899209976,
-0.023766811937093735,
0.027815844863653183,
0.08126799762248993,
0.03880136087536812,
0.05244426429271698,
-0.06329882144927979
] | 0.019385 |
and buffered in the socket will not be sent to the child. Sending IPC sockets is not supported on Windows. The optional `callback` is a function that is invoked after the message is sent but before the child process may have received it. The function is called with a single argument: `null` on success, or an [`Error`][] object on failure. If no `callback` function is provided and the message cannot be sent, an `'error'` event will be emitted by the [`ChildProcess`][] object. This can happen, for instance, when the child process has already exited. `subprocess.send()` will return `false` if the channel has closed or when the backlog of unsent messages exceeds a threshold that makes it unwise to send more. Otherwise, the method returns `true`. The `callback` function can be used to implement flow control. #### Example: sending a server object The `sendHandle` argument can be used, for instance, to pass the handle of a TCP server object to the child process as illustrated in the example below: ```cjs const { fork } = require('node:child\_process'); const { createServer } = require('node:net'); const subprocess = fork('subprocess.js'); // Open up the server object and send the handle. const server = createServer(); server.on('connection', (socket) => { socket.end('handled by parent'); }); server.listen(1337, () => { subprocess.send('server', server); }); ``` ```mjs import { fork } from 'node:child\_process'; import { createServer } from 'node:net'; const subprocess = fork('subprocess.js'); // Open up the server object and send the handle. const server = createServer(); server.on('connection', (socket) => { socket.end('handled by parent'); }); server.listen(1337, () => { subprocess.send('server', server); }); ``` The child process would then receive the server object as: ```js process.on('message', (m, server) => { if (m === 'server') { server.on('connection', (socket) => { socket.end('handled by child'); }); } }); ``` Once the server is now shared between the parent and child, some connections can be handled by the parent and some by the child. While the example above uses a server created using the `node:net` module, `node:dgram` module servers use exactly the same workflow with the exceptions of listening on a `'message'` event instead of `'connection'` and using `server.bind()` instead of `server.listen()`. This is, however, only supported on Unix platforms. #### Example: sending a socket object Similarly, the `sendHandler` argument can be used to pass the handle of a socket to the child process. The example below spawns two children that each handle connections with "normal" or "special" priority: ```cjs const { fork } = require('node:child\_process'); const { createServer } = require('node:net'); const normal = fork('subprocess.js', ['normal']); const special = fork('subprocess.js', ['special']); // Open up the server and send sockets to child. Use pauseOnConnect to prevent // the sockets from being read before they are sent to the child process. const server = createServer({ pauseOnConnect: true }); server.on('connection', (socket) => { // If this is special priority... if (socket.remoteAddress === '74.125.127.100') { special.send('socket', socket); return; } // This is normal priority. normal.send('socket', socket); }); server.listen(1337); ``` ```mjs import { fork } from 'node:child\_process'; import { createServer } from 'node:net'; const normal = fork('subprocess.js', ['normal']); const special = fork('subprocess.js', ['special']); // Open up the server and send sockets to child. Use pauseOnConnect to prevent // the sockets from being read before they are sent to the child process. const server = createServer({ pauseOnConnect: true }); server.on('connection', (socket) => { // If this is special priority... if (socket.remoteAddress === '74.125.127.100') { special.send('socket', socket); return; } // This is normal priority. normal.send('socket', socket); }); server.listen(1337); ``` The `subprocess.js` would receive the socket handle as the second argument passed to the event callback function: ```js process.on('message', (m, socket) => { | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.09051986783742905,
-0.026725824922323227,
-0.047742221504449844,
0.07452726364135742,
-0.0046624853275716305,
-0.04879441112279892,
0.03711027279496193,
0.06546872854232788,
0.07747314870357513,
0.022472692653536797,
-0.0300707146525383,
0.03713439032435417,
-0.05423269420862198,
-0.013893738389015198,
-0.038410816341638565,
0.02550232969224453,
0.09386065602302551,
-0.04119472950696945,
-0.0429685041308403,
-0.1357080638408661,
-0.020384354516863823,
0.020545456558465958,
0.0383165068924427,
-0.003104213159531355,
-0.06867336481809616,
0.022227363660931587,
-0.02332085371017456,
-0.03394632786512375,
-0.003308443119749427,
0.06324882805347443,
-0.029991215094923973,
-0.054325658828020096,
-0.08394923061132431,
0.022988934069871902,
-0.05433076620101929,
0.11749857664108276,
0.04955313727259636,
-0.030120182782411575,
-0.08358056843280792,
-0.010208448395133018,
0.037475086748600006,
0.035400889813899994,
-0.13785988092422485,
-0.022567011415958405,
-0.031850941479206085,
-0.01283856201916933,
-0.061484064906835556,
-0.022481108084321022,
-0.058692656457424164,
-0.03962600603699684,
-0.01627972349524498,
0.03713257983326912,
0.012938834726810455,
0.12819364666938782,
0.03848809748888016,
-0.07597583532333374,
-0.028557347133755684,
-0.0385020487010479,
0.015428651124238968,
0.03222935274243355,
-0.05527461692690849,
-0.03689566254615784,
-0.06583581864833832,
0.005939018446952105,
0.0411083959043026,
-0.026532985270023346,
-0.028901321813464165,
0.015227244235575199,
0.04637564718723297,
-0.023555243387818336,
-0.03882760554552078,
-0.0006740938988514245,
-0.07384458929300308,
0.04830917343497276,
0.01376750785857439,
0.007957217283546925,
0.011569787748157978,
0.0004807808727491647,
-0.11870002001523972,
-0.007160409819334745,
-0.005122922360897064,
-0.011055158451199532,
-0.05926470831036568,
-0.02366362325847149,
-0.025552555918693542,
0.034007273614406586,
-0.01013214886188507,
0.016917355358600616,
0.013534041121602058,
0.07064574211835861,
-0.07861978560686111,
0.02285970374941826,
-0.02636728622019291,
0.06998724490404129,
0.01984296552836895,
-0.02862616814672947,
-0.021824980154633522,
-0.03135808929800987,
-0.039070259779691696,
-0.0419170968234539,
0.040068577975034714,
0.04193330183625221,
0.023189717903733253,
-0.016061978414654732,
0.03042439930140972,
0.0008220567833632231,
-0.035232871770858765,
-0.008966481313109398,
0.009828842245042324,
-0.0008583113667555153,
-0.10506018996238708,
-0.01457518432289362,
0.042398594319820404,
0.058448951691389084,
-0.005438991356641054,
-0.025298401713371277,
0.07624173909425735,
0.0354110412299633,
-0.031123558059334755,
0.025739576667547226,
0.026389067992568016,
-0.03622835874557495,
0.005261107347905636,
-0.024858353659510612,
-0.010795185342431068,
-0.10155066847801208,
0.015297121368348598,
2.5357977194289473e-33,
-0.06187707930803299,
-0.09144142270088196,
-0.02432875894010067,
0.10409803688526154,
0.04289853945374489,
0.07091367244720459,
0.061476875096559525,
-0.006574754603207111,
-0.012447059154510498,
-0.023970451205968857,
-0.08504434674978256,
-0.10170940309762955,
0.07689572125673294,
-0.04917323961853981,
-0.00028303591534495354,
0.0013760323636233807,
0.004865922033786774,
0.010775619186460972,
0.08748762309551239,
0.08645346015691757,
0.013752073980867863,
0.03468194231390953,
-0.015079849399626255,
0.02507929503917694,
0.050630636513233185,
-0.05411175265908241,
-0.06629607826471329,
0.014037031680345535,
0.00010345888586016372,
-0.0020326017402112484,
-0.04934867098927498,
0.06377579271793365,
0.009014029055833817,
-0.03809637948870659,
-0.005074653774499893,
-0.014269513078033924,
0.03683391958475113,
-0.003865182166919112,
0.01680384948849678,
0.011101644486188889,
-0.0599621944129467,
-0.07678458839654922,
-0.09825123846530914,
0.019436482340097427,
-0.007228366564959288,
-0.1151236817240715,
-0.10774443298578262,
-0.003777707228437066,
0.0086281206458807,
0.023368889465928078,
0.07603912055492401,
0.03040742315351963,
0.040730614215135574,
0.018564561381936073,
0.04389016702771187,
0.015432395040988922,
0.006634136196225882,
0.05062779784202576,
-0.07657886296510696,
0.0489359013736248,
0.0816120132803917,
-0.0398300476372242,
-0.07953769713640213,
-0.0617244727909565,
0.05687674507498741,
-0.02659592218697071,
-0.02988581918179989,
0.04382100701332092,
-0.07085917145013809,
-0.05472324788570404,
-0.04498329386115074,
0.032283563166856766,
-0.06392405927181244,
0.06867969781160355,
0.004501214250922203,
0.04803226515650749,
-0.0012022159062325954,
-0.016942529007792473,
0.02494923025369644,
-0.011151510290801525,
-0.005477088037878275,
0.05058380961418152,
-0.0005443633417598903,
-0.023068830370903015,
0.033762458711862564,
-0.009737960062921047,
-0.031379297375679016,
-0.018930846825242043,
-0.04788334667682648,
0.032509781420230865,
-0.03445010259747505,
-0.015403170138597488,
0.0683322325348854,
0.0733976736664772,
0.01075117290019989,
-5.4346185837765414e-33,
0.008853278122842312,
0.026088977232575417,
-0.13156770169734955,
0.05459189414978027,
-0.04199887439608574,
-0.051576513797044754,
0.007933523505926132,
0.005812123417854309,
-0.03523300215601921,
0.001342143164947629,
-0.04185675457119942,
0.042098917067050934,
0.0031329025514423847,
0.07197362184524536,
-0.028417915105819702,
-0.02775953710079193,
-0.009796968661248684,
-0.02746272273361683,
-0.006861145608127117,
0.004424334969371557,
0.020294006913900375,
0.013342991471290588,
0.007951650768518448,
-0.045595649629831314,
-0.08956889808177948,
-0.0024420442059636116,
-0.031234117224812508,
0.007604577112942934,
-0.040301792323589325,
-0.014906537719070911,
0.04417227581143379,
-0.018319210037589073,
0.026738815009593964,
0.10263318568468094,
0.030580807477235794,
-0.03120158426463604,
0.011039421893656254,
-0.013827863149344921,
0.055554114282131195,
0.009980599395930767,
0.1274217963218689,
0.049949660897254944,
-0.040958527475595474,
0.0304120946675539,
0.023200659081339836,
0.07983161509037018,
-0.03377307206392288,
0.0031898703891783953,
-0.025932351127266884,
0.04811559617519379,
0.014597759582102299,
0.028123974800109863,
0.05180816724896431,
0.11521259695291519,
0.0014234964037314057,
0.057000938802957535,
0.1269456297159195,
0.008921739645302296,
0.06672096252441406,
-0.03362111374735832,
0.05224565416574478,
-0.08664149045944214,
0.00924819614738226,
-0.03164747357368469,
-0.002926209243014455,
0.026910966262221336,
0.0029868956189602613,
0.021995265036821365,
0.11115740984678268,
-0.07459006458520889,
0.0469876304268837,
0.06559837609529495,
-0.04433801397681236,
-0.021089937537908554,
0.030225243419408798,
0.03685160353779793,
-0.007392206694930792,
-0.04745927453041077,
-0.02334407903254032,
0.08968809247016907,
-0.0759979635477066,
0.09390208125114441,
-0.01708918809890747,
0.020370081067085266,
0.08524347096681595,
-0.001200913917273283,
-0.0152291189879179,
-0.05361498147249222,
0.01551385223865509,
-0.06061670184135437,
0.05041670426726341,
0.031423021107912064,
0.01347873080521822,
-0.008325564675033092,
0.031223099678754807,
-5.4313570529984645e-8,
-0.013910176232457161,
-0.055598318576812744,
-0.018301231786608696,
0.008882617577910423,
-0.009193272329866886,
-0.007596336770802736,
-0.044436898082494736,
-0.11034446954727173,
0.031749654561281204,
0.03831389918923378,
-0.06395804136991501,
-0.04186013713479042,
0.03853201866149902,
-0.05622127652168274,
0.07140862196683884,
-0.005771522875875235,
0.057922810316085815,
-0.04980234056711197,
0.054678864777088165,
-0.061122868210077286,
0.06876929849386215,
-0.01588660292327404,
-0.0047003477811813354,
0.1630704253911972,
-0.09435290843248367,
-0.0907973051071167,
0.10430871695280075,
0.06162840873003006,
-0.17921575903892517,
-0.07175261527299881,
-0.012303395196795464,
-0.02062428928911686,
0.06360826641321182,
0.11814038455486298,
0.0012940643355250359,
0.025676893070340157,
-0.018727174028754234,
0.011015394702553749,
0.028822245076298714,
0.02633383870124817,
0.0393025167286396,
0.027400558814406395,
-0.05946918576955795,
0.0038413763977587223,
0.0732714906334877,
0.07945456355810165,
-0.051651351153850555,
0.08163643628358841,
-0.06435215473175049,
0.03857685625553131,
-0.009158124215900898,
0.02714685909450054,
-0.014455395750701427,
0.007694018539041281,
0.0696745440363884,
-0.02795618399977684,
-0.0334809347987175,
-0.06006563454866409,
-0.0325048603117466,
0.0646808072924614,
-0.021502196788787842,
0.11319277435541153,
-0.017814327031373978,
-0.053176481276750565
] | 0.105712 |
=> { // If this is special priority... if (socket.remoteAddress === '74.125.127.100') { special.send('socket', socket); return; } // This is normal priority. normal.send('socket', socket); }); server.listen(1337); ``` The `subprocess.js` would receive the socket handle as the second argument passed to the event callback function: ```js process.on('message', (m, socket) => { if (m === 'socket') { if (socket) { // Check that the client socket exists. // It is possible for the socket to be closed between the time it is // sent and the time it is received in the child process. socket.end(`Request handled with ${process.argv[2]} priority`); } } }); ``` Do not use `.maxConnections` on a socket that has been passed to a subprocess. The parent cannot track when the socket is destroyed. Any `'message'` handlers in the subprocess should verify that `socket` exists, as the connection may have been closed during the time it takes to send the connection to the child. ### `subprocess.signalCode` \* Type: {string|null} The `subprocess.signalCode` property indicates the signal received by the child process if any, else `null`. When the child process is terminated by a signal, [`subprocess.exitCode`][] will be `null`. To get the corresponding POSIX exit code, use [`util.convertProcessSignalToExitCode(subprocess.signalCode)`][`util.convertProcessSignalToExitCode()`]. ### `subprocess.spawnargs` \* Type: {Array} The `subprocess.spawnargs` property represents the full list of command-line arguments the child process was launched with. ### `subprocess.spawnfile` \* Type: {string} The `subprocess.spawnfile` property indicates the executable file name of the child process that is launched. For [`child\_process.fork()`][], its value will be equal to [`process.execPath`][]. For [`child\_process.spawn()`][], its value will be the name of the executable file. For [`child\_process.exec()`][], its value will be the name of the shell in which the child process is launched. ### `subprocess.stderr` \* Type: {stream.Readable|null|undefined} A `Readable Stream` that represents the child process's `stderr`. If the child process was spawned with `stdio[2]` set to anything other than `'pipe'`, then this will be `null`. `subprocess.stderr` is an alias for `subprocess.stdio[2]`. Both properties will refer to the same value. The `subprocess.stderr` property can be `null` or `undefined` if the child process could not be successfully spawned. ### `subprocess.stdin` \* Type: {stream.Writable|null|undefined} A `Writable Stream` that represents the child process's `stdin`. If a child process waits to read all of its input, the child process will not continue until this stream has been closed via `end()`. If the child process was spawned with `stdio[0]` set to anything other than `'pipe'`, then this will be `null`. `subprocess.stdin` is an alias for `subprocess.stdio[0]`. Both properties will refer to the same value. The `subprocess.stdin` property can be `null` or `undefined` if the child process could not be successfully spawned. ### `subprocess.stdio` \* Type: {Array} A sparse array of pipes to the child process, corresponding with positions in the [`stdio`][] option passed to [`child\_process.spawn()`][] that have been set to the value `'pipe'`. `subprocess.stdio[0]`, `subprocess.stdio[1]`, and `subprocess.stdio[2]` are also available as `subprocess.stdin`, `subprocess.stdout`, and `subprocess.stderr`, respectively. In the following example, only the child's fd `1` (stdout) is configured as a pipe, so only the parent's `subprocess.stdio[1]` is a stream, all other values in the array are `null`. ```cjs const assert = require('node:assert'); const fs = require('node:fs'); const child\_process = require('node:child\_process'); const subprocess = child\_process.spawn('ls', { stdio: [ 0, // Use parent's stdin for child. 'pipe', // Pipe child's stdout to parent. fs.openSync('err.out', 'w'), // Direct child's stderr to a file. ], }); assert.strictEqual(subprocess.stdio[0], null); assert.strictEqual(subprocess.stdio[0], subprocess.stdin); assert(subprocess.stdout); assert.strictEqual(subprocess.stdio[1], subprocess.stdout); assert.strictEqual(subprocess.stdio[2], null); assert.strictEqual(subprocess.stdio[2], subprocess.stderr); ``` ```mjs import assert from 'node:assert'; import fs from 'node:fs'; import child\_process from 'node:child\_process'; const subprocess = child\_process.spawn('ls', { stdio: [ 0, // Use parent's stdin for child. 'pipe', // Pipe child's stdout to parent. fs.openSync('err.out', 'w'), // Direct | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.08117346465587616,
-0.0406598262488842,
0.002594398334622383,
-0.010849758051335812,
-0.021739939227700233,
-0.0896107405424118,
0.0032526846043765545,
0.02587670087814331,
0.09463939815759659,
0.03726759925484657,
-0.07651636749505997,
0.08657293021678925,
-0.034152429550886154,
0.05911307409405708,
-0.008685236796736717,
-0.0005283333593979478,
0.08620183169841766,
-0.03740924224257469,
-0.052781712263822556,
-0.1293911188840866,
0.015741385519504547,
0.0016005319776013494,
0.052064087241888046,
-0.039734818041324615,
-0.07575272023677826,
-0.041612669825553894,
0.0054449718445539474,
-0.014250101521611214,
0.0346924290060997,
0.046038564294576645,
0.0001290603686356917,
-0.06264843046665192,
-0.04450347274541855,
-0.02552100457251072,
-0.06627710163593292,
0.11140898615121841,
-0.030631620436906815,
-0.10533591359853745,
-0.01462527271360159,
0.025600263848900795,
0.049849603325128555,
0.016156306490302086,
-0.04204871878027916,
-0.07575201243162155,
-0.0008849217556416988,
-0.014410840347409248,
-0.10564297437667847,
-0.033243048936128616,
-0.043314386159181595,
-0.02210775949060917,
-0.035887859761714935,
-0.0076987785287201405,
0.015113442204892635,
0.09745286405086517,
0.034743133932352066,
-0.01563182845711708,
-0.015026850625872612,
-0.019997170194983482,
-0.012042764574289322,
0.03023664467036724,
-0.06536572426557541,
-0.012060395441949368,
-0.02494809590280056,
-0.02704181894659996,
0.009046087972819805,
0.009642527438700199,
-0.05220305174589157,
0.0011363731464371085,
-0.03765508905053139,
0.10412383824586868,
0.014115093275904655,
0.013692159205675125,
-0.08028106391429901,
-0.029006579890847206,
-0.006502987816929817,
-0.03876030817627907,
-0.021481812000274658,
-0.0483393669128418,
-0.123342365026474,
-0.021071050316095352,
-0.018535679206252098,
-0.09726151823997498,
-0.09797611832618713,
0.0006887845229357481,
0.009726905263960361,
0.028468133881688118,
0.040836531668901443,
-0.015810227021574974,
0.038690559566020966,
0.046295054256916046,
-0.10386550426483154,
0.010635605081915855,
-0.039921075105667114,
0.1174316331744194,
0.012517450377345085,
0.07379277050495148,
-0.006929491180926561,
0.05754641070961952,
-0.049727220088243484,
-0.010845444165170193,
0.009163652546703815,
-0.018964311107993126,
-0.03467407077550888,
-0.006563458126038313,
0.051460642367601395,
-0.02320644073188305,
-0.09114651381969452,
0.02597680129110813,
0.00496907252818346,
0.03538214787840843,
-0.06326203048229218,
0.011183096095919609,
0.06859584152698517,
0.05492480844259262,
-0.022023947909474373,
0.07947930693626404,
0.13614866137504578,
0.036470089107751846,
-0.038718629628419876,
0.05372340604662895,
0.09097800403833389,
0.029475441202521324,
0.0038810670375823975,
-0.01966840773820877,
0.04756886512041092,
0.002314535900950432,
0.07066746801137924,
-1.7743090810529116e-34,
-0.031468089669942856,
-0.03798757866024971,
-0.030766889452934265,
-0.02060418389737606,
-0.02351454831659794,
0.01663058251142502,
-0.02496124431490898,
0.012589563615620136,
-0.052410803735256195,
0.03873155266046524,
-0.0044457679614424706,
-0.025247829034924507,
0.0687260851264,
-0.12067689001560211,
-0.04692290723323822,
-0.009954411536455154,
0.09739292412996292,
0.005035211332142353,
0.07332704216241837,
0.007363062351942062,
-0.005307242274284363,
-0.02365223877131939,
-0.06750615686178207,
0.06377948820590973,
0.040843814611434937,
0.004844701383262873,
-0.022319892421364784,
0.02052597887814045,
-0.03371353819966316,
-0.019471095874905586,
0.027833471074700356,
0.011908863671123981,
-0.03528347238898277,
0.008733123540878296,
-0.0267524141818285,
-0.05469398945569992,
0.043999720364809036,
0.0021165136713534594,
-0.03223466873168945,
-0.010055105201900005,
0.030035141855478287,
-0.03414052352309227,
-0.14656826853752136,
0.07586117833852768,
0.012571695260703564,
-0.07913070917129517,
-0.09107477962970734,
-0.014435933902859688,
0.06728041917085648,
0.012811679393053055,
0.008276081643998623,
0.02674041874706745,
0.08939395844936371,
0.02459821105003357,
0.023249518126249313,
-0.020745733752846718,
0.01772136054933071,
0.07100065797567368,
-0.0016191403847187757,
-0.002413359936326742,
0.0707421600818634,
-0.07667511701583862,
0.006461453624069691,
-0.029497409239411354,
0.07214219868183136,
-0.06234166771173477,
-0.027559909969568253,
0.030217956751585007,
-0.008047285489737988,
-0.029485639184713364,
-0.0351349413394928,
0.04711701348423958,
0.03342040628194809,
0.016207166016101837,
0.004102901555597782,
0.03286145254969597,
0.05372881144285202,
0.052201274782419205,
0.05923561379313469,
-0.07643763720989227,
-0.04095080867409706,
0.04868951812386513,
0.00017139225383289158,
0.04333636164665222,
0.026365861296653748,
0.07015551626682281,
-0.05708901211619377,
0.0191353652626276,
-0.03139268234372139,
0.049883488565683365,
-0.053893353790044785,
0.00172556028701365,
0.06584566086530685,
-0.024488765746355057,
-0.023920970037579536,
-9.634717204614177e-34,
0.007027649320662022,
0.017326224595308304,
-0.09864188730716705,
0.07244009524583817,
0.0006653262535110116,
-0.0995391383767128,
-0.050226837396621704,
-0.05131953954696655,
-0.058843981474637985,
0.05206144601106644,
0.005586492829024792,
-0.0504789762198925,
0.06012818217277527,
-0.003390837926417589,
-0.045493923127651215,
0.02058294601738453,
-0.016055190935730934,
0.000541416578926146,
0.051427241414785385,
-0.0021632369607686996,
0.0001033155494951643,
0.0857444480061531,
0.04850677773356438,
-0.008590273559093475,
-0.06054292991757393,
0.010958927683532238,
-0.020991170778870583,
-0.014481721445918083,
-0.057113975286483765,
-0.031913578510284424,
-0.08316518366336823,
-0.03584463894367218,
0.019126787781715393,
0.06259432435035706,
-0.005508027039468288,
-0.023034870624542236,
0.03223739564418793,
0.04262322932481766,
0.07351531833410263,
0.005277043208479881,
0.08810276538133621,
0.02382976934313774,
-0.04466518014669418,
0.001825720421038568,
-0.0032923335675150156,
0.055038176476955414,
-0.012222008779644966,
-0.03004348836839199,
-0.04217682033777237,
-0.008235713467001915,
-0.028686296194791794,
0.004531925078481436,
0.050472721457481384,
0.08440340310335159,
0.043245188891887665,
0.06490278989076614,
0.05861581861972809,
-0.034274376928806305,
0.06058259680867195,
0.003849924309179187,
0.14434581995010376,
-0.07496210932731628,
0.022784775123000145,
0.006004034075886011,
0.020501915365457535,
0.09380136430263519,
-0.04970178008079529,
-0.013888586312532425,
0.1340172439813614,
-0.03324213624000549,
0.042961958795785904,
0.07922740280628204,
-0.04177555814385414,
0.0353756882250309,
-0.00137261301279068,
0.038650065660476685,
-0.01773952506482601,
-0.03038407862186432,
0.011546486057341099,
0.07736748456954956,
-0.06549087911844254,
0.09539743512868881,
-0.0865473523736,
-0.03221849724650383,
0.01856948249042034,
0.05275872349739075,
-0.03262801840901375,
0.019476870074868202,
0.0034591376315802336,
-0.11068959534168243,
0.014369701966643333,
0.03571854904294014,
-0.03877394646406174,
-0.07004097104072571,
-0.004850836470723152,
-5.0897870806920764e-8,
0.012644683942198753,
-0.04829910397529602,
-0.010452312417328358,
0.015729298815131187,
0.05844986438751221,
-0.005174059886485338,
-0.05636196956038475,
-0.047328878194093704,
0.03406098484992981,
0.07813389599323273,
-0.06058983877301216,
-0.06771186739206314,
0.07957448065280914,
-0.001304631819948554,
0.07658302783966064,
0.0015064970357343554,
0.046146243810653687,
0.009022771380841732,
-0.005167090333998203,
-0.03074091672897339,
0.04083755612373352,
0.03864645957946777,
0.028492985293269157,
0.07636906206607819,
-0.059591326862573624,
-0.07970354706048965,
0.10871566087007523,
0.01627487502992153,
-0.11094553768634796,
-0.10085927695035934,
-0.10891912132501602,
-0.01358245499432087,
0.04928368702530861,
0.03067896142601967,
-0.0318380631506443,
0.00812523439526558,
-0.0921267569065094,
0.02786348946392536,
-0.0011120495619252324,
0.04961056634783745,
0.04640660807490349,
-0.009549370035529137,
-0.0855555534362793,
0.02536487951874733,
0.02314099483191967,
0.058124080300331116,
0.029930755496025085,
0.0074640014208853245,
0.024019401520490646,
0.05131560564041138,
0.010841662995517254,
-0.028669390827417374,
0.058171238750219345,
-0.02571346051990986,
0.01718682050704956,
0.07652227580547333,
0.03274795413017273,
-0.07169479876756668,
-0.059656158089637756,
-0.019635271281003952,
0.051697250455617905,
0.12326819449663162,
-0.06363549083471298,
-0.04141497239470482
] | 0.085026 |
assert.strictEqual(subprocess.stdio[0], null); assert.strictEqual(subprocess.stdio[0], subprocess.stdin); assert(subprocess.stdout); assert.strictEqual(subprocess.stdio[1], subprocess.stdout); assert.strictEqual(subprocess.stdio[2], null); assert.strictEqual(subprocess.stdio[2], subprocess.stderr); ``` ```mjs import assert from 'node:assert'; import fs from 'node:fs'; import child\_process from 'node:child\_process'; const subprocess = child\_process.spawn('ls', { stdio: [ 0, // Use parent's stdin for child. 'pipe', // Pipe child's stdout to parent. fs.openSync('err.out', 'w'), // Direct child's stderr to a file. ], }); assert.strictEqual(subprocess.stdio[0], null); assert.strictEqual(subprocess.stdio[0], subprocess.stdin); assert(subprocess.stdout); assert.strictEqual(subprocess.stdio[1], subprocess.stdout); assert.strictEqual(subprocess.stdio[2], null); assert.strictEqual(subprocess.stdio[2], subprocess.stderr); ``` The `subprocess.stdio` property can be `undefined` if the child process could not be successfully spawned. ### `subprocess.stdout` \* Type: {stream.Readable|null|undefined} A `Readable Stream` that represents the child process's `stdout`. If the child process was spawned with `stdio[1]` set to anything other than `'pipe'`, then this will be `null`. `subprocess.stdout` is an alias for `subprocess.stdio[1]`. Both properties will refer to the same value. ```cjs const { spawn } = require('node:child\_process'); const subprocess = spawn('ls'); subprocess.stdout.on('data', (data) => { console.log(`Received chunk ${data}`); }); ``` ```mjs import { spawn } from 'node:child\_process'; const subprocess = spawn('ls'); subprocess.stdout.on('data', (data) => { console.log(`Received chunk ${data}`); }); ``` The `subprocess.stdout` property can be `null` or `undefined` if the child process could not be successfully spawned. ### `subprocess.unref()` By default, the parent process will wait for the detached child process to exit. To prevent the parent process from waiting for a given `subprocess` to exit, use the `subprocess.unref()` method. Doing so will cause the parent's event loop to not include the child process in its reference count, allowing the parent to exit independently of the child, unless there is an established IPC channel between the child and the parent processes. ```cjs const { spawn } = require('node:child\_process'); const process = require('node:process'); const subprocess = spawn(process.argv[0], ['child\_program.js'], { detached: true, stdio: 'ignore', }); subprocess.unref(); ``` ```mjs import { spawn } from 'node:child\_process'; import process from 'node:process'; const subprocess = spawn(process.argv[0], ['child\_program.js'], { detached: true, stdio: 'ignore', }); subprocess.unref(); ``` ## `maxBuffer` and Unicode The `maxBuffer` option specifies the largest number of bytes allowed on `stdout` or `stderr`. If this value is exceeded, then the child process is terminated. This impacts output that includes multibyte character encodings such as UTF-8 or UTF-16. For instance, `console.log('中文测试')` will send 13 UTF-8 encoded bytes to `stdout` although there are only 4 characters. ## Shell requirements The shell should understand the `-c` switch. If the shell is `'cmd.exe'`, it should understand the `/d /s /c` switches and command-line parsing should be compatible. ## Default Windows shell Although Microsoft specifies `%COMSPEC%` must contain the path to `'cmd.exe'` in the root environment, child processes are not always subject to the same requirement. Thus, in `child\_process` functions where a shell can be spawned, `'cmd.exe'` is used as a fallback if `process.env.ComSpec` is unavailable. ## Advanced serialization Child processes support a serialization mechanism for IPC that is based on the [serialization API of the `node:v8` module][v8.serdes], based on the [HTML structured clone algorithm][]. This is generally more powerful and supports more built-in JavaScript object types, such as `BigInt`, `Map` and `Set`, `ArrayBuffer` and `TypedArray`, `Buffer`, `Error`, `RegExp` etc. However, this format is not a full superset of JSON, and e.g. properties set on objects of such built-in types will not be passed on through the serialization step. Additionally, performance may not be equivalent to that of JSON, depending on the structure of the passed data. Therefore, this feature requires opting in by setting the `serialization` option to `'advanced'` when calling [`child\_process.spawn()`][] or [`child\_process.fork()`][]. [Advanced serialization]: #advanced-serialization [Default Windows shell]: #default-windows-shell [HTML structured clone algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web\_Workers\_API/Structured\_clone\_algorithm [Shell requirements]: #shell-requirements [Signal Events]: process.md#signal-events [`'disconnect'`]: process.md#event-disconnect [`'error'`]: #event-error [`'exit'`]: #event-exit [`'message'`]: process.md#event-message [`ChildProcess`]: #class-childprocess [`Error`]: errors.md#class-error [`EventEmitter`]: events.md#class-eventemitter [`child\_process.exec()`]: #child\_processexeccommand-options-callback [`child\_process.execFile()`]: | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.055408865213394165,
-0.005559995770454407,
0.011890007182955742,
0.005260928999632597,
0.03969041630625725,
-0.06260691583156586,
-0.07316946983337402,
0.11831897497177124,
-0.002115120878443122,
0.015895109623670578,
-0.07300646603107452,
-0.042460814118385315,
0.023492885753512383,
0.02126598171889782,
-0.03525710105895996,
-0.014413834549486637,
0.002637426368892193,
0.03445565328001976,
0.050853993743658066,
-0.1519651859998703,
0.03802105411887169,
0.000003321438271086663,
0.056571535766124725,
-0.024133890867233276,
-0.022689057514071465,
-0.021293915808200836,
-0.057704754173755646,
0.0036659473553299904,
0.05930048227310181,
-0.025137251242995262,
0.07174540311098099,
-0.008418370969593525,
0.009250670671463013,
-0.021484116092324257,
0.061569906771183014,
0.16318069398403168,
0.012896481901407242,
-0.1278415024280548,
-0.026357822120189667,
0.027234641835093498,
0.04811607673764229,
0.05364963039755821,
-0.021235406398773193,
-0.06918133050203323,
0.00501990644261241,
0.01365574635565281,
-0.07063291221857071,
-0.013099255040287971,
-0.07476547360420227,
-0.03487156704068184,
-0.03795832395553589,
-0.02053944580256939,
-0.06853705644607544,
0.02676321379840374,
-0.07276946306228638,
-0.04763622209429741,
0.06676434725522995,
0.00009180491178994998,
0.04532652348279953,
0.008237374015152454,
-0.058682508766651154,
-0.008479500189423561,
0.026025718078017235,
-0.007270478177815676,
0.032399531453847885,
0.041491854935884476,
-0.05535407364368439,
0.07440917938947678,
-0.007359660230576992,
0.10126549005508423,
0.006160827819257975,
0.03955710306763649,
-0.07423418015241623,
0.07894779741764069,
-0.08899252861738205,
-0.05816374346613884,
0.0017160888528451324,
0.009320348501205444,
-0.029805980622768402,
0.0006488444050773978,
-0.09625053405761719,
-0.0677981823682785,
-0.10241788625717163,
-0.056898534297943115,
-0.024576865136623383,
0.07930926233530045,
0.013358702883124352,
-0.057330261915922165,
0.02801407501101494,
0.05244879424571991,
-0.09142327308654785,
-0.07276888936758041,
-0.09409280866384506,
0.12062221765518188,
0.04817146435379982,
-0.022038692608475685,
-0.012203928083181381,
0.023882867768406868,
-0.009099301882088184,
0.006965673994272947,
-0.0036168224178254604,
0.06629744917154312,
0.03593837469816208,
0.012172483839094639,
0.09532149881124496,
-0.0023097796365618706,
0.03916963189840317,
-0.030707793310284615,
-0.04575589671730995,
-0.057805102318525314,
0.0014089732430875301,
0.00839976780116558,
0.07395739108324051,
0.06491541117429733,
0.06268691271543503,
-0.006657307036221027,
0.11816606670618057,
0.0212445966899395,
-0.00028175365878269076,
0.05551796033978462,
0.09518696367740631,
0.023742659017443657,
0.0034968918189406395,
0.02610214427113533,
0.010535690002143383,
-0.04995701089501381,
0.001486435648985207,
5.260287628761811e-33,
-0.011771345511078835,
-0.09461163729429245,
0.08479541540145874,
0.037631694227457047,
0.022491466253995895,
0.06084724888205528,
0.006880011409521103,
0.0087088318541646,
-0.09731976687908173,
0.04545028880238533,
-0.0733015388250351,
-0.08109388500452042,
0.016458172351121902,
-0.1007813885807991,
0.029539337381720543,
-0.04193592816591263,
0.04689595848321915,
-0.03666485473513603,
0.017855893820524216,
0.03690294548869133,
0.0446564257144928,
-0.032791513949632645,
-0.06487777829170227,
-0.039890747517347336,
0.02826869674026966,
-0.0838499516248703,
-0.013076255097985268,
0.02388392761349678,
0.04071841761469841,
-0.03406676650047302,
0.0160954799503088,
0.03979860991239548,
0.013972016051411629,
0.0408836305141449,
-0.030715877190232277,
-0.048679664731025696,
0.06794566661119461,
0.01553318277001381,
-0.04228993132710457,
-0.0779661163687706,
-0.08246344327926636,
-0.044924620538949966,
-0.033267587423324585,
-0.015013943426311016,
0.02386530674993992,
-0.11097902059555054,
-0.07921843975782394,
-0.04079388454556465,
0.018283529207110405,
0.020524144172668457,
0.12089703232049942,
0.07539275288581848,
0.039423394948244095,
-0.044898856431245804,
0.01128963753581047,
-0.02347223460674286,
0.02988782897591591,
-0.0006204995443113148,
0.008057283237576485,
0.02925591729581356,
0.014821448363363743,
0.006918385159224272,
-0.00556219695135951,
0.010006897151470184,
-0.0009775877697393298,
-0.02878705784678459,
0.005381651688367128,
0.021360324695706367,
0.049694743007421494,
0.0031787618063390255,
-0.049663882702589035,
-0.030404796823859215,
-0.04270271956920624,
-0.03315725922584534,
0.02313900738954544,
0.01692168228328228,
0.020304687321186066,
-0.016164062544703484,
-0.020943183451890945,
-0.06757288426160812,
0.03263584151864052,
-0.010341930203139782,
-0.03875592723488808,
-0.023987358435988426,
-0.018379265442490578,
-0.04000633955001831,
-0.06998014450073242,
-0.03201853856444359,
0.06959404051303864,
0.02265441045165062,
-0.059381257742643356,
-0.042434919625520706,
0.03406462073326111,
-0.005437497515231371,
-0.020234158262610435,
-7.360429142018772e-33,
0.07312004268169403,
0.09339416772127151,
-0.04460282623767853,
0.07875710725784302,
-0.007468399126082659,
-0.07893283665180206,
0.07296611368656158,
-0.05108419805765152,
-0.0483175590634346,
0.0761810913681984,
-0.07015777379274368,
-0.006642552558332682,
0.0348045714199543,
0.03897261247038841,
0.02274399809539318,
-0.029643269255757332,
0.017870869487524033,
0.04902563616633415,
0.07866845279932022,
-0.028609365224838257,
0.004980614874511957,
0.09701725095510483,
0.037934526801109314,
0.017795570194721222,
-0.03802715241909027,
0.02216680720448494,
-0.028067607432603836,
0.04247627034783363,
-0.05749296396970749,
-0.03656195104122162,
-0.028858035802841187,
0.021385645493865013,
-0.030590806156396866,
0.053832728415727615,
0.04198940843343735,
-0.10773645341396332,
0.0414661169052124,
0.1129285991191864,
0.09097018837928772,
-0.07429277896881104,
0.10231184214353561,
0.023022031411528587,
0.0009199071791954339,
0.0027459082193672657,
0.027917739003896713,
-0.0009698704816401005,
0.06606406718492508,
0.0071488069370388985,
0.03425310552120209,
-0.0036929911002516747,
-0.06380608677864075,
-0.03788551315665245,
-0.035492442548274994,
0.039722952991724014,
-0.024902211502194405,
-0.031207367777824402,
-0.019772663712501526,
-0.05420702323317528,
0.0022416473366320133,
0.00774755422025919,
0.04855148494243622,
-0.05772195756435394,
-0.03359202668070793,
0.0032122167758643627,
0.02948548085987568,
-0.06020956113934517,
-0.13612000644207,
0.03472411260008812,
0.0818958431482315,
-0.04706449806690216,
-0.003345936769619584,
0.049402233213186264,
-0.03180482238531113,
-0.036155663430690765,
0.023868124932050705,
0.031587179750204086,
-0.02081204764544964,
-0.026489214971661568,
0.014548690989613533,
0.05786935240030289,
-0.016032392159104347,
0.05195306986570358,
-0.02258218638598919,
0.045753296464681625,
-0.023962615057826042,
-0.002259910572320223,
0.02248961292207241,
0.016984956339001656,
-0.018940875306725502,
-0.00435132859274745,
0.0004767423670273274,
0.019412798807024956,
-0.06902926415205002,
-0.1283416599035263,
0.04923677071928978,
-5.0326296019420624e-8,
-0.04160377383232117,
-0.06639932096004486,
0.01707269810140133,
0.04501368850469589,
0.023948293179273605,
-0.04516681283712387,
-0.05230769142508507,
-0.07359553873538971,
0.050547897815704346,
0.028711020946502686,
-0.10558366030454636,
-0.06637763977050781,
-0.0059684994630515575,
-0.05718253180384636,
0.07238078117370605,
-0.03442133590579033,
-0.05579078942537308,
-0.0447828508913517,
0.036224767565727234,
0.0038440858479589224,
0.06064398214221001,
0.015467217192053795,
0.0316762700676918,
0.11872713267803192,
-0.08182451874017715,
-0.0962720587849617,
0.023913010954856873,
-0.014193786308169365,
-0.10029155761003494,
-0.014628703705966473,
0.009245151653885841,
0.036808185279369354,
0.07786013185977936,
0.0063767279498279095,
0.02126135118305683,
-0.02405732125043869,
-0.009326244704425335,
0.057442452758550644,
0.011689561419188976,
0.026562431827187538,
-0.022279348224401474,
0.0945507138967514,
0.0028866990469396114,
0.0018610490951687098,
-0.05616440623998642,
-0.012271641753613949,
-0.0059878830797970295,
0.04462802782654762,
0.0017387348925694823,
0.00790612306445837,
0.007065639831125736,
-0.024726901203393936,
-0.006900747772306204,
-0.011901520192623138,
0.05230306461453438,
-0.007984963245689869,
0.001076791901141405,
-0.05225092172622681,
-0.06880435347557068,
0.06780291348695755,
0.1069989874958992,
0.07696101814508438,
0.11190903186798096,
-0.05473191291093826
] | 0.031522 |
requires opting in by setting the `serialization` option to `'advanced'` when calling [`child\_process.spawn()`][] or [`child\_process.fork()`][]. [Advanced serialization]: #advanced-serialization [Default Windows shell]: #default-windows-shell [HTML structured clone algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web\_Workers\_API/Structured\_clone\_algorithm [Shell requirements]: #shell-requirements [Signal Events]: process.md#signal-events [`'disconnect'`]: process.md#event-disconnect [`'error'`]: #event-error [`'exit'`]: #event-exit [`'message'`]: process.md#event-message [`ChildProcess`]: #class-childprocess [`Error`]: errors.md#class-error [`EventEmitter`]: events.md#class-eventemitter [`child\_process.exec()`]: #child\_processexeccommand-options-callback [`child\_process.execFile()`]: #child\_processexecfilefile-args-options-callback [`child\_process.execFileSync()`]: #child\_processexecfilesyncfile-args-options [`child\_process.execSync()`]: #child\_processexecsynccommand-options [`child\_process.fork()`]: #child\_processforkmodulepath-args-options [`child\_process.spawn()`]: #child\_processspawncommand-args-options [`child\_process.spawnSync()`]: #child\_processspawnsynccommand-args-options [`dgram.Socket`]: dgram.md#class-dgramsocket [`maxBuffer` and Unicode]: #maxbuffer-and-unicode [`net.Server`]: net.md#class-netserver [`net.Socket`]: net.md#class-netsocket [`options.detached`]: #optionsdetached [`process.disconnect()`]: process.md#processdisconnect [`process.env`]: process.md#processenv [`process.execPath`]: process.md#processexecpath [`process.send()`]: process.md#processsendmessage-sendhandle-options-callback [`stdio`]: #optionsstdio [`subprocess.connected`]: #subprocessconnected [`subprocess.disconnect()`]: #subprocessdisconnect [`subprocess.exitCode`]: #subprocessexitcode [`subprocess.kill()`]: #subprocesskillsignal [`subprocess.send()`]: #subprocesssendmessage-sendhandle-options-callback [`subprocess.signalCode`]: #subprocesssignalcode [`subprocess.stderr`]: #subprocessstderr [`subprocess.stdin`]: #subprocessstdin [`subprocess.stdio`]: #subprocessstdio [`subprocess.stdout`]: #subprocessstdout [`util.convertProcessSignalToExitCode()`]: util.md#utilconvertprocesssignaltoexitcodesignalcode [`util.promisify()`]: util.md#utilpromisifyoriginal [synchronous counterparts]: #synchronous-process-creation [v8.serdes]: v8.md#serialization-api | https://github.com/nodejs/node/blob/main//doc/api/child_process.md | main | nodejs | [
-0.06884299218654633,
-0.0318242609500885,
-0.06698018312454224,
-0.000625237007625401,
-0.03653869777917862,
-0.09676342457532883,
-0.02157367765903473,
0.015657899901270866,
-0.014695299789309502,
0.008708763867616653,
-0.002876590471714735,
-0.036789100617170334,
0.01643969491124153,
0.02564993128180504,
0.05178356543183327,
0.0465303435921669,
0.005590090528130531,
-0.10931295901536942,
0.02199704386293888,
-0.05720307305455208,
0.0713292583823204,
-0.040387336164712906,
0.027410686016082764,
-0.007249137386679649,
0.007619032636284828,
-0.01233080867677927,
0.012270870618522167,
-0.009813574142754078,
0.05275830253958702,
0.003984272480010986,
0.016998205333948135,
0.04380178079009056,
-0.040361445397138596,
-0.12125995755195618,
0.11102871596813202,
0.17654810845851898,
0.10164649784564972,
-0.017866797745227814,
0.0035577372182160616,
-0.046536944806575775,
0.10262954235076904,
-0.0005307202227413654,
-0.09538242965936661,
-0.03217563033103943,
-0.07498349994421005,
-0.10892431437969208,
-0.05847149342298508,
-0.06525848060846329,
-0.05954918637871742,
-0.03494861349463463,
-0.06074132025241852,
0.012520370073616505,
0.023735227063298225,
0.03329736739397049,
0.006904653739184141,
-0.0429353229701519,
0.08601969480514526,
0.017281126230955124,
0.008487286977469921,
0.02958674170076847,
-0.044641751796007156,
0.041903041303157806,
-0.0646241307258606,
-0.005437160842120647,
0.00029686151538044214,
0.06848488003015518,
0.010870549827814102,
-0.09146973490715027,
0.0017577934777364135,
-0.009706663899123669,
-0.055454544723033905,
-0.04667476937174797,
-0.058660026639699936,
0.02950410731136799,
-0.01153619959950447,
-0.04595768079161644,
0.03512479364871979,
0.03847543150186539,
-0.10908960551023483,
-0.041456032544374466,
-0.07102802395820618,
-0.07524523884057999,
-0.006478417664766312,
-0.04762911796569824,
0.02115454711019993,
0.1106228157877922,
-0.059887632727622986,
0.005620360374450684,
0.017708800733089447,
0.05473356693983078,
-0.10734333097934723,
-0.011421134695410728,
0.043008822947740555,
0.10618586838245392,
0.053106795996427536,
0.029707318171858788,
0.008135752752423286,
0.012823349796235561,
-0.034768909215927124,
0.016983341425657272,
-0.020790230482816696,
0.0008141390280798078,
0.003422139212489128,
0.0644051656126976,
0.027326112613081932,
-0.05661335587501526,
-0.051033031195402145,
-0.014375816099345684,
-0.06048576533794403,
-0.028851626440882683,
-0.018590522930026054,
0.09114508330821991,
0.03559446334838867,
0.05550346150994301,
-0.012134715914726257,
0.047128964215517044,
0.011183119378983974,
0.06127069890499115,
-0.040144890546798706,
0.047691501677036285,
0.12043746560811996,
-0.01576247438788414,
-0.025142192840576172,
0.008148728869855404,
0.03672700375318527,
-0.10529353469610214,
0.03340454027056694,
9.580123757213136e-34,
0.10937175154685974,
-0.014106858521699905,
0.0037787621840834618,
0.06350240856409073,
0.08083150535821915,
0.08215068280696869,
0.06723320484161377,
0.02401776984333992,
-0.05825119465589523,
-0.02231670543551445,
-0.028733322396874428,
-0.07853963971138,
-0.0355539433658123,
-0.03104514256119728,
0.016170309856534004,
-0.020529212430119514,
-0.005646717734634876,
0.037784393876791,
0.06003953143954277,
0.05785154178738594,
0.03520696982741356,
0.020820049569010735,
-0.08577403426170349,
0.016994940117001534,
-0.005478543229401112,
0.07691105455160141,
-0.12375558912754059,
0.04248732700943947,
0.036330003291368484,
0.02270544320344925,
-0.0044797612354159355,
0.047752756625413895,
-0.00628084409981966,
-0.03955430909991264,
0.0073299226351082325,
-0.06397613883018494,
-0.004555920604616404,
0.0173322893679142,
-0.08284500986337662,
-0.05460771545767784,
0.03847413510084152,
-0.04314330965280533,
-0.05420951172709465,
-0.008846690878272057,
0.0037173121236264706,
-0.13862162828445435,
-0.027960155159235,
-0.009848255664110184,
0.0877348929643631,
-0.02852727100253105,
0.03914821520447731,
0.005789698101580143,
0.04515695944428444,
-0.04124809429049492,
-0.031300753355026245,
0.02804587595164776,
-0.03337346389889717,
-0.007972387596964836,
0.008592305704951286,
-0.011318612843751907,
0.06475094705820084,
-0.002585281152278185,
-0.013107000850141048,
0.006032751407474279,
0.10420913249254227,
-0.04366917908191681,
0.02196689322590828,
-0.026142731308937073,
-0.024374937638640404,
0.06113054230809212,
-0.06449254602193832,
0.06719577312469482,
-0.07701294124126434,
-0.017685601487755775,
0.028035076335072517,
-0.07593866437673569,
0.050348538905382156,
-0.0473124235868454,
-0.009154759347438812,
0.05694727972149849,
0.048497624695301056,
0.04220806434750557,
-0.07204848527908325,
-0.11731346696615219,
0.029267042875289917,
-0.01266336441040039,
-0.0007185415015555918,
0.014000952243804932,
-0.08559530973434448,
0.032758474349975586,
0.010286704637110233,
-0.05708848312497139,
-0.001453900127671659,
0.003723054425790906,
-0.05663430318236351,
-4.9831604274516414e-33,
0.05371499061584473,
-0.06976407766342163,
0.05192418396472931,
-0.003837669501081109,
-0.04764210432767868,
-0.05584138631820679,
0.05524485558271408,
-0.05025189742445946,
-0.11317549645900726,
0.005639703944325447,
-0.009738332591950893,
0.027885761111974716,
-0.023827921599149704,
0.02222762256860733,
-0.09870129078626633,
0.026165921241044998,
-0.004426251631230116,
-0.059666022658348083,
0.09300872683525085,
-0.049402277916669846,
0.03089594841003418,
0.07908176630735397,
-0.016600938513875008,
0.020335525274276733,
-0.026880532503128052,
-0.10370912402868271,
-0.05414193496108055,
0.0415755957365036,
0.03661872819066048,
-0.05583658814430237,
-0.013509823940694332,
0.03142239898443222,
-0.04356018826365471,
0.04553528130054474,
0.008626541122794151,
0.028835536912083626,
0.01109715923666954,
0.06971178948879242,
0.029961390420794487,
-0.010660756379365921,
0.04254499450325966,
-0.0063001117669045925,
-0.06659208983182907,
-0.023325972259044647,
0.054491184651851654,
0.0294880922883749,
0.017472855746746063,
-0.0155362943187356,
-0.04782027006149292,
0.08194256573915482,
0.08516697585582733,
0.06682440638542175,
0.007551243994385004,
0.023623034358024597,
0.03408541530370712,
-0.016694802790880203,
0.061178140342235565,
0.006318596191704273,
0.016764041036367416,
-0.04759661480784416,
0.06192151829600334,
-0.056369438767433167,
-0.030810927972197533,
-0.0009686314733698964,
0.03115115314722061,
0.006247940007597208,
-0.04684901610016823,
0.05910355970263481,
0.017008543014526367,
0.0013198023661971092,
0.02387111261487007,
0.08332649618387222,
-0.009829196147620678,
-0.00846060924232006,
-0.004504677839577198,
-0.023066099733114243,
-0.05157562345266342,
-0.04121023416519165,
-0.019187673926353455,
0.04774031788110733,
-0.011600632220506668,
0.04772718623280525,
0.0021504610776901245,
0.02406114898622036,
-0.07688228785991669,
-0.08086326718330383,
0.10501626878976822,
0.041973620653152466,
-0.016389425843954086,
-0.052490316331386566,
-0.006603879854083061,
0.0075483862310647964,
0.004053872544318438,
-0.023363791406154633,
0.03245890885591507,
-5.454956308881265e-8,
-0.066512830555439,
-0.037257347255945206,
-0.06011126935482025,
0.008178728632628918,
0.04726383835077286,
-0.019690880551934242,
-0.030943961814045906,
-0.11948227882385254,
0.004110744222998619,
-0.07685872167348862,
-0.07589296996593475,
-0.00021403537539299577,
0.040637094527482986,
0.06897445023059845,
-0.006299198605120182,
-0.05086991935968399,
-0.007147607859224081,
-0.00536625599488616,
0.044886019080877304,
-0.06578590720891953,
0.06223402917385101,
-0.046132445335388184,
0.008685028180480003,
0.05415476858615875,
-0.03211243823170662,
-0.03202308341860771,
0.046031463891267776,
0.03161744400858879,
-0.0194677896797657,
-0.03130913898348808,
-0.03977520763874054,
-0.038302574306726456,
0.03002736158668995,
0.036393046379089355,
-0.06749705225229263,
-0.007507467642426491,
-0.01282905787229538,
0.015381320379674435,
0.02070009708404541,
-0.07595255970954895,
0.1373969465494156,
0.08628080040216446,
-0.0803944319486618,
0.005800558719784021,
0.06102064996957779,
0.044002436101436615,
-0.09786875545978546,
0.05683775246143341,
0.04526014253497124,
0.0577898733317852,
0.04916727542877197,
0.002166938269510865,
0.043256472796201706,
0.017922863364219666,
0.005539136007428169,
0.018574513494968414,
0.03615378960967064,
-0.04842543974518776,
0.04274105280637741,
0.03586483746767044,
0.09590362757444382,
0.027074502781033516,
0.06689245253801346,
-0.061829376965761185
] | 0.056194 |
# Assert > Stability: 2 - Stable The `node:assert` module provides a set of assertion functions for verifying invariants. ## Strict assertion mode In strict assertion mode, non-strict methods behave like their corresponding strict methods. For example, [`assert.deepEqual()`][] will behave like [`assert.deepStrictEqual()`][]. In strict assertion mode, error messages for objects display a diff. In legacy assertion mode, error messages for objects display the objects, often truncated. ### Message parameter semantics For assertion methods that accept an optional `message` parameter, the message may be provided in one of the following forms: \* \*\*string\*\*: Used as-is. If additional arguments are supplied after the `message` string, they are treated as printf-like substitutions (see [`util.format()`][]). \* \*\*Error\*\*: If an `Error` instance is provided as `message`, that error is thrown directly instead of an `AssertionError`. \* \*\*function\*\*: A function of the form `(actual, expected) => string`. It is called only when the assertion fails and should return a string to be used as the error message. Non-string return values are ignored and the default message is used instead. If additional arguments are passed along with an `Error` or a function as `message`, the call is rejected with `ERR\_AMBIGUOUS\_ARGUMENT`. If the first item is neither a string, `Error`, nor function, `ERR\_INVALID\_ARG\_TYPE` is thrown. To use strict assertion mode: ```mjs import { strict as assert } from 'node:assert'; ``` ```cjs const assert = require('node:assert').strict; ``` ```mjs import assert from 'node:assert/strict'; ``` ```cjs const assert = require('node:assert/strict'); ``` Example error diff: ```mjs import { strict as assert } from 'node:assert'; assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected ... Lines skipped // // [ // [ // ... // 2, // + 3 // - '3' // ], // ... // 5 // ] ``` ```cjs const assert = require('node:assert/strict'); assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected ... Lines skipped // // [ // [ // ... // 2, // + 3 // - '3' // ], // ... // 5 // ] ``` To deactivate the colors, use the `NO\_COLOR` or `NODE\_DISABLE\_COLORS` environment variables. This will also deactivate the colors in the REPL. For more on color support in terminal environments, read the tty [`getColorDepth()`][] documentation. ## Legacy assertion mode Legacy assertion mode uses the [`==` operator][] in: \* [`assert.deepEqual()`][] \* [`assert.equal()`][] \* [`assert.notDeepEqual()`][] \* [`assert.notEqual()`][] To use legacy assertion mode: ```mjs import assert from 'node:assert'; ``` ```cjs const assert = require('node:assert'); ``` Legacy assertion mode may have surprising results, especially when using [`assert.deepEqual()`][]: ```cjs // WARNING: This does not throw an AssertionError in legacy assertion mode! assert.deepEqual(/a/gi, new Date()); ``` ## Class: `assert.AssertionError` \* Extends: {errors.Error} Indicates the failure of an assertion. All errors thrown by the `node:assert` module will be instances of the `AssertionError` class. ### `new assert.AssertionError(options)` \* `options` {Object} \* `message` {string} If provided, the error message is set to this value. \* `actual` {any} The `actual` property on the error instance. \* `expected` {any} The `expected` property on the error instance. \* `operator` {string} The `operator` property on the error instance. \* `stackStartFn` {Function} If provided, the generated stack trace omits frames before this function. \* `diff` {string} If set to `'full'`, shows the full diff in assertion errors. Defaults to `'simple'`. Accepted values: `'simple'`, `'full'`. A subclass of {Error} that indicates the failure of an assertion. All instances contain the built-in `Error` properties (`message` and `name`) and: \* `actual` {any} Set to the `actual` argument for methods such as [`assert.strictEqual()`][]. | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.09506801515817642,
0.02533201314508915,
0.041743937879800797,
0.08052825927734375,
0.0504646971821785,
-0.0780942365527153,
-0.035604264587163925,
-0.0030536584090441465,
-0.08403772860765457,
-0.018523558974266052,
-0.017994092777371407,
-0.03860095515847206,
0.07284962385892868,
0.024534499272704124,
0.01804068125784397,
0.04005908593535423,
0.01987599767744541,
0.05325571820139885,
-0.03449390456080437,
0.0016478259349241853,
0.003538232296705246,
0.02402065508067608,
-0.07139008492231369,
0.03446453809738159,
-0.028723325580358505,
-0.02101321518421173,
-0.070319265127182,
0.014349818229675293,
0.06273240596055984,
-0.03753795847296715,
-0.0013206780422478914,
0.035454973578453064,
-0.013094124384224415,
0.05869981274008751,
0.06061078608036041,
0.12269382923841476,
0.031101452186703682,
-0.12116364389657974,
-0.013712084852159023,
-0.013701193034648895,
0.03585931658744812,
0.039811424911022186,
-0.055953267961740494,
-0.04502016305923462,
-0.0013552113668993115,
0.00485417852178216,
0.00983829703181982,
0.04314356669783592,
-0.0951215997338295,
-0.06917925179004669,
0.006665495224297047,
0.015622059814631939,
0.0009269262664020061,
-0.04061342775821686,
0.019772788509726524,
-0.030071444809436798,
0.04210316762328148,
0.03336039185523987,
-0.001386309857480228,
0.02801336906850338,
0.036405049264431,
-0.02790534496307373,
0.006068904418498278,
-0.005570248235017061,
-0.007454086095094681,
0.01298933569341898,
-0.004501675255596638,
0.03364017605781555,
0.024649975821375847,
0.09757640957832336,
-0.08133870363235474,
0.030672403052449226,
-0.08944933861494064,
0.0760108232498169,
-0.022381247952580452,
0.038017645478248596,
0.038025349378585815,
-0.029384130612015724,
-0.02124137058854103,
-0.038055285811424255,
-0.02101927623152733,
-0.0563439317047596,
0.015016764402389526,
-0.0033877503592520952,
0.027136042714118958,
0.012255563400685787,
-0.030638903379440308,
-0.009969101287424564,
-0.02222982794046402,
0.04993307217955589,
0.04780174419283867,
-0.055789556354284286,
-0.024175118654966354,
0.10711944848299026,
0.06166619062423706,
-0.03353279083967209,
0.001269075321033597,
-0.021359965205192566,
0.030394138768315315,
0.0531608946621418,
0.02858443185687065,
0.031625472009181976,
0.07079757750034332,
-0.11511943489313126,
0.05332237482070923,
-0.004984668456017971,
0.06406043469905853,
-0.1329430341720581,
0.013144322670996189,
0.007643277756869793,
0.04113900288939476,
-0.0021522045135498047,
0.03305504471063614,
0.001194414566271007,
0.02176331728696823,
-0.028208870440721512,
0.022840911522507668,
0.02304861508309841,
0.016267996281385422,
0.012098260223865509,
0.039963141083717346,
-0.04042598232626915,
0.028794940561056137,
0.016840066760778427,
0.0584440715610981,
0.024564102292060852,
-0.0228401068598032,
7.098000028197696e-33,
0.020189635455608368,
0.006788678467273712,
0.017039133235812187,
0.05438225716352463,
0.00518324738368392,
0.060883529484272,
-0.03373878449201584,
-0.016952989622950554,
-0.08877751231193542,
-0.0032280045561492443,
-0.017280930653214455,
0.03310472145676613,
0.0037077481392771006,
-0.01865796558558941,
0.04456846043467522,
0.023745866492390633,
0.04749096930027008,
-0.0000606316898483783,
0.01361401192843914,
0.044557083398103714,
0.04878322035074234,
-0.07227804511785507,
-0.043056365102529526,
-0.040002092719078064,
0.014071364887058735,
-0.036582883447408676,
0.048992227762937546,
-0.0121713075786829,
-0.02805578149855137,
-0.02129340171813965,
-0.10834739357233047,
-0.06614213436841965,
0.11109975725412369,
0.14677545428276062,
0.022399121895432472,
0.0010227988241240382,
0.04447636008262634,
-0.04331222176551819,
-0.10001929849386215,
-0.06737438589334488,
-0.05299226939678192,
-0.025791935622692108,
-0.03315284848213196,
0.03937221318483353,
0.04580869898200035,
-0.14379698038101196,
-0.05969202518463135,
0.0010364006739109755,
0.048365961760282516,
-0.022585300728678703,
0.024803228676319122,
0.07616405189037323,
0.02967093139886856,
-0.07078608870506287,
0.045915037393569946,
-0.04354381561279297,
0.02032501809298992,
0.01797868311405182,
0.030001822859048843,
0.045816801488399506,
0.003958601504564285,
-0.01694088988006115,
-0.04443035274744034,
-0.06275229156017303,
-0.03139625862240791,
0.05976109579205513,
-0.07008983194828033,
-0.03061801753938198,
-0.012997584417462349,
0.029746079817414284,
-0.0563032403588295,
0.0012912708334624767,
-0.12096813321113586,
0.016504937782883644,
-0.017941171303391457,
-0.07828561216592789,
-0.02050396427512169,
0.012781372293829918,
0.04264850541949272,
-0.06333495676517487,
-0.010557479225099087,
-0.022971777245402336,
0.0008329700795002282,
0.06423615664243698,
-0.0945054218173027,
-0.034954555332660675,
-0.022243494167923927,
-0.016953356564044952,
0.028139276430010796,
-0.06666284054517746,
-0.05846073850989342,
-0.006363912019878626,
-0.02261372096836567,
-0.019016645848751068,
-0.023436803370714188,
-8.061993557948284e-33,
0.026284951716661453,
0.10582778602838516,
-0.08086331188678741,
0.1498280167579651,
-0.0494571328163147,
-0.08848952502012253,
0.03864619880914688,
0.042533088475465775,
-0.034042712301015854,
-0.06286776810884476,
-0.010060745291411877,
-0.0514933280646801,
0.0086959945037961,
-0.003029943909496069,
0.03146992623806,
-0.029482068493962288,
-0.1188681498169899,
-0.037650901824235916,
0.012787098065018654,
0.017226839438080788,
0.09057054668664932,
0.007435873616486788,
-0.006553016137331724,
-0.0032198529224842787,
-0.0362318716943264,
-0.009959478862583637,
0.017567317932844162,
-0.01292332075536251,
0.051368631422519684,
-0.006456334609538317,
0.043661125004291534,
0.053397852927446365,
-0.04345971718430519,
0.007431201171129942,
0.05451742932200432,
-0.08657742291688919,
0.05596903711557388,
0.06939513236284256,
-0.0007601745892316103,
0.012861635535955429,
0.06832585483789444,
0.06536200642585754,
-0.03377031907439232,
0.028299378231167793,
0.03197440505027771,
0.024563752114772797,
0.034315936267375946,
-0.0033118261490017176,
0.029551874846220016,
-0.04078248515725136,
0.03310883790254593,
-0.1091274693608284,
0.014146649278700352,
0.11585643142461777,
-0.047123245894908905,
-0.05420739948749542,
-0.04371536895632744,
0.047843243926763535,
-0.06738464534282684,
0.04907108470797539,
-0.076872318983078,
-0.05272040143609047,
0.016539987176656723,
0.04578591138124466,
0.004104820545762777,
0.002474521053954959,
-0.062092773616313934,
-0.02311955764889717,
0.055157966911792755,
-0.018613172695040703,
0.04427003487944603,
-0.013396735303103924,
-0.10168484598398209,
0.005571107845753431,
0.031567178666591644,
0.01871284656226635,
-0.0001795325370039791,
-0.05034416541457176,
0.06642691045999527,
0.10519575327634811,
-0.009892852045595646,
0.030492862686514854,
0.023039231076836586,
0.11025106906890869,
-0.043026797473430634,
-0.001771317794919014,
-0.016633138060569763,
0.13561920821666718,
-0.054669760167598724,
0.07498199492692947,
0.027287662029266357,
0.009578507393598557,
-0.06812312453985214,
-0.0042703840881586075,
-0.0035134684294462204,
-5.682109716076411e-8,
-0.10113278776407242,
-0.027175264433026314,
-0.017286669462919235,
-0.056603722274303436,
0.002750318730250001,
-0.027555933222174644,
0.03201262280344963,
-0.11309944093227386,
0.04936063662171364,
0.003999052569270134,
-0.030482398346066475,
-0.017321662977337837,
-0.06755588203668594,
-0.1682857722043991,
0.002652582246810198,
0.04929677024483681,
-0.05324450135231018,
-0.026264376938343048,
-0.01768733374774456,
0.0373804084956646,
0.009431448765099049,
-0.0022058598697185516,
-0.030293406918644905,
0.05499512702226639,
-0.023657741025090218,
-0.020697753876447678,
0.018079698085784912,
0.09446833282709122,
-0.056178055703639984,
0.007932708598673344,
0.03632277995347977,
0.009465554729104042,
0.024054504930973053,
-0.06272588670253754,
-0.056717582046985626,
0.13874921202659607,
0.015214953571557999,
0.007744980975985527,
0.05686025321483612,
0.050028856843709946,
-0.060762032866477966,
0.03203264996409416,
-0.06389891356229782,
-0.019664069637656212,
-0.011372963897883892,
-0.05854886770248413,
-0.0016178460791707039,
-0.015503467991948128,
-0.03189020976424217,
-0.03706064820289612,
0.007087853271514177,
0.003128918120637536,
-0.07789590954780579,
0.058237332850694656,
-0.08786910027265549,
0.03711680322885513,
-0.020005248486995697,
-0.037806186825037,
-0.028300071135163307,
0.03772500902414322,
0.13812567293643951,
0.03311357647180557,
0.1413325071334839,
-0.07158523052930832
] | 0.10672 |
`'full'`, shows the full diff in assertion errors. Defaults to `'simple'`. Accepted values: `'simple'`, `'full'`. A subclass of {Error} that indicates the failure of an assertion. All instances contain the built-in `Error` properties (`message` and `name`) and: \* `actual` {any} Set to the `actual` argument for methods such as [`assert.strictEqual()`][]. \* `expected` {any} Set to the `expected` value for methods such as [`assert.strictEqual()`][]. \* `generatedMessage` {boolean} Indicates if the message was auto-generated (`true`) or not. \* `code` {string} Value is always `ERR\_ASSERTION` to show that the error is an assertion error. \* `operator` {string} Set to the passed in operator value. ```mjs import assert from 'node:assert'; // Generate an AssertionError to compare the error message later: const { message } = new assert.AssertionError({ actual: 1, expected: 2, operator: 'strictEqual', }); // Verify error output: try { assert.strictEqual(1, 2); } catch (err) { assert(err instanceof assert.AssertionError); assert.strictEqual(err.message, message); assert.strictEqual(err.name, 'AssertionError'); assert.strictEqual(err.actual, 1); assert.strictEqual(err.expected, 2); assert.strictEqual(err.code, 'ERR\_ASSERTION'); assert.strictEqual(err.operator, 'strictEqual'); assert.strictEqual(err.generatedMessage, true); } ``` ```cjs const assert = require('node:assert'); // Generate an AssertionError to compare the error message later: const { message } = new assert.AssertionError({ actual: 1, expected: 2, operator: 'strictEqual', }); // Verify error output: try { assert.strictEqual(1, 2); } catch (err) { assert(err instanceof assert.AssertionError); assert.strictEqual(err.message, message); assert.strictEqual(err.name, 'AssertionError'); assert.strictEqual(err.actual, 1); assert.strictEqual(err.expected, 2); assert.strictEqual(err.code, 'ERR\_ASSERTION'); assert.strictEqual(err.operator, 'strictEqual'); assert.strictEqual(err.generatedMessage, true); } ``` ## Class: `assert.Assert` The `Assert` class allows creating independent assertion instances with custom options. ### `new assert.Assert([options])` \* `options` {Object} \* `diff` {string} If set to `'full'`, shows the full diff in assertion errors. Defaults to `'simple'`. Accepted values: `'simple'`, `'full'`. \* `strict` {boolean} If set to `true`, non-strict methods behave like their corresponding strict methods. Defaults to `true`. \* `skipPrototype` {boolean} If set to `true`, skips prototype and constructor comparison in deep equality checks. Defaults to `false`. Creates a new assertion instance. The `diff` option controls the verbosity of diffs in assertion error messages. ```js const { Assert } = require('node:assert'); const assertInstance = new Assert({ diff: 'full' }); assertInstance.deepStrictEqual({ a: 1 }, { a: 2 }); // Shows a full diff in the error message. ``` \*\*Important\*\*: When destructuring assertion methods from an `Assert` instance, the methods lose their connection to the instance's configuration options (such as `diff`, `strict`, and `skipPrototype` settings). The destructured methods will fall back to default behavior instead. ```js const myAssert = new Assert({ diff: 'full' }); // This works as expected - uses 'full' diff myAssert.strictEqual({ a: 1 }, { b: { c: 1 } }); // This loses the 'full' diff setting - falls back to default 'simple' diff const { strictEqual } = myAssert; strictEqual({ a: 1 }, { b: { c: 1 } }); ``` The `skipPrototype` option affects all deep equality methods: ```js class Foo { constructor(a) { this.a = a; } } class Bar { constructor(a) { this.a = a; } } const foo = new Foo(1); const bar = new Bar(1); // Default behavior - fails due to different constructors const assert1 = new Assert(); assert1.deepStrictEqual(foo, bar); // AssertionError // Skip prototype comparison - passes if properties are equal const assert2 = new Assert({ skipPrototype: true }); assert2.deepStrictEqual(foo, bar); // OK ``` When destructured, methods lose access to the instance's `this` context and revert to default assertion behavior (diff: 'simple', non-strict mode). To maintain custom options when using destructured methods, avoid destructuring and call methods directly on the instance. ## `assert(value[, message])` \* `value` {any} The input that is checked for being truthy. \* `message` {string|Error|Function} An alias of [`assert.ok()`][]. ## `assert.deepEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} \*\*Strict assertion mode\*\* | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.07443275302648544,
0.0585285909473896,
0.0642521008849144,
0.08324945718050003,
0.05340307578444481,
-0.10577473789453506,
-0.005588962230831385,
0.03297936171293259,
-0.05294225364923477,
0.025576207786798477,
0.008824171498417854,
-0.055519673973321915,
0.0810461938381195,
0.008697355166077614,
0.02522958442568779,
0.0030796423088759184,
-0.01673353649675846,
0.0036022518761456013,
-0.0023491906467825174,
-0.043277937918901443,
0.02416810393333435,
0.03942161053419113,
-0.04108421131968498,
0.06437357515096664,
-0.0015428359620273113,
-0.0030166232027113438,
-0.0372711643576622,
0.035140786319971085,
0.08122313767671585,
-0.024225128814578056,
0.006482953671365976,
0.010760864242911339,
0.004462981130927801,
0.06770655512809753,
0.02376765012741089,
0.12891921401023865,
0.007299480959773064,
-0.05355054885149002,
0.011479088105261326,
0.0069104405120015144,
0.024328293278813362,
0.07410923391580582,
-0.03542573004961014,
-0.04757080599665642,
0.035993628203868866,
-0.0011748074321076274,
-0.044682811945676804,
0.05989396944642067,
-0.057468343526124954,
-0.0701482966542244,
0.0007763980538584292,
0.013856056146323681,
-0.015417313203215599,
-0.06754083931446075,
0.04808271676301956,
-0.033246785402297974,
0.033201929181814194,
0.05148981511592865,
0.020199665799736977,
-0.006125161424279213,
-0.00527423107996583,
-0.01028432697057724,
0.009864704683423042,
-0.02406151592731476,
0.006010225974023342,
-0.03281765431165695,
0.005124237854033709,
0.05906267464160919,
0.00554053857922554,
0.08983319997787476,
-0.08032626658678055,
0.0287193413823843,
-0.05205382779240608,
0.11585424840450287,
-0.017670772969722748,
-0.011477350257337093,
0.0032852478325366974,
0.02678673341870308,
-0.0444747731089592,
0.016725748777389526,
-0.10450122505426407,
-0.10456765443086624,
0.03966435045003891,
-0.0047528804279863834,
0.00747230090200901,
0.036790989339351654,
-0.04079146683216095,
0.03625796362757683,
0.006688033230602741,
0.04001511260867119,
0.009864861145615578,
-0.10293246805667877,
-0.0641750693321228,
0.13550329208374023,
0.06986469030380249,
0.01902027241885662,
-0.024197204038500786,
0.0042595104314386845,
0.04423011839389801,
0.02292587421834469,
0.03317195549607277,
-0.01405178289860487,
0.052365973591804504,
-0.0773889496922493,
0.07391657680273056,
0.03675999492406845,
0.05948804318904877,
-0.1476062387228012,
-0.016094088554382324,
-0.008950105868279934,
0.027964314445853233,
-0.020992832258343697,
0.05266903340816498,
0.005623884033411741,
0.05362125486135483,
0.0061543467454612255,
0.0365690216422081,
0.025653913617134094,
0.03668415546417236,
0.027187874540686607,
0.05569024756550789,
-0.0365038737654686,
0.073561891913414,
0.01592026650905609,
0.04493119940161705,
0.00706590386107564,
0.04032339155673981,
1.5481069582497518e-33,
0.010096288286149502,
-0.011630062945187092,
-0.006156094837933779,
0.08197390288114548,
0.007052605040371418,
0.08384553343057632,
-0.023530511185526848,
-0.0051446217112243176,
-0.05913719907402992,
-0.015273789875209332,
-0.006582037545740604,
0.07260962575674057,
-0.0333654023706913,
-0.03002679906785488,
0.017249129712581635,
0.0274510458111763,
0.05529851093888283,
-0.026545369997620583,
-0.00046447396744042635,
0.042855773121118546,
0.006124651990830898,
-0.04221797361969948,
-0.041053105145692825,
-0.016882890835404396,
0.014368783682584763,
-0.04963415116071701,
0.03725535050034523,
0.0070909117348492146,
-0.050971485674381256,
-0.04163503274321556,
-0.05822964385151863,
-0.05561049282550812,
0.12185714393854141,
0.13397464156150818,
0.021225115284323692,
0.01335469726473093,
0.05560711771249771,
0.007812050171196461,
-0.1385778784751892,
-0.11081859469413757,
-0.08523271232843399,
-0.007106546312570572,
-0.052070241421461105,
-0.002459345618262887,
-0.003209288464859128,
-0.11057546734809875,
-0.07996371388435364,
-0.042667124420404434,
0.0844765231013298,
-0.004594272002577782,
0.024736084043979645,
0.07892733812332153,
0.040840763598680496,
-0.05445725470781326,
-0.000654031930025667,
-0.0059683541767299175,
0.06251391768455505,
0.018404584378004074,
0.027897723019123077,
-0.011424566619098186,
0.013850148767232895,
0.001768920454196632,
-0.03806355595588684,
-0.034042540937662125,
-0.005844315513968468,
0.042499005794525146,
-0.01760704442858696,
0.014226788654923439,
0.009317845106124878,
0.0199798084795475,
-0.027874380350112915,
-0.02774127572774887,
-0.09822802245616913,
0.031129544600844383,
0.007192015647888184,
-0.06809404492378235,
-0.0007289833156391978,
0.03117077611386776,
-0.021422596648335457,
-0.07748542726039886,
0.00784083642065525,
-0.02212655171751976,
-0.04456661641597748,
0.028162747621536255,
-0.0917171835899353,
0.009665912948548794,
0.0061180125921964645,
0.004384821746498346,
0.01575762778520584,
-0.024678761139512062,
-0.03239822760224342,
-0.018143048509955406,
-0.007209223695099354,
-0.010696787387132645,
-0.05341755598783493,
-4.0554977546651246e-33,
-0.0018618395552039146,
0.09955121576786041,
-0.047471314668655396,
0.13198670744895935,
-0.05207887291908264,
-0.0627860501408577,
0.08086828142404556,
0.058182064443826675,
0.010948321782052517,
-0.038626160472631454,
-0.004345717374235392,
-0.06828423589468002,
0.016687124967575073,
0.010567175224423409,
-0.021295228973031044,
-0.0055708084255456924,
-0.10911930352449417,
-0.02775557152926922,
0.009387237019836903,
-0.009280146099627018,
0.01967761106789112,
0.03591006621718407,
0.02617969550192356,
-0.04152815788984299,
-0.0863640308380127,
0.020672673359513283,
0.015546679496765137,
0.021286720409989357,
-0.019411031156778336,
-0.051631905138492584,
0.05321437492966652,
0.05220898985862732,
-0.06462088227272034,
0.017077460885047913,
-0.010195818729698658,
-0.10656469315290451,
0.06764151155948639,
0.052754614502191544,
0.016227910295128822,
-0.0038106292486190796,
0.07454611361026764,
0.05829504504799843,
-0.0636080652475357,
0.032037489116191864,
0.02130352519452572,
0.010549384169280529,
0.0023938813246786594,
-0.03565561771392822,
0.035077549517154694,
-0.05286499485373497,
0.016351208090782166,
-0.07582207769155502,
0.03888892009854317,
0.12614312767982483,
-0.04485552757978439,
-0.058144498616456985,
-0.04369014874100685,
0.05751294642686844,
-0.02497059665620327,
0.03493266552686691,
-0.09498193860054016,
-0.05603046342730522,
-0.04186106473207474,
0.06577371060848236,
-0.03905949369072914,
0.0011893098708242178,
-0.09051118046045303,
0.02148815430700779,
0.10189720243215561,
-0.034832630306482315,
-0.000949386041611433,
0.02024151012301445,
-0.07568221539258957,
-0.04193186014890671,
0.01658831536769867,
0.04054915904998779,
-0.01866448111832142,
-0.05640065297484398,
0.054027851670980453,
0.0830991342663765,
0.013957355171442032,
0.027288412675261497,
0.004863355774432421,
0.10365835577249527,
-0.09482230991125107,
-0.014956566505134106,
0.00016760407015681267,
0.11226750910282135,
-0.04469157010316849,
0.06272774934768677,
0.026082469150424004,
0.017300542443990707,
-0.05942343547940254,
-0.04753834381699562,
-0.005400503985583782,
-5.3050523973752206e-8,
-0.11551294475793839,
-0.05921345204114914,
-0.008723985403776169,
-0.06147141382098198,
0.008191077969968319,
-0.01222928985953331,
-0.0090603306889534,
-0.07549072802066803,
0.02052442729473114,
-0.005609485786408186,
-0.049950920045375824,
0.008199276402592659,
-0.09263672679662704,
-0.12627708911895752,
-0.02074929140508175,
0.030059820041060448,
-0.07991788536310196,
0.01791521906852722,
0.013364693149924278,
0.022713035345077515,
0.05297532677650452,
0.0052413358353078365,
-0.028812643140554428,
0.06218757852911949,
-0.011046878062188625,
0.0006727505824528635,
-0.001374537474475801,
0.0630357414484024,
-0.09120307862758636,
-0.03420378640294075,
-0.004246161784976721,
-0.0004471152205951512,
0.0818394124507904,
-0.08406315743923187,
-0.018519101664423943,
0.0888817235827446,
0.014041908085346222,
-0.024715669453144073,
0.02516033686697483,
0.05087907984852791,
-0.04715178161859512,
-0.007232644595205784,
-0.02557486854493618,
-0.037076231092214584,
-0.08824364095926285,
-0.07439788430929184,
-0.020553892478346825,
-0.017292648553848267,
0.0030587429646402597,
-0.08553684502840042,
0.037154968827962875,
-0.01798570528626442,
-0.06215549260377884,
0.006477756425738335,
-0.09585285931825638,
0.005936585832387209,
-0.017439110204577446,
-0.018491901457309723,
-0.03275713697075844,
-0.009774566628038883,
0.13883189857006073,
0.08271834999322891,
0.11360183358192444,
-0.040233202278614044
] | 0.045267 |
when using destructured methods, avoid destructuring and call methods directly on the instance. ## `assert(value[, message])` \* `value` {any} The input that is checked for being truthy. \* `message` {string|Error|Function} An alias of [`assert.ok()`][]. ## `assert.deepEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} \*\*Strict assertion mode\*\* An alias of [`assert.deepStrictEqual()`][]. \*\*Legacy assertion mode\*\* > Stability: 3 - Legacy: Use [`assert.deepStrictEqual()`][] instead. Tests for deep equality between the `actual` and `expected` parameters. Consider using [`assert.deepStrictEqual()`][] instead. [`assert.deepEqual()`][] can have surprising results. \_Deep equality\_ means that the enumerable "own" properties of child objects are also recursively evaluated by the following rules. ### Comparison details \* Primitive values are compared with the [`==` operator][], with the exception of {NaN}. It is treated as being identical in case both sides are {NaN}. \* [Type tags][Object.prototype.toString()] of objects should be the same. \* Only [enumerable "own" properties][] are considered. \* Object constructors are compared when available. \* {Error} names, messages, causes, and errors are always compared, even if these are not enumerable properties. \* [Object wrappers][] are compared both as objects and unwrapped values. \* `Object` properties are compared unordered. \* {Map} keys and {Set} items are compared unordered. \* Recursion stops when both sides differ or either side encounters a circular reference. \* Implementation does not test the [`[[Prototype]]`][prototype-spec] of objects. \* {Symbol} properties are not compared. \* {WeakMap}, {WeakSet} and {Promise} instances are \*\*not\*\* compared structurally. They are only equal if they reference the same object. Any comparison between different `WeakMap`, `WeakSet`, or `Promise` instances will result in inequality, even if they contain the same content. \* {RegExp} lastIndex, flags, and source are always compared, even if these are not enumerable properties. The following example does not throw an [`AssertionError`][] because the primitives are compared using the [`==` operator][]. ```mjs import assert from 'node:assert'; // WARNING: This does not throw an AssertionError! assert.deepEqual('+00000000', false); ``` ```cjs const assert = require('node:assert'); // WARNING: This does not throw an AssertionError! assert.deepEqual('+00000000', false); ``` "Deep" equality means that the enumerable "own" properties of child objects are evaluated also: ```mjs import assert from 'node:assert'; const obj1 = { a: { b: 1, }, }; const obj2 = { a: { b: 2, }, }; const obj3 = { a: { b: 1, }, }; const obj4 = { \_\_proto\_\_: obj1 }; assert.deepEqual(obj1, obj1); // OK // Values of b are different: assert.deepEqual(obj1, obj2); // AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } } assert.deepEqual(obj1, obj3); // OK // Prototypes are ignored: assert.deepEqual(obj1, obj4); // AssertionError: { a: { b: 1 } } deepEqual {} ``` ```cjs const assert = require('node:assert'); const obj1 = { a: { b: 1, }, }; const obj2 = { a: { b: 2, }, }; const obj3 = { a: { b: 1, }, }; const obj4 = { \_\_proto\_\_: obj1 }; assert.deepEqual(obj1, obj1); // OK // Values of b are different: assert.deepEqual(obj1, obj2); // AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } } assert.deepEqual(obj1, obj3); // OK // Prototypes are ignored: assert.deepEqual(obj1, obj4); // AssertionError: { a: { b: 1 } } deepEqual {} ``` If the values are not equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the [`AssertionError`][]. ## `assert.deepStrictEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} Tests for | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.09238405525684357,
-0.0031946683302521706,
0.03625648841261864,
0.018374435603618622,
-0.008233464322984219,
-0.08129649609327316,
-0.0380730964243412,
0.02646295726299286,
-0.07257416099309921,
-0.044689103960990906,
-0.02748512104153633,
-0.030127063393592834,
0.050876617431640625,
0.005602249410003424,
0.04882189258933067,
0.01955200545489788,
0.0651230737566948,
0.006604315713047981,
-0.07302399724721909,
-0.03535889834165573,
0.07577405869960785,
0.06202665716409683,
-0.04101613536477089,
0.07929372042417526,
-0.029065875336527824,
-0.041176170110702515,
-0.05058852583169937,
-0.023160576820373535,
0.02785502001643181,
-0.05936448648571968,
0.020676907151937485,
0.0672568529844284,
-0.024754764512181282,
0.049498140811920166,
0.11587473750114441,
0.1542746126651764,
-0.01874065399169922,
-0.09575015306472778,
-0.006280361674726009,
-0.014262228272855282,
-0.020886285230517387,
0.03143347427248955,
-0.05648757889866829,
-0.04012126103043556,
0.03991569206118584,
0.033847782760858536,
-0.005889886524528265,
0.03566279262304306,
-0.03130133077502251,
-0.05729445070028305,
0.007145254407078028,
0.07259222865104675,
0.009404688142240047,
0.006376159843057394,
0.041245874017477036,
-0.04323165491223335,
0.021594466641545296,
-0.0011154047679156065,
-0.03474702313542366,
0.015410142950713634,
0.03382839635014534,
0.008573195897042751,
0.002319842344149947,
-0.04250490292906761,
0.00012313238403294235,
-0.009553435258567333,
0.036807313561439514,
0.028851738199591637,
0.041463419795036316,
0.12280231714248657,
-0.044485948979854584,
0.03365572169423103,
-0.044009845703840256,
0.081086665391922,
0.006813011132180691,
0.08299829065799713,
0.041137292981147766,
-0.0709761455655098,
-0.052932918071746826,
-0.06531442701816559,
-0.010512491688132286,
-0.060331132262945175,
-0.022020310163497925,
-0.03196460381150246,
0.07140804827213287,
-0.007579904515296221,
-0.02600024826824665,
-0.029159707948565483,
0.05518094822764397,
0.08829537779092789,
0.009962283074855804,
-0.0436348058283329,
-0.0013196869986131787,
0.13371998071670532,
0.11947311460971832,
-0.013384825550019741,
-0.02724975347518921,
-0.020435182377696037,
-0.005754505284130573,
0.03847775235772133,
-0.02467193454504013,
0.023059099912643433,
0.043390512466430664,
-0.11289963126182556,
0.022267838940024376,
0.020899079740047455,
0.08374825119972229,
-0.10855068266391754,
0.012522560544312,
-0.05021459236741066,
0.013337408192455769,
-0.016154948621988297,
0.07382822781801224,
0.033772293478250504,
0.05278582498431206,
0.021269189193844795,
-0.011281818151473999,
0.030468344688415527,
-0.03976331278681755,
0.0387638695538044,
0.0191870778799057,
-0.023654194548726082,
0.05914119631052017,
0.011998044326901436,
0.0151142543181777,
0.04942464828491211,
-0.006069766357541084,
3.0259219257142232e-33,
0.028198620304465294,
-0.037470217794179916,
-0.017906304448843002,
0.0634545236825943,
-0.006541014648973942,
0.05810198932886124,
-0.011148832738399506,
0.05641021952033043,
-0.08692402392625809,
0.02954438515007496,
-0.03419575095176697,
0.06527363508939743,
-0.0239801537245512,
-0.009466257877647877,
0.05135171487927437,
0.052941642701625824,
0.00885060429573059,
0.033552385866642,
-0.022006461396813393,
-0.004317401442676783,
0.09791978448629379,
-0.053302764892578125,
-0.04187988117337227,
-0.0957634299993515,
-0.038830049335956573,
-0.01831783354282379,
0.05309758707880974,
0.005834926851093769,
-0.01134283747524023,
-0.010365990921854973,
-0.09766799956560135,
-0.06784719228744507,
0.037644099444150925,
0.11343029886484146,
0.010946967639029026,
0.026883648708462715,
0.030557598918676376,
0.0102565111592412,
-0.06760908663272858,
-0.04561754688620567,
-0.01964733377099037,
-0.010099601000547409,
0.009507468901574612,
0.01818137615919113,
0.03321082517504692,
-0.1479390412569046,
-0.09821753948926926,
0.03322283551096916,
0.04332206770777702,
-0.011309214867651463,
0.05788753554224968,
0.03500768914818764,
-0.004523429553955793,
-0.06175851449370384,
0.010239815339446068,
-0.06560458242893219,
0.06268548220396042,
0.09440156072378159,
0.05932063236832619,
0.0395440012216568,
-0.016177553683519363,
0.008531926199793816,
-0.036206476390361786,
-0.03699590265750885,
-0.00790733378380537,
0.07904643565416336,
-0.05884132906794548,
0.0015404740115627646,
0.025778507813811302,
-0.0318116769194603,
-0.03441215306520462,
-0.010227303020656109,
-0.09426004439592361,
0.023155950009822845,
-0.009839499369263649,
-0.10056900978088379,
0.018932705745100975,
-0.05674704164266586,
-0.002938490128144622,
-0.05829351767897606,
0.03406277298927307,
0.04326457902789116,
-0.05777155980467796,
0.0921580120921135,
-0.051190927624702454,
-0.03294873610138893,
-0.02245800755918026,
-0.0748351514339447,
0.050356823951005936,
-0.03651652857661247,
-0.11031997948884964,
-0.056651655584573746,
0.005124094430357218,
-0.07807754725217819,
0.015860540792346,
-5.5008452008179e-33,
0.046076174825429916,
0.1161314994096756,
-0.039743050932884216,
0.13250529766082764,
-0.040290698409080505,
-0.07773346453905106,
0.003249770263209939,
0.055238839238882065,
-0.07789880782365799,
-0.07517627626657486,
-0.04327215254306793,
-0.024017971009016037,
0.04883813112974167,
-0.02885783091187477,
0.0012965135974809527,
-0.04404233768582344,
-0.12779191136360168,
-0.10709837079048157,
-0.005425760056823492,
-0.006354357115924358,
0.02553712949156761,
0.04964406415820122,
-0.012156019918620586,
0.040189892053604126,
-0.050093360245227814,
0.030665962025523186,
-0.005520842969417572,
0.007010316476225853,
0.04989291727542877,
-0.0062800003215670586,
0.054918356239795685,
0.05567510798573494,
-0.09611742943525314,
0.06331191956996918,
0.013261411339044571,
-0.030749481171369553,
0.10728886723518372,
0.0026062324177473783,
-0.005822848528623581,
-0.01327931135892868,
0.10726304352283478,
0.08509957045316696,
-0.0430542454123497,
-0.015121475793421268,
0.007770238444209099,
0.029703861102461815,
0.04654901102185249,
-0.027631299570202827,
0.08799122273921967,
0.013446180149912834,
0.08079233765602112,
-0.08936924487352371,
-0.01256830058991909,
0.11309947073459625,
-0.01464125420898199,
-0.04622752591967583,
-0.020411284640431404,
-0.0134586775675416,
-0.06657493114471436,
0.04565862938761711,
-0.06956399977207184,
-0.026422306895256042,
-0.021459288895130157,
0.013431115075945854,
-0.007363405078649521,
-0.025001469999551773,
-0.08022751659154892,
0.06225210800766945,
0.0269386637955904,
-0.02274324744939804,
0.03341640159487724,
0.018238810822367668,
-0.08621448278427124,
-0.03755158185958862,
0.04685332998633385,
0.05705545097589493,
-0.04187159240245819,
-0.03733041137456894,
0.02186664752662182,
0.0867774486541748,
0.029815364629030228,
-0.04145607724785805,
0.00696604885160923,
0.06020527333021164,
-0.010048948228359222,
0.02086237445473671,
0.012355644255876541,
0.08337646722793579,
-0.04561314731836319,
0.04508749395608902,
-0.012681780382990837,
-0.04791766032576561,
-0.0782218798995018,
-0.015315779484808445,
0.006982822436839342,
-5.508819356236927e-8,
-0.0541706308722496,
0.004960644990205765,
-0.027684152126312256,
-0.014548584818840027,
-0.015155094675719738,
-0.0633983388543129,
-0.06443233788013458,
-0.011552967131137848,
0.04599364846944809,
-0.051753733307123184,
-0.03301229700446129,
-0.021151309832930565,
-0.07531589269638062,
-0.03418445587158203,
-0.023140672594308853,
-0.02536500059068203,
-0.02681577578186989,
0.0069443900138139725,
-0.02111365832388401,
0.010209795087575912,
0.016138831153512,
-0.026641901582479477,
-0.02608909271657467,
0.005190405994653702,
0.00174013152718544,
-0.027286117896437645,
0.02336939424276352,
0.0196145698428154,
-0.07463067024946213,
0.05133747309446335,
0.04576389491558075,
-0.027864757925271988,
0.0654052272439003,
-0.030589716508984566,
-0.005763568915426731,
0.11693371087312698,
-0.025680039077997208,
0.04681125655770302,
0.03325096517801285,
0.0263201966881752,
-0.05873613432049751,
0.06547843664884567,
-0.10638777911663055,
-0.010792016983032227,
0.016093125566840172,
-0.10854453593492508,
-0.004256627522408962,
0.004607020877301693,
-0.02224542200565338,
-0.02191280573606491,
-0.05724333971738815,
0.020364785566926003,
-0.026357850059866905,
0.04644450545310974,
-0.07657232135534286,
0.012317865155637264,
-0.023563789203763008,
-0.02761201187968254,
-0.02287883684039116,
0.011924965307116508,
0.12438137829303741,
-0.034898191690444946,
0.0713837742805481,
-0.03435295820236206
] | 0.078376 |
value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the [`AssertionError`][]. ## `assert.deepStrictEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} Tests for deep equality between the `actual` and `expected` parameters. "Deep" equality means that the enumerable "own" properties of child objects are recursively evaluated also by the following rules. ### Comparison details \* Primitive values are compared using [`Object.is()`][]. \* [Type tags][Object.prototype.toString()] of objects should be the same. \* [`[[Prototype]]`][prototype-spec] of objects are compared using the [`===` operator][]. \* Only [enumerable "own" properties][] are considered. \* {Error} names, messages, causes, and errors are always compared, even if these are not enumerable properties. `errors` is also compared. \* Enumerable own {Symbol} properties are compared as well. \* [Object wrappers][] are compared both as objects and unwrapped values. \* `Object` properties are compared unordered. \* {Map} keys and {Set} items are compared unordered. \* Recursion stops when both sides differ or either side encounters a circular reference. \* {WeakMap}, {WeakSet} and {Promise} instances are \*\*not\*\* compared structurally. They are only equal if they reference the same object. Any comparison between different `WeakMap`, `WeakSet`, or `Promise` instances will result in inequality, even if they contain the same content. \* {RegExp} lastIndex, flags, and source are always compared, even if these are not enumerable properties. ```mjs import assert from 'node:assert/strict'; // This fails because 1 !== '1'. assert.deepStrictEqual({ a: 1 }, { a: '1' }); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected // // { // + a: 1 // - a: '1' // } // The following objects don't have own properties const date = new Date(); const object = {}; const fakeDate = {}; Object.setPrototypeOf(fakeDate, Date.prototype); // Different [[Prototype]]: assert.deepStrictEqual(object, fakeDate); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected // // + {} // - Date {} // Different type tags: assert.deepStrictEqual(date, fakeDate); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected // // + 2018-04-26T00:49:08.604Z // - Date {} assert.deepStrictEqual(NaN, NaN); // OK because Object.is(NaN, NaN) is true. // Different unwrapped numbers: assert.deepStrictEqual(new Number(1), new Number(2)); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected // // + [Number: 1] // - [Number: 2] assert.deepStrictEqual(new String('foo'), Object('foo')); // OK because the object and the string are identical when unwrapped. assert.deepStrictEqual(-0, -0); // OK // Different zeros: assert.deepStrictEqual(0, -0); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected // // + 0 // - -0 const symbol1 = Symbol(); const symbol2 = Symbol(); assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol1]: 1 }); // OK, because it is the same symbol on both objects. assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol2]: 1 }); // AssertionError [ERR\_ASSERTION]: Inputs identical but not reference equal: // // { // Symbol(): 1 // } const weakMap1 = new WeakMap(); const weakMap2 = new WeakMap(); const obj = {}; weakMap1.set(obj, 'value'); weakMap2.set(obj, 'value'); // Comparing different instances fails, even with same contents assert.deepStrictEqual(weakMap1, weakMap2); // AssertionError: Values have same structure but are not reference-equal: // // WeakMap { // // } // Comparing the same instance to itself succeeds assert.deepStrictEqual(weakMap1, weakMap1); // OK const weakSet1 = new WeakSet(); const weakSet2 = new WeakSet(); weakSet1.add(obj); weakSet2.add(obj); // Comparing different instances fails, even with same contents assert.deepStrictEqual(weakSet1, weakSet2); // AssertionError: Values have same structure but are not reference-equal: // + actual - expected // // WeakSet { // // } // | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.0802910327911377,
0.018312551081180573,
0.0762878805398941,
0.045835014432668686,
-0.006460023112595081,
-0.08513257652521133,
0.008560416288673878,
0.040033116936683655,
-0.023389484733343124,
-0.03875456005334854,
-0.043094452470541,
-0.06580781191587448,
0.013443365693092346,
0.04854648560285568,
0.033795975148677826,
0.04624507576227188,
0.0822075828909874,
-0.013905471190810204,
-0.0888444259762764,
-0.010203300975263119,
0.0358162447810173,
0.016502143815159798,
0.003403400769457221,
0.02648225612938404,
-0.04171869531273842,
0.04812962934374809,
-0.05048647150397301,
-0.05441069230437279,
0.018738724291324615,
-0.01366669125854969,
0.004478697665035725,
0.01060375478118658,
-0.012897460721433163,
0.09547581523656845,
0.04857061430811882,
0.07525357604026794,
0.006695310585200787,
-0.078290656208992,
0.029315222054719925,
0.02897174470126629,
-0.005665512755513191,
0.04719816520810127,
-0.060717735439538956,
-0.028956200927495956,
0.0391995944082737,
0.05238146707415581,
-0.024314550682902336,
-0.0065359435975551605,
-0.051926422864198685,
-0.04315166920423508,
0.00022605029516853392,
0.041229575872421265,
-0.0025173164904117584,
0.04402537643909454,
0.06046007201075554,
0.01196331437677145,
-0.02655787393450737,
-0.014470566064119339,
0.04400491714477539,
0.008455694653093815,
0.04160351678729057,
-0.04984396696090698,
0.02815886400640011,
-0.025026828050613403,
0.042831894010305405,
-0.06868068873882294,
0.0293519776314497,
0.007491235621273518,
-0.014358986169099808,
0.0928480252623558,
0.003425246337428689,
0.08946067839860916,
-0.01611228659749031,
0.10225169360637665,
0.022639475762844086,
0.03490366041660309,
0.08266407251358032,
-0.04843515530228615,
-0.04665271192789078,
-0.05432256683707237,
-0.05932129546999931,
-0.05375479906797409,
-0.04965364560484886,
-0.02618194930255413,
0.08248911052942276,
0.004015053156763315,
0.011970213614404202,
0.022137470543384552,
-0.008523962460458279,
0.08243008702993393,
-0.015063893981277943,
-0.14722850918769836,
-0.033408310264348984,
0.15407942235469818,
0.06356069445610046,
-0.04331740364432335,
-0.0372590646147728,
-0.07808736711740494,
-0.06314130872488022,
0.02768527902662754,
-0.004654828459024429,
0.0008451294852420688,
0.11593405902385712,
-0.1052502915263176,
0.03135775774717331,
0.006215421482920647,
-0.0006886936025694013,
-0.12861689925193787,
-0.03139154240489006,
-0.00046323915012180805,
-0.013689032755792141,
-0.01800006628036499,
0.06081046909093857,
0.06886322796344757,
0.00018867308972403407,
-0.05779502913355827,
0.0037147437687963247,
-0.016114912927150726,
0.0033681944478303194,
0.009054586291313171,
0.0374331995844841,
-0.009070489555597305,
0.0665401965379715,
0.019719073548913002,
0.04415719956159592,
0.006608973722904921,
-0.07657694071531296,
2.844600636402939e-33,
0.004495471715927124,
0.020236430689692497,
0.0073750377632677555,
0.10621996223926544,
0.014959599822759628,
0.0730111300945282,
-0.00612327316775918,
-0.005258441902697086,
-0.06288352608680725,
0.02730206586420536,
-0.058083705604076385,
0.09772208333015442,
-0.027137812227010727,
-0.012425336986780167,
0.04612772911787033,
0.061701852828264236,
0.00016672290803398937,
0.01787446066737175,
-0.003737145569175482,
-0.016416452825069427,
-0.00789722427725792,
-0.011558124795556068,
-0.071165069937706,
-0.030640913173556328,
0.00971292331814766,
-0.032654061913490295,
0.02157043106853962,
-0.015021107159554958,
-0.05082514137029648,
-0.01606673002243042,
-0.09771104156970978,
-0.01014457456767559,
0.10189007967710495,
0.12027299404144287,
0.02905844710767269,
-0.024315746501088142,
0.09177258610725403,
-0.01899268478155136,
-0.054089054465293884,
-0.08507942408323288,
-0.054956257343292236,
-0.04260929673910141,
-0.03852738440036774,
-0.02846730500459671,
-0.006477721966803074,
-0.16087393462657928,
-0.07055928558111191,
0.002113014692440629,
0.11640089005231857,
-0.015738824382424355,
-0.00011366188118699938,
0.02437916025519371,
0.02522478811442852,
-0.05628794804215431,
0.06659725308418274,
-0.030684372410178185,
0.03334224596619606,
0.0788273885846138,
0.018148448318243027,
0.018804440274834633,
0.0021317622158676386,
-0.0036625994835048914,
-0.032282814383506775,
-0.05899427831172943,
0.0007150245946832001,
0.03761066123843193,
0.0020983912982046604,
0.013412381522357464,
0.012450260110199451,
-0.052396632730960846,
-0.02498091571033001,
-0.013193191029131413,
-0.09791688621044159,
0.03787080943584442,
-0.02204815484583378,
-0.07289765030145645,
0.012624925002455711,
0.0073556844145059586,
0.03637039288878441,
-0.03157952427864075,
-0.04416168853640556,
0.04488755017518997,
-0.01444882433861494,
0.09457040578126907,
-0.05656946077942848,
-0.028016116470098495,
-0.033583737909793854,
-0.042349472641944885,
0.009007647633552551,
0.03825709968805313,
-0.056485194712877274,
-0.03623192012310028,
-0.061087049543857574,
-0.01429139357060194,
-0.011804433539509773,
-5.109130442847589e-33,
-0.013648631051182747,
0.06312330812215805,
-0.06179501488804817,
0.11808139830827713,
-0.013176539912819862,
-0.053374335169792175,
0.0340484157204628,
0.01176217757165432,
-0.04829855263233185,
-0.0476221889257431,
-0.0223174337297678,
-0.01713412255048752,
-0.006742013152688742,
-0.03368682041764259,
0.02751927450299263,
-0.02635202556848526,
-0.1392863541841507,
-0.0867009237408638,
0.038441628217697144,
-0.05795589089393616,
0.10805615037679672,
0.05151937156915665,
-0.02353379875421524,
0.007879774086177349,
-0.09493742883205414,
0.007913405075669289,
0.010838404297828674,
0.015780044719576836,
0.04828307777643204,
-0.03983347862958908,
0.027984989807009697,
-0.025827357545495033,
-0.05552453547716141,
0.04694254696369171,
0.03740444779396057,
-0.09330061078071594,
0.09010453522205353,
0.020825233310461044,
0.003993789199739695,
0.013636212795972824,
0.048889875411987305,
0.06285414099693298,
-0.03690594807267189,
-0.01098324079066515,
-0.0507952980697155,
0.007271090988069773,
0.049921050667762756,
-0.047319747507572174,
0.10662741959095001,
-0.018011411651968956,
0.10762982070446014,
-0.07812956720590591,
-0.0011429678415879607,
0.10214931517839432,
-0.08981148153543472,
-0.0068491678684949875,
-0.037291061133146286,
-0.02949294075369835,
0.0232386514544487,
0.10375729948282242,
-0.04847511276602745,
-0.06422539055347443,
0.0066476077772676945,
0.015777787193655968,
-0.07505404949188232,
0.01153428666293621,
-0.10177969932556152,
0.049926843494176865,
0.035506781190633774,
-0.02613014541566372,
0.008669178932905197,
-0.06558498740196228,
-0.03465871512889862,
-0.05020095035433769,
0.038172319531440735,
-0.02537873573601246,
0.011015196330845356,
-0.031857214868068695,
0.07457345724105835,
-0.01939963735640049,
0.02762703225016594,
0.012334938161075115,
0.0031811532098799944,
0.0937153622508049,
-0.011994993314146996,
0.007996750064194202,
0.025903932750225067,
0.07561326026916504,
-0.074167899787426,
0.05688118934631348,
0.03770139068365097,
0.018451310694217682,
-0.029250217601656914,
0.020897937938570976,
0.006727752275764942,
-5.439045125399389e-8,
-0.09850820899009705,
-0.027391590178012848,
-0.032921455800533295,
-0.05765985697507858,
0.01124620158225298,
-0.0700826644897461,
-0.005626216065138578,
-0.03387542814016342,
0.012723715975880623,
0.003056923858821392,
-0.008677305653691292,
0.05113035440444946,
-0.00864216685295105,
-0.04265667870640755,
-0.014007861725986004,
-0.03408157825469971,
-0.05939636006951332,
-0.021275654435157776,
0.003611813299357891,
0.08756914734840393,
0.10576599091291428,
0.0185692198574543,
-0.0008788107661530375,
0.012989516369998455,
0.001715955208055675,
-0.04290030151605606,
0.02589981071650982,
0.034002840518951416,
-0.11374813318252563,
0.07872606813907623,
0.0004656215896829963,
0.022244371473789215,
0.024951206520199776,
-0.03496331721544266,
-0.003972241189330816,
0.09765592962503433,
-0.03700796142220497,
-0.016942879185080528,
-0.03377033770084381,
0.05027307569980621,
0.04739459976553917,
0.020386025309562683,
-0.09159792959690094,
0.007597221527248621,
0.023411598056554794,
-0.09756868332624435,
-0.04367685317993164,
-0.024349691346287727,
-0.02069884166121483,
-0.010563166812062263,
-0.02597040683031082,
0.06577742099761963,
-0.056846458464860916,
-0.007478214334696531,
-0.08194025605916977,
0.03147350996732712,
-0.020354358479380608,
-0.008334866724908352,
-0.014486129395663738,
0.03446881100535393,
0.15435944497585297,
0.03891157731413841,
0.05407780036330223,
-0.012429573573172092
] | 0.092701 |
assert.deepStrictEqual(weakMap1, weakMap1); // OK const weakSet1 = new WeakSet(); const weakSet2 = new WeakSet(); weakSet1.add(obj); weakSet2.add(obj); // Comparing different instances fails, even with same contents assert.deepStrictEqual(weakSet1, weakSet2); // AssertionError: Values have same structure but are not reference-equal: // + actual - expected // // WeakSet { // // } // Comparing the same instance to itself succeeds assert.deepStrictEqual(weakSet1, weakSet1); // OK ``` ```cjs const assert = require('node:assert/strict'); // This fails because 1 !== '1'. assert.deepStrictEqual({ a: 1 }, { a: '1' }); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected // // { // + a: 1 // - a: '1' // } // The following objects don't have own properties const date = new Date(); const object = {}; const fakeDate = {}; Object.setPrototypeOf(fakeDate, Date.prototype); // Different [[Prototype]]: assert.deepStrictEqual(object, fakeDate); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected // // + {} // - Date {} // Different type tags: assert.deepStrictEqual(date, fakeDate); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected // // + 2018-04-26T00:49:08.604Z // - Date {} assert.deepStrictEqual(NaN, NaN); // OK because Object.is(NaN, NaN) is true. // Different unwrapped numbers: assert.deepStrictEqual(new Number(1), new Number(2)); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected // // + [Number: 1] // - [Number: 2] assert.deepStrictEqual(new String('foo'), Object('foo')); // OK because the object and the string are identical when unwrapped. assert.deepStrictEqual(-0, -0); // OK // Different zeros: assert.deepStrictEqual(0, -0); // AssertionError: Expected inputs to be strictly deep-equal: // + actual - expected // // + 0 // - -0 const symbol1 = Symbol(); const symbol2 = Symbol(); assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol1]: 1 }); // OK, because it is the same symbol on both objects. assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol2]: 1 }); // AssertionError [ERR\_ASSERTION]: Inputs identical but not reference equal: // // { // Symbol(): 1 // } const weakMap1 = new WeakMap(); const weakMap2 = new WeakMap(); const obj = {}; weakMap1.set(obj, 'value'); weakMap2.set(obj, 'value'); // Comparing different instances fails, even with same contents assert.deepStrictEqual(weakMap1, weakMap2); // AssertionError: Values have same structure but are not reference-equal: // // WeakMap { // // } // Comparing the same instance to itself succeeds assert.deepStrictEqual(weakMap1, weakMap1); // OK const weakSet1 = new WeakSet(); const weakSet2 = new WeakSet(); weakSet1.add(obj); weakSet2.add(obj); // Comparing different instances fails, even with same contents assert.deepStrictEqual(weakSet1, weakSet2); // AssertionError: Values have same structure but are not reference-equal: // + actual - expected // // WeakSet { // // } // Comparing the same instance to itself succeeds assert.deepStrictEqual(weakSet1, weakSet1); // OK ``` If the values are not equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the `AssertionError`. ## `assert.doesNotMatch(string, regexp[, message])` \* `string` {string} \* `regexp` {RegExp} \* `message` {string|Error|Function} Expects the `string` input not to match the regular expression. ```mjs import assert from 'node:assert/strict'; assert.doesNotMatch('I will fail', /fail/); // AssertionError [ERR\_ASSERTION]: The input was expected to not match the ... assert.doesNotMatch(123, /pass/); // AssertionError [ERR\_ASSERTION]: The "string" argument must be of type string. assert.doesNotMatch('I will pass', /different/); // OK ``` ```cjs const assert = require('node:assert/strict'); assert.doesNotMatch('I will fail', /fail/); // AssertionError [ERR\_ASSERTION]: The input was expected to not match the ... assert.doesNotMatch(123, /pass/); // AssertionError [ERR\_ASSERTION]: The "string" argument must be of type string. assert.doesNotMatch('I will pass', /different/); // OK ``` If the values do match, or if | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.06996538490056992,
-0.02246650867164135,
0.07521893084049225,
0.0011178934946656227,
0.007331791799515486,
-0.057659812271595,
-0.05199552699923515,
0.0015417553950101137,
-0.025746550410985947,
-0.10711409896612167,
-0.05175625905394554,
-0.0851336419582367,
0.033442575484514236,
-0.014902301132678986,
0.05242876335978508,
0.020665042102336884,
0.023317599669098854,
0.054733723402023315,
-0.07291579246520996,
0.010961916297674179,
-0.007158226799219847,
-0.052510686218738556,
-0.04016615450382233,
0.0004131208988837898,
-0.03118239715695381,
0.009433433413505554,
-0.0525212399661541,
0.004991037305444479,
0.08635229617357254,
-0.0567626990377903,
0.02563348598778248,
-0.0020782328210771084,
-0.03861788287758827,
0.10251453518867493,
-0.010977725498378277,
0.11255979537963867,
-0.06767231225967407,
-0.07553193718194962,
0.017095079645514488,
0.027397915720939636,
-0.003959689289331436,
0.1674976795911789,
0.03232196718454361,
-0.03317594155669212,
-0.0023954398930072784,
0.0764445960521698,
-0.01659237965941429,
0.05895378813147545,
-0.029905634000897408,
-0.010733154602348804,
-0.02934424765408039,
0.029150357469916344,
0.00020143497386015952,
-0.028154967352747917,
0.02013235352933407,
0.04725240543484688,
0.003917205613106489,
0.048830486834049225,
0.004047952592372894,
0.009574751369655132,
0.010598584078252316,
-0.04491658881306648,
0.08697355538606644,
-0.05419284850358963,
0.09567747265100479,
-0.042594678699970245,
0.0030360245145857334,
0.06007137522101402,
-0.010473114438354969,
0.07735633105039597,
0.012517055496573448,
0.075467549264431,
0.04631767049431801,
0.04939252883195877,
-0.05664284527301788,
0.0451669842004776,
-0.00804061908274889,
-0.010003246366977692,
-0.023776790127158165,
-0.00031439794111065567,
-0.04454900324344635,
-0.058848313987255096,
-0.05546201765537262,
-0.07565509527921677,
0.05987909063696861,
-0.019505154341459274,
0.01073590386658907,
-0.052482254803180695,
-0.055297914892435074,
0.03497355058789253,
0.031007733196020126,
-0.04568639397621155,
-0.007270915899425745,
0.10994597524404526,
0.13307638466358185,
-0.044838182628154755,
0.05623888596892357,
0.04765816032886505,
-0.008832871913909912,
0.04353918507695198,
-0.005163807421922684,
0.0659160166978836,
0.09271357953548431,
-0.01769280433654785,
0.044309522956609726,
-0.007953695952892303,
-0.0018449801718816161,
-0.13652727007865906,
-0.03027844801545143,
-0.03785581886768341,
0.04903256893157959,
-0.0073427301831543446,
0.08149121701717377,
0.018373241648077965,
-0.02047530561685562,
-0.021853510290384293,
0.04694562405347824,
-0.03139416128396988,
-0.017934979870915413,
0.04645002260804176,
-0.03943195939064026,
-0.03299049660563469,
0.057069938629865646,
-0.017883960157632828,
-0.002338236663490534,
-0.00041642304859124124,
-0.013232732191681862,
8.329409706552723e-34,
0.04739230498671532,
-0.0733848363161087,
-0.03458649292588234,
0.016636503860354424,
-0.0040978011675179005,
0.009495162405073643,
-0.05625433847308159,
0.04717967286705971,
-0.15519355237483978,
0.017894823104143143,
-0.06750137358903885,
0.07518619298934937,
-0.03573159500956535,
0.021045580506324768,
0.01870962791144848,
0.009369183331727982,
0.04592293128371239,
-0.03175019845366478,
-0.009016579017043114,
-0.036990564316511154,
0.017438681796193123,
0.00012857664842158556,
-0.054857537150382996,
-0.07756543159484863,
-0.013295612297952175,
-0.0785636454820633,
0.04460037499666214,
0.057446155697107315,
-0.06805771589279175,
-0.04404371604323387,
-0.03282932937145233,
-0.00599321024492383,
0.030450057238340378,
0.17354674637317657,
0.01118536852300167,
-0.02634020335972309,
0.06126319244503975,
0.013769163750112057,
-0.06399956345558167,
-0.1499486118555069,
0.0025823023170232773,
0.013579622842371464,
0.016544587910175323,
-0.02725500985980034,
0.08498518913984299,
-0.10735144466161728,
-0.08837372809648514,
-0.04244687408208847,
0.03776504471898079,
-0.01004788652062416,
0.014934379607439041,
0.025193041190505028,
-0.02726917527616024,
-0.06857888400554657,
0.005903186276555061,
-0.01014584768563509,
0.05301383137702942,
0.0675148293375969,
0.07579459995031357,
0.08619045466184616,
-0.02594185620546341,
0.06838124990463257,
-0.08941609412431717,
0.052722539752721786,
-0.04730634763836861,
0.08953708410263062,
-0.05397554486989975,
-0.04107431322336197,
0.03661593049764633,
0.010668927803635597,
0.021862925961613655,
-0.030586084350943565,
-0.1170073002576828,
-0.008328288793563843,
0.00986624974757433,
-0.007759669329971075,
-0.03167400136590004,
-0.018806619569659233,
-0.014362718909978867,
-0.03793346881866455,
-0.015293790027499199,
0.07985267788171768,
0.0028770503122359514,
0.06729321926832199,
-0.10793739557266235,
0.0747741088271141,
-0.023920785635709763,
-0.06652037799358368,
0.09304258972406387,
0.028518300503492355,
0.012022685259580612,
-0.0013390571111813188,
-0.049916595220565796,
-0.04262636974453926,
0.04317253828048706,
-1.928363768706415e-33,
-0.03092428296804428,
0.09055425971746445,
-0.03200642764568329,
0.15007534623146057,
0.01962057687342167,
-0.02119867131114006,
0.011018618009984493,
-0.06000450998544693,
-0.026931937783956528,
0.040508974343538284,
0.050559140741825104,
0.0025142801459878683,
0.013061858713626862,
-0.007608936168253422,
0.04222508519887924,
-0.05616135522723198,
-0.04192609712481499,
0.012605241499841213,
0.013903031125664711,
0.021800465881824493,
0.08217637240886688,
0.04386204481124878,
-0.0010954475728794932,
0.018272314220666885,
-0.006044158712029457,
0.024943923577666283,
-0.021634455770254135,
0.03204876556992531,
0.01372998021543026,
-0.07501552253961563,
-0.05687568336725235,
-0.0012661374639719725,
-0.07506881654262543,
0.033046070486307144,
0.019231041893363,
-0.09486862272024155,
0.009064613841474056,
0.04993268847465515,
-0.0282864049077034,
-0.020845063030719757,
-0.012749421410262585,
0.05473370850086212,
-0.04896760359406471,
0.02565416321158409,
-0.033736344426870346,
0.011252133175730705,
0.04957353323698044,
-0.028121832758188248,
0.07979056239128113,
-0.0527171790599823,
0.01308512408286333,
-0.09057902544736862,
-0.02465800754725933,
0.10964789241552353,
0.0003615549358073622,
-0.08518783003091812,
-0.006548094097524881,
0.038845524191856384,
0.07014364004135132,
0.04990997910499573,
-0.034041497856378555,
-0.07253414392471313,
-0.02496781386435032,
0.08456459641456604,
0.030804703012108803,
-0.02758210338652134,
-0.11790624260902405,
0.0064188637770712376,
0.08853286504745483,
0.05011821910738945,
0.012228816747665405,
0.0559847354888916,
0.027374090626835823,
-0.05313486233353615,
0.004334832075983286,
0.016753003001213074,
-0.01086637657135725,
-0.053580351173877716,
0.033049263060092926,
-0.007559450808912516,
0.012876736000180244,
0.02564861811697483,
-0.02032666839659214,
0.055841755121946335,
-0.006731696426868439,
0.1137174740433693,
0.024769360199570656,
0.025694074109196663,
-0.04353644326329231,
0.11788584291934967,
-0.0017659092554822564,
0.03469549119472504,
-0.10203780233860016,
-0.07707337290048599,
-0.010769953019917011,
-4.6739422998598457e-8,
-0.02551337145268917,
0.002693394897505641,
-0.05937085300683975,
0.0005549737834371626,
0.022072013467550278,
-0.12261476367712021,
-0.0017726904479786754,
-0.013272316195070744,
0.013482010923326015,
0.039212703704833984,
-0.0386291965842247,
0.020629264414310455,
-0.02631237357854843,
-0.08215190470218658,
-0.024308478459715843,
-0.007124862167984247,
-0.06651788204908371,
-0.04835284501314163,
0.025160811841487885,
0.0608895942568779,
-0.0015279978979378939,
-0.011794856749475002,
0.030978960916399956,
0.10845816135406494,
0.04120313376188278,
-0.06257184594869614,
0.002723979065194726,
-0.004177717957645655,
0.009658707305788994,
0.019442524760961533,
-0.013725015334784985,
0.050436314195394516,
0.033881302922964096,
-0.06812341511249542,
-0.016522159799933434,
0.04298072308301926,
-0.04111772030591965,
0.05971734598278999,
-0.04185666888952255,
0.025108451023697853,
-0.011277822777628899,
-0.006087183486670256,
-0.05570760741829872,
-0.01689770817756653,
0.002555408515036106,
-0.04605602100491524,
0.011646986939013004,
-0.015627548098564148,
0.008434169925749302,
-0.09205295890569687,
0.021279390901327133,
0.014899090863764286,
0.008088774979114532,
0.012676394544541836,
-0.05415676161646843,
-0.03466888144612312,
-0.034353259950876236,
0.003846232546493411,
-0.015682019293308258,
-0.007174700498580933,
0.09413705766201019,
-0.019137989729642868,
0.027763955295085907,
-0.012817634269595146
] | 0.020793 |
OK ``` ```cjs const assert = require('node:assert/strict'); assert.doesNotMatch('I will fail', /fail/); // AssertionError [ERR\_ASSERTION]: The input was expected to not match the ... assert.doesNotMatch(123, /pass/); // AssertionError [ERR\_ASSERTION]: The "string" argument must be of type string. assert.doesNotMatch('I will pass', /different/); // OK ``` If the values do match, or if the `string` argument is of another type than `string`, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the [`AssertionError`][]. ## `assert.doesNotReject(asyncFn[, error][, message])` \* `asyncFn` {Function|Promise} \* `error` {RegExp|Function} \* `message` {string} \* Returns: {Promise} Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is not rejected. If `asyncFn` is a function and it throws an error synchronously, `assert.doesNotReject()` will return a rejected `Promise` with that error. If the function does not return a promise, `assert.doesNotReject()` will return a rejected `Promise` with an [`ERR\_INVALID\_RETURN\_VALUE`][] error. In both cases the error handler is skipped. Using `assert.doesNotReject()` is actually not useful because there is little benefit in catching a rejection and then rejecting it again. Instead, consider adding a comment next to the specific code path that should not reject and keep error messages as expressive as possible. If specified, `error` can be a [`Class`][], {RegExp} or a validation function. See [`assert.throws()`][] for more details. Besides the async nature to await the completion behaves identically to [`assert.doesNotThrow()`][]. ```mjs import assert from 'node:assert/strict'; await assert.doesNotReject( async () => { throw new TypeError('Wrong value'); }, SyntaxError, ); ``` ```cjs const assert = require('node:assert/strict'); (async () => { await assert.doesNotReject( async () => { throw new TypeError('Wrong value'); }, SyntaxError, ); })(); ``` ```mjs import assert from 'node:assert/strict'; assert.doesNotReject(Promise.reject(new TypeError('Wrong value'))) .then(() => { // ... }); ``` ```cjs const assert = require('node:assert/strict'); assert.doesNotReject(Promise.reject(new TypeError('Wrong value'))) .then(() => { // ... }); ``` ## `assert.doesNotThrow(fn[, error][, message])` \* `fn` {Function} \* `error` {RegExp|Function} \* `message` {string} Asserts that the function `fn` does not throw an error. Using `assert.doesNotThrow()` is actually not useful because there is no benefit in catching an error and then rethrowing it. Instead, consider adding a comment next to the specific code path that should not throw and keep error messages as expressive as possible. When `assert.doesNotThrow()` is called, it will immediately call the `fn` function. If an error is thrown and it is the same type as that specified by the `error` parameter, then an [`AssertionError`][] is thrown. If the error is of a different type, or if the `error` parameter is undefined, the error is propagated back to the caller. If specified, `error` can be a [`Class`][], {RegExp}, or a validation function. See [`assert.throws()`][] for more details. The following, for instance, will throw the {TypeError} because there is no matching error type in the assertion: ```mjs import assert from 'node:assert/strict'; assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, SyntaxError, ); ``` ```cjs const assert = require('node:assert/strict'); assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, SyntaxError, ); ``` However, the following will result in an [`AssertionError`][] with the message 'Got unwanted exception...': ```mjs import assert from 'node:assert/strict'; assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, TypeError, ); ``` ```cjs const assert = require('node:assert/strict'); assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, TypeError, ); ``` If an [`AssertionError`][] is thrown and a value is provided for the `message` parameter, the value of | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.09647823125123978,
0.055753473192453384,
0.03020447865128517,
0.0683225616812706,
0.012414385564625263,
-0.0173322893679142,
0.032196756452322006,
0.012431410141289234,
-0.012635407969355583,
-0.08159345388412476,
-0.047563280910253525,
-0.06049487367272377,
0.024688344448804855,
0.06416536867618561,
0.029435021802783012,
0.014405780471861362,
-0.014045102521777153,
-0.00030114021501503885,
0.0339810848236084,
-0.04004010930657387,
-0.01590261422097683,
-0.03547609969973564,
-0.02185344137251377,
0.006482407916337252,
-0.03928247466683388,
-0.035251617431640625,
-0.017196418717503548,
-0.06477925181388855,
0.0013957822229713202,
0.002545613329857588,
0.011461399495601654,
-0.01977422460913658,
-0.07391111552715302,
0.1062544584274292,
0.013003041967749596,
0.068031907081604,
-0.06422384083271027,
-0.07200143486261368,
0.015292705036699772,
0.00805170089006424,
-0.006812657229602337,
0.07786217331886292,
-0.03467423468828201,
-0.03709564357995987,
0.0735618844628334,
-0.028755290433764458,
-0.05066806077957153,
0.052877277135849,
-0.0872742310166359,
-0.007094568572938442,
-0.0009041732992045581,
0.014894882217049599,
-0.04335211217403412,
-0.03438543900847435,
-0.0010387626243755221,
0.010848983190953732,
0.0022547885309904814,
0.05028538778424263,
0.10021935403347015,
0.05145620182156563,
0.05402607470750809,
-0.052329085767269135,
0.05568952485918999,
0.012819278985261917,
0.0469343401491642,
-0.02334200218319893,
-0.007360538467764854,
0.02472652681171894,
0.012941441498696804,
0.052989739924669266,
-0.03411043807864189,
0.0728156566619873,
-0.008255434222519398,
0.11084560304880142,
-0.02468104101717472,
-0.02245911955833435,
-0.043541502207517624,
-0.007491465657949448,
-0.0012453206581994891,
0.04007837176322937,
-0.1118486151099205,
-0.09382841736078262,
-0.038347966969013214,
-0.007471564691513777,
0.032232049852609634,
0.06652829796075821,
-0.06752631068229675,
0.042624108493328094,
-0.00919265951961279,
0.011805194430053234,
0.0006410228670574725,
-0.11945933848619461,
-0.059359561651945114,
0.1175159364938736,
0.11318764835596085,
0.03184215724468231,
-0.03719024732708931,
0.0025088468100875616,
0.029187671840190887,
0.019908366724848747,
-0.006090465001761913,
0.011086484417319298,
0.063186876475811,
-0.06302450597286224,
0.03756855055689812,
0.00118594232480973,
0.0039541455917060375,
-0.1778840273618698,
-0.035504698753356934,
-0.006922070402652025,
0.010791277512907982,
-0.012463968247175217,
0.05292078107595444,
0.060084860771894455,
0.0033992722164839506,
0.006074013188481331,
0.09195017069578171,
-0.018260210752487183,
0.013265266083180904,
0.08074922859668732,
0.03430613875389099,
-0.02453257329761982,
0.038053352385759354,
-0.013077552430331707,
0.02450546622276306,
0.035896800458431244,
0.010459591634571552,
1.2656386044830332e-33,
0.017476212233304977,
0.020574966445565224,
-0.0315803699195385,
0.0663989707827568,
0.006171252578496933,
0.02257850393652916,
-0.02551824040710926,
0.014981688000261784,
-0.08605970442295074,
-0.039516665041446686,
-0.03130604699254036,
0.017251459881663322,
0.016659533604979515,
-0.0548129603266716,
0.04622235894203186,
0.01268287468701601,
0.07566424459218979,
-0.038874197751283646,
-0.010521288961172104,
-0.011149344965815544,
0.04061093553900719,
-0.01452814694494009,
-0.020635362714529037,
-0.03490058705210686,
-0.02404368296265602,
-0.10694177448749542,
0.0024150933604687452,
0.03915772959589958,
-0.017360277473926544,
-0.058107614517211914,
-0.022061092779040337,
-0.0278943981975317,
0.01953357458114624,
0.18932196497917175,
0.05958930402994156,
0.008188950829207897,
0.06551646441221237,
0.014682372100651264,
-0.09778984636068344,
-0.07924322038888931,
-0.06367450952529907,
-0.006251247599720955,
-0.030535899102687836,
0.0641711875796318,
0.05750846490263939,
-0.11949339509010315,
-0.024394027888774872,
-0.040197502821683884,
0.07250706106424332,
-0.01529696211218834,
-0.0068163624964654446,
0.06238364055752754,
0.06033254787325859,
-0.010326012969017029,
0.06704120337963104,
0.005706263240426779,
0.008333544246852398,
-0.021067703142762184,
0.00932080578058958,
0.05166786164045334,
0.04153808578848839,
-0.030920134857296944,
-0.06380841135978699,
-0.01864832080900669,
-0.032728664577007294,
0.03771980106830597,
-0.036827169358730316,
-0.055607348680496216,
-0.03418545797467232,
-0.02428852766752243,
0.029946861788630486,
-0.0331384502351284,
-0.1207268238067627,
0.044320810586214066,
0.017543766647577286,
-0.011709855869412422,
-0.08572301268577576,
0.07435093820095062,
-0.044521771371364594,
-0.09072807431221008,
-0.007124525029212236,
-0.03696763515472412,
-0.026402538642287254,
0.11883071064949036,
-0.03036198765039444,
0.030796874314546585,
-0.038631170988082886,
-0.04568268731236458,
0.08710635453462601,
-0.018862754106521606,
0.00042716696043498814,
-0.024129843339323997,
-0.07585109025239944,
-0.028294282034039497,
0.05005533620715141,
-2.8120025250157063e-33,
-0.03149273246526718,
0.08454802632331848,
-0.03557175397872925,
0.1195889562368393,
0.03482722118496895,
-0.035769227892160416,
0.07175715267658234,
0.0013910771813243628,
-0.002535860752686858,
-0.026843931525945663,
-0.04532429948449135,
0.0023174190428107977,
0.05598307028412819,
0.031064825132489204,
-0.03221490606665611,
-0.009352874010801315,
-0.10928250104188919,
-0.017747189849615097,
0.010412377305328846,
-0.006208153907209635,
0.037086471915245056,
0.0076732877641916275,
0.02172926627099514,
-0.01185116171836853,
-0.11161298304796219,
0.0899864137172699,
0.013714363798499107,
-0.052988603711128235,
0.010054178535938263,
0.00952549185603857,
-0.019533077254891396,
0.029764370992779732,
-0.01785779930651188,
0.01191054005175829,
0.05884956568479538,
-0.10790354758501053,
0.06954791396856308,
0.10033255815505981,
-0.01264290139079094,
-0.041054803878068924,
0.05406574904918671,
0.03870931640267372,
-0.03936213627457619,
0.0042154560796916485,
0.012434438802301884,
0.0017885175766423345,
0.049147829413414,
-0.017723504453897476,
0.04520565643906593,
-0.018664445728063583,
-0.010374491102993488,
-0.08557028323411942,
0.013457193039357662,
0.07892739027738571,
-0.051393140107393265,
0.0008211479871533811,
-0.05732445791363716,
0.017755551263689995,
0.002944197738543153,
0.05982334166765213,
-0.043995123356580734,
-0.045736368745565414,
0.033491261303424835,
0.04660707712173462,
-0.0020073249470442533,
-0.06540242582559586,
-0.0872245728969574,
0.005042470525950193,
0.09741831570863724,
0.018869999796152115,
-0.010895083658397198,
-0.00634149881079793,
-0.016820568591356277,
-0.020177215337753296,
0.028575796633958817,
-0.06239890307188034,
0.01038296241313219,
-0.05994143337011337,
0.07333309203386307,
0.09125183522701263,
0.04174642637372017,
0.04384979233145714,
0.02620597928762436,
0.0900234654545784,
0.00903048925101757,
0.06496661901473999,
-0.01696297898888588,
0.03424245864152908,
-0.06432131677865982,
0.07417842000722885,
0.05980955809354782,
0.054555926471948624,
-0.08551975339651108,
-0.04841602221131325,
0.006503772456198931,
-5.1634859943305855e-8,
-0.07085402309894562,
0.004018148873001337,
-0.04814985767006874,
-0.0669064000248909,
-0.03555706888437271,
-0.0488828606903553,
0.03508682921528816,
-0.15985265374183655,
0.03285453841090202,
0.02794698067009449,
-0.08340781927108765,
0.02534586191177368,
0.00876577291637659,
-0.0827910304069519,
-0.05281625688076019,
-0.03218855708837509,
-0.026548590511083603,
-0.006215446162968874,
0.003281098324805498,
0.025899456813931465,
0.05297185853123665,
-0.0266867745667696,
-0.050118397921323776,
0.0824035033583641,
0.03869282454252243,
-0.02643347904086113,
0.04527992382645607,
0.07353105396032333,
-0.07416702806949615,
0.028180977329611778,
-0.033700790256261826,
0.039660677313804626,
0.05601311847567558,
-0.07321164011955261,
-0.04853421822190285,
0.08060970157384872,
0.040827762335538864,
-0.041392773389816284,
0.04683174937963486,
0.02159201167523861,
0.0032183851581066847,
0.029595335945487022,
-0.02939298003911972,
-0.006953462027013302,
-0.03984391316771507,
-0.0902186930179596,
0.000029194090529927053,
-0.015414485707879066,
0.010538347065448761,
-0.0345718190073967,
0.03278205543756485,
-0.00730099668726325,
-0.07599513977766037,
0.04148455336689949,
-0.041424233466386795,
-0.03167131170630455,
-0.03795420750975609,
-0.006949823349714279,
-0.048704762011766434,
0.003953564912080765,
0.14506720006465912,
0.004322258289903402,
0.07537894695997238,
-0.0568508617579937
] | 0.076467 |
import assert from 'node:assert/strict'; assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, TypeError, ); ``` ```cjs const assert = require('node:assert/strict'); assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, TypeError, ); ``` If an [`AssertionError`][] is thrown and a value is provided for the `message` parameter, the value of `message` will be appended to the [`AssertionError`][] message: ```mjs import assert from 'node:assert/strict'; assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, /Wrong value/, 'Whoops', ); // Throws: AssertionError: Got unwanted exception: Whoops ``` ```cjs const assert = require('node:assert/strict'); assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, /Wrong value/, 'Whoops', ); // Throws: AssertionError: Got unwanted exception: Whoops ``` ## `assert.equal(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} \*\*Strict assertion mode\*\* An alias of [`assert.strictEqual()`][]. \*\*Legacy assertion mode\*\* > Stability: 3 - Legacy: Use [`assert.strictEqual()`][] instead. Tests shallow, coercive equality between the `actual` and `expected` parameters using the [`==` operator][]. `NaN` is specially handled and treated as being identical if both sides are `NaN`. ```mjs import assert from 'node:assert'; assert.equal(1, 1); // OK, 1 == 1 assert.equal(1, '1'); // OK, 1 == '1' assert.equal(NaN, NaN); // OK assert.equal(1, 2); // AssertionError: 1 == 2 assert.equal({ a: { b: 1 } }, { a: { b: 1 } }); // AssertionError: { a: { b: 1 } } == { a: { b: 1 } } ``` ```cjs const assert = require('node:assert'); assert.equal(1, 1); // OK, 1 == 1 assert.equal(1, '1'); // OK, 1 == '1' assert.equal(NaN, NaN); // OK assert.equal(1, 2); // AssertionError: 1 == 2 assert.equal({ a: { b: 1 } }, { a: { b: 1 } }); // AssertionError: { a: { b: 1 } } == { a: { b: 1 } } ``` If the values are not equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the `AssertionError`. ## `assert.fail([message])` \* `message` {string|Error} \*\*Default:\*\* `'Failed'` Throws an [`AssertionError`][] with the provided error message or a default error message. If the `message` parameter is an instance of {Error} then it will be thrown instead of the [`AssertionError`][]. ```mjs import assert from 'node:assert/strict'; assert.fail(); // AssertionError [ERR\_ASSERTION]: Failed assert.fail('boom'); // AssertionError [ERR\_ASSERTION]: boom assert.fail(new TypeError('need array')); // TypeError: need array ``` ```cjs const assert = require('node:assert/strict'); assert.fail(); // AssertionError [ERR\_ASSERTION]: Failed assert.fail('boom'); // AssertionError [ERR\_ASSERTION]: boom assert.fail(new TypeError('need array')); // TypeError: need array ``` ## `assert.ifError(value)` \* `value` {any} Throws `value` if `value` is not `undefined` or `null`. This is useful when testing the `error` argument in callbacks. The stack trace contains all frames from the error passed to `ifError()` including the potential new frames for `ifError()` itself. ```mjs import assert from 'node:assert/strict'; assert.ifError(null); // OK assert.ifError(0); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: 0 assert.ifError('error'); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: 'error' assert.ifError(new Error()); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: Error // Create some random error frames. let err; (function errorFrame() { err = new Error('test error'); })(); (function ifErrorFrame() { assert.ifError(err); })(); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: test error // at ifErrorFrame // at errorFrame ``` ```cjs const assert = require('node:assert/strict'); assert.ifError(null); // OK assert.ifError(0); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: 0 assert.ifError('error'); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: 'error' assert.ifError(new Error()); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: Error // Create some random error frames. let err; (function errorFrame() { err = new Error('test error'); | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.04211072996258736,
0.08788605779409409,
0.06914689391851425,
0.08005188405513763,
0.029154762625694275,
-0.051241591572761536,
0.05311218649148941,
-0.010600855574011803,
-0.01169106550514698,
-0.02651141956448555,
0.024566706269979477,
-0.043770451098680496,
0.04570501670241356,
0.04011646658182144,
0.025215599685907364,
-0.00102434738073498,
-0.02848983369767666,
0.05875526741147041,
0.04020315781235695,
-0.05123613774776459,
0.022771470248699188,
-0.003834641072899103,
-0.041390106081962585,
0.05054529383778572,
-0.0446096807718277,
-0.08272743225097656,
-0.014216853305697441,
-0.004104216583073139,
0.0504690483212471,
0.001966695301234722,
-0.006070907227694988,
-0.01051021832972765,
-0.08613435924053192,
0.11945174634456635,
-0.008033905178308487,
0.12261655926704407,
-0.0352790541946888,
-0.017699921503663063,
0.0008579199202358723,
0.008970624767243862,
-0.004909017123281956,
0.04829713702201843,
-0.04736877977848053,
-0.029019499197602272,
0.04818977043032646,
-0.030341753736138344,
-0.027881206944584846,
0.046207159757614136,
-0.06273306161165237,
-0.02747734822332859,
-0.013892735354602337,
0.03355490043759346,
-0.01174014713615179,
-0.010375453159213066,
0.023774586617946625,
-0.037987157702445984,
0.01689916104078293,
0.041905760765075684,
0.07453317195177078,
0.04809951409697533,
0.015474092215299606,
-0.02298158034682274,
0.05202728137373924,
-0.008120231330394745,
0.07347014546394348,
-0.029015040025115013,
-0.023076256737113,
0.09964744001626968,
0.023260226473212242,
0.11745920777320862,
0.0019274430815130472,
0.018961476162075996,
-0.032254382967948914,
0.07208795845508575,
-0.0472111850976944,
-0.019128357991576195,
-0.04818537458777428,
0.007363393437117338,
-0.04411944001913071,
0.08585649728775024,
-0.10400242358446121,
-0.04886046051979065,
-0.0556374117732048,
-0.006600833032280207,
0.0561680868268013,
0.04680664837360382,
-0.04623875394463539,
0.06282137334346771,
-0.023847445845603943,
0.029858911409974098,
-0.046042270958423615,
-0.07951512187719345,
-0.09528512507677078,
0.11389581114053726,
0.10145429521799088,
0.019175639376044273,
0.0001855602313298732,
-0.032700784504413605,
-0.006262362468987703,
0.01896529458463192,
0.05737605318427086,
0.029357941821217537,
0.04041847959160805,
-0.06848648935556412,
0.07189217209815979,
-0.017329296097159386,
-0.011009790003299713,
-0.11535476893186569,
-0.027956055477261543,
0.006054428406059742,
0.006532907951623201,
0.03553162142634392,
0.04036833718419075,
-0.028721192851662636,
-0.02755330502986908,
0.03397081047296524,
0.0716865137219429,
0.0072483643889427185,
0.013104989193379879,
0.016070270910859108,
0.05992242321372032,
-0.05031856521964073,
0.051015496253967285,
0.014305545948445797,
0.028759611770510674,
-0.0334886759519577,
-0.013634138740599155,
6.554658896763291e-34,
-0.009504345245659351,
0.004290970042347908,
-0.023198317736387253,
0.08428573608398438,
-0.010683758184313774,
0.0321020744740963,
-0.022903477773070335,
0.017004719004034996,
-0.054837699979543686,
-0.07079164683818817,
-0.04072028025984764,
-0.057440683245658875,
0.021450389176607132,
-0.05560154840350151,
0.012443652376532555,
-0.00772499106824398,
0.06499922275543213,
-0.02590608224272728,
0.01642933487892151,
0.05184796452522278,
0.03277197107672691,
-0.05696334317326546,
-0.008888098411262035,
-0.06147327274084091,
0.014405417256057262,
-0.059978216886520386,
0.014935599640011787,
-0.020342497155070305,
-0.0025456128641963005,
-0.03420725464820862,
-0.007711699232459068,
-0.03317468985915184,
0.0568373017013073,
0.14851634204387665,
0.04181325435638428,
-0.01660165563225746,
0.01029176265001297,
-0.00537216616794467,
-0.0957128256559372,
-0.08517136424779892,
-0.05489113926887512,
0.016652138903737068,
-0.014706871472299099,
0.06346352398395538,
0.08446720242500305,
-0.1295805126428604,
-0.06461180746555328,
-0.022709451615810394,
0.08226871490478516,
-0.051491137593984604,
0.06487614661455154,
0.06661135703325272,
0.1063370630145073,
0.008681299164891243,
0.011619062162935734,
0.01869248040020466,
0.04063725844025612,
-0.0492134615778923,
-0.02418019436299801,
0.01994374208152294,
0.03399428352713585,
-0.02869146689772606,
-0.06150178611278534,
0.016427217051386833,
-0.015925973653793335,
-0.0007491711294278502,
-0.05131353810429573,
0.021677633747458458,
0.0236810389906168,
-0.039582718163728714,
-0.008439556695520878,
-0.03544232249259949,
-0.1003093272447586,
0.051906466484069824,
-0.06902359426021576,
-0.0019345266046002507,
-0.07011502981185913,
0.010195489972829819,
0.03973829746246338,
-0.10673055052757263,
0.05985631048679352,
-0.10228125005960464,
-0.062139157205820084,
0.08438929170370102,
-0.021049095317721367,
0.017560411244630814,
-0.05265948921442032,
-0.04644380137324333,
0.07018320262432098,
0.021087903529405594,
-0.019832022488117218,
0.004603012464940548,
-0.03310488536953926,
-0.015081481076776981,
-0.007651854772120714,
-2.8251485926197304e-33,
-0.02871454320847988,
0.11816335469484329,
-0.0474739596247673,
0.1089693084359169,
-0.011943834833800793,
-0.03378944471478462,
0.032633546739816666,
-0.007852649316191673,
-0.035482365638017654,
-0.03689977154135704,
-0.08577632158994675,
-0.05048327147960663,
0.05575739964842796,
0.0675741508603096,
0.009545927867293358,
0.003209167392924428,
-0.11654329299926758,
0.0041293189860880375,
0.0011479778913781047,
0.006095290649682283,
0.02494538389146328,
-0.018593082204461098,
0.05289800092577934,
-0.031600166112184525,
-0.09667611122131348,
0.08082756400108337,
0.001764578395523131,
-0.00039037643000483513,
-0.0027028643526136875,
0.009715680964291096,
-0.00294800428673625,
0.05007653683423996,
-0.012209273874759674,
0.021880799904465675,
0.10575131326913834,
-0.10745906084775925,
0.055087894201278687,
0.07146961987018585,
0.021175887435674667,
0.01985209435224533,
0.09752210974693298,
0.0295571256428957,
-0.05223706737160683,
-0.011442470364272594,
0.010569951497018337,
0.005640893708914518,
0.043426092714071274,
-0.013493026606738567,
0.047179821878671646,
-0.023171469569206238,
-0.03545258566737175,
-0.11755315959453583,
-0.019420426338911057,
0.06133837625384331,
-0.053165290504693985,
-0.03998946398496628,
-0.06106516718864441,
0.05576265603303909,
0.046170130372047424,
0.01723625510931015,
-0.06124217435717583,
-0.05608989670872688,
0.012828350067138672,
0.032649435102939606,
-0.031207911670207977,
-0.05551988631486893,
-0.10231103003025055,
-0.03301089629530907,
-0.006878852844238281,
0.0024303134996443987,
-0.03617512807250023,
0.04018513858318329,
-0.08923836052417755,
-0.10555214434862137,
0.01159765012562275,
0.004278561100363731,
-0.00735684996470809,
-0.08309049159288406,
0.057333867996931076,
0.045254260301589966,
0.028521349653601646,
0.023158911615610123,
0.012884587049484253,
0.11213573068380356,
-0.0665578544139862,
0.008628375828266144,
0.010300301015377045,
0.051508303731679916,
-0.04510634392499924,
0.048417363315820694,
0.03361700847744942,
0.09123621881008148,
-0.0920342355966568,
-0.058595653623342514,
-0.04105396196246147,
-4.876069326087418e-8,
-0.10043657571077347,
-0.061338622123003006,
-0.048479124903678894,
-0.013330793008208275,
-0.005318829324096441,
-0.04154979810118675,
0.007474071346223354,
-0.09365975856781006,
0.017346737906336784,
-0.01359661016613245,
-0.061192743480205536,
-0.03392152860760689,
-0.00019082418293692172,
-0.11514094471931458,
0.0009402980795130134,
-0.05588410422205925,
-0.04532940685749054,
-0.056930091232061386,
-0.01372645702213049,
-0.0021706062834709883,
0.024912936612963676,
-0.0011122383875772357,
-0.01459482405334711,
0.11653488129377365,
-0.0014552579959854484,
-0.05736678093671799,
0.07633576542139053,
0.07893151789903641,
-0.034183427691459656,
0.023966602981090546,
-0.022444777190685272,
0.03066706471145153,
0.05455813556909561,
0.014458137564361095,
-0.03917320445179939,
0.1089167669415474,
0.003540065372362733,
0.003809445770457387,
0.07738512009382248,
0.012897051870822906,
-0.0171340499073267,
0.026996418833732605,
-0.03549856320023537,
0.024552691727876663,
-0.033849410712718964,
-0.09228694438934326,
-0.030970824882388115,
0.017156358808279037,
0.0167327169328928,
-0.046487413346767426,
0.03360007330775261,
0.0010075808968394995,
-0.045302923768758774,
0.025520147755742073,
-0.03859713673591614,
0.0040014926344156265,
-0.04132021963596344,
0.02135658450424671,
-0.01718745008111,
0.007264632731676102,
0.13936099410057068,
0.0008663651533424854,
0.08102939277887344,
-0.05023984611034393
] | 0.08896 |
assert = require('node:assert/strict'); assert.ifError(null); // OK assert.ifError(0); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: 0 assert.ifError('error'); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: 'error' assert.ifError(new Error()); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: Error // Create some random error frames. let err; (function errorFrame() { err = new Error('test error'); })(); (function ifErrorFrame() { assert.ifError(err); })(); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: test error // at ifErrorFrame // at errorFrame ``` ## `assert.match(string, regexp[, message])` \* `string` {string} \* `regexp` {RegExp} \* `message` {string|Error|Function} Expects the `string` input to match the regular expression. ```mjs import assert from 'node:assert/strict'; assert.match('I will fail', /pass/); // AssertionError [ERR\_ASSERTION]: The input did not match the regular ... assert.match(123, /pass/); // AssertionError [ERR\_ASSERTION]: The "string" argument must be of type string. assert.match('I will pass', /pass/); // OK ``` ```cjs const assert = require('node:assert/strict'); assert.match('I will fail', /pass/); // AssertionError [ERR\_ASSERTION]: The input did not match the regular ... assert.match(123, /pass/); // AssertionError [ERR\_ASSERTION]: The "string" argument must be of type string. assert.match('I will pass', /pass/); // OK ``` If the values do not match, or if the `string` argument is of another type than `string`, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the [`AssertionError`][]. ## `assert.notDeepEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} \*\*Strict assertion mode\*\* An alias of [`assert.notDeepStrictEqual()`][]. \*\*Legacy assertion mode\*\* > Stability: 3 - Legacy: Use [`assert.notDeepStrictEqual()`][] instead. Tests for any deep inequality. Opposite of [`assert.deepEqual()`][]. ```mjs import assert from 'node:assert'; const obj1 = { a: { b: 1, }, }; const obj2 = { a: { b: 2, }, }; const obj3 = { a: { b: 1, }, }; const obj4 = { \_\_proto\_\_: obj1 }; assert.notDeepEqual(obj1, obj1); // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } } assert.notDeepEqual(obj1, obj2); // OK assert.notDeepEqual(obj1, obj3); // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } } assert.notDeepEqual(obj1, obj4); // OK ``` ```cjs const assert = require('node:assert'); const obj1 = { a: { b: 1, }, }; const obj2 = { a: { b: 2, }, }; const obj3 = { a: { b: 1, }, }; const obj4 = { \_\_proto\_\_: obj1 }; assert.notDeepEqual(obj1, obj1); // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } } assert.notDeepEqual(obj1, obj2); // OK assert.notDeepEqual(obj1, obj3); // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } } assert.notDeepEqual(obj1, obj4); // OK ``` If the values are deeply equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the `AssertionError`. ## `assert.notDeepStrictEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} Tests for deep strict inequality. Opposite of [`assert.deepStrictEqual()`][]. ```mjs import assert from 'node:assert/strict'; assert.notDeepStrictEqual({ a: 1 }, { a: '1' }); // OK ``` ```cjs const assert = require('node:assert/strict'); assert.notDeepStrictEqual({ a: 1 }, { a: '1' }); // OK ``` If the values are deeply and strictly equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.07940606772899628,
0.03697412088513374,
0.023070402443408966,
0.038869135081768036,
0.10544309765100479,
-0.03642731159925461,
0.030345618724822998,
-0.01875314861536026,
0.017996564507484436,
-0.04895063489675522,
0.03191134333610535,
-0.011295469477772713,
0.019527709111571312,
0.06509660184383392,
0.037274688482284546,
-0.0240620207041502,
-0.06765862554311752,
0.05164630338549614,
0.004673907067626715,
-0.06923279911279678,
0.030219413340091705,
0.0032680940348654985,
-0.011002671904861927,
0.05112608149647713,
-0.0392453670501709,
-0.04146881401538849,
-0.032817959785461426,
-0.02243286930024624,
0.0446484312415123,
-0.04923985153436661,
0.08977246284484863,
-0.0613863542675972,
-0.03599128499627113,
0.02812080644071102,
0.03523841127753258,
0.08103245496749878,
-0.059112440794706345,
-0.0574798546731472,
-0.029594771564006805,
-0.01770832948386669,
-0.02200547605752945,
0.01802796870470047,
-0.04850289970636368,
-0.031826164573431015,
0.07259774953126907,
-0.04379482567310333,
-0.009412141516804695,
0.03991077467799187,
-0.001464750850573182,
-0.04394599422812462,
-0.008524373173713684,
0.02086915634572506,
-0.024998623877763748,
-0.08125032484531403,
0.03200649470090866,
0.022490758448839188,
0.03482552617788315,
-0.03380762040615082,
0.07280310243368149,
0.08469214290380478,
0.03149918094277382,
-0.08610062301158905,
0.05177696794271469,
-0.026754675433039665,
-0.018939051777124405,
-0.01547240186482668,
0.0001116068015107885,
0.039491016417741776,
0.03657091036438942,
0.12542599439620972,
-0.03381119295954704,
0.04995540529489517,
-0.046788956969976425,
0.09601165354251862,
-0.05248122662305832,
0.017184140160679817,
-0.07855233550071716,
-0.019746989011764526,
-0.004932021256536245,
0.03896790370345116,
-0.10308967530727386,
-0.08592834323644638,
0.02607380598783493,
0.030447138473391533,
0.052334174513816833,
0.08390457928180695,
-0.004717527888715267,
0.015920093283057213,
-0.028106702491641045,
0.005094761494547129,
-0.010022236034274101,
-0.03146449849009514,
-0.04549703001976013,
0.10342608392238617,
0.06487254053354263,
0.00927512813359499,
-0.04394594952464104,
-0.03653852269053459,
0.04648754373192787,
0.04990670830011368,
0.018938343971967697,
-0.013900058344006538,
0.02606671303510666,
-0.021060233935713768,
-0.010740662924945354,
0.03707638755440712,
-0.0025867081712931395,
-0.12249770760536194,
-0.07322705537080765,
0.022052034735679626,
0.053006742149591446,
0.03900321200489998,
0.043725382536649704,
0.022784613072872162,
0.016669444739818573,
-0.00477570341899991,
0.07698045670986176,
-0.008929689414799213,
0.039588119834661484,
0.05520357936620712,
0.08212415874004364,
0.008307834155857563,
0.05421963334083557,
-0.0018861163407564163,
0.048031363636255264,
-0.017434244975447655,
0.02821461297571659,
4.2061895182848185e-33,
0.03796938806772232,
0.02566954307258129,
-0.05593720078468323,
-0.005931732710450888,
0.0024376753717660904,
0.033420104533433914,
-0.02926032245159149,
0.04693445563316345,
-0.10405809432268143,
-0.015463707968592644,
0.015833750367164612,
-0.06913600862026215,
0.01931176520884037,
-0.08519314974546432,
0.048944368958473206,
-0.03064718097448349,
0.07858440279960632,
0.008900837041437626,
0.05961519852280617,
0.029384048655629158,
0.007344975136220455,
-0.08941683918237686,
-0.018606659024953842,
-0.025983037427067757,
-0.018940908834338188,
-0.05014604702591896,
0.01101479958742857,
-0.01912091299891472,
-0.03182469680905342,
-0.038635894656181335,
0.01627471297979355,
-0.07451096177101135,
0.051092661917209625,
0.17499321699142456,
0.08132344484329224,
-0.01392334420233965,
0.08321031183004379,
0.04305455461144447,
-0.1555958241224289,
-0.07579877972602844,
-0.08002571761608124,
-0.01570574939250946,
-0.04165802150964737,
0.04552881047129631,
0.060851410031318665,
-0.10840429365634918,
0.00012462696759030223,
0.02195957489311695,
0.08646885305643082,
-0.0181337408721447,
0.016784751787781715,
0.07151360809803009,
0.06402303278446198,
-0.08087971061468124,
0.04843224957585335,
0.009158638305962086,
-0.03345571458339691,
-0.00672558369114995,
0.011047947220504284,
-0.005263494327664375,
-0.014584854245185852,
0.011845694854855537,
-0.05640750378370285,
-0.04263874515891075,
-0.026240382343530655,
0.013175176456570625,
-0.012204241938889027,
-0.04183907434344292,
-0.042552363127470016,
-0.043088462203741074,
0.033845435827970505,
-0.05715049430727959,
-0.019542111083865166,
0.024943139404058456,
-0.009923204779624939,
-0.04724234342575073,
-0.07103125751018524,
0.07813877612352371,
-0.017705870792269707,
-0.13470380008220673,
-0.02826949581503868,
-0.09119801968336105,
-0.030476074665784836,
0.09587200731039047,
-0.06143793836236,
0.014214571565389633,
-0.014260572381317616,
-0.021558554843068123,
0.003997014835476875,
0.002505046781152487,
-0.03158802539110184,
-0.019401919096708298,
-0.011479634791612625,
-0.032297659665346146,
0.02967258356511593,
-4.855087379193676e-33,
0.027017977088689804,
0.08383443206548691,
0.012004666961729527,
0.09519361704587936,
0.0664716362953186,
-0.08155564963817596,
0.09852630645036697,
0.0553978867828846,
-0.02568870596587658,
-0.023206695914268494,
-0.08115403354167938,
-0.040746692568063736,
0.047307755798101425,
0.017317375168204308,
-0.04571099951863289,
0.010005366988480091,
-0.10343476384878159,
-0.02455391362309456,
-0.016780724748969078,
0.03328539431095123,
0.06924574077129364,
0.0589328296482563,
0.04183454439043999,
-0.04971984773874283,
-0.05080315098166466,
0.08158565312623978,
0.008908319287002087,
-0.0006966447690501809,
-0.05103634297847748,
-0.001867765444330871,
0.013443063013255596,
0.060161154717206955,
-0.03268108516931534,
0.011501736007630825,
0.10499618947505951,
-0.08792953938245773,
0.05617772042751312,
0.08220694214105606,
-0.022554533556103706,
-0.012378745712339878,
0.0505567267537117,
0.04504036158323288,
-0.052888743579387665,
-0.019002769142389297,
0.02968169003725052,
0.005311610177159309,
0.06027130037546158,
0.008000296540558338,
0.012869271449744701,
-0.03493732586503029,
-0.049818459898233414,
-0.037461262196302414,
-0.038475967943668365,
0.06704436242580414,
-0.013620211742818356,
-0.030716633424162865,
-0.021931981667876244,
0.032878030091524124,
-0.030348919332027435,
0.08088196069002151,
-0.038518745452165604,
-0.046785853803157806,
0.022910866886377335,
0.0875295102596283,
0.06630554795265198,
-0.08792128413915634,
-0.09471160918474197,
0.002793264575302601,
0.05028079077601433,
0.022964568808674812,
-0.04556550830602646,
0.0366339236497879,
-0.07379797101020813,
0.029232216998934746,
0.04435555636882782,
0.014069974422454834,
-0.013428058475255966,
-0.06634654849767685,
0.06512130051851273,
0.1679907739162445,
0.015299446880817413,
0.02464747056365013,
0.004712906200438738,
0.07046957314014435,
-0.027531547471880913,
0.03641631826758385,
-0.013612142764031887,
0.07555679976940155,
-0.021843144670128822,
0.035462867468595505,
0.025586538016796112,
0.025243699550628662,
-0.03848326578736305,
-0.033475492149591446,
0.026806555688381195,
-4.875209924648516e-8,
-0.11146046966314316,
-0.04299803823232651,
0.007325882092118263,
-0.08700960874557495,
-0.03494204208254814,
-0.0685741975903511,
0.027988363057374954,
-0.10113416612148285,
-0.008776660077273846,
-0.07548300921916962,
-0.06320428103208542,
0.03832847625017166,
-0.058271802961826324,
-0.0592203326523304,
-0.022651493549346924,
-0.047614552080631256,
-0.013927377760410309,
0.036525025963783264,
-0.005115895066410303,
-0.004442315548658371,
0.010841930285096169,
0.015210176818072796,
-0.014838512986898422,
0.00813289638608694,
-0.020406292751431465,
-0.07192336022853851,
0.022433027625083923,
0.03624113276600838,
-0.010342458263039589,
0.019073188304901123,
-0.022576503455638885,
0.008281230926513672,
0.050333376973867416,
-0.06898777186870575,
-0.03268999978899956,
0.080167256295681,
0.031167740002274513,
-0.055506858974695206,
0.029154393821954727,
-0.0005635987618006766,
-0.0006285119452513754,
0.031635113060474396,
-0.00016369235527236015,
-0.019295992329716682,
-0.01927894353866577,
-0.10044935345649719,
-0.022655876353383064,
-0.04235738515853882,
0.0791219174861908,
-0.05714384838938713,
0.04332511126995087,
-0.056594450026750565,
-0.08773287385702133,
0.002579024527221918,
-0.03946879133582115,
0.00665908120572567,
0.015901369974017143,
-0.049825213849544525,
-0.05380622297525406,
0.004025422036647797,
0.11280234158039093,
0.05632510781288147,
0.08503364771604538,
-0.06577102839946747
] | 0.045019 |
assert.notDeepStrictEqual({ a: 1 }, { a: '1' }); // OK ``` If the values are deeply and strictly equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the [`AssertionError`][]. ## `assert.notEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} \*\*Strict assertion mode\*\* An alias of [`assert.notStrictEqual()`][]. \*\*Legacy assertion mode\*\* > Stability: 3 - Legacy: Use [`assert.notStrictEqual()`][] instead. Tests shallow, coercive inequality with the [`!=` operator][]. `NaN` is specially handled and treated as being identical if both sides are `NaN`. ```mjs import assert from 'node:assert'; assert.notEqual(1, 2); // OK assert.notEqual(1, 1); // AssertionError: 1 != 1 assert.notEqual(1, '1'); // AssertionError: 1 != '1' ``` ```cjs const assert = require('node:assert'); assert.notEqual(1, 2); // OK assert.notEqual(1, 1); // AssertionError: 1 != 1 assert.notEqual(1, '1'); // AssertionError: 1 != '1' ``` If the values are equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the `AssertionError`. ## `assert.notStrictEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} Tests strict inequality between the `actual` and `expected` parameters as determined by [`Object.is()`][]. ```mjs import assert from 'node:assert/strict'; assert.notStrictEqual(1, 2); // OK assert.notStrictEqual(1, 1); // AssertionError [ERR\_ASSERTION]: Expected "actual" to be strictly unequal to: // // 1 assert.notStrictEqual(1, '1'); // OK ``` ```cjs const assert = require('node:assert/strict'); assert.notStrictEqual(1, 2); // OK assert.notStrictEqual(1, 1); // AssertionError [ERR\_ASSERTION]: Expected "actual" to be strictly unequal to: // // 1 assert.notStrictEqual(1, '1'); // OK ``` If the values are strictly equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the `AssertionError`. ## `assert.ok(value[, message])` \* `value` {any} \* `message` {string|Error|Function} Tests if `value` is truthy. It is equivalent to `assert.equal(!!value, true, message)`. If `value` is not truthy, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is `undefined`, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the `AssertionError`. If no arguments are passed in at all `message` will be set to the string: ``'No value argument passed to `assert.ok()`'``. Be aware that in the `repl` the error message will be different to the one thrown in a file! See below for further details. ```mjs import assert from 'node:assert/strict'; assert.ok(true); // OK assert.ok(1); // OK assert.ok(); // AssertionError: No value argument passed to `assert.ok()` assert.ok(false, 'it\'s false'); // AssertionError: it's false // In the repl: assert.ok(typeof 123 === 'string'); // AssertionError: false == true // In a file (e.g. test.js): assert.ok(typeof 123 === 'string'); // AssertionError: The expression evaluated to a falsy value: // // assert.ok(typeof 123 === 'string') assert.ok(false); // AssertionError: The expression evaluated to a falsy value: // // assert.ok(false) assert.ok(0); // AssertionError: The expression evaluated to a falsy value: // // assert.ok(0) ``` ```cjs const assert = require('node:assert/strict'); assert.ok(true); // OK assert.ok(1); // OK assert.ok(); // AssertionError: No value argument passed to `assert.ok()` assert.ok(false, 'it\'s false'); // AssertionError: it's false // In the repl: assert.ok(typeof 123 === | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.0496126264333725,
0.035262126475572586,
0.041154880076646805,
0.008581873029470444,
-0.0029935918282717466,
-0.06434448808431625,
0.030247528105974197,
0.00871219951659441,
-0.06833214312791824,
-0.01622362993657589,
0.009156308136880398,
-0.07669191807508469,
0.11238683015108109,
0.0532834529876709,
0.02878032997250557,
0.0317910835146904,
0.0333792008459568,
-0.017706669867038727,
-0.02401861920952797,
-0.003690340556204319,
0.026825394481420517,
0.05641859769821167,
-0.02239634096622467,
0.08325327932834625,
-0.06416679918766022,
-0.042110491544008255,
-0.06382588297128677,
-0.0025265139993280172,
0.056776441633701324,
-0.017665663734078407,
-0.013333427719771862,
0.047386284917593,
-0.007374668959528208,
0.03832260146737099,
0.06783688813447952,
0.06936924904584885,
0.007208630442619324,
-0.06003047898411751,
0.013807850889861584,
0.00021394452778622508,
-0.017360946163535118,
0.028802964836359024,
0.016776904463768005,
-0.05732891336083412,
0.008968171663582325,
0.03574229031801224,
0.004142166115343571,
0.011382440105080605,
-0.07589998841285706,
-0.04912837594747543,
0.014022649265825748,
0.04433134198188782,
0.02030288055539131,
-0.039800312370061874,
0.019389092922210693,
-0.022172650322318077,
-0.019900571554899216,
0.024412982165813446,
0.009469361044466496,
-0.004434844013303518,
0.016607316210865974,
-0.04978141933679581,
0.06047479808330536,
-0.03403947129845619,
0.010208388790488243,
-0.03352529928088188,
0.015582913532853127,
0.03984914347529411,
-0.025896213948726654,
0.11146607249975204,
-0.07775659114122391,
0.010530507192015648,
-0.04223945736885071,
0.0991974025964737,
0.007455561775714159,
0.04811134561896324,
0.058471422642469406,
-0.07367578148841858,
0.002554462291300297,
0.018781699240207672,
-0.09711264818906784,
-0.09550672769546509,
-0.06021711230278015,
-0.01693769544363022,
0.07266587764024734,
-0.0329146571457386,
-0.03637572005391121,
-0.029431404545903206,
0.07100673019886017,
0.05835812911391258,
0.01581614278256893,
-0.061541128903627396,
-0.0013537273043766618,
0.14150486886501312,
0.1020626500248909,
-0.0029705464839935303,
-0.0031803620513528585,
-0.026897413656115532,
-0.00959553848952055,
0.05963316932320595,
0.00008980840357253328,
0.04033815488219261,
0.06449267268180847,
-0.08695380389690399,
0.06637997925281525,
0.027720505371689796,
0.03789956495165825,
-0.13644541800022125,
0.0053070317953825,
0.00992470234632492,
0.0351979099214077,
-0.02713523991405964,
0.09616764634847641,
0.013046489097177982,
0.010102336294949055,
0.012505591847002506,
0.012031701393425465,
0.015734203159809113,
-0.008176684379577637,
-0.01146098505705595,
0.04094725474715233,
-0.03155094385147095,
0.06311272084712982,
0.046108074486255646,
0.08288544416427612,
0.014873137697577477,
0.02285550720989704,
1.1416204607224278e-33,
0.019779657945036888,
0.010491223074495792,
-0.02445332705974579,
0.040193986147642136,
0.0003015338152181357,
0.04628211259841919,
-0.0229431614279747,
-0.0006519810413010418,
-0.10975363850593567,
0.006094529293477535,
-0.016175828874111176,
0.03511666879057884,
-0.00711336825042963,
-0.02886962704360485,
0.06428705155849457,
0.0581899955868721,
0.05479554086923599,
-0.07381736487150192,
0.04975144565105438,
-0.002872524783015251,
0.02540861815214157,
-0.10119836032390594,
-0.07540474086999893,
-0.03358016163110733,
0.006301023066043854,
-0.08882793039083481,
0.009983118623495102,
-0.03918101266026497,
-0.010432158596813679,
-0.025478506460785866,
-0.06705208122730255,
-0.04775938764214516,
0.07598980516195297,
0.07387999445199966,
0.05395154654979706,
0.001250778092071414,
0.02776414342224598,
0.013615683652460575,
-0.0822291225194931,
-0.03528514504432678,
-0.07165313512086868,
-0.021123388782143593,
0.004569735378026962,
0.04081170633435249,
0.07227860391139984,
-0.17157097160816193,
-0.03463273495435715,
0.04465920478105545,
0.06910515576601028,
-0.006428989116102457,
0.051650580018758774,
0.011646105907857418,
0.03697777912020683,
-0.0014172261580824852,
0.03899456188082695,
-0.059177249670028687,
0.02010771818459034,
0.062411773949861526,
0.004322969354689121,
0.021006714552640915,
-0.03169822320342064,
-0.052603643387556076,
-0.01945316605269909,
-0.04215662553906441,
-0.012824035249650478,
0.03752214461565018,
-0.03190402314066887,
-0.0316004641354084,
0.024459796026349068,
-0.015499992296099663,
-0.004687255248427391,
-0.06305217742919922,
-0.11338410526514053,
0.03732077777385712,
-0.0313308946788311,
-0.06273036450147629,
0.008978161960840225,
0.031315144151449203,
0.02304139919579029,
-0.0681435614824295,
0.028458381071686745,
-0.01337093859910965,
-0.024639703333377838,
0.0848202109336853,
-0.061300162225961685,
-0.021627839654684067,
0.014732369221746922,
-0.039861876517534256,
0.014247925952076912,
-0.08188862353563309,
-0.05352937430143356,
-0.016321977600455284,
0.007765807211399078,
0.0008168088388629258,
0.029440324753522873,
-2.3844875355781255e-33,
0.029264915734529495,
0.0760311707854271,
-0.05527639389038086,
0.09374617785215378,
-0.012992789037525654,
-0.08880691975355148,
0.1390507072210312,
-0.026657385751605034,
-0.038004446774721146,
-0.09598827362060547,
-0.0272329431027174,
-0.030001046136021614,
0.01920408383011818,
-0.044838737696409225,
0.015597131103277206,
0.0095857884734869,
-0.10832730680704117,
-0.015350615605711937,
-0.00703703798353672,
0.03705884516239166,
0.046978410333395004,
0.007265216205269098,
-0.00747525691986084,
0.05945194885134697,
-0.08396939188241959,
0.05957326292991638,
0.008748862892389297,
0.012753977440297604,
0.004670300055295229,
-0.02594166249036789,
0.014527969993650913,
0.007405458949506283,
-0.05993158370256424,
-0.031380072236061096,
0.03226405382156372,
-0.1020166426897049,
0.08690589666366577,
0.03643590211868286,
-0.03996803238987923,
0.015595538541674614,
0.09468364715576172,
0.09578491747379303,
-0.040329091250896454,
0.0044488548301160336,
-0.013611008413136005,
0.04266048222780228,
0.09289972484111786,
-0.042733460664749146,
0.06173310801386833,
-0.04809219017624855,
0.049862101674079895,
-0.06532034277915955,
0.02918403036892414,
0.15295778214931488,
-0.03079993836581707,
-0.04298291355371475,
-0.06901407241821289,
0.01798977516591549,
-0.02663412131369114,
0.052181173115968704,
-0.061132077127695084,
-0.036689504981040955,
0.016956062987446785,
0.05134383216500282,
-0.01998755894601345,
-0.03928070142865181,
-0.09768867492675781,
0.034036822617053986,
0.0640292763710022,
0.004936130251735449,
0.021730417385697365,
-0.0260494202375412,
-0.06523746997117996,
-0.0855223536491394,
0.020828044041991234,
0.002524196170270443,
0.052116233855485916,
-0.015548196621239185,
0.06781827658414841,
0.08645384013652802,
0.03013014979660511,
0.03976677730679512,
0.06498654931783676,
0.077931247651577,
-0.05648636072874069,
0.05206742510199547,
0.014797475188970566,
0.08252792060375214,
-0.04560502618551254,
0.06866814196109772,
0.011859136633574963,
0.011293432675302029,
-0.022807110100984573,
-0.05442150682210922,
0.022898564115166664,
-5.1717172766529984e-8,
-0.08276762813329697,
-0.04052172228693962,
-0.03958833962678909,
-0.08316045254468918,
-0.03019101731479168,
-0.030086463317275047,
-0.03363059088587761,
-0.14613375067710876,
0.012817911803722382,
-0.02599615976214409,
-0.013042842969298363,
0.021024711430072784,
-0.06900042295455933,
-0.0884939655661583,
-0.015203887596726418,
-0.03750045597553253,
-0.08303213864564896,
0.0024540408048778772,
-0.025219867005944252,
0.0002650009701028466,
0.00689349789172411,
-0.02310357242822647,
-0.036222249269485474,
-0.014724028296768665,
-0.003815270960330963,
-0.01799103431403637,
0.014585648663341999,
-0.011442498303949833,
-0.014839706011116505,
0.006668854504823685,
0.028366034850478172,
-0.013855244033038616,
0.09781765937805176,
-0.08831246197223663,
-0.010122601874172688,
0.07776059955358505,
0.023786356672644615,
-0.0021443681325763464,
-0.023514598608016968,
0.06170724332332611,
-0.01228500809520483,
0.03996356576681137,
-0.05649245157837868,
-0.033384792506694794,
-0.00493355467915535,
-0.08931776136159897,
0.02189714089035988,
-0.005290177650749683,
0.034776847809553146,
-0.0301233921200037,
0.04386042803525925,
0.04009179025888443,
-0.039179954677820206,
0.06506815552711487,
-0.08153887093067169,
-0.04250152036547661,
-0.025211375206708908,
0.01063441764563322,
-0.06332770735025406,
-0.014439169317483902,
0.19574441015720367,
0.007444263435900211,
0.06267032772302628,
-0.060663219541311264
] | 0.032963 |
// assert.ok(false) assert.ok(0); // AssertionError: The expression evaluated to a falsy value: // // assert.ok(0) ``` ```cjs const assert = require('node:assert/strict'); assert.ok(true); // OK assert.ok(1); // OK assert.ok(); // AssertionError: No value argument passed to `assert.ok()` assert.ok(false, 'it\'s false'); // AssertionError: it's false // In the repl: assert.ok(typeof 123 === 'string'); // AssertionError: false == true // In a file (e.g. test.js): assert.ok(typeof 123 === 'string'); // AssertionError: The expression evaluated to a falsy value: // // assert.ok(typeof 123 === 'string') assert.ok(false); // AssertionError: The expression evaluated to a falsy value: // // assert.ok(false) assert.ok(0); // AssertionError: The expression evaluated to a falsy value: // // assert.ok(0) ``` ```mjs import assert from 'node:assert/strict'; // Using `assert()` works the same: assert(2 + 2 > 5); // AssertionError: The expression evaluated to a falsy value: // // assert(2 + 2 > 5) ``` ```cjs const assert = require('node:assert'); // Using `assert()` works the same: assert(2 + 2 > 5); // AssertionError: The expression evaluated to a falsy value: // // assert(2 + 2 > 5) ``` ## `assert.rejects(asyncFn[, error][, message])` \* `asyncFn` {Function|Promise} \* `error` {RegExp|Function|Object|Error} \* `message` {string} \* Returns: {Promise} Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is rejected. If `asyncFn` is a function and it throws an error synchronously, `assert.rejects()` will return a rejected `Promise` with that error. If the function does not return a promise, `assert.rejects()` will return a rejected `Promise` with an [`ERR\_INVALID\_RETURN\_VALUE`][] error. In both cases the error handler is skipped. Besides the async nature to await the completion behaves identically to [`assert.throws()`][]. If specified, `error` can be a [`Class`][], {RegExp}, a validation function, an object where each property will be tested for, or an instance of error where each property will be tested for including the non-enumerable `message` and `name` properties. If specified, `message` will be the message provided by the [`AssertionError`][] if the `asyncFn` fails to reject. ```mjs import assert from 'node:assert/strict'; await assert.rejects( async () => { throw new TypeError('Wrong value'); }, { name: 'TypeError', message: 'Wrong value', }, ); ``` ```cjs const assert = require('node:assert/strict'); (async () => { await assert.rejects( async () => { throw new TypeError('Wrong value'); }, { name: 'TypeError', message: 'Wrong value', }, ); })(); ``` ```mjs import assert from 'node:assert/strict'; await assert.rejects( async () => { throw new TypeError('Wrong value'); }, (err) => { assert.strictEqual(err.name, 'TypeError'); assert.strictEqual(err.message, 'Wrong value'); return true; }, ); ``` ```cjs const assert = require('node:assert/strict'); (async () => { await assert.rejects( async () => { throw new TypeError('Wrong value'); }, (err) => { assert.strictEqual(err.name, 'TypeError'); assert.strictEqual(err.message, 'Wrong value'); return true; }, ); })(); ``` ```mjs import assert from 'node:assert/strict'; assert.rejects( Promise.reject(new Error('Wrong value')), Error, ).then(() => { // ... }); ``` ```cjs const assert = require('node:assert/strict'); assert.rejects( Promise.reject(new Error('Wrong value')), Error, ).then(() => { // ... }); ``` `error` cannot be a string. If a string is provided as the second argument, then `error` is assumed to be omitted and the string will be used for `message` instead. This can lead to easy-to-miss mistakes. Please read the example in [`assert.throws()`][] carefully if using a string as the second argument gets considered. ## `assert.strictEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} Postfix `printf`-like arguments in case it's used as format string. If message is a function, it is called in case of a comparison failure. The function receives the `actual` and `expected` arguments and has to return a string that is going to be used as error message. `printf`-like | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.13548187911510468,
0.06753186881542206,
0.010360630229115486,
0.04759962484240532,
0.04105133190751076,
-0.011697775684297085,
0.015803705900907516,
0.02726326324045658,
0.025110462680459023,
-0.0045223236083984375,
-0.02362004853785038,
-0.02454826422035694,
-0.03053070418536663,
0.04934656247496605,
0.0031979663763195276,
-0.001134280813857913,
-0.05836961418390274,
0.037451568990945816,
0.005300171207636595,
-0.045484788715839386,
0.03945378214120865,
-0.05694291368126869,
-0.018826188519597054,
-0.029406266286969185,
0.033039119094610214,
-0.06266850978136063,
-0.030434582382440567,
0.0028399855364114046,
0.07846572250127792,
-0.021512364968657494,
0.042429037392139435,
-0.02469516173005104,
-0.04636160284280777,
0.06366749852895737,
0.031460557132959366,
0.11844918876886368,
0.01952829770743847,
-0.1024271547794342,
0.0034711335320025682,
0.026329608634114265,
-0.007705355994403362,
0.07419142127037048,
-0.0662045031785965,
-0.032773517072200775,
0.09414731711149216,
-0.00029728253139182925,
-0.0033144617918878794,
0.0169567558914423,
-0.11693728715181351,
-0.015995057299733162,
0.016997432336211205,
-0.004417519550770521,
-0.041142016649246216,
-0.06540858000516891,
-0.02957131341099739,
0.004429189953953028,
-0.03955363854765892,
-0.0003487377252895385,
0.11146396398544312,
0.12018745392560959,
0.007411926984786987,
-0.04647735878825188,
0.0403885543346405,
0.027104444801807404,
0.03604339435696602,
-0.012674159370362759,
-0.020128855481743813,
0.026850111782550812,
0.014802570454776287,
0.022543547675013542,
-0.053469907492399216,
0.05584133788943291,
0.013314212672412395,
0.052305467426776886,
-0.0540139302611351,
-0.0428190641105175,
-0.047245092689991,
-0.00928559247404337,
0.058767177164554596,
0.013864552602171898,
-0.07376687228679657,
-0.0760965570807457,
-0.007551941089332104,
-0.002443513600155711,
0.013497413136065006,
0.06377460807561874,
-0.027968840673565865,
0.021928077563643456,
-0.03135454282164574,
0.10475368052721024,
0.0024279928766191006,
-0.07957354187965393,
-0.07185196131467819,
0.0721563771367073,
0.08876292407512665,
0.018512586131691933,
-0.03543106094002724,
-0.0035364164505153894,
0.01511705107986927,
0.006374660413712263,
0.011076907627284527,
0.04016010835766792,
0.0956072136759758,
-0.04527687281370163,
-0.004963584244251251,
-0.020572343841195107,
0.04098447412252426,
-0.05238545313477516,
-0.05667802691459656,
0.008751451037824154,
0.012085745111107826,
0.03684324771165848,
0.03905315324664116,
-0.09507647156715393,
-0.050657790154218674,
0.020706504583358765,
0.0626378059387207,
-0.04605506360530853,
0.0681167021393776,
0.027658017352223396,
0.04851226136088371,
-0.026469923555850983,
0.018689285963773727,
0.03376220166683197,
0.03420105576515198,
0.0005896590300835669,
0.041837554425001144,
1.6550995357066348e-33,
0.031841155141592026,
0.0022329692728817463,
-0.026458855718374252,
0.02411218173801899,
-0.041600607335567474,
-0.046696946024894714,
-0.026035865768790245,
0.02937578223645687,
-0.12739571928977966,
0.02090698666870594,
-0.014587784186005592,
-0.0015090900706127286,
0.006201617885380983,
-0.08822381496429443,
0.0018377747619524598,
0.012088813818991184,
0.059213392436504364,
-0.0057914298959076405,
-0.01914348267018795,
-0.002892160788178444,
0.0774497240781784,
-0.023320544511079788,
-0.006147516425698996,
-0.011081612668931484,
-0.022333664819598198,
-0.08822710812091827,
0.05213290452957153,
0.05881369113922119,
-0.05018964037299156,
-0.024210810661315918,
0.040544163435697556,
-0.06401189416646957,
0.057092729955911636,
0.16214339435100555,
0.028005843982100487,
0.04908663406968117,
0.029860036447644234,
0.019069716334342957,
-0.08478785306215286,
-0.03137077018618584,
-0.009189195930957794,
0.020458368584513664,
-0.03334936499595642,
0.0408250093460083,
0.06376201659440994,
-0.10729870200157166,
-0.04726079851388931,
-0.05220092460513115,
0.0892956554889679,
-0.016663802787661552,
0.009615810588002205,
0.10609897971153259,
0.045245036482810974,
0.026920925825834274,
0.038109876215457916,
0.03613508492708206,
-0.0017847194103524089,
-0.03802214935421944,
-0.03531862050294876,
0.013360021635890007,
0.04184496030211449,
0.02414265275001526,
-0.095235176384449,
-0.03532187640666962,
-0.08304696530103683,
0.030733613297343254,
-0.05184599757194519,
-0.0557035468518734,
-0.01942090131342411,
0.02466503717005253,
0.007593083195388317,
-0.020064525306224823,
-0.07752534002065659,
-0.04368804395198822,
0.07327873259782791,
0.00269632157869637,
-0.08714739233255386,
0.08372426778078079,
0.0009214120800606906,
-0.06979051232337952,
0.013014322146773338,
-0.06912954896688461,
-0.034484442323446274,
0.12721233069896698,
-0.03036395274102688,
-0.013552544638514519,
-0.06312905251979828,
-0.041521359235048294,
0.09549864381551743,
-0.020614255219697952,
0.04671839252114296,
-0.04349016398191452,
-0.08546487987041473,
-0.05516771599650383,
-0.010911540128290653,
-2.949970296971718e-33,
0.01730332151055336,
0.08091374486684799,
-0.016224779188632965,
0.13564836978912354,
-0.008286667987704277,
-0.033144671469926834,
0.03506376966834068,
0.017904555425047874,
0.013369651511311531,
-0.0027219830080866814,
-0.04438994824886322,
-0.0020743838977068663,
0.01808941923081875,
0.03782004863023758,
0.021787941455841064,
-0.0027878882829099894,
-0.14164486527442932,
-0.03347225487232208,
0.02385103702545166,
0.0031686159782111645,
0.005609800107777119,
0.05687616765499115,
0.09751187264919281,
0.015125846490263939,
-0.053546033799648285,
0.05722053721547127,
-0.03674827516078949,
0.002477163914591074,
0.017876682803034782,
0.03988446295261383,
-0.01908336579799652,
0.048646941781044006,
-0.03807613253593445,
0.000774382206145674,
0.01635008677840233,
-0.12988242506980896,
0.06696636229753494,
0.1331254094839096,
-0.006993519142270088,
0.004921261686831713,
0.06863295286893845,
-0.003826879896223545,
-0.06244611367583275,
-0.0038875462487339973,
0.02934308536350727,
0.018706081435084343,
0.052966225892305374,
0.0008864453993737698,
0.05521480366587639,
-0.060828015208244324,
0.0024984616320580244,
-0.04030192270874977,
0.00047209838521666825,
0.059359416365623474,
-0.018003391101956367,
-0.031097495928406715,
-0.07996068894863129,
0.009189505130052567,
-0.025495212525129318,
0.059566888958215714,
-0.027725180611014366,
-0.08229035139083862,
0.0139398705214262,
0.042480356991291046,
0.028243452310562134,
-0.0386686697602272,
-0.09176811575889587,
0.037915363907814026,
0.05416274815797806,
-0.03855113685131073,
-0.043431106954813004,
0.011788779869675636,
-0.03992454707622528,
-0.0450536273419857,
0.04724202677607536,
-0.013578425161540508,
0.0070570083335042,
-0.042806025594472885,
0.06180936470627785,
0.11175648868083954,
0.05138759687542915,
0.04468346759676933,
-0.012387877330183983,
0.06722727417945862,
-0.0011394725879654288,
0.022083641961216927,
-0.008958695456385612,
0.06363099813461304,
-0.08950803428888321,
0.07350019365549088,
0.024455128237605095,
0.09185262769460678,
-0.10120819509029388,
-0.04089174419641495,
0.02509080059826374,
-5.1794330602206173e-8,
-0.09114059060811996,
0.004119344986975193,
-0.056755177676677704,
-0.06144152581691742,
-0.04857311770319939,
-0.016138065606355667,
0.02290279045701027,
-0.1100010871887207,
0.030578140169382095,
-0.0027053679805248976,
-0.07278946042060852,
0.05215450003743172,
-0.023697881028056145,
-0.07802464812994003,
-0.0438118577003479,
-0.006383356172591448,
-0.04478780925273895,
-0.0466306135058403,
-0.0075105540454387665,
0.046963006258010864,
-0.023448344320058823,
0.010127093642950058,
-0.018601682037115097,
0.0886225774884224,
0.03238789364695549,
-0.04589186981320381,
0.04163874685764313,
0.04680380970239639,
-0.03173591569066048,
0.026995474472641945,
-0.040975652635097504,
0.0676814541220665,
0.024538246914744377,
-0.05414581671357155,
-0.03562656790018082,
0.0935072973370552,
0.01978914812207222,
-0.01814572513103485,
0.034122761338949203,
0.0481446199119091,
-0.02444089576601982,
0.016639476642012596,
-0.016955483704805374,
0.017224175855517387,
-0.06026428937911987,
-0.07987209409475327,
-0.03003336675465107,
-0.006084269843995571,
-0.009836820885539055,
-0.07971903681755066,
0.02295558899641037,
-0.027086861431598663,
-0.09799658507108688,
0.016398249194025993,
-0.061093006283044815,
-0.021635599434375763,
-0.029866792261600494,
-0.02038869448006153,
-0.042635656893253326,
-0.0021912443917244673,
0.1432105302810669,
0.014035849831998348,
0.10268821567296982,
-0.03444501385092735
] | 0.035067 |
`message` {string|Error|Function} Postfix `printf`-like arguments in case it's used as format string. If message is a function, it is called in case of a comparison failure. The function receives the `actual` and `expected` arguments and has to return a string that is going to be used as error message. `printf`-like format strings and functions are beneficial for performance reasons in case arguments are passed through. In addition, it allows nice formatting with ease. Tests strict equality between the `actual` and `expected` parameters as determined by [`Object.is()`][]. ```mjs import assert from 'node:assert/strict'; assert.strictEqual(1, 2); // AssertionError [ERR\_ASSERTION]: Expected inputs to be strictly equal: // // 1 !== 2 assert.strictEqual(1, 1); // OK assert.strictEqual('Hello foobar', 'Hello World!'); // AssertionError [ERR\_ASSERTION]: Expected inputs to be strictly equal: // + actual - expected // // + 'Hello foobar' // - 'Hello World!' // ^ const apples = 1; const oranges = 2; assert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`); // AssertionError [ERR\_ASSERTION]: apples 1 !== oranges 2 assert.strictEqual(apples, oranges, 'apples %s !== oranges %s', apples, oranges); // AssertionError [ERR\_ASSERTION]: apples 1 !== oranges 2 assert.strictEqual(1, '1', new TypeError('Inputs are not identical')); // TypeError: Inputs are not identical assert.strictEqual(apples, oranges, (actual, expected) => { // Do 'heavy' computations return `I expected ${expected} but I got ${actual}`; }); // AssertionError [ERR\_ASSERTION]: I expected oranges but I got apples ``` ```cjs const assert = require('node:assert/strict'); assert.strictEqual(1, 2); // AssertionError [ERR\_ASSERTION]: Expected inputs to be strictly equal: // // 1 !== 2 assert.strictEqual(1, 1); // OK assert.strictEqual('Hello foobar', 'Hello World!'); // AssertionError [ERR\_ASSERTION]: Expected inputs to be strictly equal: // + actual - expected // // + 'Hello foobar' // - 'Hello World!' // ^ const apples = 1; const oranges = 2; assert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`); // AssertionError [ERR\_ASSERTION]: apples 1 !== oranges 2 assert.strictEqual(apples, oranges, 'apples %s !== oranges %s', apples, oranges); // AssertionError [ERR\_ASSERTION]: apples 1 !== oranges 2 assert.strictEqual(1, '1', new TypeError('Inputs are not identical')); // TypeError: Inputs are not identical assert.strictEqual(apples, oranges, (actual, expected) => { // Do 'heavy' computations return `I expected ${expected} but I got ${actual}`; }); // AssertionError [ERR\_ASSERTION]: I expected oranges but I got apples ``` If the values are not strictly equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the [`AssertionError`][]. ## `assert.throws(fn[, error][, message])` \* `fn` {Function} \* `error` {RegExp|Function|Object|Error} \* `message` {string} Expects the function `fn` to throw an error. If specified, `error` can be a [`Class`][], {RegExp}, a validation function, a validation object where each property will be tested for strict deep equality, or an instance of error where each property will be tested for strict deep equality including the non-enumerable `message` and `name` properties. When using an object, it is also possible to use a regular expression, when validating against a string property. See below for examples. If specified, `message` will be appended to the message provided by the `AssertionError` if the `fn` call fails to throw or in case the error validation fails. Custom validation object/error instance: ```mjs import assert from 'node:assert/strict'; const err = new TypeError('Wrong value'); err.code = 404; err.foo = 'bar'; err.info = { nested: true, baz: 'text', }; err.reg = /abc/i; assert.throws( () => { throw err; }, { name: 'TypeError', message: 'Wrong value', info: { nested: true, baz: 'text', }, // Only properties on the validation object will be tested for. // Using nested objects requires all | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.025444133207201958,
0.07459086179733276,
0.04184379801154137,
0.03963146731257439,
-0.0029782652854919434,
-0.06761663407087326,
-0.005199054256081581,
0.030472714453935623,
-0.021976977586746216,
-0.03709433972835541,
-0.015950437635183334,
-0.029147416353225708,
0.08388878405094147,
0.0066283028572797775,
0.06582976877689362,
-0.017270855605602264,
0.0222728680819273,
0.008127507753670216,
0.016065534204244614,
-0.06725168973207474,
0.014035590924322605,
0.008405951783061028,
-0.013288685120642185,
0.02241998165845871,
-0.06789420545101166,
-0.036934975534677505,
-0.05105389282107353,
0.030052287504076958,
0.008513366803526878,
-0.021711407229304314,
0.01801241561770439,
0.008243420161306858,
-0.012878584675490856,
0.0637679174542427,
0.02499108575284481,
0.1177060678601265,
-0.006109594367444515,
-0.16639398038387299,
-0.027259698137640953,
-0.03850782662630081,
-0.03255351260304451,
0.058724645525217056,
-0.06262534856796265,
-0.0616365410387516,
0.05513925105333328,
0.02923203818500042,
-0.003980972804129124,
0.09278231859207153,
-0.0656878873705864,
-0.05481474846601486,
-0.02291877195239067,
-0.009834264405071735,
-0.0636158287525177,
-0.05084005370736122,
0.04899114370346069,
-0.0013914942974224687,
-0.04618213325738907,
0.01282233465462923,
0.048399418592453,
-0.04009876772761345,
-0.0043804338201880455,
-0.01684887707233429,
0.05468016490340233,
-0.01917782425880432,
0.06672783941030502,
-0.04020560905337334,
-0.0076232654973864555,
0.03575277701020241,
-0.044126514345407486,
0.05778130888938904,
-0.039303168654441833,
0.040357742458581924,
-0.04678100720047951,
0.08739329129457474,
-0.06081612408161163,
0.03974149748682976,
-0.0085669606924057,
-0.022552426904439926,
-0.020810937508940697,
0.09211337566375732,
-0.04798058420419693,
-0.09139615297317505,
-0.005702281836420298,
-0.006227341014891863,
0.01864822395145893,
0.04222261160612106,
-0.016408048570156097,
0.002265605377033353,
0.011358275078237057,
0.010605795308947563,
-0.01641470566391945,
-0.06902331858873367,
-0.07640664279460907,
0.10760858654975891,
0.06474999338388443,
-0.008936634287238121,
-0.03272108733654022,
0.023356517776846886,
-0.010894483886659145,
0.037743158638477325,
0.05661223828792572,
0.03356710448861122,
0.1151229590177536,
-0.0901937261223793,
0.08617163449525833,
0.014368420466780663,
0.03194799646735191,
-0.12436254322528839,
0.02100346051156521,
-0.04561314731836319,
0.002175663597881794,
0.0006810595514252782,
0.008964020758867264,
-0.0009986720979213715,
0.03375696390867233,
0.013721621595323086,
0.10595471411943436,
0.03794354200363159,
0.06642907857894897,
0.024301603436470032,
0.07846131175756454,
0.009065866470336914,
0.027986757457256317,
0.007215932477265596,
0.05977412685751915,
-0.031188717111945152,
0.041543468832969666,
9.15281686700985e-34,
-0.025672681629657745,
0.00388735206797719,
0.05392037704586983,
0.06273551285266876,
-0.011567875742912292,
0.00034880024031735957,
-0.04024496674537659,
-0.03422226756811142,
-0.027781203389167786,
-0.028610166162252426,
-0.08961221575737,
0.037549324333667755,
0.06054672598838806,
-0.041267190128564835,
0.05525602400302887,
0.012784780003130436,
0.06149901822209358,
-0.010856952518224716,
0.056161876767873764,
0.04318011924624443,
0.04294599965214729,
-0.05615675076842308,
-0.006979258731007576,
-0.014645648188889027,
0.008592941798269749,
-0.11031237989664078,
0.07418219745159149,
-0.017961852252483368,
-0.0414801724255085,
-0.044611044228076935,
-0.046482931822538376,
-0.04879668354988098,
0.06581886857748032,
0.11764919757843018,
0.038874559104442596,
0.007777380291372538,
0.01886116899549961,
-0.003716717241331935,
-0.1200636476278305,
-0.051235612481832504,
-0.10163968801498413,
-0.005514905322343111,
-0.018826745450496674,
0.05716360732913017,
0.024499252438545227,
-0.0934239998459816,
-0.08675874769687653,
-0.039427537471055984,
0.09468322992324829,
-0.03597365319728851,
0.015140676870942116,
0.05008627846837044,
0.07814823091030121,
0.020356548950076103,
0.06772410869598389,
0.026868911460042,
0.08275169879198074,
0.03264304995536804,
0.0017035759519785643,
0.014685677364468575,
0.01205369457602501,
-0.004403529688715935,
-0.015274915844202042,
-0.021293915808200836,
0.01562490500509739,
0.015536786988377571,
-0.02431115135550499,
0.015267186798155308,
0.02171161212027073,
0.012657367624342442,
0.010229024104773998,
-0.04316682368516922,
-0.11605993658304214,
-0.006716625299304724,
0.012333233840763569,
-0.055261868983507156,
-0.059109121561050415,
-0.010472152382135391,
0.02067081816494465,
-0.1060638278722763,
0.03303532302379608,
-0.06971387565135956,
-0.05936694145202637,
0.06681788712739944,
-0.061342015862464905,
-0.008154942654073238,
-0.0006970724207349122,
-0.004068904090672731,
-0.0005889554158784449,
0.003928704187273979,
-0.047292400151491165,
0.0025619103107601404,
-0.028679268434643745,
-0.047341760247945786,
0.03333229571580887,
-3.104111401827106e-33,
-0.03819704055786133,
0.07325997948646545,
-0.053176507353782654,
0.13023599982261658,
-0.03817388042807579,
-0.05421138182282448,
0.09347754716873169,
0.04289612919092178,
0.004889028146862984,
0.0028897414449602365,
-0.10137028992176056,
-0.014826239086687565,
0.03963563218712807,
0.015169822610914707,
-0.0352260060608387,
-0.005324267782270908,
-0.10291893780231476,
-0.013468907214701176,
0.012966977432370186,
-0.015925724059343338,
-0.020855508744716644,
0.041428010910749435,
0.03620343655347824,
0.027048062533140182,
-0.10771650820970535,
0.05812940001487732,
0.022824054583907127,
-0.042816583067178726,
-0.029570404440164566,
-0.044812723994255066,
-0.02640550769865513,
0.03559962287545204,
-0.0036857021041214466,
0.04212438687682152,
0.0003660015354398638,
-0.09909979999065399,
0.07005397975444794,
0.07867800444364548,
0.08557992428541183,
-0.0034566777758300304,
0.05709812045097351,
0.06214515119791031,
0.005447051487863064,
0.04446146637201309,
-0.001353037660010159,
-0.02510744147002697,
-0.015190050937235355,
0.015097015537321568,
0.06289709359407425,
-0.01770983263850212,
-0.06695164740085602,
-0.04793550446629524,
-0.002181338844820857,
0.05061517655849457,
-0.06087806448340416,
-0.0813387930393219,
-0.09360331296920776,
-0.012887765653431416,
-0.03529967740178108,
0.06383819133043289,
-0.06715288013219833,
-0.039131272584199905,
0.034751854836940765,
0.046363282948732376,
0.017516829073429108,
-0.08915921300649643,
-0.07379811257123947,
-0.08032090216875076,
0.09696350246667862,
-0.018221961334347725,
0.028087254613637924,
0.01755942590534687,
-0.06258776783943176,
0.016342783346772194,
0.032605379819869995,
0.014760488644242287,
-0.02004224807024002,
-0.011876988224685192,
0.04782293364405632,
0.09820055216550827,
0.035468656569719315,
-0.001220376812852919,
0.013005241751670837,
0.10678385198116302,
-0.05778184160590172,
-0.0017731229308992624,
0.03735486418008804,
0.04568159207701683,
-0.057673316448926926,
0.01600482687354088,
0.08685445040464401,
0.06645330786705017,
-0.08180289715528488,
-0.05083868280053139,
-0.008015782572329044,
-5.2609390621682905e-8,
-0.08678217977285385,
-0.07324039191007614,
-0.043269459158182144,
-0.03642849251627922,
-0.05676717311143875,
0.013661075383424759,
0.0356169268488884,
-0.14118948578834534,
0.08634378015995026,
-0.0257936529815197,
-0.04614941403269768,
-0.005465625785291195,
-0.04005403444170952,
-0.11723893880844116,
-0.011926913633942604,
-0.02378174290060997,
-0.047511983662843704,
-0.04941172897815704,
-0.019631316885352135,
0.046941518783569336,
0.026519866660237312,
-0.014576176181435585,
-0.06637652218341827,
0.05448831617832184,
0.030868668109178543,
-0.005133390426635742,
0.029540399089455605,
0.05194900557398796,
-0.04526747390627861,
0.004224499687552452,
0.03032609075307846,
-0.004620619583874941,
0.07851362973451614,
-0.03524290397763252,
-0.08623864501714706,
0.062195613980293274,
0.06543049961328506,
0.0008569937199354172,
0.018576249480247498,
0.05685469135642052,
0.0003727138682734221,
-0.019514182582497597,
-0.029281653463840485,
-0.04163108393549919,
-0.015213599428534508,
-0.050818026065826416,
0.06405230611562729,
0.01657472550868988,
-0.015013463795185089,
-0.04357627406716347,
0.021086212247610092,
-0.01880628801882267,
-0.06990712881088257,
0.009601231664419174,
-0.0632719174027443,
-0.01938675157725811,
-0.03820531815290451,
-0.01055932603776455,
0.0007383623160421848,
0.03029497154057026,
0.13214442133903503,
0.07325473427772522,
0.09906645119190216,
-0.047856684774160385
] | 0.091056 |
= 'bar'; err.info = { nested: true, baz: 'text', }; err.reg = /abc/i; assert.throws( () => { throw err; }, { name: 'TypeError', message: 'Wrong value', info: { nested: true, baz: 'text', }, // Only properties on the validation object will be tested for. // Using nested objects requires all properties to be present. Otherwise // the validation is going to fail. }, ); // Using regular expressions to validate error properties: assert.throws( () => { throw err; }, { // The `name` and `message` properties are strings and using regular // expressions on those will match against the string. If they fail, an // error is thrown. name: /^TypeError$/, message: /Wrong/, foo: 'bar', info: { nested: true, // It is not possible to use regular expressions for nested properties! baz: 'text', }, // The `reg` property contains a regular expression and only if the // validation object contains an identical regular expression, it is going // to pass. reg: /abc/i, }, ); // Fails due to the different `message` and `name` properties: assert.throws( () => { const otherErr = new Error('Not found'); // Copy all enumerable properties from `err` to `otherErr`. for (const [key, value] of Object.entries(err)) { otherErr[key] = value; } throw otherErr; }, // The error's `message` and `name` properties will also be checked when using // an error as validation object. err, ); ``` ```cjs const assert = require('node:assert/strict'); const err = new TypeError('Wrong value'); err.code = 404; err.foo = 'bar'; err.info = { nested: true, baz: 'text', }; err.reg = /abc/i; assert.throws( () => { throw err; }, { name: 'TypeError', message: 'Wrong value', info: { nested: true, baz: 'text', }, // Only properties on the validation object will be tested for. // Using nested objects requires all properties to be present. Otherwise // the validation is going to fail. }, ); // Using regular expressions to validate error properties: assert.throws( () => { throw err; }, { // The `name` and `message` properties are strings and using regular // expressions on those will match against the string. If they fail, an // error is thrown. name: /^TypeError$/, message: /Wrong/, foo: 'bar', info: { nested: true, // It is not possible to use regular expressions for nested properties! baz: 'text', }, // The `reg` property contains a regular expression and only if the // validation object contains an identical regular expression, it is going // to pass. reg: /abc/i, }, ); // Fails due to the different `message` and `name` properties: assert.throws( () => { const otherErr = new Error('Not found'); // Copy all enumerable properties from `err` to `otherErr`. for (const [key, value] of Object.entries(err)) { otherErr[key] = value; } throw otherErr; }, // The error's `message` and `name` properties will also be checked when using // an error as validation object. err, ); ``` Validate instanceof using constructor: ```mjs import assert from 'node:assert/strict'; assert.throws( () => { throw new Error('Wrong value'); }, Error, ); ``` ```cjs const assert = require('node:assert/strict'); assert.throws( () => { throw new Error('Wrong value'); }, Error, ); ``` Validate error message using {RegExp}: Using a regular expression runs `.toString` on the error object, and will therefore also include the error name. ```mjs import assert from 'node:assert/strict'; assert.throws( () => { throw new Error('Wrong value'); }, /^Error: Wrong value$/, ); ``` ```cjs const assert = require('node:assert/strict'); assert.throws( () => { throw new Error('Wrong value'); }, /^Error: Wrong value$/, ); ``` Custom error validation: The function must return `true` to indicate all internal validations passed. It will otherwise fail with an [`AssertionError`][]. ```mjs import assert from 'node:assert/strict'; assert.throws( () => { | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.03657836839556694,
0.14123980700969696,
0.0971410796046257,
0.0663779079914093,
0.00997986365109682,
-0.03359198570251465,
0.02936812862753868,
-0.011327886022627354,
0.015117944218218327,
-0.006643474567681551,
-0.044131800532341,
-0.05896296352148056,
0.02649059146642685,
0.09706930816173553,
0.10479069501161575,
0.04279068484902382,
-0.0785486251115799,
0.0501108281314373,
-0.03758871182799339,
-0.011616067960858345,
0.06794261932373047,
0.0017356871394440532,
0.033104751259088516,
-0.003270834218710661,
-0.04015764594078064,
0.04624620079994202,
-0.024060167372226715,
0.0028092425782233477,
0.015878992155194283,
-0.01876499131321907,
0.03563739359378815,
-0.053412385284900665,
-0.002489676931872964,
0.04762653261423111,
0.001225425978191197,
-0.018748395144939423,
0.009476644918322563,
0.041755907237529755,
-0.013643545098602772,
0.024600021541118622,
0.01732376590371132,
0.048164982348680496,
0.017363499850034714,
-0.10011258721351624,
0.07084251940250397,
-0.04408162459731102,
-0.011385471560060978,
0.008905507624149323,
-0.023424727842211723,
-0.013586370274424553,
0.008532739244401455,
-0.038915008306503296,
0.006772876717150211,
0.019941406324505806,
0.0709693655371666,
0.034435030072927475,
0.011444373987615108,
-0.05315869301557541,
0.10078959912061691,
-0.02135384827852249,
0.09901849925518036,
-0.0665426254272461,
0.01116121094673872,
-0.05055373162031174,
0.013638012111186981,
-0.025548120960593224,
0.006173003930598497,
0.04853799194097519,
-0.014489442110061646,
0.08945911377668381,
0.028167543932795525,
0.014986169524490833,
0.028494054451584816,
0.08111946284770966,
-0.009254411794245243,
-0.011897125281393528,
-0.049673352390527725,
-0.012061216868460178,
0.014722508378326893,
0.03343525156378746,
-0.11577532440423965,
-0.06563044339418411,
-0.04460884630680084,
0.00028593672323040664,
0.04625067114830017,
0.07248709350824356,
-0.018631011247634888,
0.0423768013715744,
-0.05892679840326309,
-0.0009549772366881371,
0.011502888053655624,
-0.14166292548179626,
0.042109910398721695,
0.09009259194135666,
0.04433615133166313,
0.012400827370584011,
-0.08017998933792114,
-0.11811402440071106,
0.0458056814968586,
0.0328516811132431,
0.032323144376277924,
-0.03404397889971733,
0.040768351405858994,
-0.0621710829436779,
0.06854873895645142,
0.05038836970925331,
0.0029352917335927486,
-0.04545661062002182,
-0.03266855701804161,
0.08828121423721313,
0.0038891611620783806,
0.031129317358136177,
0.02744346298277378,
0.016895830631256104,
-0.03876330703496933,
-0.027224956080317497,
0.010626754723489285,
-0.004000818356871605,
0.01970226876437664,
0.06419064104557037,
0.0712452232837677,
-0.010729442350566387,
0.08816645294427872,
-0.04412117227911949,
0.11134625971317291,
-0.00589365791529417,
-0.006469531450420618,
1.772166834434034e-33,
0.002197826746851206,
0.04609385132789612,
-0.07217145711183548,
0.07283147424459457,
-0.014132347889244556,
0.04878342151641846,
-0.10177095979452133,
0.010220140218734741,
-0.02174026519060135,
-0.023215515539050102,
-0.008056259714066982,
-0.016460375860333443,
-0.008581086993217468,
-0.10094372183084488,
0.05904527008533478,
0.05514651909470558,
0.023136768490076065,
-0.019495276734232903,
0.004551400430500507,
0.000123251011245884,
-0.013925543986260891,
-0.06711151450872421,
-0.049277324229478836,
-0.0003346251032780856,
-0.003194627119228244,
-0.04327848181128502,
0.030086804181337357,
0.0011682508047670126,
-0.060391657054424286,
-0.03739459067583084,
0.05227556452155113,
-0.07783044874668121,
0.10099540650844574,
0.07437581568956375,
0.04568951204419136,
0.0330684669315815,
0.06865577399730682,
0.000689809035975486,
-0.06157340854406357,
-0.027237419039011,
-0.06097641587257385,
-0.04717002809047699,
-0.07052291929721832,
0.07730641216039658,
0.0028416914865374565,
-0.08418579399585724,
0.005625567864626646,
-0.04897616431117058,
0.09119129180908203,
-0.04849783703684807,
-0.011088448576629162,
0.024587376043200493,
0.020626315847039223,
0.023865869268774986,
0.01686720736324787,
0.07002409547567368,
-0.0028705080039799213,
0.05486564338207245,
0.016368838027119637,
-0.02597079984843731,
0.017872028052806854,
0.012914000079035759,
-0.02472384087741375,
-0.04310956224799156,
-0.05859285220503807,
-0.025752458721399307,
0.01740548387169838,
-0.0005819054204039276,
-0.05720812454819679,
-0.10448164492845535,
0.02683536522090435,
-0.021583715453743935,
-0.06105669215321541,
0.03584218770265579,
0.022044846788048744,
-0.06432592868804932,
0.01933382824063301,
0.06774923950433731,
-0.026176320388913155,
-0.08181013911962509,
0.03149197995662689,
-0.07406843453645706,
-0.040566880255937576,
0.15000741183757782,
-0.09370424598455429,
0.06702660769224167,
0.02759384550154209,
-0.003336972324177623,
-0.01675753854215145,
0.01886618323624134,
-0.0383792482316494,
-0.04846992343664169,
-0.08769114315509796,
-0.046479832381010056,
0.012183277867734432,
-1.867172308248407e-33,
0.018537934869527817,
0.015859059989452362,
0.0016933380393311381,
0.03844907134771347,
0.02046988531947136,
-0.09784525632858276,
0.033227045089006424,
0.024545352905988693,
-0.05270547419786453,
-0.07726628333330154,
-0.03584573417901993,
-0.07717004418373108,
0.021939745172858238,
-0.00870579108595848,
-0.03960477560758591,
0.017226269468665123,
-0.08712582290172577,
-0.056959427893161774,
0.07412800192832947,
-0.04331837594509125,
0.06351961195468903,
-0.00392485037446022,
-0.003642977913841605,
0.021189751103520393,
-0.09239223599433899,
0.01140138041228056,
-0.03230447322130203,
0.032322902232408524,
-0.0035393431317061186,
0.04508685693144798,
0.03380418196320534,
0.05625048652291298,
0.058660734444856644,
0.020639438182115555,
-0.012133673764765263,
-0.13709042966365814,
0.06126238778233528,
0.020000040531158447,
-0.037328559905290604,
-0.018440794199705124,
0.07255671918392181,
0.07215404510498047,
-0.05027628690004349,
-0.04569123312830925,
0.0143637889996171,
0.02795136533677578,
0.06679805368185043,
-0.05435528978705406,
-0.0018256371840834618,
-0.041703205555677414,
-0.000739856215659529,
-0.07122248411178589,
-0.05130195617675781,
0.07673010230064392,
-0.04059914872050285,
-0.037862036377191544,
-0.012873748317360878,
-0.05246106535196304,
-0.034361112862825394,
0.10079193115234375,
-0.09310461580753326,
-0.008712132461369038,
0.07686024159193039,
0.10969207435846329,
0.01448780670762062,
-0.028802867978811264,
-0.06355705112218857,
-0.018853794783353806,
0.07225484400987625,
-0.055718302726745605,
-0.026308683678507805,
-0.0064406185410916805,
-0.03135787323117256,
0.027200907468795776,
0.023108234629034996,
0.034650471061468124,
-0.011498097330331802,
-0.05124324560165405,
0.08284414559602737,
0.011656193993985653,
0.013834334909915924,
-0.0178837850689888,
0.006587107665836811,
0.1028347983956337,
-0.009841075167059898,
0.011099417693912983,
-0.018798211589455605,
0.08779096603393555,
-0.04216644540429115,
0.029994038864970207,
0.009428170509636402,
0.01732890121638775,
-0.0029001266229897738,
-0.07145573943853378,
-0.0005436180508695543,
-4.734135217177027e-8,
-0.13937494158744812,
-0.01854006201028824,
0.0041095176711678505,
-0.006371938623487949,
-0.05417375639081001,
-0.012815283611416817,
0.048566725105047226,
-0.0972009226679802,
0.05938052386045456,
-0.03893190249800682,
-0.042109061032533646,
0.03765493258833885,
-0.07261043787002563,
-0.07742640376091003,
-0.0020349237602204084,
-0.009252548217773438,
0.010644571855664253,
0.05720352381467819,
-0.01797456666827202,
0.11425966769456863,
0.059044260531663895,
0.017163045704364777,
0.015167713165283203,
0.05989987775683403,
0.03034237213432789,
-0.002016804413869977,
0.028068574145436287,
0.007828371599316597,
-0.04844251275062561,
-0.014084297232329845,
-0.0678497850894928,
0.030917035415768623,
0.061901696026325226,
0.05575328692793846,
-0.05146656185388565,
0.07646242529153824,
0.015349357388913631,
-0.022495031356811523,
0.03496392443776131,
0.08524549007415771,
0.06719111651182175,
-0.050117503851652145,
-0.05285178869962692,
-0.07102867215871811,
-0.0031279027462005615,
-0.02307216078042984,
-0.04206857457756996,
-0.029707297682762146,
0.03905567154288292,
-0.06204874813556671,
0.08237668126821518,
-0.03673745319247246,
-0.07853908836841583,
0.012114438228309155,
-0.10401058197021484,
-0.007687816396355629,
-0.01957849971950054,
0.01787635311484337,
-0.008369718678295612,
-0.018806157633662224,
0.12016525864601135,
0.013504945673048496,
0.04823039844632149,
-0.04549047723412514
] | 0.000133 |
``` ```cjs const assert = require('node:assert/strict'); assert.throws( () => { throw new Error('Wrong value'); }, /^Error: Wrong value$/, ); ``` Custom error validation: The function must return `true` to indicate all internal validations passed. It will otherwise fail with an [`AssertionError`][]. ```mjs import assert from 'node:assert/strict'; assert.throws( () => { throw new Error('Wrong value'); }, (err) => { assert(err instanceof Error); assert(/value/.test(err)); // Avoid returning anything from validation functions besides `true`. // Otherwise, it's not clear what part of the validation failed. Instead, // throw an error about the specific validation that failed (as done in this // example) and add as much helpful debugging information to that error as // possible. return true; }, 'unexpected error', ); ``` ```cjs const assert = require('node:assert/strict'); assert.throws( () => { throw new Error('Wrong value'); }, (err) => { assert(err instanceof Error); assert(/value/.test(err)); // Avoid returning anything from validation functions besides `true`. // Otherwise, it's not clear what part of the validation failed. Instead, // throw an error about the specific validation that failed (as done in this // example) and add as much helpful debugging information to that error as // possible. return true; }, 'unexpected error', ); ``` `error` cannot be a string. If a string is provided as the second argument, then `error` is assumed to be omitted and the string will be used for `message` instead. This can lead to easy-to-miss mistakes. Using the same message as the thrown error message is going to result in an `ERR\_AMBIGUOUS\_ARGUMENT` error. Please read the example below carefully if using a string as the second argument gets considered: ```mjs import assert from 'node:assert/strict'; function throwingFirst() { throw new Error('First'); } function throwingSecond() { throw new Error('Second'); } function notThrowing() {} // The second argument is a string and the input function threw an Error. // The first case will not throw as it does not match for the error message // thrown by the input function! assert.throws(throwingFirst, 'Second'); // In the next example the message has no benefit over the message from the // error and since it is not clear if the user intended to actually match // against the error message, Node.js throws an `ERR\_AMBIGUOUS\_ARGUMENT` error. assert.throws(throwingSecond, 'Second'); // TypeError [ERR\_AMBIGUOUS\_ARGUMENT] // The string is only used (as message) in case the function does not throw: assert.throws(notThrowing, 'Second'); // AssertionError [ERR\_ASSERTION]: Missing expected exception: Second // If it was intended to match for the error message do this instead: // It does not throw because the error messages match. assert.throws(throwingSecond, /Second$/); // If the error message does not match, an AssertionError is thrown. assert.throws(throwingFirst, /Second$/); // AssertionError [ERR\_ASSERTION] ``` ```cjs const assert = require('node:assert/strict'); function throwingFirst() { throw new Error('First'); } function throwingSecond() { throw new Error('Second'); } function notThrowing() {} // The second argument is a string and the input function threw an Error. // The first case will not throw as it does not match for the error message // thrown by the input function! assert.throws(throwingFirst, 'Second'); // In the next example the message has no benefit over the message from the // error and since it is not clear if the user intended to actually match // against the error message, Node.js throws an `ERR\_AMBIGUOUS\_ARGUMENT` error. assert.throws(throwingSecond, 'Second'); // TypeError [ERR\_AMBIGUOUS\_ARGUMENT] // The string is only used (as message) in case the function does not throw: assert.throws(notThrowing, 'Second'); // AssertionError [ERR\_ASSERTION]: Missing expected exception: Second // If it was intended to match for the error message do this instead: // It does not throw because the error messages match. assert.throws(throwingSecond, /Second$/); // If the error message does | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.05191668123006821,
0.0728180930018425,
0.07437644153833389,
0.06111364811658859,
0.04754263907670975,
-0.03726969659328461,
0.007631555199623108,
0.04268598556518555,
-0.029934274032711983,
-0.030910607427358627,
-0.003841801080852747,
-0.047188833355903625,
0.06519291549921036,
0.018134476616978645,
0.035789236426353455,
-0.03834618628025055,
-0.03285077214241028,
0.11101662367582321,
0.04606403782963753,
-0.06055431813001633,
0.010886975564062595,
-0.023844711482524872,
-0.01825420744717121,
0.04596664011478424,
-0.05859587714076042,
-0.07354264706373215,
-0.03976178169250488,
0.02078437991440296,
0.014557368122041225,
-0.031993672251701355,
0.05398901179432869,
-0.011716864071786404,
-0.06260073930025101,
0.06378605216741562,
0.034922316670417786,
0.11925463378429413,
-0.06927885115146637,
-0.055525042116642,
-0.007690811064094305,
-0.01571143977344036,
-0.0237300805747509,
0.08161390572786331,
0.003224140265956521,
-0.030566208064556122,
0.07209121435880661,
-0.03763354569673538,
-0.028065554797649384,
0.05372118577361107,
-0.044899534434080124,
0.00592548493295908,
-0.013787329196929932,
0.02424706518650055,
-0.04764840006828308,
-0.03612569719552994,
0.014357172884047031,
-0.01541068498045206,
0.02007605880498886,
-0.0010081561049446464,
0.05737949535250664,
0.06465351581573486,
0.05438782274723053,
-0.037133581936359406,
0.07152225077152252,
-0.020649928599596024,
0.05595804750919342,
-0.04971785470843315,
-0.030109958723187447,
0.04732215031981468,
-0.022650206461548805,
0.13065506517887115,
-0.011783570982515812,
0.011531416326761246,
-0.02730354107916355,
0.08703906089067459,
-0.0661875456571579,
-0.019493022933602333,
-0.055550482124090195,
0.019557597115635872,
-0.02558484859764576,
0.08480818569660187,
-0.092563696205616,
-0.019216196611523628,
-0.007804664317518473,
-0.03920299932360649,
0.055380675941705704,
0.0742407813668251,
-0.03542286530137062,
0.03626342490315437,
-0.02315511368215084,
0.03351505473256111,
0.02315598540008068,
-0.07900889962911606,
-0.1256454437971115,
0.09794827550649643,
0.09303049743175507,
-0.01747051440179348,
0.012390163727104664,
-0.040151920169591904,
0.03954156115651131,
0.005256644915789366,
0.0065193078480660915,
-0.012265905737876892,
0.050159767270088196,
-0.07880087196826935,
0.05916893109679222,
0.026771478354930878,
0.0022593005560338497,
-0.11760637909173965,
-0.00022213198826648295,
-0.005024875979870558,
0.006259218789637089,
-0.007678214926272631,
-0.01589779555797577,
-0.037795666605234146,
0.03615356981754303,
0.039157141000032425,
0.09268248826265335,
-0.015336166135966778,
0.02363625541329384,
0.07743806391954422,
-0.015635455027222633,
-0.0053895991295576096,
0.11489898711442947,
-0.0017538170795887709,
0.06856522709131241,
-0.05165673792362213,
0.010501581244170666,
2.5409280175863173e-33,
-0.001213636016473174,
-0.009489206597208977,
-0.015196963213384151,
0.05635128170251846,
-0.024989353492856026,
0.025725992396473885,
-0.018505766987800598,
0.013315550051629543,
-0.09486664086580276,
-0.03460472449660301,
0.019718918949365616,
-0.018092120066285133,
0.0130362119525671,
-0.05941115319728851,
0.03751387447118759,
0.059078335762023926,
0.07135706394910812,
-0.052905019372701645,
0.028994515538215637,
0.014999082311987877,
0.016855763271450996,
-0.10310183465480804,
-0.010415060445666313,
-0.028105339035391808,
-0.016812823712825775,
-0.050392407923936844,
0.024499844759702682,
0.03609578683972359,
-0.01178545132279396,
-0.03916148096323013,
-0.0023684543557465076,
-0.015950575470924377,
0.0831935703754425,
0.08467471599578857,
0.040580399334430695,
0.00213467120192945,
0.02726205252110958,
0.027036406099796295,
-0.08239682018756866,
-0.059191033244132996,
-0.10259264707565308,
0.03885095566511154,
-0.03156476467847824,
0.07380616664886475,
0.043513182550668716,
-0.09721624851226807,
-0.04363551735877991,
-0.033773262053728104,
0.08954372256994247,
-0.018140193074941635,
0.005754183046519756,
0.0932929515838623,
0.0502975769340992,
-0.03594046086072922,
0.034467872232198715,
0.043243806809186935,
-0.0060871965251863,
-0.001477899495512247,
-0.023570550605654716,
-0.04082586243748665,
0.06686815619468689,
-0.04627546668052673,
-0.08325964957475662,
-0.011719993315637112,
-0.0645865947008133,
0.008319027721881866,
-0.035593658685684204,
0.01802116446197033,
-0.017512330785393715,
-0.023045631125569344,
-0.030257023870944977,
-0.06881460547447205,
-0.07347497344017029,
-0.01599610410630703,
0.013254181481897831,
-0.03304094821214676,
-0.0268672164529562,
0.018254488706588745,
-0.010763525031507015,
-0.15558449923992157,
0.05107831954956055,
-0.04707864299416542,
-0.07339745759963989,
0.09873361140489578,
-0.004907398484647274,
0.04609524831175804,
-0.006619355641305447,
0.013036539778113365,
0.059208545833826065,
0.03647715598344803,
-0.01284321304410696,
-0.02366718277335167,
-0.029882879927754402,
-0.05018789321184158,
-0.058150116354227066,
-4.630560978688911e-33,
0.011566742323338985,
0.1303984373807907,
-0.005637157242745161,
0.1162334680557251,
-0.007709477096796036,
-0.06728750467300415,
0.038929615169763565,
0.0014499457320198417,
-0.04487090930342674,
0.011589371599256992,
-0.06644703447818756,
-0.047304462641477585,
0.05563840642571449,
0.07979699969291687,
-0.06011960282921791,
0.00897974707186222,
-0.1332753449678421,
-0.023483967408537865,
0.0006959160091355443,
-0.005501491483300924,
0.025608759373426437,
-0.0067302207462489605,
0.07479026168584824,
-0.013372532092034817,
-0.10000814497470856,
0.07918579876422882,
-0.0482010655105114,
-0.008059563115239143,
-0.013334770686924458,
0.007143388967961073,
-0.014708388596773148,
0.06872536987066269,
-0.014798256568610668,
0.059968844056129456,
0.09493923932313919,
-0.10414239019155502,
0.04122696444392204,
0.024669703096151352,
0.019251685589551926,
0.0038508870638906956,
0.0771767869591713,
0.0403369665145874,
-0.04535505920648575,
-0.05216425284743309,
-0.0002917704696301371,
-0.03362959250807762,
0.03889787197113037,
-0.016088834032416344,
-0.01409390103071928,
-0.047062866389751434,
-0.07045339047908783,
-0.08097831159830093,
-0.04950763285160065,
0.06789305061101913,
-0.045960281044244766,
-0.0285602156072855,
-0.022941499948501587,
0.0335928313434124,
0.03987725079059601,
0.04596855491399765,
-0.08320564031600952,
-0.047780003398656845,
0.008303439244627953,
0.05088776350021362,
-0.03474555164575577,
-0.039896316826343536,
-0.10363122075796127,
0.008157855831086636,
0.07043290138244629,
0.002572066383436322,
-0.0639413446187973,
0.07580185681581497,
-0.02955838292837143,
-0.026428667828440666,
0.0003321274707559496,
0.014989049173891544,
-0.03654488921165466,
-0.06873687356710434,
0.08612790703773499,
0.08703625947237015,
0.05846371501684189,
0.053159214556217194,
0.022864539176225662,
0.060950007289648056,
-0.029583660885691643,
0.021894782781600952,
-0.007119813933968544,
0.00764065096154809,
-0.0578521192073822,
0.01895689032971859,
0.03537643700838089,
0.021405324339866638,
-0.07149790227413177,
-0.08877141028642654,
-0.004037773236632347,
-5.280428894138822e-8,
-0.11600764840841293,
-0.04718296229839325,
-0.010247253812849522,
-0.07414230704307556,
-0.023591486737132072,
-0.06381531804800034,
0.033389363437891006,
-0.08184873312711716,
0.04337436705827713,
-0.0012303834082558751,
-0.016782592982053757,
-0.013762272894382477,
-0.014749146066606045,
-0.05977759510278702,
-0.034525316208601,
-0.004863005597144365,
-0.026455441489815712,
0.03026544488966465,
-0.0018457398982718587,
0.06062336638569832,
0.002285800175741315,
0.004366014152765274,
0.0037548188120126724,
0.09817474335432053,
0.01612567901611328,
-0.0168478861451149,
0.015265321359038353,
0.062193114310503006,
-0.06246044114232063,
-0.01267363503575325,
-0.03458257019519806,
0.00662589818239212,
0.09580348432064056,
-0.003885173937305808,
-0.052052490413188934,
0.08987770974636078,
-0.0018060674192383885,
-0.0010620631510391831,
0.056147485971450806,
0.0651092454791069,
-0.013288335874676704,
0.014031562022864819,
-0.016322430223226547,
-0.017038462683558464,
-0.058885738253593445,
-0.09223855286836624,
-0.019979825243353844,
0.028183141723275185,
-0.014875946566462517,
-0.05884072184562683,
0.026857569813728333,
-0.02027108706533909,
-0.08340805768966675,
0.039567895233631134,
-0.037293944507837296,
-0.008213884197175503,
-0.06394968926906586,
0.015476565808057785,
-0.06361362338066101,
-0.053341660648584366,
0.09423141181468964,
0.09659169614315033,
0.08923310041427612,
-0.0597296841442585
] | 0.044617 |
(as message) in case the function does not throw: assert.throws(notThrowing, 'Second'); // AssertionError [ERR\_ASSERTION]: Missing expected exception: Second // If it was intended to match for the error message do this instead: // It does not throw because the error messages match. assert.throws(throwingSecond, /Second$/); // If the error message does not match, an AssertionError is thrown. assert.throws(throwingFirst, /Second$/); // AssertionError [ERR\_ASSERTION] ``` Due to the confusing error-prone notation, avoid a string as the second argument. ## `assert.partialDeepStrictEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} \* `message` {string|Error|Function} Tests for partial deep equality between the `actual` and `expected` parameters. "Deep" equality means that the enumerable "own" properties of child objects are recursively evaluated also by the following rules. "Partial" equality means that only properties that exist on the `expected` parameter are going to be compared. This method always passes the same test cases as [`assert.deepStrictEqual()`][], behaving as a super set of it. ### Comparison details \* Primitive values are compared using [`Object.is()`][]. \* [Type tags][Object.prototype.toString()] of objects should be the same. \* [`[[Prototype]]`][prototype-spec] of objects are not compared. \* Only [enumerable "own" properties][] are considered. \* {Error} names, messages, causes, and errors are always compared, even if these are not enumerable properties. `errors` is also compared. \* Enumerable own {Symbol} properties are compared as well. \* [Object wrappers][] are compared both as objects and unwrapped values. \* `Object` properties are compared unordered. \* {Map} keys and {Set} items are compared unordered. \* Recursion stops when both sides differ or both sides encounter a circular reference. \* {WeakMap}, {WeakSet} and {Promise} instances are \*\*not\*\* compared structurally. They are only equal if they reference the same object. Any comparison between different `WeakMap`, `WeakSet`, or `Promise` instances will result in inequality, even if they contain the same content. \* {RegExp} lastIndex, flags, and source are always compared, even if these are not enumerable properties. \* Holes in sparse arrays are ignored. ```mjs import assert from 'node:assert'; assert.partialDeepStrictEqual( { a: { b: { c: 1 } } }, { a: { b: { c: 1 } } }, ); // OK assert.partialDeepStrictEqual( { a: 1, b: 2, c: 3 }, { b: 2 }, ); // OK assert.partialDeepStrictEqual( [1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 8], ); // OK assert.partialDeepStrictEqual( new Set([{ a: 1 }, { b: 1 }]), new Set([{ a: 1 }]), ); // OK assert.partialDeepStrictEqual( new Map([['key1', 'value1'], ['key2', 'value2']]), new Map([['key2', 'value2']]), ); // OK assert.partialDeepStrictEqual(123n, 123n); // OK assert.partialDeepStrictEqual( [1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 4, 8], ); // AssertionError assert.partialDeepStrictEqual( { a: 1 }, { a: 1, b: 2 }, ); // AssertionError assert.partialDeepStrictEqual( { a: { b: 2 } }, { a: { b: '2' } }, ); // AssertionError ``` ```cjs const assert = require('node:assert'); assert.partialDeepStrictEqual( { a: { b: { c: 1 } } }, { a: { b: { c: 1 } } }, ); // OK assert.partialDeepStrictEqual( { a: 1, b: 2, c: 3 }, { b: 2 }, ); // OK assert.partialDeepStrictEqual( [1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 8], ); // OK assert.partialDeepStrictEqual( new Set([{ a: 1 }, { b: 1 }]), new Set([{ a: 1 }]), ); // OK assert.partialDeepStrictEqual( new Map([['key1', 'value1'], ['key2', 'value2']]), new Map([['key2', 'value2']]), ); // OK assert.partialDeepStrictEqual(123n, 123n); // OK assert.partialDeepStrictEqual( [1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 4, 8], ); // AssertionError assert.partialDeepStrictEqual( { a: 1 }, { a: 1, b: 2 }, ); // AssertionError assert.partialDeepStrictEqual( { a: { b: 2 } }, { a: { b: '2' | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.0370369553565979,
0.04071494936943054,
0.07270529866218567,
0.05377385765314102,
0.0546984039247036,
-0.036919087171554565,
0.006383241154253483,
0.009924749843776226,
0.0018101498717442155,
-0.03256935626268387,
-0.004143684636801481,
-0.059818871319293976,
0.08237678557634354,
0.03376418352127075,
0.07698709517717361,
-0.0012317982036620378,
-0.016783297061920166,
0.014708471484482288,
0.004470591899007559,
-0.05533907189965248,
0.025484725832939148,
0.03366301208734512,
-0.018331365659832954,
0.03720078617334366,
-0.030631689354777336,
-0.013474163599312305,
-0.03897789865732193,
0.03411194309592247,
-0.03747648745775223,
-0.02494024485349655,
0.015307332389056683,
-0.036045026034116745,
-0.0468231663107872,
0.03680833429098129,
0.06026061996817589,
0.0820712149143219,
-0.013720265589654446,
-0.04947848245501518,
-0.02127315104007721,
-0.027531802654266357,
-0.0027800118550658226,
0.007996244356036186,
-0.03894570842385292,
-0.07598087191581726,
0.025539536029100418,
0.03146573156118393,
-0.012838892638683319,
0.04550832509994507,
-0.06423940509557724,
-0.04587571322917938,
0.05406113341450691,
0.024150921031832695,
0.0005800521466881037,
-0.018953081220388412,
0.07900640368461609,
0.031988419592380524,
0.001667332835495472,
-0.026307132095098495,
0.028658786788582802,
-0.004150694236159325,
0.046193622052669525,
-0.0644724890589714,
0.004842287860810757,
-0.013154259882867336,
0.027967136353254318,
-0.07461576163768768,
0.03659078851342201,
0.03437966853380203,
-0.051900848746299744,
0.15221592783927917,
-0.010962791740894318,
0.05746686831116676,
-0.08768020570278168,
0.11814192682504654,
0.06161472201347351,
0.023155678063631058,
0.03992157801985741,
-0.01639690436422825,
-0.011135783046483994,
-0.02936207503080368,
-0.13570496439933777,
-0.07141262292861938,
-0.01645604893565178,
-0.03842770308256149,
0.039947524666786194,
-0.013825454749166965,
0.005700195673853159,
0.04511053115129471,
0.0002742228680290282,
0.012498533353209496,
-0.024145878851413727,
-0.08433812111616135,
-0.03399918973445892,
0.1688595563173294,
0.10305886715650558,
-0.003425802104175091,
-0.027142036706209183,
-0.05033271759748459,
-0.034278515726327896,
0.037814751267433167,
0.030123356729745865,
0.040811266750097275,
0.08129575103521347,
-0.13843518495559692,
0.07461275160312653,
0.014239148236811161,
0.013702387921512127,
-0.15198302268981934,
-0.026214201003313065,
-0.0654912069439888,
0.005275066010653973,
-0.019985001534223557,
0.07665976136922836,
0.04093150794506073,
0.015607798472046852,
0.0006320149987004697,
0.09154389053583145,
0.006392982788383961,
-0.002677282551303506,
-0.015187016688287258,
0.0803515613079071,
-0.01008259505033493,
0.038024481385946274,
0.0066589792259037495,
0.06947434693574905,
-0.022596929222345352,
-0.016632096841931343,
3.0559727041090257e-33,
0.02722756378352642,
0.0060750520788133144,
0.010850351303815842,
0.07311319559812546,
0.005488889757543802,
0.08009600639343262,
-0.03364166244864464,
-0.011511933989822865,
-0.07875630259513855,
0.02405446395277977,
-0.060729965567588806,
0.023741651326417923,
-0.003340186318382621,
-0.04548245295882225,
0.04596710205078125,
0.07634871453046799,
0.010069931857287884,
0.00856807827949524,
0.023215360939502716,
0.06895709782838821,
-0.007924837991595268,
-0.07164618372917175,
-0.05119824409484863,
0.0003914792032446712,
-0.0491713285446167,
-0.047920212149620056,
0.030870240181684494,
-0.010278902016580105,
0.000796025269664824,
-0.044763702899217606,
-0.006890594027936459,
-0.0414758063852787,
0.026775004342198372,
0.12248022109270096,
0.023571670055389404,
-0.03843019902706146,
0.08643804490566254,
-0.00901501439511776,
-0.08738308399915695,
-0.01334107294678688,
-0.07788784801959991,
-0.011558630503714085,
-0.02689816616475582,
0.037931617349386215,
0.02621893398463726,
-0.15036512911319733,
-0.08845020830631256,
0.004755155183374882,
0.13561461865901947,
0.03641129657626152,
0.06373865902423859,
0.0763792097568512,
0.11207984387874603,
-0.040754277259111404,
0.03545721247792244,
0.023807959631085396,
-0.05777563527226448,
0.0694553479552269,
0.029091743752360344,
-0.005074521526694298,
0.06109553575515747,
-0.04802151769399643,
-0.013830317184329033,
-0.03797609731554985,
-0.04906829074025154,
0.007070285268127918,
-0.03507858142256737,
0.004750867374241352,
-0.027994683012366295,
-0.032482706010341644,
-0.008302433416247368,
-0.03761903569102287,
-0.0765380859375,
0.024440519511699677,
0.07110092788934708,
-0.1191989928483963,
0.012009898200631142,
0.006573960185050964,
0.043955788016319275,
-0.1003652960062027,
0.010171844623982906,
-0.0070875585079193115,
-0.043361879885196686,
0.05098780617117882,
-0.11342883110046387,
0.016145963221788406,
-0.007949660532176495,
-0.03875182941555977,
-0.008381575345993042,
-0.024869784712791443,
-0.0916338786482811,
-0.003342964453622699,
-0.04344969615340233,
-0.008773958310484886,
0.04013196751475334,
-5.3272320320411406e-33,
0.008823039941489697,
0.08673809468746185,
-0.01653413474559784,
0.10929775983095169,
-0.007386466488242149,
-0.06150203198194504,
0.09180029481649399,
0.030368905514478683,
-0.024006173014640808,
-0.04924117028713226,
-0.05522753298282623,
-0.05819866806268692,
0.014285976998507977,
-0.0047202203422784805,
-0.0202029962092638,
-0.012964041903614998,
-0.08040549606084824,
-0.05755595117807388,
0.02869734913110733,
-0.04438203573226929,
0.1112343817949295,
0.053263358771800995,
0.026308508589863777,
-0.0116307083517313,
-0.0767512395977974,
0.009412255138158798,
-0.004450656473636627,
-0.03245081380009651,
0.013411631807684898,
0.007641968317329884,
0.038550205528736115,
0.0298375952988863,
-0.007911096327006817,
0.02454085275530815,
0.015993308275938034,
-0.13434521853923798,
0.10617124289274216,
0.027631962671875954,
-0.0031015975400805473,
0.01339553389698267,
0.06685636192560196,
0.024455854669213295,
-0.008074373938143253,
0.007698859088122845,
0.032833024859428406,
-0.0016549049178138375,
0.07065700739622116,
-0.041084472090005875,
0.033854708075523376,
-0.029628831893205643,
0.024653848260641098,
-0.04072758927941322,
-0.02445279248058796,
0.1212233304977417,
-0.007844210602343082,
-0.05345620959997177,
-0.046927280724048615,
-0.0012644617818295956,
-0.029899481683969498,
0.04467974603176117,
-0.09401632845401764,
0.018750911578536034,
0.02766544744372368,
0.03242868930101395,
-0.03809027001261711,
-0.020398709923028946,
-0.07476232945919037,
-0.008520148694515228,
0.07867050170898438,
0.006868279539048672,
-0.05601486563682556,
-0.01911712810397148,
-0.10437935590744019,
-0.04691236838698387,
0.048229169100522995,
0.04269498586654663,
-0.01770021766424179,
-0.05133746191859245,
0.05444767698645592,
0.06855612993240356,
0.0144618796184659,
-0.05356334149837494,
0.040345244109630585,
0.040495313704013824,
-0.03544881194829941,
-0.020910147577524185,
0.05683569982647896,
0.02270415797829628,
-0.07598084956407547,
0.05950015038251877,
0.04712206870317459,
0.01630827598273754,
-0.023766105994582176,
-0.020953014492988586,
0.023185396566987038,
-5.438325700879432e-8,
-0.08822258561849594,
-0.028912674635648727,
-0.04791439324617386,
-0.07507825642824173,
-0.07173987478017807,
-0.008221869356930256,
0.008718330413103104,
-0.07597038894891739,
0.017930081114172935,
-0.04649749770760536,
-0.0181216262280941,
-0.006240767892450094,
0.008330334909260273,
-0.0547633171081543,
-0.005396504420787096,
-0.032243043184280396,
-0.021297641098499298,
-0.01758662983775139,
-0.011324585415422916,
0.08909283578395844,
0.0174082163721323,
0.04295506700873375,
-0.04225097969174385,
-0.010982658714056015,
-0.02960665337741375,
-0.008717820979654789,
0.07643821090459824,
0.0272030308842659,
-0.09111297130584717,
-0.043455589562654495,
-0.00839014071971178,
-0.03350410237908363,
0.053761258721351624,
-0.0789288878440857,
-0.060236137360334396,
0.10705864429473877,
-0.00731999147683382,
0.010476105846464634,
0.025676202028989792,
0.008567782118916512,
-0.047995761036872864,
-0.015570851974189281,
-0.00872991792857647,
-0.040904950350522995,
-0.012039735913276672,
-0.12015573680400848,
-0.03987112268805504,
-0.0011713524581864476,
-0.023785242810845375,
-0.035458240658044815,
0.020382892340421677,
-0.0016206522705033422,
-0.024524059146642685,
-0.0000761560004320927,
-0.04846026003360748,
0.04770321771502495,
-0.0033241519704461098,
-0.03752504661679268,
-0.0502701960504055,
0.021702749654650688,
0.13476143777370453,
0.07456313073635101,
0.03511090949177742,
-0.028089553117752075
] | 0.020969 |
); // OK assert.partialDeepStrictEqual(123n, 123n); // OK assert.partialDeepStrictEqual( [1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 4, 8], ); // AssertionError assert.partialDeepStrictEqual( { a: 1 }, { a: 1, b: 2 }, ); // AssertionError assert.partialDeepStrictEqual( { a: { b: 2 } }, { a: { b: '2' } }, ); // AssertionError ``` [Object wrappers]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data\_structures#primitive\_values [Object.prototype.toString()]: https://tc39.github.io/ecma262/#sec-object.prototype.tostring [`!=` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Inequality [`===` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict\_equality [`==` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality [`AssertionError`]: #class-assertassertionerror [`Class`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes [`ERR\_INVALID\_RETURN\_VALUE`]: errors.md#err\_invalid\_return\_value [`Object.is()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Object/is [`assert.deepEqual()`]: #assertdeepequalactual-expected-message [`assert.deepStrictEqual()`]: #assertdeepstrictequalactual-expected-message [`assert.doesNotThrow()`]: #assertdoesnotthrowfn-error-message [`assert.equal()`]: #assertequalactual-expected-message [`assert.notDeepEqual()`]: #assertnotdeepequalactual-expected-message [`assert.notDeepStrictEqual()`]: #assertnotdeepstrictequalactual-expected-message [`assert.notEqual()`]: #assertnotequalactual-expected-message [`assert.notStrictEqual()`]: #assertnotstrictequalactual-expected-message [`assert.ok()`]: #assertokvalue-message [`assert.strictEqual()`]: #assertstrictequalactual-expected-message [`assert.throws()`]: #assertthrowsfn-error-message [`getColorDepth()`]: tty.md#writestreamgetcolordepthenv [`util.format()`]: util.md#utilformatformat-args [enumerable "own" properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Enumerability\_and\_ownership\_of\_properties [prototype-spec]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots | https://github.com/nodejs/node/blob/main//doc/api/assert.md | main | nodejs | [
-0.07054631412029266,
0.09550713747739792,
0.06796392053365707,
0.021612675860524178,
-0.030096527189016342,
0.0167288389056921,
-0.03649488463997841,
-0.025156186893582344,
-0.011246934533119202,
-0.007621750235557556,
-0.07332409918308258,
-0.03930448368191719,
0.010702087543904781,
0.056373029947280884,
0.08945438265800476,
0.03711634501814842,
-0.033264897763729095,
-0.00851272139698267,
-0.02630026452243328,
-0.04124193638563156,
-0.01098579727113247,
-0.07023394107818604,
-0.06450584530830383,
0.04631795361638069,
-0.0018552434630692005,
0.017529891803860664,
0.011366061866283417,
-0.002050724346190691,
0.055501677095890045,
0.00008569160127080977,
-0.008121545426547527,
-0.04150199890136719,
-0.06811163574457169,
0.0014875098131597042,
0.01975100114941597,
0.06717783957719803,
-0.013191324658691883,
-0.04056262597441673,
0.05570600554347038,
0.02579689584672451,
0.025060070678591728,
0.0023546854499727488,
-0.0019169197184965014,
-0.021846497431397438,
0.07207846641540527,
0.07137076556682587,
-0.01103481836616993,
0.02894733101129532,
-0.06028059870004654,
-0.037803806364536285,
0.020163457840681076,
0.025918487459421158,
0.023176155984401703,
0.0027153955306857824,
0.00882136169821024,
-0.004860384855419397,
-0.03558327257633209,
-0.02184356562793255,
0.061109863221645355,
0.04874351993203163,
0.03986164927482605,
-0.07983053475618362,
0.029904501512646675,
0.0018193464493378997,
0.03128660097718239,
-0.07793401181697845,
0.036928657442331314,
0.03253361955285072,
-0.05547672510147095,
0.13129647076129913,
-0.032925475388765335,
0.0368829071521759,
0.022032201290130615,
0.09943998605012894,
0.03721501678228378,
-0.00038557479274459183,
0.0409594364464283,
-0.05917767435312271,
-0.016189921647310257,
-0.03602828085422516,
-0.0844971090555191,
-0.06475778669118881,
-0.0381280854344368,
0.004649393726140261,
0.02801107056438923,
-0.019583025947213173,
-0.013961339369416237,
-0.008657312020659447,
0.008654126897454262,
0.06537067145109177,
-0.01746685989201069,
-0.0894523486495018,
-0.03973667323589325,
0.13694600760936737,
0.018204793334007263,
-0.029168667271733284,
0.024217473343014717,
-0.007953447289764881,
-0.009915693663060665,
0.025610240176320076,
0.014244130812585354,
0.0012299236841499805,
0.04682892933487892,
-0.056472666561603546,
0.05765955150127411,
0.007588217966258526,
-0.0018090232042595744,
-0.13530601561069489,
-0.003456064499914646,
-0.018927691504359245,
0.03957872837781906,
0.06081380322575569,
0.06355968862771988,
0.021004365757107735,
-0.0044252886436879635,
-0.009521996602416039,
-0.014718994498252869,
-0.03723033517599106,
0.0972047969698906,
-0.00400710990652442,
0.10514330118894577,
-0.04416896402835846,
-0.011563001200556755,
0.052940983325242996,
0.00817137397825718,
0.02743471972644329,
-0.0042885672301054,
2.5353688476618894e-33,
0.07248716056346893,
0.004005316644906998,
0.010575286112725735,
0.02036965638399124,
-0.05383017659187317,
0.0724034309387207,
-0.041790787130594254,
0.047932203859090805,
-0.11802636086940765,
0.06500318646430969,
-0.05101223662495613,
0.08042041957378387,
-0.031141851097345352,
-0.08012155443429947,
0.0464368537068367,
-0.00009478824358666316,
-0.010624388232827187,
-0.03026469424366951,
-0.006952865049242973,
-0.023982267826795578,
-0.040526166558265686,
-0.02460915967822075,
-0.08472786843776703,
0.02305327169597149,
0.02024851366877556,
-0.06841594725847244,
0.0074686636216938496,
0.027591949328780174,
-0.062223032116889954,
0.0070302048698067665,
0.01657804287970066,
-0.0238332636654377,
0.024277927353978157,
0.13875506818294525,
0.019825445488095284,
-0.01890009082853794,
0.05694304406642914,
0.00607489887624979,
-0.07683967053890228,
-0.040991317480802536,
-0.02443973533809185,
-0.016207274049520493,
-0.030248165130615234,
-0.014660876244306564,
-0.015169099904596806,
-0.17999881505966187,
0.013691767118871212,
-0.04010864719748497,
0.1025039330124855,
-0.011234759353101254,
-0.05412380024790764,
0.08374477922916412,
0.006092153489589691,
-0.0878288745880127,
-0.020294789224863052,
-0.02281167544424534,
0.007082226220518351,
0.02849799394607544,
-0.03421745076775551,
-0.005648525431752205,
-0.021335534751415253,
0.047307442873716354,
0.017058763653039932,
-0.04675007984042168,
-0.1165025383234024,
0.005835470277816057,
-0.002256547100841999,
-0.02253517508506775,
-0.014256570488214493,
-0.020470280200242996,
-0.02100091613829136,
0.0013060389319434762,
-0.017832761630415916,
-0.0204473864287138,
0.026907993480563164,
-0.08200082927942276,
-0.011862402781844139,
0.06681913882493973,
0.040950413793325424,
-0.11680036038160324,
-0.043786223977804184,
0.016062481328845024,
0.031077489256858826,
0.0812554582953453,
-0.05832500755786896,
0.042401961982250214,
-0.055334221571683884,
-0.016446474939584732,
0.019951220601797104,
-0.006389478221535683,
-0.056248269975185394,
0.025114160031080246,
-0.04812079668045044,
0.031717054545879364,
-0.006695359013974667,
-4.513395415980623e-33,
0.04631984606385231,
0.044723231345415115,
0.002894488861784339,
0.06283362209796906,
0.009554222226142883,
-0.10062356293201447,
0.07149336487054825,
0.031980592757463455,
-0.025324378162622452,
-0.040921930223703384,
0.03698424622416496,
-0.03157820180058479,
-0.009875631891191006,
-0.09111732989549637,
0.01945566199719906,
0.00024319607473444194,
-0.13229213654994965,
-0.027243347838521004,
0.05038593336939812,
-0.062142278999090195,
0.1345917284488678,
0.027982575818896294,
0.023550337180495262,
0.02151564136147499,
-0.07196888327598572,
-0.010131265968084335,
0.01486277487128973,
0.013121095485985279,
0.03800857439637184,
-0.02348043955862522,
-0.011498459614813328,
-0.04953397810459137,
-0.02105487324297428,
-0.01920356974005699,
-0.04631877318024635,
-0.1246282085776329,
0.0917024314403534,
0.05813242495059967,
0.01092712115496397,
0.028472313657402992,
0.053223561495542526,
0.026244694367051125,
0.009411107748746872,
0.03826956823468208,
0.05473628267645836,
0.06969678401947021,
0.06641098856925964,
-0.016578909009695053,
0.11226991564035416,
-0.03230024874210358,
0.04790690913796425,
-0.03272252157330513,
-0.0550336055457592,
0.09288451820611954,
-0.05312211439013481,
-0.09342244267463684,
-0.10881619900465012,
-0.09195408225059509,
0.05735630914568901,
0.06531432271003723,
-0.05022672936320305,
-0.041493915021419525,
0.09896641969680786,
0.08522680401802063,
0.00844531413167715,
0.01639098860323429,
-0.09158583730459213,
0.05306395888328552,
0.07284322381019592,
-0.001816381118260324,
-0.00537903793156147,
0.0011413614265620708,
-0.01692175306379795,
-0.061179883778095245,
0.01802827976644039,
-0.021411804482340813,
0.008419262245297432,
-0.049364566802978516,
0.0745018869638443,
0.014843922108411789,
0.027085939422249794,
0.005228802561759949,
0.03515692427754402,
0.06498079746961594,
-0.03220998868346214,
0.06949878484010696,
0.02788214385509491,
0.09778439253568649,
-0.08366384357213974,
0.0587226003408432,
0.016918400302529335,
0.07904951274394989,
-0.058356352150440216,
-0.08688519150018692,
0.02956617809832096,
-5.549265580384599e-8,
-0.1041957214474678,
-0.05750523880124092,
-0.07005172967910767,
-0.08159816265106201,
-0.04589913785457611,
-0.05620522052049637,
0.010600403882563114,
-0.026583371683955193,
0.05116439238190651,
-0.020538369193673134,
0.010829550214111805,
0.07381030172109604,
-0.007286955136805773,
-0.061785951256752014,
-0.013619465753436089,
-0.06340508162975311,
-0.06318914145231247,
-0.04850972816348076,
0.0003253489267081022,
0.10872536897659302,
0.0420561209321022,
-0.02943270467221737,
0.02022252418100834,
0.014085033908486366,
0.09041756391525269,
-0.013835606165230274,
-0.055673304945230484,
0.03935527428984642,
0.05652618035674095,
0.028801243752241135,
-0.07519283145666122,
0.034298982471227646,
0.019140392541885376,
-0.054917652159929276,
0.02648061141371727,
0.07621106505393982,
-0.010043583810329437,
-0.01387013029307127,
-0.027548136189579964,
0.06481892615556717,
0.03184615075588226,
-0.06866120547056198,
-0.06318546086549759,
0.019752131775021553,
0.04374522715806961,
-0.058090437203645706,
0.011686880141496658,
0.006305184215307236,
-0.00012840400449931622,
-0.08667699992656708,
-0.0037488252855837345,
-0.008565531112253666,
-0.020575789734721184,
-0.024119174107909203,
-0.05425850301980972,
-0.04384872317314148,
-0.01291625201702118,
-0.048516035079956055,
-0.03236660361289978,
0.018220925703644753,
0.1256367713212967,
0.012332079000771046,
-0.01481183897703886,
-0.002327346010133624
] | 0.011508 |
# REPL > Stability: 2 - Stable The `node:repl` module provides a Read-Eval-Print-Loop (REPL) implementation that is available both as a standalone program or includible in other applications. It can be accessed using: ```mjs import repl from 'node:repl'; ``` ```cjs const repl = require('node:repl'); ``` ## Design and features The `node:repl` module exports the [`repl.REPLServer`][] class. While running, instances of [`repl.REPLServer`][] will accept individual lines of user input, evaluate those according to a user-defined evaluation function, then output the result. Input and output may be from `stdin` and `stdout`, respectively, or may be connected to any Node.js [stream][]. Instances of [`repl.REPLServer`][] support automatic completion of inputs, completion preview, simplistic Emacs-style line editing, multi-line inputs, [ZSH][]-like reverse-i-search, [ZSH][]-like substring-based history search, ANSI-styled output, saving and restoring current REPL session state, error recovery, and customizable evaluation functions. Terminals that do not support ANSI styles and Emacs-style line editing automatically fall back to a limited feature set. ### Commands and special keys The following special commands are supported by all REPL instances: \* `.break`: When in the process of inputting a multi-line expression, enter the `.break` command (or press `Ctrl`+`C`) to abort further input or processing of that expression. \* `.clear`: Resets the REPL `context` to an empty object and clears any multi-line expression being input. \* `.exit`: Close the I/O stream, causing the REPL to exit. \* `.help`: Show this list of special commands. \* `.save`: Save the current REPL session to a file: `> .save ./file/to/save.js` \* `.load`: Load a file into the current REPL session. `> .load ./file/to/load.js` \* `.editor`: Enter editor mode (`Ctrl`+`D` to finish, `Ctrl`+`C` to cancel). ```console > .editor // Entering editor mode (^D to finish, ^C to cancel) function welcome(name) { return `Hello ${name}!`; } welcome('Node.js User'); // ^D 'Hello Node.js User!' > ``` The following key combinations in the REPL have these special effects: \* `Ctrl`+`C`: When pressed once, has the same effect as the `.break` command. When pressed twice on a blank line, has the same effect as the `.exit` command. \* `Ctrl`+`D`: Has the same effect as the `.exit` command. \* `Tab`: When pressed on a blank line, displays global and local (scope) variables. When pressed while entering other input, displays relevant autocompletion options. For key bindings related to the reverse-i-search, see [`reverse-i-search`][]. For all other key bindings, see [TTY keybindings][]. ### Default evaluation By default, all instances of [`repl.REPLServer`][] use an evaluation function that evaluates JavaScript expressions and provides access to Node.js built-in modules. This default behavior can be overridden by passing in an alternative evaluation function when the [`repl.REPLServer`][] instance is created. #### JavaScript expressions The default evaluator supports direct evaluation of JavaScript expressions: ```console > 1 + 1 2 > const m = 2 undefined > m + 1 3 ``` Unless otherwise scoped within blocks or functions, variables declared either implicitly or using the `const`, `let`, or `var` keywords are declared at the global scope. #### Global and local scope The default evaluator provides access to any variables that exist in the global scope. It is possible to expose a variable to the REPL explicitly by assigning it to the `context` object associated with each `REPLServer`: ```mjs import repl from 'node:repl'; const msg = 'message'; repl.start('> ').context.m = msg; ``` ```cjs const repl = require('node:repl'); const msg = 'message'; repl.start('> ').context.m = msg; ``` Properties in the `context` object appear as local within the REPL: ```console $ node repl\_test.js > m 'message' ``` Context properties are not read-only by default. To specify read-only globals, context properties must be defined using `Object.defineProperty()`: ```mjs import repl from 'node:repl'; const msg = | https://github.com/nodejs/node/blob/main//doc/api/repl.md | main | nodejs | [
-0.13750645518302917,
0.002248306293040514,
-0.06426481902599335,
0.06610836088657379,
0.019181715324521065,
-0.040903009474277496,
-0.01867767609655857,
0.017265863716602325,
0.025397446006536484,
-0.026093875989317894,
-0.04236967861652374,
0.04603302851319313,
0.021245116367936134,
-0.02984418347477913,
-0.027368472889065742,
0.021572383120656013,
-0.029703667387366295,
0.09181440621614456,
0.021296748891472816,
-0.12766395509243011,
0.01803862862288952,
-0.03000648133456707,
0.012823808006942272,
-0.03324209153652191,
-0.030290702357888222,
-0.015911607071757317,
-0.05419310927391052,
0.07859180122613907,
0.042190954089164734,
-0.07478521764278412,
0.059075672179460526,
-0.04024516046047211,
-0.03263105824589729,
0.03236689418554306,
-0.06021420285105705,
0.1758350431919098,
-0.012453808449208736,
-0.1170031875371933,
-0.060437511652708054,
0.003767756512388587,
0.031862981617450714,
0.09628725051879883,
-0.06963274627923965,
-0.06375875324010849,
0.07268039882183075,
-0.04416636377573013,
-0.07976297289133072,
-0.0493791364133358,
-0.0961613580584526,
-0.0034979565534740686,
-0.008881554938852787,
-0.03420639783143997,
-0.052366647869348526,
-0.004359074868261814,
-0.0192014891654253,
0.02179720811545849,
0.012293336912989616,
0.03597734123468399,
0.041726820170879364,
-0.012818721123039722,
0.0033208923414349556,
-0.012450633570551872,
0.011466492898762226,
-0.02350771427154541,
0.04109981656074524,
0.017490630969405174,
-0.018765505403280258,
0.0765155553817749,
0.05704107508063316,
-0.013158757239580154,
-0.0937601774930954,
0.01951896771788597,
-0.01133760903030634,
-0.04564112797379494,
-0.06293963640928268,
-0.07132208347320557,
-0.016880983486771584,
-0.019654186442494392,
0.012132389470934868,
0.04714563488960266,
-0.015895573422312737,
-0.02123856730759144,
-0.023188238963484764,
0.03735065087676048,
-0.04354105144739151,
0.10725322365760803,
0.021037179976701736,
0.02856293134391308,
0.11366359144449234,
0.03739989176392555,
-0.06774365156888962,
-0.017889441922307014,
0.024082163348793983,
0.04087722301483154,
-0.018430206924676895,
0.0674920380115509,
0.03125451132655144,
-0.02423686347901821,
-0.020628314465284348,
0.029624661430716515,
0.021265868097543716,
0.04601038992404938,
0.09223636984825134,
-0.08872541785240173,
0.03371758759021759,
-0.000742260308470577,
0.013253520242869854,
0.03609193116426468,
-0.03895488753914833,
-0.023407096043229103,
0.015357976779341698,
0.07832057774066925,
-0.005384476855397224,
0.011621126905083656,
0.0041784909553825855,
0.007234869059175253,
0.06462239474058151,
-0.04322188347578049,
0.10387277603149414,
0.09347236901521683,
0.0818367525935173,
0.02870665118098259,
-0.0019387040520086884,
-0.035380080342292786,
0.060415226966142654,
-0.03528580442070961,
0.05897735804319382,
4.859313648726867e-33,
-0.026338256895542145,
-0.04061379283666611,
0.007661773823201656,
0.07918407022953033,
0.029818382114171982,
0.025024956092238426,
0.013138865120708942,
-0.01965889148414135,
-0.15402428805828094,
-0.010536436922848225,
-0.04036039486527443,
0.04155220091342926,
-0.015183950774371624,
0.020054878666996956,
-0.018424633890390396,
-0.01802741177380085,
0.04577117785811424,
0.050225913524627686,
0.006488058716058731,
0.04233359545469284,
0.0008770826971158385,
0.014368850737810135,
0.00224047782830894,
-0.029570406302809715,
0.061617378145456314,
-0.02620738372206688,
0.05366554483771324,
0.0440901517868042,
-0.05483289435505867,
-0.040709447115659714,
0.04491487145423889,
0.04764916002750397,
-0.0027579052839428186,
0.034066881984472275,
0.013576534576714039,
-0.018135540187358856,
0.027716178447008133,
0.03585216403007507,
-0.06099843233823776,
-0.03929324075579643,
0.012269136495888233,
0.03876357898116112,
-0.02386332117021084,
0.04267856106162071,
-0.02645544707775116,
-0.09130360186100006,
-0.058624617755413055,
-0.007622605189681053,
0.03317097947001457,
-0.014048660174012184,
-0.050002362579107285,
0.09456983208656311,
-0.002908894093707204,
-0.04793322831392288,
0.020856071263551712,
0.011044182814657688,
0.02358994632959366,
0.012309130281209946,
-0.011110441759228706,
0.039308153092861176,
0.044224146753549576,
0.06979132443666458,
-0.04005523771047592,
-0.021114293485879898,
-0.036096297204494476,
0.051862772554159164,
-0.11658657342195511,
-0.022284947335720062,
0.022861575707793236,
0.08830682933330536,
-0.0686645433306694,
0.05636440962553024,
-0.02079491876065731,
-0.03641899675130844,
0.025527451187372208,
-0.021867014467716217,
-0.11357979476451874,
-0.02317470870912075,
0.05931813269853592,
0.012786833569407463,
0.011263868771493435,
-0.009474677965044975,
-0.08143438398838043,
0.0922316163778305,
0.0764869675040245,
-0.013453147374093533,
-0.06738793104887009,
-0.03142192214727402,
0.08258376270532608,
0.000841030792798847,
-0.0018453743541613221,
-0.03504094108939171,
-0.0053519681096076965,
-0.1388535052537918,
-0.07078755646944046,
-6.113777710037396e-33,
-0.0066214571706950665,
0.029966063797473907,
-0.053204260766506195,
0.14539985358715057,
-0.06515750288963318,
-0.07201867550611496,
-0.05020252242684364,
0.014506623148918152,
0.006287942174822092,
-0.008602485992014408,
-0.07135853171348572,
0.04688325896859169,
0.05185159668326378,
0.04825420677661896,
0.0700521171092987,
0.041391048580408096,
-0.14553381502628326,
-0.0598115511238575,
0.0570039227604866,
-0.022022826597094536,
-0.011906261555850506,
0.0005353076849132776,
0.068611279129982,
0.08142418414354324,
-0.05161329358816147,
0.014816006645560265,
0.022312553599476814,
-0.04149336367845535,
0.03083387017250061,
-0.02209797129034996,
-0.024873986840248108,
-0.028420785441994667,
-0.05629783496260643,
0.033230409026145935,
-0.024613220244646072,
-0.055452633649110794,
-0.015068024396896362,
0.09835111349821091,
0.06248203292489052,
-0.017145326361060143,
0.058924801647663116,
-0.010612063109874725,
-0.05578914284706116,
-0.03370053321123123,
0.016627218574285507,
-0.029979337006807327,
-0.04613679274916649,
0.09961879998445511,
-0.018702715635299683,
-0.04374177008867264,
-0.0883522480726242,
-0.05630236491560936,
-0.058534570038318634,
0.004600685089826584,
-0.053140364587306976,
-0.063886858522892,
-0.004524318501353264,
0.018260756507515907,
0.051585618406534195,
0.03780880197882652,
-0.04872884228825569,
-0.1164461150765419,
-0.0033327669370919466,
0.002745948964729905,
-0.0036511546932160854,
-0.007963546551764011,
-0.09988323599100113,
-0.03797747194766998,
0.06510082632303238,
0.021656794473528862,
0.07940345257520676,
0.014241166412830353,
0.00838997308164835,
-0.05631568282842636,
0.025703225284814835,
-0.01860901154577732,
-0.05836435779929161,
-0.06319442391395569,
0.02828662097454071,
0.02224947325885296,
-0.041688960045576096,
0.11487322300672531,
0.027870502322912216,
0.03757380694150925,
0.017092961817979813,
0.00256201159209013,
0.02033665031194687,
0.028197500854730606,
0.04001293703913689,
0.008181985467672348,
0.062452998012304306,
0.0409991592168808,
-0.11691131442785263,
-0.004084186628460884,
0.017272448167204857,
-5.471961728176211e-8,
-0.06679025292396545,
-0.021611420437693596,
-0.059363313019275665,
0.02829403057694435,
0.00050425308290869,
0.02185622975230217,
0.04518629238009453,
-0.030515817925333977,
0.06419391930103302,
0.05066833272576332,
0.02446608804166317,
-0.024367596954107285,
-0.009707720018923283,
-0.00843545887619257,
0.0014061912661418319,
0.1565493643283844,
0.014126264490187168,
0.07009881734848022,
-0.025261765345931053,
0.00883923377841711,
0.01751735247671604,
0.011513114906847477,
-0.028703153133392334,
0.09727954864501953,
-0.002725756261497736,
-0.07214725017547607,
0.030285807326436043,
0.09455686062574387,
-0.07776353508234024,
-0.08385305106639862,
0.0051984176971018314,
0.028928004205226898,
0.0004100465739611536,
-0.018328633159399033,
0.04394901171326637,
-0.0006070149247534573,
0.008003968745470047,
0.0031405503395944834,
0.06585978716611862,
0.03761735558509827,
-0.04670906066894531,
0.024939222261309624,
-0.032830074429512024,
0.0169474296271801,
-0.06555227190256119,
-0.032305072993040085,
0.0017015592893585563,
-0.04096783697605133,
-0.008758999407291412,
0.002114361384883523,
0.055252060294151306,
-0.0893261507153511,
-0.07668437063694,
-0.02880943939089775,
-0.03496280685067177,
0.026494475081562996,
-0.003729909425601363,
-0.064418263733387,
-0.013769869692623615,
0.042119018733501434,
0.054179832339286804,
0.013736356981098652,
0.08051817864179611,
-0.0717100128531456
] | 0.08138 |
repl.start('> ').context.m = msg; ``` Properties in the `context` object appear as local within the REPL: ```console $ node repl\_test.js > m 'message' ``` Context properties are not read-only by default. To specify read-only globals, context properties must be defined using `Object.defineProperty()`: ```mjs import repl from 'node:repl'; const msg = 'message'; const r = repl.start('> '); Object.defineProperty(r.context, 'm', { configurable: false, enumerable: true, value: msg, }); ``` ```cjs const repl = require('node:repl'); const msg = 'message'; const r = repl.start('> '); Object.defineProperty(r.context, 'm', { configurable: false, enumerable: true, value: msg, }); ``` #### Accessing core Node.js modules The default evaluator will automatically load Node.js core modules into the REPL environment when used. For instance, unless otherwise declared as a global or scoped variable, the input `fs` will be evaluated on-demand as `global.fs = require('node:fs')`. ```console > fs.createReadStream('./some/file'); ``` #### Global uncaught exceptions The REPL uses the [`domain`][] module to catch all uncaught exceptions for that REPL session. This use of the [`domain`][] module in the REPL has these side effects: \* Uncaught exceptions only emit the [`'uncaughtException'`][] event in the standalone REPL. Adding a listener for this event in a REPL within another Node.js program results in [`ERR\_INVALID\_REPL\_INPUT`][]. ```js const r = repl.start(); r.write('process.on("uncaughtException", () => console.log("Foobar"));\n'); // Output stream includes: // TypeError [ERR\_INVALID\_REPL\_INPUT]: Listeners for `uncaughtException` // cannot be used in the REPL r.close(); ``` \* Trying to use [`process.setUncaughtExceptionCaptureCallback()`][] throws an [`ERR\_DOMAIN\_CANNOT\_SET\_UNCAUGHT\_EXCEPTION\_CAPTURE`][] error. #### Assignment of the `\_` (underscore) variable The default evaluator will, by default, assign the result of the most recently evaluated expression to the special variable `\_` (underscore). Explicitly setting `\_` to a value will disable this behavior. ```console > [ 'a', 'b', 'c' ] [ 'a', 'b', 'c' ] > \_.length 3 > \_ += 1 Expression assignment to \_ now disabled. 4 > 1 + 1 2 > \_ 4 ``` Similarly, `\_error` will refer to the last seen error, if there was any. Explicitly setting `\_error` to a value will disable this behavior. ```console > throw new Error('foo'); Uncaught Error: foo > \_error.message 'foo' ``` #### `await` keyword Support for the `await` keyword is enabled at the top level. ```console > await Promise.resolve(123) 123 > await Promise.reject(new Error('REPL await')) Uncaught Error: REPL await at REPL2:1:54 > const timeout = util.promisify(setTimeout); undefined > const old = Date.now(); await timeout(1000); console.log(Date.now() - old); 1002 undefined ``` One known limitation of using the `await` keyword in the REPL is that it will invalidate the lexical scoping of the `const` keywords. For example: ```console > const m = await Promise.resolve(123) undefined > m 123 > m = await Promise.resolve(234) 234 // redeclaring the constant does error > const m = await Promise.resolve(345) Uncaught SyntaxError: Identifier 'm' has already been declared ``` [`--no-experimental-repl-await`][] shall disable top-level await in REPL. ### Reverse-i-search The REPL supports bi-directional reverse-i-search similar to [ZSH][]. It is triggered with `Ctrl`+`R` to search backward and `Ctrl`+`S` to search forwards. Duplicated history entries will be skipped. Entries are accepted as soon as any key is pressed that doesn't correspond with the reverse search. Cancelling is possible by pressing `Esc` or `Ctrl`+`C`. Changing the direction immediately searches for the next entry in the expected direction from the current position on. ### Custom evaluation functions When a new [`repl.REPLServer`][] is created, a custom evaluation function may be provided. This can be used, for instance, to implement fully customized REPL applications. An evaluation function accepts the following four arguments: \* `code` {string} The code to be executed (e.g. `1 + 1`). \* `context` {Object} The context in which the code is executed. This can either be the JavaScript | https://github.com/nodejs/node/blob/main//doc/api/repl.md | main | nodejs | [
-0.022503025829792023,
0.0317227728664875,
-0.04545355215668678,
0.10125661641359329,
0.02272292599081993,
0.002853013575077057,
0.04514840617775917,
0.0375039242208004,
0.03868705406785011,
0.0012708354042842984,
0.017247790470719337,
-0.029156433418393135,
0.02144012041389942,
0.026145698502659798,
0.04077938571572304,
0.04379301518201828,
0.07948886603116989,
0.015449943020939827,
-0.009975644759833813,
-0.05218663066625595,
0.03445444628596306,
0.0036109706852585077,
0.07574838399887085,
-0.012225347571074963,
-0.04049936681985855,
-0.012602020055055618,
-0.06208857148885727,
0.0765702947974205,
0.018275536596775055,
-0.013437749817967415,
0.054501354694366455,
-0.0009485732880420983,
-0.034276921302080154,
0.04387475177645683,
0.00312722846865654,
0.17962154746055603,
-0.0176237840205431,
-0.09726796299219131,
-0.0029156990349292755,
0.012037333101034164,
0.055852219462394714,
0.09978900104761124,
-0.05505431070923805,
-0.054945752024650574,
0.08501645177602768,
-0.07235243171453476,
0.00618007592856884,
0.05469803884625435,
-0.06214460730552673,
-0.026911480352282524,
-0.004267994314432144,
-0.022479409351944923,
-0.07296133786439896,
-0.03598029166460037,
0.0013672653585672379,
0.06252480298280716,
0.01536860503256321,
0.04645828902721405,
0.08081211149692535,
-0.05449628829956055,
-0.034199949353933334,
-0.0436243936419487,
0.043173812329769135,
-0.04771774262189865,
-0.006918288767337799,
0.01204683631658554,
-0.04642610251903534,
0.08187996596097946,
0.024108385667204857,
0.005493792239576578,
0.003689045086503029,
0.04291719198226929,
0.03931346535682678,
0.028065653517842293,
-0.05295303091406822,
-0.03573959693312645,
-0.06270179152488708,
-0.00657692551612854,
0.0038298743311315775,
0.0003324224962852895,
-0.0383756197988987,
-0.019019676372408867,
-0.00025961731444112957,
-0.01847810484468937,
-0.022931020706892014,
0.10840112715959549,
0.046858370304107666,
0.018113471567630768,
0.025955388322472572,
0.05194777622818947,
-0.05977540835738182,
-0.10936439037322998,
-0.05876500904560089,
0.0983300730586052,
0.0006008252967149019,
-0.015523998066782951,
-0.010198947973549366,
-0.042668409645557404,
0.022531893104314804,
0.003203021362423897,
0.03218032792210579,
-0.025096412748098373,
0.11029604077339172,
0.043029673397541046,
0.03409872576594353,
-0.002493771957233548,
-0.06439048051834106,
0.0023630503565073013,
-0.06396090239286423,
-0.006980897393077612,
-0.0014570782659575343,
0.0989627093076706,
-0.021314328536391258,
-0.004327990580350161,
0.005852172151207924,
0.0009549278183840215,
0.07224790006875992,
-0.07254096120595932,
0.0633544847369194,
0.05695043504238129,
0.06731271743774414,
-0.0709841251373291,
-0.040635693818330765,
-0.03803717717528343,
0.013490987941622734,
0.00803285650908947,
0.06887367367744446,
4.003497190662608e-33,
-0.006539918947964907,
-0.06226109340786934,
0.011702102608978748,
0.10260708630084991,
0.05620335042476654,
0.05903597176074982,
0.034316930919885635,
0.0014393037417903543,
-0.09646374732255936,
-0.06343236565589905,
0.009505805559456348,
0.07507812976837158,
-0.020216355100274086,
-0.04661617428064346,
-0.028201429173350334,
0.06589382141828537,
0.04826858639717102,
0.0014608276542276144,
0.09787869453430176,
0.009740321896970272,
-0.05327681452035904,
-0.01759975403547287,
-0.01470880676060915,
-0.07075139880180359,
-0.025048961862921715,
-0.017977941781282425,
0.0350787378847599,
-0.012420423328876495,
-0.047288328409194946,
-0.04333772882819176,
0.05613447353243828,
0.06496212631464005,
0.020841188728809357,
0.12305045127868652,
0.013033311814069748,
-0.058494627475738525,
0.03113820031285286,
0.0064565264619886875,
-0.1307966411113739,
-0.04319734498858452,
0.060798726975917816,
-0.018140539526939392,
0.008500182069838047,
-0.0027105086483061314,
-0.07583556324243546,
-0.07324835658073425,
-0.06993976980447769,
0.01749112643301487,
0.02977563813328743,
-0.040941834449768066,
-0.043713949620723724,
0.09396325051784515,
0.00492718443274498,
-0.11822520941495895,
0.03492703661322594,
0.010048381052911282,
-0.018658393993973732,
-0.026994479820132256,
-0.045643437653779984,
-0.0783001184463501,
-0.03535062447190285,
0.01954924501478672,
0.0553782619535923,
0.017964033409953117,
0.030928809195756912,
0.04408837482333183,
-0.1252540498971939,
-0.0441613532602787,
0.03843294829130173,
-0.0170806422829628,
-0.004975005052983761,
0.019316168501973152,
-0.01952931471168995,
0.07687626034021378,
-0.010080356150865555,
0.01910221576690674,
-0.05101699009537697,
0.06398884952068329,
0.023612914606928825,
-0.003232173854485154,
-0.00782522838562727,
0.05424622446298599,
-0.07951994985342026,
0.14201350510120392,
0.0021875689271837473,
0.013565801084041595,
-0.037640757858753204,
-0.022662432864308357,
0.06104931980371475,
-0.02572530135512352,
-0.013510598801076412,
-0.05657123029232025,
-0.01277119293808937,
-0.07195232063531876,
-0.10583645105361938,
-6.146176538397966e-33,
-0.003840629244223237,
0.016726834699511528,
-0.037981994450092316,
0.08782768994569778,
-0.01786956377327442,
-0.05374222621321678,
-0.03313219174742699,
0.016996758058667183,
-0.03881506621837616,
0.07739266008138657,
0.0032412621658295393,
-0.004192363936454058,
0.06747231632471085,
0.050579726696014404,
-0.0005200215382501483,
0.03172386810183525,
-0.08397570997476578,
-0.04797017574310303,
0.038384098559617996,
-0.07329647988080978,
0.044102828949689865,
0.029274191707372665,
0.0030899897683411837,
0.04760607331991196,
-0.07661596685647964,
-0.021793777123093605,
-0.07872354984283447,
-0.08082429319620132,
-0.027644621208310127,
-0.044170089066028595,
-0.0341387577354908,
0.0849258229136467,
-0.07353956252336502,
0.05218914896249771,
-0.058322057127952576,
-0.08343273401260376,
0.010586782358586788,
0.06031014770269394,
-0.011620483361184597,
0.05271882191300392,
0.04266480356454849,
0.055285077542066574,
-0.08796956390142441,
-0.027910077944397926,
0.015393102541565895,
-0.027456404641270638,
0.06121062487363815,
-0.034655917435884476,
0.01261921226978302,
0.01122612040489912,
-0.07649539411067963,
-0.08279217034578323,
0.030346982181072235,
-0.010183053091168404,
-0.04272938147187233,
-0.0193449966609478,
0.014774320647120476,
-0.0008823946700431406,
0.08180158585309982,
-0.025609122589230537,
0.038051556795835495,
-0.11615227162837982,
-0.0858629047870636,
0.021159378811717033,
-0.0159162450581789,
-0.029435716569423676,
-0.02841232344508171,
-0.019716020673513412,
0.06946331262588501,
-0.09041257202625275,
-0.01845237798988819,
-0.060095079243183136,
0.0026751013938337564,
-0.07232262939214706,
0.07417869567871094,
0.008356329053640366,
-0.04206925258040428,
-0.09389214217662811,
0.008251002058386803,
0.04052221402525902,
-0.023366080597043037,
0.004174266941845417,
-0.03598955646157265,
0.06775709986686707,
0.03349811211228371,
-0.06273194402456284,
-0.03118709661066532,
0.0668770968914032,
0.01667880080640316,
0.027175422757864,
-0.0016029778635129333,
0.014348609372973442,
-0.08360349386930466,
0.005416786763817072,
-0.01569281704723835,
-4.893344396350585e-8,
-0.14011050760746002,
-0.05691974237561226,
-0.10438844561576843,
-0.01843939535319805,
-0.008434943854808807,
0.0019085119711235166,
0.013043650425970554,
-0.03886127099394798,
0.05108783766627312,
0.06066775321960449,
-0.03601484373211861,
-0.03100650943815708,
0.03158898651599884,
-0.012811463326215744,
-0.09392312169075012,
0.016753604635596275,
-0.030577005818486214,
0.02785310335457325,
0.014704190194606781,
0.0067372629418969154,
0.06330425292253494,
0.03778213635087013,
-0.002511049387976527,
0.09324800968170166,
0.08711039274930954,
-0.0795389711856842,
0.08318370580673218,
0.057039979845285416,
-0.05920427665114403,
0.029043378308415413,
-0.04917117580771446,
0.03620445355772972,
0.03104647435247898,
0.03451143577694893,
-0.07412133365869522,
0.010354572907090187,
0.05439004674553871,
0.057046134024858475,
0.04566022753715515,
0.04125500097870827,
0.023324083536863327,
-0.054193105548620224,
-0.10076936334371567,
0.03960386663675308,
-0.0756741464138031,
-0.03918367624282837,
-0.00740905711427331,
0.021670684218406677,
0.013236197642982006,
0.025583872571587563,
0.035248953849077225,
0.016782155260443687,
-0.029758350923657417,
-0.026006178930401802,
-0.03265061601996422,
0.011791391298174858,
0.05453326180577278,
0.025752967223525047,
-0.022750956937670708,
-0.014637595973908901,
-0.001950535923242569,
-0.030513586476445198,
-0.00525390962138772,
-0.10752628743648529
] | 0.017469 |
provided. This can be used, for instance, to implement fully customized REPL applications. An evaluation function accepts the following four arguments: \* `code` {string} The code to be executed (e.g. `1 + 1`). \* `context` {Object} The context in which the code is executed. This can either be the JavaScript `global` context or a context specific to the REPL instance, depending on the `useGlobal` option. \* `replResourceName` {string} An identifier for the REPL resource associated with the current code evaluation. This can be useful for debugging purposes. \* `callback` {Function} A function to invoke once the code evaluation is complete. The callback takes two parameters: \* An error object to provide if an error occurred during evaluation, or `null`/`undefined` if no error occurred. \* The result of the code evaluation (this is not relevant if an error is provided). The following illustrates an example of a REPL that squares a given number, an error is instead printed if the provided input is not actually a number: ```mjs import repl from 'node:repl'; function byThePowerOfTwo(number) { return number \* number; } function myEval(code, context, replResourceName, callback) { if (isNaN(code)) { callback(new Error(`${code.trim()} is not a number`)); } else { callback(null, byThePowerOfTwo(code)); } } repl.start({ prompt: 'Enter a number: ', eval: myEval }); ``` ```cjs const repl = require('node:repl'); function byThePowerOfTwo(number) { return number \* number; } function myEval(code, context, replResourceName, callback) { if (isNaN(code)) { callback(new Error(`${code.trim()} is not a number`)); } else { callback(null, byThePowerOfTwo(code)); } } repl.start({ prompt: 'Enter a number: ', eval: myEval }); ``` #### Recoverable errors At the REPL prompt, pressing `Enter` sends the current line of input to the `eval` function. In order to support multi-line input, the `eval` function can return an instance of `repl.Recoverable` to the provided callback function: ```js function myEval(cmd, context, filename, callback) { let result; try { result = vm.runInThisContext(cmd); } catch (e) { if (isRecoverableError(e)) { return callback(new repl.Recoverable(e)); } } callback(null, result); } function isRecoverableError(error) { if (error.name === 'SyntaxError') { return /^(Unexpected end of input|Unexpected token)/.test(error.message); } return false; } ``` ### Customizing REPL output By default, [`repl.REPLServer`][] instances format output using the [`util.inspect()`][] method before writing the output to the provided `Writable` stream (`process.stdout` by default). The `showProxy` inspection option is set to true by default and the `colors` option is set to true depending on the REPL's `useColors` option. The `useColors` boolean option can be specified at construction to instruct the default writer to use ANSI style codes to colorize the output from the `util.inspect()` method. If the REPL is run as standalone program, it is also possible to change the REPL's [inspection defaults][`util.inspect()`] from inside the REPL by using the `inspect.replDefaults` property which mirrors the `defaultOptions` from [`util.inspect()`][]. ```console > util.inspect.replDefaults.compact = false; false > [1] [ 1 ] > ``` To fully customize the output of a [`repl.REPLServer`][] instance pass in a new function for the `writer` option on construction. The following example, for instance, simply converts any input text to upper case: ```mjs import repl from 'node:repl'; const r = repl.start({ prompt: '> ', eval: myEval, writer: myWriter }); function myEval(cmd, context, filename, callback) { callback(null, cmd); } function myWriter(output) { return output.toUpperCase(); } ``` ```cjs const repl = require('node:repl'); const r = repl.start({ prompt: '> ', eval: myEval, writer: myWriter }); function myEval(cmd, context, filename, callback) { callback(null, cmd); } function myWriter(output) { return output.toUpperCase(); } ``` ## Class: `REPLServer` \* `options` {Object|string} See [`repl.start()`][] \* Extends: {readline.Interface} Instances of `repl.REPLServer` are created using the [`repl.start()`][] method or directly using the JavaScript `new` keyword. ```mjs import repl from 'node:repl'; const options = | https://github.com/nodejs/node/blob/main//doc/api/repl.md | main | nodejs | [
-0.1872682422399521,
-0.015639038756489754,
-0.10344389081001282,
0.05975411459803581,
-0.0911884605884552,
-0.04271501302719116,
0.04001498222351074,
0.020117932930588722,
0.050519976764917374,
-0.05836404487490654,
-0.03238639608025551,
0.017728177830576897,
0.05046496167778969,
0.001429454074241221,
-0.025244420394301414,
-0.005305725149810314,
0.02187362127006054,
0.05690767243504524,
-0.05822472274303436,
-0.11106309294700623,
0.06220194324851036,
-0.031117340549826622,
-0.05390921235084534,
0.018303848803043365,
-0.002059360733255744,
-0.07992483675479889,
-0.042482275515794754,
0.041042476892471313,
0.05606114864349365,
-0.017298506572842598,
0.06917072832584381,
-0.03393375128507614,
-0.02249073050916195,
0.017087824642658234,
-0.011358843185007572,
0.1817580908536911,
-0.07099106907844543,
-0.0761759877204895,
-0.044492457062006,
0.03662610799074173,
0.011872764676809311,
0.033444296568632126,
-0.07395307719707489,
0.00106835609767586,
0.016755269840359688,
-0.08437973260879517,
-0.040051501244306564,
-0.018383324146270752,
-0.10230690985918045,
-0.02998696267604828,
0.033870257437229156,
-0.007019414566457272,
-0.05715378746390343,
-0.04468737542629242,
0.013110578991472721,
-0.025694167241454124,
0.05090268701314926,
-0.01015396136790514,
0.032684076577425,
0.012768981978297234,
0.008975937962532043,
-0.014801772311329842,
0.020545341074466705,
-0.024009671062231064,
0.0056264703162014484,
0.004438790027052164,
-0.00986347533762455,
-0.01033245213329792,
-0.0053030080161988735,
-0.004554248880594969,
-0.09163693338632584,
0.024587281048297882,
0.011647230014204979,
0.03480134904384613,
-0.015556705184280872,
-0.02932778373360634,
-0.02518826723098755,
-0.008258748799562454,
0.019137363880872726,
-0.0041824267245829105,
0.04913826286792755,
-0.022247593849897385,
-0.011300274170935154,
0.07595297694206238,
0.05388433486223221,
0.06320367008447647,
0.04830397665500641,
0.08080893009901047,
0.1293552666902542,
0.07030244916677475,
-0.044299665838479996,
-0.022631565108895302,
0.03977128118276596,
0.015251404605805874,
-0.0006295176572166383,
0.0314822793006897,
0.04260365292429924,
-0.10677025467157364,
-0.008474748581647873,
0.003642888041213155,
0.008157169446349144,
-0.0021918548736721277,
0.09252242743968964,
-0.08820981532335281,
0.05007252097129822,
0.02870193123817444,
0.003062209580093622,
-0.004781641531735659,
-0.030157705768942833,
-0.035910435020923615,
-0.0160323828458786,
0.06476227194070816,
0.013748254626989365,
-0.017757100984454155,
0.013320271857082844,
0.04330421984195709,
0.05992267653346062,
-0.06108921021223068,
0.10285221040248871,
0.0026688012294471264,
0.11979735642671585,
0.030117211863398552,
0.029278671368956566,
-0.06103759631514549,
-0.0020679673179984093,
0.0099897850304842,
0.041102442890405655,
4.13891524190329e-33,
0.014657251536846161,
-0.011198582127690315,
0.014109876938164234,
0.048985596746206284,
0.006232100538909435,
-0.008109599351882935,
-0.020124977454543114,
-0.007526461500674486,
-0.0800347775220871,
-0.026755353435873985,
0.0014920938992872834,
0.07643922418355942,
0.0034761761780828238,
0.005405590869486332,
-0.012758135795593262,
0.09056509286165237,
0.030431875959038734,
0.08508910238742828,
-0.0009193628211505711,
0.04645850509405136,
-0.050208382308483124,
-0.039634257555007935,
0.00957262422889471,
0.0003853821544907987,
0.04623323306441307,
0.08950836211442947,
0.01507751364260912,
-0.026906903833150864,
-0.03917020931839943,
-0.008653259836137295,
0.055333368480205536,
-0.020255940034985542,
-0.030810266733169556,
0.0783640444278717,
0.05576372519135475,
-0.030518684536218643,
-0.010189221240580082,
0.018935540691018105,
-0.04644031822681427,
-0.003138706088066101,
-0.004421471152454615,
-0.003185596549883485,
-0.08578881621360779,
0.05937526747584343,
0.01563020423054695,
-0.11413073539733887,
-0.005567123182117939,
0.02416415698826313,
0.023232590407133102,
0.00892637949436903,
0.0034343027509748936,
0.14402104914188385,
0.04464990645647049,
-0.017617758363485336,
0.009237886406481266,
0.014093243516981602,
0.0023126297164708376,
0.0029222050216048956,
0.027887167409062386,
-0.014123082160949707,
0.022692371159791946,
0.024638628587126732,
-0.04431423544883728,
-0.016135942190885544,
-0.04561728611588478,
0.018084131181240082,
-0.06480108946561813,
-0.016685152426362038,
0.005081021226942539,
0.057397738099098206,
-0.04631723091006279,
0.01873716711997986,
-0.027750791981816292,
0.03865550830960274,
-0.004312195349484682,
-0.037837881594896317,
-0.032645292580127716,
0.00867359060794115,
0.017905615270137787,
-0.027270179241895676,
0.0014908142620697618,
-0.03014286234974861,
-0.029980573803186417,
0.030344659462571144,
-0.00129630824085325,
0.004105114843696356,
-0.01739552617073059,
-0.08131496608257294,
-0.032956983894109726,
-0.015258780680596828,
-0.03465992212295532,
-0.06500539183616638,
-0.08243025839328766,
-0.09269464761018753,
-0.02803993597626686,
-6.305201087597051e-33,
0.026523247361183167,
0.008397899568080902,
-0.01042204163968563,
0.12433155626058578,
-0.046476446092128754,
-0.09552472829818726,
-0.006905642803758383,
0.05518903210759163,
0.00422764103859663,
-0.025215761736035347,
-0.06503038853406906,
0.020295141264796257,
0.04138808324933052,
0.04623831436038017,
0.06522393226623535,
0.04513786733150482,
-0.1577114462852478,
-0.0430801659822464,
-0.030194681137800217,
-0.0033112165983766317,
0.09170906245708466,
-0.0052826059982180595,
0.03839728981256485,
0.030093174427747726,
-0.07644245028495789,
0.02180527336895466,
-0.00868261605501175,
-0.09151871502399445,
0.053883060812950134,
0.0013265747111290693,
0.015335438773036003,
0.047155387699604034,
-0.056746337562799454,
0.007634839508682489,
-0.007926002144813538,
-0.049811892211437225,
0.10410226136445999,
0.05028856173157692,
0.00415843678638339,
0.00596876535564661,
0.06246303394436836,
0.00026480856467969716,
0.008612281642854214,
0.01557015161961317,
0.006576559506356716,
-0.01671486906707287,
-0.0678311362862587,
0.03884446993470192,
0.007506227120757103,
-0.0850636437535286,
-0.06941989064216614,
-0.03201794996857643,
-0.04592852666974068,
0.05469191446900368,
-0.055281687527894974,
-0.02238808199763298,
-0.012294048443436623,
0.02016339637339115,
0.0181925967335701,
0.08842458575963974,
-0.08311553299427032,
-0.1193062886595726,
0.05188524350523949,
-0.017891855910420418,
-0.05737699568271637,
0.01364086288958788,
-0.05581657588481903,
-0.06754786521196365,
0.03394894674420357,
0.006592622026801109,
0.12199375778436661,
-0.02142198011279106,
-0.029831044375896454,
-0.050086721777915955,
-0.041309647262096405,
-0.004397175740450621,
-0.054770760238170624,
-0.08276466280221939,
0.02259681187570095,
0.08346445858478546,
0.05371169000864029,
0.03476399555802345,
0.1190137267112732,
0.018477926030755043,
-0.012639936059713364,
-0.025347499176859856,
0.013415494933724403,
0.13578030467033386,
-0.017523430287837982,
-0.02623366005718708,
-0.007974919863045216,
0.0532868318259716,
-0.09464376419782639,
0.03519313782453537,
0.02190111018717289,
-6.354166259825433e-8,
-0.060907311737537384,
0.04495988413691521,
-0.01842881366610527,
-0.028555281460285187,
-0.07450434565544128,
-0.0039598760195076466,
-0.0348501019179821,
-0.02911233901977539,
0.025058498606085777,
-0.0389968566596508,
0.024032747372984886,
-0.009356445632874966,
-0.00003104453571722843,
0.02556121163070202,
-0.028761552646756172,
0.13830867409706116,
-0.005989944562315941,
0.024068409577012062,
-0.008204181678593159,
0.04991280660033226,
-0.011215077713131905,
0.017375333234667778,
-0.029358230531215668,
0.04745461046695709,
-0.025603581219911575,
-0.07695543766021729,
0.03212841600179672,
0.16039854288101196,
-0.06688139587640762,
-0.11355427652597427,
0.06470566987991333,
0.07448219507932663,
0.020107025280594826,
-0.0015097911236807704,
-0.04647977277636528,
0.0710449144244194,
0.04387664049863815,
-0.04144766926765442,
0.07288122177124023,
-0.007063241209834814,
0.024509532377123833,
-0.00992134865373373,
-0.05468711256980896,
0.008434114046394825,
0.0037227310240268707,
0.04356514289975166,
-0.03944692760705948,
-0.07605966925621033,
-0.07874149084091187,
-0.03214389085769653,
0.014739551581442356,
-0.05376899614930153,
-0.09570619463920593,
0.03173498064279556,
-0.06478653848171234,
0.029382819309830666,
-0.033050891011953354,
-0.03889327496290207,
0.009199555031955242,
0.06524256616830826,
0.036910295486450195,
0.04872426390647888,
0.06621871888637543,
-0.07509791105985641
] | 0.139134 |
myEval(cmd, context, filename, callback) { callback(null, cmd); } function myWriter(output) { return output.toUpperCase(); } ``` ## Class: `REPLServer` \* `options` {Object|string} See [`repl.start()`][] \* Extends: {readline.Interface} Instances of `repl.REPLServer` are created using the [`repl.start()`][] method or directly using the JavaScript `new` keyword. ```mjs import repl from 'node:repl'; const options = { useColors: true }; const firstInstance = repl.start(options); const secondInstance = new repl.REPLServer(options); ``` ```cjs const repl = require('node:repl'); const options = { useColors: true }; const firstInstance = repl.start(options); const secondInstance = new repl.REPLServer(options); ``` ### Event: `'exit'` The `'exit'` event is emitted when the REPL is exited either by receiving the `.exit` command as input, the user pressing `Ctrl`+`C` twice to signal `SIGINT`, or by pressing `Ctrl`+`D` to signal `'end'` on the input stream. The listener callback is invoked without any arguments. ```js replServer.on('exit', () => { console.log('Received "exit" event from repl!'); process.exit(); }); ``` ### Event: `'reset'` The `'reset'` event is emitted when the REPL's context is reset. This occurs whenever the `.clear` command is received as input \_unless\_ the REPL is using the default evaluator and the `repl.REPLServer` instance was created with the `useGlobal` option set to `true`. The listener callback will be called with a reference to the `context` object as the only argument. This can be used primarily to re-initialize REPL context to some pre-defined state: ```mjs import repl from 'node:repl'; function initializeContext(context) { context.m = 'test'; } const r = repl.start({ prompt: '> ' }); initializeContext(r.context); r.on('reset', initializeContext); ``` ```cjs const repl = require('node:repl'); function initializeContext(context) { context.m = 'test'; } const r = repl.start({ prompt: '> ' }); initializeContext(r.context); r.on('reset', initializeContext); ``` When this code is executed, the global `'m'` variable can be modified but then reset to its initial value using the `.clear` command: ```console $ ./node example.js > m 'test' > m = 1 1 > m 1 > .clear Clearing context... > m 'test' > ``` ### `replServer.defineCommand(keyword, cmd)` \* `keyword` {string} The command keyword (\_without\_ a leading `.` character). \* `cmd` {Object|Function} The function to invoke when the command is processed. The `replServer.defineCommand()` method is used to add new `.`-prefixed commands to the REPL instance. Such commands are invoked by typing a `.` followed by the `keyword`. The `cmd` is either a `Function` or an `Object` with the following properties: \* `help` {string} Help text to be displayed when `.help` is entered (Optional). \* `action` {Function} The function to execute, optionally accepting a single string argument. The following example shows two new commands added to the REPL instance: ```mjs import repl from 'node:repl'; const replServer = repl.start({ prompt: '> ' }); replServer.defineCommand('sayhello', { help: 'Say hello', action(name) { this.clearBufferedCommand(); console.log(`Hello, ${name}!`); this.displayPrompt(); }, }); replServer.defineCommand('saybye', function saybye() { console.log('Goodbye!'); this.close(); }); ``` ```cjs const repl = require('node:repl'); const replServer = repl.start({ prompt: '> ' }); replServer.defineCommand('sayhello', { help: 'Say hello', action(name) { this.clearBufferedCommand(); console.log(`Hello, ${name}!`); this.displayPrompt(); }, }); replServer.defineCommand('saybye', function saybye() { console.log('Goodbye!'); this.close(); }); ``` The new commands can then be used from within the REPL instance: ```console > .sayhello Node.js User Hello, Node.js User! > .saybye Goodbye! ``` ### `replServer.displayPrompt([preserveCursor])` \* `preserveCursor` {boolean} The `replServer.displayPrompt()` method readies the REPL instance for input from the user, printing the configured `prompt` to a new line in the `output` and resuming the `input` to accept new input. When multi-line input is being entered, a pipe `'|'` is printed rather than the 'prompt'. When `preserveCursor` is `true`, the cursor placement will not be reset to `0`. The `replServer.displayPrompt` method is primarily intended to be called from within the action function for commands registered using the `replServer.defineCommand()` method. ### `replServer.clearBufferedCommand()` The | https://github.com/nodejs/node/blob/main//doc/api/repl.md | main | nodejs | [
-0.11032167822122574,
0.020835917443037033,
-0.02272828482091427,
0.079549141228199,
-0.047906357795000076,
-0.02436147630214691,
-0.0006362560670822859,
0.05851877108216286,
0.03463537618517876,
-0.0038426981773227453,
0.0011609563371166587,
0.007778682745993137,
0.04575721547007561,
-0.02990727871656418,
0.0059841712936758995,
0.029986858367919922,
-0.046998679637908936,
0.039313461631536484,
-0.01831625960767269,
-0.09197323769330978,
0.05107537657022476,
-0.030466077849268913,
0.009518619626760483,
-0.06905478239059448,
0.04021115228533745,
-0.059910472482442856,
0.013985807076096535,
0.06358609348535538,
0.02368537150323391,
-0.0801524817943573,
0.0975804552435875,
-0.06067977845668793,
-0.03990080952644348,
-0.02992289699614048,
-0.012015863321721554,
0.17548568546772003,
-0.00795749668031931,
-0.08293964713811874,
-0.03196530416607857,
-0.024311386048793793,
0.05124642327427864,
0.10896338522434235,
-0.022198934108018875,
-0.028276927769184113,
0.02517126500606537,
-0.07319993525743484,
-0.012935126200318336,
-0.023822657763957977,
-0.06909560412168503,
-0.02823912724852562,
-0.006507668644189835,
-0.03861232474446297,
-0.06395016610622406,
-0.07452027499675751,
-0.05398862436413765,
0.07332660257816315,
-0.061755940318107605,
0.04048135504126549,
0.057499367743730545,
-0.03334503248333931,
-0.03663799539208412,
-0.026411430910229683,
0.01493801735341549,
-0.03051861748099327,
-0.016207585111260414,
0.007424755021929741,
0.013245313428342342,
0.10746844857931137,
-0.01870896853506565,
-0.010095656849443913,
-0.05552743747830391,
0.010517026297748089,
-0.0011993618682026863,
0.018949322402477264,
-0.06435948610305786,
-0.09629835188388824,
-0.018132539466023445,
0.01084879133850336,
-0.01973084732890129,
-0.013509589247405529,
0.023613743484020233,
-0.07012935727834702,
-0.03451165184378624,
0.07246565073728561,
0.003232969669625163,
0.1134364902973175,
0.018576474860310555,
-0.03046835958957672,
0.045298535376787186,
0.05023856461048126,
-0.07261323928833008,
-0.07666786015033722,
-0.006278215441852808,
0.0010982915991917253,
-0.08275362104177475,
0.03546350821852684,
-0.0067587182857096195,
-0.011405721306800842,
0.01999852992594242,
0.02891211211681366,
0.007284950464963913,
0.0023231683298945427,
-0.0019771151710301638,
-0.044127896428108215,
0.046384889632463455,
0.015241173096001148,
-0.010973132215440273,
0.022528115659952164,
-0.04567829519510269,
-0.023238319903612137,
0.00690679345279932,
0.10321210324764252,
-0.059519171714782715,
-0.060075290501117706,
0.0038880533538758755,
0.060477010905742645,
0.12444368004798889,
-0.07051123678684235,
0.09994994848966599,
0.014695796184241772,
0.10719417035579681,
-0.0064993142150342464,
-0.052966196089982986,
-0.028106804937124252,
-0.017436379566788673,
-0.039335038512945175,
0.0888492614030838,
6.930334126152128e-33,
0.018256697803735733,
-0.08683116734027863,
-0.02774854004383087,
0.06660861521959305,
0.036206506192684174,
0.028865845873951912,
0.03163387253880501,
0.032412637025117874,
-0.15793535113334656,
-0.07041489332914352,
-0.011608628556132317,
-0.02252388186752796,
0.0025746538303792477,
-0.059719230979681015,
-0.04491139575839043,
0.0007677592220716178,
0.025628570467233658,
0.010843347758054733,
0.011270777322351933,
0.028518790379166603,
-0.0650855228304863,
0.06584746390581131,
0.02665439434349537,
0.018277158960700035,
-0.011559653095901012,
-0.018266811966896057,
0.10166547447443008,
-0.003493835451081395,
-0.04800601676106453,
-0.04710209742188454,
0.11357847601175308,
-0.013056905940175056,
-0.014920240268111229,
0.10273702442646027,
-0.02118939347565174,
0.03092002496123314,
0.018987007439136505,
0.010364782996475697,
-0.07907038927078247,
-0.011596393771469593,
-0.0026269028894603252,
0.014190495014190674,
-0.06309355795383453,
0.01773175224661827,
-0.021849537268280983,
-0.03878054395318031,
-0.0945592001080513,
0.04183223843574524,
0.028840787708759308,
0.0025197321083396673,
-0.05633167177438736,
0.1469831019639969,
0.053151920437812805,
-0.038271237164735794,
0.033638957887887955,
0.06468436121940613,
-0.06114288419485092,
0.02931472659111023,
-0.02355346828699112,
-0.041532717645168304,
-0.011405253782868385,
0.09214077889919281,
-0.04102986305952072,
0.05244997516274452,
-0.033529240638017654,
0.08267553150653839,
-0.07170839607715607,
-0.0220898799598217,
0.026510972529649734,
0.04543919861316681,
-0.008490584790706635,
0.015122462064027786,
-0.01054800022393465,
0.04136587306857109,
0.06935621798038483,
0.03937613219022751,
-0.1223645880818367,
0.010504205711185932,
0.06244182214140892,
-0.04979589581489563,
0.0025763846933841705,
-0.011409289203584194,
-0.0874674916267395,
0.07664528489112854,
0.07045552879571915,
0.027999019250273705,
-0.0478481650352478,
-0.0345185361802578,
0.14207950234413147,
0.022423777729272842,
-0.046601440757513046,
-0.03156435117125511,
-0.04802914708852768,
-0.1252199411392212,
-0.06483345478773117,
-8.806095441014208e-33,
0.06619323790073395,
0.014724920503795147,
-0.026160838082432747,
0.09793177247047424,
-0.018159111961722374,
-0.05303167551755905,
-0.01627463661134243,
0.04839520901441574,
-0.030316520482301712,
0.05380529537796974,
-0.09020250290632248,
0.09509071707725525,
0.032257333397865295,
0.014069952070713043,
0.057196080684661865,
-0.010128996334969997,
-0.1122753918170929,
-0.030463380739092827,
0.010460506193339825,
-0.07250750809907913,
-0.02161566913127899,
0.030632805079221725,
0.0833912268280983,
0.059247471392154694,
-0.019872451201081276,
0.0041020894423127174,
-0.0454830639064312,
0.04988520219922066,
-0.014770852401852608,
-0.03957725688815117,
-0.040275320410728455,
0.0032002851366996765,
-0.045585669577121735,
0.05264432355761528,
0.0017724261851981282,
-0.020224930718541145,
-0.004389529582113028,
0.1215004175901413,
0.05696718767285347,
0.040823645889759064,
-0.01473408006131649,
-0.07578390091657639,
-0.0038898505736142397,
0.010281638242304325,
-0.012727360241115093,
-0.05125679448246956,
-0.033420659601688385,
0.07958970218896866,
0.02872723527252674,
-0.048572272062301636,
-0.08652683347463608,
-0.06116780266165733,
-0.000630427966825664,
-0.008995240554213524,
0.021218061447143555,
-0.07678917795419693,
0.05121610313653946,
-0.042240869253873825,
0.03954092413187027,
0.0952000543475151,
0.043339185416698456,
-0.1310524344444275,
0.009033172391355038,
-0.027326226234436035,
0.02439000830054283,
-0.06967417150735855,
-0.057548586279153824,
-0.05445406585931778,
0.03388331085443497,
-0.01891644112765789,
0.02506299689412117,
-0.047358106821775436,
0.03569535166025162,
-0.0630808025598526,
0.09640402346849442,
0.014558929018676281,
0.00771993538364768,
-0.04462940990924835,
0.020417511463165283,
0.015513701364398003,
-0.006003443617373705,
0.016774611547589302,
0.020814400166273117,
-0.017211657017469406,
0.04455990344285965,
-0.04205300658941269,
-0.01696929894387722,
0.09528325498104095,
0.04038931801915169,
-0.04113336279988289,
0.03182387351989746,
0.0709637925028801,
-0.05952833965420723,
0.010694654658436775,
-0.009091630578041077,
-5.957353366170537e-8,
-0.1007542759180069,
-0.020869947969913483,
-0.04538535699248314,
0.00816821027547121,
-0.02564098685979843,
0.0027024566661566496,
-0.01965935342013836,
-0.08443751186132431,
0.04731115698814392,
-0.011669711209833622,
-0.01172187365591526,
-0.023942941799759865,
0.0179519671946764,
0.00814905297011137,
-0.026877541095018387,
0.0010160250822082162,
0.02075398713350296,
0.01806449145078659,
-0.0426628403365612,
0.029676316305994987,
-0.04044496640563011,
-0.018113993108272552,
-0.07184798270463943,
0.0336068794131279,
0.03769778460264206,
-0.04983917623758316,
0.01157623715698719,
0.07997539639472961,
-0.03347206860780716,
0.028068197891116142,
-0.011100181378424168,
0.07650557160377502,
-0.0023490702733397484,
0.022528575733304024,
-0.046564094722270966,
0.031876545399427414,
0.05566874518990517,
-0.02798507548868656,
0.05052298307418823,
0.012149086222052574,
-0.008250951766967773,
-0.005524065811187029,
-0.02407575398683548,
0.08016051352024078,
-0.026166077703237534,
-0.019313417375087738,
0.01319208275526762,
0.02185051515698433,
0.029780106619000435,
0.04901114106178284,
0.006470867898315191,
-0.07222370058298111,
-0.009700678288936615,
-0.044572893530130386,
-0.08922675997018814,
-0.00020780693739652634,
0.0491834357380867,
-0.00714511564001441,
0.00959992315620184,
0.00751864816993475,
0.08238216489553452,
-0.04235043749213219,
0.042890407145023346,
-0.02081911824643612
] | 0.002678 |
input is being entered, a pipe `'|'` is printed rather than the 'prompt'. When `preserveCursor` is `true`, the cursor placement will not be reset to `0`. The `replServer.displayPrompt` method is primarily intended to be called from within the action function for commands registered using the `replServer.defineCommand()` method. ### `replServer.clearBufferedCommand()` The `replServer.clearBufferedCommand()` method clears any command that has been buffered but not yet executed. This method is primarily intended to be called from within the action function for commands registered using the `replServer.defineCommand()` method. ### `replServer.setupHistory(historyConfig, callback)` \* `historyConfig` {Object|string} the path to the history file If it is a string, it is the path to the history file. If it is an object, it can have the following properties: \* `filePath` {string} the path to the history file \* `size` {number} Maximum number of history lines retained. To disable the history set this value to `0`. This option makes sense only if `terminal` is set to `true` by the user or by an internal `output` check, otherwise the history caching mechanism is not initialized at all. \*\*Default:\*\* `30`. \* `removeHistoryDuplicates` {boolean} If `true`, when a new input line added to the history list duplicates an older one, this removes the older line from the list. \*\*Default:\*\* `false`. \* `onHistoryFileLoaded` {Function} called when history writes are ready or upon error \* `err` {Error} \* `repl` {repl.REPLServer} \* `callback` {Function} called when history writes are ready or upon error (Optional if provided as `onHistoryFileLoaded` in `historyConfig`) \* `err` {Error} \* `repl` {repl.REPLServer} Initializes a history log file for the REPL instance. When executing the Node.js binary and using the command-line REPL, a history file is initialized by default. However, this is not the case when creating a REPL programmatically. Use this method to initialize a history log file when working with REPL instances programmatically. ## `repl.builtinModules` > Stability: 0 - Deprecated. Use [`module.builtinModules`][] instead. \* Type: {string\[]} A list of the names of some Node.js modules, e.g., `'http'`. An automated migration is available ([source](https://github.com/nodejs/userland-migrations/tree/main/recipes/repl-builtin-modules)): ```bash npx codemod@latest @nodejs/repl-builtin-modules ``` ## `repl.start([options])` \* `options` {Object|string} \* `prompt` {string} The input prompt to display. \*\*Default:\*\* `'> '` (with a trailing space). \* `input` {stream.Readable} The `Readable` stream from which REPL input will be read. \*\*Default:\*\* `process.stdin`. \* `output` {stream.Writable} The `Writable` stream to which REPL output will be written. \*\*Default:\*\* `process.stdout`. \* `terminal` {boolean} If `true`, specifies that the `output` should be treated as a TTY terminal. \*\*Default:\*\* checking the value of the `isTTY` property on the `output` stream upon instantiation. \* `eval` {Function} The function to be used when evaluating each given line of input. \*\*Default:\*\* an async wrapper for the JavaScript `eval()` function. An `eval` function can error with `repl.Recoverable` to indicate the input was incomplete and prompt for additional lines. See the [custom evaluation functions][] section for more details. \* `useColors` {boolean} If `true`, specifies that the default `writer` function should include ANSI color styling to REPL output. If a custom `writer` function is provided then this has no effect. \*\*Default:\*\* checking color support on the `output` stream if the REPL instance's `terminal` value is `true`. \* `useGlobal` {boolean} If `true`, specifies that the default evaluation function will use the JavaScript `global` as the context as opposed to creating a new separate context for the REPL instance. The node CLI REPL sets this value to `true`. \*\*Default:\*\* `false`. \* `ignoreUndefined` {boolean} If `true`, specifies that the default writer will not output the return value of a command if it evaluates to `undefined`. \*\*Default:\*\* `false`. \* `writer` {Function} The function to invoke to format the output of each command before writing to | https://github.com/nodejs/node/blob/main//doc/api/repl.md | main | nodejs | [
-0.05755547806620598,
-0.03277924284338951,
-0.06313521414995193,
0.0020262659527361393,
-0.06070489436388016,
-0.00028867251239717007,
0.03855140879750252,
0.029941126704216003,
0.005711651407182217,
0.016408655792474747,
0.026994097977876663,
0.006987191271036863,
0.059689342975616455,
-0.03176075965166092,
-0.0952719897031784,
-0.020881421864032745,
-0.02947656251490116,
-0.09636193513870239,
0.03734501451253891,
-0.054059747606515884,
-0.004439389333128929,
0.014428561553359032,
0.05435016006231308,
0.011234021745622158,
0.011709091253578663,
-0.024945486336946487,
0.047393057495355606,
-0.05773558467626572,
-0.008901381865143776,
-0.00403192825615406,
-0.016024233773350716,
-0.013363721780478954,
-0.05930924788117409,
-0.015163455158472061,
-0.00620481139048934,
0.13925275206565857,
0.005663182120770216,
-0.03692570701241493,
-0.05170898512005806,
-0.021418895572423935,
0.08282984793186188,
0.03573157638311386,
-0.0930207148194313,
-0.049082864075899124,
-0.044332437217235565,
0.01066428329795599,
-0.023190319538116455,
-0.031134381890296936,
-0.02820897102355957,
0.04848252981901169,
0.04370582476258278,
0.04247094690799713,
0.01587320677936077,
-0.030456917360424995,
0.021264489740133286,
0.08055854588747025,
0.0756407305598259,
0.06931010633707047,
-0.019531311467289925,
-0.011528155766427517,
-0.028518207371234894,
-0.03136284649372101,
-0.08061972260475159,
-0.008321414701640606,
0.0119977667927742,
0.030984237790107727,
0.03694593161344528,
0.01690877415239811,
0.09109584242105484,
-0.059290509670972824,
-0.0774376168847084,
0.07813411206007004,
-0.08892165124416351,
-0.042881060391664505,
-0.030027972534298897,
-0.0031797613482922316,
-0.013644649647176266,
0.04208524525165558,
-0.028990721330046654,
-0.06920381635427475,
0.06354597955942154,
-0.09077201783657074,
-0.045119404792785645,
0.04483608528971672,
0.037365544587373734,
0.033354636281728745,
-0.014591923914849758,
-0.11142444610595703,
0.10243995487689972,
0.06524422764778137,
-0.01484584342688322,
-0.10915831476449966,
0.010662081651389599,
0.002261615125462413,
-0.05505362153053284,
0.036220695823431015,
0.009815221652388573,
0.02694912627339363,
0.0013827234506607056,
-0.0019723991863429546,
0.05000115931034088,
0.03070315718650818,
0.08483779430389404,
-0.0277240127325058,
0.019245976582169533,
0.024619583040475845,
-0.010628251358866692,
-0.031013885512948036,
-0.025632470846176147,
0.0277959406375885,
-0.021480826660990715,
-0.01071151439100504,
0.013319344259798527,
0.04913884773850441,
0.05729016661643982,
0.028480101376771927,
0.007148345001041889,
0.023067565634846687,
-0.04156186804175377,
0.01516040414571762,
0.08689422160387039,
0.018508411943912506,
-0.02117766998708248,
-0.018151992931962013,
0.039788346737623215,
0.010139474645256996,
0.0731181874871254,
3.13730515824242e-33,
0.049635421484708786,
-0.11826664954423904,
-0.04781172797083855,
0.044097982347011566,
0.028795484453439713,
0.14140693843364716,
0.03280610591173172,
0.08713003993034363,
0.03238411247730255,
-0.07152920216321945,
0.016043536365032196,
-0.07925526797771454,
-0.011680991388857365,
0.00993705540895462,
-0.05032847076654434,
-0.004142958205193281,
0.006949869450181723,
0.09707584232091904,
-0.03125958889722824,
0.03787322714924812,
0.002905745292082429,
0.12462368607521057,
-0.01760874129831791,
-0.1381409615278244,
-0.00007107157580321655,
-0.04570300504565239,
-0.016575733199715614,
0.08048033714294434,
-0.09105881303548813,
-0.024705050513148308,
-0.0377134308218956,
-0.0013084893580526114,
-0.002093070186674595,
0.06249197944998741,
0.015599513426423073,
0.02168305404484272,
0.06728754937648773,
-0.048020269721746445,
0.02526814304292202,
0.0074904561042785645,
-0.003203091211616993,
-0.031115954741835594,
-0.0687551498413086,
-0.004875713028013706,
0.018764585256576538,
-0.18268799781799316,
-0.0980023443698883,
0.03715481236577034,
-0.003780139610171318,
0.02984706126153469,
0.00825309194624424,
0.07030268758535385,
0.03024139814078808,
-0.09158308804035187,
-0.04540879279375076,
-0.03496455028653145,
0.010942641645669937,
-0.04388857260346413,
-0.012420136481523514,
-0.051597610116004944,
0.05926737189292908,
0.11763770133256912,
-0.006418007425963879,
0.02949151024222374,
0.02419881708920002,
0.05817396193742752,
0.006653674878180027,
-0.04108433425426483,
0.01814238354563713,
0.0036615398712456226,
-0.04616785794496536,
0.07298590987920761,
0.012346914038062096,
-0.03415212780237198,
0.060575541108846664,
-0.010893450118601322,
-0.09286096692085266,
0.008917668834328651,
0.00019792240345850587,
-0.011376118287444115,
0.049691274762153625,
-0.018630599603056908,
-0.11175382882356644,
0.04240267351269722,
0.014887421391904354,
0.009478761814534664,
0.027359260246157646,
0.019908485934138298,
0.034933965653181076,
-0.030518434941768646,
0.027707453817129135,
-0.04966437444090843,
-0.014628824777901173,
-0.02778218500316143,
0.003643371630460024,
-7.130226940509458e-33,
0.07199598848819733,
0.06636343896389008,
-0.015876714140176773,
0.04913986474275589,
-0.05780720338225365,
-0.029705531895160675,
0.030996892601251602,
0.025295035913586617,
-0.055806681513786316,
-0.11427589505910873,
-0.039116110652685165,
0.09633283317089081,
-0.025979401543736458,
0.004538228269666433,
0.047641903162002563,
0.10473416745662689,
-0.0401325449347496,
0.005522632971405983,
-0.06805011630058289,
-0.08318105340003967,
0.02906658500432968,
-0.05101462081074715,
0.019039425998926163,
0.10397949814796448,
-0.06530340015888214,
-0.11155300587415695,
0.058003973215818405,
-0.01795652136206627,
0.040653079748153687,
0.03368416056036949,
0.06350452452898026,
0.03312564268708229,
-0.051656078547239304,
0.01988835260272026,
-0.027930909767746925,
-0.09643427282571793,
0.04205106571316719,
0.03316532447934151,
0.024032481014728546,
0.04562770575284958,
0.16575126349925995,
0.005911222659051418,
-0.006044474430382252,
0.00911512691527605,
0.030523991212248802,
-0.03327132761478424,
-0.029718026518821716,
-0.0016162567771971226,
-0.00130066170822829,
0.0022277680691331625,
-0.008015540428459644,
-0.09373671561479568,
0.03633308410644531,
0.015623407438397408,
-0.008687797002494335,
0.010157209821045399,
-0.0008180392906069756,
0.000960271805524826,
-0.02249675989151001,
-0.02566756121814251,
-0.04736706241965294,
0.06479153782129288,
-0.05375325679779053,
-0.0504508838057518,
-0.03426125645637512,
0.03623638302087784,
-0.009921679273247719,
0.03379161283373833,
0.014527791179716587,
-0.08291590958833694,
0.05494898557662964,
-0.0625462457537651,
0.005406112875789404,
-0.00980320293456316,
0.08171393722295761,
0.0540175586938858,
-0.06040025129914284,
-0.08507263660430908,
-0.010144690051674843,
0.07122229784727097,
-0.016675086691975594,
-0.0005104357842355967,
0.007669012062251568,
-0.08731076121330261,
0.0407467857003212,
0.006983287166804075,
-0.07679297775030136,
0.09250431507825851,
0.0025083201471716166,
-0.019981542602181435,
0.018075672909617424,
-0.05907929688692093,
-0.047433629631996155,
-0.021533062681555748,
-0.016179662197828293,
-5.634353783534607e-8,
-0.06282231956720352,
0.05597493797540665,
-0.011544455774128437,
0.055657267570495605,
-0.0002646228240337223,
-0.04535733908414841,
0.009905537590384483,
-0.02934880554676056,
0.03657712787389755,
-0.06701059639453888,
-0.04301738739013672,
0.02841932512819767,
-0.04349730908870697,
-0.042545005679130554,
0.01711747981607914,
0.010913586243987083,
-0.007485765032470226,
-0.0628923773765564,
-0.037607040256261826,
-0.006152673624455929,
0.011376595124602318,
-0.07369233667850494,
-0.082846499979496,
0.017371291294693947,
-0.020468607544898987,
0.006081912200897932,
0.0225696824491024,
0.1388801783323288,
-0.06597557663917542,
-0.04741470515727997,
0.1040998324751854,
0.031120648607611656,
0.03935810178518295,
0.008074197918176651,
0.0007981382077559829,
0.011606981046497822,
0.13722272217273712,
-0.0031398539431393147,
0.08150505274534225,
0.00870672706514597,
-0.08378288894891739,
0.002921981969848275,
-0.023747365921735764,
0.003074096515774727,
-0.07210719585418701,
-0.018232164904475212,
0.019131893292069435,
0.006916125304996967,
-0.0164624210447073,
-0.037962473928928375,
-0.11504609882831573,
0.036585740745067596,
0.012713572941720486,
0.052856627851724625,
0.013457128778100014,
-0.005932861007750034,
0.028057679533958435,
-0.03528396040201187,
-0.05729716643691063,
0.08920733630657196,
0.05626024678349495,
0.027649596333503723,
-0.013064203783869743,
0.01903676614165306
] | -0.033755 |
sets this value to `true`. \*\*Default:\*\* `false`. \* `ignoreUndefined` {boolean} If `true`, specifies that the default writer will not output the return value of a command if it evaluates to `undefined`. \*\*Default:\*\* `false`. \* `writer` {Function} The function to invoke to format the output of each command before writing to `output`. \*\*Default:\*\* [`util.inspect()`][]. \* `completer` {Function} An optional function used for custom Tab auto completion. See [`readline.InterfaceCompleter`][] for an example. \* `replMode` {symbol} A flag that specifies whether the default evaluator executes all JavaScript commands in strict mode or default (sloppy) mode. Acceptable values are: \* `repl.REPL\_MODE\_SLOPPY` to evaluate expressions in sloppy mode. \* `repl.REPL\_MODE\_STRICT` to evaluate expressions in strict mode. This is equivalent to prefacing every repl statement with `'use strict'`. \* `breakEvalOnSigint` {boolean} Stop evaluating the current piece of code when `SIGINT` is received, such as when `Ctrl`+`C` is pressed. This cannot be used together with a custom `eval` function. \*\*Default:\*\* `false`. \* `preview` {boolean} Defines if the repl prints autocomplete and output previews or not. \*\*Default:\*\* `true` with the default eval function and `false` in case a custom eval function is used. If `terminal` is falsy, then there are no previews and the value of `preview` has no effect. \* Returns: {repl.REPLServer} The `repl.start()` method creates and starts a [`repl.REPLServer`][] instance. If `options` is a string, then it specifies the input prompt: ```mjs import repl from 'node:repl'; // a Unix style prompt repl.start('$ '); ``` ```cjs const repl = require('node:repl'); // a Unix style prompt repl.start('$ '); ``` ## The Node.js REPL Node.js itself uses the `node:repl` module to provide its own interactive interface for executing JavaScript. This can be used by executing the Node.js binary without passing any arguments (or by passing the `-i` argument): ```console $ node > const a = [1, 2, 3]; undefined > a [ 1, 2, 3 ] > a.forEach((v) => { ... console.log(v); ... }); 1 2 3 ``` ### Environment variable options Various behaviors of the Node.js REPL can be customized using the following environment variables: \* `NODE\_REPL\_HISTORY`: When a valid path is given, persistent REPL history will be saved to the specified file rather than `.node\_repl\_history` in the user's home directory. Setting this value to `''` (an empty string) will disable persistent REPL history. Whitespace will be trimmed from the value. On Windows platforms environment variables with empty values are invalid so set this variable to one or more spaces to disable persistent REPL history. \* `NODE\_REPL\_HISTORY\_SIZE`: Controls how many lines of history will be persisted if history is available. Must be a positive number. \*\*Default:\*\* `1000`. \* `NODE\_REPL\_MODE`: May be either `'sloppy'` or `'strict'`. \*\*Default:\*\* `'sloppy'`, which will allow non-strict mode code to be run. ### Persistent history By default, the Node.js REPL will persist history between `node` REPL sessions by saving inputs to a `.node\_repl\_history` file located in the user's home directory. This can be disabled by setting the environment variable `NODE\_REPL\_HISTORY=''`. ### Using the Node.js REPL with advanced line-editors For advanced line-editors, start Node.js with the environment variable `NODE\_NO\_READLINE=1`. This will start the main and debugger REPL in canonical terminal settings, which will allow use with `rlwrap`. For example, the following can be added to a `.bashrc` file: ```bash alias node="env NODE\_NO\_READLINE=1 rlwrap node" ``` ### Starting multiple REPL instances in the same process It is possible to create and run multiple REPL instances against a single running instance of Node.js that share a single `global` object (by setting the `useGlobal` option to `true`) but have separate I/O interfaces. The following example, for instance, provides separate REPLs on `stdin`, a Unix socket, and a TCP | https://github.com/nodejs/node/blob/main//doc/api/repl.md | main | nodejs | [
-0.05575362592935562,
0.008599196560680866,
0.019491398707032204,
0.0814950093626976,
-0.010070091113448143,
-0.032039906829595566,
0.05725761130452156,
-0.018898002803325653,
-0.008708137087523937,
0.016754159703850746,
0.01501054223626852,
-0.017600959166884422,
-0.018762635067105293,
0.02553071454167366,
-0.03877051919698715,
-0.011397155001759529,
0.010205751284956932,
-0.0564301572740078,
-0.028024479746818542,
-0.09766755253076553,
0.040640853345394135,
0.03173905238509178,
0.04452018067240715,
-0.007931066676974297,
0.019625578075647354,
-0.007626155856996775,
-0.03715648129582405,
-0.04461303725838661,
0.013393012806773186,
-0.027079345658421516,
-0.04465070366859436,
-0.012526500038802624,
0.019198784604668617,
-0.010962136089801788,
0.005647578276693821,
0.06242752820253372,
-0.05929330736398697,
-0.014631510712206364,
0.020285388454794884,
-0.0066307587549090385,
-0.06257005780935287,
0.0053545525297522545,
-0.08308977633714676,
-0.04200339317321777,
-0.03487114980816841,
-0.053001247346401215,
-0.05452809855341911,
-0.11239509284496307,
-0.060030560940504074,
0.011756845749914646,
-0.03906703740358353,
0.06446776539087296,
-0.04545493796467781,
-0.10067842900753021,
0.04977603629231453,
0.022362330928444862,
-0.11081168055534363,
-0.03515949472784996,
-0.013164415024220943,
-0.005843954160809517,
-0.0776834636926651,
0.007888954132795334,
-0.04126141220331192,
0.001344357617199421,
0.05383981391787529,
0.021736469119787216,
-0.051612645387649536,
0.002125420840457082,
-0.004744508769363165,
0.07215698063373566,
-0.048108961433172226,
0.007639406714588404,
-0.006895740050822496,
0.03617962449789047,
0.020415624603629112,
-0.07976492494344711,
-0.03758087009191513,
0.060733549296855927,
-0.07206744700670242,
-0.017673926427960396,
-0.04784775525331497,
-0.0767567828297615,
-0.0076107364147901535,
0.09946910291910172,
0.02774670720100403,
0.09527896344661713,
-0.033262211829423904,
0.0276995487511158,
0.1241418868303299,
0.0924663245677948,
-0.00951665360480547,
-0.12297798693180084,
-0.04008863866329193,
0.09247072786092758,
-0.044416315853595734,
0.052791133522987366,
0.0641184002161026,
-0.060702741146087646,
-0.0018470855429768562,
0.02277817204594612,
0.011330010369420052,
0.005456855520606041,
0.0985015332698822,
-0.024503516033291817,
0.08443180471658707,
0.00021446713071782142,
0.03153431788086891,
-0.031101733446121216,
-0.0006948426598683,
0.007118708454072475,
0.04043133929371834,
0.008796616457402706,
0.03741521015763283,
-0.05897839367389679,
0.022071747109293938,
0.07720724493265152,
0.06895282864570618,
-0.054923687130212784,
0.09814588725566864,
0.09345625340938568,
0.10164095461368561,
0.003878003219142556,
-0.025067809969186783,
0.06117844954133034,
0.06940610706806183,
-0.027878809720277786,
0.008553444407880306,
5.648025175064512e-33,
0.04232659935951233,
-0.01860732026398182,
-0.04345797374844551,
0.027351735159754753,
-0.035467129200696945,
0.042875438928604126,
-0.06688535213470459,
0.02502479963004589,
-0.05726829543709755,
0.03769170120358467,
0.030704550445079803,
0.028799984604120255,
-0.043018218129873276,
0.05992082878947258,
-0.06832002848386765,
0.046831581741571426,
0.06769043207168579,
0.046994611620903015,
-0.04029759019613266,
0.0004408670065458864,
0.014316461980342865,
0.02742021158337593,
-0.017478158697485924,
0.03802662342786789,
0.016554158180952072,
-0.0004894032026641071,
0.008220640011131763,
0.04569660499691963,
-0.06352292001247406,
-0.006122216582298279,
-0.011478909291327,
-0.06666475534439087,
0.04347475990653038,
0.061864446848630905,
-0.0555594339966774,
0.08882966637611389,
-0.06343142688274384,
-0.03053923323750496,
-0.004740801174193621,
0.05530184879899025,
-0.03274510055780411,
0.015284959226846695,
-0.09639507532119751,
-0.01805078610777855,
-0.008693418465554714,
-0.12638330459594727,
-0.02152853086590767,
0.05898360162973404,
0.05953951179981232,
0.01580110937356949,
-0.014349527657032013,
0.08612968772649765,
0.05734100192785263,
0.045314155519008636,
0.009495357051491737,
0.015991032123565674,
-0.04670923203229904,
-0.0006406648899428546,
0.009208224713802338,
0.033626969903707504,
-0.023130714893341064,
0.030863787978887558,
-0.03449894115328789,
0.03372573107481003,
-0.07317853718996048,
-0.002360251499339938,
0.04843008890748024,
0.0025590690784156322,
0.04111886024475098,
-0.08553921431303024,
-0.09228060394525528,
-0.050727084279060364,
-0.007938472554087639,
0.023385165259242058,
0.05322456732392311,
-0.06738507002592087,
-0.049472350627183914,
-0.11883393675088882,
0.058184780180454254,
-0.0679640844464302,
0.028536755591630936,
0.011877327226102352,
-0.054007433354854584,
0.011480703018605709,
0.0421137772500515,
0.016621552407741547,
0.03949989750981331,
-0.0432656891644001,
0.025052392855286598,
0.009571416303515434,
0.025397319346666336,
-0.03184554725885391,
-0.008656991645693779,
-0.07516747713088989,
-0.06151040270924568,
-7.933167458621823e-33,
0.08817462623119354,
0.008609410375356674,
-0.06917653232812881,
0.059649962931871414,
-0.14062373340129852,
-0.05147417262196541,
0.052477817982435226,
0.024904686957597733,
0.07544291764497757,
-0.07551303505897522,
0.022479642182588577,
0.0015811980701982975,
0.03699725866317749,
-0.00012709537986665964,
-0.004450572654604912,
0.07959806174039841,
-0.11995639652013779,
-0.053779322654008865,
0.012365598231554031,
-0.0023944536224007607,
0.07988666743040085,
-0.05891549959778786,
0.04994048550724983,
0.04903848469257355,
-0.06616474688053131,
0.0012347009032964706,
0.002582024782896042,
0.018981100991368294,
-0.05264180153608322,
-0.003304692916572094,
0.06680465489625931,
0.08118758350610733,
-0.06033672019839287,
-0.031085392460227013,
0.011708001606166363,
-0.07837696373462677,
-0.0019476889865472913,
0.11603493988513947,
-0.033804427832365036,
0.02623707428574562,
0.106450155377388,
0.012823017314076424,
-0.02727852389216423,
0.008246776647865772,
-0.0319310799241066,
0.028231875970959663,
0.00553297670558095,
-0.010661696083843708,
0.03945883363485336,
-0.04494103044271469,
-0.03689482808113098,
-0.09868606179952621,
-0.00848541222512722,
0.030350329354405403,
-0.050863564014434814,
-0.0077287862077355385,
0.024358587339520454,
-0.028109755367040634,
-0.06667709350585938,
0.058012042194604874,
-0.07666553556919098,
-0.07119165360927582,
0.10347972810268402,
-0.028450168669223785,
-0.010036666877567768,
-0.05784739926457405,
0.015414475463330746,
0.04527051001787186,
0.057876333594322205,
-0.011406541801989079,
0.02024693973362446,
-0.032423313707113266,
-0.004452090710401535,
-0.038379717618227005,
0.028267182409763336,
0.06637522578239441,
0.0655578076839447,
-0.052038293331861496,
0.0025519037153571844,
0.05933746322989464,
0.043809160590171814,
0.06424510478973389,
0.04208078235387802,
-0.025592155754566193,
-0.08286964148283005,
0.02232573740184307,
-0.06794759631156921,
0.14543576538562775,
-0.04178245738148689,
0.058622803539037704,
0.07294072955846786,
0.035163234919309616,
-0.02551303058862686,
0.00911357905715704,
-0.08400000631809235,
-5.9230274018773343e-8,
-0.15460744500160217,
-0.03432183712720871,
-0.08038443326950073,
-0.040527548640966415,
-0.001961053116247058,
-0.03494707867503166,
0.028286607936024666,
-0.04431319236755371,
-0.009884195402264595,
-0.11046311259269714,
0.027768651023507118,
0.02787693776190281,
-0.018067514523863792,
-0.06203274801373482,
0.005930513143539429,
0.042851053178310394,
0.0058639501221477985,
0.01588573306798935,
-0.047052718698978424,
-0.019493678584694862,
-0.014538418501615524,
-0.01608467847108841,
-0.04387911781668663,
0.0010265335440635681,
0.02928130514919758,
0.027285676449537277,
-0.07727650552988052,
0.08087749034166336,
-0.05238629877567291,
0.037175290286540985,
0.031230419874191284,
0.05117086321115494,
0.07548316568136215,
-0.037690408527851105,
-0.02146722748875618,
0.018132878467440605,
0.11116066575050354,
-0.0857437327504158,
-0.011110564693808556,
0.05785175785422325,
0.06472215801477432,
0.001799865043722093,
-0.03168824687600136,
-0.016197599470615387,
-0.06716762483119965,
-0.04801143333315849,
-0.008389726281166077,
0.01818116195499897,
0.04904676601290703,
-0.10145682096481323,
0.0012173440773040056,
0.07314670830965042,
-0.010405652225017548,
0.04235958307981491,
-0.04400428384542465,
0.02644108235836029,
0.002574426122009754,
0.036917418241500854,
-0.02134235017001629,
0.015689758583903313,
0.061793021857738495,
-0.009642178192734718,
0.01809358038008213,
-0.034110166132450104
] | 0.074282 |
is possible to create and run multiple REPL instances against a single running instance of Node.js that share a single `global` object (by setting the `useGlobal` option to `true`) but have separate I/O interfaces. The following example, for instance, provides separate REPLs on `stdin`, a Unix socket, and a TCP socket, all sharing the same `global` object: ```mjs import net from 'node:net'; import repl from 'node:repl'; import process from 'node:process'; import fs from 'node:fs'; let connections = 0; repl.start({ prompt: 'Node.js via stdin> ', useGlobal: true, input: process.stdin, output: process.stdout, }); const unixSocketPath = '/tmp/node-repl-sock'; // If the socket file already exists let's remove it fs.rmSync(unixSocketPath, { force: true }); net.createServer((socket) => { connections += 1; repl.start({ prompt: 'Node.js via Unix socket> ', useGlobal: true, input: socket, output: socket, }).on('exit', () => { socket.end(); }); }).listen(unixSocketPath); net.createServer((socket) => { connections += 1; repl.start({ prompt: 'Node.js via TCP socket> ', useGlobal: true, input: socket, output: socket, }).on('exit', () => { socket.end(); }); }).listen(5001); ``` ```cjs const net = require('node:net'); const repl = require('node:repl'); const fs = require('node:fs'); let connections = 0; repl.start({ prompt: 'Node.js via stdin> ', useGlobal: true, input: process.stdin, output: process.stdout, }); const unixSocketPath = '/tmp/node-repl-sock'; // If the socket file already exists let's remove it fs.rmSync(unixSocketPath, { force: true }); net.createServer((socket) => { connections += 1; repl.start({ prompt: 'Node.js via Unix socket> ', useGlobal: true, input: socket, output: socket, }).on('exit', () => { socket.end(); }); }).listen(unixSocketPath); net.createServer((socket) => { connections += 1; repl.start({ prompt: 'Node.js via TCP socket> ', useGlobal: true, input: socket, output: socket, }).on('exit', () => { socket.end(); }); }).listen(5001); ``` Running this application from the command line will start a REPL on stdin. Other REPL clients may connect through the Unix socket or TCP socket. `telnet`, for instance, is useful for connecting to TCP sockets, while `socat` can be used to connect to both Unix and TCP sockets. By starting a REPL from a Unix socket-based server instead of stdin, it is possible to connect to a long-running Node.js process without restarting it. ### Examples #### Full-featured "terminal" REPL over `net.Server` and `net.Socket` This is an example on how to run a "full-featured" (terminal) REPL using [`net.Server`][] and [`net.Socket`][] The following script starts an HTTP server on port `1337` that allows clients to establish socket connections to its REPL instance. ```mjs // repl-server.js import repl from 'node:repl'; import net from 'node:net'; net .createServer((socket) => { const r = repl.start({ prompt: `socket ${socket.remoteAddress}:${socket.remotePort}> `, input: socket, output: socket, terminal: true, useGlobal: false, }); r.on('exit', () => { socket.end(); }); r.context.socket = socket; }) .listen(1337); ``` ```cjs // repl-server.js const repl = require('node:repl'); const net = require('node:net'); net .createServer((socket) => { const r = repl.start({ prompt: `socket ${socket.remoteAddress}:${socket.remotePort}> `, input: socket, output: socket, terminal: true, useGlobal: false, }); r.on('exit', () => { socket.end(); }); r.context.socket = socket; }) .listen(1337); ``` While the following implements a client that can create a socket connection with the above defined server over port `1337`. ```mjs // repl-client.js import net from 'node:net'; import process from 'node:process'; const sock = net.connect(1337); process.stdin.pipe(sock); sock.pipe(process.stdout); sock.on('connect', () => { process.stdin.resume(); process.stdin.setRawMode(true); }); sock.on('close', () => { process.stdin.setRawMode(false); process.stdin.pause(); sock.removeListener('close', done); }); process.stdin.on('end', () => { sock.destroy(); console.log(); }); process.stdin.on('data', (b) => { if (b.length === 1 && b[0] === 4) { process.stdin.emit('end'); } }); ``` ```cjs // repl-client.js const net = require('node:net'); const sock = net.connect(1337); process.stdin.pipe(sock); sock.pipe(process.stdout); sock.on('connect', () => { process.stdin.resume(); process.stdin.setRawMode(true); }); sock.on('close', () => { process.stdin.setRawMode(false); process.stdin.pause(); sock.removeListener('close', done); }); process.stdin.on('end', () => { sock.destroy(); console.log(); }); process.stdin.on('data', (b) => { if (b.length === 1 && b[0] === 4) { process.stdin.emit('end'); | https://github.com/nodejs/node/blob/main//doc/api/repl.md | main | nodejs | [
-0.13023057579994202,
-0.07807499915361404,
-0.04747089371085167,
0.062255412340164185,
-0.03577025979757309,
-0.054021209478378296,
0.010095767676830292,
-0.003202056745067239,
0.06226811185479164,
-0.022613711655139923,
-0.1063445582985878,
0.019061585888266563,
0.035252783447504044,
-0.0054113594815135,
0.021042892709374428,
-0.02182609960436821,
0.053732190281152725,
0.0270127784460783,
0.045769017189741135,
-0.0558074489235878,
0.007273007649928331,
-0.04772235453128815,
0.05350068584084511,
-0.024290114641189575,
-0.07169786095619202,
-0.05925759673118591,
-0.021639486774802208,
0.060732584446668625,
0.05009794235229492,
-0.0435066781938076,
0.11203625053167343,
-0.04036082327365875,
-0.10690797865390778,
0.057585351169109344,
-0.027945000678300858,
0.12524165213108063,
-0.03846975043416023,
-0.09230214357376099,
-0.08178964257240295,
0.07906313985586166,
0.10788559913635254,
0.10453979671001434,
-0.03593383729457855,
-0.04460073262453079,
0.02584032155573368,
-0.041854169219732285,
-0.07377857714891434,
0.01703622005879879,
-0.024378864094614983,
-0.06719975173473358,
0.036077067255973816,
-0.04375109449028969,
-0.018271105363965034,
-0.002987236250191927,
0.02046055905520916,
0.009793631732463837,
0.02459069713950157,
0.022673914209008217,
0.038779668509960175,
0.025647839531302452,
-0.027888335287570953,
-0.004006298258900642,
0.08862490206956863,
-0.027067843824625015,
0.04352946579456329,
0.08274824917316437,
0.0026085840072482824,
0.0664258673787117,
0.0022039744071662426,
0.002627822570502758,
-0.030965959653258324,
0.017388416454195976,
0.005708103068172932,
0.024997249245643616,
-0.05875662341713905,
0.001914263586513698,
-0.024848533794283867,
-0.010329160839319229,
-0.03706923499703407,
0.008023379370570183,
-0.018144695088267326,
-0.006312017794698477,
-0.06530328840017319,
-0.0433160699903965,
-0.07946286350488663,
0.041796211153268814,
0.015477566979825497,
-0.036854565143585205,
0.09896349906921387,
0.057695601135492325,
-0.04655167832970619,
0.006868990138173103,
0.005658804439008236,
0.01103347260504961,
0.0864095464348793,
-0.045689474791288376,
0.009264973923563957,
0.008123124949634075,
0.03717146813869476,
-0.009647974744439125,
-0.0031512167770415545,
-0.043011438101530075,
0.07022649049758911,
0.04309485852718353,
0.069241464138031,
0.04334743320941925,
-0.0721656084060669,
-0.03832471743226051,
-0.05419884994626045,
-0.03413037210702896,
-0.01493165548890829,
0.09567919373512268,
0.015968240797519684,
0.02097986824810505,
-0.024931957945227623,
0.06046130135655403,
0.08211660385131836,
-0.025545116513967514,
0.057173945009708405,
0.10831990092992783,
-0.022648386657238007,
-0.03193139657378197,
0.015228314325213432,
0.019805723801255226,
-0.014717335812747478,
-0.04798392578959465,
0.04917682707309723,
3.7488895223783164e-33,
-0.03513343632221222,
-0.11901503801345825,
0.019748525694012642,
-0.01113460399210453,
0.06012494117021561,
0.028709616512060165,
0.0022828776855021715,
0.06690911948680878,
-0.12587717175483704,
-0.0198750551789999,
-0.0271469596773386,
0.05947037786245346,
0.0032839402556419373,
-0.06865192949771881,
0.00034993322333320975,
0.06362544000148773,
0.0337357223033905,
0.049132052809000015,
0.07838630676269531,
0.05417964607477188,
-0.00756058981642127,
0.009398196823894978,
-0.03137174993753433,
-0.0019423658959567547,
-0.011818532831966877,
0.0024562033358961344,
0.042999450117349625,
-0.03190576285123825,
0.003050906816497445,
-0.011127721518278122,
0.05713534727692604,
0.01600498892366886,
-0.04962678253650665,
0.08953338116407394,
-0.029169758781790733,
-0.035411059856414795,
-0.002190903527662158,
0.08253039419651031,
-0.07404692471027374,
-0.02189895696938038,
0.059930525720119476,
0.011537475511431694,
-0.030526872724294662,
-0.0053642219863832,
0.006415128707885742,
-0.06936446577310562,
-0.12012626230716705,
-0.02197016030550003,
0.016941756010055542,
-0.03782621771097183,
0.0041350615210831165,
0.07858051359653473,
0.029189344495534897,
-0.08457805961370468,
0.048024214804172516,
-0.03871312364935875,
-0.03228049352765083,
0.01585007831454277,
0.04942535236477852,
0.003361098002642393,
-0.05198794975876808,
0.034669313579797745,
-0.11314613372087479,
0.021510859951376915,
0.018797043710947037,
0.05186451971530914,
-0.07012178748846054,
0.007927799597382545,
-0.021510597318410873,
0.057930588722229004,
-0.034979019314050674,
0.05552227050065994,
-0.050424013286828995,
-0.01813689060509205,
0.019668830558657646,
0.043860722333192825,
-0.02098415605723858,
0.05746374651789665,
0.000020449604562600143,
0.004927185829728842,
-0.06197044625878334,
0.008020089939236641,
-0.04216121509671211,
0.06283441185951233,
0.010002226568758488,
0.03943217918276787,
-0.04092926159501076,
-0.021417273208498955,
0.027966707944869995,
0.045797303318977356,
0.003429459873586893,
-0.034880612045526505,
0.007257926743477583,
-0.08480842411518097,
-0.07086856663227081,
-5.752553806159476e-33,
0.004376850090920925,
0.047690268605947495,
-0.059045564383268356,
0.05799824371933937,
-0.013176338747143745,
-0.03054887428879738,
-0.05382165685296059,
-0.05851735174655914,
-0.08771210163831711,
0.08922593295574188,
-0.03724447265267372,
0.01889488287270069,
0.09647255390882492,
0.019675716757774353,
-0.027689408510923386,
-0.0294784065335989,
-0.06817885488271713,
-0.00007612998888362199,
0.03678790479898453,
0.009994802996516228,
-0.013344645500183105,
-0.002909791423007846,
0.13685229420661926,
-0.05026678368449211,
0.002828761236742139,
0.0017891953466460109,
-0.04974101856350899,
0.01744702458381653,
-0.07278646528720856,
0.01510060578584671,
-0.02290007658302784,
-0.003335291286930442,
-0.022759409621357918,
-0.02220246195793152,
-0.021043306216597557,
-0.028308147564530373,
-0.025860091671347618,
0.09364353865385056,
0.08189629018306732,
-0.015483343042433262,
0.029521282762289047,
-0.07112453132867813,
-0.08931789547204971,
-0.0018291737651452422,
0.006977580022066832,
-0.0011996268294751644,
-0.09037884324789047,
0.022297944873571396,
-0.08124155551195145,
0.00019179360242560506,
-0.10579081624746323,
0.024606147781014442,
-0.022241447120904922,
-0.018204955384135246,
-0.04682432860136032,
-0.025438155978918076,
0.04012659937143326,
0.05394526198506355,
0.025839287787675858,
0.0140661196783185,
0.14400216937065125,
-0.11895400285720825,
-0.052152328193187714,
0.018707696348428726,
0.02534935064613819,
-0.06665290892124176,
-0.04488932341337204,
-0.061926811933517456,
0.07713992148637772,
-0.005240840837359428,
0.029556289315223694,
0.03726012632250786,
-0.030123744159936905,
-0.027100468054413795,
0.009887350723147392,
0.07250115275382996,
-0.02434728667140007,
-0.10898073762655258,
-0.0066301231272518635,
0.07516645640134811,
-0.11494452506303787,
0.08649016171693802,
0.0009502312750555575,
0.008938251063227654,
0.0179621372371912,
0.007908647879958153,
0.014969288371503353,
0.10482633858919144,
0.06601599603891373,
0.043150875717401505,
0.0020056436769664288,
0.048413924872875214,
-0.056082673370838165,
-0.05619777739048004,
-0.02363813854753971,
-5.311001416430372e-8,
0.012835577130317688,
0.045300036668777466,
-0.04629187658429146,
0.10168356448411942,
-0.03322814032435417,
-0.031345635652542114,
-0.07215973734855652,
-0.050864819437265396,
0.06468817591667175,
0.10717277973890305,
-0.050307270139455795,
-0.003749014576897025,
0.024195745587348938,
0.020600927993655205,
0.042362965643405914,
0.030247783288359642,
-0.022909102961421013,
-0.06175609305500984,
0.0006885211332701147,
-0.008066467940807343,
0.06347888708114624,
0.0077108596451580524,
-0.021227115765213966,
0.12949250638484955,
-0.05361856147646904,
-0.06555742025375366,
0.09292545169591904,
-0.01630345918238163,
-0.11375042051076889,
-0.029863813892006874,
-0.03310880810022354,
0.004144302103668451,
-0.04019435867667198,
0.06964148581027985,
0.009491126984357834,
-0.016646116971969604,
-0.06965184211730957,
0.08254387229681015,
0.04478389769792557,
-0.006899792701005936,
-0.061521030962467194,
-0.021382637321949005,
-0.059403251856565475,
0.04375933110713959,
0.008943570777773857,
0.043891917914152145,
-0.022950196638703346,
-0.02308606542646885,
-0.0031946946401149035,
0.0757378414273262,
0.014035047963261604,
-0.02323872596025467,
-0.039803553372621536,
0.057112470269203186,
0.011815973557531834,
0.027490908280014992,
0.03387032449245453,
-0.06166653335094452,
-0.006269313395023346,
0.003093437757343054,
-0.02878033183515072,
-0.037540189921855927,
0.015657059848308563,
-0.045915860682725906
] | 0.050621 |
```cjs // repl-client.js const net = require('node:net'); const sock = net.connect(1337); process.stdin.pipe(sock); sock.pipe(process.stdout); sock.on('connect', () => { process.stdin.resume(); process.stdin.setRawMode(true); }); sock.on('close', () => { process.stdin.setRawMode(false); process.stdin.pause(); sock.removeListener('close', done); }); process.stdin.on('end', () => { sock.destroy(); console.log(); }); process.stdin.on('data', (b) => { if (b.length === 1 && b[0] === 4) { process.stdin.emit('end'); } }); ``` To run the example open two different terminals on your machine, start the server with `node repl-server.js` in one terminal and `node repl-client.js` on the other. Original code from . #### REPL over `curl` This is an example on how to run a REPL instance over [`curl()`][] The following script starts an HTTP server on port `8000` that can accept a connection established via [`curl()`][]. ```mjs import http from 'node:http'; import repl from 'node:repl'; const server = http.createServer((req, res) => { res.setHeader('content-type', 'multipart/octet-stream'); repl.start({ prompt: 'curl repl> ', input: req, output: res, terminal: false, useColors: true, useGlobal: false, }); }); server.listen(8000); ``` ```cjs const http = require('node:http'); const repl = require('node:repl'); const server = http.createServer((req, res) => { res.setHeader('content-type', 'multipart/octet-stream'); repl.start({ prompt: 'curl repl> ', input: req, output: res, terminal: false, useColors: true, useGlobal: false, }); }); server.listen(8000); ``` When the above script is running you can then use [`curl()`][] to connect to the server and connect to its REPL instance by running `curl --no-progress-meter -sSNT. localhost:8000`. \*\*Warning\*\* This example is intended purely for educational purposes to demonstrate how Node.js REPLs can be started using different I/O streams. It should \*\*not\*\* be used in production environments or any context where security is a concern without additional protective measures. If you need to implement REPLs in a real-world application, consider alternative approaches that mitigate these risks, such as using secure input mechanisms and avoiding open network interfaces. Original code from . [TTY keybindings]: readline.md#tty-keybindings [ZSH]: https://en.wikipedia.org/wiki/Z\_shell [`'uncaughtException'`]: process.md#event-uncaughtexception [`--no-experimental-repl-await`]: cli.md#--no-experimental-repl-await [`ERR\_DOMAIN\_CANNOT\_SET\_UNCAUGHT\_EXCEPTION\_CAPTURE`]: errors.md#err\_domain\_cannot\_set\_uncaught\_exception\_capture [`ERR\_INVALID\_REPL\_INPUT`]: errors.md#err\_invalid\_repl\_input [`curl()`]: https://curl.haxx.se/docs/manpage.html [`domain`]: domain.md [`module.builtinModules`]: module.md#modulebuiltinmodules [`net.Server`]: net.md#class-netserver [`net.Socket`]: net.md#class-netsocket [`process.setUncaughtExceptionCaptureCallback()`]: process.md#processsetuncaughtexceptioncapturecallbackfn [`readline.InterfaceCompleter`]: readline.md#use-of-the-completer-function [`repl.ReplServer`]: #class-replserver [`repl.start()`]: #replstartoptions [`reverse-i-search`]: #reverse-i-search [`util.inspect()`]: util.md#utilinspectobject-options [custom evaluation functions]: #custom-evaluation-functions [stream]: stream.md | https://github.com/nodejs/node/blob/main//doc/api/repl.md | main | nodejs | [
-0.05708641931414604,
-0.03481581062078476,
-0.06370183080434799,
-0.004822243936359882,
-0.04742738977074623,
-0.009840035811066628,
-0.034226302057504654,
0.0527963861823082,
0.06305702775716782,
-0.0018675742903724313,
-0.08452579379081726,
0.05249631404876709,
-0.043156374245882034,
-0.023466331884264946,
-0.015734106302261353,
0.014544588513672352,
-0.07502438127994537,
-0.008807928301393986,
0.028900207951664925,
-0.11471175402402878,
0.019466862082481384,
-0.044533029198646545,
0.01520196907222271,
-0.08209075033664703,
-0.04223453253507614,
-0.016572196036577225,
0.018142061308026314,
-0.030067427083849907,
0.028523467481136322,
0.019612165167927742,
0.010768869891762733,
-0.06867758929729462,
-0.1273728609085083,
0.024502310901880264,
-0.00951138511300087,
0.11835721880197525,
-0.06308254599571228,
-0.03127913549542427,
-0.07451595366001129,
0.0345316119492054,
0.09909055382013321,
0.023686300963163376,
-0.08387361466884613,
-0.02227281592786312,
0.023791735991835594,
-0.01903204619884491,
-0.11330026388168335,
-0.04172121360898018,
0.024997573345899582,
-0.004617189988493919,
-0.064380943775177,
0.007186155300587416,
-0.013921113684773445,
0.042426396161317825,
0.018355412408709526,
-0.027217727154493332,
0.01608431711792946,
0.01705830916762352,
0.025834903120994568,
0.022980807349085808,
-0.03983465954661369,
0.007869254797697067,
0.003337492700666189,
0.01166176050901413,
0.05868854001164436,
0.055461615324020386,
-0.025103464722633362,
0.04717867448925972,
0.004665115382522345,
0.012971239164471626,
-0.05645709112286568,
0.03031383827328682,
-0.09864023327827454,
-0.01579378731548786,
-0.10715626180171967,
-0.06526771932840347,
-0.011746537871658802,
0.003897426649928093,
-0.06696783751249313,
0.03061586432158947,
-0.007140544708818197,
-0.04149539768695831,
-0.07546526193618774,
0.0472017377614975,
-0.06625153124332428,
0.16650617122650146,
-0.012538067996501923,
-0.020225970074534416,
0.022759217768907547,
0.027756784111261368,
-0.09562628716230392,
0.042324673384428024,
-0.05434171482920647,
0.06678710132837296,
0.025948522612452507,
0.021663032472133636,
0.03961166739463806,
0.04812758043408394,
-0.027089040726423264,
0.020424945279955864,
0.015191770158708096,
0.0224410742521286,
-0.0029849205166101456,
-0.004875753074884415,
0.01585671678185463,
-0.054021693766117096,
0.022093547508120537,
0.04499950259923935,
-0.00018601620104163885,
-0.033124327659606934,
-0.004127110820263624,
0.031759776175022125,
-0.016264885663986206,
0.019313592463731766,
0.010459570214152336,
0.057067062705755234,
0.08738382160663605,
0.033169787377119064,
0.024233663454651833,
0.10780057311058044,
0.05808724835515022,
0.0012897197157144547,
-0.08455894142389297,
-0.012706499546766281,
0.03733062371611595,
-0.07914739847183228,
0.11807142943143845,
1.4733485481088275e-33,
-0.026153456419706345,
-0.1134856566786766,
0.0020078090019524097,
0.03133222088217735,
0.10416563600301743,
0.03170529380440712,
0.022310476750135422,
0.046147823333740234,
-0.11428379267454147,
0.06442330777645111,
-0.024940991774201393,
-0.037186481058597565,
0.026502570137381554,
-0.07530998438596725,
-0.03995644673705101,
-0.06368497759103775,
0.10770756006240845,
0.023691661655902863,
0.05431128665804863,
-0.0065069496631622314,
0.08140089362859726,
-0.04766750708222389,
0.014899100176990032,
0.04314359650015831,
0.021806322038173676,
-0.04330473765730858,
-0.045793432742357254,
0.07511034607887268,
0.025755999609827995,
-0.02302863635122776,
0.08055990189313889,
0.0532805398106575,
-0.015985501930117607,
0.05697259679436684,
-0.04781576991081238,
-0.08745809644460678,
0.03618479147553444,
0.04536881670355797,
-0.0171576589345932,
-0.04860854148864746,
0.05705326795578003,
0.0000073987303039757535,
-0.050096333026885986,
0.05954229459166527,
-0.04796779155731201,
-0.11068277806043625,
-0.0644664317369461,
-0.03551380708813667,
0.02745559997856617,
0.002620039274916053,
0.056808438152074814,
0.09069837629795074,
0.02205655723810196,
-0.04641525074839592,
0.02072266675531864,
0.005102481227368116,
-0.005140059161931276,
0.002256795298308134,
-0.05432263761758804,
0.055580247193574905,
0.02070438861846924,
0.07849092036485672,
-0.049406569451093674,
-0.02279558777809143,
0.06381408125162125,
-0.005059035494923592,
-0.06961081176996231,
-0.04223116487264633,
-0.016823390498757362,
-0.001941160298883915,
-0.10494533181190491,
-0.03260551765561104,
0.026028333231806755,
-0.02700933814048767,
0.027581576257944107,
0.06993437558412552,
-0.07463356852531433,
0.05119703710079193,
-0.007305619306862354,
-0.0500619038939476,
0.06496346741914749,
-0.05243472382426262,
-0.044945891946554184,
0.03933445364236832,
0.06720879673957825,
0.014284930191934109,
-0.049189310520887375,
-0.01586180552840233,
0.035271674394607544,
0.055138908326625824,
-0.008708200417459011,
0.015479161404073238,
0.0394354909658432,
-0.04297199472784996,
-0.036343470215797424,
-4.054728540549305e-33,
-0.019030895084142685,
0.07100135087966919,
-0.07818420976400375,
0.06380952149629593,
0.00914306566119194,
-0.04306419566273689,
0.023658007383346558,
-0.06799633055925369,
-0.058265041559934616,
0.06167471781373024,
0.07325056195259094,
0.022474531084299088,
0.016851823776960373,
0.09331941604614258,
-0.019595326855778694,
0.014377912506461143,
-0.0003131046541966498,
0.06469786912202835,
-0.007720245514065027,
0.014433636330068111,
-0.03882038965821266,
0.03745691850781441,
0.057213254272937775,
-0.012924835085868835,
-0.04699885845184326,
0.006822577677667141,
-0.002722014207392931,
0.00709810433909297,
-0.09050516784191132,
-0.044314123690128326,
-0.010520987212657928,
-0.0032723809126764536,
-0.03795456141233444,
0.02177022397518158,
-0.012820210307836533,
-0.04277652129530907,
0.03955098241567612,
0.061014603823423386,
0.09316371381282806,
-0.004249514080584049,
0.15554028749465942,
-0.05249609425663948,
-0.09303531050682068,
-0.02258184179663658,
0.04866454750299454,
-0.01776980422437191,
-0.06914686411619186,
0.01768031343817711,
-0.0673644170165062,
0.010093324817717075,
-0.056377120316028595,
0.030354170128703117,
-0.006904446054250002,
-0.01022956520318985,
0.002098226919770241,
-0.01755346544086933,
0.08816783875226974,
-0.056538570672273636,
0.02710098773241043,
-0.025113344192504883,
0.07852641493082047,
-0.11780374497175217,
0.013084218837320805,
0.024928463622927666,
0.10222283005714417,
-0.0635179802775383,
-0.07860268652439117,
0.06897715479135513,
0.08621406555175781,
-0.0728980004787445,
-0.034306738525629044,
0.08018729835748672,
0.03058040514588356,
0.04299455136060715,
-0.022523794323205948,
-0.03347836062312126,
-0.014782036654651165,
-0.10875405371189117,
0.03727245330810547,
0.09054602682590485,
-0.025092540308833122,
0.0665392205119133,
-0.02658175118267536,
0.01650938019156456,
0.03585372120141983,
0.03803358972072601,
0.023041116073727608,
0.032429568469524384,
0.032090649008750916,
-0.0031316126696765423,
-0.02593495324254036,
0.0477166585624218,
-0.03064155951142311,
-0.0012702468084171414,
0.030356988310813904,
-5.375200018420401e-8,
-0.04232599213719368,
-0.0319099947810173,
-0.0021157937590032816,
0.06667908281087875,
0.03932569921016693,
-0.02565837651491165,
-0.05956582352519035,
-0.03837857395410538,
0.06377580761909485,
0.010641645640134811,
-0.07306896150112152,
0.017614034935832024,
0.0444454662501812,
0.02816564030945301,
0.051146190613508224,
0.01952512003481388,
0.004896064288914204,
-0.03995160758495331,
0.06097462400794029,
-0.004890069831162691,
0.01992180570960045,
-0.06633269041776657,
0.0015642663929611444,
0.13475722074508667,
-0.00213823514059186,
-0.10497135668992996,
0.08487513661384583,
0.03447529301047325,
-0.10513114184141159,
-0.05256733298301697,
-0.09040362387895584,
-0.009397758170962334,
0.036057040095329285,
0.008239631541073322,
-0.015086567029356956,
0.02010800689458847,
-0.01926339790225029,
0.0025450640823692083,
0.018877610564231873,
0.03333099186420441,
0.018420597538352013,
0.04392104223370552,
-0.06978451460599899,
-0.006990020629018545,
-0.02508234605193138,
0.006868288386613131,
0.021478304639458656,
0.024881824851036072,
-0.002412814646959305,
0.018788522109389305,
-0.009349285624921322,
-0.02448906935751438,
-0.010588251054286957,
-0.06070712208747864,
0.03064417652785778,
-0.05228747799992561,
-0.029132451862096786,
-0.06886489689350128,
-0.058443985879421234,
0.06286142766475677,
0.007526973262429237,
0.06482165306806564,
-0.06179516762495041,
-0.0744800865650177
] | 0.056054 |
# Events > Stability: 2 - Stable Much of the Node.js core API is built around an idiomatic asynchronous event-driven architecture in which certain kinds of objects (called "emitters") emit named events that cause `Function` objects ("listeners") to be called. For instance: a [`net.Server`][] object emits an event each time a peer connects to it; a [`fs.ReadStream`][] emits an event when the file is opened; a [stream][] emits an event whenever data is available to be read. All objects that emit events are instances of the `EventEmitter` class. These objects expose an `eventEmitter.on()` function that allows one or more functions to be attached to named events emitted by the object. Typically, event names are camel-cased strings but any valid JavaScript property key can be used. When the `EventEmitter` object emits an event, all of the functions attached to that specific event are called \_synchronously\_. Any values returned by the called listeners are \_ignored\_ and discarded. The following example shows a simple `EventEmitter` instance with a single listener. The `eventEmitter.on()` method is used to register listeners, while the `eventEmitter.emit()` method is used to trigger the event. ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('event', () => { console.log('an event occurred!'); }); myEmitter.emit('event'); ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('event', () => { console.log('an event occurred!'); }); myEmitter.emit('event'); ``` ## Passing arguments and `this` to listeners The `eventEmitter.emit()` method allows an arbitrary set of arguments to be passed to the listener functions. Keep in mind that when an ordinary listener function is called, the standard `this` keyword is intentionally set to reference the `EventEmitter` instance to which the listener is attached. ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('event', function(a, b) { console.log(a, b, this, this === myEmitter); // Prints: // a b MyEmitter { // \_events: [Object: null prototype] { event: [Function (anonymous)] }, // \_eventsCount: 1, // \_maxListeners: undefined, // Symbol(shapeMode): false, // Symbol(kCapture): false // } true }); myEmitter.emit('event', 'a', 'b'); ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('event', function(a, b) { console.log(a, b, this, this === myEmitter); // Prints: // a b MyEmitter { // \_events: [Object: null prototype] { event: [Function (anonymous)] }, // \_eventsCount: 1, // \_maxListeners: undefined, // Symbol(shapeMode): false, // Symbol(kCapture): false // } true }); myEmitter.emit('event', 'a', 'b'); ``` It is possible to use ES6 Arrow Functions as listeners, however, when doing so, the `this` keyword will no longer reference the `EventEmitter` instance: ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('event', (a, b) => { console.log(a, b, this); // Prints: a b undefined }); myEmitter.emit('event', 'a', 'b'); ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('event', (a, b) => { console.log(a, b, this); // Prints: a b {} }); myEmitter.emit('event', 'a', 'b'); ``` ## Asynchronous vs. synchronous The `EventEmitter` calls all listeners synchronously in the order in which they were registered. This ensures the proper sequencing of events and helps avoid race conditions and logic errors. When appropriate, listener functions can switch to an asynchronous mode of operation using the `setImmediate()` or `process.nextTick()` methods: ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('event', (a, b) => { setImmediate(() => { console.log('this happens asynchronously'); }); }); myEmitter.emit('event', 'a', 'b'); ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends | https://github.com/nodejs/node/blob/main//doc/api/events.md | main | nodejs | [
-0.04668070003390312,
-0.05048558861017227,
0.03122340701520443,
0.10821567475795746,
0.06232919171452522,
-0.033050548285245895,
0.024643732234835625,
0.016222143545746803,
0.13800999522209167,
0.008111572824418545,
-0.06321254372596741,
0.09061869233846664,
-0.06459853053092957,
-0.05196215584874153,
0.016389383003115654,
0.025482969358563423,
0.043668851256370544,
-0.008449574932456017,
-0.09937189519405365,
-0.0448673740029335,
-0.06812895834445953,
-0.10252395272254944,
-0.07399635761976242,
-0.03680645301938057,
-0.04792233183979988,
-0.00308540603145957,
-0.03292372450232506,
-0.044599905610084534,
0.033133234828710556,
0.01841604895889759,
0.018225353211164474,
-0.10632742941379547,
-0.09235984086990356,
0.027989938855171204,
-0.06506260484457016,
0.05571427568793297,
0.010839284397661686,
-0.10943657159805298,
-0.047798413783311844,
-0.015347573906183243,
0.09509699791669846,
0.021227601915597916,
-0.060948699712753296,
-0.053767312318086624,
-0.0000661640806356445,
-0.022735992446541786,
-0.06839647889137268,
-0.029697205871343613,
-0.11807946860790253,
0.01886601559817791,
-0.015818998217582703,
-0.018322058022022247,
-0.04162883386015892,
0.04164921119809151,
0.06440187245607376,
0.03605566918849945,
-0.00468398118391633,
0.013627837412059307,
-0.00710369274020195,
0.03386233374476433,
0.02521819807589054,
-0.050873175263404846,
-0.029449261724948883,
0.043324824422597885,
0.08113391697406769,
0.03152717277407646,
0.021078767254948616,
0.03646579384803772,
0.039116304367780685,
0.014229239895939827,
0.007459769491106272,
0.062186431139707565,
-0.024696433916687965,
0.008549625985324383,
0.02818295545876026,
-0.0943007692694664,
-0.0238470658659935,
-0.016167424619197845,
-0.030538363382220268,
0.015304671600461006,
-0.008517458103597164,
-0.04520922899246216,
0.009070463478565216,
-0.00992745440453291,
0.023565292358398438,
0.08996467292308807,
-0.015451188199222088,
0.01790207251906395,
-0.05337027087807655,
0.055218782275915146,
-0.12809844315052032,
-0.02115773782134056,
0.05881663039326668,
0.06160064414143562,
-0.008513876236975193,
0.0550578236579895,
0.042300619184970856,
-0.010661794804036617,
0.02928515523672104,
-0.010196134448051453,
-0.017581041902303696,
0.0700313001871109,
-0.03722625598311424,
0.0307999886572361,
0.041669003665447235,
-0.05710706487298012,
-0.06786651909351349,
-0.035928886383771896,
-0.03532029688358307,
0.02512027509510517,
-0.019331032410264015,
0.02151814103126526,
-0.032361410558223724,
-0.0339437834918499,
-0.05473342910408974,
0.009266997687518597,
0.0376598984003067,
0.0176196601241827,
0.05832229554653168,
0.09881170839071274,
0.12132109701633453,
0.04883094131946564,
-0.0025272532366216183,
-0.024137407541275024,
0.036242883652448654,
-0.05128082260489464,
0.025710178539156914,
5.173868222825234e-33,
-0.04818598926067352,
-0.0792696550488472,
-0.045264631509780884,
0.03180185705423355,
0.04291551560163498,
0.011002643965184689,
0.008732509799301624,
-0.06435438245534897,
-0.06677057594060898,
0.034683044999837875,
0.0016320898430421948,
0.04660847410559654,
0.029658280313014984,
-0.05800483003258705,
0.0791044607758522,
-0.03470388799905777,
0.01861477643251419,
0.007920580916106701,
0.057308539748191833,
0.009870498441159725,
-0.02939602918922901,
-0.016030697152018547,
-0.026922591030597687,
0.08240630477666855,
0.04396293684840202,
-0.011978344060480595,
-0.005170699208974838,
0.07691949605941772,
-0.04216380417346954,
0.009594788774847984,
0.0027624566573649645,
0.03211694583296776,
-0.013370019383728504,
-0.004404368810355663,
0.001591021311469376,
-0.04212002456188202,
-0.027817681431770325,
-0.06699392199516296,
-0.08301813900470734,
-0.05415301024913788,
-0.006606521084904671,
0.021654509007930756,
-0.14727315306663513,
-0.009112577885389328,
-0.06387276947498322,
-0.07087226957082748,
-0.06339758634567261,
-0.0473736934363842,
0.03705080226063728,
-0.06788096576929092,
-0.014184621162712574,
0.0343792550265789,
0.10227715224027634,
-0.02074492909014225,
0.04842856898903847,
0.05615243315696716,
0.04779435321688652,
-0.042449451982975006,
-0.07192055881023407,
0.08013094216585159,
0.08902066946029663,
-0.05753684416413307,
-0.001577148213982582,
-0.04535873979330063,
0.026090865954756737,
0.03148118779063225,
-0.030024679377675056,
-0.0710657462477684,
0.017614757642149925,
-0.00832253135740757,
0.01715024933218956,
0.09211080521345139,
-0.009235834702849388,
-0.03236980736255646,
0.011276447214186192,
0.03141114488244057,
-0.09631433337926865,
-0.006484895013272762,
-0.024120664224028587,
0.025124337524175644,
-0.010827046819031239,
-0.07110004872083664,
-0.021473689004778862,
0.10500023514032364,
-0.012189590372145176,
0.016359206289052963,
-0.09322809427976608,
-0.002758611226454377,
-0.023025698959827423,
0.03135659173130989,
0.07358793914318085,
0.02284221537411213,
0.0546724796295166,
-0.07297727465629578,
-0.07752610743045807,
-6.872924451425906e-33,
-0.05024943873286247,
0.011271009221673012,
-0.14978939294815063,
0.11169692128896713,
-0.020612644031643867,
-0.008337718434631824,
-0.12084593623876572,
-0.023212552070617676,
-0.029080169275403023,
0.012422353960573673,
-0.01205381564795971,
0.026833083480596542,
-0.06450402736663818,
-0.008821896277368069,
0.0149257006123662,
0.04410216957330704,
-0.04251205176115036,
-0.10497669875621796,
0.04476580768823624,
-0.0390290729701519,
0.017237504944205284,
0.007565849926322699,
0.033809468150138855,
-0.012749849818646908,
-0.005625506862998009,
-0.01943613402545452,
-0.04204970598220825,
-0.017146626487374306,
-0.023345012217760086,
-0.053662847727537155,
-0.07309357821941376,
0.016948087140917778,
-0.01908104121685028,
-0.01323667261749506,
0.03422972559928894,
-0.03725627437233925,
0.038020625710487366,
0.006396882236003876,
0.02321908436715603,
-0.08146033436059952,
0.0524434819817543,
0.06022580713033676,
-0.00024173004203476012,
-0.009378696791827679,
0.026530800387263298,
0.06170377880334854,
-0.06930594146251678,
0.12390070408582687,
0.007887664251029491,
-0.0011717675952240825,
-0.018138829618692398,
-0.05532913655042648,
0.0037144948728382587,
0.050442323088645935,
0.0010082360822707415,
0.03782566636800766,
0.014019673690199852,
-0.031118959188461304,
0.05757734179496765,
0.06365984678268433,
0.059266336262226105,
-0.10553131252527237,
-0.019092803820967674,
0.10184763371944427,
-0.002711750101298094,
0.015149849466979504,
-0.055694278329610825,
-0.024069273844361305,
0.08667059242725372,
0.00930643267929554,
0.02492152340710163,
0.0094448896124959,
-0.05937650799751282,
-0.02736622467637062,
-0.040034275501966476,
0.02064596302807331,
0.001697385567240417,
-0.1628786027431488,
0.025908660143613815,
0.020680151879787445,
-0.08574261516332626,
0.13613958656787872,
-0.01929968222975731,
0.026864172890782356,
0.048439279198646545,
0.03637067228555679,
0.018403351306915283,
0.010825306177139282,
0.027499007061123848,
-0.01176038384437561,
-0.0015968778170645237,
0.06533851474523544,
-0.10797954350709915,
0.016324182972311974,
-0.09749361872673035,
-6.289702980666334e-8,
-0.03420937806367874,
0.03067743591964245,
-0.08077675849199295,
-0.0013490868732333183,
0.02536553516983986,
-0.015621799044311047,
0.005952951963990927,
-0.005416021682322025,
0.09246505796909332,
0.033684998750686646,
0.0039449455216526985,
-0.03795944154262543,
0.04802330955862999,
-0.053788743913173676,
0.05484931915998459,
0.039424244314432144,
0.06732018291950226,
0.002701563760638237,
-0.03800974786281586,
-0.008191938512027264,
0.04932631179690361,
0.018623409792780876,
-0.0031674865167587996,
0.05531700700521469,
-0.005703447852283716,
-0.014355196617543697,
0.07757821679115295,
0.10324505716562271,
0.027943996712565422,
-0.02542608231306076,
-0.08806107193231583,
0.044591013342142105,
0.050880130380392075,
0.0025381757877767086,
-0.04612376540899277,
0.050717052072286606,
0.0043003009632229805,
-0.051756057888269424,
0.05022858455777168,
0.05126726254820824,
0.09746748208999634,
-0.024067245423793793,
-0.034686919301748276,
0.08217041194438934,
-0.015541098080575466,
0.06118306145071983,
-0.0031342124566435814,
-0.007099014241248369,
0.027163159102201462,
0.04760242626070976,
-0.01486879214644432,
-0.05163334310054779,
-0.04173373803496361,
0.018244795501232147,
0.006187486927956343,
-0.030690927058458328,
0.048385027796030045,
-0.07148390263319016,
0.06146576255559921,
0.0012343653943389654,
0.048134103417396545,
0.07326347380876541,
-0.014629366807639599,
-0.004312528297305107
] | 0.208408 |
of operation using the `setImmediate()` or `process.nextTick()` methods: ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('event', (a, b) => { setImmediate(() => { console.log('this happens asynchronously'); }); }); myEmitter.emit('event', 'a', 'b'); ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('event', (a, b) => { setImmediate(() => { console.log('this happens asynchronously'); }); }); myEmitter.emit('event', 'a', 'b'); ``` ## Handling events only once When a listener is registered using the `eventEmitter.on()` method, that listener is invoked \_every time\_ the named event is emitted. ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); let m = 0; myEmitter.on('event', () => { console.log(++m); }); myEmitter.emit('event'); // Prints: 1 myEmitter.emit('event'); // Prints: 2 ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); let m = 0; myEmitter.on('event', () => { console.log(++m); }); myEmitter.emit('event'); // Prints: 1 myEmitter.emit('event'); // Prints: 2 ``` Using the `eventEmitter.once()` method, it is possible to register a listener that is called at most once for a particular event. Once the event is emitted, the listener is unregistered and \_then\_ called. ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); let m = 0; myEmitter.once('event', () => { console.log(++m); }); myEmitter.emit('event'); // Prints: 1 myEmitter.emit('event'); // Ignored ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); let m = 0; myEmitter.once('event', () => { console.log(++m); }); myEmitter.emit('event'); // Prints: 1 myEmitter.emit('event'); // Ignored ``` ## Error events When an error occurs within an `EventEmitter` instance, the typical action is for an `'error'` event to be emitted. These are treated as special cases within Node.js. If an `EventEmitter` does \_not\_ have at least one listener registered for the `'error'` event, and an `'error'` event is emitted, the error is thrown, a stack trace is printed, and the Node.js process exits. ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.emit('error', new Error('whoops!')); // Throws and crashes Node.js ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.emit('error', new Error('whoops!')); // Throws and crashes Node.js ``` To guard against crashing the Node.js process the [`domain`][] module can be used. (Note, however, that the `node:domain` module is deprecated.) As a best practice, listeners should always be added for the `'error'` events. ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('error', (err) => { console.error('whoops! there was an error'); }); myEmitter.emit('error', new Error('whoops!')); // Prints: whoops! there was an error ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); myEmitter.on('error', (err) => { console.error('whoops! there was an error'); }); myEmitter.emit('error', new Error('whoops!')); // Prints: whoops! there was an error ``` It is possible to monitor `'error'` events without consuming the emitted error by installing a listener using the symbol `events.errorMonitor`. ```mjs import { EventEmitter, errorMonitor } from 'node:events'; const myEmitter = new EventEmitter(); myEmitter.on(errorMonitor, (err) => { MyMonitoringTool.log(err); }); myEmitter.emit('error', new Error('whoops!')); // Still throws and crashes Node.js ``` ```cjs const { EventEmitter, errorMonitor } = require('node:events'); const myEmitter = new EventEmitter(); myEmitter.on(errorMonitor, (err) => { MyMonitoringTool.log(err); }); myEmitter.emit('error', new Error('whoops!')); // Still throws and crashes Node.js ``` ## Capture rejections of promises Using `async` functions with event handlers is problematic, because it can lead to an unhandled rejection in case of a thrown exception: ```mjs import | https://github.com/nodejs/node/blob/main//doc/api/events.md | main | nodejs | [
-0.01623016595840454,
-0.017787819728255272,
-0.005198770668357611,
0.03892350196838379,
-0.016035065054893494,
0.00565071078017354,
0.046256471425294876,
0.06583037227392197,
0.09656588733196259,
-0.0017623498570173979,
-0.027975013479590416,
-0.00917953159660101,
-0.05214841291308403,
-0.011027931235730648,
0.07537230849266052,
0.002634520875290036,
0.008056627586483955,
0.019681358709931374,
-0.08444831520318985,
-0.08668431639671326,
-0.029747286811470985,
-0.090375617146492,
0.005437311716377735,
-0.01857626624405384,
-0.04958471283316612,
-0.08740206062793732,
-0.0010350857628509402,
-0.052115533500909805,
0.11896322667598724,
0.01717975176870823,
0.03914143517613411,
-0.06147450953722,
-0.15130701661109924,
0.026449957862496376,
-0.05622849613428116,
0.08038567751646042,
-0.0562339723110199,
-0.10004600137472153,
-0.02287566103041172,
-0.01481117494404316,
0.11192156374454498,
0.0034867480862885714,
-0.05994546785950661,
-0.05325794219970703,
0.05268048867583275,
-0.03725447505712509,
-0.06530729681253433,
0.0334528386592865,
-0.08810628950595856,
0.01633463241159916,
0.001448037102818489,
0.006794404238462448,
-0.03268042579293251,
-0.013528772629797459,
0.011791816912591457,
0.0359383225440979,
0.08111108094453812,
0.003820432350039482,
0.03824331611394882,
0.006502688396722078,
-0.02107560634613037,
-0.03917103633284569,
-0.0018411977216601372,
0.03704610466957092,
0.01673288829624653,
0.0073010907508432865,
0.013291383162140846,
0.06624924391508102,
0.0438031405210495,
0.08683480322360992,
-0.016969550400972366,
-0.02303389646112919,
0.021681489422917366,
0.05268515646457672,
-0.026362815871834755,
-0.09604760259389877,
-0.0027553474064916372,
0.07617659121751785,
-0.10888697952032089,
0.014745863154530525,
-0.0014488641172647476,
-0.05761145055294037,
-0.016063451766967773,
-0.0036192317493259907,
0.04535854235291481,
0.05593203753232956,
-0.07060761004686356,
-0.029121216386556625,
-0.010731741786003113,
0.06119278073310852,
-0.09086743742227554,
0.0008129252237267792,
-0.034815724939107895,
0.055146224796772,
0.006206908728927374,
0.023188946768641472,
0.07409760355949402,
0.021875932812690735,
0.05570216104388237,
0.013883532024919987,
-0.009890738874673843,
0.040864646434783936,
-0.08057291060686111,
0.04456273466348648,
-0.00011463384726084769,
-0.05523122102022171,
-0.11920028179883957,
-0.05547675862908363,
-0.03015006333589554,
-0.05065551772713661,
0.025215081870555878,
-0.005272312089800835,
0.011188876815140247,
-0.0020005833357572556,
-0.033107951283454895,
0.05701758712530136,
0.0668802261352539,
0.0035579330287873745,
0.07298032939434052,
0.06111996993422508,
0.07033547013998032,
0.031122971326112747,
-0.004072854295372963,
-0.044918645173311234,
0.013076831586658955,
-0.0555759072303772,
0.038118500262498856,
2.5252092703929232e-33,
0.008210758678615093,
-0.10253703594207764,
-0.0895792618393898,
-0.0037589247804135084,
0.002376657910645008,
0.11115676164627075,
0.0036541749723255634,
-0.01902470365166664,
-0.0667046383023262,
-0.009136305190622807,
0.03580581024289131,
-0.05530102923512459,
0.01779870130121708,
-0.05839424580335617,
0.04288538917899132,
-0.03608013316988945,
0.06457576155662537,
-0.04414677992463112,
0.056182973086833954,
0.011949168518185616,
0.019967658445239067,
0.010985863395035267,
-0.059997573494911194,
0.06925270706415176,
0.017947033047676086,
0.020413415506482124,
-0.003900200128555298,
0.03944999352097511,
-0.06820754706859589,
0.010454094037413597,
0.03488558903336525,
0.0714118629693985,
-0.06038713827729225,
-0.0037085369694978,
-0.021866032853722572,
-0.04951887205243111,
-0.062163062393665314,
0.0026048053987324238,
-0.08750732988119125,
-0.1014743372797966,
0.011097271926701069,
-0.010733814910054207,
-0.0972430557012558,
-0.05302520468831062,
-0.053030434995889664,
-0.07077905535697937,
-0.06719169020652771,
-0.000964451115578413,
0.09212864190340042,
-0.08184486627578735,
0.011576799675822258,
0.03762489929795265,
0.09811615943908691,
-0.035319678485393524,
0.07700429856777191,
0.08026915043592453,
0.015436251647770405,
-0.015486257150769234,
-0.05540040135383606,
0.048977483063936234,
0.019453298300504684,
-0.04729313775897026,
-0.0642295554280281,
0.062277983874082565,
-0.06834927201271057,
0.044496189802885056,
-0.06523261219263077,
-0.07161932438611984,
0.043884094804525375,
-0.06827155500650406,
0.019281167536973953,
0.03671976923942566,
-0.009065162390470505,
-0.0011400323128327727,
0.0036820215173065662,
0.08074314892292023,
-0.08545882999897003,
0.008324023336172104,
-0.0564892441034317,
-0.04222317785024643,
0.007689987774938345,
0.01154217217117548,
-0.017253488302230835,
0.08508146554231644,
0.030388548970222473,
0.002893059980124235,
-0.0581757053732872,
0.02301592379808426,
0.015159960836172104,
0.04765531048178673,
-0.020935747772455215,
0.006644564680755138,
0.06470533460378647,
-0.04681091755628586,
-0.055232010781764984,
-6.320598594224885e-33,
0.002100848127156496,
0.09597679227590561,
-0.0746978372335434,
0.05847925320267677,
0.019669286906719208,
-0.006409266963601112,
0.004482022020965815,
-0.0696132481098175,
-0.05980750173330307,
0.06958135217428207,
-0.04649200662970543,
0.043287135660648346,
-0.03516734763979912,
-0.018084047362208366,
-0.04514536261558533,
0.03674847632646561,
-0.012461980804800987,
-0.025253931060433388,
0.05381641164422035,
0.0022976757027208805,
-0.020144617184996605,
0.006029192358255386,
0.10019964724779129,
-0.04117624834179878,
-0.010167699307203293,
-0.004757835529744625,
0.01484969723969698,
0.03461878374218941,
-0.06763207167387009,
-0.058109644800424576,
-0.0759793296456337,
-0.015470835380256176,
-0.009240847080945969,
0.04295266792178154,
0.049233730882406235,
-0.03378261625766754,
0.06951036304235458,
0.039397742599248886,
0.020238371565937996,
-0.04686294496059418,
0.09731502830982208,
0.020613547414541245,
-0.026281170547008514,
0.025443674996495247,
-0.0020451575983315706,
0.028680719435214996,
-0.11247945576906204,
0.032115813344717026,
0.033624835312366486,
0.03191190958023071,
-0.07183156907558441,
-0.05382060632109642,
0.02071972005069256,
0.041279226541519165,
-0.015429810620844364,
-0.023584112524986267,
0.05999985337257385,
-0.05443935468792915,
0.046856243163347244,
0.04906851053237915,
0.014428024180233479,
-0.13305392861366272,
0.057882633060216904,
0.06076814606785774,
0.046536535024642944,
-0.012689951807260513,
-0.05929010733962059,
0.012161999940872192,
0.08021282404661179,
-0.001817867043428123,
0.02192308008670807,
0.09342636913061142,
-0.05646036937832832,
-0.039374884217977524,
-0.0008815006585791707,
0.0010586946737021208,
-0.0025710579939186573,
-0.1463443636894226,
0.050336338579654694,
-0.01036022137850523,
-0.05575855076313019,
0.027458153665065765,
-0.005609478801488876,
0.0010528713464736938,
-0.016843421384692192,
0.061178598552942276,
0.010413999669253826,
0.029014408588409424,
0.046168871223926544,
-0.04366276413202286,
-0.042147256433963776,
0.035431552678346634,
-0.06314495950937271,
-0.026438647881150246,
-0.04913846403360367,
-5.508746170335144e-8,
-0.04854616895318031,
-0.03151760995388031,
-0.001779096433892846,
0.017027927562594414,
0.028809024021029472,
-0.0674191266298294,
-0.010727325454354286,
-0.016207925975322723,
0.020965078845620155,
-0.012588719837367535,
-0.08060333877801895,
-0.02656741440296173,
0.1546141654253006,
0.005256077740341425,
0.038586318492889404,
-0.03348613530397415,
0.04290870949625969,
-0.06773599982261658,
-0.03896811977028847,
0.0077620605006814,
-0.01643332652747631,
-0.014623088762164116,
0.06259961426258087,
0.08145982772111893,
-0.00868337880820036,
-0.055748697370290756,
0.038404710590839386,
0.06246183067560196,
0.06629525870084763,
-0.03352891653776169,
-0.1018950492143631,
0.051087506115436554,
0.06980525702238083,
0.030194707214832306,
-0.09058772772550583,
-0.021160056814551353,
-0.0017743484349921346,
-0.03112279251217842,
0.08896192163228989,
0.056108515709638596,
0.048518046736717224,
-0.06154758110642433,
-0.045972082763910294,
0.09211892634630203,
-0.01880098134279251,
-0.013865714892745018,
-0.04397265613079071,
-0.04667215421795845,
0.050544414669275284,
0.08886502683162689,
-0.04139900580048561,
-0.038419291377067566,
-0.03143731504678726,
0.004019217565655708,
0.04081108421087265,
-0.03982364013791084,
-0.004696489777415991,
-0.0645458996295929,
0.07803870737552643,
0.02530677616596222,
-0.0016727704787626863,
0.04494912549853325,
-0.032545123249292374,
-0.05626616254448891
] | 0.104971 |
const myEmitter = new EventEmitter(); myEmitter.on(errorMonitor, (err) => { MyMonitoringTool.log(err); }); myEmitter.emit('error', new Error('whoops!')); // Still throws and crashes Node.js ``` ## Capture rejections of promises Using `async` functions with event handlers is problematic, because it can lead to an unhandled rejection in case of a thrown exception: ```mjs import { EventEmitter } from 'node:events'; const ee = new EventEmitter(); ee.on('something', async (value) => { throw new Error('kaboom'); }); ``` ```cjs const EventEmitter = require('node:events'); const ee = new EventEmitter(); ee.on('something', async (value) => { throw new Error('kaboom'); }); ``` The `captureRejections` option in the `EventEmitter` constructor or the global setting change this behavior, installing a `.then(undefined, handler)` handler on the `Promise`. This handler routes the exception asynchronously to the [`Symbol.for('nodejs.rejection')`][rejection] method if there is one, or to [`'error'`][error] event handler if there is none. ```mjs import { EventEmitter } from 'node:events'; const ee1 = new EventEmitter({ captureRejections: true }); ee1.on('something', async (value) => { throw new Error('kaboom'); }); ee1.on('error', console.log); const ee2 = new EventEmitter({ captureRejections: true }); ee2.on('something', async (value) => { throw new Error('kaboom'); }); ee2[Symbol.for('nodejs.rejection')] = console.log; ``` ```cjs const EventEmitter = require('node:events'); const ee1 = new EventEmitter({ captureRejections: true }); ee1.on('something', async (value) => { throw new Error('kaboom'); }); ee1.on('error', console.log); const ee2 = new EventEmitter({ captureRejections: true }); ee2.on('something', async (value) => { throw new Error('kaboom'); }); ee2[Symbol.for('nodejs.rejection')] = console.log; ``` Setting `events.captureRejections = true` will change the default for all new instances of `EventEmitter`. ```mjs import { EventEmitter } from 'node:events'; EventEmitter.captureRejections = true; const ee1 = new EventEmitter(); ee1.on('something', async (value) => { throw new Error('kaboom'); }); ee1.on('error', console.log); ``` ```cjs const events = require('node:events'); events.captureRejections = true; const ee1 = new events.EventEmitter(); ee1.on('something', async (value) => { throw new Error('kaboom'); }); ee1.on('error', console.log); ``` The `'error'` events that are generated by the `captureRejections` behavior do not have a catch handler to avoid infinite error loops: the recommendation is to \*\*not use `async` functions as `'error'` event handlers\*\*. ## Class: `EventEmitter` The `EventEmitter` class is defined and exposed by the `node:events` module: ```mjs import { EventEmitter } from 'node:events'; ``` ```cjs const EventEmitter = require('node:events'); ``` All `EventEmitter`s emit the event `'newListener'` when new listeners are added and `'removeListener'` when existing listeners are removed. It supports the following option: \* `captureRejections` {boolean} It enables [automatic capturing of promise rejection][capturerejections]. \*\*Default:\*\* `false`. ### Event: `'newListener'` \* `eventName` {string|symbol} The name of the event being listened for \* `listener` {Function} The event handler function The `EventEmitter` instance will emit its own `'newListener'` event \_before\_ a listener is added to its internal array of listeners. Listeners registered for the `'newListener'` event are passed the event name and a reference to the listener being added. The fact that the event is triggered before adding the listener has a subtle but important side effect: any \_additional\_ listeners registered to the same `name` \_within\_ the `'newListener'` callback are inserted \_before\_ the listener that is in the process of being added. ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); // Only do this once so we don't loop forever myEmitter.once('newListener', (event, listener) => { if (event === 'event') { // Insert a new listener in front myEmitter.on('event', () => { console.log('B'); }); } }); myEmitter.on('event', () => { console.log('A'); }); myEmitter.emit('event'); // Prints: // B // A ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); // Only do this once so we don't loop forever myEmitter.once('newListener', (event, listener) => { if (event === 'event') { // Insert a new listener in front | https://github.com/nodejs/node/blob/main//doc/api/events.md | main | nodejs | [
-0.01974034681916237,
0.06558944284915924,
0.06530296802520752,
0.05442727357149124,
0.04719977080821991,
-0.015455065295100212,
0.011709935963153839,
0.08466625213623047,
0.0941966325044632,
-0.002467029495164752,
-0.07766804844141006,
-0.09366794675588608,
-0.023412030190229416,
-0.06758377701044083,
0.004129601176828146,
-0.02107985131442547,
0.009535731747746468,
0.056211985647678375,
-0.04639025032520294,
-0.03583287075161934,
-0.013799807988107204,
-0.05339124798774719,
-0.009520135819911957,
0.008266459219157696,
-0.09369209408760071,
-0.07224095612764359,
-0.06764426082372665,
-0.04571593552827835,
0.03385629132390022,
0.001015030313283205,
0.004962088540196419,
-0.09786149114370346,
-0.09682474285364151,
0.03662420064210892,
-0.026294277980923653,
0.07614080607891083,
-0.06427199393510818,
-0.06526229530572891,
-0.05269598588347435,
-0.05471424013376236,
0.07780815660953522,
0.061437591910362244,
-0.04559890553355217,
-0.03741205111145973,
0.05294540524482727,
-0.0871860608458519,
-0.021104825660586357,
-0.001422088360413909,
-0.049445074051618576,
0.03201591223478317,
0.035762012004852295,
0.053721170872449875,
-0.01882285438477993,
0.012519368901848793,
0.025585122406482697,
0.029601413756608963,
0.004902367480099201,
0.00578132551163435,
0.04191882908344269,
0.03611774742603302,
0.01767638698220253,
-0.0636296197772026,
-0.0029644970782101154,
0.005932857748121023,
0.03695571422576904,
0.01811445876955986,
0.006705607753247023,
0.0279998742043972,
-0.0079192528501153,
0.10175822675228119,
0.002559661166742444,
-0.06584825366735458,
-0.07681232690811157,
0.09829816967248917,
0.0015615677693858743,
-0.022751443088054657,
-0.06571642309427261,
-0.0009078317089006305,
-0.05046442523598671,
0.0738837793469429,
-0.024171622470021248,
-0.056156761944293976,
-0.012400469742715359,
-0.022130945697426796,
0.037613894790410995,
0.08812976628541946,
-0.06557874381542206,
0.00024204517831094563,
0.029083499684929848,
-0.0026580668054521084,
-0.07089133560657501,
-0.008709408342838287,
-0.03938012570142746,
0.08200444281101227,
0.019453298300504684,
0.0235331691801548,
0.0464913547039032,
0.03432989493012428,
0.014867001213133335,
0.00629441998898983,
0.04514375329017639,
0.08163534104824066,
-0.06909424066543579,
-0.0362914614379406,
-0.0007621042896062136,
-0.015190914273262024,
-0.07734060287475586,
-0.12005582451820374,
-0.03430096060037613,
-0.02046014741063118,
-0.027027640491724014,
-0.007908351719379425,
0.00008196581620723009,
0.010089359246194363,
0.06547563523054123,
0.014494407922029495,
0.05546293407678604,
-0.027065636590123177,
0.032740138471126556,
0.051174286752939224,
0.05963262543082237,
0.042056161910295486,
0.05326734110713005,
0.015170294791460037,
0.059355251491069794,
-0.05110767483711243,
0.018424874171614647,
2.250739972012558e-33,
-0.010098431259393692,
-0.014510490000247955,
-0.05691857635974884,
0.03917550668120384,
0.05571718513965607,
0.10101666301488876,
-0.0006225997349247336,
-0.019218798726797104,
-0.04513471946120262,
-0.026265162974596024,
-0.009868856519460678,
-0.08339434862136841,
0.036866482347249985,
-0.14650960266590118,
0.07333775609731674,
0.008001720532774925,
0.041105348616838455,
-0.05482495576143265,
0.06298238784074783,
0.07964794337749481,
-0.005603157915174961,
-0.09079558402299881,
0.0061322785913944244,
0.04293851554393768,
0.026117464527487755,
0.002297998173162341,
-0.022004837170243263,
0.07953324913978577,
0.02864770032465458,
-0.015506359748542309,
-0.010942335240542889,
0.034212008118629456,
-0.0022181347012519836,
-0.0065629929304122925,
-0.01284521073102951,
-0.07372558116912842,
-0.030507395043969154,
0.02524031698703766,
-0.09593933075666428,
-0.06114053353667259,
-0.1162799596786499,
0.03931661322712898,
-0.12247051298618317,
-0.011917762458324432,
0.008900662884116173,
-0.0797119215130806,
0.010593081824481487,
-0.03863217681646347,
0.1160883754491806,
-0.05358049273490906,
-0.0027232831344008446,
-0.016489053145051003,
0.1114935427904129,
0.008452964946627617,
0.08409040421247482,
0.1136348694562912,
0.04953034222126007,
-0.024453720077872276,
0.003075193613767624,
-0.005827225279062986,
0.05939376354217529,
-0.04254736378788948,
-0.03171440586447716,
-0.03571290150284767,
0.04661385715007782,
0.013312299735844135,
-0.03172598406672478,
0.010837187059223652,
-0.061920277774333954,
-0.07066621631383896,
0.01686057448387146,
-0.0668901801109314,
-0.00649295886978507,
0.008629530668258667,
0.042042091488838196,
0.03857819736003876,
-0.06861115992069244,
0.03492766246199608,
-0.06098446249961853,
-0.046845242381095886,
0.02822474204003811,
-0.10473806411027908,
-0.03151649609208107,
0.08100973814725876,
0.03355417400598526,
0.049250368028879166,
-0.047484517097473145,
0.03626950830221176,
0.016035698354244232,
0.07949020713567734,
0.00037330371560528874,
-0.02036336623132229,
-0.009162911213934422,
-0.03478382155299187,
-0.07691986858844757,
-4.971574828598334e-33,
-0.03905893489718437,
0.06857994198799133,
-0.07804048806428909,
0.0753399059176445,
0.037822406738996506,
-0.02057228609919548,
-0.002948336536064744,
-0.05791937932372093,
-0.03833718225359917,
-0.023898782208561897,
-0.03879188373684883,
-0.018519099801778793,
0.011516283266246319,
0.08794652670621872,
-0.027670888230204582,
-0.01884310133755207,
-0.04905794560909271,
0.00906489510089159,
0.007498780265450478,
0.003662937320768833,
0.045264918357133865,
-0.00604909285902977,
0.03503694385290146,
-0.010833879001438618,
-0.08345726132392883,
0.03571692109107971,
0.01144328061491251,
-0.023744869977235794,
-0.02435484528541565,
-0.08351278305053711,
-0.030830899253487587,
0.019116660580039024,
-0.0298262108117342,
0.07572024315595627,
0.1339510977268219,
-0.10551201552152634,
0.014510517939925194,
0.059532925486564636,
-0.03482537344098091,
-0.10358154773712158,
0.08475977182388306,
0.040548041462898254,
-0.03998522087931633,
-0.017744600772857666,
0.03916703909635544,
-0.041750237345695496,
-0.05851761996746063,
0.024296429008245468,
0.0486212782561779,
0.030611366033554077,
-0.09991714358329773,
-0.057235367596149445,
-0.026188291609287262,
0.09471345692873001,
-0.022853925824165344,
0.0038778982125222683,
0.10920078307390213,
-0.022208476439118385,
0.059975091367959976,
0.04386697709560394,
-0.12752698361873627,
-0.07811401784420013,
0.0507596880197525,
0.03849375247955322,
0.024041015654802322,
0.012310597114264965,
-0.03457866981625557,
0.05403345450758934,
0.09340619295835495,
0.08120211958885193,
-0.013354027643799782,
0.06781034171581268,
-0.06248456984758377,
-0.015574600547552109,
-0.046915002167224884,
0.020128972828388214,
-0.038684483617544174,
-0.11713426560163498,
0.10421548783779144,
0.032595325261354446,
-0.03561808168888092,
0.02827570028603077,
0.03332456201314926,
0.02765987068414688,
0.02212340384721756,
0.021268323063850403,
-0.005466130096465349,
0.020783400163054466,
0.02049058862030506,
-0.015588595531880856,
-0.018077149987220764,
-0.0077309743501245975,
-0.023701557889580727,
-0.00821748562157154,
-0.027753908187150955,
-5.113812306944965e-8,
-0.06999805569648743,
0.033530496060848236,
-0.014729597605764866,
-0.0215995442122221,
0.05172702670097351,
-0.04889032989740372,
-0.05273669213056564,
-0.06936740130186081,
-0.01685459539294243,
-0.007095676381140947,
-0.06245436891913414,
-0.04663865268230438,
0.05395454913377762,
0.01830621249973774,
0.03503161668777466,
-0.06737678498029709,
0.05885768309235573,
0.023315289989113808,
0.0014151253271847963,
-0.006247837562114,
0.01801321841776371,
0.009100819937884808,
0.02872578799724579,
0.027286620810627937,
0.02326822094619274,
-0.06816328316926956,
0.06402353197336197,
0.097803495824337,
-0.029011176899075508,
-0.0685778334736824,
-0.09354815632104874,
0.00734786968678236,
0.09735573828220367,
0.027252160012722015,
-0.05295289680361748,
0.021878227591514587,
0.008098174817860126,
-0.0483311228454113,
0.07924813032150269,
-0.04794857278466225,
0.04884454235434532,
0.00030827606678940356,
0.020099762827157974,
0.01988925412297249,
-0.02592487819492817,
0.031158600002527237,
0.024445364251732826,
-0.03143252432346344,
0.08035991340875626,
0.06235070899128914,
-0.04526625946164131,
-0.04699030891060829,
-0.03356469050049782,
0.02664637751877308,
0.008632850833237171,
-0.043820396065711975,
-0.0171330738812685,
-0.09271252900362015,
0.0290059857070446,
-0.012668955139815807,
0.05504802241921425,
0.005487834103405476,
-0.01319315005093813,
-0.03757506608963013
] | 0.08043 |
myEmitter.emit('event'); // Prints: // B // A ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); // Only do this once so we don't loop forever myEmitter.once('newListener', (event, listener) => { if (event === 'event') { // Insert a new listener in front myEmitter.on('event', () => { console.log('B'); }); } }); myEmitter.on('event', () => { console.log('A'); }); myEmitter.emit('event'); // Prints: // B // A ``` ### Event: `'removeListener'` \* `eventName` {string|symbol} The event name \* `listener` {Function} The event handler function The `'removeListener'` event is emitted \_after\_ the `listener` is removed. ### `emitter.addListener(eventName, listener)` \* `eventName` {string|symbol} \* `listener` {Function} Alias for `emitter.on(eventName, listener)`. ### `emitter.emit(eventName[, ...args])` \* `eventName` {string|symbol} \* `...args` {any} \* Returns: {boolean} Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments to each. Returns `true` if the event had listeners, `false` otherwise. ```mjs import { EventEmitter } from 'node:events'; const myEmitter = new EventEmitter(); // First listener myEmitter.on('event', function firstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', function secondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', function thirdListener(...args) { const parameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); }); console.log(myEmitter.listeners('event')); myEmitter.emit('event', 1, 2, 3, 4, 5); // Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener ``` ```cjs const EventEmitter = require('node:events'); const myEmitter = new EventEmitter(); // First listener myEmitter.on('event', function firstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', function secondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', function thirdListener(...args) { const parameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); }); console.log(myEmitter.listeners('event')); myEmitter.emit('event', 1, 2, 3, 4, 5); // Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener ``` ### `emitter.eventNames()` \* Returns: {string\[]|symbol\[]} Returns an array listing the events for which the emitter has registered listeners. ```mjs import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] ``` ```cjs const EventEmitter = require('node:events'); const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] ``` ### `emitter.getMaxListeners()` \* Returns: {integer} Returns the current max listener value for the `EventEmitter` which is either set by [`emitter.setMaxListeners(n)`][] or defaults to [`events.defaultMaxListeners`][]. ### `emitter.listenerCount(eventName[, listener])` \* `eventName` {string|symbol} The name of the event being listened for \* `listener` {Function} The event handler function \* Returns: {integer} Returns the number of listeners listening for the event named `eventName`. If `listener` is provided, it will return how many times the listener is found in the list of the listeners of the event. ### `emitter.listeners(eventName)` \* `eventName` {string|symbol} \* Returns: {Function\[]} Returns a copy of the array of listeners for the event named `eventName`. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ``` ### `emitter.off(eventName, listener)` \* `eventName` {string|symbol} \* `listener` {Function} \* Returns: {EventEmitter} Alias for [`emitter.removeListener()`][]. ### `emitter.on(eventName, listener)` \* `eventName` {string|symbol} The | https://github.com/nodejs/node/blob/main//doc/api/events.md | main | nodejs | [
0.02144663967192173,
0.0241862665861845,
0.027686061337590218,
0.02330228127539158,
-0.0024292697198688984,
-0.0072415792383253574,
0.10355745255947113,
0.03307958319783211,
0.1049746423959732,
-0.056196536868810654,
-0.01920522004365921,
0.011008662171661854,
-0.07196502387523651,
-0.023890241980552673,
0.07726415991783142,
0.045456815510988235,
-0.05331036448478699,
0.022494427859783173,
-0.07577026635408401,
-0.09502362459897995,
-0.03292904794216156,
-0.031079355627298355,
-0.07247516512870789,
-0.027385249733924866,
0.0002262256748508662,
-0.08426570892333984,
0.052506063133478165,
-0.01867518573999405,
0.0898723304271698,
0.0018835990922525525,
0.08734610676765442,
-0.1125054806470871,
-0.0468120202422142,
0.029754407703876495,
-0.016128892078995705,
0.04389338195323944,
-0.0772659033536911,
-0.09594157338142395,
-0.01881333254277706,
-0.0013353853719308972,
0.08430419117212296,
0.040527381002902985,
-0.08977816253900528,
-0.060816530138254166,
0.01382291316986084,
-0.00186952855437994,
-0.12432486563920975,
0.02016177959740162,
-0.08026313781738281,
0.060735177248716354,
0.06272825598716736,
0.008602233603596687,
-0.015036690048873425,
-0.013587502762675285,
0.03365502506494522,
-0.02476203255355358,
0.026188978925347328,
0.006058237515389919,
0.035810746252536774,
-0.03178085759282112,
0.010300038382411003,
-0.022691426798701286,
0.006298662628978491,
0.03864607587456703,
0.014432483352720737,
-0.041742198169231415,
0.01516764983534813,
0.05506192520260811,
0.05755036696791649,
0.09071864187717438,
-0.04612187296152115,
-0.005133520811796188,
0.024041224271059036,
-0.015724385157227516,
0.0069203306920826435,
-0.07386992871761322,
-0.020633414387702942,
0.03681929409503937,
-0.06262008845806122,
0.04952230677008629,
-0.02245084010064602,
-0.06704645603895187,
-0.01168967504054308,
-0.005488447844982147,
0.030024008825421333,
0.07054184377193451,
-0.03887336328625679,
-0.024711942300200462,
-0.05502120032906532,
0.02216714806854725,
-0.10113482922315598,
0.009541052393615246,
0.014138693921267986,
0.05422058328986168,
0.010831818915903568,
0.04651130735874176,
0.04216224327683449,
-0.0042965104803442955,
-0.05131636932492256,
0.08366044610738754,
-0.016496974974870682,
0.03818729892373085,
-0.08923905342817307,
0.052138444036245346,
-0.0449494794011116,
-0.0405610129237175,
-0.1733035296201706,
-0.04810372367501259,
-0.024911360815167427,
-0.014520359225571156,
0.03959871828556061,
0.012320440262556076,
0.016147973015904427,
0.008971033617854118,
-0.0681995153427124,
0.06765072047710419,
0.08798379451036453,
0.055894635617733,
0.04164821282029152,
0.062106747180223465,
0.06786415725946426,
-0.020280908793210983,
0.005805672146379948,
-0.008665465749800205,
-0.014350786805152893,
-0.06696327030658722,
0.019811702892184258,
2.4154466588654267e-34,
-0.033524803817272186,
-0.040673814713954926,
-0.12569180130958557,
-0.005076577886939049,
0.02885150909423828,
0.08476153761148453,
-0.025231339037418365,
0.006739799398928881,
-0.04395541176199913,
0.015358763746917248,
0.028300901874899864,
-0.0004834759165532887,
0.048685502260923386,
-0.08846422284841537,
0.06671524792909622,
-0.007033214438706636,
0.06100183725357056,
-0.018267899751663208,
0.035550229251384735,
-0.008224761113524437,
0.00225670519284904,
-0.026387544348835945,
-0.057923927903175354,
0.10633856058120728,
-0.00028815798577852547,
0.024258017539978027,
0.009266335517168045,
0.06479864567518234,
-0.0719296932220459,
-0.009433728642761707,
0.07272414118051529,
0.07461164891719818,
-0.043172307312488556,
0.01355742011219263,
0.010677450336515903,
-0.07669749110937119,
0.013372275047004223,
-0.0020493001211434603,
-0.09285881370306015,
-0.07145003229379654,
0.019219573587179184,
-0.021721044555306435,
-0.08105591684579849,
-0.04285389184951782,
0.00665000407025218,
-0.06225450336933136,
-0.02762383408844471,
-0.030428782105445862,
0.07517065107822418,
-0.10038401186466217,
-0.029788993299007416,
0.018653633072972298,
0.1227455884218216,
-0.03450481593608856,
0.0671391561627388,
0.048650506883859634,
0.006590922363102436,
-0.04507054388523102,
-0.027765225619077682,
0.06741458177566528,
0.031693484634160995,
0.025827772915363312,
0.00541384844109416,
0.06295391917228699,
-0.0905427411198616,
0.02006891928613186,
-0.03959175571799278,
-0.03909105062484741,
0.03620737046003342,
-0.06905747205018997,
0.013974579982459545,
0.058712661266326904,
0.021373936906456947,
-0.034753717482089996,
-0.02235756814479828,
0.06287471950054169,
-0.07473727315664291,
0.015708541497588158,
-0.06540738046169281,
-0.033193256705999374,
0.022375306114554405,
-0.058583613485097885,
0.02675614319741726,
0.06118987128138542,
0.08965490758419037,
-0.020685620605945587,
-0.06896711885929108,
-0.04085294529795647,
0.00903453677892685,
0.05844612419605255,
-0.01638995110988617,
0.014524114318192005,
0.029017912223935127,
-0.09042400866746902,
-0.05560735985636711,
-4.144791611631447e-33,
0.0003020060539711267,
0.11873912066221237,
-0.04343950003385544,
0.0245932899415493,
0.02853330969810486,
0.010971242561936378,
-0.04944305121898651,
-0.011857118457555771,
-0.09131118655204773,
0.0170159749686718,
-0.04478270933032036,
0.06058579683303833,
0.0083546107634902,
0.042867325246334076,
-0.012504829093813896,
0.07098162174224854,
-0.08681020885705948,
-0.0306891817599535,
-0.025974754244089127,
0.02365349419414997,
-0.007052082102745771,
0.02517860010266304,
0.11078397929668427,
-0.03560377284884453,
-0.06240495666861534,
0.005791162606328726,
0.05276160314679146,
0.012144068256020546,
-0.02427150495350361,
-0.0339386984705925,
-0.08477763086557388,
0.047453004866838455,
0.005417590029537678,
0.0503043532371521,
0.03264716640114784,
-0.07015714049339294,
0.06498536467552185,
0.048423077911138535,
0.043754879385232925,
-0.06987959891557693,
0.049977369606494904,
0.011668972671031952,
-0.04035566374659538,
0.003015506314113736,
-0.060752835124731064,
0.008272777311503887,
-0.060534171760082245,
0.06601376831531525,
0.036581553518772125,
0.004894930869340897,
-0.05223952978849411,
-0.06311176717281342,
-0.008661671541631222,
0.0358593575656414,
-0.04201977327466011,
0.022100545465946198,
0.012749132700264454,
-0.03603664040565491,
0.01366409007459879,
0.06494352966547012,
0.0023118779063224792,
-0.11119391024112701,
0.03664146736264229,
0.0872613936662674,
0.03898921608924866,
-0.0595330186188221,
-0.06509913504123688,
0.07247225940227509,
0.07913544028997421,
-0.01940719597041607,
-0.01990031823515892,
0.10772156715393066,
-0.05774221941828728,
-0.016014503315091133,
-0.01581878960132599,
0.06576690077781677,
-0.00031750189373269677,
-0.14769473671913147,
0.0827360525727272,
-0.020219143480062485,
-0.0773850530385971,
0.06192013993859291,
-0.03045101836323738,
-0.05106819421052933,
0.013001712039113045,
0.026942800730466843,
-0.027306562289595604,
0.05168059468269348,
0.012025457806885242,
-0.024897301569581032,
-0.001178092323243618,
0.07033346593379974,
-0.0005482367123477161,
-0.013828455470502377,
-0.03503383696079254,
-4.9889038677974895e-8,
0.0004431612615007907,
-0.027597839012742043,
-0.03925395384430885,
-0.024102889001369476,
0.011981219984591007,
-0.06919172406196594,
-0.009104250930249691,
-0.048113446682691574,
-0.02572673186659813,
-0.0029686479829251766,
-0.07483348250389099,
0.005320132244378328,
0.05375056713819504,
0.0011688327649608254,
0.02065756730735302,
-0.023286456242203712,
0.0072099086828529835,
-0.017521660774946213,
-0.04178258031606674,
0.0073280781507492065,
-0.012545584701001644,
0.0010925679234787822,
0.054832201451063156,
0.04585973918437958,
0.006874194834381342,
-0.08304351568222046,
0.027977745980024338,
0.05010116845369339,
0.0556032620370388,
-0.044214844703674316,
-0.08255352079868317,
0.0313604399561882,
0.058600686490535736,
0.02248312532901764,
-0.0726565569639206,
-0.018254293128848076,
-0.036609672009944916,
-0.040528759360313416,
0.052166298031806946,
0.07154052704572678,
0.0968763530254364,
-0.029522910714149475,
-0.03393012657761574,
0.07592602074146271,
-0.08965574949979782,
-0.03594820573925972,
-0.02155742608010769,
-0.025823164731264114,
0.06717502325773239,
0.118193119764328,
-0.03835146501660347,
-0.009272015653550625,
-0.0515785776078701,
-0.037850767374038696,
-0.0059256418608129025,
-0.014874977059662342,
-0.018857721239328384,
0.005003094207495451,
0.035056814551353455,
0.011840361170470715,
0.003830843372270465,
0.07383766770362854,
-0.051127839833498,
-0.07629626244306564
] | 0.101742 |
Returns a copy of the array of listeners for the event named `eventName`. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ``` ### `emitter.off(eventName, listener)` \* `eventName` {string|symbol} \* `listener` {Function} \* Returns: {EventEmitter} Alias for [`emitter.removeListener()`][]. ### `emitter.on(eventName, listener)` \* `eventName` {string|symbol} The name of the event. \* `listener` {Function} The callback function \* Returns: {EventEmitter} Adds the `listener` function to the end of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```mjs import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` ```cjs const EventEmitter = require('node:events'); const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` ### `emitter.once(eventName, listener)` \* `eventName` {string|symbol} The name of the event. \* `listener` {Function} The callback function \* Returns: {EventEmitter} Adds a \*\*one-time\*\* `listener` function for the event named `eventName`. The next time `eventName` is triggered, this listener is removed and then invoked. ```js server.once('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```mjs import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` ```cjs const EventEmitter = require('node:events'); const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` ### `emitter.prependListener(eventName, listener)` \* `eventName` {string|symbol} The name of the event. \* `listener` {Function} The callback function \* Returns: {EventEmitter} Adds the `listener` function to the \_beginning\_ of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.prependListener('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. ### `emitter.prependOnceListener(eventName, listener)` \* `eventName` {string|symbol} The name of the event. \* `listener` {Function} The callback function \* Returns: {EventEmitter} Adds a \*\*one-time\*\* `listener` function for the event named `eventName` to the \_beginning\_ of the listeners array. The next time `eventName` is triggered, this listener is removed, and then invoked. ```js server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. ### `emitter.removeAllListeners([eventName])` \* `eventName` {string|symbol} \* Returns: {EventEmitter} Removes all listeners, or those of the specified `eventName`. It is bad practice to remove listeners added elsewhere in the code, particularly when the `EventEmitter` instance was created by some other component or module (e.g. sockets or file streams). Returns a reference to the `EventEmitter`, so that calls can be | https://github.com/nodejs/node/blob/main//doc/api/events.md | main | nodejs | [
-0.030462030321359634,
-0.011758982203900814,
0.030222419649362564,
0.050586309283971786,
0.02146398462355137,
-0.0495150089263916,
0.141843780875206,
-0.008910664357244968,
0.15343447029590607,
-0.05842336639761925,
-0.031843822449445724,
0.06074104458093643,
-0.10204237699508667,
0.008890394121408463,
0.010345938615500927,
0.0005825089756399393,
-0.025358835235238075,
0.00716474000364542,
-0.04843220114707947,
-0.08256864547729492,
-0.030219921842217445,
-0.03137217089533806,
-0.09326067566871643,
-0.014447589404881,
0.02783559262752533,
-0.0483858548104763,
0.045202869921922684,
-0.04477466642856598,
0.042515866458415985,
0.005405733827501535,
0.07995223253965378,
-0.08131802827119827,
-0.09507743269205093,
-0.027462095022201538,
-0.08882959932088852,
0.030455391854047775,
-0.032556965947151184,
-0.05993686243891716,
-0.009441554546356201,
-0.006683429703116417,
0.10594147443771362,
-0.0085185207426548,
-0.06667222827672958,
-0.08196117728948593,
-0.0426773838698864,
0.0019130716100335121,
-0.10226662456989288,
-0.04411410912871361,
-0.06484141200780869,
0.034576620906591415,
0.04047621041536331,
0.01838810183107853,
-0.05213887616991997,
0.06147787719964981,
0.0880737379193306,
-0.044573549181222916,
-0.028298282995820045,
0.0021997387520968914,
0.0038785673677921295,
-0.0007237624959088862,
-0.04795222729444504,
-0.0495285838842392,
-0.03727881982922554,
0.06635569036006927,
0.020241526886820793,
-0.047786109149456024,
-0.00872795283794403,
0.05242002755403519,
0.053109679371118546,
0.06351371109485626,
-0.03797255456447601,
0.03942076861858368,
0.012430742383003235,
-0.048350926488637924,
0.034266822040081024,
-0.0785263180732727,
0.008447189815342426,
0.041843485087156296,
-0.03788286820054054,
0.02716837078332901,
0.016701173037290573,
-0.09021375328302383,
-0.05190553143620491,
0.0008288589888252318,
0.0018764191772788763,
0.07205268740653992,
-0.066290482878685,
-0.03849487751722336,
-0.0016920045018196106,
0.022647803649306297,
-0.1566419005393982,
0.0013466826640069485,
0.009840346872806549,
0.06526002287864685,
-0.028764881193637848,
0.06448562443256378,
0.0157718975096941,
0.0057373326271772385,
-0.006680212449282408,
0.058579251170158386,
-0.01615661196410656,
0.0929044708609581,
-0.026918167248368263,
0.022654887288808823,
0.005747442599385977,
-0.025988955050706863,
-0.12389487773180008,
-0.022175822407007217,
0.011238603852689266,
0.010796520859003067,
-0.005473746452480555,
0.01775343157351017,
0.010656341910362244,
0.06307357549667358,
-0.06611686199903488,
0.1076345443725586,
0.05132683739066124,
0.04534962400794029,
0.035994336009025574,
0.06489350646734238,
0.10894742608070374,
-0.003041239222511649,
0.05485362932085991,
0.01964205875992775,
0.024107474833726883,
0.0026721274480223656,
0.010740621946752071,
3.907889184157943e-34,
-0.012251725420355797,
-0.04670408368110657,
-0.09216094017028809,
0.002903619548305869,
0.07412505149841309,
0.058492183685302734,
-0.017397141084074974,
-0.018064942210912704,
-0.03511865437030792,
0.04977424442768097,
0.01402380783110857,
0.05965898931026459,
0.05265340954065323,
-0.06773001700639725,
0.039046578109264374,
0.022557111456990242,
0.051971327513456345,
0.044385574758052826,
0.01660848781466484,
0.03017875738441944,
0.009359881281852722,
-0.024968886747956276,
-0.034127186983823776,
0.10609680414199829,
0.011492108926177025,
0.012296982109546661,
-0.020023290067911148,
0.0618172362446785,
-0.03117964044213295,
0.003109342185780406,
0.05481259524822235,
0.04497597739100456,
-0.0394364669919014,
0.015511508099734783,
0.07032564282417297,
-0.04296122118830681,
-0.003544202074408531,
-0.04961961880326271,
-0.09781160950660706,
-0.025460947304964066,
0.057738155126571655,
-0.041124504059553146,
-0.17848794162273407,
-0.02355916239321232,
-0.03871122747659683,
-0.08407589793205261,
-0.07777577638626099,
-0.0326443612575531,
0.139043927192688,
-0.07041055709123611,
-0.05315260961651802,
0.015245824120938778,
0.1423647403717041,
0.0012909381184726954,
0.0039528305642306805,
0.04637722671031952,
-0.01602526754140854,
0.025211915373802185,
-0.022929374128580093,
0.0323355607688427,
0.005165750626474619,
0.0034553389996290207,
0.021625306457281113,
-0.015011440962553024,
0.018150020390748978,
-0.013916624709963799,
-0.02945508435368538,
-0.00948493555188179,
0.02099015936255455,
-0.03445776179432869,
0.009197542443871498,
0.07702568173408508,
-0.016674527898430824,
-0.00479289423674345,
-0.00034720858093351126,
0.03522033616900444,
-0.07056626677513123,
0.026924923062324524,
-0.011026482097804546,
0.02614687755703926,
0.020312510430812836,
-0.03091840259730816,
-0.020062528550624847,
0.09846732020378113,
0.05324035510420799,
-0.00701417401432991,
-0.08348000049591064,
-0.06810120493173599,
-0.015120266005396843,
0.01804516091942787,
-0.010116226971149445,
0.01950201392173767,
0.03325125202536583,
-0.07030349969863892,
-0.08937012404203415,
-3.985608370695001e-33,
-0.013858238235116005,
0.06034746393561363,
-0.03083520010113716,
-0.0023413056042045355,
-0.03178128972649574,
-0.023855825886130333,
-0.0021058323327451944,
0.05434833839535713,
-0.06059623509645462,
-0.01569429412484169,
0.018524378538131714,
0.04293418303132057,
-0.02358204498887062,
-0.002118953038007021,
-0.010132129304111004,
0.0867539569735527,
-0.0615093894302845,
-0.0819515585899353,
0.01132538728415966,
-0.028813114389777184,
0.011871428228914738,
0.006973301991820335,
0.10146808624267578,
-0.0048680915497243404,
-0.0950750932097435,
-0.010567368939518929,
0.07632681727409363,
-0.029474468901753426,
-0.06800549477338791,
-0.026715310290455818,
-0.03432294353842735,
0.05712365359067917,
-0.01153943408280611,
0.018149543553590775,
0.03854113817214966,
-0.015706082805991173,
0.10137291997671127,
0.08523807674646378,
0.0030334664043039083,
-0.08034936338663101,
0.07449252158403397,
0.04053131490945816,
-0.011067372746765614,
-0.042019784450531006,
-0.010837406851351261,
0.03455767408013344,
-0.06966403126716614,
0.08393783122301102,
0.018979571759700775,
-0.012294396758079529,
0.0023280188906937838,
-0.033814992755651474,
-0.01159452460706234,
0.05828871577978134,
-0.04940994828939438,
0.004930289462208748,
0.04274839535355568,
-0.029748007655143738,
0.05199561268091202,
0.03949294984340668,
0.036278996616601944,
-0.10468406975269318,
-0.017124474048614502,
0.0753987655043602,
-0.014885812066495419,
-0.033982254564762115,
-0.05851440876722336,
0.04822010546922684,
0.09058234840631485,
-0.01161246933043003,
0.008617514744400978,
-0.008984499610960484,
-0.06345146894454956,
-0.01483683567494154,
-0.023333612829446793,
0.08944234251976013,
-0.041827380657196045,
-0.15379375219345093,
0.045505423098802567,
0.05081203579902649,
-0.023471243679523468,
0.07378679513931274,
-0.030483298003673553,
-0.04292745515704155,
0.049072399735450745,
0.013638465665280819,
0.004422451369464397,
0.07646699994802475,
-0.017732616513967514,
-0.032461635768413544,
0.011861707083880901,
0.03934812545776367,
-0.05822494626045227,
0.01254357025027275,
-0.05980551615357399,
-4.925999519400648e-8,
-0.009432625956833363,
-0.02701553702354431,
-0.03197777643799782,
-0.0448630154132843,
0.004737658891826868,
-0.03558879345655441,
-0.04828532040119171,
-0.026848625391721725,
-0.03737915679812431,
-0.011812077835202217,
-0.09263072907924652,
-0.03635672852396965,
0.07108619809150696,
0.026005543768405914,
0.08477859199047089,
-0.003257202683016658,
0.024109454825520515,
0.04217671602964401,
-0.06038018688559532,
0.002100399462506175,
0.034384384751319885,
-0.016187330707907677,
0.02203291282057762,
0.042779114097356796,
0.01466476358473301,
-0.0571172870695591,
0.05757861211895943,
0.04729405418038368,
0.003157882485538721,
-0.09467291086912155,
-0.07118261605501175,
0.05444885790348053,
0.04528025910258293,
0.04457039758563042,
-0.04345950111746788,
0.025539090856909752,
-0.06083652749657631,
-0.08790238946676254,
0.026925500482320786,
0.09065968543291092,
0.03279168903827667,
-0.04501038417220116,
-0.010287845507264137,
0.0746985375881195,
-0.029547978192567825,
0.024553965777158737,
0.013352173380553722,
0.01841273158788681,
0.04600166901946068,
0.024401888251304626,
-0.03683604672551155,
0.0014641712186858058,
-0.03192531690001488,
-0.07516179233789444,
-0.0327736921608448,
-0.029992427676916122,
-0.027048351243138313,
-0.025707364082336426,
0.028903864324092865,
-0.034110285341739655,
0.017545415088534355,
0.09500554949045181,
-0.04164452105760574,
-0.07255592942237854
] | 0.119209 |
Removes all listeners, or those of the specified `eventName`. It is bad practice to remove listeners added elsewhere in the code, particularly when the `EventEmitter` instance was created by some other component or module (e.g. sockets or file streams). Returns a reference to the `EventEmitter`, so that calls can be chained. ### `emitter.removeListener(eventName, listener)` \* `eventName` {string|symbol} \* `listener` {Function} \* Returns: {EventEmitter} Removes the specified `listener` from the listener array for the event named `eventName`. ```js const callback = (stream) => { console.log('someone connected!'); }; server.on('connection', callback); // ... server.removeListener('connection', callback); ``` `removeListener()` will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified `eventName`, then `removeListener()` must be called multiple times to remove each instance. Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls \_after\_ emitting and \_before\_ the last listener finishes execution will not remove them from `emit()` in progress. Subsequent events behave as expected. ```mjs import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); }; const callbackB = () => { console.log('B'); }; myEmitter.on('event', callbackA); myEmitter.on('event', callbackB); // callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B // callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A ``` ```cjs const EventEmitter = require('node:events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); }; const callbackB = () => { console.log('B'); }; myEmitter.on('event', callbackA); myEmitter.on('event', callbackB); // callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B // callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A ``` Because listeners are managed using an internal array, calling this will change the position indexes of any listener registered \_after\_ the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the `emitter.listeners()` method will need to be recreated. When a single function has been added as a handler multiple times for a single event (as in the example below), `removeListener()` will remove the most recently added instance. In the example the `once('ping')` listener is removed: ```mjs import { EventEmitter } from 'node:events'; const ee = new EventEmitter(); function pong() { console.log('pong'); } ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong); ee.emit('ping'); ee.emit('ping'); ``` ```cjs const EventEmitter = require('node:events'); const ee = new EventEmitter(); function pong() { console.log('pong'); } ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong); ee.emit('ping'); ee.emit('ping'); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. ### `emitter.setMaxListeners(n)` \* `n` {integer} \* Returns: {EventEmitter} By default `EventEmitter`s will print a warning if more than `10` listeners are added for a particular event. This is a useful default that helps finding memory leaks. The `emitter.setMaxListeners()` method allows the limit to be modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners. Returns a reference to the `EventEmitter`, so that calls can be chained. ### `emitter.rawListeners(eventName)` \* `eventName` {string|symbol} \* Returns: {Function\[]} Returns a copy of the array of listeners for the event | https://github.com/nodejs/node/blob/main//doc/api/events.md | main | nodejs | [
-0.0195869579911232,
0.023008588701486588,
0.05859212577342987,
0.04962584376335144,
0.0017940723337233067,
-0.01711519993841648,
0.11764606088399887,
-0.0446663461625576,
0.14666931331157684,
-0.03761832416057587,
-0.008292007260024548,
0.07659795880317688,
-0.07623326033353806,
-0.003205047221854329,
-0.00331102148629725,
-0.024685345590114594,
-0.018101299181580544,
-0.011519349180161953,
-0.05170251801609993,
-0.08189660310745239,
-0.023909853771328926,
-0.05970100685954094,
-0.08740092068910599,
-0.012367433868348598,
0.07639432698488235,
-0.05615444853901863,
0.0612497441470623,
-0.05900212377309799,
0.0461488775908947,
0.0035148330498486757,
0.07861370593309402,
-0.05594896525144577,
-0.04553273320198059,
-0.03045915998518467,
-0.07749253511428833,
-0.006956830155104399,
-0.07631319761276245,
-0.0529513880610466,
-0.03278588876128197,
0.00017430557636544108,
0.08337359130382538,
0.03508676216006279,
-0.08546865731477737,
-0.08481989055871964,
-0.02711375616490841,
0.02474796026945114,
-0.11452209949493408,
-0.07697804272174835,
-0.06123913452029228,
0.02119978703558445,
0.0572362020611763,
0.07767786830663681,
-0.050966668874025345,
0.09202395379543304,
0.08517439663410187,
-0.10635308921337128,
-0.002225275617092848,
0.013459276407957077,
0.011239985004067421,
-0.007804094348102808,
-0.00012413943477440625,
-0.03572433069348335,
-0.052418775856494904,
0.015003976412117481,
0.055326372385025024,
-0.004423154518008232,
0.019699551165103912,
0.049619272351264954,
0.09342952072620392,
0.07950727641582489,
-0.027829857543110847,
0.041039276868104935,
0.0596151240170002,
-0.054626427590847015,
0.022752486169338226,
-0.034357309341430664,
-0.02533586509525776,
0.013664203695952892,
-0.011890333145856857,
0.04958552494645119,
0.016144080087542534,
-0.09705954790115356,
-0.03351213037967682,
-0.04325035586953163,
-0.03420276939868927,
0.04487163573503494,
-0.07383289188146591,
-0.06585139036178589,
-0.034463707357645035,
0.005166045855730772,
-0.1078910157084465,
0.01800604537129402,
0.04263676702976227,
0.06945999711751938,
0.03384732827544212,
0.017877202481031418,
0.007379034534096718,
0.014623194001615047,
-0.03292470425367355,
0.03940208628773689,
-0.009967109188437462,
0.049590639770030975,
-0.030947981402277946,
0.05233694612979889,
-0.02519720420241356,
-0.02046455629169941,
-0.12764523923397064,
-0.007384352385997772,
-0.02833312563598156,
-0.0002272908022860065,
-0.03611691668629646,
0.006235779728740454,
-0.0028136204928159714,
0.03519987687468529,
-0.08094346523284912,
0.1086076870560646,
0.10209927707910538,
0.07414406538009644,
-0.006879535503685474,
0.08118364214897156,
0.0553261935710907,
-0.01570253074169159,
0.05919790267944336,
0.02070530876517296,
-0.006004326976835728,
-0.012502193450927734,
0.010417230427265167,
1.555894424652957e-33,
-0.06141163408756256,
-0.04762864112854004,
-0.112885981798172,
-0.03981854021549225,
0.09798341244459152,
0.052869025617837906,
-0.033906497061252594,
0.004463794641196728,
0.009138981811702251,
0.03621325641870499,
0.036587487906217575,
0.0067231017164886,
0.06402982771396637,
-0.0785684809088707,
0.08787789195775986,
0.016375796869397163,
0.04860148951411247,
0.018605591729283333,
0.0237283855676651,
-0.0033224564976990223,
0.01475977711379528,
-0.012973026372492313,
-0.03327125683426857,
0.10898282378911972,
-0.00043288798769935966,
-0.010348190553486347,
-0.0014524143189191818,
0.03869905695319176,
-0.048173341900110245,
-0.01729138009250164,
0.060067448765039444,
0.07269686460494995,
-0.059083133935928345,
0.02591320499777794,
0.06734446436166763,
-0.05076782777905464,
0.013183701783418655,
-0.0395369715988636,
-0.08675637096166611,
-0.047787562012672424,
0.025079166516661644,
-0.005367015954107046,
-0.16619110107421875,
-0.0054811653681099415,
0.019306525588035583,
-0.041066840291023254,
-0.03688275068998337,
-0.029146792367100716,
0.07200516760349274,
-0.07684403657913208,
-0.028687236830592155,
0.05840932950377464,
0.15827716886997223,
-0.01625700108706951,
0.008571402169764042,
0.04647600278258324,
0.047600094228982925,
0.0005067875608801842,
-0.0333833284676075,
0.03032762184739113,
-0.004624221008270979,
0.002949455287307501,
-0.0034988396801054478,
-0.002231248887255788,
0.020983707159757614,
-0.000290562747977674,
-0.04677031561732292,
-0.005803605075925589,
-0.022308887913823128,
-0.08338277041912079,
0.02217358537018299,
0.0812799409031868,
0.038264770060777664,
-0.019787199795246124,
-0.02059740573167801,
0.016943983733654022,
-0.011357266455888748,
0.02411208115518093,
-0.0327916145324707,
-0.0057259052991867065,
-0.013764489442110062,
-0.002060690661892295,
0.025767631828784943,
0.087831050157547,
0.07599696516990662,
-0.015229052864015102,
-0.05081737041473389,
-0.06796980649232864,
0.009624936617910862,
0.08751372992992401,
0.03887145221233368,
0.03063197433948517,
0.0001492976298322901,
-0.052110008895397186,
-0.06566794216632843,
-3.837038741720526e-33,
-0.03771820664405823,
0.09499582648277283,
-0.056352321058511734,
-0.010291341692209244,
-0.012043548747897148,
0.01431713905185461,
-0.043958015739917755,
0.0792117714881897,
-0.027909180149435997,
-0.0588635616004467,
0.030901094898581505,
0.025264548137784004,
0.01658051647245884,
-0.00890662893652916,
-0.021676428616046906,
0.09286122769117355,
-0.07954145222902298,
-0.07968701422214508,
-0.026888014748692513,
-0.02236815169453621,
0.02803025394678116,
0.03195205330848694,
0.10360288619995117,
-0.0034803664311766624,
-0.08412075787782669,
-0.02546127699315548,
0.045243456959724426,
0.0019388875225558877,
-0.017620958387851715,
-0.04205650836229324,
-0.05004507303237915,
0.05242370814085007,
0.0005744737572968006,
0.0035212456714361906,
0.030884921550750732,
-0.04122106358408928,
0.08049856126308441,
0.12228234857320786,
0.01576840505003929,
-0.06268547475337982,
0.03751498833298683,
0.022755345329642296,
-0.011529228650033474,
-0.04086902365088463,
-0.00801936537027359,
0.003319486975669861,
-0.0572272427380085,
0.07321588695049286,
0.015662211924791336,
-0.0029469463042914867,
-0.03973720967769623,
-0.03844514861702919,
-0.03245995193719864,
0.027953170239925385,
-0.02555863745510578,
0.006062394008040428,
0.05416892468929291,
-0.030930273234844208,
0.06865863502025604,
0.015247034840285778,
0.077828548848629,
-0.05206316336989403,
-0.02302030473947525,
0.07844335585832596,
0.045686669647693634,
-0.02566041424870491,
-0.05442366749048233,
0.06319963932037354,
0.09424515813589096,
-0.029623864218592644,
-0.00961308740079403,
0.035300686955451965,
-0.06809499114751816,
-0.009945027530193329,
-0.01801246590912342,
0.09002375602722168,
-0.0676461011171341,
-0.15091131627559662,
0.027949916198849678,
-0.005341900512576103,
-0.04213627427816391,
0.06570683419704437,
-0.03138891980051994,
-0.05867302417755127,
0.010627813637256622,
0.0017344871303066611,
-0.005319653078913689,
0.029357610270380974,
-0.005101122427731752,
0.03352944552898407,
0.00788913480937481,
0.0202482920140028,
-0.016073714941740036,
-0.0059865606017410755,
-0.07260042428970337,
-4.558663135867391e-8,
0.039814554154872894,
-0.03722438961267471,
-0.06495605409145355,
-0.035463280975818634,
0.008925347588956356,
-0.05988925322890282,
-0.020070137456059456,
0.06756696105003357,
-0.013714659959077835,
-0.02445482648909092,
-0.04203551262617111,
0.001931432168930769,
0.03449283167719841,
0.0205889530479908,
0.08932482451200485,
-0.040006089955568314,
0.010798213072121143,
0.011407343670725822,
-0.06677310913801193,
-0.013211014680564404,
0.01868387684226036,
-0.01828450709581375,
0.004840767476707697,
0.05019974708557129,
0.006926585920155048,
-0.05864682048559189,
0.11813411116600037,
0.05849155783653259,
0.014363033697009087,
-0.09348587691783905,
-0.09167440980672836,
0.03144684061408043,
0.03635066747665405,
0.038056306540966034,
-0.057042594999074936,
0.03245425969362259,
-0.019911078736186028,
-0.0483761765062809,
-0.007529490161687136,
0.10116332024335861,
0.017962487414479256,
-0.020078590139746666,
-0.03392196074128151,
0.08556360751390457,
-0.028273994103074074,
-0.0052563794888556,
0.02539227157831192,
0.002369416644796729,
0.04073658585548401,
0.05809222161769867,
-0.05029438063502312,
0.02906351163983345,
-0.06198646128177643,
-0.05795379728078842,
-0.02551453188061714,
-0.015450684353709221,
0.019988849759101868,
0.012781276367604733,
0.02713898941874504,
-0.019752103835344315,
0.005463212728500366,
0.07941538840532303,
-0.03877251222729683,
-0.08090640604496002
] | 0.111378 |
specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners. Returns a reference to the `EventEmitter`, so that calls can be chained. ### `emitter.rawListeners(eventName)` \* `eventName` {string|symbol} \* Returns: {Function\[]} Returns a copy of the array of listeners for the event named `eventName`, including any wrappers (such as those created by `.once()`). ```mjs import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.once('log', () => console.log('log once')); // Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0]; // Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener(); // Logs "log once" to the console and removes the listener logFnWrapper(); emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above const newListeners = emitter.rawListeners('log'); // Logs "log persistently" twice newListeners[0](); emitter.emit('log'); ``` ```cjs const EventEmitter = require('node:events'); const emitter = new EventEmitter(); emitter.once('log', () => console.log('log once')); // Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0]; // Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener(); // Logs "log once" to the console and removes the listener logFnWrapper(); emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above const newListeners = emitter.rawListeners('log'); // Logs "log persistently" twice newListeners[0](); emitter.emit('log'); ``` ### `emitter[Symbol.for('nodejs.rejection')](err, eventName[, ...args])` \* `err` {Error} \* `eventName` {string|symbol} \* `...args` {any} The `Symbol.for('nodejs.rejection')` method is called in case a promise rejection happens when emitting an event and [`captureRejections`][capturerejections] is enabled on the emitter. It is possible to use [`events.captureRejectionSymbol`][rejectionsymbol] in place of `Symbol.for('nodejs.rejection')`. ```mjs import { EventEmitter, captureRejectionSymbol } from 'node:events'; class MyClass extends EventEmitter { constructor() { super({ captureRejections: true }); } [captureRejectionSymbol](err, event, ...args) { console.log('rejection happened for', event, 'with', err, ...args); this.destroy(err); } destroy(err) { // Tear the resource down here. } } ``` ```cjs const { EventEmitter, captureRejectionSymbol } = require('node:events'); class MyClass extends EventEmitter { constructor() { super({ captureRejections: true }); } [captureRejectionSymbol](err, event, ...args) { console.log('rejection happened for', event, 'with', err, ...args); this.destroy(err); } destroy(err) { // Tear the resource down here. } } ``` ## `events.defaultMaxListeners` By default, a maximum of `10` listeners can be registered for any single event. This limit can be changed for individual `EventEmitter` instances using the [`emitter.setMaxListeners(n)`][] method. To change the default for \_all\_ `EventEmitter` instances, the `events.defaultMaxListeners` property can be used. If this value is not a positive number, a `RangeError` is thrown. Take caution when setting the `events.defaultMaxListeners` because the change affects \_all\_ `EventEmitter` instances, including those created before the change is made. However, calling [`emitter.setMaxListeners(n)`][] still has precedence over `events.defaultMaxListeners`. This is not a hard limit. The `EventEmitter` instance will allow more listeners to be added but will output a trace warning to stderr indicating that a "possible EventEmitter memory leak" has been detected. For any single `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to temporarily avoid this warning: `defaultMaxListeners` has no effect on `AbortSignal` instances. While it is still possible to use [`emitter.setMaxListeners(n)`][] to set a warning limit for individual `AbortSignal` instances, per default `AbortSignal` instances will not warn. ```mjs import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.setMaxListeners(emitter.getMaxListeners() + 1); emitter.once('event', () => { // do stuff emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); }); ``` ```cjs const EventEmitter = | https://github.com/nodejs/node/blob/main//doc/api/events.md | main | nodejs | [
0.00011107797035947442,
-0.03786313161253929,
0.08212202787399292,
0.09262946993112564,
-0.0036860082764178514,
-0.02743685245513916,
0.0724223181605339,
0.019927602261304855,
0.11231039464473724,
-0.020601969212293625,
-0.03925912082195282,
-0.02253558672964573,
-0.03497952222824097,
0.011890282854437828,
0.03837127238512039,
0.054764337837696075,
-0.013192444108426571,
0.07026425004005432,
-0.06268814951181412,
-0.059423621743917465,
0.0358579196035862,
-0.013095065020024776,
-0.019028401002287865,
0.030464019626379013,
-0.01183487568050623,
-0.0885625034570694,
0.004544010851532221,
-0.01040963176637888,
0.0986088216304779,
-0.03438398987054825,
0.07166242599487305,
-0.03479744866490364,
-0.1007956713438034,
0.08969748765230179,
-0.03537309914827347,
0.05136440321803093,
-0.06967609375715256,
-0.07983838766813278,
-0.04192803427577019,
0.009234674274921417,
0.08963729441165924,
0.054742105305194855,
-0.051135919988155365,
-0.09128118306398392,
0.03217838332056999,
-0.05250413343310356,
-0.08866727352142334,
-0.002442555967718363,
-0.0565289668738842,
0.05747728794813156,
0.09593195468187332,
0.026812251657247543,
-0.010457644239068031,
0.04368840530514717,
0.08740170300006866,
-0.022034453228116035,
0.012576820328831673,
-0.004448475316166878,
0.05358750373125076,
-0.002011561067774892,
-0.037812937051057816,
-0.03364197909832001,
0.004230247810482979,
-0.0050170570611953735,
0.04640871286392212,
0.0064473832026124,
-0.008728362619876862,
0.08729257434606552,
0.05140644684433937,
0.09965629130601883,
-0.045019883662462234,
-0.04423085227608681,
0.03721735626459122,
-0.01944929175078869,
0.0282388124614954,
-0.06254511326551437,
-0.02346489392220974,
0.0639146938920021,
-0.03970998525619507,
0.0679893046617508,
-0.05295716971158981,
-0.06360017508268356,
-0.011920920573174953,
-0.0226337518543005,
0.011916708201169968,
0.069029800593853,
-0.07570876181125641,
0.0490710623562336,
0.029615437611937523,
0.04489051178097725,
-0.16221274435520172,
-0.06533641368150711,
0.006827475503087044,
0.08411805331707001,
0.008460192009806633,
0.02937972918152809,
-0.0036084046587347984,
0.038367800414562225,
-0.005435631610453129,
0.015458788722753525,
-0.0046882894821465015,
0.0864463523030281,
-0.03881218656897545,
0.040526196360588074,
-0.021905211731791496,
-0.05850284546613693,
-0.09975380450487137,
-0.0628085806965828,
-0.06705234944820404,
0.0049278088845312595,
0.026783082634210587,
0.04375872015953064,
0.02129548415541649,
0.03304470703005791,
-0.023842113092541695,
0.07019838690757751,
0.04187851399183273,
0.0408853143453598,
0.039190154522657394,
0.1058589294552803,
0.06685061007738113,
0.001124738366343081,
0.037323739379644394,
-0.006027994677424431,
0.02244909293949604,
0.03118852712213993,
0.034225236624479294,
2.287248438826198e-33,
-0.038504574447870255,
-0.03723917156457901,
-0.08054005354642868,
0.00402206601575017,
0.05279816314578056,
0.10213154554367065,
-0.01824973337352276,
0.0040026274509727955,
-0.0643577054142952,
0.03814581409096718,
-0.01391593273729086,
0.08588588237762451,
0.05515061691403389,
-0.09775591641664505,
0.04787975177168846,
-0.04615680128335953,
0.04167935252189636,
-0.000995285459794104,
0.03991713747382164,
0.00966599676758051,
-0.039577629417181015,
0.0030373423360288143,
-0.041141360998153687,
0.02041657641530037,
-0.007599306758493185,
-0.010574311017990112,
0.015642398968338966,
0.06951433420181274,
-0.012960650026798248,
0.00655957218259573,
0.014106210321187973,
0.05345335230231285,
-0.024746086448431015,
-0.015592794865369797,
0.01936224102973938,
-0.07949148118495941,
-0.03351704776287079,
0.01084812730550766,
-0.10828749090433121,
-0.07025617361068726,
-0.02527766488492489,
-0.02494201250374317,
-0.12602494657039642,
-0.057071566581726074,
-0.03582832217216492,
-0.10024915635585785,
-0.06480234861373901,
-0.018961388617753983,
0.05345337465405464,
-0.12949691712856293,
0.009615045972168446,
0.06329924613237381,
0.07412265986204147,
-0.07257429510354996,
0.061203908175230026,
0.016890186816453934,
0.045438311994075775,
-0.016469230875372887,
-0.012633596546947956,
0.03998708352446556,
-0.033313825726509094,
0.01710371859371662,
0.017310844734311104,
0.017575595527887344,
0.011905870400369167,
0.08478730171918869,
-0.026194851845502853,
0.0037673546466976404,
0.007135668303817511,
-0.04071185365319252,
0.04477311298251152,
0.028154628351330757,
-0.014343288727104664,
-0.03278534486889839,
-0.022500883787870407,
0.037144146859645844,
-0.03465681150555611,
-0.007345268502831459,
-0.04379257187247276,
0.014432532712817192,
-0.007208319380879402,
-0.014426042325794697,
-0.01369967870414257,
0.10351405292749405,
0.0879882201552391,
-0.0408901609480381,
-0.0759233608841896,
-0.07015743106603622,
-0.034543611109256744,
0.034623220562934875,
0.0243344996124506,
-0.010519705712795258,
0.024006890133023262,
-0.07026101648807526,
-0.08374835550785065,
-4.703936438093192e-33,
-0.014898831956088543,
0.12677334249019623,
-0.044638969004154205,
0.04273767024278641,
-0.031861305236816406,
-0.03359575197100639,
-0.08629181236028671,
0.03149695694446564,
-0.07239078730344772,
-0.02652224898338318,
0.011596811935305595,
0.005717121064662933,
-0.024039143696427345,
0.005956438370049,
-0.0009471122757531703,
0.10572625696659088,
-0.074598029255867,
-0.0066761961206793785,
0.0488240122795105,
-0.0212336964905262,
0.047466397285461426,
0.00857391208410263,
0.004670983646064997,
0.007204809691756964,
-0.08930604159832001,
0.009101180359721184,
0.0507945790886879,
0.017958106473088264,
0.011840425431728363,
-0.08111396431922913,
-0.06438596546649933,
-0.006479378789663315,
-0.028946053236722946,
0.005397619679570198,
0.04810498654842377,
-0.043409254401922226,
0.09943640232086182,
0.10378838330507278,
0.06463971734046936,
-0.0466846339404583,
0.07803107053041458,
0.03231809288263321,
-0.039082132279872894,
-0.014535492286086082,
-0.03571706637740135,
0.001077624736353755,
-0.08621997386217117,
0.04888082668185234,
0.08966399729251862,
-0.022580446675419807,
-0.05667148157954216,
-0.09133124351501465,
0.014171627350151539,
0.035893384367227554,
-0.07027396559715271,
-0.009425939060747623,
0.00906673725694418,
-0.002727990970015526,
0.05446721613407135,
0.02825949341058731,
0.005592161323875189,
-0.10360343754291534,
0.02325308509171009,
0.06787042319774628,
0.024871336296200752,
-0.03339932858943939,
-0.06337900459766388,
-0.025140633806586266,
0.023987336084246635,
-0.006123008672147989,
0.03385158255696297,
0.016961881890892982,
-0.04849107190966606,
-0.015181171707808971,
-0.02055559866130352,
0.08483544737100601,
-0.04995710030198097,
-0.17054477334022522,
0.03659619763493538,
-0.04229668527841568,
-0.04505254328250885,
0.04573192819952965,
-0.04930152744054794,
-0.02031683176755905,
0.017511418089270592,
-0.0021854834631085396,
0.017283743247389793,
0.06638668477535248,
0.0653611570596695,
-0.012592583894729614,
0.011176039464771748,
0.05968807265162468,
-0.07523953914642334,
-0.009637498296797276,
-0.0950533002614975,
-5.391587620806604e-8,
-0.04921324923634529,
-0.07882460206747055,
-0.034683067351579666,
-0.02547343075275421,
0.06509559601545334,
-0.008173414506018162,
-0.030156219378113747,
-0.008682724088430405,
-0.028548354282975197,
0.013230398297309875,
-0.02539055235683918,
-0.0187398549169302,
0.031273841857910156,
0.011464531533420086,
0.033440303057432175,
-0.0014015502529218793,
0.018674926832318306,
-0.014564143493771553,
-0.04295237734913826,
0.01582072488963604,
0.020428132265806198,
-0.010906342417001724,
0.07110856473445892,
0.04325396567583084,
-0.018060320988297462,
-0.09192727506160736,
0.03980766236782074,
0.09129125624895096,
0.019666897132992744,
-0.050682492554187775,
-0.062418386340141296,
0.04763226956129074,
0.028401702642440796,
0.03392650932073593,
-0.1152673289179802,
-0.00649799732491374,
-0.02169724740087986,
-0.07383605092763901,
0.05190253257751465,
0.06759435683488846,
0.028611287474632263,
-0.06292525678873062,
-0.023328717797994614,
0.06975948065519333,
-0.07361804693937302,
-0.009809528477489948,
-0.011473985388875008,
-0.004866361618041992,
0.06065112724900246,
0.09637556970119476,
-0.024898044764995575,
0.016338203102350235,
-0.028240812942385674,
-0.032400935888290405,
-0.021325277164578438,
0.0008677335572429001,
0.025677889585494995,
-0.016009924933314323,
0.07123854756355286,
0.009469203650951385,
-0.007195676676928997,
0.022222425788640976,
-0.018299533054232597,
-0.06933551281690598
] | 0.115549 |
use [`emitter.setMaxListeners(n)`][] to set a warning limit for individual `AbortSignal` instances, per default `AbortSignal` instances will not warn. ```mjs import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.setMaxListeners(emitter.getMaxListeners() + 1); emitter.once('event', () => { // do stuff emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); }); ``` ```cjs const EventEmitter = require('node:events'); const emitter = new EventEmitter(); emitter.setMaxListeners(emitter.getMaxListeners() + 1); emitter.once('event', () => { // do stuff emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); }); ``` The [`--trace-warnings`][] command-line flag can be used to display the stack trace for such warnings. The emitted warning can be inspected with [`process.on('warning')`][] and will have the additional `emitter`, `type`, and `count` properties, referring to the event emitter instance, the event's name and the number of attached listeners, respectively. Its `name` property is set to `'MaxListenersExceededWarning'`. ## `events.errorMonitor` This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called. Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no regular `'error'` listener is installed. ## `events.getEventListeners(emitterOrTarget, eventName)` \* `emitterOrTarget` {EventEmitter|EventTarget} \* `eventName` {string|symbol} \* Returns: {Function\[]} Returns a copy of the array of listeners for the event named `eventName`. For `EventEmitter`s this behaves exactly the same as calling `.listeners` on the emitter. For `EventTarget`s this is the only way to get the event listeners for the event target. This is useful for debugging and diagnostic purposes. ```mjs import { getEventListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); const listener = () => console.log('Events are fun'); ee.on('foo', listener); console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ] } { const et = new EventTarget(); const listener = () => console.log('Events are fun'); et.addEventListener('foo', listener); console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ] } ``` ```cjs const { getEventListeners, EventEmitter } = require('node:events'); { const ee = new EventEmitter(); const listener = () => console.log('Events are fun'); ee.on('foo', listener); console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ] } { const et = new EventTarget(); const listener = () => console.log('Events are fun'); et.addEventListener('foo', listener); console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ] } ``` ## `events.getMaxListeners(emitterOrTarget)` \* `emitterOrTarget` {EventEmitter|EventTarget} \* Returns: {number} Returns the currently set max amount of listeners. For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on the emitter. For `EventTarget`s this is the only way to get the max event listeners for the event target. If the number of event handlers on a single EventTarget exceeds the max set, the EventTarget will print a warning. ```mjs import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); console.log(getMaxListeners(ee)); // 10 setMaxListeners(11, ee); console.log(getMaxListeners(ee)); // 11 } { const et = new EventTarget(); console.log(getMaxListeners(et)); // 10 setMaxListeners(11, et); console.log(getMaxListeners(et)); // 11 } ``` ```cjs const { getMaxListeners, setMaxListeners, EventEmitter } = require('node:events'); { const ee = new EventEmitter(); console.log(getMaxListeners(ee)); // 10 setMaxListeners(11, ee); console.log(getMaxListeners(ee)); // 11 } { const et = new EventTarget(); console.log(getMaxListeners(et)); // 10 setMaxListeners(11, et); console.log(getMaxListeners(et)); // 11 } ``` ## `events.once(emitter, name[, options])` \* `emitter` {EventEmitter} \* `name` {string|symbol} \* `options` {Object} \* `signal` {AbortSignal} Can be used to cancel waiting for the event. \* Returns: {Promise} Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget][WHATWG-EventTarget] interface, which has no special `'error'` event semantics and does | https://github.com/nodejs/node/blob/main//doc/api/events.md | main | nodejs | [
0.02623920701444149,
0.012972954660654068,
0.03893299400806427,
0.017583554610610008,
-0.03411334007978439,
0.00350751681253314,
0.06517086923122406,
0.06944523751735687,
0.06163899600505829,
-0.024495568126440048,
-0.041482891887426376,
-0.03639332577586174,
-0.006757280323654413,
-0.02579525299370289,
-0.029613208025693893,
0.005151944234967232,
-0.00457087904214859,
0.05715009942650795,
-0.04863730072975159,
-0.10076248645782471,
0.044356685131788254,
-0.025347871705889702,
0.020801395177841187,
0.05007154494524002,
-0.06271718442440033,
-0.07758871465921402,
0.0034836193080991507,
0.0048542688600718975,
0.09684236347675323,
-0.03802170976996422,
0.0813024640083313,
-0.07515787333250046,
-0.03820880874991417,
0.051923684775829315,
0.012147310189902782,
0.00047830576659180224,
-0.14864830672740936,
-0.11000841110944748,
-0.027979616075754166,
-0.012132763862609863,
0.054627008736133575,
0.05946280434727669,
-0.023959673941135406,
-0.0408966988325119,
0.0011861389502882957,
-0.040612224489450455,
-0.11198344081640244,
-0.044937409460544586,
-0.03458341583609581,
-0.010481521487236023,
0.046862319111824036,
0.016315538436174393,
0.006717965472489595,
0.01602676697075367,
0.059408895671367645,
-0.07525188475847244,
0.017119525000452995,
-0.010509454645216465,
0.028487157076597214,
0.02448846586048603,
-0.017455600202083588,
-0.05761101469397545,
0.017179781571030617,
-0.04878174886107445,
0.027699125930666924,
0.049143798649311066,
-0.017082663252949715,
0.07938229292631149,
0.012959983199834824,
0.18744106590747833,
-0.010580772534012794,
-0.038799066096544266,
0.009543166495859623,
0.03834760561585426,
0.018654074519872665,
-0.01952354796230793,
-0.049817007035017014,
0.01118368748575449,
-0.0440276563167572,
0.007975698448717594,
-0.0918218269944191,
-0.06852039694786072,
0.01747129112482071,
-0.047527946531772614,
0.01700820028781891,
0.052084606140851974,
-0.035262443125247955,
0.02637135237455368,
0.03390805795788765,
0.03276032581925392,
-0.10291346162557602,
-0.003332378575578332,
0.01112639345228672,
0.11544247716665268,
0.007219765335321426,
0.05100998282432556,
0.005515413358807564,
-0.025431262329220772,
-0.026436040177941322,
-0.0014413659228011966,
0.00818904209882021,
0.0013923177029937506,
-0.03318027779459953,
0.0664878711104393,
0.0040891217067837715,
-0.0955045223236084,
-0.09052329510450363,
-0.03902652859687805,
-0.039971865713596344,
-0.06449993699789047,
0.013297817669808865,
0.034473199397325516,
0.047696251422166824,
-0.017168700695037842,
-0.03427743539214134,
0.09384660422801971,
0.08047936111688614,
0.07797490060329437,
0.04507211968302727,
0.07602211833000183,
0.06503953039646149,
0.01845398172736168,
0.005674666725099087,
-0.017609046772122383,
0.01216393057256937,
0.02775888331234455,
0.059931471943855286,
5.9053750512640816e-33,
-0.003641213523223996,
-0.09916559606790543,
-0.05594736337661743,
-0.03800423815846443,
0.012980058789253235,
0.08054246008396149,
-0.035829104483127594,
0.05077779293060303,
-0.07139051705598831,
0.015143528580665588,
0.03646611049771309,
-0.04397071525454521,
-0.005224284715950489,
-0.10483763366937637,
0.05652843043208122,
-0.09021271020174026,
0.08073683828115463,
0.011677797883749008,
0.037960294634103775,
-0.04667484015226364,
0.02887115254998207,
-0.14327698945999146,
-0.06307291239500046,
0.02587507851421833,
0.049240995198488235,
0.02019461803138256,
0.02475791424512863,
0.08268352597951889,
-0.03004990890622139,
-0.009351569227874279,
0.025047531351447105,
0.10398215800523758,
-0.03935837373137474,
-0.0006287277210503817,
-0.018532628193497658,
-0.06364632397890091,
-0.0605563186109066,
0.07449325919151306,
-0.003447091206908226,
-0.08194686472415924,
-0.02545841410756111,
-0.024293115362524986,
-0.0748029574751854,
0.0007443464710377157,
-0.0038578491657972336,
-0.03153965249657631,
0.0096664447337389,
-0.03428773954510689,
0.03368834778666496,
-0.0032645731698721647,
0.015048804692924023,
-0.006675146985799074,
0.07033241540193558,
-0.03432082012295723,
0.060482874512672424,
0.02967817708849907,
0.0005083454889245331,
0.007860561832785606,
-0.018236763775348663,
0.0033385562710464,
0.0075170439667999744,
-0.04446295648813248,
-0.006114690098911524,
0.017853202298283577,
-0.046879421919584274,
0.039549585431814194,
-0.08380815386772156,
-0.009815625846385956,
0.004535382147878408,
-0.02485758438706398,
0.013377496972680092,
0.006204177625477314,
0.04148497432470322,
-0.06241847574710846,
-0.05860237404704094,
0.00040164636448025703,
0.027985235676169395,
0.022660881280899048,
-0.07627012580633163,
-0.10520760715007782,
0.027918115258216858,
-0.04057581350207329,
0.033689554780721664,
-0.022770501673221588,
0.07235976308584213,
-0.021936511620879173,
-0.06440658867359161,
0.031950693577528,
-0.03530034050345421,
0.074656642973423,
0.003524218685925007,
-0.0336470901966095,
0.046734295785427094,
0.02575359120965004,
-0.11130819469690323,
-6.512925633066735e-33,
-0.00035127534647472203,
0.08685047924518585,
-0.02674017660319805,
0.012927818112075329,
0.0172028299421072,
-0.01341160573065281,
-0.057701077312231064,
0.010391815565526485,
-0.08134160935878754,
0.04144112765789032,
0.0403197817504406,
0.026135722175240517,
0.03145534545183182,
0.01012040302157402,
-0.07106798887252808,
0.01578797772526741,
0.005423449445515871,
0.014244360849261284,
0.07844127714633942,
-0.003968212753534317,
-0.03396313264966011,
0.013120301067829132,
-0.008024116046726704,
0.0005954680382274091,
-0.04508161172270775,
0.037628818303346634,
0.011304734274744987,
0.014848549850285053,
0.014653177931904793,
-0.0757945105433464,
-0.05454065650701523,
0.02122458815574646,
-0.03261272981762886,
0.0918118804693222,
0.05121110752224922,
-0.10837555676698685,
0.08342352509498596,
0.10566059499979019,
0.05131591856479645,
0.020171618089079857,
0.10631770640611649,
0.03524045646190643,
-0.043207257986068726,
0.029791736975312233,
-0.0005021397955715656,
-0.01601496897637844,
0.006290003191679716,
0.02303161844611168,
0.004378702491521835,
0.025395497679710388,
-0.1195109412074089,
-0.10607559233903885,
0.027266891673207283,
0.06268579512834549,
-0.03731619939208031,
-0.028339438140392303,
0.05611318722367287,
-0.037970028817653656,
0.0481635257601738,
0.01667625457048416,
-0.009395779110491276,
-0.09050653874874115,
0.03012646920979023,
0.04909520223736763,
0.03707725927233696,
-0.015202514827251434,
-0.13202106952667236,
0.050186097621917725,
0.053092870861291885,
0.04444357752799988,
0.0217518899589777,
0.11944053322076797,
-0.0605846531689167,
-0.026980921626091003,
-0.0612180233001709,
0.005038912873715162,
-0.012125931680202484,
-0.13414259254932404,
0.0688934177160263,
-0.04717099666595459,
-0.05679604038596153,
0.08497326821088791,
-0.012058744207024574,
0.02123423106968403,
-0.049519188702106476,
0.03503304719924927,
-0.011776565574109554,
0.03751043230295181,
0.04279168322682381,
0.04900024086236954,
-0.072508305311203,
0.022883567959070206,
0.00018950377125293016,
-0.05093177780508995,
-0.06724773347377777,
-5.028723393252221e-8,
-0.026888767257332802,
-0.030440712347626686,
-0.015167610719799995,
0.0010943186935037374,
0.13608519732952118,
-0.06851419806480408,
-0.011794491671025753,
0.016717782244086266,
0.015119235962629318,
-0.0024589737877249718,
0.014238433912396431,
-0.0015965320635586977,
0.07450776547193527,
0.026417234912514687,
0.04549755901098251,
-0.0706683099269867,
-0.006021490786224604,
-0.03838362172245979,
-0.003015745896846056,
0.041431501507759094,
0.004050879739224911,
-0.026592951267957687,
0.08547888696193695,
0.048773352056741714,
0.02359301596879959,
-0.06752938032150269,
0.06790212541818619,
0.06085232272744179,
0.026881016790866852,
-0.054596155881881714,
-0.15842032432556152,
-0.00013479146582540125,
0.060955923050642014,
0.015002826228737831,
-0.09768354892730713,
0.04444479942321777,
-0.027651550248265266,
-0.007045646198093891,
0.02426539734005928,
0.07121884822845459,
0.03803012892603874,
-0.07688382267951965,
-0.01366423163563013,
0.05785265192389488,
-0.045942217111587524,
0.02121792361140251,
-0.030458515509963036,
-0.02954452857375145,
0.061126839369535446,
0.06490769982337952,
-0.00973556749522686,
-0.04130870848894119,
0.010557823814451694,
0.014115015044808388,
-0.040581267327070236,
-0.007906999439001083,
0.0037028288934379816,
0.009757289662957191,
-0.0030312875751405954,
0.04127335548400879,
0.002310797106474638,
0.026726091280579567,
-0.058494098484516144,
-0.016847185790538788
] | 0.108942 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.