This repository was archived by the owner on Jan 31, 2023. It is now read-only.
File tree 2 files changed +19
-3
lines changed 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
- let through = require ( 'through2' )
1
+ const through = require ( 'through2' )
2
+ const path = require ( 'path' )
2
3
3
4
const isJson = ( code ) => {
4
5
try {
@@ -14,8 +15,9 @@ const isJson = (code) => {
14
15
// It means it should check types whenever spec file is changed
15
16
// and it slows down the test speed a lot.
16
17
// We skip this slow type-checking process by using transpileModule() api.
17
- module . exports = function ( b , opts ) {
18
+ module . exports = function ( filePath , opts ) {
18
19
const chunks = [ ]
20
+ const ext = path . extname ( filePath )
19
21
20
22
return through (
21
23
( buf , enc , next ) => {
@@ -32,7 +34,7 @@ module.exports = function (b, opts) {
32
34
this . push ( ts . transpileModule ( text , {
33
35
compilerOptions : {
34
36
esModuleInterop : true ,
35
- jsx : ' react',
37
+ jsx : ext === '.tsx' || ext === '.jsx' || ext === '.js' ? ' react' : undefined ,
36
38
downlevelIteration : true ,
37
39
} ,
38
40
} ) . outputText )
Original file line number Diff line number Diff line change @@ -5,6 +5,13 @@ const { add } = math
5
5
6
6
const x : number = 3
7
7
8
+ // ensures that generics can be properly compiled and not treated
9
+ // as react components in `.ts` files.
10
+ // https://github.com/cypress-io/cypress-browserify-preprocessor/issues/44
11
+ const isKeyOf = < T > ( obj : T , key : any ) : key is keyof T => {
12
+ return typeof key === 'string' && key in obj ;
13
+ }
14
+
8
15
context ( 'math.ts' , function ( ) {
9
16
it ( 'imports function' , ( ) => {
10
17
expect ( add , 'add' ) . to . be . a ( 'function' )
@@ -20,4 +27,11 @@ context('math.ts', function () {
20
27
21
28
expect ( arr [ 0 ] + arr [ 1 ] ) . to . eq ( 1 )
22
29
} )
30
+ it ( 'Test generic' , ( ) => {
31
+ const x = {
32
+ key : 'value'
33
+ }
34
+
35
+ expect ( isKeyOf ( x , 'key' ) ) . to . eq ( true )
36
+ } )
23
37
} )
You can’t perform that action at this time.
0 commit comments