1- // Flags: --permission --allow-fs-read=*
21'use strict' ;
32
43const common = require ( '../common' ) ;
4+ const { spawnSyncAndExitWithoutError } = require ( '../common/child_process' ) ;
55const { isMainThread } = require ( 'worker_threads' ) ;
66
77if ( ! isMainThread ) {
@@ -12,7 +12,21 @@ if (!common.hasCrypto) {
1212 common . skip ( 'no crypto' ) ;
1313}
1414
15+ // We need to define the flags dynamically to account for the `NODE_TEST_DIR` env var.
16+ if ( ! process . permission ) {
17+ spawnSyncAndExitWithoutError ( process . execPath , [
18+ '--permission' ,
19+ '--allow-fs-read=*' , `--allow-fs-write=${ process . env . NODE_TEST_DIR || './test' } /.tmp.*` , '--allow-child-process' ,
20+ __filename ,
21+ ] ) ;
22+ return ;
23+ }
24+
1525const assert = require ( 'assert' ) ;
26+ const path = require ( 'path' ) ;
27+ const tmpdir = require ( '../common/tmpdir' ) ;
28+
29+ tmpdir . refresh ( ) ;
1630
1731{
1832 assert . throws ( ( ) => {
@@ -33,3 +47,29 @@ const assert = require('assert');
3347 resource : process . cwd ( ) ,
3448 } ) ) ;
3549}
50+
51+ {
52+ const reportPath = path . join ( tmpdir . path , 'report.json' ) ;
53+ spawnSyncAndExitWithoutError (
54+ process . execPath ,
55+ [
56+ '--permission' ,
57+ '--allow-fs-read=*' ,
58+ `--allow-fs-write=${ tmpdir . path } /*` ,
59+ '-e' ,
60+ `process.report.writeReport(${ JSON . stringify ( reportPath ) } )` ,
61+ ]
62+ ) ;
63+ }
64+
65+ spawnSyncAndExitWithoutError (
66+ process . execPath ,
67+ [
68+ '--permission' ,
69+ '--allow-fs-read=*' ,
70+ `--allow-fs-write=${ tmpdir . path } ` ,
71+ '-e' ,
72+ 'process.report.writeReport()' ,
73+ ] ,
74+ { cwd : tmpdir . path }
75+ ) ;
0 commit comments