diff --git a/package.json b/package.json index 114e118..cd8e30b 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,8 @@ "homepage": "https://github.com/mozilla/readability", "devDependencies": { "chai": "^2.1.*", - "chai-as-promised": "^4.3.*", "html": "0.0.*", - "mocha": "^2.2.*", - "readable-proxy": "1.3.*" + "jsdom": "^3.1.2", + "mocha": "^2.2.*" } } diff --git a/test/index.js b/test/index.js index 4610c0a..b9f1007 100644 --- a/test/index.js +++ b/test/index.js @@ -1,11 +1,8 @@ var path = require("path"); var fs = require("fs"); +var jsdom = require("jsdom"); var prettyPrint = require("html").prettyPrint; -var chai = require("chai"); -var chaiAsPromised = require("chai-as-promised"); -chai.should(); -chai.use(chaiAsPromised); -var expect = chai.expect; +var expect = require("chai").expect; var testPageRoot = path.join(__dirname, "test-pages"); var testPages = fs.readdirSync(testPageRoot).map(function(dir) { @@ -17,32 +14,30 @@ var testPages = fs.readdirSync(testPageRoot).map(function(dir) { }); describe("Test page", function() { - var oldLibPath = process.env.READABILITY_LIB_PATH; - process.env.READABILITY_LIB_PATH = path.join(__dirname, "..", "Readability.js"); - var scrape = require("readable-proxy").scrape; testPages.forEach(function(testPage) { describe(testPage.dir, function() { - it("should render as expected", function() { - // Allows up to 10 seconds for parsing to complete. - // XXX: Scraping is damn slow. Investigate. - this.timeout(10000); + it("should render as expected", function(done) { var expected = fs.readFileSync(testPage.expected, {encoding: "utf-8"}); - return scrape("file://" + testPage.source).catch(function(err) { - throw err; - }).then(function(result) { - // print Readability log messages - (result.consoleLogs || []) - .filter(function(logMessage) { - return logMessage.indexOf("Reader: (Readability)") === 0; - }) - .forEach(function(logMessage) { - console.log("[LOG]", logMessage); - }); - // normalize html - return prettyPrint(result.content); - }).should.eventually.become(prettyPrint(expected)); + jsdom.env( + fs.readFileSync(testPage.source, {encoding: "utf-8"}), + [path.join(__dirname, "..", "Readability.js")], + function (errors, window) { + if (errors) { + throw new Error(errors); + } + var uri = { + spec: "http://fakehost/test/page.html", + host: "fakehost", + prePath: "http://fakehost", + scheme: "http", + pathBase: "http://fakehost/test" + }; + var result = new window.Readability(uri, window.document).parse(); + expect(prettyPrint(result.content)).eql(prettyPrint(expected)) + done(); + } + ); }); }); }); - process.env.READABILITY_LIB_PATH = oldLibPath; }); diff --git a/test/test-pages/001/expected.html b/test/test-pages/001/expected.html index 3ba79a2..e02c492 100644 --- a/test/test-pages/001/expected.html +++ b/test/test-pages/001/expected.html @@ -1,5 +1,5 @@
-

So finally you're testing your frontend JavaScript code? Great! The more you +

So finally you're testing your frontend JavaScript code? Great! The more you write tests, the more confident you are with your codeā€¦ but how much precisely? That's where code coverage might help.

@@ -24,7 +24,7 @@ matter of adding this simple line to your HTML test file:

Source files: blanket.js, mocha-blanket.js

-

As an example, let's reuse the silly Cow example we used in a previous episode:

+

As an example, let's reuse the silly Cow example we used in a previous episode:

// cow.js
 (function(exports) {
   "use strict";
@@ -98,7 +98,7 @@ Mocha:

  • The HTML test file must be served over HTTP for the adapter to be loaded.
  • Running the tests now gives us something like this:

    -

    screenshot

    +

    screenshot

    As you can see, the report at the bottom highlights that we haven't actually tested the case where an error is raised in case a target name is missing. We've been informed of that, nothing more, nothing less. We simply know we're