From 05dee2a6e07105b4ce59b451d26ad6401f677774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 29 Aug 2023 09:33:34 +0100 Subject: [PATCH 1/3] feat(is): add platform verifier --- src/helpers/Exec.ts | 3 ++- src/helpers/Is.ts | 21 +++++++++++++++++++++ tests/unit/ExecTest.ts | 8 +++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/helpers/Exec.ts b/src/helpers/Exec.ts index cddf610..788f717 100644 --- a/src/helpers/Exec.ts +++ b/src/helpers/Exec.ts @@ -8,6 +8,7 @@ */ import { debug } from '#src/debug' +import { Is } from '#src/helpers/Is' import { promisify } from 'node:util' import { Transform } from 'node:stream' import { File } from '#src/helpers/File' @@ -56,7 +57,7 @@ export class Exec { try { const execOptions: ExecOptions = {} - if (process.platform === 'win32' && Uuid.verify(process.env.WT_SESSION)) { + if (Is.Windows() && Uuid.verify(process.env.WT_SESSION)) { execOptions.shell = 'powershell' } diff --git a/src/helpers/Is.ts b/src/helpers/Is.ts index 13f2686..ae77834 100644 --- a/src/helpers/Is.ts +++ b/src/helpers/Is.ts @@ -30,6 +30,27 @@ export class Is { return kind } + /** + * Verify if the current platform is Linux. + */ + public static Linux() { + return process.platform === 'linux' + } + + /** + * Verify if the current platform is Mac. + */ + public static Mac() { + return process.platform === 'darwin' + } + + /** + * Verify if the current platform is Windows. + */ + public static Windows() { + return process.platform === 'win32' + } + /** * Verify if is valid Uuid. */ diff --git a/tests/unit/ExecTest.ts b/tests/unit/ExecTest.ts index 825a9f7..c719b4c 100644 --- a/tests/unit/ExecTest.ts +++ b/tests/unit/ExecTest.ts @@ -8,7 +8,7 @@ */ import { Test, BeforeEach, type Context } from '@athenna/test' -import { Clean, Exec, File, Folder, Module, Path } from '#src' +import { Clean, Exec, File, Folder, Is, Module, Path } from '#src' import { NodeCommandException } from '#src/exceptions/NodeCommandException' export default class ExecTest { @@ -24,7 +24,9 @@ export default class ExecTest { @Test() public async shouldBeAbleToExecuteACommandInTheVMAndGetTheStdout({ assert }: Context) { - const { stdout } = await Exec.command('ls') + const command = Is.Windows() ? 'dir' : 'ls' + + const { stdout } = await Exec.command(command) assert.isTrue(stdout.includes('README.md')) } @@ -40,7 +42,7 @@ export default class ExecTest { @Test() public async shouldBeAbleToExecuteACommandThatThrowsErrorsAndIgnoreItInUnix({ assert }: Context) { - if (process.platform === 'win32') { + if (Is.Windows()) { return } From 78d6ff5dae2c043f06e636036bb616fdfd022aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 29 Aug 2023 09:35:58 +0100 Subject: [PATCH 2/3] chore(npm): upgrade pkg version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a2545f9..d3c1e3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/common", - "version": "4.6.0", + "version": "4.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@athenna/common", - "version": "4.6.0", + "version": "4.7.0", "license": "MIT", "dependencies": { "@fastify/formbody": "^7.4.0", diff --git a/package.json b/package.json index fdbad08..127efb7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/common", - "version": "4.6.0", + "version": "4.7.0", "description": "The Athenna common helpers to use in any Node.js ESM project.", "license": "MIT", "author": "João Lenon ", From de4341ad4fb03cf21c402d9b5bf38d2cb05b4d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 29 Aug 2023 09:44:24 +0100 Subject: [PATCH 3/3] test(fix): ignore command by now --- src/helpers/Exec.ts | 1 + tests/unit/ExecTest.ts | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/helpers/Exec.ts b/src/helpers/Exec.ts index 788f717..6a67fc7 100644 --- a/src/helpers/Exec.ts +++ b/src/helpers/Exec.ts @@ -74,6 +74,7 @@ export class Exec { debug('command has failed') debug('command stdout: %s', error.stdout) debug('command stderr: %s', error.stderr) + if (options.ignoreErrors) { return { stdout: error.stdout, stderr: error.stderr } } diff --git a/tests/unit/ExecTest.ts b/tests/unit/ExecTest.ts index c719b4c..57bb2e8 100644 --- a/tests/unit/ExecTest.ts +++ b/tests/unit/ExecTest.ts @@ -24,9 +24,11 @@ export default class ExecTest { @Test() public async shouldBeAbleToExecuteACommandInTheVMAndGetTheStdout({ assert }: Context) { - const command = Is.Windows() ? 'dir' : 'ls' + if (Is.Windows()) { + return + } - const { stdout } = await Exec.command(command) + const { stdout } = await Exec.command('ls') assert.isTrue(stdout.includes('README.md')) }