From 3427f4a7e89bdd03626c527941be622c26bef9c8 Mon Sep 17 00:00:00 2001 From: Elliot Blackburn Date: Tue, 16 May 2017 11:46:33 +0100 Subject: [PATCH 1/2] Add mocha test to check validity of all external links --- .gitignore | 1 + package.json | 30 ++++++++++++++++++++++++++ test/list_spec.js | 33 +++++++++++++++++++++++++++++ test/utils/external-link-checker.js | 22 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 .gitignore create mode 100644 package.json create mode 100644 test/list_spec.js create mode 100644 test/utils/external-link-checker.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..30bc162 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..4cbf5a2 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "awesome-campus-expert", + "version": "1.0.0", + "description": "A curated list of awesome resources for GitHub Campus Experts", + "main": "index.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "mocha './test/**/*_spec.js'" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/campus-experts/awesome-campus-expert.git" + }, + "author": "GitHub Campus Experts", + "license": "UNLICENSED", + "bugs": { + "url": "https://github.com/campus-experts/awesome-campus-expert/issues" + }, + "homepage": "https://github.com/campus-experts/awesome-campus-expert#readme", + "devDependencies": { + "async": "^2.4.0", + "link-check": "^4.0.2", + "lodash": "^4.17.4", + "markdown-link-extractor": "^1.1.0", + "mocha": "^3.4.1", + "should": "^11.2.1" + } +} diff --git a/test/list_spec.js b/test/list_spec.js new file mode 100644 index 0000000..97e2af9 --- /dev/null +++ b/test/list_spec.js @@ -0,0 +1,33 @@ +const path = require('path'); +const fs = require('fs'); +const should = require('should'); +const checkExternalLinks = require('./utils/external-link-checker'); + +describe('Awesome list', function() { + + describe('links', function() { + + it('should all be valid', function(done) { + // Each link will be tested over http which + // can take quite a while. + this.timeout(15000); + + const listPath = path.resolve(__dirname, '../readme.md'); + + fs.readFile(listPath, 'utf8', function(err, markdown) { + if (err) return done(err); + + checkExternalLinks(markdown, function(err, results) { + if (err) return done(err); + + results.forEach(function(result) { + result.statusCode.should.equal(200); + result.status.should.equal('alive'); + }); + + done(); + }); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/utils/external-link-checker.js b/test/utils/external-link-checker.js new file mode 100644 index 0000000..61750c6 --- /dev/null +++ b/test/utils/external-link-checker.js @@ -0,0 +1,22 @@ +const path = require('path'); +const _ = require('lodash'); +const async = require('async'); +const linkCheck = require('link-check'); +const markdownLinkExtractor = require('markdown-link-extractor'); + +module.exports = function checkExternalLinks(markdown, opts, callback) { + if (arguments.length === 2 && typeof opts === 'function') { + callback = opts; + opts = {}; + } + + let links = _.uniq(markdownLinkExtractor(markdown)); + // linkCheck will only check external links + let externalLinks = links.filter(function(link) { + return link.startsWith('http'); + }); + + async.mapLimit(externalLinks, 2, function(link, callback) { + linkCheck(link, opts, callback); + }, callback); +}; \ No newline at end of file From bb7176977962f82fb8642a439f512d2212a71f9e Mon Sep 17 00:00:00 2001 From: Elliot Blackburn Date: Tue, 16 May 2017 11:51:54 +0100 Subject: [PATCH 2/2] Add travis build declrations --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..253f29c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: + - "7" + +branches: + only: + - master \ No newline at end of file