feat: Add data parameter to app.requestSingleInstanceLock()
(#30891)
* WIP * Use serialization * Rebase windows impl of new app requestSingleInstanceLock parameter * Fix test * Implement posix side * Add backwards compatibility test * Apply PR feedback Windows * Fix posix impl * Switch mac impl back to vector * Refactor Windows impl * Use vectors, inline make_span * Use blink converter * fix: ownership across sequences * Fix upstream merge from Chromium Co-authored-by: deepak1556 <hop2deep@gmail.com>
This commit is contained in:
parent
5592652504
commit
db0a152bc1
9 changed files with 442 additions and 22 deletions
|
@ -207,7 +207,7 @@ describe('app module', () => {
|
|||
describe('app.requestSingleInstanceLock', () => {
|
||||
it('prevents the second launch of app', async function () {
|
||||
this.timeout(120000);
|
||||
const appPath = path.join(fixturesPath, 'api', 'singleton');
|
||||
const appPath = path.join(fixturesPath, 'api', 'singleton-data');
|
||||
const first = cp.spawn(process.execPath, [appPath]);
|
||||
await emittedOnce(first.stdout, 'data');
|
||||
// Start second app when received output.
|
||||
|
@ -218,8 +218,8 @@ describe('app module', () => {
|
|||
expect(code1).to.equal(0);
|
||||
});
|
||||
|
||||
it('passes arguments to the second-instance event', async () => {
|
||||
const appPath = path.join(fixturesPath, 'api', 'singleton');
|
||||
async function testArgumentPassing (fixtureName: string, expectedSecondInstanceData: unknown) {
|
||||
const appPath = path.join(fixturesPath, 'api', fixtureName);
|
||||
const first = cp.spawn(process.execPath, [appPath]);
|
||||
const firstExited = emittedOnce(first, 'exit');
|
||||
|
||||
|
@ -236,14 +236,34 @@ describe('app module', () => {
|
|||
expect(code2).to.equal(1);
|
||||
const [code1] = await firstExited;
|
||||
expect(code1).to.equal(0);
|
||||
const data2 = (await data2Promise)[0].toString('ascii');
|
||||
const secondInstanceArgsReceived: string[] = JSON.parse(data2.toString('ascii'));
|
||||
const received = await data2Promise;
|
||||
const [args, additionalData] = received[0].toString('ascii').split('||');
|
||||
const secondInstanceArgsReceived: string[] = JSON.parse(args.toString('ascii'));
|
||||
const secondInstanceDataReceived = JSON.parse(additionalData.toString('ascii'));
|
||||
|
||||
// Ensure secondInstanceArgs is a subset of secondInstanceArgsReceived
|
||||
for (const arg of secondInstanceArgs) {
|
||||
expect(secondInstanceArgsReceived).to.include(arg,
|
||||
`argument ${arg} is missing from received second args`);
|
||||
}
|
||||
expect(secondInstanceDataReceived).to.be.deep.equal(expectedSecondInstanceData,
|
||||
`received data ${JSON.stringify(secondInstanceDataReceived)} is not equal to expected data ${JSON.stringify(expectedSecondInstanceData)}.`);
|
||||
}
|
||||
|
||||
it('passes arguments to the second-instance event', async () => {
|
||||
const expectedSecondInstanceData = {
|
||||
level: 1,
|
||||
testkey: 'testvalue1',
|
||||
inner: {
|
||||
level: 2,
|
||||
testkey: 'testvalue2'
|
||||
}
|
||||
};
|
||||
await testArgumentPassing('singleton-data', expectedSecondInstanceData);
|
||||
});
|
||||
|
||||
it('passes arguments to the second-instance event no additional data', async () => {
|
||||
await testArgumentPassing('singleton', null);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue