Skip to content
This repository was archived by the owner on Dec 10, 2020. It is now read-only.

Commit 3a4624c

Browse files
committed
Add cli test
1 parent e964276 commit 3a4624c

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ jobs:
3535
- uses: actions/checkout@v2
3636
- run: npm install
3737
- run: npm run test:browser
38+
test-cli:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/setup-node@v1
42+
with:
43+
node-version: 12.x
44+
- uses: actions/checkout@v2
45+
- run: npm install
46+
- run: npm run test:cli

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Coverage Status][coverage-badge]][coverage-link]
66
[![Discord][discord-badge]][discord-link]
77

8-
This is the work repository for the EthereumJS client project targeting both Node.js and the browser as a platform.
8+
This is the work repository for the EthereumJS client project targeting both Node.js and the browser.
99

1010
See [Technical Guidelines](#technical-guidelines) to dive directly into development info.
1111

@@ -31,8 +31,7 @@ For the `ethereumjs` CLI command to work run:
3131
npm link
3232
```
3333

34-
Note: for development purposes you can invoke the client by build with `npm run build:node` and
35-
then run `node ./dist/bin/cli.js`.
34+
Note: for development purposes you can invoke the client with `npm run client:start`
3635

3736
**Running the Client**
3837

@@ -44,7 +43,7 @@ You can run the current state of the client with:
4443
ethereumjs --network=mainnet [--loglevel=debug]
4544
```
4645

47-
For development you might want to connect to `rinkeby` as the network with the currently
46+
For development you might want to connect to `rinkeby` as the network with the currently
4847
most reliable connection:
4948

5049
```shell

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "dist/lib/index.d.ts",
77
"browser": "dist/bundle.js",
88
"bin": {
9-
"ethereumjs": "bin/cli.js"
9+
"ethereumjs": "dist/bin/cli.js"
1010
},
1111
"files": [
1212
"bin",
@@ -17,15 +17,16 @@
1717
"build:node": "tsc -p ./tsconfig.prod.json",
1818
"build:browser": "tsc -p ./tsconfig.browser.json && npm run bundle && rm -rf dist.browser",
1919
"bundle": "webpack",
20-
"client:start": "tsc -p tsconfig.prod.json && node dist/bin/cli.js",
20+
"client:start": "ts-node bin/cli.ts",
2121
"coverage": "nyc npm run test && nyc report --reporter=lcov",
2222
"docs:build": "typedoc --tsconfig tsconfig.prod.json",
2323
"lint": "ethereumjs-config-lint",
2424
"lint:fix": "ethereumjs-config-lint-fix",
2525
"tape": "tape -r ts-node/register",
2626
"test": "npm run test:unit && npm run test:integration",
27-
"test:unit": "npm run tape -- 'test/!(integration)/**/*.spec.ts'",
27+
"test:unit": "npm run tape -- 'test/!(integration|cli)/**/*.spec.ts'",
2828
"test:integration": "npm run tape -- 'test/integration/**/*.spec.ts'",
29+
"test:cli": "npm run build:node && npm run tape -- 'test/cli/*.spec.ts'",
2930
"test:browser": "karma start karma.conf.js"
3031
},
3132
"husky": {

test/cli/cli.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { spawn } from 'child_process'
2+
import tape from 'tape'
3+
4+
tape('[CLI]', (t) => {
5+
t.test('should begin downloading blocks', { timeout: 260000 }, (t) => {
6+
const file = require.resolve('../../dist/bin/cli.js')
7+
const child = spawn(process.execPath, [file])
8+
9+
const timeout = setTimeout(() => {
10+
child.kill('SIGINT')
11+
t.fail('timed out before finishing')
12+
t.end()
13+
}, 240000)
14+
15+
const end = () => {
16+
clearTimeout(timeout)
17+
child.kill('SIGINT')
18+
t.end()
19+
}
20+
21+
child.stdout.on('data', (data) => {
22+
const message = data.toString()
23+
if (message.toLowerCase().includes('error')) {
24+
t.fail(message)
25+
end()
26+
}
27+
if (message.includes('Imported blocks')) {
28+
t.pass('successfully imported blocks')
29+
end()
30+
}
31+
// log for easier debugging
32+
// eslint-disable-next-line no-console
33+
console.log(message)
34+
})
35+
36+
child.stderr.on('data', (data) => {
37+
const message = data.toString()
38+
t.fail(`stderr: ${message}`)
39+
end()
40+
})
41+
42+
child.on('close', (code) => {
43+
if (code !== 0) {
44+
t.fail(`child process exited with code ${code}`)
45+
end()
46+
}
47+
})
48+
})
49+
})

0 commit comments

Comments
 (0)