2020-03-20 23:28:31 +03:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import * as childProcess from 'child_process';
|
2021-06-07 22:19:39 +03:00
|
|
|
import * as fs from 'fs';
|
2020-03-20 23:28:31 +03:00
|
|
|
import * as path from 'path';
|
|
|
|
import * as util from 'util';
|
|
|
|
import { emittedOnce } from './events-helpers';
|
|
|
|
import { ifdescribe, ifit } from './spec-helpers';
|
2020-04-07 03:04:09 +03:00
|
|
|
import { webContents, WebContents } from 'electron/main';
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-06-23 06:32:45 +03:00
|
|
|
const features = process._linkedBinding('electron_common_features');
|
2021-03-22 23:11:03 +03:00
|
|
|
const mainFixturesPath = path.resolve(__dirname, 'fixtures');
|
2019-09-20 17:41:40 +03:00
|
|
|
|
|
|
|
describe('node feature', () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
const fixtures = path.join(__dirname, '..', 'spec', 'fixtures');
|
2019-09-20 17:41:40 +03:00
|
|
|
describe('child_process', () => {
|
|
|
|
describe('child_process.fork', () => {
|
2020-07-01 01:10:36 +03:00
|
|
|
it('Works in browser process', async () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
const child = childProcess.fork(path.join(fixtures, 'module', 'ping.js'));
|
2020-07-01 01:10:36 +03:00
|
|
|
const message = emittedOnce(child, 'message');
|
2020-03-20 23:28:31 +03:00
|
|
|
child.send('message');
|
2020-07-01 01:10:36 +03:00
|
|
|
const [msg] = await message;
|
|
|
|
expect(msg).to.equal('message');
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2021-04-09 10:09:17 +03:00
|
|
|
it('does not hang when using the fs module in the renderer process', async () => {
|
2021-03-22 23:11:03 +03:00
|
|
|
const appPath = path.join(mainFixturesPath, 'apps', 'libuv-hang', 'main.js');
|
|
|
|
const appProcess = childProcess.spawn(process.execPath, [appPath], {
|
|
|
|
cwd: path.join(mainFixturesPath, 'apps', 'libuv-hang'),
|
|
|
|
stdio: 'inherit'
|
|
|
|
});
|
|
|
|
const [code] = await emittedOnce(appProcess, 'close');
|
|
|
|
expect(code).to.equal(0);
|
|
|
|
});
|
|
|
|
|
2019-09-20 17:41:40 +03:00
|
|
|
describe('contexts', () => {
|
|
|
|
describe('setTimeout called under Chromium event loop in browser process', () => {
|
2020-02-07 05:59:38 +03:00
|
|
|
it('Can be scheduled in time', (done) => {
|
2020-03-20 23:28:31 +03:00
|
|
|
setTimeout(done, 0);
|
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-02-07 05:59:38 +03:00
|
|
|
it('Can be promisified', (done) => {
|
2020-03-20 23:28:31 +03:00
|
|
|
util.promisify(setTimeout)(0).then(done);
|
|
|
|
});
|
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
|
|
|
describe('setInterval called under Chromium event loop in browser process', () => {
|
|
|
|
it('can be scheduled in time', (done) => {
|
2020-03-20 23:28:31 +03:00
|
|
|
let interval: any = null;
|
|
|
|
let clearing = false;
|
2019-09-20 17:41:40 +03:00
|
|
|
const clear = () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
if (interval === null || clearing) return;
|
2019-09-20 17:41:40 +03:00
|
|
|
|
|
|
|
// interval might trigger while clearing (remote is slow sometimes)
|
2020-03-20 23:28:31 +03:00
|
|
|
clearing = true;
|
|
|
|
clearInterval(interval);
|
|
|
|
clearing = false;
|
|
|
|
interval = null;
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
interval = setInterval(clear, 10);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2019-11-02 04:06:15 +03:00
|
|
|
describe('NODE_OPTIONS', () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
let child: childProcess.ChildProcessWithoutNullStreams;
|
|
|
|
let exitPromise: Promise<any[]>;
|
2019-11-02 04:06:15 +03:00
|
|
|
|
2020-02-07 05:59:38 +03:00
|
|
|
it('Fails for options disallowed by Node.js itself', (done) => {
|
|
|
|
after(async () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
const [code, signal] = await exitPromise;
|
|
|
|
expect(signal).to.equal(null);
|
2020-02-07 05:59:38 +03:00
|
|
|
|
|
|
|
// Exit code 9 indicates cli flag parsing failure
|
2020-03-20 23:28:31 +03:00
|
|
|
expect(code).to.equal(9);
|
|
|
|
child.kill();
|
|
|
|
});
|
2019-11-02 04:06:15 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
const env = Object.assign({}, process.env, { NODE_OPTIONS: '--v8-options' });
|
|
|
|
child = childProcess.spawn(process.execPath, { env });
|
|
|
|
exitPromise = emittedOnce(child, 'exit');
|
2019-11-02 04:06:15 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
let output = '';
|
|
|
|
let success = false;
|
2020-02-07 05:59:38 +03:00
|
|
|
const cleanup = () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.removeListener('data', listener);
|
|
|
|
child.stdout.removeListener('data', listener);
|
|
|
|
};
|
2019-11-02 04:06:15 +03:00
|
|
|
|
2020-02-07 05:59:38 +03:00
|
|
|
const listener = (data: Buffer) => {
|
2020-03-20 23:28:31 +03:00
|
|
|
output += data;
|
2019-11-02 04:06:15 +03:00
|
|
|
if (/electron: --v8-options is not allowed in NODE_OPTIONS/m.test(output)) {
|
2020-03-20 23:28:31 +03:00
|
|
|
success = true;
|
|
|
|
cleanup();
|
|
|
|
done();
|
2019-11-02 04:06:15 +03:00
|
|
|
}
|
2020-03-20 23:28:31 +03:00
|
|
|
};
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.on('data', listener);
|
|
|
|
child.stdout.on('data', listener);
|
2020-02-07 05:59:38 +03:00
|
|
|
child.on('exit', () => {
|
|
|
|
if (!success) {
|
2020-03-20 23:28:31 +03:00
|
|
|
cleanup();
|
|
|
|
done(new Error(`Unexpected output: ${output.toString()}`));
|
2020-02-07 05:59:38 +03:00
|
|
|
}
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|
|
|
|
});
|
2019-11-02 04:06:15 +03:00
|
|
|
|
2020-02-07 05:59:38 +03:00
|
|
|
it('Disallows crypto-related options', (done) => {
|
|
|
|
after(() => {
|
2020-03-20 23:28:31 +03:00
|
|
|
child.kill();
|
|
|
|
});
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
const env = Object.assign({}, process.env, { NODE_OPTIONS: '--use-openssl-ca' });
|
|
|
|
child = childProcess.spawn(process.execPath, ['--enable-logging'], { env });
|
2019-11-02 04:06:15 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
let output = '';
|
2020-02-07 05:59:38 +03:00
|
|
|
const cleanup = () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.removeListener('data', listener);
|
|
|
|
child.stdout.removeListener('data', listener);
|
|
|
|
};
|
2019-11-02 04:06:15 +03:00
|
|
|
|
2020-02-07 05:59:38 +03:00
|
|
|
const listener = (data: Buffer) => {
|
2020-03-20 23:28:31 +03:00
|
|
|
output += data;
|
2019-11-02 04:06:15 +03:00
|
|
|
if (/The NODE_OPTION --use-openssl-ca is not supported in Electron/m.test(output)) {
|
2020-03-20 23:28:31 +03:00
|
|
|
cleanup();
|
|
|
|
done();
|
2019-11-02 04:06:15 +03:00
|
|
|
}
|
2020-03-20 23:28:31 +03:00
|
|
|
};
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.on('data', listener);
|
|
|
|
child.stdout.on('data', listener);
|
|
|
|
});
|
2021-06-03 08:46:44 +03:00
|
|
|
|
|
|
|
it('does allow --require in non-packaged apps', async () => {
|
|
|
|
const appPath = path.join(fixtures, 'module', 'noop.js');
|
|
|
|
const env = Object.assign({}, process.env, {
|
|
|
|
NODE_OPTIONS: `--require=${path.join(fixtures, 'module', 'fail.js')}`
|
|
|
|
});
|
|
|
|
// App should exit with code 1.
|
|
|
|
const child = childProcess.spawn(process.execPath, [appPath], { env });
|
|
|
|
const [code] = await emittedOnce(child, 'exit');
|
|
|
|
expect(code).to.equal(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not allow --require in packaged apps', async () => {
|
|
|
|
const appPath = path.join(fixtures, 'module', 'noop.js');
|
|
|
|
const env = Object.assign({}, process.env, {
|
|
|
|
ELECTRON_FORCE_IS_PACKAGED: 'true',
|
|
|
|
NODE_OPTIONS: `--require=${path.join(fixtures, 'module', 'fail.js')}`
|
|
|
|
});
|
|
|
|
// App should exit with code 0.
|
|
|
|
const child = childProcess.spawn(process.execPath, [appPath], { env });
|
|
|
|
const [code] = await emittedOnce(child, 'exit');
|
|
|
|
expect(code).to.equal(0);
|
|
|
|
});
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2021-04-09 10:09:17 +03:00
|
|
|
ifdescribe(features.isRunAsNodeEnabled())('Node.js cli flags', () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
let child: childProcess.ChildProcessWithoutNullStreams;
|
|
|
|
let exitPromise: Promise<any[]>;
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2021-03-17 00:02:47 +03:00
|
|
|
it('Prohibits crypto-related flags in ELECTRON_RUN_AS_NODE mode', (done) => {
|
2020-02-07 05:59:38 +03:00
|
|
|
after(async () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
const [code, signal] = await exitPromise;
|
|
|
|
expect(signal).to.equal(null);
|
|
|
|
expect(code).to.equal(9);
|
|
|
|
child.kill();
|
|
|
|
});
|
2020-02-07 05:59:38 +03:00
|
|
|
|
|
|
|
child = childProcess.spawn(process.execPath, ['--force-fips'], {
|
|
|
|
env: { ELECTRON_RUN_AS_NODE: 'true' }
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|
|
|
|
exitPromise = emittedOnce(child, 'exit');
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
let output = '';
|
2020-02-07 05:59:38 +03:00
|
|
|
const cleanup = () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.removeListener('data', listener);
|
|
|
|
child.stdout.removeListener('data', listener);
|
|
|
|
};
|
2020-02-07 05:59:38 +03:00
|
|
|
|
|
|
|
const listener = (data: Buffer) => {
|
2020-03-20 23:28:31 +03:00
|
|
|
output += data;
|
2020-02-07 05:59:38 +03:00
|
|
|
if (/.*The Node.js cli flag --force-fips is not supported in Electron/m.test(output)) {
|
2020-03-20 23:28:31 +03:00
|
|
|
cleanup();
|
|
|
|
done();
|
2020-02-07 05:59:38 +03:00
|
|
|
}
|
2020-03-20 23:28:31 +03:00
|
|
|
};
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.on('data', listener);
|
|
|
|
child.stdout.on('data', listener);
|
|
|
|
});
|
|
|
|
});
|
2019-11-02 04:06:15 +03:00
|
|
|
|
2020-10-05 20:10:38 +03:00
|
|
|
describe('process.stdout', () => {
|
|
|
|
it('is a real Node stream', () => {
|
|
|
|
expect((process.stdout as any)._type).to.not.be.undefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-07 22:19:39 +03:00
|
|
|
describe('fs.readFile', () => {
|
|
|
|
it('can accept a FileHandle as the Path argument', async () => {
|
|
|
|
const filePathForHandle = path.resolve(mainFixturesPath, 'dogs-running.txt');
|
|
|
|
const fileHandle = await fs.promises.open(filePathForHandle, 'r');
|
|
|
|
|
|
|
|
const file = await fs.promises.readFile(fileHandle, { encoding: 'utf8' });
|
|
|
|
expect(file).to.not.be.empty();
|
|
|
|
await fileHandle.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-09 10:09:17 +03:00
|
|
|
ifdescribe(features.isRunAsNodeEnabled())('inspector', () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
let child: childProcess.ChildProcessWithoutNullStreams;
|
|
|
|
let exitPromise: Promise<any[]>;
|
2019-09-20 17:41:40 +03:00
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
if (child && exitPromise) {
|
2020-03-20 23:28:31 +03:00
|
|
|
const [code, signal] = await exitPromise;
|
|
|
|
expect(signal).to.equal(null);
|
|
|
|
expect(code).to.equal(0);
|
2019-09-20 17:41:40 +03:00
|
|
|
} else if (child) {
|
2020-03-20 23:28:31 +03:00
|
|
|
child.kill();
|
2019-09-20 17:41:40 +03:00
|
|
|
}
|
2020-05-19 05:05:49 +03:00
|
|
|
child = null as any;
|
|
|
|
exitPromise = null as any;
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-02-07 05:59:38 +03:00
|
|
|
it('Supports starting the v8 inspector with --inspect/--inspect-brk', (done) => {
|
2019-09-20 17:41:40 +03:00
|
|
|
child = childProcess.spawn(process.execPath, ['--inspect-brk', path.join(fixtures, 'module', 'run-as-node.js')], {
|
2020-02-07 05:59:38 +03:00
|
|
|
env: { ELECTRON_RUN_AS_NODE: 'true' }
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
let output = '';
|
2020-02-07 05:59:38 +03:00
|
|
|
const cleanup = () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.removeListener('data', listener);
|
|
|
|
child.stdout.removeListener('data', listener);
|
|
|
|
};
|
2020-02-07 05:59:38 +03:00
|
|
|
|
|
|
|
const listener = (data: Buffer) => {
|
2020-03-20 23:28:31 +03:00
|
|
|
output += data;
|
2020-02-07 05:59:38 +03:00
|
|
|
if (/Debugger listening on ws:/m.test(output)) {
|
2020-03-20 23:28:31 +03:00
|
|
|
cleanup();
|
|
|
|
done();
|
2019-09-20 17:41:40 +03:00
|
|
|
}
|
2020-03-20 23:28:31 +03:00
|
|
|
};
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.on('data', listener);
|
|
|
|
child.stdout.on('data', listener);
|
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-07-01 01:10:36 +03:00
|
|
|
it('Supports starting the v8 inspector with --inspect and a provided port', async () => {
|
2019-09-20 17:41:40 +03:00
|
|
|
child = childProcess.spawn(process.execPath, ['--inspect=17364', path.join(fixtures, 'module', 'run-as-node.js')], {
|
2020-02-07 05:59:38 +03:00
|
|
|
env: { ELECTRON_RUN_AS_NODE: 'true' }
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|
|
|
|
exitPromise = emittedOnce(child, 'exit');
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
let output = '';
|
|
|
|
const listener = (data: Buffer) => { output += data; };
|
2020-02-07 05:59:38 +03:00
|
|
|
const cleanup = () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.removeListener('data', listener);
|
|
|
|
child.stdout.removeListener('data', listener);
|
|
|
|
};
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.on('data', listener);
|
|
|
|
child.stdout.on('data', listener);
|
2020-07-01 01:10:36 +03:00
|
|
|
await emittedOnce(child, 'exit');
|
|
|
|
cleanup();
|
|
|
|
if (/^Debugger listening on ws:/m.test(output)) {
|
|
|
|
expect(output.trim()).to.contain(':17364', 'should be listening on port 17364');
|
|
|
|
} else {
|
|
|
|
throw new Error(`Unexpected output: ${output.toString()}`);
|
|
|
|
}
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-07-01 01:10:36 +03:00
|
|
|
it('Does not start the v8 inspector when --inspect is after a -- argument', async () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
child = childProcess.spawn(process.execPath, [path.join(fixtures, 'module', 'noop.js'), '--', '--inspect']);
|
|
|
|
exitPromise = emittedOnce(child, 'exit');
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
let output = '';
|
|
|
|
const listener = (data: Buffer) => { output += data; };
|
|
|
|
child.stderr.on('data', listener);
|
|
|
|
child.stdout.on('data', listener);
|
2020-07-01 01:10:36 +03:00
|
|
|
await emittedOnce(child, 'exit');
|
|
|
|
if (output.trim().startsWith('Debugger listening on ws://')) {
|
|
|
|
throw new Error('Inspector was started when it should not have been');
|
|
|
|
}
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2021-03-17 00:02:47 +03:00
|
|
|
// IPC Electron child process not supported on Windows.
|
|
|
|
ifit(process.platform !== 'win32')('does not crash when quitting with the inspector connected', function (done) {
|
2019-09-20 17:41:40 +03:00
|
|
|
child = childProcess.spawn(process.execPath, [path.join(fixtures, 'module', 'delay-exit'), '--inspect=0'], {
|
|
|
|
stdio: ['ipc']
|
2020-03-20 23:28:31 +03:00
|
|
|
}) as childProcess.ChildProcessWithoutNullStreams;
|
|
|
|
exitPromise = emittedOnce(child, 'exit');
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-02-07 05:59:38 +03:00
|
|
|
const cleanup = () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.removeListener('data', listener);
|
|
|
|
child.stdout.removeListener('data', listener);
|
|
|
|
};
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
let output = '';
|
2020-05-19 05:05:49 +03:00
|
|
|
const success = false;
|
2020-02-07 05:59:38 +03:00
|
|
|
function listener (data: Buffer) {
|
2020-03-20 23:28:31 +03:00
|
|
|
output += data;
|
2020-05-26 04:20:16 +03:00
|
|
|
console.log(data.toString()); // NOTE: temporary debug logging to try to catch flake.
|
2020-05-19 05:05:49 +03:00
|
|
|
const match = /^Debugger listening on (ws:\/\/.+:\d+\/.+)\n/m.exec(output.trim());
|
|
|
|
if (match) {
|
|
|
|
cleanup();
|
2020-05-26 04:20:16 +03:00
|
|
|
// NOTE: temporary debug logging to try to catch flake.
|
|
|
|
child.stderr.on('data', (m) => console.log(m.toString()));
|
|
|
|
child.stdout.on('data', (m) => console.log(m.toString()));
|
2020-05-19 05:05:49 +03:00
|
|
|
const w = (webContents as any).create({}) as WebContents;
|
|
|
|
w.loadURL('about:blank')
|
|
|
|
.then(() => w.executeJavaScript(`new Promise(resolve => {
|
|
|
|
const connection = new WebSocket(${JSON.stringify(match[1])})
|
|
|
|
connection.onopen = () => {
|
2020-05-26 17:47:49 +03:00
|
|
|
connection.onclose = () => resolve()
|
2020-05-19 05:05:49 +03:00
|
|
|
connection.close()
|
|
|
|
}
|
|
|
|
})`))
|
|
|
|
.then(() => {
|
|
|
|
(w as any).destroy();
|
|
|
|
child.send('plz-quit');
|
|
|
|
done();
|
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
}
|
|
|
|
}
|
2020-02-07 05:59:38 +03:00
|
|
|
|
2020-03-20 23:28:31 +03:00
|
|
|
child.stderr.on('data', listener);
|
|
|
|
child.stdout.on('data', listener);
|
2020-02-07 05:59:38 +03:00
|
|
|
child.on('exit', () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
if (!success) cleanup();
|
|
|
|
});
|
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-07-01 01:10:36 +03:00
|
|
|
it('Supports js binding', async () => {
|
2019-09-20 17:41:40 +03:00
|
|
|
child = childProcess.spawn(process.execPath, ['--inspect', path.join(fixtures, 'module', 'inspector-binding.js')], {
|
2020-02-07 05:59:38 +03:00
|
|
|
env: { ELECTRON_RUN_AS_NODE: 'true' },
|
2019-09-20 17:41:40 +03:00
|
|
|
stdio: ['ipc']
|
2020-03-20 23:28:31 +03:00
|
|
|
}) as childProcess.ChildProcessWithoutNullStreams;
|
|
|
|
exitPromise = emittedOnce(child, 'exit');
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2020-07-01 01:10:36 +03:00
|
|
|
const [{ cmd, debuggerEnabled, success }] = await emittedOnce(child, 'message');
|
|
|
|
expect(cmd).to.equal('assert');
|
|
|
|
expect(debuggerEnabled).to.be.true();
|
|
|
|
expect(success).to.be.true();
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|
|
|
|
});
|
2019-09-20 17:41:40 +03:00
|
|
|
|
2021-04-09 10:09:17 +03:00
|
|
|
it('Can find a module using a package.json main field', () => {
|
2020-03-20 23:28:31 +03:00
|
|
|
const result = childProcess.spawnSync(process.execPath, [path.resolve(fixtures, 'api', 'electron-main-module', 'app.asar')]);
|
|
|
|
expect(result.status).to.equal(0);
|
|
|
|
});
|
2020-04-21 22:18:22 +03:00
|
|
|
|
2020-07-01 01:10:36 +03:00
|
|
|
ifit(features.isRunAsNodeEnabled())('handles Promise timeouts correctly', async () => {
|
2020-04-21 22:18:22 +03:00
|
|
|
const scriptPath = path.join(fixtures, 'module', 'node-promise-timer.js');
|
|
|
|
const child = childProcess.spawn(process.execPath, [scriptPath], {
|
|
|
|
env: { ELECTRON_RUN_AS_NODE: 'true' }
|
|
|
|
});
|
2020-07-01 01:10:36 +03:00
|
|
|
const [code, signal] = await emittedOnce(child, 'exit');
|
|
|
|
expect(code).to.equal(0);
|
|
|
|
expect(signal).to.equal(null);
|
|
|
|
child.kill();
|
2020-04-21 22:18:22 +03:00
|
|
|
});
|
2020-06-17 20:08:10 +03:00
|
|
|
|
|
|
|
it('performs microtask checkpoint correctly', (done) => {
|
|
|
|
const f3 = async () => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
reject(new Error('oops'));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
process.once('unhandledRejection', () => done('catch block is delayed to next tick'));
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
f3().catch(() => done());
|
|
|
|
});
|
|
|
|
});
|
2020-03-20 23:28:31 +03:00
|
|
|
});
|