From 3a4624cf58ad88162ada8fbec9c27187f19f9efc Mon Sep 17 00:00:00 2001 From: Ryan Ghods Date: Tue, 3 Nov 2020 12:39:34 -0800 Subject: [PATCH] Add cli test --- .github/workflows/build.yml | 9 +++++++ README.md | 7 +++--- package.json | 7 +++--- test/cli/cli.spec.ts | 49 +++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 test/cli/cli.spec.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 48843dc..d3b28bb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,3 +35,12 @@ jobs: - uses: actions/checkout@v2 - run: npm install - run: npm run test:browser + test-cli: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v1 + with: + node-version: 12.x + - uses: actions/checkout@v2 + - run: npm install + - run: npm run test:cli diff --git a/README.md b/README.md index 495bc20..4bedc90 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Coverage Status][coverage-badge]][coverage-link] [![Discord][discord-badge]][discord-link] -This is the work repository for the EthereumJS client project targeting both Node.js and the browser as a platform. +This is the work repository for the EthereumJS client project targeting both Node.js and the browser. See [Technical Guidelines](#technical-guidelines) to dive directly into development info. @@ -31,8 +31,7 @@ For the `ethereumjs` CLI command to work run: npm link ``` -Note: for development purposes you can invoke the client by build with `npm run build:node` and -then run `node ./dist/bin/cli.js`. +Note: for development purposes you can invoke the client with `npm run client:start` **Running the Client** @@ -44,7 +43,7 @@ You can run the current state of the client with: ethereumjs --network=mainnet [--loglevel=debug] ``` -For development you might want to connect to `rinkeby` as the network with the currently +For development you might want to connect to `rinkeby` as the network with the currently most reliable connection: ```shell diff --git a/package.json b/package.json index 584148c..5659919 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "types": "dist/lib/index.d.ts", "browser": "dist/bundle.js", "bin": { - "ethereumjs": "bin/cli.js" + "ethereumjs": "dist/bin/cli.js" }, "files": [ "bin", @@ -17,15 +17,16 @@ "build:node": "tsc -p ./tsconfig.prod.json", "build:browser": "tsc -p ./tsconfig.browser.json && npm run bundle && rm -rf dist.browser", "bundle": "webpack", - "client:start": "tsc -p tsconfig.prod.json && node dist/bin/cli.js", + "client:start": "ts-node bin/cli.ts", "coverage": "nyc npm run test && nyc report --reporter=lcov", "docs:build": "typedoc --tsconfig tsconfig.prod.json", "lint": "ethereumjs-config-lint", "lint:fix": "ethereumjs-config-lint-fix", "tape": "tape -r ts-node/register", "test": "npm run test:unit && npm run test:integration", - "test:unit": "npm run tape -- 'test/!(integration)/**/*.spec.ts'", + "test:unit": "npm run tape -- 'test/!(integration|cli)/**/*.spec.ts'", "test:integration": "npm run tape -- 'test/integration/**/*.spec.ts'", + "test:cli": "npm run build:node && npm run tape -- 'test/cli/*.spec.ts'", "test:browser": "karma start karma.conf.js" }, "husky": { diff --git a/test/cli/cli.spec.ts b/test/cli/cli.spec.ts new file mode 100644 index 0000000..acb7f64 --- /dev/null +++ b/test/cli/cli.spec.ts @@ -0,0 +1,49 @@ +import { spawn } from 'child_process' +import tape from 'tape' + +tape('[CLI]', (t) => { + t.test('should begin downloading blocks', { timeout: 260000 }, (t) => { + const file = require.resolve('../../dist/bin/cli.js') + const child = spawn(process.execPath, [file]) + + const timeout = setTimeout(() => { + child.kill('SIGINT') + t.fail('timed out before finishing') + t.end() + }, 240000) + + const end = () => { + clearTimeout(timeout) + child.kill('SIGINT') + t.end() + } + + child.stdout.on('data', (data) => { + const message = data.toString() + if (message.toLowerCase().includes('error')) { + t.fail(message) + end() + } + if (message.includes('Imported blocks')) { + t.pass('successfully imported blocks') + end() + } + // log for easier debugging + // eslint-disable-next-line no-console + console.log(message) + }) + + child.stderr.on('data', (data) => { + const message = data.toString() + t.fail(`stderr: ${message}`) + end() + }) + + child.on('close', (code) => { + if (code !== 0) { + t.fail(`child process exited with code ${code}`) + end() + } + }) + }) +})