Skip to content

Commit

Permalink
add a "global entropy" test for --help (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiebee authored Sep 24, 2024
1 parent 988555a commit c855201
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions tests/global.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})
16 changes: 16 additions & 0 deletions tests/testing-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { exec } from 'node:child_process'
// @ts-ignore
import { spinNetworkUp, spinNetworkDown, } from "@entropyxyz/sdk/testing"
import * as readline from 'readline'
Expand All @@ -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<any> {
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.
*
Expand Down

0 comments on commit c855201

Please sign in to comment.