Type test scripts for TypeScript testing

TypeScript applications often use untyped JavaScript libraries. To support static type checking of such applications, the typed APIs of the libraries are expressed as separate declaration files. This raises the challenge of checking that the declaration files are correct with respect to the library implementations. Previous work has shown that mismatches are frequent and cause TypeScript's type checker to misguide the programmers by rejecting correct applications and accepting incorrect ones. This paper shows how feedback-directed random testing, which is an automated testing technique that has mostly been used for testing Java libraries, can be adapted to effectively detect such type mismatches. Given a JavaScript library with a TypeScript declaration file, our tool TSTEST generates a "type test script", which is an application that interacts with the library and tests that it behaves according to the type declarations. Compared to alternative solutions that involve static analysis, this approach finds significantly more mismatches in a large collection of real-world JavaScript libraries with TypeScript declaration files, and with fewer false positives. It also has the advantage that reported mismatches are easily reproducible with concrete executions, which aids diagnosis and debugging.

[1]  Jeremy G. Siek Gradual Typing for Functional Languages , 2006 .

[2]  Koushik Sen,et al.  TypeDevil: Dynamic Type Inconsistency Analysis for JavaScript , 2015, 2015 IEEE/ACM 37th IEEE International Conference on Software Engineering.

[3]  Koushik Sen,et al.  DART: directed automated random testing , 2005, PLDI '05.

[4]  Edsger W. Dijkstra,et al.  Notes on structured programming , 1970 .

[5]  Philip Wadler,et al.  Well-Typed Programs Can't Be Blamed , 2009, ESOP.

[6]  Peter Thiemann,et al.  Blame assignment for higher-order contracts with intersection and union , 2015, ICFP.

[7]  Gordon Fraser,et al.  Automated Test Generation for Java Generics , 2014, SWQD.

[8]  Koushik Sen,et al.  Jalangi: a selective record-replay and dynamic analysis framework for JavaScript , 2013, ESEC/FSE 2013.

[9]  Anders Møller,et al.  Checking correctness of TypeScript interfaces for JavaScript libraries , 2014, OOPSLA.

[10]  Steve Hanna,et al.  A Symbolic Execution Framework for JavaScript , 2010, 2010 IEEE Symposium on Security and Privacy.

[11]  Philip Wadler,et al.  Theorems for free! , 1989, FPCA.

[12]  Peter Thiemann,et al.  TreatJS: Higher-Order Contracts for JavaScript , 2015, ArXiv.

[13]  Peter Thiemann,et al.  Type Analysis for JavaScript , 2009, SAS.

[14]  Anders Møller,et al.  Inference and Evolution of TypeScript Declaration Files , 2017, FASE.

[15]  Sam Tobin-Hochstadt,et al.  The design and implementation of typed scheme , 2008, POPL '08.

[16]  Koushik Sen,et al.  CUTE: a concolic unit testing engine for C , 2005, ESEC/FSE-13.

[17]  Gavin M. Bierman,et al.  Safe & Efficient Gradual Typing for TypeScript , 2015, POPL.

[18]  Koen Claessen,et al.  QuickCheck: a lightweight tool for random testing of Haskell programs , 2000, ICFP.

[19]  Frank Tip,et al.  A framework for automated testing of javascript web applications , 2011, 2011 33rd International Conference on Software Engineering (ICSE).

[20]  Walid Taha,et al.  Gradual Typing for Objects , 2007, ECOOP.

[21]  Peter Thiemann,et al.  Contract-Driven Testing of JavaScript Code , 2010, TOOLS.

[22]  Martín Abadi,et al.  Understanding TypeScript , 2014, ECOOP.

[23]  Philip Wadler,et al.  Mixed Messages: Measuring Conformance and Non-Interference in TypeScript , 2017, ECOOP.

[24]  John Tang Boyland,et al.  Refined Criteria for Gradual Typing , 2015, SNAPL.

[25]  Guodong Li,et al.  SymJS: automatic symbolic testing of JavaScript web applications , 2014, SIGSOFT FSE.

[26]  Jim Baker,et al.  Design and evaluation of gradual typing for python , 2014, DLS.

[27]  Michael D. Ernst,et al.  Feedback-Directed Random Test Generation , 2007, 29th International Conference on Software Engineering (ICSE'07).