JSConTest: Contract-Driven Testing for JavaScript

Program understanding is a major obstacle during program maintenance. In an object-oriented language, understanding an operation requires understanding its type and its effect on the object network. The effect is particularly important for scripting languages where there is neither class structure that restricts the shape of an object nor any other kind of access control. We have designed and implemented JSConTest. JSContest is a tool that enhances JavaScript with simple, type-like contracts and provides a framework for monitoring and guided random testing of programs against these contracts at the same time.

JSConTest enables a programmer to gradually introduce partial type and effect specifications in a program. Both specifications take the form of contracts that are monitored at run time. An effect specification restricts the paths that may be accessed from the free variables in scope. JSConTest contains an effect inference algorithm that computes access permissions from sample runs of the program. The resulting effect specifications are concise and precise. They are as good as manually determined ones and sometimes better. Thus, effect inference appears to be a useful tool to analyze JavaScript programs and enhance their contracts with effect information.