mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
test: fixup GDK_BACKEND test
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "dbus/bus.h"
|
||||
#include "dbus/message.h"
|
||||
#include "dbus/object_proxy.h"
|
||||
#include "shell/browser/electron_browser_main_parts.h"
|
||||
#include "shell/common/platform_util_internal.h"
|
||||
#include "ui/gtk/gtk_util.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
@@ -367,6 +367,66 @@ describe('web security', () => {
|
||||
});
|
||||
});
|
||||
|
||||
ifdescribe(process.platform === 'linux')('subprocesses', () => {
|
||||
let appProcess: ChildProcess.ChildProcessWithoutNullStreams | undefined;
|
||||
afterEach(() => {
|
||||
if (appProcess && !appProcess.killed) {
|
||||
appProcess.kill();
|
||||
appProcess = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
it('does not propagate GDK_BACKEND', async () => {
|
||||
const appPath = path.join(fixturesPath, 'api', 'gdk-backend-check');
|
||||
appProcess = ChildProcess.spawn(process.execPath, [appPath], {
|
||||
env: {
|
||||
GDK_BACKEND: ''
|
||||
}
|
||||
});
|
||||
|
||||
let output = '';
|
||||
appProcess.stdout.on('data', (data) => { output += data; });
|
||||
let stderr = '';
|
||||
appProcess.stderr.on('data', (data) => { stderr += data; });
|
||||
|
||||
const [code, signal] = await emittedOnce(appProcess, 'exit');
|
||||
if (code !== 0) {
|
||||
throw new Error(`Process exited with code "${code}" signal "${signal}" output "${output}" stderr "${stderr}"`);
|
||||
}
|
||||
|
||||
output = output.replace(/(\r\n|\n|\r)/gm, '');
|
||||
|
||||
const backend = String(process.env.GDK_BACKEND);
|
||||
expect(output).to.not.equal(backend);
|
||||
expect(output).to.be.empty();
|
||||
});
|
||||
|
||||
it('successfully honors GDK_BACKEND set in the subproc', async () => {
|
||||
const appPath = path.join(fixturesPath, 'api', 'gdk-backend-check');
|
||||
appProcess = ChildProcess.spawn(process.execPath, [appPath], {
|
||||
env: {
|
||||
GDK_BACKEND: 'wayland'
|
||||
}
|
||||
});
|
||||
|
||||
let output = '';
|
||||
appProcess.stdout.on('data', (data) => { output += data; });
|
||||
let stderr = '';
|
||||
appProcess.stderr.on('data', (data) => { stderr += data; });
|
||||
|
||||
const [code, signal] = await emittedOnce(appProcess, 'exit');
|
||||
if (code !== 0) {
|
||||
throw new Error(`Process exited with code "${code}" signal "${signal}" output "${output}" stderr "${stderr}"`);
|
||||
}
|
||||
|
||||
output = output.replace(/(\r\n|\n|\r)/gm, '');
|
||||
|
||||
const backend = String(process.env.GDK_BACKEND);
|
||||
expect(output).to.not.equal(backend);
|
||||
expect(output).to.equal('wayland');
|
||||
});
|
||||
});
|
||||
|
||||
describe('command line switches', () => {
|
||||
let appProcess: ChildProcess.ChildProcessWithoutNullStreams | undefined;
|
||||
afterEach(() => {
|
||||
|
||||
8
spec/fixtures/api/gdk-backend-check/main.js
vendored
Normal file
8
spec/fixtures/api/gdk-backend-check/main.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
const { app } = require('electron');
|
||||
|
||||
app.whenReady().then(() => {
|
||||
process.stdout.write(String(process.env.GDK_BACKEND));
|
||||
process.stdout.end();
|
||||
|
||||
app.quit();
|
||||
});
|
||||
5
spec/fixtures/api/gdk-backend-check/package.json
vendored
Normal file
5
spec/fixtures/api/gdk-backend-check/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "electron-test-gdk-backend-check",
|
||||
"main": "main.js"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user