@@ -5,46 +5,72 @@ const os = require("node:os");
55const path = require ( "node:path" ) ;
66const { invokeNode } = require ( "./helpers.cjs" ) ;
77
8+ async function invokeNodeWithLinkedMocha ( args ) {
9+ const repoRoot = path . resolve ( __dirname , ".." , ".." ) ;
10+ const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "mocha-package-root-" ) ) ;
11+ const packageDir = path . join ( tempDir , "node_modules" , "mocha" ) ;
12+
13+ fs . mkdirSync ( path . dirname ( packageDir ) , { recursive : true } ) ;
14+
15+ try {
16+ if ( process . platform === "win32" ) {
17+ fs . symlinkSync ( repoRoot , packageDir , "junction" ) ;
18+ } else {
19+ fs . symlinkSync ( repoRoot , packageDir ) ;
20+ }
21+
22+ return await new Promise ( ( resolve , reject ) => {
23+ invokeNode (
24+ args ,
25+ ( err , res ) => {
26+ if ( err ) {
27+ reject ( err ) ;
28+ return ;
29+ }
30+ resolve ( res ) ;
31+ } ,
32+ { cwd : tempDir , stdio : [ "ignore" , "pipe" , "pipe" ] } ,
33+ ) ;
34+ } ) ;
35+ } finally {
36+ fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
37+ }
38+ }
39+
840describe ( "package entrypoint" , function ( ) {
941 it ( "should resolve the package root without DEP0151 warnings" , async function ( ) {
10- const repoRoot = path . resolve ( __dirname , ".." , ".." ) ;
11- const tempDir = fs . mkdtempSync (
12- path . join ( os . tmpdir ( ) , "mocha-package-root-" ) ,
13- ) ;
14- const packageDir = path . join ( tempDir , "node_modules" , "mocha" ) ;
15-
16- fs . mkdirSync ( path . dirname ( packageDir ) , { recursive : true } ) ;
17-
18- try {
19- if ( process . platform === "win32" ) {
20- fs . symlinkSync ( repoRoot , packageDir , "junction" ) ;
21- } else {
22- fs . symlinkSync ( repoRoot , packageDir ) ;
23- }
24-
25- const result = await new Promise ( ( resolve , reject ) => {
26- invokeNode (
27- [
28- "--input-type=module" ,
29- "-e" ,
30- "import {describe, it} from 'mocha'; console.log(typeof describe, typeof it);" ,
31- ] ,
32- ( err , res ) => {
33- if ( err ) {
34- reject ( err ) ;
35- return ;
36- }
37- resolve ( res ) ;
38- } ,
39- { cwd : tempDir , stdio : [ "ignore" , "pipe" , "pipe" ] } ,
40- ) ;
41- } ) ;
42-
43- expect ( result . code , "to be" , 0 ) ;
44- expect ( result . output , "to contain" , "function function" ) ;
45- expect ( result . output , "not to contain" , "DEP0151" ) ;
46- } finally {
47- fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
48- }
42+ const result = await invokeNodeWithLinkedMocha ( [
43+ "--input-type=module" ,
44+ "-e" ,
45+ "import {describe, it} from 'mocha'; console.log(typeof describe, typeof it);" ,
46+ ] ) ;
47+
48+ expect ( result . code , "to be" , 0 ) ;
49+ expect ( result . output , "to contain" , "function function" ) ;
50+ expect ( result . output , "not to contain" , "DEP0151" ) ;
51+ } ) ;
52+
53+ it ( "should resolve deep subpaths without a file extension" , async function ( ) {
54+ const result = await invokeNodeWithLinkedMocha ( [
55+ "-e" ,
56+ "require.resolve('mocha/lib/reporters/base');" +
57+ "require.resolve('mocha/lib/stats-collector');" +
58+ "console.log('resolved deep subpaths');" ,
59+ ] ) ;
60+
61+ expect ( result . code , "to be" , 0 ) ;
62+ expect ( result . output , "to contain" , "resolved deep subpaths" ) ;
63+ } ) ;
64+
65+ it ( "should resolve deep subpaths with a file extension" , async function ( ) {
66+ const result = await invokeNodeWithLinkedMocha ( [
67+ "-e" ,
68+ "require.resolve('mocha/lib/reporters/base.js');" +
69+ "require.resolve('mocha/lib/stats-collector.js');" +
70+ "console.log('resolved deep subpaths');" ,
71+ ] ) ;
72+
73+ expect ( result . code , "to be" , 0 ) ;
74+ expect ( result . output , "to contain" , "resolved deep subpaths" ) ;
4975 } ) ;
5076} ) ;
0 commit comments