From 316d6aac4022673c33ee01994aef09e08ea73fc4 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Fri, 25 Mar 2016 12:54:36 +0100 Subject: [PATCH 1/4] Add travis and coveralls integration --- .travis.yml | 20 +++++++++++ Makefile | 7 ---- package.json | 43 +++++++++++++++++------- test/mocha.opts | 2 ++ test/phantom.js | 71 --------------------------------------- test/phantom_spec.js | 71 +++++++++++++++++++++++++++++++++++++++ test/phantom_xray_spec.js | 22 ++++++++++++ 7 files changed, 145 insertions(+), 91 deletions(-) create mode 100644 .travis.yml delete mode 100644 Makefile create mode 100644 test/mocha.opts delete mode 100644 test/phantom.js create mode 100644 test/phantom_spec.js create mode 100644 test/phantom_xray_spec.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5e7f1ca --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +language: node_js +node_js: + - "stable" + - "5" + - "4" + - "0.12" + - "0.10" + - "iojs" +before_install: + - npm install -g phantomjs-prebuilt +env: + - CXX=g++-4.8 +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 +script: npm run-script coveralls +after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index e6c20c9..0000000 --- a/Makefile +++ /dev/null @@ -1,7 +0,0 @@ - -test: - @./node_modules/.bin/mocha \ - --reporter spec \ - --timeout 30000 - -.PHONY: test diff --git a/package.json b/package.json index 111c6f6..8b07761 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,41 @@ { "name": "x-ray-phantom", - "version": "1.0.1", "description": "phantom driver for x-ray", - "keywords": [], - "author": "Matthew Mueller ", + "version": "1.0.1", + "main": "index", + "author": { + "name": "Matthew Mueller", + "email": "matt@lapwinglabs.com" + }, "repository": { "type": "git", "url": "git://github.com/lapwinglabs/x-ray-phantom.git" }, + "keywords": [], "dependencies": { - "debug": "^2.1.1", - "nightmare": "^1.7.0", - "normalizeurl": "^0.1.3", - "wrap-fn": "^0.1.4" + "debug": "~2.1.1", + "nightmare": "~1.7.0", + "normalizeurl": "~0.1.3", + "wrap-fn": "~0.1.4" }, "devDependencies": { - "cheerio": "^0.19.0", - "mocha": "*", - "nightmare-swiftly": "^0.2.4", - "x-ray-crawler": "^2.0.1" + "cheerio": "~0.19.0", + "coveralls": "~2.11.8", + "istanbul": "~0.4.2", + "mocha": "latest", + "nightmare-swiftly": "~0.2.4", + "x-ray-crawler": "~2.0.1" + }, + "engines": { + "node": ">= 0.10" + }, + "scripts": { + "coveralls": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly", + "pretest": "standard", + "test": "mocha" + }, + "bugs": { + "url": "https://github.com/lapwinglabs/x-ray-phantom/issues" }, - "main": "index" -} \ No newline at end of file + "homepage": "https://github.com/lapwinglabs/x-ray-phantom#readme" +} diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..16b33ef --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,2 @@ +--reporter spec +--timeout 30000 \ No newline at end of file diff --git a/test/phantom.js b/test/phantom.js deleted file mode 100644 index 6eed8ef..0000000 --- a/test/phantom.js +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Module Dependencies - */ - -var Crawler = require('x-ray-crawler'); -var cheerio = require('cheerio'); -var join = require('path').join; -var assert = require('assert'); -var phantom = require('../'); -var fs = require('fs'); - -/** - * Tests - */ - -describe('phantom driver', function() { - - it('should have sensible defaults', function(done) { - var crawler = Crawler() - .driver(phantom()) - - crawler('http://google.com', function(err, ctx) { - if (err) return done(err); - var $ = cheerio.load(ctx.body); - var title = $('title').text(); - assert.equal('Google', title); - done(); - }) - }); - - it('should work with client-side pages', function(done) { - var crawler = Crawler() - .driver(phantom()); - - crawler('https://exchange.coinbase.com/trade', function(err, ctx) { - if (err) return done(err); - var $ = cheerio.load(ctx.body); - var price = $('.market-num').text(); - assert.equal(false, isNaN(+price)); - done(); - }) - }) - - it('should support custom functions', function(done) { - var crawler = Crawler() - .driver(phantom(runner)); - - crawler('http://mat.io', function(err, ctx) { - if (err) return done(err); - var $ = cheerio.load(ctx.body); - var title = $('title').text(); - assert.equal('Lapwing Labs', title); - done(); - }) - - function runner(ctx, nightmare) { - return nightmare - .goto(ctx.url) - .click('.Header-logo-item+ .Header-list-item a') - .wait() - } - }) -}) - -/** - * Read - */ - -function get(path) { - return require(join(__dirname, 'fixtures', path)); -} diff --git a/test/phantom_spec.js b/test/phantom_spec.js new file mode 100644 index 0000000..ebef0a9 --- /dev/null +++ b/test/phantom_spec.js @@ -0,0 +1,71 @@ +/* global describe, it */ + +/** + * Module Dependencies + */ + +var Crawler = require('x-ray-crawler') +var cheerio = require('cheerio') +var join = require('path').join +var assert = require('assert') +var phantom = require('../') + +/** + * Tests + */ + +describe('phantom driver', function () { + it('should have sensible defaults', function (done) { + var crawler = Crawler() + .driver(phantom()) + + crawler('http://google.com', function (err, ctx) { + if (err) return done(err) + var $ = cheerio.load(ctx.body) + var title = $('title').text() + assert.equal('Google', title) + done() + }) + }) + + it('should work with client-side pages', function (done) { + var crawler = Crawler() + .driver(phantom()) + + crawler('https://exchange.coinbase.com/trade', function (err, ctx) { + if (err) return done(err) + var $ = cheerio.load(ctx.body) + var price = $('.market-num').text() + assert.equal(false, isNaN(+price)) + done() + }) + }) + + it('should support custom functions', function (done) { + var crawler = Crawler() + .driver(phantom(runner)) + + crawler('http://mat.io', function (err, ctx) { + if (err) return done(err) + var $ = cheerio.load(ctx.body) + var title = $('title').text() + assert.equal('Lapwing Labs', title) + done() + }) + + function runner (ctx, nightmare) { + return nightmare + .goto(ctx.url) + .click('.Header-logo-item+ .Header-list-item a') + .wait() + } + }) +}) + +/** + * Read + */ + +function get (path) { + return require(join(__dirname, 'fixtures', path)) +} diff --git a/test/phantom_xray_spec.js b/test/phantom_xray_spec.js new file mode 100644 index 0000000..29c40c6 --- /dev/null +++ b/test/phantom_xray_spec.js @@ -0,0 +1,22 @@ +/* global it, describe */ + +'use strict' + +var Xray = require('x-ray') +var phantom = require('x-ray-phantom') +var assert = require('assert') + +describe('Xray.driver(fn)', function () { + it('should support basic phantom', function (done) { + var x = Xray() + .driver(phantom({ + webSecurity: false + })) + + x('http://www.google.com/ncr', 'title')(function (err, str) { + if (err) return done(err) + assert.equal('Google', str) + done() + }) + }) +}) From 97803f4fcb98929dfa6f49d3d914a648c6c496bc Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Fri, 25 Mar 2016 12:58:08 +0100 Subject: [PATCH 2/4] Add x-ray as devDependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 8b07761..37f5608 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "istanbul": "~0.4.2", "mocha": "latest", "nightmare-swiftly": "~0.2.4", + "x-ray": "~2.0.3", "x-ray-crawler": "~2.0.1" }, "engines": { From 90cea9829878acff74593077639a227d4c9b5395 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Fri, 25 Mar 2016 13:23:12 +0100 Subject: [PATCH 3/4] Fix typo --- test.js => example.js | 0 test/phantom_xray_spec.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename test.js => example.js (100%) diff --git a/test.js b/example.js similarity index 100% rename from test.js rename to example.js diff --git a/test/phantom_xray_spec.js b/test/phantom_xray_spec.js index 29c40c6..fdc15a6 100644 --- a/test/phantom_xray_spec.js +++ b/test/phantom_xray_spec.js @@ -3,7 +3,7 @@ 'use strict' var Xray = require('x-ray') -var phantom = require('x-ray-phantom') +var phantom = require('../') var assert = require('assert') describe('Xray.driver(fn)', function () { From d777ad73c30b6ea679936cfa9c39fabe4415699b Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Fri, 25 Mar 2016 13:41:06 +0100 Subject: [PATCH 4/4] disable security for tests --- test/phantom_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/phantom_spec.js b/test/phantom_spec.js index ebef0a9..ce88dd7 100644 --- a/test/phantom_spec.js +++ b/test/phantom_spec.js @@ -17,7 +17,7 @@ var phantom = require('../') describe('phantom driver', function () { it('should have sensible defaults', function (done) { var crawler = Crawler() - .driver(phantom()) + .driver(phantom({ webSecurity: false })) crawler('http://google.com', function (err, ctx) { if (err) return done(err) @@ -30,7 +30,7 @@ describe('phantom driver', function () { it('should work with client-side pages', function (done) { var crawler = Crawler() - .driver(phantom()) + .driver(phantom({ webSecurity: false })) crawler('https://exchange.coinbase.com/trade', function (err, ctx) { if (err) return done(err)