content large_stringlengths 3 20.5k | url large_stringlengths 53 192 ⌀ | branch large_stringclasses 4
values | source large_stringclasses 51
values | embeddings listlengths 384 384 | score float64 -0.21 0.65 |
|---|---|---|---|---|---|
handler or when any other value is returned from the handler, applying the changeset is aborted and the database is rolled back. \*\*Default\*\*: A function that returns `SQLITE\_CHANGESET\_ABORT`. \* Returns: {boolean} Whether the changeset was applied successfully without being aborted. An exception is thrown if the ... | https://github.com/nodejs/node/blob/main/doc/api/sqlite.md | main | nodejs | [
0.016511540859937668,
0.005110786762088537,
-0.02076316624879837,
0.047049254179000854,
-0.013878763653337955,
-0.018981361761689186,
0.042722754180431366,
0.04592316225171089,
0.019105136394500732,
0.08657875657081604,
0.00905196089297533,
-0.034495655447244644,
-0.0036878855898976326,
-0... | 0.045377 |
method returns an empty array. The prepared statement [parameters are bound][] using the values in `namedParameters` and `anonymousParameters`. ### `statement.columns()` \* Returns: {Array} An array of objects. Each object corresponds to a column in the prepared statement, and contains the following properties: \* `col... | https://github.com/nodejs/node/blob/main/doc/api/sqlite.md | main | nodejs | [
0.02250772714614868,
0.017605528235435486,
-0.11050844192504883,
0.04807551950216293,
-0.06560612469911575,
-0.09384063631296158,
0.03335300832986832,
0.021408267319202423,
-0.0212114155292511,
-0.015778830274939537,
0.009574987925589085,
-0.08224064111709595,
0.03734012693166733,
-0.14046... | 0.085243 |
field is either a number or a `BigInt` depending on the prepared statement's configuration. This property is the result of [`sqlite3\_changes64()`][]. \* `lastInsertRowid` {number|bigint} The most recently inserted rowid. This field is either a number or a `BigInt` depending on the prepared statement's configuration. T... | https://github.com/nodejs/node/blob/main/doc/api/sqlite.md | main | nodejs | [
-0.01181048434227705,
0.027512148022651672,
-0.038567084819078445,
0.05794660747051239,
-0.07897321879863739,
-0.004096134100109339,
0.020927580073475838,
0.017236970365047455,
-0.0009820954874157906,
0.023707157000899315,
-0.03167787939310074,
-0.013251553289592266,
0.05451548099517822,
-... | 0.081864 |
the rows returned by the query. Executes the given SQL query and returns all resulting rows as an array of objects. This function is intended to be used as a template literal tag, not to be called directly. ### `sqlTagStore.get(stringElements[, ...boundParameters])` \* `stringElements` {string\[]} Template literal elem... | https://github.com/nodejs/node/blob/main/doc/api/sqlite.md | main | nodejs | [
0.02612435445189476,
0.05549388378858566,
0.006401016842573881,
0.0682782456278801,
-0.08579771965742111,
-0.017898306250572205,
0.09325938671827316,
0.04558172821998596,
-0.06217719614505768,
-0.047933179885149,
-0.03201080113649368,
-0.023152710869908333,
0.018314369022846222,
-0.0793322... | -0.033988 |
the same connection - same {DatabaseSync} - object will be reflected in the backup right away. However, mutations from other connections will cause the backup process to restart. ```cjs const { backup, DatabaseSync } = require('node:sqlite'); (async () => { const sourceDb = new DatabaseSync('source.db'); const totalPag... | https://github.com/nodejs/node/blob/main/doc/api/sqlite.md | main | nodejs | [
-0.11564826965332031,
-0.028035465627908707,
-0.020163629204034805,
0.04537232592701912,
-0.039210740476846695,
-0.04237571358680725,
-0.04448718950152397,
-0.048748474568128586,
0.009181218221783638,
-0.0020332641433924437,
-0.031464409083127975,
0.04601490870118141,
0.041596997529268265,
... | -0.004616 |
to proceed normally. | | `SQLITE_DENY` | Deny the operation and cause an error to be returned. | | `SQLITE_IGNORE` | Ignore the operation and continue as if it had never been requested. | ##### Authorization action codes The following constants are passed as the first argument to the authorizer callback function to ind... | https://github.com/nodejs/node/blob/main/doc/api/sqlite.md | main | nodejs | [
-0.011896906420588493,
-0.007078658323734999,
-0.10370398312807083,
0.03129217401146889,
-0.03409700095653534,
-0.06668145209550858,
0.10449712723493576,
-0.0014667479554191232,
-0.07032573223114014,
0.05989773944020271,
0.08073685318231583,
-0.06894171237945557,
0.04755684733390808,
-0.06... | 0.028118 |
# Stream > Stability: 2 - Stable A stream is an abstract interface for working with streaming data in Node.js. The `node:stream` module provides an API for implementing the stream interface. There are many stream objects provided by Node.js. For instance, a [request to an HTTP server][http-incoming-message] and [`proce... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.04832777753472328,
-0.02461600862443447,
0.01245670486241579,
0.027663903310894966,
0.06049765273928642,
-0.02142409048974514,
-0.0185977965593338,
0.050491828471422195,
0.039725787937641144,
-0.042334698140621185,
-0.0737425908446312,
0.05312336981296539,
-0.08163343369960785,
0.012114... | 0.138117 |
signal }) { source.setEncoding('utf8'); // Work with strings rather than `Buffer`s. for await (const chunk of source) { yield await processChunk(chunk, { signal }); } }, fs.createWriteStream('uppercase.txt'), ); console.log('Pipeline succeeded.'); } run().catch(console.error); ``` ```mjs import { pipeline } from 'node:... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.024190671741962433,
0.02352224476635456,
0.01818167418241501,
-0.024721240624785423,
-0.07658626139163971,
-0.03280533477663994,
-0.025139017030596733,
0.12643231451511383,
0.020538287237286568,
-0.055035416036844254,
-0.05080673098564148,
-0.020890163257718086,
-0.0024402036797255278,
... | 0.04724 |
number of bytes][hwm-gotcha]. For streams operating in object mode, the `highWaterMark` specifies a total number of objects. For streams operating on (but not decoding) strings, the `highWaterMark` specifies a total number of UTF-16 code units. Data is buffered in `Readable` streams when the implementation calls [`stre... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.009721480309963226,
-0.00295035052113235,
-0.04504572972655296,
-0.006387977860867977,
-0.01903548836708069,
-0.11710165441036224,
0.04680173471570015,
0.027804570272564888,
-0.010395410470664501,
-0.03790624067187309,
-0.05415889993309975,
0.04629207402467728,
-0.017115173861384392,
-0... | 0.096119 |
} }); }); server.listen(1337); // $ curl localhost:1337 -d "{}" // object // $ curl localhost:1337 -d "\"foo\"" // string // $ curl localhost:1337 -d "not json" // error: Unexpected token 'o', "not json" is not valid JSON ``` [`Writable`][] streams (such as `res` in the example) expose methods such as `write()` and `en... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.03161061182618141,
0.03862990066409111,
-0.057846687734127045,
-0.03788752853870392,
-0.06035851314663887,
-0.04973224923014641,
-0.026640189811587334,
0.016435813158750534,
0.09979028254747391,
-0.02864585444331169,
-0.008799812756478786,
0.027337070554494858,
-0.03777959197759628,
0.0... | 0.15733 |
##### Event: `'finish'` The `'finish'` event is emitted after the [`stream.end()`][stream-end] method has been called, and all data has been flushed to the underlying system. ```js const writer = getWritableStreamSomehow(); for (let i = 0; i < 100; i++) { writer.write(`hello, #${i}!\n`); } writer.on('finish', () => { c... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.004100474528968334,
0.002939383964985609,
0.02394012361764908,
0.028934171423316002,
0.030154773965477943,
-0.028101468458771706,
-0.00994904711842537,
0.013063862919807434,
0.07927650213241577,
-0.0014711848925799131,
-0.03744921088218689,
0.06626342982053757,
-0.11402423679828644,
-0.... | 0.128252 |
const myStream = new Writable(); console.log(myStream.destroyed); // false myStream.destroy(); console.log(myStream.destroyed); // true ``` ##### `writable.end([chunk[, encoding]][, callback])` \* `chunk` {string|Buffer|TypedArray|DataView|any} Optional data to write. For streams not operating in object mode, `chunk` m... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.010923793539404869,
-0.005884394980967045,
0.007172592915594578,
0.041352663189172745,
-0.015510724857449532,
-0.04911837726831436,
-0.012078933417797089,
0.024655308574438095,
0.024104265496134758,
-0.046101413667201996,
-0.09989546239376068,
0.09373729676008224,
-0.11610795557498932,
... | 0.0818 |
than `null`. \* `encoding` {string|null} The encoding, if `chunk` is a string. \*\*Default:\*\* `'utf8'` \* `callback` {Function} Callback for when this chunk of data is flushed. \* Returns: {boolean} `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to wr... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.07431057095527649,
0.026633616536855698,
-0.035783346742391586,
0.07837475091218948,
-0.0695832148194313,
-0.09784012287855148,
-0.0116482675075531,
0.030281325802206993,
0.01656041108071804,
-0.04055172950029373,
-0.052515722811222076,
0.031001197174191475,
-0.010043509304523468,
-0.05... | 0.08789 |
using events via the [`EventEmitter`][] interface. \* In paused mode, the [`stream.read()`][stream-read] method must be called explicitly to read chunks of data from the stream. All [`Readable`][] streams begin in paused mode but can be switched to flowing mode in one of the following ways: \* Adding a [`'data'`][] eve... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.014044057577848434,
-0.025417018681764603,
-0.044573940336704254,
0.011224008165299892,
-0.005502968095242977,
-0.03716408461332321,
-0.004655390977859497,
0.02759215421974659,
-0.04015040770173073,
-0.014685924164950848,
-0.04952896758913994,
0.06227264553308487,
-0.08279132097959518,
... | 0.065025 |
should choose \_one\_ of the methods of consuming data and \_should never\_ use multiple methods to consume data from a single stream. Specifically, using a combination of `on('data')`, `on('readable')`, `pipe()`, or async iterators could lead to unintuitive behavior. #### Class: `stream.Readable` ##### Event: `'close'... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.03769557923078537,
-0.013761756010353565,
-0.008195677772164345,
0.05734400823712349,
0.05653270706534386,
-0.08665315061807632,
0.05884624272584915,
0.030087199062108994,
0.05205560848116875,
-0.017598900943994522,
-0.037031929939985275,
0.0414956733584404,
-0.09989459067583084,
-0.001... | 0.090407 |
{ console.log(data); } }); ``` If the end of the stream has been reached, calling [`stream.read()`][stream-read] will return `null` and trigger the `'end'` event. This is also true if there never was any data to be read. For instance, in the following example, `foo.txt` is an empty file: ```js const fs = require('node:... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.0017338177422061563,
0.010686350986361504,
-0.042204052209854126,
0.06606370210647583,
0.08232027292251587,
-0.037253789603710175,
-0.00433906726539135,
0.05701236426830292,
0.08096813410520554,
0.024558119475841522,
-0.03924769535660744,
0.09519311785697937,
-0.05607854947447777,
-0.01... | 0.075066 |
data will be automatically managed so that the destination `Writable` stream is not overwhelmed by a faster `Readable` stream. The following example pipes all of the data from the `readable` into a file named `file.txt`: ```js const fs = require('node:fs'); const readable = getReadableStreamSomehow(); const writable = ... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.02536769211292267,
-0.021636174991726875,
-0.04837340489029884,
0.05023388937115669,
0.006174146663397551,
-0.0770842656493187,
-0.0322599820792675,
0.06673094630241394,
0.000050538015784695745,
-0.006667217239737511,
-0.04960312694311142,
0.09203777462244034,
-0.0012420850107446313,
0.... | 0.087336 |
indicating that it has consumed all buffered content but there may be more data yet to be buffered. In such cases, a new `'readable'` event is emitted once there's more data in the buffer, and the `'end'` event signifies the end of data transmission. Therefore to read a file's whole contents from a `readable`, it is ne... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
0.012947994284331799,
0.019887864589691162,
0.02151154913008213,
0.020354866981506348,
0.04548272117972374,
-0.055184002965688705,
0.04397020861506462,
0.05517124384641647,
0.04664243012666702,
-0.023084495216608047,
-0.08129949122667313,
0.1216946393251419,
-0.1151595339179039,
-0.0047138... | 0.076951 |
=> { assert.equal(typeof chunk, 'string'); console.log('Got %d characters of string data:', chunk.length); }); ``` ##### `readable.unpipe([destination])` \* `destination` {stream.Writable} Optional specific stream to unpipe \* Returns: {this} The `readable.unpipe()` method detaches a `Writable` stream previously attach... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.043954867869615555,
0.0373612716794014,
0.031404048204422,
0.03123212605714798,
0.02527575008571148,
-0.07821781933307648,
0.001392063102684915,
0.07858947664499283,
0.0002222232724307105,
-0.012511848472058773,
-0.021335411816835403,
0.07668717950582504,
-0.050007082521915436,
0.001762... | 0.096339 |
as it is currently defined. (See [Compatibility][] for more information.) When using an older Node.js library that emits [`'data'`][] events and has a [`stream.pause()`][stream-pause] method that is advisory only, the `readable.wrap()` method can be used to create a [`Readable`][] stream that uses the old stream as its... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.05259402096271515,
-0.011336307972669601,
-0.026234352961182594,
0.05581866204738617,
0.12090146541595459,
0.01638123393058777,
-0.03612704947590828,
0.02805153839290142,
-0.0009569434332661331,
-0.02168925851583481,
-0.03647911548614502,
0.11253045499324799,
-0.09883321821689606,
-0.00... | 0.145314 |
to `false`, calling `return` on the async iterator, or exiting a `for await...of` iteration using a `break`, `return`, or `throw` will not destroy the stream. \*\*Default:\*\* `true`. \* Returns: {AsyncIterator} to consume the stream. The iterator created by this method gives users the option to cancel the destruction ... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.06928898394107819,
0.06296709924936295,
-0.01795293018221855,
0.06867162138223648,
0.07996626943349838,
-0.058042481541633606,
0.006215019151568413,
-0.0024221872445195913,
0.035477325320243835,
-0.05291980504989624,
-0.05623123422265053,
0.06890088319778442,
-0.05280563607811928,
0.007... | 0.025715 |
truthy value, the chunk will be passed to the result stream. If the `fn` function returns a promise - that promise will be `await`ed. ```mjs import { Readable } from 'node:stream'; import { Resolver } from 'node:dns/promises'; // With a synchronous predicate. for await (const chunk of Readable.from([1, 2, 3, 4]).filter... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.06517156958580017,
0.04459569975733757,
0.03071817383170128,
0.015835830941796303,
0.04581572860479355,
-0.07213453948497772,
-0.05462587624788284,
-0.0017963945865631104,
0.05893117934465408,
-0.020258968695998192,
-0.09288346767425537,
0.0022328610066324472,
-0.032708652317523956,
-0.... | 0.023056 |
= new Resolver(); // Make dns queries concurrently using .map and collect // the results into an array using toArray const dnsResults = await Readable.from([ 'nodejs.org', 'openjsf.org', 'www.linuxfoundation.org', ]).map(async (domain) => { const { address } = await resolver.resolve4(domain, { ttl: true }); return addr... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.07273157685995102,
-0.009631920605897903,
-0.01445151399821043,
0.03696294501423836,
-0.07081922143697739,
-0.09396814554929733,
-0.06579633057117462,
0.0053895385935902596,
0.04469379782676697,
-0.0012939231237396598,
-0.10469985753297806,
0.05209623649716377,
-0.06596934795379639,
-0.... | 0.036611 |
> 10); // undefined // With an asynchronous predicate, making at most 2 file checks at a time. const foundBigFile = await Readable.from([ 'file1', 'file2', 'file3', ]).find(async (fileName) => { const stats = await stat(fileName); return stats.size > 1024 \* 1024; }, { concurrency: 2 }); console.log(foundBigFile); // F... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.08713189512491226,
0.029956990852952003,
-0.06860142946243286,
0.06977951526641846,
0.07594684511423111,
-0.06909271329641342,
-0.02509770542383194,
0.07023482769727707,
0.034310318529605865,
0.013474460691213608,
-0.02105506882071495,
0.0866064578294754,
-0.07227488607168198,
-0.009195... | 0.140025 |
result of concatResult) { // This will contain the contents (all chunks) of all 4 files console.log(result); } ``` ##### `readable.drop(limit[, options])` > Stability: 1 - Experimental \* `limit` {number} the number of chunks to drop from the readable. \* `options` {Object} \* `signal` {AbortSignal} allows destroying t... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.028515763580799103,
0.04469621926546097,
0.04609757289290428,
0.031876396387815475,
0.07136065512895584,
-0.06233638525009155,
-0.0017986003076657653,
0.03289799764752388,
0.0054972367361187935,
-0.003834664588794112,
-0.04368504881858826,
0.08245481550693512,
-0.012005671858787537,
0.0... | 0.0942 |
to `true`. This can be changed manually to change the half-open behavior of an existing `Duplex` stream instance, but must be changed before the `'end'` event is emitted. #### Class: `stream.Transform` Transform streams are [`Duplex`][] streams where the output is in some way related to the input. Like all [`Duplex`][]... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.11101473122835159,
0.07274413108825684,
-0.02539195492863655,
0.005446247290819883,
0.010688507929444313,
-0.05511413514614105,
-0.035134654492139816,
0.015340746380388737,
-0.022913111373782158,
-0.06773252040147781,
-0.05580352991819382,
0.04881911352276802,
0.0081033231690526,
0.0674... | 0.069753 |
invoked in the callback: ```js const cleanup = finished(rs, (err) => { cleanup(); // ... }); ``` ### `stream.pipeline(source[, ...transforms], destination, callback)` ### `stream.pipeline(streams, callback)` \* `streams` {Stream\[]|Iterable\[]|AsyncIterable\[]|Function\[]| ReadableStream\[]|WritableStream\[]|TransformS... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.10162586718797684,
0.019111935049295425,
-0.03871387615799904,
0.010867570526897907,
0.03060186468064785,
-0.041033435612916946,
-0.0290084145963192,
0.03331737965345383,
0.027557894587516785,
-0.06795123219490051,
-0.07613582164049149,
0.09947869926691055,
-0.08829443901777267,
0.02094... | 0.095844 |
Cannot yield `null`. \* `AsyncGeneratorFunction` converts into a readable/writable transform `Duplex`. Must take a source `AsyncIterable` as first parameter. Cannot yield `null`. \* `AsyncFunction` converts into a writable `Duplex`. Must return either `null` or `undefined`. ```mjs import { compose } from 'node:stream';... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.09903432428836823,
0.003906817641109228,
-0.013367337174713612,
0.07804544270038605,
-0.0474860705435276,
0.01835421659052372,
-0.09458409249782562,
0.029565440490841866,
-0.027798430994153023,
-0.06576965004205704,
-0.01964298076927662,
-0.046752702444791794,
-0.01769440248608589,
-0.0... | 0.008695 |
A utility method for creating duplex streams. \* `Stream` converts writable stream into writable `Duplex` and readable stream to `Duplex`. \* `Blob` converts into readable `Duplex`. \* `string` converts into readable `Duplex`. \* `ArrayBuffer` converts into readable `Duplex`. \* `AsyncIterable` converts into a readable... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.0697995126247406,
0.003709944663569331,
-0.10136198252439499,
0.06807366758584976,
-0.08850400149822235,
-0.030601954087615013,
0.002883341396227479,
0.03761499747633934,
-0.0626702532172203,
-0.04312768578529358,
-0.04657895117998123,
-0.00817128550261259,
-0.011914992704987526,
0.0147... | 0.088839 |
controller.signal, fs.createReadStream(('object.json')), ); // Later, abort the operation closing the stream controller.abort(); ``` Or using an `AbortSignal` with a readable stream as an async iterable: ```js const controller = new AbortController(); setTimeout(() => controller.abort(), 10\_000); // set a timeout cons... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.07795417308807373,
0.025790464133024216,
-0.06195266917347908,
0.004028975032269955,
0.0354611836373806,
-0.01164235919713974,
-0.04286906495690346,
0.08053386211395264,
0.08098349720239639,
0.0010976976482197642,
-0.010182330384850502,
0.06876223534345627,
-0.08460569381713867,
0.03072... | 0.106248 |
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 writ... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.08072493970394135,
0.030642591416835785,
-0.017747774720191956,
0.0326593853533268,
-0.00585726834833622,
-0.05531388148665428,
0.015013703145086765,
0.053893379867076874,
-0.021927407011389732,
-0.03726828470826149,
-0.08884523808956146,
0.042788900434970856,
-0.08820367604494095,
0.02... | 0.098937 |
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 (t... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.11156768351793289,
0.0863274335861206,
-0.05841248482465744,
0.0035736244171857834,
-0.0002762273361440748,
-0.0810309499502182,
0.03590451553463936,
0.09013976901769638,
0.051048584282398224,
-0.011677198112010956,
-0.05024605989456177,
0.0853772833943367,
-0.05563554912805557,
-0.0199... | 0.135368 |
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 pr... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.08488429337739944,
0.013868615962564945,
-0.02030385658144951,
0.03997268155217171,
-0.0004613825003616512,
-0.10627137869596481,
-0.010104358196258545,
0.04226769879460335,
0.030840976163744926,
0.0167408250272274,
-0.030764419585466385,
0.13300548493862152,
-0.035753749310970306,
-0.0... | 0.10633 |
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 ... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.013707882724702358,
0.02544400840997696,
-0.049559976905584335,
0.025526685640215874,
-0.03014654479920864,
-0.06325560808181763,
0.07714544236660004,
0.040965016931295395,
0.05331292003393173,
-0.02477850206196308,
-0.06417683511972427,
0.006388228386640549,
-0.05972510576248169,
0.032... | 0.14602 |
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... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.06132780760526657,
-0.000009717052307678387,
-0.04253411665558815,
0.03110135719180107,
-0.06056741252541542,
-0.1310759037733078,
0.031676508486270905,
0.0236146692186594,
0.006696015130728483,
-0.04438556730747223,
-0.023410366848111153,
0.10824020206928253,
-0.029443738982081413,
-0.... | 0.087294 |
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 w... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.03817396238446236,
-0.0007723818998783827,
-0.005415188614279032,
0.04122430831193924,
0.054244909435510635,
-0.06563819199800491,
-0.00021348700101953,
0.06136469915509224,
0.043549731373786926,
-0.032699715346097946,
-0.04661760479211807,
0.09686355292797089,
-0.0475463829934597,
0.04... | 0.166179 |
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('complet... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.09729112684726715,
0.0392005480825901,
0.0042902203276753426,
0.031846534460783005,
-0.023792685940861702,
-0.107016421854496,
-0.027655761688947678,
0.029193203896284103,
0.03665852174162865,
-0.006751331966370344,
-0.04572940245270729,
0.100937120616436,
-0.07516998797655106,
0.008052... | 0.132254 |
\* `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);... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.12057536840438843,
0.06470906734466553,
0.022030897438526154,
-0.003349687671288848,
-0.021501071751117706,
0.004454906098544598,
-0.04593152925372124,
0.02200043573975563,
0.05150577053427696,
-0.038602981716394424,
0.015019601210951805,
0.03273381292819977,
-0.10432887077331543,
0.039... | 0.064299 |
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 fir... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.17327557504177094,
-0.0004786221543326974,
-0.018293673172593117,
0.05006791278719902,
-0.03574356064200401,
-0.05480156093835831,
-0.07789544016122818,
0.0191772673279047,
0.10636947304010391,
-0.06506799906492233,
-0.01065001916140318,
0.06801942735910416,
-0.01630290411412716,
-0.062... | 0.069483 |
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 necess... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.0541173592209816,
-0.010922419838607311,
0.012393767014145851,
0.04771830514073372,
0.08288391679525375,
-0.0484122559428215,
-0.0241127647459507,
0.01342766173183918,
0.01789817586541176,
-0.018463464453816414,
-0.0195885319262743,
0.15564246475696564,
-0.08392150700092316,
-0.01569038... | 0.125779 |
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 ... | https://github.com/nodejs/node/blob/main/doc/api/stream.md | main | nodejs | [
-0.04209436848759651,
0.04487153887748718,
-0.023503128439188004,
-0.012296753004193306,
0.03451671451330185,
-0.04042763635516167,
-0.017141735181212425,
-0.02656063437461853,
0.007311664521694183,
0.02344718761742115,
-0.07701674103736877,
-0.007832000032067299,
-0.07655268907546997,
0.0... | 0.016099 |
# 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 ... | 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.... | 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 b... | 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.0447... | 0.033362 |
Returns the same object or value // The error will be caught here } ``` ### `asyncLocalStorage.withScope(store)` > Stability: 1 - Experimental \* `store` {any} \* Returns: {RunScope} Creates a disposable scope that enters the given store and automatically restores the previous store value when the scope is disposed. Th... | https://github.com/nodejs/node/blob/main/doc/api/async_context.md | main | nodejs | [
-0.07497459650039673,
0.07569937407970428,
-0.067868672311306,
0.15439069271087646,
-0.04420814290642738,
-0.0248205978423357,
0.0190139077603817,
-0.007273873779922724,
0.0057422928512096405,
-0.007775295525789261,
0.022746870294213295,
0.0283860731869936,
0.0069503746926784515,
-0.029569... | 0.005234 |
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: `RunScope` > Stability: 1 -... | https://github.com/nodejs/node/blob/main/doc/api/async_context.md | main | nodejs | [
-0.0796133503317833,
0.056641075760126114,
-0.03892683610320091,
0.13003486394882202,
-0.001317757647484541,
-0.07001187652349472,
0.07631810754537582,
0.013072086498141289,
0.022557292133569717,
-0.006018043030053377,
-0.00932267401367426,
0.043189920485019684,
0.012939141131937504,
-0.01... | 0.029658 |
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 creat... | https://github.com/nodejs/node/blob/main/doc/api/async_context.md | main | nodejs | [
-0.04992391914129257,
0.029250608757138252,
-0.08059584349393845,
0.1436539888381958,
-0.046173058450222015,
-0.026093672960996628,
0.039142776280641556,
-0.021096065640449524,
0.07225529849529266,
-0.04331118240952492,
-0.055550772696733475,
-0.030468638986349106,
-0.01522692758589983,
-0... | 0.078336 |
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 {... | https://github.com/nodejs/node/blob/main/doc/api/async_context.md | main | nodejs | [
-0.08320655673742294,
0.03978936746716499,
0.006908440962433815,
0.06513886153697968,
-0.008926636539399624,
-0.029046565294265747,
-0.008172828704118729,
-0.035455863922834396,
0.10691395401954651,
-0.0025789602659642696,
-0.020444124937057495,
-0.05195138603448868,
-0.0592585913836956,
-... | 0.094399 |
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('.... | https://github.com/nodejs/node/blob/main/doc/api/async_context.md | main | nodejs | [
-0.0556039996445179,
0.05145951360464096,
-0.0014187172055244446,
0.03810940310359001,
0.013502538204193115,
-0.07036728411912918,
0.018467366695404053,
-0.01082755345851183,
0.03593001514673233,
-0.02155710570514202,
-0.08471323549747467,
-0.01034693792462349,
-0.06896281987428665,
0.0129... | 0.104556 |
# 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 ... | 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.04746... | 0.158815 |
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 obje... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.03331023454666138,
-0.015149645507335663,
-0.002728191902860999,
0.09807749837636948,
-0.011433053761720657,
-0.000979190575890243,
-0.05741972103714943,
-0.00912392232567072,
0.022016339004039764,
-0.03896518051624298,
-0.014483417384326458,
0.039357732981443405,
0.022271722555160522,
... | 0.054373 |
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 ... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.05223044008016586,
0.07814688235521317,
0.06971194595098495,
0.01977158896625042,
0.09634938091039658,
-0.06482905894517899,
0.017956214025616646,
0.01906578429043293,
0.055402133613824844,
-0.0029922444373369217,
0.026385603472590446,
0.019203947857022285,
-0.03969639167189598,
0.01647... | 0.102495 |
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 execut... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.02140478789806366,
0.017255550250411034,
0.027967866510152817,
0.09456678479909897,
0.11077777296304703,
-0.022636737674474716,
-0.11281073838472366,
0.0011639317963272333,
0.004768047481775284,
-0.021815136075019836,
-0.028799720108509064,
0.033335521817207336,
-0.024039775133132935,
-... | 0.023999 |
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 nam... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.10189235210418701,
0.02864551916718483,
0.009871356189250946,
0.021844109520316124,
0.06362937390804291,
-0.08540917932987213,
0.042435888200998306,
-0.03644208610057831,
0.028876330703496933,
-0.05464911833405495,
0.021732907742261887,
0.006925481837242842,
0.012891869060695171,
-0.017... | 0.067212 |
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 `unhandledReje... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.015180276706814766,
-0.019303906708955765,
0.023300303146243095,
0.11695913225412369,
0.0923130139708519,
0.0011974057415500283,
-0.03417868912220001,
0.04996670410037041,
0.024892760440707207,
-0.020252836868166924,
-0.01675168052315712,
0.00733559112995863,
0.03919058293104172,
0.0046... | 0.072554 |
```bash node --test "\*\*/\*.test.js" "\*\*/\*.spec.js" ``` ### Randomizing tests execution order > Stability: 1.0 - Early development The test runner can randomize execution order to help detect order-dependent tests. When enabled, the runner randomizes both discovered test files and queued tests within each file. Use... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.03172258287668228,
0.024162059649825096,
-0.019105833023786545,
0.08182738721370697,
0.08950003236532211,
-0.04355604946613312,
-0.012344427406787872,
-0.04059584066271782,
0.01726539619266987,
0.005825115833431482,
-0.023799285292625427,
0.09703352302312851,
-0.010635742917656898,
-0.0... | 0.023686 |
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: \* `-... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.0712985247373581,
0.002083905739709735,
-0.009569757618010044,
0.07700477540493011,
0.12675516307353973,
-0.06665891408920288,
0.011438777670264244,
-0.018173834308981895,
-0.019849000498652458,
0.018015658482909203,
0.028415925800800323,
0.06938979774713516,
-0.043124206364154816,
-0.0... | 0.109054 |
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.st... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.09732169657945633,
-0.009647858329117298,
-0.007046878803521395,
0.018575245514512062,
-0.07395080476999283,
-0.04131847620010376,
-0.019124427810311317,
0.011886118911206722,
0.019195403903722763,
-0.0019728096667677164,
-0.07361094653606415,
-0.03070877306163311,
0.002540480112656951,
... | 0.038168 |
// 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.... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.07548313587903976,
0.010802492499351501,
-0.01588151790201664,
0.06793871521949768,
-0.024877240881323814,
-0.007701120339334011,
-0.05597348511219025,
0.03618651255965233,
0.05818259343504906,
-0.015120957978069782,
0.0014065243303775787,
-0.01039605587720871,
-0.04489332437515259,
-0.... | 0.055455 |
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({ a... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.06492339074611664,
0.041297122836112976,
0.0049143885262310505,
0.06343066692352295,
-0.04589027166366577,
-0.003029865212738514,
-0.05661781504750252,
0.03345146030187607,
0.024186313152313232,
0.010308769531548023,
-0.011125970631837845,
-0.028424449265003204,
-0.0052499896846711636,
... | 0.034063 |
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 ... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.07829441875219345,
0.019649216905236244,
-0.036021653562784195,
0.0419253446161747,
0.03528355807065964,
-0.04944433644413948,
-0.058470435440540314,
0.002631867304444313,
0.05219109728932381,
-0.00024364839191548526,
0.0051522147841751575,
0.03916432335972786,
0.06006411090493202,
-0.0... | 0.011818 |
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 rep... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.0702461451292038,
0.0416177473962307,
-0.03244435042142868,
0.1283973753452301,
-0.010827606543898582,
0.005709612742066383,
-0.004558486398309469,
0.08371101319789886,
0.07677892595529556,
0.039666276425123215,
0.025471307337284088,
-0.051689766347408295,
-0.005615348927676678,
-0.0346... | 0.075146 |
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... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.0545782707631588,
0.020618000999093056,
-0.06512387841939926,
0.019428957253694534,
0.0025853775441646576,
-0.06869968771934509,
0.01689545251429081,
0.06841657310724258,
-0.03187435492873192,
0.03219864144921303,
0.07450549304485321,
0.022472713142633438,
-0.02385219931602478,
0.031338... | 0.070681 |
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... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.02016652189195156,
0.06521939486265182,
-0.017822718247771263,
0.06513093411922455,
0.052472807466983795,
0.01031809113919735,
0.0009467379422858357,
-0.008261475712060928,
-0.04988376051187515,
-0.03218315541744232,
0.04666019603610039,
0.027476124465465546,
0.0338018462061882,
0.02411... | 0.02645 |
\* `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 concurren... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.12039053440093994,
0.03149109333753586,
0.002839417662471533,
0.09710125625133514,
0.006424404680728912,
-0.03287823498249054,
-0.0030385672580450773,
0.0037656635977327824,
-0.012919438071548939,
-0.022548189386725426,
-0.04632866010069847,
-0.04702950268983841,
-0.0010192646877840161,
... | 0.067994 |
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. ... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.08757195621728897,
0.09548301994800568,
0.03648209944367409,
0.11218336224555969,
0.01665644347667694,
-0.0795404389500618,
-0.05755849927663803,
-0.006467584986239672,
0.047058045864105225,
-0.022866474464535713,
-0.015568958595395088,
0.05732708424329758,
-0.024878865107893944,
-0.009... | 0.063004 |
{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 fu... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.09287554025650024,
0.04258009418845177,
-0.02163108065724373,
0.10016132891178131,
0.004807969089597464,
-0.028107983991503716,
-0.04399416595697403,
-0.018741972744464874,
0.04404763877391815,
-0.051820047199726105,
-0.032413531094789505,
0.05640396475791931,
-0.09145539253950119,
-0.0... | 0.10129 |
`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 t... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.08666432648897171,
0.003849476110190153,
-0.03424733877182007,
0.021876394748687744,
-0.06804896146059036,
-0.10072911530733109,
0.07787074893712997,
0.019922884181141853,
0.0378536731004715,
-0.02973059192299843,
-0.02272537350654602,
-0.031244253739714622,
-0.0010119949001818895,
-0.0... | 0.107679 |
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... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.07068387418985367,
0.006174519192427397,
-0.03704266995191574,
0.05435130000114441,
-0.08027943968772888,
-0.07085660099983215,
0.0957290381193161,
0.002325050299987197,
-0.003172068390995264,
0.0024621360935270786,
-0.05750154331326485,
-0.043520279228687286,
0.017259586602449417,
-0.0... | 0.044124 |
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 = ... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.06940435618162155,
-0.05348377674818039,
-0.015563859604299068,
0.02817128412425518,
-0.07494711875915527,
0.0030723477248102427,
0.027963582426309586,
0.03993522748351097,
0.0414649061858654,
0.008758787997066975,
0.01289848331362009,
0.016772300004959106,
-0.010269256308674812,
-0.019... | 0.089426 |
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 valu... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.06541724503040314,
-0.009874179027974606,
0.008600728586316109,
0.0406084880232811,
0.051086053252220154,
0.007845258340239525,
0.02081545814871788,
0.03963349014520645,
-0.0014846653211861849,
0.02123955637216568,
0.0446903258562088,
-0.06396479159593582,
-0.041779495775699615,
-0.0041... | 0.06131 |
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 long... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.07617046684026718,
-0.06305444240570068,
-0.02194741554558277,
0.04053248092532158,
-0.0543021634221077,
-0.10819544643163681,
-0.02533748745918274,
-0.03079202026128769,
-0.0699765607714653,
-0.005697638262063265,
-0.02399177849292755,
0.05037442967295647,
0.003936228808015585,
0.00200... | 0.040127 |
= 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... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.05135147273540497,
0.026888912543654442,
0.0028477762825787067,
0.08641891181468964,
-0.01105330791324377,
-0.04800281301140785,
0.0010491958819329739,
0.008193783462047577,
0.07507198303937912,
0.0004005908267572522,
0.004084703512489796,
0.04203282669186592,
0.006939043290913105,
-0.0... | 0.078176 |
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 tim... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.09816822409629822,
0.02381422370672226,
-0.011385110206902027,
0.0905442088842392,
0.0016748131019994617,
-0.017417317256331444,
-0.0030871329363435507,
0.0019964813254773617,
0.05185205861926079,
-0.02081805095076561,
0.0018008943879976869,
0.03630917891860008,
0.008160273544490337,
0.... | 0.096078 |
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); ... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.05842781439423561,
0.02108134515583515,
0.027084629982709885,
0.07442989200353622,
-0.031174607574939728,
0.0026524795684963465,
-0.09641905874013901,
0.005457078572362661,
0.07571044564247131,
-0.03754051774740219,
-0.025903301313519478,
0.02496575005352497,
-0.0040635582990944386,
-0.... | 0.04135 |
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}... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.009310944937169552,
0.047661252319812775,
-0.06140244007110596,
0.006212156731635332,
-0.10378432273864746,
-0.019250968471169472,
0.08450423181056976,
0.09338276833295822,
-0.006301200948655605,
0.04741496592760086,
-0.04501352459192276,
-0.018313435837626457,
0.06070105358958244,
-0.0... | 0.064695 |
events for the same test instance, enabling reliable correlation in custom reporters. \* `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 com... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.08750849217176437,
-0.029017644003033638,
-0.02008616179227829,
0.09777706116437912,
0.00837165117263794,
-0.04601955786347389,
0.02484702505171299,
-0.03062707558274269,
0.07418948411941528,
0.019337622448801994,
0.06295850872993469,
0.00792241096496582,
0.013104167766869068,
0.0399576... | 0.095021 |
across all events for the same test instance, enabling reliable correlation in custom reporters. \* `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 d... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.07216135412454605,
-0.016957523301243782,
-0.0743161141872406,
0.11725396662950516,
-0.006734877824783325,
-0.03542833775281906,
0.0019267285242676735,
-0.011520099826157093,
0.04222740978002548,
0.013680779375135899,
0.04785430058836937,
-0.006616546306759119,
0.0567842461168766,
0.051... | 0.069951 |
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 defi... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.08928418159484863,
0.03617040440440178,
-0.04748711362481117,
0.026605473831295967,
0.04778551310300827,
-0.05236544832587242,
-0.002216279273852706,
-0.009501888416707516,
-0.01737985759973526,
-0.02735086716711521,
0.0692640170454979,
0.0015334245981648564,
0.014100991189479828,
0.069... | 0.033991 |
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 `std... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
0.0376792773604393,
0.048775814473629,
0.012691306881606579,
0.09564580768346786,
0.014008180238306522,
-0.020787693560123444,
0.014517334289848804,
0.02006937749683857,
0.0852210521697998,
0.012942671775817871,
0.05596635863184929,
0.02301490120589733,
0.03410568833351135,
-0.002863051835... | 0.049849 |
`'tracing:node.test:start'` \* `data` {Object} \* `name` {string} The name of the test. \* `nesting` {number} The nesting level of the test. \* `file` {string|undefined} The path to the test file, or `undefined` when running in the REPL. \* `type` {string} The type of test. Either `'test'` or `'suite'`. Emitted when a ... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.046754784882068634,
0.018058467656373978,
-0.00934432540088892,
0.12036006897687912,
0.019185634329915047,
-0.05781201645731926,
-0.01853802427649498,
-0.02391740307211876,
0.0027299835346639156,
0.015536824241280556,
0.03897598013281822,
0.058991752564907074,
-0.037641193717718124,
-0.... | 0.074241 |
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', ... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.11965523660182953,
0.02002684399485588,
-0.015121192671358585,
0.12207234650850296,
0.0030646505765616894,
-0.05022480711340904,
-0.0029649112839251757,
0.03827105462551117,
0.03377756476402283,
-0.060523129999637604,
0.0077960919588804245,
0.01981469616293907,
-0.05728953331708908,
0.0... | 0.112534 |
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 t... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.049053069204092026,
0.06622833758592606,
0.005976647138595581,
0.05761853978037834,
0.05541117861866951,
-0.021312303841114044,
-0.04697128012776375,
-0.005500320345163345,
0.013923258520662785,
-0.026485448703169823,
-0.003421132918447256,
0.06355274468660355,
0.003981504123657942,
-0.... | 0.09371 |
import time) const workerId = process.env.NODE\_TEST\_WORKER\_ID; // Use workerId to allocate separate resources per worker }); ``` ### `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` {bo... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.09675844013690948,
0.061112917959690094,
-0.01941094733774662,
0.12486948072910309,
0.06391864269971848,
-0.09294308722019196,
-0.014387759380042553,
-0.0012106510112062097,
0.014912538230419159,
-0.023067304864525795,
-0.0554959699511528,
0.007557341363281012,
-0.01841575652360916,
-0.... | 0.195334 |
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'); }); ``` ... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.04281375929713249,
0.0906858965754509,
0.07034678757190704,
0.06988798826932907,
0.08172240853309631,
-0.06382671743631363,
0.07405390590429306,
-0.019264623522758484,
0.046384457498788834,
-0.06257543712854385,
0.07697535306215286,
-0.008748111315071583,
-0.00855198036879301,
0.0020793... | 0.121076 |
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 a... | https://github.com/nodejs/node/blob/main/doc/api/test.md | main | nodejs | [
-0.08924303948879242,
0.07044187188148499,
0.0058672064915299416,
0.0661531537771225,
-0.0006562085472978652,
-0.012015232816338539,
0.025108501315116882,
0.004088796209543943,
0.03478501737117767,
0.005351502448320389,
0.00515126483514905,
-0.004104149993509054,
0.008305159397423267,
-0.0... | 0.092181 |
# 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'); co... | 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.0304051... | 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 `cal... | 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.01471... | 0.147752 |
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.0025383334141224623,
0.028142914175987244,
0.0045500402338802814,
0.057453665882349014,
0.047726280987262726,
-0.040094178169965744,
0.051373593509197235,
0.05981561914086342,
0.016470981761813164,
0.030199330300092697,
0.011386437341570854,
-0.012471616268157959,
0.0051717027090489864,
... | 0.047423 |
```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])` \* `fi... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
-0.02455371618270874,
0.02069760486483574,
-0.06529751420021057,
-0.01799175702035427,
0.0513141043484211,
-0.022257709875702858,
0.0012604024959728122,
0.11914938688278198,
0.023095890879631042,
0.06573177129030228,
0.014278815127909184,
0.00958956591784954,
-0.0619148425757885,
0.0055302... | 0.079841 |
} 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 i... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
0.012021890841424465,
0.02679203823208809,
-0.06590640544891357,
0.0452774316072464,
0.06644701212644577,
-0.03495161980390549,
-0.027687793597579002,
0.10300444066524506,
-0.012779385782778263,
0.034766796976327896,
0.0027735005132853985,
-0.01981351152062416,
-0.08786813169717789,
-0.028... | 0.088179 |
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 ... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
-0.07614006847143173,
-0.06752225011587143,
-0.009139705449342728,
-0.028835194185376167,
0.060422878712415695,
-0.11912476271390915,
-0.031676363199949265,
0.11340480297803879,
0.04640744626522064,
0.06982076913118362,
-0.017830900847911835,
0.04543756693601608,
-0.04771227017045021,
-0.0... | 0.057461 |
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 i... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
-0.06839750707149506,
0.004731216933578253,
-0.039285968989133835,
0.04965359345078468,
0.02994632162153721,
-0.04612467437982559,
-0.00579317519441247,
0.09549770504236221,
0.026713812723755836,
0.01606820337474346,
0.005144783295691013,
-0.008881699293851852,
-0.06427153944969177,
0.0225... | 0.176419 |
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.06322126090526581,
0.014696191065013409,
-0.018464667722582817,
-0.012321790680289268,
0.08916132897138596,
-0.02558005042374134,
0.027132967486977577,
0.081197589635849,
0.04221176728606224,
0.047745827585458755,
-0.009152011945843697,
0.017616031691432,
-0.02625587210059166,
-0.006734... | 0.089641 |
`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', 'inhe... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
-0.0008249875972978771,
-0.0024143692571669817,
-0.0570911206305027,
0.010604704730212688,
-0.044363465160131454,
-0.08568679541349411,
0.06963055580854416,
0.10166937112808228,
-0.031029680743813515,
-0.014568889513611794,
0.004283837042748928,
-0.019386714324355125,
-0.03111664019525051,
... | 0.141027 |
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 de... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
-0.052859142422676086,
0.026645563542842865,
-0.0928945392370224,
-0.01347559504210949,
0.02407938987016678,
-0.01095886155962944,
-0.0017158238915726542,
0.12423854321241379,
0.04007590189576149,
-0.0005061944248154759,
-0.03727862611413002,
0.00046978684258647263,
-0.07247291505336761,
0... | 0.093361 |
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 e... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
-0.0016267813043668866,
0.010425697080790997,
-0.08458367735147476,
0.03192977234721184,
0.024204835295677185,
-0.013639348559081554,
-0.007805985398590565,
0.08177386969327927,
0.04593674838542938,
0.057125311344861984,
-0.041727617383003235,
0.007410714402794838,
-0.05031928792595863,
-0... | 0.063272 |
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 ... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
-0.019574960693717003,
-0.006065810099244118,
-0.1095120757818222,
0.04928169399499893,
-0.017620934173464775,
-0.03463159501552582,
-0.0016586104175075889,
0.08473112434148788,
0.07168138772249222,
0.016781438142061234,
-0.03157399594783783,
-0.031002433970570564,
-0.03697718679904938,
0.... | 0.111769 |
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 `SIG... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
-0.012358995154500008,
0.004543479066342115,
-0.05143892765045166,
-0.010817003436386585,
0.0326913446187973,
-0.06368301808834076,
0.020952586084604263,
0.12599879503250122,
0.018819516524672508,
0.06400486826896667,
0.014463229104876518,
-0.028477532789111137,
-0.04293248802423477,
-0.03... | 0.104993 |
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 ... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
-0.03252418339252472,
-0.005357102025300264,
-0.004638750106096268,
0.018853556364774704,
0.08267729729413986,
-0.029810326173901558,
-0.02147003263235092,
0.04618287459015846,
0.08325536549091339,
0.036112647503614426,
-0.02870137058198452,
0.007475023157894611,
-0.07726544141769409,
-0.0... | 0.117271 |
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` prope... | https://github.com/nodejs/node/blob/main/doc/api/child_process.md | main | nodejs | [
-0.052365049719810486,
-0.016962988302111626,
-0.030272815376520157,
0.02181192860007286,
0.03950026258826256,
-0.05859903618693352,
0.005428818985819817,
0.045412030071020126,
0.05388541519641876,
0.03455786406993866,
-0.07945466041564941,
0.015749245882034302,
-0.0793636366724968,
-0.043... | 0.074962 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.