Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piuccio committed Jun 26, 2017
1 parent f0598d3 commit 068e5dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions __tests__/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"jest": true
}
}
7 changes: 7 additions & 0 deletions __tests__/prerender.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ 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) {
return { extractedHTML: `<!doctype html>${evaluatedCode.result.value}` };
}

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,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 068e5dd

Please sign in to comment.