This repository was archived by the owner on Jan 31, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 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' )
23
34const isJson = ( code ) => {
45 try {
@@ -14,8 +15,9 @@ const isJson = (code) => {
1415// It means it should check types whenever spec file is changed
1516// and it slows down the test speed a lot.
1617// We skip this slow type-checking process by using transpileModule() api.
17- module . exports = function ( b , opts ) {
18+ module . exports = function ( filePath , opts ) {
1819 const chunks = [ ]
20+ const ext = path . extname ( filePath )
1921
2022 return through (
2123 ( buf , enc , next ) => {
@@ -32,7 +34,7 @@ module.exports = function (b, opts) {
3234 this . push ( ts . transpileModule ( text , {
3335 compilerOptions : {
3436 esModuleInterop : true ,
35- jsx : ' react',
37+ jsx : ext === '.tsx' || ext === '.jsx' || ext === '.js' ? ' react' : undefined ,
3638 downlevelIteration : true ,
3739 } ,
3840 } ) . outputText )
Original file line number Diff line number Diff line change @@ -5,6 +5,13 @@ const { add } = math
55
66const x : number = 3
77
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+
815context ( 'math.ts' , function ( ) {
916 it ( 'imports function' , ( ) => {
1017 expect ( add , 'add' ) . to . be . a ( 'function' )
@@ -20,4 +27,11 @@ context('math.ts', function () {
2027
2128 expect ( arr [ 0 ] + arr [ 1 ] ) . to . eq ( 1 )
2229 } )
30+ it ( 'Test generic' , ( ) => {
31+ const x = {
32+ key : 'value'
33+ }
34+
35+ expect ( isKeyOf ( x , 'key' ) ) . to . eq ( true )
36+ } )
2337} )
You can’t perform that action at this time.
0 commit comments