test: worker should be able to load asar files (#28858)
This commit is contained in:
parent
72092c2312
commit
b97b973306
4 changed files with 58 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as url from 'url';
|
||||||
import { BrowserWindow, ipcMain } from 'electron/main';
|
import { BrowserWindow, ipcMain } from 'electron/main';
|
||||||
import { closeAllWindows } from './window-helpers';
|
import { closeAllWindows } from './window-helpers';
|
||||||
import { emittedOnce } from './events-helpers';
|
import { emittedOnce } from './events-helpers';
|
||||||
|
@ -79,4 +80,32 @@ describe('asar package', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('worker', () => {
|
||||||
|
it('Worker can load asar file', async () => {
|
||||||
|
const w = new BrowserWindow({ show: false });
|
||||||
|
await w.loadFile(path.join(fixtures, 'workers', 'load_worker.html'));
|
||||||
|
|
||||||
|
const workerUrl = url.format({
|
||||||
|
pathname: path.resolve(fixtures, 'workers', 'workers.asar', 'worker.js').replace(/\\/g, '/'),
|
||||||
|
protocol: 'file',
|
||||||
|
slashes: true
|
||||||
|
});
|
||||||
|
const result = await w.webContents.executeJavaScript(`loadWorker('${workerUrl}')`);
|
||||||
|
expect(result).to.equal('success');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('SharedWorker can load asar file', async () => {
|
||||||
|
const w = new BrowserWindow({ show: false });
|
||||||
|
await w.loadFile(path.join(fixtures, 'workers', 'load_shared_worker.html'));
|
||||||
|
|
||||||
|
const workerUrl = url.format({
|
||||||
|
pathname: path.resolve(fixtures, 'workers', 'workers.asar', 'shared_worker.js').replace(/\\/g, '/'),
|
||||||
|
protocol: 'file',
|
||||||
|
slashes: true
|
||||||
|
});
|
||||||
|
const result = await w.webContents.executeJavaScript(`loadSharedWorker('${workerUrl}')`);
|
||||||
|
expect(result).to.equal('success');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
15
spec/fixtures/workers/load_shared_worker.html
vendored
Normal file
15
spec/fixtures/workers/load_shared_worker.html
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<script>
|
||||||
|
function loadSharedWorker(url) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
try {
|
||||||
|
const w = new SharedWorker(url);
|
||||||
|
w.onerror = () => resolve('failed');
|
||||||
|
w.port.onmessage = (m) => resolve(m.data);
|
||||||
|
w.port.postMessage('success');
|
||||||
|
} catch {
|
||||||
|
resolve('failed');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
14
spec/fixtures/workers/load_worker.html
vendored
Normal file
14
spec/fixtures/workers/load_worker.html
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<script>
|
||||||
|
function loadWorker(url) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
try {
|
||||||
|
const w = new Worker(url);
|
||||||
|
w.onerror = () => resolve('failed');
|
||||||
|
w.onmessage = (m) => resolve(m.data);
|
||||||
|
w.postMessage('success');
|
||||||
|
} catch {
|
||||||
|
resolve('failed');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
BIN
spec/fixtures/workers/workers.asar
vendored
Normal file
BIN
spec/fixtures/workers/workers.asar
vendored
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue