electron/spec-main/fixtures/api/net-log/main.js

32 lines
674 B
JavaScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
const { app, net, session } = require('electron');
if (process.env.TEST_DUMP_FILE) {
2020-03-20 20:28:31 +00:00
app.commandLine.appendSwitch('log-net-log', process.env.TEST_DUMP_FILE);
}
function request () {
return new Promise((resolve) => {
2020-03-20 20:28:31 +00:00
const req = net.request(process.env.TEST_REQUEST_URL);
req.on('response', () => {
2020-03-20 20:28:31 +00:00
resolve();
});
req.end();
});
}
app.whenReady().then(async () => {
2020-03-20 20:28:31 +00:00
const netLog = session.defaultSession.netLog;
if (process.env.TEST_DUMP_FILE_DYNAMIC) {
2020-03-20 20:28:31 +00:00
await netLog.startLogging(process.env.TEST_DUMP_FILE_DYNAMIC);
}
2020-03-20 20:28:31 +00:00
await request();
if (process.env.TEST_MANUAL_STOP) {
2020-03-20 20:28:31 +00:00
await netLog.stopLogging();
}
2020-03-20 20:28:31 +00:00
app.quit();
});