Make tab width 2 spaces (#445)

This commit is contained in:
Francesco Stasi
2021-07-09 10:14:42 +02:00
committed by GitHub
parent 40a73af82b
commit e10f0f1683
205 changed files with 19676 additions and 20141 deletions

View File

@@ -13,149 +13,143 @@ import { CLI_CONFIG } from '../../node/cli-config';
const track = temp.track();
class SilentArduinoDaemonImpl extends ArduinoDaemonImpl {
constructor(
private port: string | number,
private logFormat: 'text' | 'json'
) {
super();
}
constructor(
private port: string | number,
private logFormat: 'text' | 'json'
) {
super();
}
onData(data: string): void {
// NOOP
}
onData(data: string): void {
// NOOP
}
async spawnDaemonProcess(): Promise<ChildProcess> {
return super.spawnDaemonProcess();
}
async spawnDaemonProcess(): Promise<ChildProcess> {
return super.spawnDaemonProcess();
}
protected async getSpawnArgs(): Promise<string[]> {
const cliConfigPath = await this.initCliConfig();
return [
'daemon',
'--config-file',
cliConfigPath,
'-v',
'--log-format',
this.logFormat,
];
}
protected async getSpawnArgs(): Promise<string[]> {
const cliConfigPath = await this.initCliConfig();
return [
'daemon',
'--config-file',
cliConfigPath,
'-v',
'--log-format',
this.logFormat,
];
}
private async initCliConfig(): Promise<string> {
const cliPath = await this.getExecPath();
const destDir = track.mkdirSync();
await spawnCommand(`"${cliPath}"`, [
'config',
'init',
'--dest-dir',
destDir,
]);
const content = fs.readFileSync(path.join(destDir, CLI_CONFIG), {
encoding: 'utf8',
});
const cliConfig = safeLoad(content) as any;
cliConfig.daemon.port = String(this.port);
const modifiedContent = safeDump(cliConfig);
fs.writeFileSync(path.join(destDir, CLI_CONFIG), modifiedContent, {
encoding: 'utf8',
});
return path.join(destDir, CLI_CONFIG);
}
private async initCliConfig(): Promise<string> {
const cliPath = await this.getExecPath();
const destDir = track.mkdirSync();
await spawnCommand(`"${cliPath}"`, [
'config',
'init',
'--dest-dir',
destDir,
]);
const content = fs.readFileSync(path.join(destDir, CLI_CONFIG), {
encoding: 'utf8',
});
const cliConfig = safeLoad(content) as any;
cliConfig.daemon.port = String(this.port);
const modifiedContent = safeDump(cliConfig);
fs.writeFileSync(path.join(destDir, CLI_CONFIG), modifiedContent, {
encoding: 'utf8',
});
return path.join(destDir, CLI_CONFIG);
}
}
describe('arduino-daemon-impl', () => {
after(() => {
track.cleanupSync();
});
after(() => {
track.cleanupSync();
});
// it('should parse an error - address already in use error [json]', async function (): Promise<void> {
// if (process.platform === 'win32') {
// this.skip();
// }
// let server: net.Server | undefined = undefined;
// try {
// server = await new Promise<net.Server>(resolve => {
// const server = net.createServer();
// server.listen(() => resolve(server));
// });
// const address = server.address() as net.AddressInfo;
// await new SilentArduinoDaemonImpl(address.port, 'json').spawnDaemonProcess();
// fail('Expected a failure.')
// } catch (e) {
// expect(e).to.be.instanceOf(DaemonError);
// expect(e.code).to.be.equal(DaemonError.ADDRESS_IN_USE);
// } finally {
// if (server) {
// server.close();
// }
// }
// });
// it('should parse an error - address already in use error [json]', async function (): Promise<void> {
// if (process.platform === 'win32') {
// this.skip();
// }
// let server: net.Server | undefined = undefined;
// try {
// server = await new Promise<net.Server>(resolve => {
// const server = net.createServer();
// server.listen(() => resolve(server));
// });
// const address = server.address() as net.AddressInfo;
// await new SilentArduinoDaemonImpl(address.port, 'json').spawnDaemonProcess();
// fail('Expected a failure.')
// } catch (e) {
// expect(e).to.be.instanceOf(DaemonError);
// expect(e.code).to.be.equal(DaemonError.ADDRESS_IN_USE);
// } finally {
// if (server) {
// server.close();
// }
// }
// });
// it('should parse an error - address already in use error [text]', async function (): Promise<void> {
// if (process.platform === 'win32') {
// this.skip();
// }
// let server: net.Server | undefined = undefined;
// try {
// server = await new Promise<net.Server>(resolve => {
// const server = net.createServer();
// server.listen(() => resolve(server));
// });
// const address = server.address() as net.AddressInfo;
// await new SilentArduinoDaemonImpl(address.port, 'text').spawnDaemonProcess();
// fail('Expected a failure.')
// } catch (e) {
// expect(e).to.be.instanceOf(DaemonError);
// expect(e.code).to.be.equal(DaemonError.ADDRESS_IN_USE);
// } finally {
// if (server) {
// server.close();
// }
// }
// });
// it('should parse an error - address already in use error [text]', async function (): Promise<void> {
// if (process.platform === 'win32') {
// this.skip();
// }
// let server: net.Server | undefined = undefined;
// try {
// server = await new Promise<net.Server>(resolve => {
// const server = net.createServer();
// server.listen(() => resolve(server));
// });
// const address = server.address() as net.AddressInfo;
// await new SilentArduinoDaemonImpl(address.port, 'text').spawnDaemonProcess();
// fail('Expected a failure.')
// } catch (e) {
// expect(e).to.be.instanceOf(DaemonError);
// expect(e.code).to.be.equal(DaemonError.ADDRESS_IN_USE);
// } finally {
// if (server) {
// server.close();
// }
// }
// });
it('should parse an error - unknown address [json]', async () => {
try {
await new SilentArduinoDaemonImpl(
'foo',
'json'
).spawnDaemonProcess();
fail('Expected a failure.');
} catch (e) {
expect(e).to.be.instanceOf(DaemonError);
expect(e.code).to.be.equal(DaemonError.UNKNOWN_ADDRESS);
}
});
it('should parse an error - unknown address [json]', async () => {
try {
await new SilentArduinoDaemonImpl('foo', 'json').spawnDaemonProcess();
fail('Expected a failure.');
} catch (e) {
expect(e).to.be.instanceOf(DaemonError);
expect(e.code).to.be.equal(DaemonError.UNKNOWN_ADDRESS);
}
});
it('should parse an error - unknown address [text]', async () => {
try {
await new SilentArduinoDaemonImpl(
'foo',
'text'
).spawnDaemonProcess();
fail('Expected a failure.');
} catch (e) {
expect(e).to.be.instanceOf(DaemonError);
expect(e.code).to.be.equal(DaemonError.UNKNOWN_ADDRESS);
}
});
it('should parse an error - unknown address [text]', async () => {
try {
await new SilentArduinoDaemonImpl('foo', 'text').spawnDaemonProcess();
fail('Expected a failure.');
} catch (e) {
expect(e).to.be.instanceOf(DaemonError);
expect(e.code).to.be.equal(DaemonError.UNKNOWN_ADDRESS);
}
});
it('should parse an error - invalid port [json]', async () => {
try {
await new SilentArduinoDaemonImpl(-1, 'json').spawnDaemonProcess();
fail('Expected a failure.');
} catch (e) {
expect(e).to.be.instanceOf(DaemonError);
expect(e.code).to.be.equal(DaemonError.INVALID_PORT);
}
});
it('should parse an error - invalid port [json]', async () => {
try {
await new SilentArduinoDaemonImpl(-1, 'json').spawnDaemonProcess();
fail('Expected a failure.');
} catch (e) {
expect(e).to.be.instanceOf(DaemonError);
expect(e.code).to.be.equal(DaemonError.INVALID_PORT);
}
});
it('should parse an error - invalid port [text]', async () => {
try {
await new SilentArduinoDaemonImpl(-1, 'text').spawnDaemonProcess();
fail('Expected a failure.');
} catch (e) {
expect(e).to.be.instanceOf(DaemonError);
expect(e.code).to.be.equal(DaemonError.INVALID_PORT);
}
});
it('should parse an error - invalid port [text]', async () => {
try {
await new SilentArduinoDaemonImpl(-1, 'text').spawnDaemonProcess();
fail('Expected a failure.');
} catch (e) {
expect(e).to.be.instanceOf(DaemonError);
expect(e.code).to.be.equal(DaemonError.INVALID_PORT);
}
});
});

View File

@@ -2,56 +2,53 @@ import { expect } from 'chai';
import { DefaultCliConfig } from '../../node/cli-config';
describe('cli-config', () => {
type ConfigProvider = DefaultCliConfig | { (): DefaultCliConfig };
type ConfigProvider = DefaultCliConfig | { (): DefaultCliConfig };
(
[
[defaultConfig, defaultConfig, true],
[
() => {
const conf = defaultConfig();
delete conf.board_manager;
return conf;
},
defaultConfig,
true,
],
[
() => {
const conf = defaultConfig();
(conf.daemon as any).port = String(conf.daemon.port);
return conf;
},
defaultConfig,
true,
],
] as [ConfigProvider, ConfigProvider, boolean][]
).forEach(([leftInput, rightInput, expectation]) => {
const left = typeof leftInput === 'function' ? leftInput() : leftInput;
const right =
typeof rightInput === 'function' ? rightInput() : rightInput;
it(`${JSON.stringify(left)} should ${
expectation ? '' : 'not '
}be the same as ${JSON.stringify(right)}`, () => {
expect(DefaultCliConfig.sameAs(left, right)).to.be.equal(
expectation
);
});
(
[
[defaultConfig, defaultConfig, true],
[
() => {
const conf = defaultConfig();
delete conf.board_manager;
return conf;
},
defaultConfig,
true,
],
[
() => {
const conf = defaultConfig();
(conf.daemon as any).port = String(conf.daemon.port);
return conf;
},
defaultConfig,
true,
],
] as [ConfigProvider, ConfigProvider, boolean][]
).forEach(([leftInput, rightInput, expectation]) => {
const left = typeof leftInput === 'function' ? leftInput() : leftInput;
const right = typeof rightInput === 'function' ? rightInput() : rightInput;
it(`${JSON.stringify(left)} should ${
expectation ? '' : 'not '
}be the same as ${JSON.stringify(right)}`, () => {
expect(DefaultCliConfig.sameAs(left, right)).to.be.equal(expectation);
});
});
function defaultConfig(): DefaultCliConfig {
return {
board_manager: {
additional_urls: [],
},
daemon: {
port: 5000,
},
directories: {
data: 'data',
downloads: 'downloads',
user: 'user',
},
};
}
function defaultConfig(): DefaultCliConfig {
return {
board_manager: {
additional_urls: [],
},
daemon: {
port: 5000,
},
directories: {
data: 'data',
downloads: 'downloads',
user: 'user',
},
};
}
});

View File

@@ -5,29 +5,29 @@ import { getExecPath } from '../../node/exec-util';
use(require('chai-string'));
describe('getExecPath', () => {
it('should resolve arduino-cli', async () => {
const actual = await getExecPath('arduino-cli', onError, 'version');
const expected =
os.platform() === 'win32' ? '\\arduino-cli.exe' : '/arduino-cli';
expect(actual).to.endsWith(expected);
});
it('should resolve arduino-cli', async () => {
const actual = await getExecPath('arduino-cli', onError, 'version');
const expected =
os.platform() === 'win32' ? '\\arduino-cli.exe' : '/arduino-cli';
expect(actual).to.endsWith(expected);
});
it('should resolve arduino-language-server', async () => {
const actual = await getExecPath('arduino-language-server');
const expected =
os.platform() === 'win32'
? '\\arduino-language-server.exe'
: '/arduino-language-server';
expect(actual).to.endsWith(expected);
});
it('should resolve arduino-language-server', async () => {
const actual = await getExecPath('arduino-language-server');
const expected =
os.platform() === 'win32'
? '\\arduino-language-server.exe'
: '/arduino-language-server';
expect(actual).to.endsWith(expected);
});
it('should resolve clangd', async () => {
const actual = await getExecPath('clangd', onError, '--version', true);
const expected = os.platform() === 'win32' ? '\\clangd.exe' : '/clangd';
expect(actual).to.endsWith(expected);
});
it('should resolve clangd', async () => {
const actual = await getExecPath('clangd', onError, '--version', true);
const expected = os.platform() === 'win32' ? '\\clangd.exe' : '/clangd';
expect(actual).to.endsWith(expected);
});
function onError(error: Error): void {
console.error(error);
}
function onError(error: Error): void {
console.error(error);
}
});