diff --git a/package.json b/package.json index 55bf10ac..19b4c70a 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,12 @@ "description": "cli and tui for interacting with the entropy protocol", "type": "module", "scripts": { - "start": "yarn build && npm install -g && entropy", + "start": "yarn build:global && entropy", "start:debug": "DEBUG=@entropyxyz/cli yarn start", "build": "tsup", - "test": "yarn test:types && yarn test:ts && yarn test:only", + "build:global": "tsup && npm install -g", "lint": "eslint . --ext .ts --fix", + "test": "yarn test:types && yarn build:global && yarn test:ts && yarn test:only", "test:only": "./dev/bin/test-only.sh", "test:ts": "yarn removedb && ./dev/bin/test-ts.sh", "test:types": "tsc --project tsconfig.json", diff --git a/tests/global.test.ts b/tests/global.test.ts new file mode 100644 index 00000000..bff68d43 --- /dev/null +++ b/tests/global.test.ts @@ -0,0 +1,14 @@ +import test from 'tape' + +import { + promiseRunner, + execPromise +} from './testing-utils' + +test('Global: entropy --help', async (t) => { + /* Setup */ + const run = promiseRunner(t) + + await run('should run the global entropy --help', execPromise('entropy --help')) + t.end() +}) \ No newline at end of file diff --git a/tests/testing-utils/index.ts b/tests/testing-utils/index.ts index 99cfde31..a6eae14a 100644 --- a/tests/testing-utils/index.ts +++ b/tests/testing-utils/index.ts @@ -1,3 +1,4 @@ +import { exec } from 'node:child_process' // @ts-ignore import { spinNetworkUp, spinNetworkDown, } from "@entropyxyz/sdk/testing" import * as readline from 'readline' @@ -11,6 +12,21 @@ export { export * from './constants' export * from './setup-test' +/* Promise wrapper function of [exec](https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback) + * + * @param {string} command - a string command to run in child process + */ + +export function execPromise (command: string): Promise { + return new Promise((res, rej) => { + exec(command, (error, stdout, stderr) => { + if (!error && !stderr) res(stdout) + else if (!!stderr && !error) rej(stderr) + else if (!!error) rej(error) + }) + }) +} + /* Helper for wrapping promises which makes it super clear in logging if the promise * resolves or threw. *