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

Commit

Permalink
Add cli test
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Nov 3, 2020
1 parent a7c24ed commit 9478e5a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
"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 coverage:test && nyc report --reporter=lcov",
"coverage:test": "tape -r ts-node/register 'test/!(integration)/**/*.ts' 'test/integration/**/*.ts'",
"coverage:test": "npm run tape -- 'test/!(integration|cli)/**/*.ts' 'test/integration/**/*.ts'",
"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)/**/*.ts'",
"test:unit": "npm run tape -- 'test/!(integration|cli)/**/*.ts'",
"test:integration": "npm run tape -- 'test/integration/**/*.ts'",
"test:cli": "npm run build:node && npm run tape -- 'test/cli/*.ts'",
"test:browser": "karma start karma.conf.js"
},
"husky": {
Expand Down
45 changes: 45 additions & 0 deletions test/cli/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import tape from 'tape'
import { spawn } from 'child_process'

tape('[CLI]', (t) => {
t.test('should start and begin downloading blocks', (t) => {
const file = require.resolve('../../dist/bin/cli.js')
const child = spawn(process.execPath, [file])

const timeout = setTimeout(() => {
child.kill('SIGINT')
}, 120000)

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()
end()
}
console.log(message) // eslint-disable-line no-console
})

child.stderr.on('data', (data) => {
const message = data.toString()
t.fail(message)
end()
})

child.on('close', (code) => {
if (code !== 0) {
t.fail(`child process exited with code ${code}`)
end()
}
})
})
})

0 comments on commit 9478e5a

Please sign in to comment.