diff --git a/rewire/rewire-tests.ts b/rewire/rewire-tests.ts
new file mode 100644
index 000000000..3e81050e4
--- /dev/null
+++ b/rewire/rewire-tests.ts
@@ -0,0 +1,48 @@
+///
+
+var myModule = rewire("../lib/myModule.js");
+
+myModule.__set__("path", "/dev/null");
+myModule.__get__("path"); // = '/dev/null'
+
+var fsMock = {
+ readFile: function (path: string, encoding: string, cb: Function) {
+ cb(null, "Success!");
+ }
+};
+myModule.__set__("fs", fsMock);
+
+myModule.__set__({
+ fs: fsMock,
+ path: "/dev/null"
+});
+
+myModule.__set__({
+ console: {
+ log: function () { /* be quiet */ }
+ },
+ process: {
+ argv: ["testArg1", "testArg2"]
+ }
+});
+
+var revert = myModule.__set__("port", 3000);
+
+// port is now 3000
+revert();
+// port is now the previous value
+
+myModule.__with__({
+ port: 3000
+})(function () {
+ // within this function port is 3000
+});
+// now port is the previous value again
+
+myModule.__with__({
+ port: 3000
+})(function () {
+}).then(function () {
+ // now port is the previous value again
+});
+// port is still 3000 here because the promise hasn't been resolved yet
diff --git a/rewire/rewire.d.ts b/rewire/rewire.d.ts
new file mode 100644
index 000000000..78ece94ee
--- /dev/null
+++ b/rewire/rewire.d.ts
@@ -0,0 +1,38 @@
+// Type definitions for rewire v2.5.1
+// Project: https://github.com/jhnns/rewire
+// Definitions by: Borislav Zhivkov
+// Definitions: https://github.com/borisyankov/DefinitelyTyped
+
+declare module RewireInterfaces {
+ interface Rewire {
+ /**
+ * Returns a rewired version of the module found at filename. Use rewire() exactly like require().
+ */
+ (filename: string): RewiredModule;
+ }
+
+ interface RewiredModule {
+ /**
+ * Takes all enumerable keys of obj as variable names and sets the values respectively. Returns a function which can be called to revert the change.
+ */
+ __set__(obj: Object): Function;
+ /**
+ * Sets the internal variable name to the given value. Returns a function which can be called to revert the change.
+ */
+ __set__(name: string, value: any): Function;
+ /**
+ * Returns the private variable with the given name.
+ */
+ __get__(name: string): any;
+ /**
+ * Returns a function which - when being called - sets obj, executes the given callback and reverts obj. If callback returns a promise, obj is only reverted after
+ * the promise has been resolved or rejected. For your convenience the returned function passes the received promise through.
+ */
+ __with__(obj: Object): (callback: Function) => any;
+ }
+}
+
+declare var rewire: RewireInterfaces.Rewire;
+declare module "rewire" {
+ export = rewire;
+}