Merge pull request #3437 from Asana/jsdom

Adding a JsDom type definition
This commit is contained in:
Masahiro Wakame
2015-01-11 12:16:28 +09:00
2 changed files with 113 additions and 0 deletions
+72
View File
@@ -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(
'<p><a class="the-link" href="https://github.com/tmpvar/jsdom">jsdom!</a></p>',
["http://code.jquery.com/jquery.js"],
function (errors, window) {
console.log("contents of a.the-link:", (<any>window).$("a.the-link").text());
}
);
jsdom.env({
url: "http://news.ycombinator.com/",
scripts: ["http://code.jquery.com/jquery.js"],
done: function (errors, window) {
var $ = (<any>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 $ = (<any>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("<div>foobar</div>").parentWindow;
var window = jsdom.jsdom("<div>foobar</div>", {
scripts: ["http://code.jquery.com/jquery.js"],
done: function (errors, window) {
var $ = (<any>window).$;
console.log("HN Links");
$("td.title:not(:last) a").each(function() {
console.log(" -", $(this).text());
});
}}).parentWindow;
+41
View File
@@ -0,0 +1,41 @@
// Type definitions for jsdom 2.0.0
// Project: https://github.com/tmpvar/jsdom
// Definitions by: Asana <https://asana.com>
// 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;
}
}