| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0c46051 commit b8ef1b4
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -113,4 +113,56 @@ describe('Loader hooks', { concurrency: true }, () => { | |||
| 113 | 113 | assert.strictEqual(signal, null); | |
| 114 | 114 | }); | |
| 115 | 115 | }); | |
| 116 | + | ||
| 117 | + it('should work without worker permission', async () => { | ||
| 118 | + const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ | ||
| 119 | + '--no-warnings', | ||
| 120 | + '--experimental-permission', | ||
| 121 | + '--allow-fs-read', | ||
| 122 | + '*', | ||
| 123 | + '--experimental-loader', | ||
| 124 | + fixtures.fileURL('empty.js'), | ||
| 125 | + fixtures.path('es-modules/esm-top-level-await.mjs'), | ||
| 126 | + ]); | ||
| 127 | + | ||
| 128 | + assert.strictEqual(stderr, ''); | ||
| 129 | + assert.match(stdout, /^1\r?\n2\r?\n$/); | ||
| 130 | + assert.strictEqual(code, 0); | ||
| 131 | + assert.strictEqual(signal, null); | ||
| 132 | + }); | ||
| 133 | + | ||
| 134 | + it('should allow loader hooks to spawn workers when allowed by the CLI flags', async () => { | ||
| 135 | + const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ | ||
| 136 | + '--no-warnings', | ||
| 137 | + '--experimental-permission', | ||
| 138 | + '--allow-worker', | ||
| 139 | + '--allow-fs-read', | ||
| 140 | + '*', | ||
| 141 | + '--experimental-loader', | ||
| 142 | + `data:text/javascript,import{Worker}from"worker_threads";new Worker(${encodeURIComponent(JSON.stringify(fixtures.path('empty.js')))}).unref()`, | ||
| 143 | + fixtures.path('es-modules/esm-top-level-await.mjs'), | ||
| 144 | + ]); | ||
| 145 | + | ||
| 146 | + assert.strictEqual(stderr, ''); | ||
| 147 | + assert.match(stdout, /^1\r?\n2\r?\n$/); | ||
| 148 | + assert.strictEqual(code, 0); | ||
| 149 | + assert.strictEqual(signal, null); | ||
| 150 | + }); | ||
| 151 | + | ||
| 152 | + it('should not allow loader hooks to spawn workers if restricted by the CLI flags', async () => { | ||
| 153 | + const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ | ||
| 154 | + '--no-warnings', | ||
| 155 | + '--experimental-permission', | ||
| 156 | + '--allow-fs-read', | ||
| 157 | + '*', | ||
| 158 | + '--experimental-loader', | ||
| 159 | + `data:text/javascript,import{Worker}from"worker_threads";new Worker(${encodeURIComponent(JSON.stringify(fixtures.path('empty.js')))}).unref()`, | ||
| 160 | + fixtures.path('es-modules/esm-top-level-await.mjs'), | ||
| 161 | + ]); | ||
| 162 | + | ||
| 163 | + assert.match(stderr, /code: 'ERR_ACCESS_DENIED'/); | ||
| 164 | + assert.strictEqual(stdout, ''); | ||
| 165 | + assert.strictEqual(code, 1); | ||
| 166 | + assert.strictEqual(signal, null); | ||
| 167 | + }); | ||
| 116 | 168 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments