chore: move remote module fixtures for easier deletion when removed (#25736)
This commit is contained in:
parent
485adae94c
commit
508b8d902b
28 changed files with 38 additions and 40 deletions
|
@ -1913,8 +1913,8 @@ describe('BrowserWindow module', () => {
|
|||
const [, test] = await emittedOnce(ipcMain, 'answer');
|
||||
expect(test).to.eql('preload');
|
||||
});
|
||||
it('can successfully delete the Buffer global', async () => {
|
||||
const preload = path.join(__dirname, 'fixtures', 'module', 'delete-buffer.js');
|
||||
ifit(features.isRemoteModuleEnabled())('can successfully delete the Buffer global', async () => {
|
||||
const preload = path.join(__dirname, 'fixtures', 'remote', 'delete-buffer.js');
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
|
@ -2039,7 +2039,7 @@ describe('BrowserWindow module', () => {
|
|||
ifdescribe(features.isRemoteModuleEnabled())('"enableRemoteModule" option', () => {
|
||||
const generateSpecs = (description: string, sandbox: boolean) => {
|
||||
describe(description, () => {
|
||||
const preload = path.join(__dirname, 'fixtures', 'module', 'preload-remote.js');
|
||||
const preload = path.join(__dirname, 'fixtures', 'remote', 'preload-remote.js');
|
||||
|
||||
it('disables the remote module by default', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
|
|
@ -216,7 +216,7 @@ describe('typeUtils serialization/deserialization', () => {
|
|||
});
|
||||
|
||||
ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
||||
const fixtures = path.join(__dirname, 'fixtures');
|
||||
const fixtures = path.join(__dirname, 'fixtures', 'remote');
|
||||
|
||||
describe('', () => {
|
||||
const w = makeWindow();
|
||||
|
@ -318,7 +318,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
w().webContents.once('did-finish-load', () => {
|
||||
w().webContents.loadURL('about:blank');
|
||||
});
|
||||
w().loadFile(path.join(fixtures, 'api', 'send-on-exit.html'));
|
||||
w().loadFile(path.join(fixtures, 'send-on-exit.html'));
|
||||
await emittedOnce(ipcMain, 'SENT_ON_EXIT');
|
||||
});
|
||||
});
|
||||
|
@ -330,7 +330,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
afterEach(closeAllWindows);
|
||||
|
||||
it('works when created in preload script', async () => {
|
||||
const preload = path.join(fixtures, 'module', 'preload-remote-function.js');
|
||||
const preload = path.join(fixtures, 'preload-remote-function.js');
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
|
@ -354,7 +354,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
});
|
||||
|
||||
const message = emittedOnce(ipcMain, 'error-message');
|
||||
w.loadFile(path.join(fixtures, 'api', 'render-view-deleted.html'));
|
||||
w.loadFile(path.join(fixtures, 'render-view-deleted.html'));
|
||||
const [, msg] = await message;
|
||||
expect(msg).to.match(/^Cannot call method 'getURL' on missing remote object/);
|
||||
});
|
||||
|
@ -439,7 +439,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
enableRemoteModule: true
|
||||
}
|
||||
});
|
||||
await w.loadFile(path.join(fixtures, 'api', 'remote-event-handler.html'));
|
||||
await w.loadFile(path.join(fixtures, 'remote-event-handler.html'));
|
||||
w.webContents.reload();
|
||||
await emittedOnce(w.webContents, 'did-finish-load');
|
||||
|
||||
|
@ -482,12 +482,12 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
expect(a).to.equal(b);
|
||||
});
|
||||
|
||||
remotely.it(path.join(fixtures, 'module', 'id.js'))('should work when object contains id property', (module: string) => {
|
||||
remotely.it(path.join(fixtures, 'id.js'))('should work when object contains id property', (module: string) => {
|
||||
const { id } = require('electron').remote.require(module);
|
||||
expect(id).to.equal(1127);
|
||||
});
|
||||
|
||||
remotely.it(path.join(fixtures, 'module', 'no-prototype.js'))('should work when object has no prototype', (module: string) => {
|
||||
remotely.it(path.join(fixtures, 'no-prototype.js'))('should work when object has no prototype', (module: string) => {
|
||||
const a = require('electron').remote.require(module);
|
||||
expect(a.foo.bar).to.equal('baz');
|
||||
expect(a.foo.baz).to.equal(false);
|
||||
|
@ -517,13 +517,13 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
const path = require('path');
|
||||
|
||||
{
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'module', 'export-function-with-properties.js'));
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'export-function-with-properties.js'));
|
||||
expect(typeof a).to.equal('function');
|
||||
expect(a.bar).to.equal('baz');
|
||||
}
|
||||
|
||||
{
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'module', 'function-with-properties.js'));
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'function-with-properties.js'));
|
||||
expect(typeof a).to.equal('object');
|
||||
expect(a.foo()).to.equal('hello');
|
||||
expect(a.foo.bar).to.equal('baz');
|
||||
|
@ -533,7 +533,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
}
|
||||
|
||||
{
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'module', 'function-with-missing-properties.js')).setup();
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'function-with-missing-properties.js')).setup();
|
||||
expect(a.bar()).to.equal(true);
|
||||
expect(a.bar.baz).to.be.undefined();
|
||||
}
|
||||
|
@ -541,7 +541,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
|
||||
remotely.it(fixtures)('should work with static class members', (fixtures: string) => {
|
||||
const path = require('path');
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'module', 'remote-static.js'));
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'remote-static.js'));
|
||||
expect(typeof a.Foo).to.equal('function');
|
||||
expect(a.Foo.foo()).to.equal(3);
|
||||
expect(a.Foo.bar).to.equal('baz');
|
||||
|
@ -550,7 +550,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
|
||||
remotely.it(fixtures)('includes the length of functions specified as arguments', (fixtures: string) => {
|
||||
const path = require('path');
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'module', 'function-with-args.js'));
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'function-with-args.js'));
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
expect(a((a: any, b: any, c: any) => {})).to.equal(3);
|
||||
expect(a((a: any) => {})).to.equal(1);
|
||||
|
@ -560,7 +560,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
|
||||
remotely.it(fixtures)('handles circular references in arrays and objects', (fixtures: string) => {
|
||||
const path = require('path');
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'module', 'circular.js'));
|
||||
const a = require('electron').remote.require(path.join(fixtures, 'circular.js'));
|
||||
|
||||
let arrayA: any[] = ['foo'];
|
||||
const arrayB = [arrayA, 'bar'];
|
||||
|
@ -619,7 +619,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
const { remote } = require('electron');
|
||||
const path = require('path');
|
||||
const buf = Buffer.from('test');
|
||||
const call = remote.require(path.join(fixtures, 'module', 'call.js'));
|
||||
const call = remote.require(path.join(fixtures, 'call.js'));
|
||||
const result = call.call((remote as any).createFunctionWithReturnValue(buf));
|
||||
expect(result).to.be.an.instanceOf(Uint8Array);
|
||||
});
|
||||
|
@ -640,7 +640,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
const { readText } = require('electron').remote.clipboard;
|
||||
expect(readText.toString().startsWith('function')).to.be.true();
|
||||
|
||||
const { functionWithToStringProperty } = require('electron').remote.require(path.join(fixtures, 'module', 'to-string-non-function.js'));
|
||||
const { functionWithToStringProperty } = require('electron').remote.require(path.join(fixtures, 'to-string-non-function.js'));
|
||||
expect(functionWithToStringProperty.toString).to.equal('hello');
|
||||
});
|
||||
});
|
||||
|
@ -650,7 +650,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
const remotely = makeRemotely(win);
|
||||
|
||||
remotely.it(fixtures)('can change its properties', (fixtures: string) => {
|
||||
const module = require('path').join(fixtures, 'module', 'property.js');
|
||||
const module = require('path').join(fixtures, 'property.js');
|
||||
const property = require('electron').remote.require(module);
|
||||
expect(property.property).to.equal(1127);
|
||||
property.property = null;
|
||||
|
@ -672,7 +672,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
});
|
||||
|
||||
remotely.it(fixtures)('rethrows errors getting/setting properties', (fixtures: string) => {
|
||||
const foo = require('electron').remote.require(require('path').join(fixtures, 'module', 'error-properties.js'));
|
||||
const foo = require('electron').remote.require(require('path').join(fixtures, 'error-properties.js'));
|
||||
|
||||
expect(() => {
|
||||
// eslint-disable-next-line
|
||||
|
@ -686,18 +686,18 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
|
||||
remotely.it(fixtures)('can set a remote property with a remote object', (fixtures: string) => {
|
||||
const { remote } = require('electron');
|
||||
const foo = remote.require(require('path').join(fixtures, 'module', 'remote-object-set.js'));
|
||||
const foo = remote.require(require('path').join(fixtures, 'remote-object-set.js'));
|
||||
foo.bar = remote.getCurrentWindow();
|
||||
});
|
||||
|
||||
remotely.it(fixtures)('can construct an object from its member', (fixtures: string) => {
|
||||
const call = require('electron').remote.require(require('path').join(fixtures, 'module', 'call.js'));
|
||||
const call = require('electron').remote.require(require('path').join(fixtures, 'call.js'));
|
||||
const obj = new call.constructor();
|
||||
expect(obj.test).to.equal('test');
|
||||
});
|
||||
|
||||
remotely.it(fixtures)('can reassign and delete its member functions', (fixtures: string) => {
|
||||
const remoteFunctions = require('electron').remote.require(require('path').join(fixtures, 'module', 'function.js'));
|
||||
const remoteFunctions = require('electron').remote.require(require('path').join(fixtures, 'function.js'));
|
||||
expect(remoteFunctions.aFunction()).to.equal(1127);
|
||||
|
||||
remoteFunctions.aFunction = () => { return 1234; };
|
||||
|
@ -724,7 +724,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
|
||||
describe('remote value in browser', () => {
|
||||
const remotely = makeRemotely(makeWindow());
|
||||
const print = path.join(fixtures, 'module', 'print_name.js');
|
||||
const print = path.join(fixtures, 'print_name.js');
|
||||
|
||||
remotely.it(print)('preserves NaN', (print: string) => {
|
||||
const printName = require('electron').remote.require(print);
|
||||
|
@ -836,13 +836,13 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
const remotely = makeRemotely(makeWindow());
|
||||
|
||||
remotely.it(fixtures)('can be used as promise in each side', async (fixtures: string) => {
|
||||
const promise = require('electron').remote.require(require('path').join(fixtures, 'module', 'promise.js'));
|
||||
const promise = require('electron').remote.require(require('path').join(fixtures, 'promise.js'));
|
||||
const value = await promise.twicePromise(Promise.resolve(1234));
|
||||
expect(value).to.equal(2468);
|
||||
});
|
||||
|
||||
remotely.it(fixtures)('handles rejections via catch(onRejected)', async (fixtures: string) => {
|
||||
const promise = require('electron').remote.require(require('path').join(fixtures, 'module', 'rejected-promise.js'));
|
||||
const promise = require('electron').remote.require(require('path').join(fixtures, 'rejected-promise.js'));
|
||||
const error = await new Promise<Error>(resolve => {
|
||||
promise.reject(Promise.resolve(1234)).catch(resolve);
|
||||
});
|
||||
|
@ -850,7 +850,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
});
|
||||
|
||||
remotely.it(fixtures)('handles rejections via then(onFulfilled, onRejected)', async (fixtures: string) => {
|
||||
const promise = require('electron').remote.require(require('path').join(fixtures, 'module', 'rejected-promise.js'));
|
||||
const promise = require('electron').remote.require(require('path').join(fixtures, 'rejected-promise.js'));
|
||||
const error = await new Promise<Error>(resolve => {
|
||||
promise.reject(Promise.resolve(1234)).then(() => {}, resolve);
|
||||
});
|
||||
|
@ -864,7 +864,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
process.once('unhandledRejection', onUnhandledRejection);
|
||||
|
||||
remotely(async (fixtures: string) => {
|
||||
const promise = require('electron').remote.require(require('path').join(fixtures, 'module', 'unhandled-rejection.js'));
|
||||
const promise = require('electron').remote.require(require('path').join(fixtures, 'unhandled-rejection.js'));
|
||||
return new Promise((resolve, reject) => {
|
||||
promise.reject().then(() => {
|
||||
reject(new Error('Promise was not rejected'));
|
||||
|
@ -897,7 +897,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
promise.reject().then(() => {
|
||||
reject(new Error('Promise was not rejected'));
|
||||
});
|
||||
}), path.join(fixtures, 'module', 'unhandled-rejection.js')).then(
|
||||
}), path.join(fixtures, 'unhandled-rejection.js')).then(
|
||||
(message) => {
|
||||
try {
|
||||
expect(message).to.equal('rejected');
|
||||
|
@ -947,17 +947,17 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
const remotely = makeRemotely(makeWindow());
|
||||
|
||||
remotely.it(fixtures)('can get methods', (fixtures: string) => {
|
||||
const { base } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js'));
|
||||
const { base } = require('electron').remote.require(require('path').join(fixtures, 'class.js'));
|
||||
expect(base.method()).to.equal('method');
|
||||
});
|
||||
|
||||
remotely.it(fixtures)('can get properties', (fixtures: string) => {
|
||||
const { base } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js'));
|
||||
const { base } = require('electron').remote.require(require('path').join(fixtures, 'class.js'));
|
||||
expect(base.readonly).to.equal('readonly');
|
||||
});
|
||||
|
||||
remotely.it(fixtures)('can change properties', (fixtures: string) => {
|
||||
const { base } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js'));
|
||||
const { base } = require('electron').remote.require(require('path').join(fixtures, 'class.js'));
|
||||
expect(base.value).to.equal('old');
|
||||
base.value = 'new';
|
||||
expect(base.value).to.equal('new');
|
||||
|
@ -965,13 +965,13 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
});
|
||||
|
||||
remotely.it(fixtures)('has unenumerable methods', (fixtures: string) => {
|
||||
const { base } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js'));
|
||||
const { base } = require('electron').remote.require(require('path').join(fixtures, 'class.js'));
|
||||
expect(base).to.not.have.ownProperty('method');
|
||||
expect(Object.getPrototypeOf(base)).to.have.ownProperty('method');
|
||||
});
|
||||
|
||||
remotely.it(fixtures)('keeps prototype chain in derived class', (fixtures: string) => {
|
||||
const { derived } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js'));
|
||||
const { derived } = require('electron').remote.require(require('path').join(fixtures, 'class.js'));
|
||||
expect(derived.method()).to.equal('method');
|
||||
expect(derived.readonly).to.equal('readonly');
|
||||
expect(derived).to.not.have.ownProperty('method');
|
||||
|
@ -981,7 +981,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
});
|
||||
|
||||
remotely.it(fixtures)('is referenced by methods in prototype chain', (fixtures: string) => {
|
||||
let { derived } = require('electron').remote.require(require('path').join(fixtures, 'module', 'class.js'));
|
||||
let { derived } = require('electron').remote.require(require('path').join(fixtures, 'class.js'));
|
||||
const method = derived.method;
|
||||
derived = null;
|
||||
global.gc();
|
||||
|
@ -993,14 +993,14 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
const remotely = makeRemotely(makeWindow());
|
||||
|
||||
remotely.it(fixtures)('throws errors from the main process', (fixtures: string) => {
|
||||
const throwFunction = require('electron').remote.require(require('path').join(fixtures, 'module', 'exception.js'));
|
||||
const throwFunction = require('electron').remote.require(require('path').join(fixtures, 'exception.js'));
|
||||
expect(() => {
|
||||
throwFunction();
|
||||
}).to.throw(/undefined/);
|
||||
});
|
||||
|
||||
remotely.it(fixtures)('tracks error cause', (fixtures: string) => {
|
||||
const throwFunction = require('electron').remote.require(require('path').join(fixtures, 'module', 'exception.js'));
|
||||
const throwFunction = require('electron').remote.require(require('path').join(fixtures, 'exception.js'));
|
||||
try {
|
||||
throwFunction(new Error('error from main'));
|
||||
expect.fail();
|
||||
|
|
|
@ -6,8 +6,6 @@ delete window.Buffer;
|
|||
delete global.Buffer;
|
||||
|
||||
// Test that remote.js doesn't use Buffer global
|
||||
if (remote) {
|
||||
remote.require(path.join(__dirname, 'print_name.js')).echo(Buffer.from('bar'));
|
||||
}
|
||||
remote.require(path.join(__dirname, 'print_name.js')).echo(Buffer.from('bar'));
|
||||
|
||||
window.test = Buffer.from('buffer');
|
Loading…
Reference in a new issue