Skip to content

Commit

Permalink
chore: replace browser from Electron to Puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
Quramy committed Nov 2, 2019
1 parent bd66c53 commit d7cbec5
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 1,832 deletions.
5 changes: 1 addition & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
defaults: &defaults
working_directory: ~/reg-suit
docker:
- image: quramy/node-nightmare
- image: regviz/node-xcb
environment:
DISPLAY: ":99"
GOOGLE_APPLICATION_CREDENTIALS: "/root/gcloud-service-key.json"

version: 2
Expand Down Expand Up @@ -35,9 +34,7 @@ jobs:
- run:
name: Test
command: |
xvfbd start
yarn run test
xvfbd stop
- run:
name: Regression using gh-io components
command: |
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
},
"devDependencies": {
"@types/node": "8.10.0",
"avaron": "^0.2.0",
"electron": "^1.8.4",
"lerna": "2.11.0",
"npm-run-all": "^4.0.2",
"rimraf": "^2.6.1",
Expand Down
1 change: 1 addition & 0 deletions packages/reg-suit-toppage/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ lib/
dist/
public/css/
screenshot/
landing-page/
.reg/
112 changes: 0 additions & 112 deletions packages/reg-suit-toppage/bs-config.js

This file was deleted.

70 changes: 43 additions & 27 deletions packages/reg-suit-toppage/capture.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
const Nightmare = require("nightmare");
const nightmare = Nightmare({ show: false, width: 1200, height: 300, webPreferences: {
nodeIntegration: true,
preload: `${__dirname}/preload.js`,
}});

const mkdirp = require("mkdirp");
mkdirp.sync(`${__dirname}/screenshot`);
const Puppeteer = require('puppeteer');

async function main() {
try {
mkdirp.sync(`${__dirname}/screenshot`);

const browser = await Puppeteer.launch({
args: ["--no-sandbox", "--disable-setuid-sandbox"],
headless: true,
});
const page = await browser.newPage();
await page.goto(`file://${__dirname}/landing-page/public/index.html`);

await page.setViewport({
width: 1440,
height: 600,
});
await page.waitFor(500);
await page.screenshot({ path: `${__dirname}/screenshot/index_desktop.png`, fullPage: true });

nightmare
.goto(`file://${__dirname}/dist/index.html`)
.wait(500)
.evaluate(() => win.setSize(1200, 3300))
.wait(100)
.screenshot(`${__dirname}/screenshot/index.png`)
.evaluate(() => win.setSize(900, 3500))
.wait(100)
.screenshot(`${__dirname}/screenshot/index_mid.png`)
.evaluate(() => win.setSize(700, 3500))
.wait(100)
.screenshot(`${__dirname}/screenshot/index_sp.png`)
.end()
.then(() => {
console.log("Captured screenshot")
})
.catch(x => {
console.error(x);
await page.setViewport({
width: 1044,
height: 768,
});
await page.waitFor(500);
await page.screenshot({ path: `${__dirname}/screenshot/index_tablet.png`, fullPage: true });

await page.setViewport({
width: 375,
height: 767,
});
await page.waitFor(500);
await page.screenshot({ path: `${__dirname}/screenshot/index_mobile.png`, fullPage: true });

await page.close();
await new Promise(res => setTimeout(res, 50));
await browser.close();
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
})
;
}
}

main();
16 changes: 3 additions & 13 deletions packages/reg-suit-toppage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
"description": "",
"scripts": {
"test": "npm run screenshot",
"scss": "node-sass public/styles/index.scss -o public/css",
"postcss": "postcss public/css/*.css --use autoprefixer -d dist/css",
"build": "npm run scss && npm run postcss && cpx \"public/**/*.{html,ico,png,jpg,svg,js}\" dist && cpx circle.yml dist",
"prepublish": "npm run build",
"watch": "node-sass public/styles/index.scss -w public/styles -r -o public/css",
"start": "browser-sync start -c bs-config.js",
"build": "bash scripts/build.sh v1.0.0",
"screenshot": "node capture.js && ls screenshot",
"reg-suit": "node ../../node_modules/reg-suit/lib/cli.js",
"regression": "npm run reg-suit -- run -v",
"deploy": "gh-pages -d dist"
"deploy": "gh-pages -d landing-page/public"
},
"keywords": [
"reg"
Expand All @@ -26,14 +21,9 @@
"repository": "git+https://github.com/reg-viz/reg-suit.git",
"license": "MIT",
"devDependencies": {
"autoprefixer": "^7.1.2",
"browser-sync": "^2.18.13",
"cpx": "^1.5.0",
"gh-pages": "^1.0.0",
"mkdirp": "^0.5.1",
"nightmare": "^2.10.0",
"node-sass": "^4.5.3",
"postcss-cli": "^4.1.0",
"puppeteer": "^2.0.0",
"reg-keygen-git-hash-plugin": "^0.7.25",
"reg-notify-github-plugin": "^0.7.26",
"reg-notify-slack-plugin": "^0.7.25",
Expand Down
3 changes: 0 additions & 3 deletions packages/reg-suit-toppage/preload.js

This file was deleted.

17 changes: 17 additions & 0 deletions packages/reg-suit-toppage/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
VERSION=$1
DIR=landing-page

if [ -e "$DIR" ]; then
cd $DIR
git fetch origin
git checkout refs/tags/$VERSION
else
git clone https://github.com/reg-viz/reg-suit-lp.git -b $VERSION $DIR --depth 1
cd $DIR
fi

yarn install --frozen-lockfile

yarn build

Loading

0 comments on commit d7cbec5

Please sign in to comment.