Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Factor out and use some test helpers for file URLs.

  • Loading branch information...
commit f9b0c95cf5ba1a0748e0e257faba8751191776c2 1 parent 1b342a1
@domenic domenic authored
Showing with 27 additions and 14 deletions.
  1. +2 −1  test/jsdom/index.js
  2. +4 −13 test/level2/html.js
  3. +21 −0 test/util.js
View
3  test/jsdom/index.js
@@ -1,6 +1,7 @@
var path = require("path");
var fs = require("fs");
var jsdom = require('../../lib/jsdom');
+var toFileUrl = require('../util').toFileUrl(__dirname);
exports.tests = {
build_window: function(test) {
@@ -482,7 +483,7 @@ exports.tests = {
var html = '\
<html>\
<head>\
- <script type="text/javascript" src="file://'+__dirname+'/files/hello.js"></script>\
+ <script type="text/javascript" src="' + toFileUrl('files/hello.js') + '"></script>\
</head>\
<body>\
<span id="test">hello from html</span>\
View
17 test/level2/html.js
@@ -1,6 +1,9 @@
var fs = require('fs');
var path = require('path');
var jsdom = require("../../lib/jsdom");
+var toPathname = require("../util").toPathname(__dirname);
+var toFileUrl = require("../util").toFileUrl(__dirname);
+
var fileCache = {};
var load = function(name, options) {
options || (options = {});
@@ -28,18 +31,6 @@ var getImplementation = function() {
return doc.implementation;
};
-var toFileUrl = function(relativePath) {
- return 'file://' + toPathname(relativePath);
-};
-
-var toPathname = function(relativePath) {
- var pathname = path.resolve(__dirname, relativePath).replace(/\\/g, '/');
- if (pathname[0] !== '/') {
- pathname = '/' + pathname;
- }
- return pathname;
-}
-
exports.tests = {
/**
*
@@ -19800,7 +19791,7 @@ exports.tests = {
var img = doc.getElementsByTagName("img").item(0);
test.strictEqual(img.src, "src", "<img> elements should not have their attribute properties masked by defining a normalize method on string instances");
-
+
delete String.prototype.normalize;
test.done();
}
View
21 test/util.js
@@ -0,0 +1,21 @@
+var path = require('path');
+
+function toPathname(dirname, relativePath) {
+ var pathname = path.resolve(dirname, relativePath).replace(/\\/g, '/');
+ if (pathname[0] !== '/') {
+ pathname = '/' + pathname;
+ }
+ return pathname;
+}
+
+exports.toFileUrl = function (dirname) {
+ return function (relativePath) {
+ return 'file://' + toPathname(dirname, relativePath);
+ };
+};
+
+exports.toPathname = function (dirname) {
+ return function (relativePath) {
+ return toPathname(dirname, relativePath);
+ };
+};
Please sign in to comment.
Something went wrong with that request. Please try again.