2020-03-20 20:28:31 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import * as path from 'path';
|
2020-04-07 00:04:09 +00:00
|
|
|
import { BrowserWindow, ipcMain } from 'electron/main';
|
2020-03-20 20:28:31 +00:00
|
|
|
import { closeAllWindows } from './window-helpers';
|
2020-06-30 22:10:36 +00:00
|
|
|
import { emittedOnce } from './events-helpers';
|
2019-10-11 16:56:51 +00:00
|
|
|
|
|
|
|
describe('asar package', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const fixtures = path.join(__dirname, '..', 'spec', 'fixtures');
|
|
|
|
const asarDir = path.join(fixtures, 'test.asar');
|
2019-10-11 16:56:51 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
afterEach(closeAllWindows);
|
2019-10-11 16:56:51 +00:00
|
|
|
|
|
|
|
describe('asar protocol', () => {
|
2020-06-30 22:10:36 +00:00
|
|
|
it('sets __dirname correctly', async function () {
|
2019-10-11 16:56:51 +00:00
|
|
|
after(function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
ipcMain.removeAllListeners('dirname');
|
|
|
|
});
|
2019-10-11 16:56:51 +00:00
|
|
|
|
|
|
|
const w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
const p = path.resolve(asarDir, 'web.asar', 'index.html');
|
2020-06-30 22:10:36 +00:00
|
|
|
const dirnameEvent = emittedOnce(ipcMain, 'dirname');
|
2020-03-20 20:28:31 +00:00
|
|
|
w.loadFile(p);
|
2020-06-30 22:10:36 +00:00
|
|
|
const [, dirname] = await dirnameEvent;
|
|
|
|
expect(dirname).to.equal(path.dirname(p));
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-10-11 16:56:51 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('loads script tag in html', async function () {
|
2019-10-11 16:56:51 +00:00
|
|
|
after(function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
ipcMain.removeAllListeners('ping');
|
|
|
|
});
|
2019-10-11 16:56:51 +00:00
|
|
|
|
|
|
|
const w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
const p = path.resolve(asarDir, 'script.asar', 'index.html');
|
2020-06-30 22:10:36 +00:00
|
|
|
const ping = emittedOnce(ipcMain, 'ping');
|
2020-03-20 20:28:31 +00:00
|
|
|
w.loadFile(p);
|
2020-06-30 22:10:36 +00:00
|
|
|
const [, message] = await ping;
|
|
|
|
expect(message).to.equal('pong');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-10-11 16:56:51 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('loads video tag in html', async function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
this.timeout(60000);
|
2019-10-11 16:56:51 +00:00
|
|
|
|
|
|
|
after(function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
ipcMain.removeAllListeners('asar-video');
|
|
|
|
});
|
2019-10-11 16:56:51 +00:00
|
|
|
|
|
|
|
const w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
const p = path.resolve(asarDir, 'video.asar', 'index.html');
|
|
|
|
w.loadFile(p);
|
2020-06-30 22:10:36 +00:00
|
|
|
const [, message, error] = await emittedOnce(ipcMain, 'asar-video');
|
|
|
|
if (message === 'ended') {
|
|
|
|
expect(error).to.be.null();
|
|
|
|
} else if (message === 'error') {
|
|
|
|
throw new Error(error);
|
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|