diff --git a/jsdom/jsdom-tests.ts b/jsdom/jsdom-tests.ts new file mode 100644 index 000000000..87eddbfc5 --- /dev/null +++ b/jsdom/jsdom-tests.ts @@ -0,0 +1,72 @@ +import jsdom = require("jsdom"); + +jsdom.env( + "http://nodejs.org/dist/", + ["http://code.jquery.com/jquery.js"], + function (errors, window) { + console.log("there have been nodejs releases!"); + } +); + +jsdom.env( + "http://nodejs.org/dist/", + function (errors, window) { + console.log("there have been nodejs releases!"); + } +); + +jsdom.env( + "http://nodejs.org/dist/", + { + scripts: ["http://code.jquery.com/jquery.js"], + }, + function (errors, window) { + console.log("there have been nodejs releases!"); + } +); + +jsdom.env( + '

jsdom!

', + ["http://code.jquery.com/jquery.js"], + function (errors, window) { + console.log("contents of a.the-link:", (window).$("a.the-link").text()); + } +); + +jsdom.env({ + url: "http://news.ycombinator.com/", + scripts: ["http://code.jquery.com/jquery.js"], + done: function (errors, window) { + var $ = (window).$; + console.log("HN Links"); + $("td.title:not(:last) a").each(function() { + console.log(" -", $(this).text()); + }); + } +}); + +var jquery: string; + +jsdom.env({ + url: "http://news.ycombinator.com/", + src: [jquery], + done: function (errors, window) { + var $ = (window).$; + console.log("HN Links"); + $("td.title:not(:last) a").each(function () { + console.log(" -", $(this).text()); + }); + } +}); + +var window = jsdom.jsdom().parentWindow; +var window = jsdom.jsdom("
foobar
").parentWindow; +var window = jsdom.jsdom("
foobar
", { +scripts: ["http://code.jquery.com/jquery.js"], +done: function (errors, window) { + var $ = (window).$; + console.log("HN Links"); + $("td.title:not(:last) a").each(function() { + console.log(" -", $(this).text()); + }); +}}).parentWindow; \ No newline at end of file diff --git a/jsdom/jsdom.d.ts b/jsdom/jsdom.d.ts new file mode 100644 index 000000000..4dbcb086e --- /dev/null +++ b/jsdom/jsdom.d.ts @@ -0,0 +1,41 @@ +// Type definitions for jsdom 2.0.0 +// Project: https://github.com/tmpvar/jsdom +// Definitions by: Asana +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "jsdom" { + export function env(config: Config): void; + export function env(htmlRef: string, callback: Callback): void; + export function env(htmlRef: string, scripts: string[], callback: Callback): void; + export function env(htmlRef: string, config: Config, callback: Callback): void; + export function env(htmlRef: string, scripts: string[], config: Config, callback: Callback): void; + export function jsdom(markup?: string, options?: Config): Document; + + interface Callback { + (errors: Error[], window: Window): any; + } + + interface Config { + html?: string; + file?: string; + url?: string; + scripts?: string[]; + src?: string[]; + jar?: Object; + parsingMode?: string; + document?: { + referrer?: string; + cookie?: string; + cookieDomain?: string; + }; + headers?: Object; + features?: { + FetchExternalResources?: any; // string | string[] | boolean + ProcessExternalResources?: any; // string | string[] | boolean + SkipExternalResources?: any; // RegExp | boolean + }; + created?: Callback; + loaded?: Callback; + done?: Callback; + } +} \ No newline at end of file