diff --git a/__tests__/.eslintrc.json b/__tests__/.eslintrc.json new file mode 100644 index 0000000..55f121d --- /dev/null +++ b/__tests__/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "env": { + "jest": true + } +} diff --git a/__tests__/prerender.test.js b/__tests__/prerender.test.js new file mode 100644 index 0000000..5f1cc25 --- /dev/null +++ b/__tests__/prerender.test.js @@ -0,0 +1,7 @@ +const render = require('../index'); + +describe('Pre-renderer', () => { + it('pre-renders a web page', () => { + return expect(render('https://google.com')).resolves.toMatch(/google/i); + }); +}); diff --git a/index.js b/index.js index fde4dc2..929d845 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ module.exports = function (source, chromeFlags) { () => chrome.kill() ); }) - .then((results) => results.find(r => r.extractedHTML).extractedHTML); + .then((results) => results.find(r => r && r.extractedHTML).extractedHTML); } function extractHtml(evaluatedCode) { @@ -34,12 +34,12 @@ function extractHtml(evaluatedCode) { } function launchChrome(url, flags) { - debug('Launching Chrome headless'); + debug('Launching Chrome headless for url "%s"', url); const chromeFlags = [ '--disable-gpu', '--headless', - ].concat(flags); - debug('Chrome flags: %s', chromeFlags.join(' ')); + ].concat(flags).filter(Boolean); + debug('Chrome flags: %s', chromeFlags); return chromeLauncher.launch({ startingUrl: url, diff --git a/package.json b/package.json index 20894cb..fd09357 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ }, "scripts": { "lint": "eslint index.js", - "test": "jest" + "test": "jest", + "test:watch": "DEBUG=prerender jest --watchAll" }, "dependencies": { "chrome-launcher": "^0.2.1",