MCPcopy Index your code
hub / github.com/nodejs/node / parseTestMetadata

Function parseTestMetadata

test/common/index.js:92–129  ·  view source on GitHub ↗

* Parse test metadata from the specified file. * @param {string} filename - The name of the file to parse. * @returns {{ * flags: string[], * envs: Record * }} An object containing the parsed flags and environment variables.

(filename = process.argv[1])

Source from the content-addressed store, hash-verified

90 * }} An object containing the parsed flags and environment variables.
91 */
92function parseTestMetadata(filename = process.argv[1]) {
93 // The copyright notice is relatively big and the metadata could come afterwards.
94 const bytesToRead = 1500;
95 const buffer = Buffer.allocUnsafe(bytesToRead);
96 const fd = fs.openSync(filename, 'r');
97 const bytesRead = fs.readSync(fd, buffer, 0, bytesToRead);
98 fs.closeSync(fd);
99 const source = buffer.toString('utf8', 0, bytesRead);
100
101 const flagStart = source.search(/\/\/ Flags:\s+--/) + 10;
102 let flags = [];
103 if (flagStart !== 9) {
104 let flagEnd = source.indexOf('\n', flagStart);
105 if (source[flagEnd - 1] === '\r') {
106 flagEnd--;
107 }
108 flags = source
109 .substring(flagStart, flagEnd)
110 .split(/\s+/)
111 .filter(Boolean);
112 }
113
114 const envStart = source.search(/\/\/ Env:\s+/) + 8;
115 let envs = {};
116 if (envStart !== 7) {
117 let envEnd = source.indexOf('\n', envStart);
118 if (source[envEnd - 1] === '\r') {
119 envEnd--;
120 }
121 const envArray = source
122 .substring(envStart, envEnd)
123 .split(/\s+/)
124 .filter(Boolean);
125 envs = Object.fromEntries(envArray.map((env) => env.split('=')));
126 }
127
128 return { flags, envs };
129}
130
131// Check for flags. Skip this for workers (both, the `cluster` module and
132// `worker_threads`) and child processes.

Callers 1

index.jsFile · 0.85

Calls 9

filterMethod · 0.65
mapMethod · 0.65
openSyncMethod · 0.45
readSyncMethod · 0.45
closeSyncMethod · 0.45
toStringMethod · 0.45
searchMethod · 0.45
indexOfMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…