2020-03-20 20:28:31 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import * as path from 'path';
|
|
|
|
import { BrowserWindow, ipcMain } from 'electron';
|
|
|
|
import { closeAllWindows } from './window-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', () => {
|
|
|
|
it('sets __dirname correctly', function (done) {
|
|
|
|
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');
|
2019-10-11 16:56:51 +00:00
|
|
|
ipcMain.once('dirname', function (event, dirname) {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(dirname).to.equal(path.dirname(p));
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
w.loadFile(p);
|
|
|
|
});
|
2019-10-11 16:56:51 +00:00
|
|
|
|
|
|
|
it('loads script tag in html', function (done) {
|
|
|
|
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');
|
|
|
|
w.loadFile(p);
|
2019-10-11 16:56:51 +00:00
|
|
|
ipcMain.once('ping', function (event, message) {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(message).to.equal('pong');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-10-11 16:56:51 +00:00
|
|
|
|
|
|
|
it('loads video tag in html', function (done) {
|
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);
|
2019-10-11 16:56:51 +00:00
|
|
|
ipcMain.on('asar-video', function (event, message, error) {
|
|
|
|
if (message === 'ended') {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(error).to.be.null();
|
|
|
|
done();
|
2019-10-11 16:56:51 +00:00
|
|
|
} else if (message === 'error') {
|
2020-03-20 20:28:31 +00:00
|
|
|
done(error);
|
2019-10-11 16:56:51 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|