electron/spec-main/asar-spec.ts
Samuel Attard 0d2e967960
feat: expose electron/{process} typed modules (#22937)
* feat: expose electron/{process} typed modules

* chore: update imports for common modules

* chore: update typescript generator

* chore: remap electron/* to the internal packages
2020-04-06 17:04:09 -07:00

82 lines
2.1 KiB
TypeScript

import { expect } from 'chai';
import * as path from 'path';
import { BrowserWindow, ipcMain } from 'electron/main';
import { closeAllWindows } from './window-helpers';
describe('asar package', () => {
const fixtures = path.join(__dirname, '..', 'spec', 'fixtures');
const asarDir = path.join(fixtures, 'test.asar');
afterEach(closeAllWindows);
describe('asar protocol', () => {
it('sets __dirname correctly', function (done) {
after(function () {
ipcMain.removeAllListeners('dirname');
});
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
nodeIntegration: true
}
});
const p = path.resolve(asarDir, 'web.asar', 'index.html');
ipcMain.once('dirname', function (event, dirname) {
expect(dirname).to.equal(path.dirname(p));
done();
});
w.loadFile(p);
});
it('loads script tag in html', function (done) {
after(function () {
ipcMain.removeAllListeners('ping');
});
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
nodeIntegration: true
}
});
const p = path.resolve(asarDir, 'script.asar', 'index.html');
w.loadFile(p);
ipcMain.once('ping', function (event, message) {
expect(message).to.equal('pong');
done();
});
});
it('loads video tag in html', function (done) {
this.timeout(60000);
after(function () {
ipcMain.removeAllListeners('asar-video');
});
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
nodeIntegration: true
}
});
const p = path.resolve(asarDir, 'video.asar', 'index.html');
w.loadFile(p);
ipcMain.on('asar-video', function (event, message, error) {
if (message === 'ended') {
expect(error).to.be.null();
done();
} else if (message === 'error') {
done(error);
}
});
});
});
});