Skip to content

Commit 2cfde23

Browse files
MoLowcjihrigbenglMrJithilfossamagna
authored
Pull latest commits from node core (#43)
Co-authored-by: cjihrig <[email protected]> Co-authored-by: Bryan English <[email protected]> Co-authored-by: Jithil P Ponnan <[email protected]> Co-authored-by: MURAKAMI Masahiko <[email protected]> Co-authored-by: Wassim Chegham <[email protected]> Co-authored-by: Pulkit Gupta <[email protected]> Co-authored-by: Antoine du Hamel <[email protected]> Co-authored-by: Erick Wendel <[email protected]>
1 parent 9b04919 commit 2cfde23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+7784
-325
lines changed

README.md

Lines changed: 496 additions & 2 deletions
Large diffs are not rendered by default.

bin/node--test-name-pattern.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env node
2+
3+
const { argv } = require('#internal/options')
4+
5+
argv['test-name-pattern'] = true
6+
7+
require('./node-core-test.js')

bin/node-core-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ const { argv } = require('#internal/options')
1010

1111
Object.assign(argv, minimist(process.argv.slice(2), {
1212
boolean: ['test', 'test-only'],
13+
string: ['test-name-pattern'],
1314
default: Object.prototype.hasOwnProperty.call(argv, 'test') ? { test: argv.test } : undefined
1415
}))
1516

17+
if (typeof argv['test-name-pattern'] === 'string') {
18+
argv['test-name-pattern'] = [argv['test-name-pattern']]
19+
}
20+
1621
process.argv.splice(1, Infinity, ...argv._)
1722
if (argv.test) {
1823
require('#internal/main/test_runner')

lib/internal/errors.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/1aab13cad9c800f4121c1d35b554b78c1b17bdbd/lib/internal/errors.js
1+
// https://github.com/nodejs/node/blob/f8ce9117b19702487eb600493d941f7876e00e01/lib/internal/errors.js
22

33
'use strict'
44

@@ -346,6 +346,21 @@ module.exports = {
346346
kIsNodeError
347347
}
348348

349+
E('ERR_TAP_LEXER_ERROR', function (errorMsg) {
350+
hideInternalStackFrames(this)
351+
return errorMsg
352+
}, Error)
353+
E('ERR_TAP_PARSER_ERROR', function (errorMsg, details, tokenCausedError, source) {
354+
hideInternalStackFrames(this)
355+
this.cause = tokenCausedError
356+
const { column, line, start, end } = tokenCausedError.location
357+
const errorDetails = `${details} at line ${line}, column ${column} (start ${start}, end ${end})`
358+
return errorMsg + errorDetails
359+
}, SyntaxError)
360+
E('ERR_TAP_VALIDATION_ERROR', function (errorMsg) {
361+
hideInternalStackFrames(this)
362+
return errorMsg
363+
}, Error)
349364
E('ERR_TEST_FAILURE', function (error, failureType) {
350365
hideInternalStackFrames(this)
351366
assert(typeof failureType === 'string',

lib/internal/main/test_runner.js

Lines changed: 16 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,26 @@
1-
// https://github.com/nodejs/node/blob/2fd4c013c221653da2a7921d08fe1aa96aaba504/lib/internal/main/test_runner.js
1+
// https://github.com/nodejs/node/blob/a165193c5c8e4bcfbd12b2c3f6e55a81a251c258/lib/internal/main/test_runner.js
22
'use strict'
3-
const {
4-
ArrayFrom,
5-
ArrayPrototypeFilter,
6-
ArrayPrototypeIncludes,
7-
ArrayPrototypeJoin,
8-
ArrayPrototypePush,
9-
ArrayPrototypeSlice,
10-
ArrayPrototypeSort,
11-
SafePromiseAll,
12-
SafeSet
13-
} = require('#internal/per_context/primordials')
143
const {
154
prepareMainThreadExecution
16-
} = require('#internal/bootstrap/pre_execution')
17-
const { spawn } = require('child_process')
18-
const { readdirSync, statSync } = require('fs')
19-
const {
20-
codes: {
21-
ERR_TEST_FAILURE
22-
}
23-
} = require('#internal/errors')
24-
const { toArray } = require('#internal/streams/operators').promiseReturningOperators
25-
const { test } = require('#internal/test_runner/harness')
26-
const { kSubtestsFailed } = require('#internal/test_runner/test')
27-
const {
28-
isSupportedFileType,
29-
doesPathMatchFilter
30-
} = require('#internal/test_runner/utils')
31-
const { basename, join, resolve } = require('path')
32-
const { once } = require('events')
33-
const kFilterArgs = ['--test']
5+
} = require('#internal/process/pre_execution')
6+
const { isUsingInspector } = require('#internal/util/inspector')
7+
const { run } = require('#internal/test_runner/runner')
348

359
prepareMainThreadExecution(false)
3610
// markBootstrapComplete();
3711

38-
// TODO(cjihrig): Replace this with recursive readdir once it lands.
39-
function processPath (path, testFiles, options) {
40-
const stats = statSync(path)
41-
42-
if (stats.isFile()) {
43-
if (options.userSupplied ||
44-
(options.underTestDir && isSupportedFileType(path)) ||
45-
doesPathMatchFilter(path)) {
46-
testFiles.add(path)
47-
}
48-
} else if (stats.isDirectory()) {
49-
const name = basename(path)
50-
51-
if (!options.userSupplied && name === 'node_modules') {
52-
return
53-
}
54-
55-
// 'test' directories get special treatment. Recursively add all .js,
56-
// .cjs, and .mjs files in the 'test' directory.
57-
const isTestDir = name === 'test'
58-
const { underTestDir } = options
59-
const entries = readdirSync(path)
60-
61-
if (isTestDir) {
62-
options.underTestDir = true
63-
}
12+
let concurrency = true
13+
let inspectPort
6414

65-
options.userSupplied = false
66-
67-
for (let i = 0; i < entries.length; i++) {
68-
processPath(join(path, entries[i]), testFiles, options)
69-
}
70-
71-
options.underTestDir = underTestDir
72-
}
15+
if (isUsingInspector()) {
16+
process.emitWarning('Using the inspector with --test forces running at a concurrency of 1. ' +
17+
'Use the inspectPort option to run with concurrency')
18+
concurrency = 1
19+
inspectPort = process.debugPort
7320
}
7421

75-
function createTestFileList () {
76-
const cwd = process.cwd()
77-
const hasUserSuppliedPaths = process.argv.length > 1
78-
const testPaths = hasUserSuppliedPaths
79-
? ArrayPrototypeSlice(process.argv, 1)
80-
: [cwd]
81-
const testFiles = new SafeSet()
82-
83-
try {
84-
for (let i = 0; i < testPaths.length; i++) {
85-
const absolutePath = resolve(testPaths[i])
86-
87-
processPath(absolutePath, testFiles, { userSupplied: true })
88-
}
89-
} catch (err) {
90-
if (err?.code === 'ENOENT') {
91-
console.error(`Could not find '${err.path}'`)
92-
process.exit(1)
93-
}
94-
95-
throw err
96-
}
97-
98-
return ArrayPrototypeSort(ArrayFrom(testFiles))
99-
}
100-
101-
function filterExecArgv (arg) {
102-
return !ArrayPrototypeIncludes(kFilterArgs, arg)
103-
}
104-
105-
function runTestFile (path) {
106-
return test(path, async (t) => {
107-
const args = ArrayPrototypeFilter(process.execArgv, filterExecArgv)
108-
ArrayPrototypePush(args, path)
109-
110-
const child = spawn(process.execPath, args, { signal: t.signal, encoding: 'utf8' })
111-
// TODO(cjihrig): Implement a TAP parser to read the child's stdout
112-
// instead of just displaying it all if the child fails.
113-
let err
114-
115-
child.on('error', (error) => {
116-
err = error
117-
})
118-
119-
const { 0: { 0: code, 1: signal }, 1: stdout, 2: stderr } = await SafePromiseAll([
120-
once(child, 'exit', { signal: t.signal }),
121-
toArray.call(child.stdout, { signal: t.signal }),
122-
toArray.call(child.stderr, { signal: t.signal })
123-
])
124-
125-
if (code !== 0 || signal !== null) {
126-
if (!err) {
127-
err = new ERR_TEST_FAILURE('test failed', kSubtestsFailed)
128-
err.exitCode = code
129-
err.signal = signal
130-
err.stdout = ArrayPrototypeJoin(stdout, '')
131-
err.stderr = ArrayPrototypeJoin(stderr, '')
132-
// The stack will not be useful since the failures came from tests
133-
// in a child process.
134-
err.stack = undefined
135-
}
136-
137-
throw err
138-
}
139-
})
140-
}
141-
142-
;(async function main () {
143-
const testFiles = createTestFileList()
144-
145-
for (let i = 0; i < testFiles.length; i++) {
146-
runTestFile(testFiles[i])
147-
}
148-
})()
22+
const tapStream = run({ concurrency, inspectPort })
23+
tapStream.pipe(process.stdout)
24+
tapStream.once('test:fail', () => {
25+
process.exitCode = 1
26+
})

lib/internal/per_context/primordials.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,44 @@
33
const replaceAll = require('string.prototype.replaceall')
44

55
exports.ArrayFrom = (it, mapFn) => Array.from(it, mapFn)
6+
exports.ArrayIsArray = Array.isArray
7+
exports.ArrayPrototypeConcat = (arr, ...el) => arr.concat(...el)
68
exports.ArrayPrototypeFilter = (arr, fn) => arr.filter(fn)
9+
exports.ArrayPrototypeFind = (arr, fn) => arr.find(fn)
710
exports.ArrayPrototypeForEach = (arr, fn, thisArg) => arr.forEach(fn, thisArg)
811
exports.ArrayPrototypeIncludes = (arr, el, fromIndex) => arr.includes(el, fromIndex)
912
exports.ArrayPrototypeJoin = (arr, str) => arr.join(str)
1013
exports.ArrayPrototypeMap = (arr, mapFn) => arr.map(mapFn)
14+
exports.ArrayPrototypePop = arr => arr.pop()
1115
exports.ArrayPrototypePush = (arr, ...el) => arr.push(...el)
1216
exports.ArrayPrototypeReduce = (arr, fn, originalVal) => arr.reduce(fn, originalVal)
1317
exports.ArrayPrototypeShift = arr => arr.shift()
1418
exports.ArrayPrototypeSlice = (arr, offset) => arr.slice(offset)
19+
exports.ArrayPrototypeSome = (arr, fn) => arr.some(fn)
1520
exports.ArrayPrototypeSort = (arr, fn) => arr.sort(fn)
21+
exports.ArrayPrototypeSplice = (arr, offset, len, ...el) => arr.splice(offset, len, ...el)
1622
exports.ArrayPrototypeUnshift = (arr, ...el) => arr.unshift(...el)
23+
exports.Boolean = Boolean
1724
exports.Error = Error
1825
exports.ErrorCaptureStackTrace = (...args) => Error.captureStackTrace(...args)
1926
exports.FunctionPrototype = Function.prototype
2027
exports.FunctionPrototypeBind = (fn, obj, ...args) => fn.bind(obj, ...args)
28+
exports.FunctionPrototypeCall = (fn, obj, ...args) => fn.call(obj, ...args)
2129
exports.MathMax = (...args) => Math.max(...args)
2230
exports.Number = Number
31+
exports.NumberIsInteger = Number.isInteger
32+
exports.NumberIsNaN = Number.isNaN
33+
exports.NumberParseInt = (str, radix) => Number.parseInt(str, radix)
34+
exports.NumberMIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER
35+
exports.NumberMAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER
36+
exports.ObjectAssign = (target, ...sources) => Object.assign(target, ...sources)
2337
exports.ObjectCreate = obj => Object.create(obj)
2438
exports.ObjectDefineProperties = (obj, props) => Object.defineProperties(obj, props)
2539
exports.ObjectDefineProperty = (obj, key, descr) => Object.defineProperty(obj, key, descr)
2640
exports.ObjectEntries = obj => Object.entries(obj)
2741
exports.ObjectFreeze = obj => Object.freeze(obj)
2842
exports.ObjectGetOwnPropertyDescriptor = (obj, key) => Object.getOwnPropertyDescriptor(obj, key)
43+
exports.ObjectGetPrototypeOf = obj => Object.getPrototypeOf(obj)
2944
exports.ObjectIsExtensible = obj => Object.isExtensible(obj)
3045
exports.ObjectPrototypeHasOwnProperty = (obj, property) => Object.prototype.hasOwnProperty.call(obj, property)
3146
exports.ObjectSeal = (obj) => Object.seal(obj)
@@ -35,22 +50,34 @@ exports.PromiseAll = iterator => Promise.all(iterator)
3550
exports.PromisePrototypeThen = (promise, thenFn, catchFn) => promise.then(thenFn, catchFn)
3651
exports.PromiseResolve = val => Promise.resolve(val)
3752
exports.PromiseRace = val => Promise.race(val)
53+
exports.Proxy = Proxy
54+
exports.RegExpPrototypeSymbolSplit = (reg, str) => reg[Symbol.split](str)
3855
exports.SafeArrayIterator = class ArrayIterator {constructor (array) { this.array = array }[Symbol.iterator] () { return this.array.values() }}
3956
exports.SafeMap = Map
4057
exports.SafePromiseAll = (array, mapFn) => Promise.all(mapFn ? array.map(mapFn) : array)
4158
exports.SafePromiseRace = (array, mapFn) => Promise.race(mapFn ? array.map(mapFn) : array)
4259
exports.SafeSet = Set
4360
exports.SafeWeakMap = WeakMap
61+
exports.SafeWeakSet = WeakSet
62+
exports.String = String
63+
exports.StringPrototypeEndsWith = (haystack, needle, index) => haystack.endsWith(needle, index)
4464
exports.StringPrototypeIncludes = (str, needle) => str.includes(needle)
4565
exports.StringPrototypeMatch = (str, reg) => str.match(reg)
66+
exports.StringPrototypeRepeat = (str, times) => str.repeat(times)
4667
exports.StringPrototypeReplace = (str, search, replacement) =>
4768
str.replace(search, replacement)
4869
exports.StringPrototypeReplaceAll = replaceAll
4970
exports.StringPrototypeStartsWith = (haystack, needle, index) => haystack.startsWith(needle, index)
5071
exports.StringPrototypeSlice = (str, ...args) => str.slice(...args)
5172
exports.StringPrototypeSplit = (str, search, limit) => str.split(search, limit)
73+
exports.StringPrototypeSubstring = (str, ...args) => str.substring(...args)
74+
exports.StringPrototypeToUpperCase = str => str.toUpperCase()
75+
exports.StringPrototypeTrim = str => str.trim()
5276
exports.Symbol = Symbol
5377
exports.SymbolFor = repr => Symbol.for(repr)
78+
exports.ReflectApply = (target, self, args) => Reflect.apply(target, self, args)
79+
exports.ReflectConstruct = (target, args, newTarget) => Reflect.construct(target, args, newTarget)
80+
exports.ReflectGet = (target, property, receiver) => Reflect.get(target, property, receiver)
5481
exports.RegExpPrototypeExec = (reg, str) => reg.exec(str)
5582
exports.RegExpPrototypeSymbolReplace = (regexp, str, replacement) =>
5683
regexp[Symbol.replace](str, replacement)
File renamed without changes.

0 commit comments

Comments
 (0)