asar-spec.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { expect } from 'chai';
  2. import * as path from 'path';
  3. import { BrowserWindow, ipcMain } from 'electron';
  4. import { closeAllWindows } from './window-helpers';
  5. describe('asar package', () => {
  6. const fixtures = path.join(__dirname, '..', 'spec', 'fixtures');
  7. const asarDir = path.join(fixtures, 'test.asar');
  8. afterEach(closeAllWindows);
  9. describe('asar protocol', () => {
  10. it('sets __dirname correctly', function (done) {
  11. after(function () {
  12. ipcMain.removeAllListeners('dirname');
  13. });
  14. const w = new BrowserWindow({
  15. show: false,
  16. width: 400,
  17. height: 400,
  18. webPreferences: {
  19. nodeIntegration: true
  20. }
  21. });
  22. const p = path.resolve(asarDir, 'web.asar', 'index.html');
  23. ipcMain.once('dirname', function (event, dirname) {
  24. expect(dirname).to.equal(path.dirname(p));
  25. done();
  26. });
  27. w.loadFile(p);
  28. });
  29. it('loads script tag in html', function (done) {
  30. after(function () {
  31. ipcMain.removeAllListeners('ping');
  32. });
  33. const w = new BrowserWindow({
  34. show: false,
  35. width: 400,
  36. height: 400,
  37. webPreferences: {
  38. nodeIntegration: true
  39. }
  40. });
  41. const p = path.resolve(asarDir, 'script.asar', 'index.html');
  42. w.loadFile(p);
  43. ipcMain.once('ping', function (event, message) {
  44. expect(message).to.equal('pong');
  45. done();
  46. });
  47. });
  48. it('loads video tag in html', function (done) {
  49. this.timeout(60000);
  50. after(function () {
  51. ipcMain.removeAllListeners('asar-video');
  52. });
  53. const w = new BrowserWindow({
  54. show: false,
  55. width: 400,
  56. height: 400,
  57. webPreferences: {
  58. nodeIntegration: true
  59. }
  60. });
  61. const p = path.resolve(asarDir, 'video.asar', 'index.html');
  62. w.loadFile(p);
  63. ipcMain.on('asar-video', function (event, message, error) {
  64. if (message === 'ended') {
  65. expect(error).to.be.null();
  66. done();
  67. } else if (message === 'error') {
  68. done(error);
  69. }
  70. });
  71. });
  72. });
  73. });