test: remove remote usage from asar spec (#20513)
This commit is contained in:
parent
d21519ed2e
commit
032353b14f
2 changed files with 82 additions and 80 deletions
82
spec-main/asar-spec.ts
Normal file
82
spec-main/asar-spec.ts
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
import { expect } from 'chai'
|
||||||
|
import * as path from 'path'
|
||||||
|
import { BrowserWindow, ipcMain } from 'electron'
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -5,12 +5,7 @@ const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const temp = require('temp').track()
|
const temp = require('temp').track()
|
||||||
const util = require('util')
|
const util = require('util')
|
||||||
const { closeWindow } = require('./window-helpers')
|
|
||||||
|
|
||||||
const nativeImage = require('electron').nativeImage
|
const nativeImage = require('electron').nativeImage
|
||||||
const remote = require('electron').remote
|
|
||||||
|
|
||||||
const { ipcMain, BrowserWindow } = remote
|
|
||||||
|
|
||||||
const features = process.electronBinding('features')
|
const features = process.electronBinding('features')
|
||||||
|
|
||||||
|
@ -1353,12 +1348,6 @@ describe('asar package', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('asar protocol', function () {
|
describe('asar protocol', function () {
|
||||||
let w = null
|
|
||||||
|
|
||||||
afterEach(function () {
|
|
||||||
return closeWindow(w).then(function () { w = null })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can request a file in package', function (done) {
|
it('can request a file in package', function (done) {
|
||||||
const p = path.resolve(asarDir, 'a.asar', 'file1')
|
const p = path.resolve(asarDir, 'a.asar', 'file1')
|
||||||
$.get('file://' + p, function (data) {
|
$.get('file://' + p, function (data) {
|
||||||
|
@ -1401,75 +1390,6 @@ describe('asar package', function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sets __dirname correctly', function (done) {
|
|
||||||
after(function () {
|
|
||||||
ipcMain.removeAllListeners('dirname')
|
|
||||||
})
|
|
||||||
|
|
||||||
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')
|
|
||||||
})
|
|
||||||
|
|
||||||
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')
|
|
||||||
})
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('original-fs module', function () {
|
describe('original-fs module', function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue