app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } });
// Helper to determine whether we should exclude const shouldExclude = (excludes = []) => { // Only do this on non linux if (process.platform === 'linux') return false; // Otherwise return if we have non-empty config return !_.isEmpty(getExcludes(excludes)); }
test('node correctly use nodePath', async t => { const {stdout} = await execa.node(process.platform === 'win32' ? 'hello.cmd' : 'hello.sh', { stdout: 'pipe', nodePath: process.platform === 'win32' ? 'cmd.exe' : 'bash', nodeOptions: process.platform === 'win32' ? ['/c'] : [] }); t.is(stdout, 'Hello World'); });
updateDisks() { if (!PLATFORMS_SUPPORTED.includes(process.platform)) { return Promise.resolve([]); } return diskUsage[process.platform]().then(disks => { if (disks.length !== this.disks.length || disks.some((d, i) => d.used !== this.disks[i].used)) { this.tLastChange = Date.now(); this.disks = disks; this.emit(diskUsageServiceEvents.DISK_USAGE_CHANGE, this.getDiskUsage()); } }); }
test('use extend environment with `extendEnv: true` and `shell: true`', async t => { process.env.TEST = 'test'; const command = process.platform === 'win32' ? 'echo %TEST%' : 'echo $TEST'; const {stdout} = await execa(command, {shell: true, env: {}, extendEnv: true}); t.is(stdout, 'test'); delete process.env.TEST; });
/* * Helper to parse nginx config */ const parseNginx = options => { options.command = (process.platform !== 'win32') ? ['php-fpm'] : ['php-fpm -R']; options.image = 'fpm'; options.remoteFiles.vhosts = '/opt/bitnami/nginx/conf/lando.conf'; options.defaultFiles.vhosts = (options.ssl) ? 'default-ssl.conf.tpl' : 'default.conf.tpl'; options.nginxSsl = options.ssl; options.ssl = false; if (process.platform === 'win32') { options.volumes.push(`${options.confDest}/zz-lando.conf:/usr/local/etc/php-fpm.d/zz-lando.conf`); } options.remoteFiles.pool = '/usr/local/etc/php-fpm.d/zz-lando.conf'; return options; }
test('localDir option', async t => { const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH'; const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'}); const envPaths = stdout.split(path.delimiter); t.true(envPaths.some(envPath => envPath.endsWith('.bin'))); });
/* * Helper to get an executable */ const getDockerBin = (bin, base) => { // Do platform appropriate things to get started const join = (process.platform === 'win32') ? path.win32.join : path.posix.join; let binPath = (process.platform === 'win32') ? join(base, `${bin}.exe`) : join(base, bin); // Use PATH compose executable on posix if ours does not exist if (process.platform !== 'win32' && (!fs.existsSync(binPath) || fs.statSync(binPath).isDirectory())) { binPath = _.toString(shell.which(bin)); } // If the binpath still does not exist then we should set to false and handle downstream if (!fs.existsSync(binPath)) return false; // Otherwise return a normalized binpath switch (process.platform) { case 'darwin': return path.posix.normalize(binPath); case 'linux': return path.posix.normalize(binPath); case 'win32': return path.win32.normalize(binPath); } }
test('error.killed is false if process was killed indirectly', async t => { const subprocess = execa('noop'); process.kill(subprocess.pid, 'SIGINT'); // `process.kill()` is emulated by Node.js on Windows const message = process.platform === 'win32' ? /failed with exit code 1/ : /was killed with SIGINT/; const {killed} = await t.throwsAsync(subprocess, {message}); t.false(killed); });
// Helper to determine whether we should use mutagen or not const shouldMutagen = (dockerVersion = '0.0.0') => { // Only do this on non linux if (process.platform !== 'darwin') return false; // Otherwise return if we have sufficient docker version return semver.gte(dockerVersion, '2.3.30'); }
/* * Get services wrapper */ const buildDockerCmd = cmd => { switch (process.platform) { case 'darwin': return ['open', macOSBase]; case 'linux': if (_.includes(_.toString(shell.which('systemctl')), 'systemctl')) { return ['sudo', 'systemctl', cmd, 'docker']; } else { return ['sudo', 'service', 'docker'].concat(cmd); } case 'win32': const base = process.env.ProgramW6432 || process.env.ProgramFiles; const dockerBin = base + '\\Docker\\Docker\\Docker Desktop.exe'; return ['cmd', '/C', `"${dockerBin}"`]; } }
this.interval = 0; if (!PLATFORMS_SUPPORTED.includes(process.platform)) { console.log(`warning: DiskUsageService is only supported in ${PLATFORMS_SUPPORTED.join()}`); return;
test('write to fast-exit process', async t => { // Try-catch here is necessary, because this test is not 100% accurate // Sometimes process can manage to accept input before exiting try { await execa(`fast-exit-${process.platform}`, [], {input: 'data'}); t.pass(); } catch (error) { t.is(error.code, 'EPIPE'); } });
test('can use `options.shell: string`', async t => { const shell = process.platform === 'win32' ? 'cmd.exe' : '/bin/bash'; const {stdout} = await execa('node test/fixtures/noop foo', {shell}); t.is(stdout, 'foo'); });
app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } });