-
- Description and source-code:
async function assertErrorThrownAsync(asyncFunc, regexp) {
let err;
try {
await asyncFunc();
} catch (errCaught) {
err = errCaught;
}
assertOrThrow(err, "no error thrown");
assertOrThrow(
regexp === undefined || new RegExp(regexp).test(err.message),
err
);
}
- Example usage:
...
jstestDescribe((
"test v8CoverageReportCreate's handling-behavior"
), function () {
jstestIt((
"test null-case handling-behavior"
), async function () {
await assertErrorThrownAsync(function () {
return v8CoverageReportCreate({});
}, "invalid coverageDir");
});
// CL-xxx - coverage - Relax requirement for coverageDir to be in cwd.
// jstestIt((
// "test invalid-coverageDir handling-behavior"
...
-
- Description and source-code:
function assertJsonEqual(aa, bb) {
aa = JSON.stringify(objectDeepCopyWithKeysSorted(aa));
bb = JSON.stringify(objectDeepCopyWithKeysSorted(bb));
if (aa !== bb) {
throw new Error(
JSON.stringify(aa) + " !== " + JSON.stringify(bb)
);
}
}
- Example usage:
...
// Debug data1.
// await moduleFs.promises.writeFile(
// ".test_v8_coverage_node_sqlite_merged.json",
// JSON.stringify(objectDeepCopyWithKeysSorted(data1), undefined, 4) + "\n"
// );
assertJsonEqual(data1, data2);
});
});
jstestDescribe((
"test v8CoverageReportCreate's handling-behavior"
), function () {
jstestIt((
...
-
- Description and source-code:
function assertOrThrow(condition, message) {
if (!condition) {
throw (
(!message || typeof message === "string")
? new Error(String(message).slice(0, 2048))
: message
);
}
}
- Example usage:
...
});
// test assertJsonEqual's error handling-behavior
await assertErrorThrownAsync(function () {
assertJsonEqual(1, 2);
});
// test assertOrThrow's error handling-behavior
await assertErrorThrownAsync(function () {
assertOrThrow(undefined, "undefined");
});
await assertErrorThrownAsync(function () {
assertOrThrow(undefined, new Error());
});
}());
(async function () {
...
-
- Description and source-code:
function (...argv) {
consoleError("\n\ndebugInline");
consoleError(...argv);
consoleError("\n");
consoleError = console.error;
return argv[0];
}
- Example usage:
...
jslint_cli({
cjs_module,
cjs_require
});
}());
// Coverage-hack.
debugInline();
...
-
- Description and source-code:
async function fsRmRecursive(path, option_dict) {
await moduleFsInit();
console.error("rm -r path " + path);
if (((
option_dict && option_dict.process_version
) || process.version) < "v14") {
// Legacy rmdir for nodejs v12
await Promise.all([
moduleFs.promises.unlink(path).catch(noop),
moduleFs.promises.rmdir(path, {
recursive: true
}).catch(noop)
]);
return;
}
await moduleFs.promises.rm(path, {
recursive: true
}).catch(noop);
}
- Example usage:
...
}
(function testCaseFsXxx() {
/*
* this function will test fsXxx's handling-behavior
*/
// test fsRmRecursive handling-behavior
fsRmRecursive(".artifact/fsRmRecursive");
fsRmRecursive(".artifact/fsRmRecursive", {
process_version: "v12"
});
// test fsWriteFileWithParents handling-behavior
(async function () {
await fsRmRecursive(".tmp/fsWriteFileWithParents");
await fsWriteFileWithParents(
...
-
- Description and source-code:
async function fsWriteFileWithParents(pathname, data) {
await moduleFsInit();
// Try writing to pathname.
try {
await moduleFs.promises.writeFile(pathname, data);
} catch (ignore) {
// Lazy mkdirp.
await moduleFs.promises.mkdir(modulePath.dirname(pathname), {
recursive: true
});
// Retry writing to pathname.
await moduleFs.promises.writeFile(pathname, data);
}
console.error("wrote file " + pathname);
}
- Example usage:
...
]
].forEach(function ([
file, data
], ii) {
jstestIt(file, async function () {
let dir = ".tmp/coverage" + ii + "/";
file = dir + file;
await fsWriteFileWithParents(file, data);
await jslint.jslint_cli({
mode_cli: true,
processArgv: [
"node", "jslint.mjs",
"v8_coverage_report=" + dir,
"node",
file
...
-
- Description and source-code:
function htmlEscape(str) {
return String(str).replace((
/&/g
), "&").replace((
/</g
), "<").replace((
/>/g
), ">");
}
- Example usage:
...
});
chunk = "";
line.forEach(function ({
char,
isHole
}) {
if (inHole !== isHole) {
lineHtml += htmlEscape(chunk);
lineHtml += (
isHole
? "</span><span class=\"uncovered\">"
: "</span><span>"
);
chunk = "";
inHole = isHole;
...
-
- Description and source-code:
function jslint(
source = "", // A text to analyze.
option_dict = empty(), // An object whose keys correspond to option
// ... names.
global_list = [] // An array of strings containing global
// ... variables that the file is allowed
// ... readonly access.
) {
let catch_list = []; // The array containing all catch-blocks.
let catch_stack = [ // The stack of catch-blocks.
{
context: empty()
}
];
let cause_dict = empty(); // The object of test-causes.
let directive_list = []; // The directive comments.
let export_dict = empty(); // The exported names and values.
let function_list = []; // The array containing all functions.
let function_stack = []; // The stack of functions.
let global_dict = empty(); // The object containing the global
// ... declarations.
let import_list = []; // The array collecting all import-from strings.
let line_list = String( // The array containing source lines.
"\n" + source
).split(
// rx_crlf
/\n|\r\n?/
).map(function (line_source) {
return {
line_source
};
});
let mode_stop = false; // true if JSLint cannot finish.
let property_dict = empty(); // The object containing the tallied
// ... property names.
let state = empty(); // jslint state-object to be passed between
// jslint functions.
let syntax_dict = empty(); // The object containing the parser.
let tenure = empty(); // The predefined property registry.
let token_global = { // The global object; the outermost context.
async: 0,
body: true,
context: empty(),
f...
}
- Example usage:
...
}).join(", ")
+ "]"
);
}).sort().join("\n");
assertOrThrow(causeList === tmp, "\n" + causeList + "\n\n" + tmp);
causeList.split("\n").forEach(function (cause) {
cause = JSON.parse(cause);
tmp = jslint.jslint(cause[0], {
beta: true,
test_cause: true
}).causes;
// Validate cause.
assertOrThrow(
tmp[JSON.stringify(cause.slice(1))],
(
...
-
- Description and source-code:
async function jslint_apidoc({
example_list,
github_repo,
module_list,
package_name,
pathname,
version
}) {
let elem_ii = 0;
let html;
function elem_create(moduleObj, key, moduleName) {
// This function will create a sub API Doc from elem <moduleObj>[<key>].
let example = "N/A";
let id = encodeURIComponent("apidoc.elem." + moduleName + "." + key);
let name;
let signature;
let source;
name = htmlEscape((typeof moduleObj[key]) + " " + key);
if (typeof moduleObj[key] !== "function") {
return {
name,
signature: (`
<a class="apidocElementLiA" href="#${id}">
${name}
</a>
`),
source: (`
<li>
<h2>
<a href="#${id}" id="${id}">
${name}
</a>
</h2>
</li>
`)
};
}
// init source
source = htmlEscape(trim_start(moduleObj[key].toString()));
// init signature
source = source.replace((
/(\([\S\s]*?\)) \{/
), function (match0, match1) {
signature = htmlEscape(
match1.replace((
/ *?\/\*[\S\s]*?\*\/ */g
), "").replace((
/ *?\/\/.*/g
), "").replace((
/\n{2,}/g
), "\n")
);
return match0;
});
// init comment
source = source.replace((
/\n(?:\/\/.*?\n)+\n/
), "<span class=\"apidocCodeCommentSpan\">$&</span>");
// init example
example_list.some(function (example2) {
example2.replace(
new RegExp((
"((?:\\n.*?){8}(function )?)\\b"
+ key
+ "(\\((?:.*?\\n){8})"
), "g"),
...
}
- Example usage:
...
command[1] = command.slice(1).join("=");
switch (command[0]) {
// PR-362 - Add API Doc.
case "jslint_apidoc":
await jslint_apidoc(Object.assign(JSON.parse(processArgv[3]), {
pathname: command[1]
}));
return;
// COMMIT-b26d6df2 - Add command jslint_plugin_vim.
case "jslint_plugin_vim":
...
-
- Description and source-code:
function jslint_assert(condition, message) {
if (condition) {
return condition;
}
throw new Error(
`This was caused by a bug in JSLint.
Please open an issue with this stack-trace (and possible example-code) at
https://github.com/jslint-org/jslint/issues.
edition = "${jslint_edition}";
${String(message).slice(0, 2000)}`
);
}
- Example usage:
...
// ["let aa={};", "whitage", "opener", "", 0]
test_cause("opener");
// Probably deadcode.
// case "${}":
jslint_assert(
!(left.id + right.id === "${}"),
"Expected !(left.id + right.id === \"${}\")."
);
switch (left.id + right.id) {
case "()":
case "[]":
case "{}":
...
-
- Description and source-code:
async function jslint_cli({
cjs_module,
cjs_require,
console_error,
console_log,
file,
mode_cli,
mode_noop,
option,
processArgv,
processEnv,
process_exit,
source
}) {
let command;
let data;
let exit_code = 0;
let mode_plugin_vim;
let mode_report;
let result;
function jslint_from_file({
code,
file,
line_offset = 0,
option = empty()
}) {
let result_from_file;
option = Object.assign(empty(), option, {
file
});
switch ((
/\.\w+?$|$/m
).exec(file)[0]) {
case ".html":
// Recursively jslint embedded "<script>\n...\n</script>".
code.replace((
/^<script\b[^>]*?>\n([\S\s]*?\n)<\/script>$/gm
), function (ignore, match1, ii) {
jslint_from_file({
code: match1,
file: file + ".<script>.js",
line_offset: string_line_count(code.slice(0, ii)) + 1,
option: Object.assign(empty(), {
browser: true
}, option)
});
return "";
});
return;
case ".sh":
// Recursively jslint embedded "node -e '\n...\n'".
code.replace((
/\bnode\b.*? -e '\n([\S\s]*?\n)'/gm
), function (ignore, match1, ii) {
jslint_from_file({
code: match1,
file: file + ".<node -e>.js",
line_offset: string_line_count(code.slice(0, ii)) + 1,
option: Object.assign(empty(), {
beta: Boolean(
processEnv.JSLINT_BETA
&& !(
/0|false|null|undefined/
)....
}
- Example usage:
...
].forEach(function ([
file, data
], ii) {
jstestIt(file, async function () {
let dir = ".tmp/coverage" + ii + "/";
file = dir + file;
await fsWriteFileWithParents(file, data);
await jslint.jslint_cli({
mode_cli: true,
processArgv: [
"node", "jslint.mjs",
"v8_coverage_report=" + dir,
"node",
file
]
...
-
- Description and source-code:
function jslint_phase1_split() {
return;
}
- Example usage:
...
warn,
warn_at,
warning_list
});
// PHASE 1. Split <source> by newlines into <line_list>.
jslint_phase1_split(state);
jslint_assert(catch_stack.length === 1, `catch_stack.length === 1.`);
jslint_assert(
function_stack.length === 0,
`function_stack.length === 0.`
);
// PHASE 2. Lex <line_list> into <token_list>.
...
-
- Description and source-code:
function jslint_phase2_lex(state) {
let {
artifact,
directive_list,
global_dict,
global_list,
line_list,
option_dict,
stop,
stop_at,
tenure,
test_cause,
token_global,
token_list,
warn,
warn_at
} = state;
let char; // The current character being lexed.
let column = 0; // The column number of the next character.
let from; // The starting column number of the token.
let from_mega; // The starting column of megastring.
let line = 0; // The line number of the next character.
let line_disable; // The starting line of "/*jslint-disable*/".
let line_mega; // The starting line of megastring.
let line_source = ""; // The remaining line source string.
let line_whole = ""; // The whole line source string.
let mode_directive = true; // true if directives are still allowed.
let mode_mega = false; // true if currently parsing a megastring
// ... literal.
let mode_regexp; // true if regular expression literal seen on
// ... this line.
let rx_token = new RegExp(
"^("
+ "(\\s+)"
+ "|([a-zA-Z_$][a-zA-Z0-9_$]*)"
+ "|[(){}\\[\\],:;'\"~\\`]"
+ "|\\?[?.]?"
+ "|=(?:==?|>)?"
+ "|\\.+"
+ "|\\*[*\\/=]?"
+ "|\\/[*\\/]?"
+ "|\\+[=+]?"
+ "|-[=\\-]?"
+ "|[\\^%]=?"
+ "|&[&=]?"
+ "|\\"
+ "|[|=]?"
+ "|>{1,3}=?"
+ "|<<?=?"
+ "|!(?:!|==?)?"
// PR-351 - Add BigInt support.
+ "|(0n?|[1-9][0-9]*n?)"
+ ")"
+ "(.*)$"
);
let snippet = ""; // A piece of string.
let token_1; ...
}
- Example usage:
...
jslint_assert(
function_stack.length === 0,
`function_stack.length === 0.`
);
// PHASE 2. Lex <line_list> into <token_list>.
jslint_phase2_lex(state);
jslint_assert(catch_stack.length === 1, `catch_stack.length === 1.`);
jslint_assert(
function_stack.length === 0,
`function_stack.length === 0.`
);
// PHASE 3. Parse <token_list> into <token_tree> using the Pratt-parser.
...
-
- Description and source-code:
function jslint_phase3_parse(state) {
// Parsing:
// Parsing weaves the tokens into an abstract syntax tree. During that process,
// a token may be given any of these properties:
// arity string
// label identifier
// name identifier
// expression expressions
// block statements
// else statements (else, default, catch)
// Specialized tokens may have additional properties.
let anon = "anonymous"; // The guessed name for anonymous functions.
let {
artifact,
catch_list,
catch_stack,
export_dict,
function_list,
function_stack,
global_dict,
import_list,
is_equal,
option_dict,
property_dict,
stop,
syntax_dict,
tenure,
test_cause,
token_global,
token_list,
warn,
warn_at
} = state;
let catchage = catch_stack[0]; // The current catch-block.
let functionage = token_global; // The current function.
let mode_var; // "var" if using var; "let" if using let.
let rx_identifier = (
/^([a-zA-Z_$][a-zA-Z0-9_$]*)$/
);
let token_ii = 0; // The number of the next token.
let token_now = token_global; // The current token being examined in
// ... the parse.
let token_nxt = token_global; // The next token to be examined in
// ... <token_list>.
function advance(id, match) {
// Produce the next token.
// Attempt to give helpful names to anonymous functions.
if (token_now.identifier && token_now.id !== "function") {
anon = token_now.id;
} else if (
token_now.id === "(string)"
&& rx_identifier.test(token_now.value)
) {
a...
}
- Example usage:
...
jslint_assert(
function_stack.length === 0,
`function_stack.length === 0.`
);
// PHASE 3. Parse <token_list> into <token_tree> using the Pratt-parser.
jslint_phase3_parse(state);
jslint_assert(catch_stack.length === 1, `catch_stack.length === 1.`);
jslint_assert(
function_stack.length === 0,
`function_stack.length === 0.`
);
// PHASE 4. Walk <token_tree>, traversing all nodes of the tree. It is a
...
-
- Description and source-code:
function jslint_phase4_walk(state) {
let {
artifact,
catch_stack,
function_stack,
global_dict,
is_equal,
is_weird,
option_dict,
syntax_dict,
test_cause,
token_global,
warn
} = state;
let block_stack = []; // The stack of blocks.
let blockage = token_global; // The current block.
let catchage = catch_stack[0]; // The current catch-block.
let functionage = token_global; // The current function.
let postaction;
let postamble;
let posts = empty();
let preaction;
let preamble;
let pres = empty();
// The relational operators.
let relationop = object_assign_from_list(empty(), [
"!=", "!==", "<", "<=", "==", "===", ">", ">="
], true);
// Ambulation of the parse tree.
function action(when) {
// Produce a function that will register task functions that will be called as
// the tree is traversed.
return function (arity, id, task) {
let a_set = when[arity];
let i_set;
// The id parameter is optional. If excluded, the task will be applied to all
// ids.
if (typeof id !== "string") {
task = id;
id = "(all)";
}
// If this arity has no registrations yet, then create a set object to hold
// them.
if (a_set === undefined) {
a_set = empty();
when[arity] = a_set;
}
// If this id has no registrations yet, then create a set array to hold them.
i_set = a_set[id];
if (i_set === undefined) {
i_set = [];
a_set[id] = i_set;
}
// Register the task with the arity and the id.
...
}
- Example usage:
...
);
// PHASE 4. Walk <token_tree>, traversing all nodes of the tree. It is a
// recursive traversal. Each node may be processed on the way down
// (preaction) and on the way up (postaction).
if (!state.mode_json) {
jslint_phase4_walk(state);
}
jslint_assert(catch_stack.length === 1, `catch_stack.length === 1.`);
jslint_assert(
function_stack.length === 0,
`function_stack.length === 0.`
);
...
-
- Description and source-code:
function jslint_phase5_whitage(state) {
let {
artifact,
catch_list,
function_list,
function_stack,
option_dict,
test_cause,
token_global,
token_list,
warn
} = state;
let closer = "(end)";
let free = false;
// free = false
// cause:
// "()=>0"
// "aa()"
// "aa(0,0)"
// "function(){}"
// free = true
// cause:
// "(0)"
// "(aa)"
// "aa(0)"
// "do{}while()"
// "for(){}"
// "if(){}"
// "switch(){}"
// "while(){}"
let left = token_global;
let margin = 0;
let mode_indent = (
// PR-330 - Allow 2-space indent.
option_dict.indent2
? 2
: 4
);
let nr_comments_skipped = 0;
let open = true;
let opening = true;
let right;
// This is the set of infix operators that require a space on each side.
let spaceop = object_assign_from_list(empty(), [
"!=", "!==", "%", "%=", "&", "&&", "&=", "*", "*=", "+=", "-=", "/",
"/=", "<", "<<", "<<=", "<=", "=", "==", "===", "=>", ">", ">=", ">>",
">>=", ">>>", ">>>=", "^", "^=", "|", "|=", "||"
], true);
function at_margin(fit) {
const at = margin + fit;
if (right.from !== at) {
return expected_at(at);
}
}
function delve(the_function) {
Object.keys(the_function.context).forEach(function (id) {
const name = the_function.context[id];
if (id !== "ignore" && name.parent === the_function) {
// test_cause:
// ["function aa(aa) {return aa;}", "delve", "id", "", 0]
test_cause("id");
if (
name.used === 0
// Probably deadcode.
// && (
// name.role !== "function"
// || name.parent.arity !== "unary"
// )
&& jslint_assert(
name.role...
}
- Example usage:
...
function_stack.length === 0,
`function_stack.length === 0.`
);
// PHASE 5. Check whitespace between tokens in <token_list>.
if (!state.mode_json && warning_list.length === 0) {
jslint_phase5_whitage(state);
}
jslint_assert(catch_stack.length === 1, `catch_stack.length === 1.`);
jslint_assert(
function_stack.length === 0,
`function_stack.length === 0.`
);
...
-
- Description and source-code:
function jslint_report({
exports,
froms,
functions,
global,
json,
module,
property,
stop,
warnings
}) {
let html = "";
let length_80 = 1111;
function detail(title, list) {
return (
(Array.isArray(list) && list.length > 0)
? (
// Google Lighthouse Accessibility - <dl>'s do not contain only properly-ordered
// <dt> and <dd> groups, <script>, <template> or <div> elements.
"<dl>"
+ "<dt>" + htmlEscape(title) + "</dt>"
+ "<dd>" + list.join(", ") + "</dd>"
+ "</dl>"
)
: ""
);
}
html += "<div class=\"JSLINT_\" id=\"JSLINT_REPORT_HTML\">\n";
html += String(`
<style class="JSLINT_REPORT_STYLE">
/* jslint utility2:true */
/*csslint box-model: false, ids:false */
/*csslint ignore:start*/
@font-face {
font-display: swap;
font-family: "Daley";
src: url(
"data:font/woff2;base64,d09GMgABAAAAABy4AA4AAAAAThwAABxiAAEAAAAAAAAAAAAA\
AAAAAAAAAAAAAAAABmAAgiQINAmcDBEICuc41DEBNgIkA4R2C4I+AAQgBYkuByAMgScfYUIF\
7NgjsHGAbcDVFkXZ5Jwd+P96IGPc9rl9ETBEaCzCJkvY2UpziRZ7zftZWk8052U9+NqX6vXL\
KDflSQnlJ0bP+QnPQAy744n9mup6H9PaCDFwM5zjf8exB89bZ1cdrYOP0NgnuRDRWlk9u/fE\
llkxqmfH8lmRQ/DAmER9opk9wR6suc1LvTiXNEe1vbhUCH2USgnEwH3vUm05JQqejGvZvOtz\
7sIKEGgLdDNl/IrfqWVZG/wr42ekomEm91VA1p4LhHBuFzHF8//u7vvbREHMQqGtNLmiOOD/\
X7WWiwqyCE98qt0jk5JJmgR5WJJElBmzRb1F7a66MmSLTNWZ2XSHfKBSKHoVteSEJ6EOdvVw\
fNZOtXKDe39jXdRlkmMnOWIOFBgeEK/b0mFsgffnPyyAitNyutKky7J8a8MSEkAKGLgfptnS\
/gDRSo7vwdNUmQDB7oP6pK7QF5d9SrY8M/tkrXcurSIQAmX7tz7pd33LIB7GQkBQ/k81s/0D\
gpt4gbw7x0Cn/PocitK5KIGPGQIzQzAMuCeC2ERAidx9TySVq...
}
- Example usage:
...
warnings
}) {
// This function will create human-readable, html-report
// for warnings, properties, and functions from jslint-result-object.
// Example usage:
// let result = jslint("console.log('hello world')");
// let html = jslint_report(result);
let html = "";
let length_80 = 1111;
function detail(title, list) {
return (
(Array.isArray(list) && list.length > 0)
...
-
- Description and source-code:
async function jstestDescribe(description, testFunction) {
let message;
let result;
// Init jstestTimeStart.
if (jstestTimeStart === undefined) {
jstestTimeStart = jstestTimeStart || Date.now();
process.on("exit", jstestOnExit);
}
// Init jstestItList.
jstestItList = [];
testFunction();
// Wait for jstestItList to resolve.
result = await Promise.all(jstestItList);
// Print test results.
message = (
"\n " + (Date.now() - jstestTimeStart) + "ms"
+ " - test describe - " + description + "\n"
+ result.map(function ([
err, description, mode
]) {
jstestItCount += 1;
if (err) {
jstestCountFailed += 1;
err = (
" \u001b[31m\u2718 " + jstestItCount + ". test it - "
+ description + "\n" + err.stack + "\u001b[39m"
);
if (mode === "pass") {
jstestCountFailed -= 1;
err = "";
}
}
return err || (
" \u001b[32m\u2714 " + jstestItCount + ". test it - "
+ description + "\u001b[39m"
);
}).join("\n")
);
console.error(message);
}
- Example usage:
...
// JSON.stringify(objectDeepCopyWithKeysSorted(data1), undefined, 4) + "\n"
// );
assertJsonEqual(data1, data2);
});
});
jstestDescribe((
"test v8CoverageReportCreate's handling-behavior"
), function () {
jstestIt((
"test null-case handling-behavior"
), async function () {
await assertErrorThrownAsync(function () {
return v8CoverageReportCreate({});
...
-
- Description and source-code:
function jstestIt(description, testFunction, mode) {
jstestCountTotal += 1;
jstestItList.push(new Promise(async function (resolve) {
let err;
try {
await testFunction();
} catch (errCaught) {
err = errCaught;
}
resolve([
err, description, mode
]);
}));
}
- Example usage:
...
+ "case 2:break;\n"
+ "}\n"
)
]
].forEach(function ([
file, data
], ii) {
jstestIt(file, async function () {
let dir = ".tmp/coverage" + ii + "/";
file = dir + file;
await fsWriteFileWithParents(file, data);
await jslint.jslint_cli({
mode_cli: true,
processArgv: [
"node", "jslint.mjs",
...
-
- Description and source-code:
function jstestOnExit(exitCode, processExit, countFailed) {
let message = (
(
(jstestCountFailed || countFailed)
? "\n\u001b[31m"
: "\n\u001b[32m"
)
+ " tests total - " + jstestCountTotal + "\n"
+ " tests failed - " + jstestCountFailed + "\n"
+ "\u001b[39m"
);
if (!processExit) {
console.error(message);
processExit = process.exit;
}
processExit(exitCode || jstestCountFailed);
return message;
}
- Example usage:
...
"test jstestDescribe's error handling-behavior"
), function () {
throw new Error();
}, "pass");
jstestIt((
"test jstestOnExit's error handling-behavior"
), function () {
jstestOnExit(undefined, noop, 1);
});
});
jstestDescribe((
"test v8CoverageListMerge's handling-behavior"
), function () {
let functionsExpected = JSON.stringify([
...
-
- Description and source-code:
async function moduleFsInit() {
// State 3 - Modules already imported.
if (moduleFs !== undefined) {
return;
}
// State 2 - Wait while modules are importing.
if (moduleFsInitResolveList !== undefined) {
return new Promise(function (resolve) {
moduleFsInitResolveList.push(resolve);
});
}
// State 1 - Start importing modules.
moduleFsInitResolveList = [];
[
moduleChildProcess,
moduleFs,
modulePath,
moduleUrl
] = await Promise.all([
import("child_process"),
import("fs"),
import("path"),
import("url")
]);
while (moduleFsInitResolveList.length > 0) {
moduleFsInitResolveList.shift()();
}
}
- Example usage:
...
return pathname;
}
/*
function sentinel() {}
*/
await moduleFsInit();
consoleError = consoleError || console.error;
cwd = process.cwd().replace((
/\\/g
), "/") + "/";
// Init coverageDir.
// Assert coverageDir is subdirectory of cwd.
...
-
- Description and source-code:
function noop(val) {
return val;
}
- Example usage:
...
}());
(async function testCaseMisc() {
/*
* this function will test misc handling-behavior
*/
// test debugInline's handling-behavior
noop(debugInline);
// test assertErrorThrownAsync's error handling-behavior
await assertErrorThrownAsync(function () {
return assertErrorThrownAsync(noop);
});
// test assertJsonEqual's error handling-behavior
await assertErrorThrownAsync(function () {
assertJsonEqual(1, 2);
...
-
- Description and source-code:
function v8CoverageListMerge(processCovs) {
let resultMerged = []; // List of merged scripts from processCovs.
let urlToScriptDict = new Map(); // Map scriptCov.url to scriptCovs.
function compareRangeList(aa, bb) {
// Compares two range coverages.
// The ranges are first ordered by ascending `startOffset` and then by
// descending `endOffset`.
// This corresponds to a pre-order tree traversal.
if (aa.startOffset !== bb.startOffset) {
return aa.startOffset - bb.startOffset;
}
return bb.endOffset - aa.endOffset;
}
function dictKeyValueAppend(dict, key, val) {
// This function will append <val> to list <dict>[<key>].
let list = dict.get(key);
if (list === undefined) {
list = [];
dict.set(key, list);
}
list.push(val);
}
function mergeTreeList(parentTrees) {
// This function will return RangeTree object with <parentTrees> merged into
// property-children.
// @precondition Same `start` and `end` for all the parentTrees
if (parentTrees.length <= 1) {
return parentTrees[0];
}
// new RangeTree().
return {
// Merge parentTrees into property-children.
children: mergeTreeListToChildren(parentTrees),
delta: parentTrees.reduce(function (aa, bb) {
return aa + bb.delta;
}, 0),
end: parentTrees[0].end,
start: parentTrees[0].start
...
}
- Example usage:
...
"test_v8_coverage_node_sqlite_13216_1633662333140_0.json"
].map(function (file) {
return testCoverageMergeData[file];
});
let data2 = testCoverageMergeData[
"test_v8_coverage_node_sqlite_merged.json"
];
data1 = v8CoverageListMerge(data1);
data1 = v8CoverageListMerge([data1]);
// Debug data1.
// await moduleFs.promises.writeFile(
// ".test_v8_coverage_node_sqlite_merged.json",
// JSON.stringify(objectDeepCopyWithKeysSorted(data1), undefined, 4) + "\n"
// );
...
-
- Description and source-code:
async function v8CoverageReportCreate({
consoleError,
coverageDir,
processArgv = []
}) {
let cwd;
let exitCode = 0;
let fileDict;
let promiseList = [];
let v8CoverageObj;
function htmlRender({
fileList,
lineList,
modeIndex,
pathname
}) {
let html;
let padLines;
let padPathname;
let txt;
let txtBorder;
html = "";
html += String(`
<!DOCTYPE html>
<html lang="en">
<head>
<title>V8 Coverage Report</title>
<style>
/* jslint utility2:true */
/*csslint ignore:start*/
* {
box-sizing: border-box;
font-family: consolas, menlo, monospace;
}
/*csslint ignore:end*/
body {
margin: 0;
}
.coverage pre {
margin: 5px 0;
}
.coverage table {
border-collapse: collapse;
}
.coverage td,
.coverage th {
border: 1px solid #777;
margin: 0;
padding: 5px;
}
.coverage td span {
display: inline-block;
width: 100%;
}
.coverage .content {
padding: 0 5px;
}
.coverage .content a {
text-decoration: none;
}
.coverage .count {
margin: 0 5px;
padding: 0 5px;
}
.coverage .footer,
.coverage .header {
padding: 20px;
}
.coverage .footer {
text-align: center;
}
.coverage .percentbar {
height: 12px;
margin: 2px 0;
min-width: 200px;
position: relative;
width: 100%;
}
.coverage .percentbar div {
height: 100%;
position: absolute;
}
.coverage .title {
font-size: large;
font-weight: bold;
margin-bottom: 10px;
}
.coverage td,
.coverage th {
background: #fff;
}
.coverage .count {
background: #9d9;
color: #777;
}
.coverage .coverageHigh{
background: #...
}
- Example usage:
...
/*jslint node*/
import v8_coverage_report from "v8-coverage-report";
(async function () {
// Create V8 coverage report from program `npm run test` in javascript.
await v8_coverage_report.v8CoverageReportCreate({
coverageDir: "../.artifact/coverage_sqlite3_js/",
processArgv: ["npm", "run", "test"]
});
}());
'
```
...
-
-