@@ -31,6 +31,10 @@ const assert = require('assert');
31
31
const path = require ( 'path' ) ;
32
32
const fixtures = require ( '../common/fixtures' ) ;
33
33
const { builtinModules } = require ( 'module' ) ;
34
+ const publicModules = builtinModules . filter (
35
+ ( lib ) => ! lib . startsWith ( '_' ) && ! lib . includes ( '/' ) ,
36
+ ) ;
37
+
34
38
const hasInspector = process . features . inspector ;
35
39
36
40
if ( ! common . isMainThread )
@@ -239,9 +243,9 @@ putIn.run(['.clear']);
239
243
240
244
testMe . complete ( 'require(\'' , common . mustCall ( function ( error , data ) {
241
245
assert . strictEqual ( error , null ) ;
242
- builtinModules . forEach ( ( lib ) => {
246
+ publicModules . forEach ( ( lib ) => {
243
247
assert (
244
- data [ 0 ] . includes ( lib ) || lib . startsWith ( '_' ) || lib . includes ( '/' ) ,
248
+ data [ 0 ] . includes ( lib ) && data [ 0 ] . includes ( `node: ${ lib } ` ) ,
245
249
`${ lib } not found`
246
250
) ;
247
251
} ) ;
@@ -258,11 +262,15 @@ testMe.complete("require\t( 'n", common.mustCall(function(error, data) {
258
262
assert . strictEqual ( error , null ) ;
259
263
assert . strictEqual ( data . length , 2 ) ;
260
264
assert . strictEqual ( data [ 1 ] , 'n' ) ;
265
+ // require(...) completions include `node:`-prefixed modules:
266
+ publicModules . forEach ( ( lib , index ) =>
267
+ assert . strictEqual ( data [ 0 ] [ index ] , `node:${ lib } ` ) ) ;
268
+ assert . strictEqual ( data [ 0 ] [ publicModules . length ] , '' ) ;
261
269
// There is only one Node.js module that starts with n:
262
- assert . strictEqual ( data [ 0 ] [ 0 ] , 'net' ) ;
263
- assert . strictEqual ( data [ 0 ] [ 1 ] , '' ) ;
270
+ assert . strictEqual ( data [ 0 ] [ publicModules . length + 1 ] , 'net' ) ;
271
+ assert . strictEqual ( data [ 0 ] [ publicModules . length + 2 ] , '' ) ;
264
272
// It's possible to pick up non-core modules too
265
- data [ 0 ] . slice ( 2 ) . forEach ( ( completion ) => {
273
+ data [ 0 ] . slice ( publicModules . length + 3 ) . forEach ( ( completion ) => {
266
274
assert . match ( completion , / ^ n / ) ;
267
275
} ) ;
268
276
} ) ) ;
0 commit comments