Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 2bfd780

Browse files
committed
test: add cli test
1 parent f7ae784 commit 2bfd780

File tree

3 files changed

+92
-3
lines changed

3 files changed

+92
-3
lines changed

package-lock.json

Lines changed: 63 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@knisterpeter/standard-tslint": "^1.6.0",
4141
"@types/babel-generator": "^6.25.0",
4242
"@types/diff": "^3.2.2",
43+
"@types/execa": "0.8.0",
4344
"@types/node": "^8.0.50",
4445
"@types/prop-types": "15.5.2",
4546
"@types/react": "^16.0.21",
@@ -52,6 +53,7 @@
5253
"coveralls": "^3.0.0",
5354
"cz-conventional-changelog": "2.1.0",
5455
"diff": "3.4.0",
56+
"execa": "0.8.0",
5557
"nyc": "11.3.0",
5658
"prop-types": "15.6.0",
5759
"react": "^16.0.0",

tests/cli-test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import test from 'ava';
2+
import { shell } from 'execa';
3+
import * as fs from 'fs';
4+
5+
function normalize(input: string): string {
6+
return input
7+
.replace(/\s+/g, ' ')
8+
.replace(/ => /g, '=>');
9+
}
10+
11+
test('cli should read from stdin', async t => {
12+
const expected = fs.readFileSync('./tests/import-react-component.d.ts').toString();
13+
14+
const result = await shell(
15+
`cat ./tests/import-react-component.jsx |${process.argv[0]} ./cli.js --module-name component`);
16+
17+
t.is(normalize(result.stdout), normalize(expected));
18+
});
19+
20+
test('cli should read from file', async t => {
21+
const expected = fs.readFileSync('./tests/import-react-component.d.ts').toString();
22+
23+
const result = await shell(
24+
`${process.argv[0]} ./cli.js --module-name component --file ./tests/import-react-component.jsx`);
25+
26+
t.is(normalize(result.stdout), normalize(expected));
27+
});

0 commit comments

Comments
 (0)