|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -constcommon=require('../common'); |
4 | | -const{ spawn }=require('child_process'); |
5 | | -constassert=require('assert'); |
6 | | -constpath=require('path'); |
7 | | -constfs=require('fs'); |
8 | | - |
| 3 | +const{ spawnPromisified, skip }=require('../common'); |
9 | 4 | consttmpdir=require('../common/tmpdir'); |
| 5 | + |
| 6 | +// Invoke the main file via a symlink. In this case --preserve-symlinks-main |
| 7 | +// dictates that it'll resolve relative imports in the main file relative to |
| 8 | +// the symlink, and not relative to the symlink target; the file structure set |
| 9 | +// up below requires this to not crash when loading ./submodule_link.js |
| 10 | + |
| 11 | +constassert=require('node:assert'); |
| 12 | +constfs=require('node:fs'); |
| 13 | +constpath=require('node:path'); |
| 14 | +const{ execPath }=require('node:process'); |
| 15 | +const{ describe, it }=require('node:test'); |
| 16 | + |
10 | 17 | tmpdir.refresh(); |
11 | 18 | consttmpDir=tmpdir.path; |
12 | 19 |
|
13 | 20 | fs.mkdirSync(path.join(tmpDir,'nested')); |
14 | 21 | fs.mkdirSync(path.join(tmpDir,'nested2')); |
15 | 22 |
|
16 | 23 | constentry=path.join(tmpDir,'nested','entry.js'); |
17 | | -constentry_link_absolute_path=path.join(tmpDir,'link.js'); |
| 24 | +constentry_link_absolute_path=path.join(tmpDir,'index.js'); |
18 | 25 | constsubmodule=path.join(tmpDir,'nested2','submodule.js'); |
19 | 26 | constsubmodule_link_absolute_path=path.join(tmpDir,'submodule_link.js'); |
20 | 27 |
|
|
31 | 38 | fs.symlinkSync(submodule,submodule_link_absolute_path); |
32 | 39 | }catch(err){ |
33 | 40 | if(err.code!=='EPERM')throwerr; |
34 | | -common.skip('insufficient privileges for symlinks'); |
| 41 | +skip('insufficient privileges for symlinks'); |
35 | 42 | } |
36 | 43 |
|
37 | | -functiondoTest(flags,done){ |
38 | | -// Invoke the main file via a symlink. In this case --preserve-symlinks-main |
39 | | -// dictates that it'll resolve relative imports in the main file relative to |
40 | | -// the symlink, and not relative to the symlink target; the file structure set |
41 | | -// up above requires this to not crash when loading ./submodule_link.js |
42 | | -spawn(process.execPath,[ |
43 | | -'--preserve-symlinks', |
44 | | -'--preserve-symlinks-main', |
45 | | -entry_link_absolute_path, |
46 | | -],{stdio: 'inherit'}) |
47 | | -.on('exit',(code)=>{ |
48 | | -assert.strictEqual(code,0); |
49 | | -done(); |
50 | | -}); |
51 | | -} |
| 44 | +describe('Invoke the main file via a symlink.',{concurrency: true},()=>{ |
| 45 | +it('should resolve relative imports in the main file',async()=>{ |
| 46 | +const{ code }=awaitspawnPromisified(execPath,[ |
| 47 | +'--preserve-symlinks', |
| 48 | +'--preserve-symlinks-main', |
| 49 | +entry_link_absolute_path, |
| 50 | +]); |
| 51 | + |
| 52 | +assert.strictEqual(code,0); |
| 53 | +}); |
| 54 | + |
| 55 | +it('should resolve relative imports in the main file when file extension is omitted',async()=>{ |
| 56 | +constentry_link_absolute_path_without_ext=path.join(tmpDir,'index'); |
| 57 | + |
| 58 | +const{ code }=awaitspawnPromisified(execPath,[ |
| 59 | +'--preserve-symlinks', |
| 60 | +'--preserve-symlinks-main', |
| 61 | +entry_link_absolute_path_without_ext, |
| 62 | +]); |
| 63 | + |
| 64 | +assert.strictEqual(code,0); |
| 65 | +}); |
| 66 | + |
| 67 | +it('should resolve relative imports in the main file when filename(index.js) is omitted',async()=>{ |
| 68 | +const{ code }=awaitspawnPromisified(execPath,[ |
| 69 | +'--preserve-symlinks', |
| 70 | +'--preserve-symlinks-main', |
| 71 | +tmpDir, |
| 72 | +]); |
52 | 73 |
|
53 | | -// First test the commonjs module loader |
54 | | -doTest([],()=>{ |
55 | | -// Now test the new loader |
56 | | -doTest([],()=>{}); |
| 74 | +assert.strictEqual(code,0); |
| 75 | +}); |
57 | 76 | }); |
0 commit comments