fix(core): update

This commit is contained in:
Philipp Kunz 2019-06-03 17:16:47 +02:00
parent 8853eecbb9
commit 54a0ec6c71
9 changed files with 106 additions and 83 deletions

15
package-lock.json generated
View File

@ -153,7 +153,6 @@
"version": "2.0.3",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartdelay/-/smartdelay-2.0.3.tgz",
"integrity": "sha512-TXKDDqsc7sBTLl+oiYNaF6IdNk1n70i8ur8QfwcUU6tegTnrEkvMWy9h5Zdty/fq1ioCNpKLvuXoA+fgYVwKGQ==",
"dev": true,
"requires": {
"@pushrocks/smartpromise": "^3.0.2"
}
@ -264,9 +263,9 @@
"integrity": "sha512-MaI0+uLQPCr2V3WGnbdgb0pWa9xkWyrP4qYcbsHIjeismGLbn9s3jmP/HIXU8LkgzRgaVb+BJxmZJHOwl32DyA=="
},
"@pushrocks/smartpdf": {
"version": "1.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpdf/-/smartpdf-1.0.6.tgz",
"integrity": "sha512-zA6jmOgi+0tOX8kFCYqv+dxgXIPcmWjw7oVdE4THfh50uHKxubFpZkxq0MF+H8O16P3Akx3qQUYpnGhCkiTxxA==",
"version": "1.0.17",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpdf/-/smartpdf-1.0.17.tgz",
"integrity": "sha512-LOZOluCQeh7u4dWZ7J7Ufz9XPMXTwgC86NGTonr5tu7YB0bpcxnwA4aCZmi/nGtd1NnSpyyxSz3x+xONDqI8bA==",
"requires": {
"@pushrocks/smartfile": "^7.0.2",
"@pushrocks/smartnetwork": "^1.1.6",
@ -2273,9 +2272,9 @@
"dev": true
},
"tslint": {
"version": "5.16.0",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.16.0.tgz",
"integrity": "sha512-UxG2yNxJ5pgGwmMzPMYh/CCnCnh0HfPgtlVRDs1ykZklufFBL1ZoTlWFRz2NQjcoEiDoRp+JyT0lhBbbH/obyA==",
"version": "5.17.0",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.17.0.tgz",
"integrity": "sha512-pflx87WfVoYepTet3xLfDOLDm9Jqi61UXIKePOuca0qoAZyrGWonDG9VTbji58Fy+8gciUn8Bt7y69+KEVjc/w==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.0.0",
@ -2284,7 +2283,7 @@
"commander": "^2.12.1",
"diff": "^3.2.0",
"glob": "^7.1.1",
"js-yaml": "^3.13.0",
"js-yaml": "^3.13.1",
"minimatch": "^3.0.4",
"mkdirp": "^0.5.1",
"resolve": "^1.3.2",

View File

@ -5,8 +5,8 @@
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(npmts)",
"build": "echo \"Not needed for now\""
"test": "tstest test/",
"build": "tsbuild"
},
"repository": {
"type": "git",
@ -19,14 +19,16 @@
},
"homepage": "https://gitlab.com/pushrocks/smartbrowser#README",
"dependencies": {
"@pushrocks/smartpdf": "^1.0.6",
"@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartpdf": "^1.0.17",
"@pushrocks/smartunique": "^3.0.1",
"puppeteer": "^1.17.0"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.11",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.9",
"tslint": "^5.16.0",
"tslint": "^5.17.0",
"tslint-config-prettier": "^1.18.0"
},
"private": true,

View File

@ -1,6 +0,0 @@
<head>
<title>Test</title>
</head>
<body>
Test
</body>

View File

@ -1,33 +0,0 @@
"use strict";
require("typings-test");
const should = require("should");
const smartbrowser = require("../dist/index");
let testSmartBrowser;
describe('smartbrowser', () => {
it('should instanstiate a new browser ', function () {
testSmartBrowser = new smartbrowser.Smartbrowser({
webroot: './test/assets/',
watchFiles: ['./test/assets/']
});
should(testSmartBrowser).be.instanceof(smartbrowser.Smartbrowser);
});
it('should start the browser ', function (done) {
testSmartBrowser.start().then((bsInstance) => {
done();
}).catch((err) => { console.log(err); });
});
it('should stop the browser ', function (done) {
this.timeout(10000);
setTimeout(() => {
testSmartBrowser.stop().then(() => {
done();
}).catch((err) => { console.log(err); });
}, 2000);
});
it('should exit correctly', function () {
setTimeout(() => {
process.exit(0);
}, 2000);
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsOENBQTZDO0FBRTdDLElBQUksZ0JBQTJDLENBQUE7QUFFL0MsUUFBUSxDQUFDLGNBQWMsRUFBRTtJQUNyQixFQUFFLENBQUMsb0NBQW9DLEVBQUU7UUFDckMsZ0JBQWdCLEdBQUcsSUFBSSxZQUFZLENBQUMsWUFBWSxDQUFDO1lBQzdDLE9BQU8sRUFBRSxnQkFBZ0I7WUFDekIsVUFBVSxFQUFFLENBQUMsZ0JBQWdCLENBQUM7U0FDakMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLGdCQUFnQixDQUFDLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxZQUFZLENBQUMsWUFBWSxDQUFDLENBQUE7SUFDckUsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsMkJBQTJCLEVBQUUsVUFBVSxJQUFJO1FBQzFDLGdCQUFnQixDQUFDLEtBQUssRUFBRSxDQUFDLElBQUksQ0FBQyxDQUFDLFVBQVU7WUFDckMsSUFBSSxFQUFFLENBQUE7UUFDVixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxHQUFHLE9BQU8sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO0lBQzNDLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLDBCQUEwQixFQUFFLFVBQVUsSUFBSTtRQUN6QyxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBQ25CLFVBQVUsQ0FBQztZQUNQLGdCQUFnQixDQUFDLElBQUksRUFBRSxDQUFDLElBQUksQ0FBQztnQkFDekIsSUFBSSxFQUFFLENBQUE7WUFDVixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxHQUFHLE9BQU8sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzNDLENBQUMsRUFBRSxJQUFJLENBQUMsQ0FBQTtJQUNaLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLHVCQUF1QixFQUFDO1FBQ3ZCLFVBQVUsQ0FBQztZQUNQLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDbkIsQ0FBQyxFQUFDLElBQUksQ0FBQyxDQUFBO0lBQ1gsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -1,32 +1,30 @@
import { tap, expect } from 'tapbundle';
import * as smartdelay from 'smartdelay';
import { tap, expect } from '@pushrocks/tapbundle';
import * as smartbrowser from '../dist/index';
let testSmartBrowser: smartbrowser.Smartbrowser;
import * as smartbrowser from '../ts/index';
let testSmartBrowser: smartbrowser.SmartBrowser;
tap
.test('should instanstiate a new browser ', async () => {
testSmartBrowser = new smartbrowser.Smartbrowser({
webroot: './test/assets/',
watchFiles: ['./test/assets/']
});
return expect(testSmartBrowser).to.be.instanceof(smartbrowser.Smartbrowser);
testSmartBrowser = new smartbrowser.SmartBrowser();
return expect(testSmartBrowser).to.be.instanceof(smartbrowser.SmartBrowser);
})
.catch(tap.threw);
tap
.test('should start the browser ', async () => {
return await expect(testSmartBrowser.start()).to.eventually.be.fulfilled;
})
.catch(tap.threw);
tap.test('should start the browser ', async () => {
await expect(testSmartBrowser.start()).to.eventually.be.fulfilled;
});
tap.test('should create a PDF from a page', async (tools) => {
const result = await testSmartBrowser.pdfFromPage('https://lossless.com');
expect(result.buffer).to.be.instanceOf(Buffer);
});
tap.test('should produce a valid screenshot', async (tools) => {
const result = await testSmartBrowser.screenshotFromPage('https://lossless.com');
expect(result.buffer).to.be.instanceOf(Buffer);
});
tap.test('should stop the browser ', async () => {
return await smartdelay.delayFor(2000).then(() => {
return expect(testSmartBrowser.stop()).to.eventually.be.fulfilled;
});
});
tap.test('should exit correctly', async () => {
smartdelay.delayFor(2000).then(() => {
process.exit(0);
});
await expect(testSmartBrowser.stop()).to.eventually.be.fulfilled;
});
tap.start();

View File

@ -1,21 +1,76 @@
import * as plugins from './smartbrowser.plugins';
import * as interfaces from './interfaces';
/**
* SmartBrowser
*/
export class SmartBrowser {
puppeteer: plugins.puppeteer.Browser;
smartpdf: plugins.smartpdf.SmartPdf;
pdfFromPage(urlArg: string) {
this.smartpdf.getFullWebsiteAsSinglePdf(urlArg: );
public headlessBrowser: plugins.puppeteer.Browser;
public smartpdf: plugins.smartpdf.SmartPdf;
/**
* create a pdf from page
* @param urlArg
*/
public pdfFromPage(urlArg: string) {
const result = this.smartpdf.getFullWebsiteAsSinglePdf(urlArg);
return result;
}
/**
* make a screenshot from a page
* @param urlArg
*/
public async screenshotFromPage(urlArg: string): Promise<interfaces.IScreenShotResult> {
const pageId = plugins.smartunique.shortId();
const page = await this.headlessBrowser.newPage();
await page.goto(urlArg, {
waitUntil: 'networkidle2'
});
const screenshotBuffer = await page.screenshot({
encoding: 'binary'
});
await page.close();
return {
name: pageId,
id: `${pageId}.js`,
buffer: screenshotBuffer
};
}
/**
* evalutes an expression on a page
* @param urlArg
* @param funcArg
*/
public async evaluateOnPage (urlArg: string, funcArg: () => Promise<any>) {
const page = await this.headlessBrowser.newPage();
await page.goto(urlArg, {
waitUntil: 'networkidle2'
});
}
/**
* start a page
*/
public async start() {
this.headlessBrowser = await plugins.puppeteer.launch({
defaultViewport: {
width: 1600,
height: 1080
}
});
this.smartpdf = new plugins.smartpdf.SmartPdf();
this.smartpdf.init();
await this.smartpdf.start(this.headlessBrowser);
}
/**
* stops the smartbrowser instance
*/
stop() {
this.smartpdf.close();
public async stop() {
await this.headlessBrowser.close();
await this.smartpdf.stop();
}
}

2
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1,2 @@
export * from './interfaces.screenshotresult';

View File

@ -0,0 +1,5 @@
export interface IScreenShotResult {
name: string;
id: string;
buffer: Buffer;
}

View File

@ -1,9 +1,10 @@
// pushrocks scope
import * as smartpdf from '@pushrocks/smartpdf';
import * as smartunique from '@pushrocks/smartunique';
export { smartpdf };
export { smartpdf, smartunique };
// third party
import * as puppeteer from 'puppeteer';
import puppeteer from 'puppeteer';
export { puppeteer };