| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 00c70e1 commit d61a505
27 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1984,8 +1984,12 @@ Emitted when code coverage is enabled and all tests have completed. | |||
| 1984 | 1984 | ### Event: `'test:dequeue'` | |
| 1985 | 1985 | ||
| 1986 | 1986 | * `data` {Object} | |
| 1987 | + * `column` {number|undefined} The column number where the test is defined, or | ||
| 1988 | + `undefined` if the test was run through the REPL. | ||
| 1987 | 1989 | * `file` {string|undefined} The path of the test file, | |
| 1988 | 1990 | `undefined` if test was run through the REPL. | |
| 1991 | + * `line` {number|undefined} The line number where the test is defined, or | ||
| 1992 | + `undefined` if the test was run through the REPL. | ||
| 1989 | 1993 | * `name` {string} The test name. | |
| 1990 | 1994 | * `nesting` {number} The nesting level of the test. | |
| 1991 | 1995 | ||
@@ -1994,8 +1998,12 @@ Emitted when a test is dequeued, right before it is executed. | |||
| 1994 | 1998 | ### Event: `'test:diagnostic'` | |
| 1995 | 1999 | ||
| 1996 | 2000 | * `data` {Object} | |
| 2001 | + * `column` {number|undefined} The column number where the test is defined, or | ||
| 2002 | + `undefined` if the test was run through the REPL. | ||
| 1997 | 2003 | * `file` {string|undefined} The path of the test file, | |
| 1998 | 2004 | `undefined` if test was run through the REPL. | |
| 2005 | + * `line` {number|undefined} The line number where the test is defined, or | ||
| 2006 | + `undefined` if the test was run through the REPL. | ||
| 1999 | 2007 | * `message` {string} The diagnostic message. | |
| 2000 | 2008 | * `nesting` {number} The nesting level of the test. | |
| 2001 | 2009 | ||
@@ -2004,8 +2012,12 @@ Emitted when [`context.diagnostic`][] is called. | |||
| 2004 | 2012 | ### Event: `'test:enqueue'` | |
| 2005 | 2013 | ||
| 2006 | 2014 | * `data` {Object} | |
| 2015 | + * `column` {number|undefined} The column number where the test is defined, or | ||
| 2016 | + `undefined` if the test was run through the REPL. | ||
| 2007 | 2017 | * `file` {string|undefined} The path of the test file, | |
| 2008 | 2018 | `undefined` if test was run through the REPL. | |
| 2019 | + * `line` {number|undefined} The line number where the test is defined, or | ||
| 2020 | + `undefined` if the test was run through the REPL. | ||
| 2009 | 2021 | * `name` {string} The test name. | |
| 2010 | 2022 | * `nesting` {number} The nesting level of the test. | |
| 2011 | 2023 | ||
@@ -2014,6 +2026,8 @@ Emitted when a test is enqueued for execution. | |||
| 2014 | 2026 | ### Event: `'test:fail'` | |
| 2015 | 2027 | ||
| 2016 | 2028 | * `data` {Object} | |
| 2029 | + * `column` {number|undefined} The column number where the test is defined, or | ||
| 2030 | + `undefined` if the test was run through the REPL. | ||
| 2017 | 2031 | * `details` {Object} Additional execution metadata. | |
| 2018 | 2032 | * `duration_ms` {number} The duration of the test in milliseconds. | |
| 2019 | 2033 | * `error` {Error} An error wrapping the error thrown by the test. | |
@@ -2022,6 +2036,8 @@ Emitted when a test is enqueued for execution. | |||
| 2022 | 2036 | this is a suite. | |
| 2023 | 2037 | * `file` {string|undefined} The path of the test file, | |
| 2024 | 2038 | `undefined` if test was run through the REPL. | |
| 2039 | + * `line` {number|undefined} The line number where the test is defined, or | ||
| 2040 | + `undefined` if the test was run through the REPL. | ||
| 2025 | 2041 | * `name` {string} The test name. | |
| 2026 | 2042 | * `nesting` {number} The nesting level of the test. | |
| 2027 | 2043 | * `testNumber` {number} The ordinal number of the test. | |
@@ -2033,12 +2049,16 @@ Emitted when a test fails. | |||
| 2033 | 2049 | ### Event: `'test:pass'` | |
| 2034 | 2050 | ||
| 2035 | 2051 | * `data` {Object} | |
| 2052 | + * `column` {number|undefined} The column number where the test is defined, or | ||
| 2053 | + `undefined` if the test was run through the REPL. | ||
| 2036 | 2054 | * `details` {Object} Additional execution metadata. | |
| 2037 | 2055 | * `duration_ms` {number} The duration of the test in milliseconds. | |
| 2038 | 2056 | * `type` {string|undefined} The type of the test, used to denote whether | |
| 2039 | 2057 | this is a suite. | |
| 2040 | 2058 | * `file` {string|undefined} The path of the test file, | |
| 2041 | 2059 | `undefined` if test was run through the REPL. | |
| 2060 | + * `line` {number|undefined} The line number where the test is defined, or | ||
| 2061 | + `undefined` if the test was run through the REPL. | ||
| 2042 | 2062 | * `name` {string} The test name. | |
| 2043 | 2063 | * `nesting` {number} The nesting level of the test. | |
| 2044 | 2064 | * `testNumber` {number} The ordinal number of the test. | |
@@ -2050,8 +2070,12 @@ Emitted when a test passes. | |||
| 2050 | 2070 | ### Event: `'test:plan'` | |
| 2051 | 2071 | ||
| 2052 | 2072 | * `data` {Object} | |
| 2073 | + * `column` {number|undefined} The column number where the test is defined, or | ||
| 2074 | + `undefined` if the test was run through the REPL. | ||
| 2053 | 2075 | * `file` {string|undefined} The path of the test file, | |
| 2054 | 2076 | `undefined` if test was run through the REPL. | |
| 2077 | + * `line` {number|undefined} The line number where the test is defined, or | ||
| 2078 | + `undefined` if the test was run through the REPL. | ||
| 2055 | 2079 | * `nesting` {number} The nesting level of the test. | |
| 2056 | 2080 | * `count` {number} The number of subtests that have ran. | |
| 2057 | 2081 | ||
@@ -2060,8 +2084,12 @@ Emitted when all subtests have completed for a given test. | |||
| 2060 | 2084 | ### Event: `'test:start'` | |
| 2061 | 2085 | ||
| 2062 | 2086 | * `data` {Object} | |
| 2087 | + * `column` {number|undefined} The column number where the test is defined, or | ||
| 2088 | + `undefined` if the test was run through the REPL. | ||
| 2063 | 2089 | * `file` {string|undefined} The path of the test file, | |
| 2064 | 2090 | `undefined` if test was run through the REPL. | |
| 2091 | + * `line` {number|undefined} The line number where the test is defined, or | ||
| 2092 | + `undefined` if the test was run through the REPL. | ||
| 2065 | 2093 | * `name` {string} The test name. | |
| 2066 | 2094 | * `nesting` {number} The nesting level of the test. | |
| 2067 | 2095 | ||
@@ -2072,7 +2100,11 @@ defined. | |||
| 2072 | 2100 | ### Event: `'test:stderr'` | |
| 2073 | 2101 | ||
| 2074 | 2102 | * `data` {Object} | |
| 2103 | + * `column` {number|undefined} The column number where the test is defined, or | ||
| 2104 | + `undefined` if the test was run through the REPL. | ||
| 2075 | 2105 | * `file` {string} The path of the test file. | |
| 2106 | + * `line` {number|undefined} The line number where the test is defined, or | ||
| 2107 | + `undefined` if the test was run through the REPL. | ||
| 2076 | 2108 | * `message` {string} The message written to `stderr`. | |
| 2077 | 2109 | ||
| 2078 | 2110 | Emitted when a running test writes to `stderr`. | |
@@ -2081,7 +2113,11 @@ This event is only emitted if `--test` flag is passed. | |||
| 2081 | 2113 | ### Event: `'test:stdout'` | |
| 2082 | 2114 | ||
| 2083 | 2115 | * `data` {Object} | |
| 2116 | + * `column` {number|undefined} The column number where the test is defined, or | ||
| 2117 | + `undefined` if the test was run through the REPL. | ||
| 2084 | 2118 | * `file` {string} The path of the test file. | |
| 2119 | + * `line` {number|undefined} The line number where the test is defined, or | ||
| 2120 | + `undefined` if the test was run through the REPL. | ||
| 2085 | 2121 | * `message` {string} The message written to `stdout`. | |
| 2086 | 2122 | ||
| 2087 | 2123 | Emitted when a running test writes to `stdout`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ const { | |||
| 5 | 5 | PromiseResolve, | |
| 6 | 6 | SafeMap, | |
| 7 | 7 | } = primordials; | |
| 8 | + const { getCallerLocation } = internalBinding('util'); | ||
| 8 | 9 | const { | |
| 9 | 10 | createHook, | |
| 10 | 11 | executionAsyncId, | |
@@ -215,17 +216,38 @@ function runInParentContext(Factory) { | |||
| 215 | 216 | return PromiseResolve(); | |
| 216 | 217 | } | |
| 217 | 218 | ||
| 218 | - const test = (name, options, fn) => run(name, options, fn); | ||
| 219 | + const test = (name, options, fn) => { | ||
| 220 | + const overrides = { | ||
| 221 | + __proto__: null, | ||
| 222 | + loc: getCallerLocation(), | ||
| 223 | + }; | ||
| 224 | + | ||
| 225 | + return run(name, options, fn, overrides); | ||
| 226 | + }; | ||
| 219 | 227 | ArrayPrototypeForEach(['skip', 'todo', 'only'], (keyword) => { | |
| 220 | - test[keyword] = (name, options, fn) => run(name, options, fn, { __proto__: null, [keyword]: true }); | ||
| 228 | + test[keyword] = (name, options, fn) => { | ||
| 229 | + const overrides = { | ||
| 230 | + __proto__: null, | ||
| 231 | + [keyword]: true, | ||
| 232 | + loc: getCallerLocation(), | ||
| 233 | + }; | ||
| 234 | + | ||
| 235 | + return run(name, options, fn, overrides); | ||
| 236 | + }; | ||
| 221 | 237 | }); | |
| 222 | 238 | return test; | |
| 223 | 239 | } | |
| 224 | 240 | ||
| 225 | 241 | function hook(hook) { | |
| 226 | 242 | return (fn, options) => { | |
| 227 | 243 | const parent = testResources.get(executionAsyncId()) || getGlobalRoot(); | |
| 228 | - parent.createHook(hook, fn, options); | ||
| 244 | + parent.createHook(hook, fn, { | ||
| 245 | + __proto__: null, | ||
| 246 | + ...options, | ||
| 247 | + parent, | ||
| 248 | + hookType: hook, | ||
| 249 | + loc: getCallerLocation(), | ||
| 250 | + }); | ||
| 229 | 251 | }; | |
| 230 | 252 | } | |
| 231 | 253 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ const { inspectWithNoCustomRetry } = require('internal/errors'); | |||
| 17 | 17 | const { green, blue, red, white, gray, shouldColorize } = require('internal/util/colors'); | |
| 18 | 18 | const { kSubtestsFailed } = require('internal/test_runner/test'); | |
| 19 | 19 | const { getCoverageReport } = require('internal/test_runner/utils'); | |
| 20 | + const { relative } = require('path'); | ||
| 20 | 21 | ||
| 21 | 22 | const inspectOptions = { __proto__: null, colors: shouldColorize(process.stdout), breakLength: Infinity }; | |
| 22 | 23 | ||
@@ -40,6 +41,7 @@ class SpecReporter extends Transform { | |||
| 40 | 41 | #reported = []; | |
| 41 | 42 | #indentMemo = new SafeMap(); | |
| 42 | 43 | #failedTests = []; | |
| 44 | + #cwd = process.cwd(); | ||
| 43 | 45 | ||
| 44 | 46 | constructor() { | |
| 45 | 47 | super({ __proto__: null, writableObjectMode: true }); | |
@@ -142,10 +144,12 @@ class SpecReporter extends Transform { | |||
| 142 | 144 | } | |
| 143 | 145 | const results = [`\n${colors['test:fail']}${symbols['test:fail']}failing tests:${white}\n`]; | |
| 144 | 146 | for (let i = 0; i < this.#failedTests.length; i++) { | |
| 145 | - ArrayPrototypePush(results, this.#formatTestReport( | ||
| 146 | - 'test:fail', | ||
| 147 | - this.#failedTests[i], | ||
| 148 | - )); | ||
| 147 | + const test = this.#failedTests[i]; | ||
| 148 | + const relPath = relative(this.#cwd, test.file); | ||
| 149 | + const formattedErr = this.#formatTestReport('test:fail', test); | ||
| 150 | + const location = `test at ${relPath}:${test.line}:${test.column}`; | ||
| 151 | + | ||
| 152 | + ArrayPrototypePush(results, location, formattedErr); | ||
| 149 | 153 | } | |
| 150 | 154 | callback(null, ArrayPrototypeJoin(results, '\n')); | |
| 151 | 155 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,13 +31,14 @@ async function * tapReporter(source) { | |||
| 31 | 31 | yield `TAP version ${kDefaultTAPVersion}\n`; | |
| 32 | 32 | for await (const { type, data } of source) { | |
| 33 | 33 | switch (type) { | |
| 34 | - case 'test:fail': | ||
| 34 | + case 'test:fail': { | ||
| 35 | 35 | yield reportTest(data.nesting, data.testNumber, 'not ok', data.name, data.skip, data.todo); | |
| 36 | - yield reportDetails(data.nesting, data.details); | ||
| 36 | + const location = `${data.file}:${data.line}:${data.column}`; | ||
| 37 | + yield reportDetails(data.nesting, data.details, location); | ||
| 37 | 38 | break; | |
| 38 | - case 'test:pass': | ||
| 39 | + } case 'test:pass': | ||
| 39 | 40 | yield reportTest(data.nesting, data.testNumber, 'ok', data.name, data.skip, data.todo); | |
| 40 | - yield reportDetails(data.nesting, data.details); | ||
| 41 | + yield reportDetails(data.nesting, data.details, null); | ||
| 41 | 42 | break; | |
| 42 | 43 | case 'test:plan': | |
| 43 | 44 | yield `${indent(data.nesting)}1..${data.count}\n`; | |
@@ -81,13 +82,18 @@ function reportTest(nesting, testNumber, status, name, skip, todo) { | |||
| 81 | 82 | return line; | |
| 82 | 83 | } | |
| 83 | 84 | ||
| 84 | - function reportDetails(nesting, data = kEmptyObject) { | ||
| 85 | + function reportDetails(nesting, data = kEmptyObject, location) { | ||
| 85 | 86 | const { error, duration_ms } = data; | |
| 86 | 87 | const _indent = indent(nesting); | |
| 87 | 88 | let details = `${_indent} ---\n`; | |
| 88 | 89 | ||
| 89 | 90 | details += jsToYaml(_indent, 'duration_ms', duration_ms); | |
| 90 | 91 | details += jsToYaml(_indent, 'type', data.type); | |
| 92 | + | ||
| 93 | + if (location) { | ||
| 94 | + details += jsToYaml(_indent, 'location', location); | ||
| 95 | + } | ||
| 96 | + | ||
| 91 | 97 | details += jsToYaml(_indent, null, error, new SafeSet()); | |
| 92 | 98 | details += `${_indent} ...\n`; | |
| 93 | 99 | return details; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments