Skip to content

Commit c445879

Browse files
Add support for JSX - fixes #15 (#36)
1 parent 03c170b commit c445879

File tree

17 files changed

+108
-22
lines changed

17 files changed

+108
-22
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
},
5050
"devDependencies": {
5151
"@types/node": "^11.10.4",
52+
"@types/react": "^16.9.2",
5253
"@types/update-notifier": "^2.2.0",
5354
"ava": "^1.4.1",
5455
"cpy-cli": "^2.0.0",
5556
"del-cli": "^1.1.0",
57+
"react": "^16.9.0",
5658
"tslint": "^5.11.0",
5759
"tslint-xo": "^0.9.0"
5860
}

source/lib/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ const findTypingsFile = async (pkg: any, options: Options) => {
2525

2626
const findTestFiles = async (typingsFile: string, options: Options & {config: Config}) => {
2727
const testFile = typingsFile.replace(/\.d\.ts$/, '.test-d.ts');
28+
const tsxTestFile = typingsFile.replace(/\.d\.ts$/, '.test-d.tsx');
2829
const testDir = options.config.directory;
2930

30-
const testFileExists = await pathExists(path.join(options.cwd, testFile));
31+
let testFiles = await globby([testFile, tsxTestFile], {cwd: options.cwd});
32+
3133
const testDirExists = await pathExists(path.join(options.cwd, testDir));
3234

33-
if (!testFileExists && !testDirExists) {
34-
throw new Error(`The test file \`${testFile}\` does not exist. Create one and try again.`);
35+
if (testFiles.length === 0 && !testDirExists) {
36+
throw new Error(`The test file \`${testFile}\` or \`${tsxTestFile}\` does not exist. Create one and try again.`);
3537
}
3638

37-
let testFiles = [testFile];
38-
39-
if (!testFileExists) {
40-
testFiles = await globby(`${testDir}/**/*.ts`, {cwd: options.cwd});
39+
if (testFiles.length === 0) {
40+
testFiles = await globby([`${testDir}/**/*.ts`, `${testDir}/**/*.tsx`], {cwd: options.cwd});
4141
}
4242

4343
return testFiles;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
declare const document: Document;
1+
declare const window: Window;
22

3-
export default document;
3+
export default window;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports.default = window.document;
1+
module.exports.default = window;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import {expectType} from '../../../..';
2-
import document from '.';
2+
import window from '.';
33

4-
expectType<Document>(document);
4+
expectType<Window>(window);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference lib="dom"/>
22

3-
declare const document: Document;
3+
declare const window: Window;
44

5-
export default document;
5+
export default window;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports.default = window.document;
1+
module.exports.default = window;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import {expectType} from '../../../..';
2-
import document from '.';
2+
import window from '.';
33

4-
expectType<Document>(document);
4+
expectType<Window>(window);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {Component} from 'react';
2+
3+
interface UnicornProps {
4+
rainbow: string;
5+
}
6+
7+
export class Unicorn extends Component<UnicornProps> {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
const React = require('react');
3+
4+
export class Unicorn extends React.Component {
5+
constructor(props) {
6+
super(props);
7+
}
8+
9+
render() {
10+
return <h1>{this.props.rainbow}</h1>;
11+
}
12+
}

0 commit comments

Comments
 (0)