electron/spec-main/asar-spec.ts

83 lines
2.3 KiB
TypeScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
import { expect } from 'chai';
import * as path from 'path';
import { BrowserWindow, ipcMain } from 'electron/main';
2020-03-20 20:28:31 +00:00
import { closeAllWindows } from './window-helpers';
import { emittedOnce } from './events-helpers';
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');
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
describe('asar protocol', () => {
it('sets __dirname correctly', async function () {
after(function () {
2020-03-20 20:28:31 +00:00
ipcMain.removeAllListeners('dirname');
});
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
2020-03-20 20:28:31 +00:00
});
const p = path.resolve(asarDir, 'web.asar', 'index.html');
const dirnameEvent = emittedOnce(ipcMain, 'dirname');
2020-03-20 20:28:31 +00:00
w.loadFile(p);
const [, dirname] = await dirnameEvent;
expect(dirname).to.equal(path.dirname(p));
2020-03-20 20:28:31 +00:00
});
it('loads script tag in html', async function () {
after(function () {
2020-03-20 20:28:31 +00:00
ipcMain.removeAllListeners('ping');
});
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
2020-03-20 20:28:31 +00:00
});
const p = path.resolve(asarDir, 'script.asar', 'index.html');
const ping = emittedOnce(ipcMain, 'ping');
2020-03-20 20:28:31 +00:00
w.loadFile(p);
const [, message] = await ping;
expect(message).to.equal('pong');
2020-03-20 20:28:31 +00:00
});
it('loads video tag in html', async function () {
2020-03-20 20:28:31 +00:00
this.timeout(60000);
after(function () {
2020-03-20 20:28:31 +00:00
ipcMain.removeAllListeners('asar-video');
});
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
2020-03-20 20:28:31 +00:00
});
const p = path.resolve(asarDir, 'video.asar', 'index.html');
w.loadFile(p);
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
});
});
});