forked from nodejs/undici
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(WPTRunner): parse
META
tags (nodejs#1664)
* feat(WPTRunner): parse `META` tags * feat: add more routes * feat: add /resources/data.json route * fix(fetch): throw AbortError DOMException on consume if aborted * fix(fetch): throw AbortError on `.formData()` after abort * feat: add expected failures & end log * fix: import DOMException for node 16 * feat: run each test in its own worker & simplify worker
- Loading branch information
Showing
15 changed files
with
1,044 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"key": "value"} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { exit } from 'node:process' | ||
|
||
/** | ||
* Parse the `Meta:` tags sometimes included in tests. | ||
* These can include resources to inject, how long it should | ||
* take to timeout, and which globals to expose. | ||
* @example | ||
* // META: timeout=long | ||
* // META: global=window,worker | ||
* // META: script=/common/utils.js | ||
* // META: script=/common/get-host-info.sub.js | ||
* // META: script=../request/request-error.js | ||
* @see https://nodejs.org/api/readline.html#readline_example_read_file_stream_line_by_line | ||
* @param {string} fileContents | ||
*/ | ||
export function parseMeta (fileContents) { | ||
const lines = fileContents.split(/\r?\n/g) | ||
|
||
const meta = { | ||
/** @type {string|null} */ | ||
timeout: null, | ||
/** @type {string[]} */ | ||
global: [], | ||
/** @type {string[]} */ | ||
scripts: [] | ||
} | ||
|
||
for (const line of lines) { | ||
if (!line.startsWith('// META: ')) { | ||
break | ||
} | ||
|
||
const groups = /^\/\/ META: (?<type>.*?)=(?<match>.*)$/.exec(line)?.groups | ||
|
||
if (!groups) { | ||
console.log(`Failed to parse META tag: ${line}`) | ||
exit(1) | ||
} | ||
|
||
switch (groups.type) { | ||
case 'timeout': { | ||
meta.timeout = groups.match | ||
break | ||
} | ||
case 'global': { | ||
// window,worker -> ['window', 'worker'] | ||
meta.global.push(...groups.match.split(',')) | ||
break | ||
} | ||
case 'script': { | ||
// A relative or absolute file path to the resources | ||
// needed for the current test. | ||
meta.scripts.push(groups.match) | ||
break | ||
} | ||
default: { | ||
console.log(`Unknown META tag: ${groups.type}`) | ||
exit(1) | ||
} | ||
} | ||
} | ||
|
||
return meta | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.