mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-16 15:56:33 +00:00
patch: remove node-ipc and tests
This commit is contained in:
parent
b3e33824ed
commit
ccc31bb9aa
@ -45,7 +45,6 @@
|
|||||||
"i18next": "23.7.8",
|
"i18next": "23.7.8",
|
||||||
"immutable": "3.8.2",
|
"immutable": "3.8.2",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"node-ipc": "9.2.1",
|
|
||||||
"outdent": "0.8.0",
|
"outdent": "0.8.0",
|
||||||
"path-is-inside": "1.0.2",
|
"path-is-inside": "1.0.2",
|
||||||
"pretty-bytes": "5.6.0",
|
"pretty-bytes": "5.6.0",
|
||||||
@ -77,7 +76,6 @@
|
|||||||
"@types/mime-types": "2.1.4",
|
"@types/mime-types": "2.1.4",
|
||||||
"@types/mocha": "^10.0.6",
|
"@types/mocha": "^10.0.6",
|
||||||
"@types/node": "^20.11.6",
|
"@types/node": "^20.11.6",
|
||||||
"@types/node-ipc": "9.2.3",
|
|
||||||
"@types/react": "17.0.2",
|
"@types/react": "17.0.2",
|
||||||
"@types/react-dom": "17.0.2",
|
"@types/react-dom": "17.0.2",
|
||||||
"@types/semver": "7.5.6",
|
"@types/semver": "7.5.6",
|
||||||
|
182
test-wrapper.ts
182
test-wrapper.ts
@ -1,182 +0,0 @@
|
|||||||
/*
|
|
||||||
* This is a test wrapper for etcher-utils.
|
|
||||||
* The only use for this file is debugging while developing etcher-utils.
|
|
||||||
* It will create a IPC server, spawn the cli version of etcher-writer, and wait for it to connect.
|
|
||||||
* Requires elevated privileges to work (launch with sudo)
|
|
||||||
* Note that you'll need to to edit `ipc.server.on('ready', ...` function based on what you want to test.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import * as ipc from 'node-ipc';
|
|
||||||
import * as os from 'os';
|
|
||||||
import * as path from 'path';
|
|
||||||
|
|
||||||
import * as packageJSON from './package.json';
|
|
||||||
import * as permissions from './lib/shared/permissions';
|
|
||||||
|
|
||||||
// if (process.argv.length !== 3) {
|
|
||||||
// console.error('Expects an image to flash as only arg!');
|
|
||||||
// process.exit(1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
const THREADS_PER_CPU = 16;
|
|
||||||
|
|
||||||
// There might be multiple Etcher instances running at
|
|
||||||
// the same time, therefore we must ensure each IPC
|
|
||||||
// server/client has a different name.
|
|
||||||
const IPC_SERVER_ID = `etcher-server-${process.pid}`;
|
|
||||||
const IPC_CLIENT_ID = `etcher-client-${process.pid}`;
|
|
||||||
|
|
||||||
ipc.config.id = IPC_SERVER_ID;
|
|
||||||
ipc.config.socketRoot = path.join(
|
|
||||||
process.env.XDG_RUNTIME_DIR || os.tmpdir(),
|
|
||||||
path.sep,
|
|
||||||
);
|
|
||||||
|
|
||||||
// NOTE: Ensure this isn't disabled, as it will cause
|
|
||||||
// the stdout maxBuffer size to be exceeded when flashing
|
|
||||||
ipc.config.silent = true;
|
|
||||||
|
|
||||||
function writerArgv(): string[] {
|
|
||||||
const entryPoint = path.join('./generated/etcher-util');
|
|
||||||
return [entryPoint];
|
|
||||||
}
|
|
||||||
|
|
||||||
function writerEnv() {
|
|
||||||
return {
|
|
||||||
IPC_SERVER_ID,
|
|
||||||
IPC_CLIENT_ID,
|
|
||||||
IPC_SOCKET_ROOT: ipc.config.socketRoot,
|
|
||||||
UV_THREADPOOL_SIZE: (os.cpus().length * THREADS_PER_CPU).toString(),
|
|
||||||
// This environment variable prevents the AppImages
|
|
||||||
// desktop integration script from presenting the
|
|
||||||
// "installation" dialog
|
|
||||||
SKIP: '1',
|
|
||||||
...(process.platform === 'win32' ? {} : process.env),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function start(): Promise<any> {
|
|
||||||
ipc.serve();
|
|
||||||
|
|
||||||
return await new Promise((resolve, reject) => {
|
|
||||||
ipc.server.on('error', (message) => {
|
|
||||||
console.log('IPC server error', message);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipc.server.on('log', (message) => {
|
|
||||||
console.log('log', message);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipc.server.on('fail', ({ device, error }) => {
|
|
||||||
console.log('failure', error, device);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipc.server.on('done', (event) => {
|
|
||||||
console.log('done', event);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipc.server.on('abort', () => {
|
|
||||||
console.log('abort');
|
|
||||||
});
|
|
||||||
|
|
||||||
ipc.server.on('skip', () => {
|
|
||||||
console.log('skip');
|
|
||||||
});
|
|
||||||
|
|
||||||
ipc.server.on('state', (progress) => {
|
|
||||||
console.log('progress', progress);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipc.server.on('drives', (drives) => {
|
|
||||||
console.log('drives', drives);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipc.server.on('ready', (_data, socket) => {
|
|
||||||
console.log('ready');
|
|
||||||
ipc.server.emit(socket, 'scan', {});
|
|
||||||
// ipc.server.emit(socket, "hello", { message: "world" });
|
|
||||||
// ipc.server.emit(socket, "write", {
|
|
||||||
// image: {
|
|
||||||
// path: process.argv[2],
|
|
||||||
// displayName: "Random image for test",
|
|
||||||
// description: "Random image for test",
|
|
||||||
// SourceType: "File",
|
|
||||||
// },
|
|
||||||
// destinations: [
|
|
||||||
// {
|
|
||||||
// size: 15938355200,
|
|
||||||
// isVirtual: false,
|
|
||||||
// enumerator: "DiskArbitration",
|
|
||||||
// logicalBlockSize: 512,
|
|
||||||
// raw: "/dev/rdisk4",
|
|
||||||
// error: null,
|
|
||||||
// isReadOnly: false,
|
|
||||||
// displayName: "/dev/disk4",
|
|
||||||
// blockSize: 512,
|
|
||||||
// isSCSI: false,
|
|
||||||
// isRemovable: true,
|
|
||||||
// device: "/dev/disk4",
|
|
||||||
// busVersion: null,
|
|
||||||
// isSystem: false,
|
|
||||||
// busType: "USB",
|
|
||||||
// isCard: false,
|
|
||||||
// isUSB: true,
|
|
||||||
// devicePath:
|
|
||||||
// "IODeviceTree:/arm-io@10F00000/usb-drd1@2280000/usb-drd1-port-hs@01100000",
|
|
||||||
// mountpoints: [
|
|
||||||
// {
|
|
||||||
// path: "/Volumes/flash-rootB",
|
|
||||||
// label: "flash-rootB",
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// path: "/Volumes/flash-rootA",
|
|
||||||
// label: "flash-rootA",
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// path: "/Volumes/flash-boot",
|
|
||||||
// label: "flash-boot",
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// description: "Generic Flash Disk Media",
|
|
||||||
// isUAS: null,
|
|
||||||
// partitionTableType: "mbr",
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// SourceType: "File",
|
|
||||||
// autoBlockmapping: true,
|
|
||||||
// decompressFirst: true,
|
|
||||||
// });
|
|
||||||
});
|
|
||||||
|
|
||||||
const argv = writerArgv();
|
|
||||||
|
|
||||||
ipc.server.on('start', async () => {
|
|
||||||
console.log(`Elevating command: ${argv.join(' ')}`);
|
|
||||||
const env = writerEnv();
|
|
||||||
try {
|
|
||||||
await permissions.elevateCommand(argv, {
|
|
||||||
applicationName: packageJSON.displayName,
|
|
||||||
environment: env,
|
|
||||||
});
|
|
||||||
} catch (error: any) {
|
|
||||||
console.log('error', error);
|
|
||||||
// This happens when the child is killed using SIGKILL
|
|
||||||
const SIGKILL_EXIT_CODE = 137;
|
|
||||||
if (error.code === SIGKILL_EXIT_CODE) {
|
|
||||||
error.code = 'ECHILDDIED';
|
|
||||||
}
|
|
||||||
reject(error);
|
|
||||||
} finally {
|
|
||||||
console.log('Terminating IPC server');
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clear the update lock timer to prevent longer
|
|
||||||
// flashing timing it out, and releasing the lock
|
|
||||||
ipc.server.start();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2018 balena.io
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { expect } from 'chai';
|
|
||||||
import * as ipc from 'node-ipc';
|
|
||||||
|
|
||||||
import('../../../lib/gui/modules/child-writer');
|
|
||||||
|
|
||||||
describe('Browser: childWriter', function () {
|
|
||||||
it('should have the ipc config set to silent', function () {
|
|
||||||
expect(ipc.config.silent).to.be.true;
|
|
||||||
});
|
|
||||||
});
|
|
@ -17,7 +17,6 @@
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { Drive as DrivelistDrive } from 'drivelist';
|
import { Drive as DrivelistDrive } from 'drivelist';
|
||||||
import { sourceDestination } from 'etcher-sdk';
|
import { sourceDestination } from 'etcher-sdk';
|
||||||
import * as ipc from 'node-ipc';
|
|
||||||
import { assert, SinonStub, stub } from 'sinon';
|
import { assert, SinonStub, stub } from 'sinon';
|
||||||
|
|
||||||
import { SourceMetadata } from '../../../lib/gui/app/components/source-selector/source-selector';
|
import { SourceMetadata } from '../../../lib/gui/app/components/source-selector/source-selector';
|
||||||
@ -140,11 +139,4 @@ describe('Browser: imageWriter', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.performWrite()', function () {
|
|
||||||
it('should set the ipc config to silent', function () {
|
|
||||||
// Reset this value as it can persist from other tests
|
|
||||||
expect(ipc.config.silent).to.be.true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user