From b0050f7571ee1c1e57891002db1a7215fbc5f2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vy=C4=8D=C3=ADtal?= Date: Sat, 5 Oct 2019 14:54:32 +0200 Subject: [PATCH] fix(screenshots): prevent infinite blocking Global functions alert and confirm block and never return without user action which won't happen in headless mode. This fix makes these functions return immediately. This also improves tests to catch more issues with screenshots (like timing out or not generating one per example). --- .circleci/config.yml | 23 +++++++- @types/index.d.ts | 5 ++ rollup.config.js | 4 +- src/generate-examples-index/index.ts | 6 ++- .../screenshot-script.js | 25 --------- .../screenshot-script.js.txt | 12 +++++ test/generate-examples-index/basic.test.ts | 52 ++++++++++++------- .../examples/example-alert.html | 16 ++++++ .../examples/example-confirm.html | 16 ++++++ 9 files changed, 111 insertions(+), 48 deletions(-) delete mode 100644 src/generate-examples-index/screenshot-script.js create mode 100644 src/generate-examples-index/screenshot-script.js.txt create mode 100644 test/generate-examples-index/examples/example-alert.html create mode 100644 test/generate-examples-index/examples/example-confirm.html diff --git a/.circleci/config.yml b/.circleci/config.yml index 150dd5293..d59b8373c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,6 +4,23 @@ # version: 2.1 +commands: + install-deps-for-screenshot-taking: + description: Install headless Chromium dependencies + steps: + - run: + name: Install Headless Chromium dependencies + command: | + sudo apt-get install -yq \ + ca-certificates fonts-liberation gconf-service libappindicator1 \ + libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 \ + libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 \ + libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 \ + libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 \ + libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 \ + libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget \ + xdg-utils + executors: node: docker: @@ -39,7 +56,7 @@ jobs: - persist_to_workspace: root: . paths: - - '*' + - "*" build: executor: node @@ -53,7 +70,7 @@ jobs: - persist_to_workspace: root: . paths: - - 'bin' + - "bin" lint: executor: node @@ -71,6 +88,8 @@ jobs: - attach_workspace: at: . + - install-deps-for-screenshot-taking + - run: npm run test release: diff --git a/@types/index.d.ts b/@types/index.d.ts index 4112c4167..b3ebf6fc7 100644 --- a/@types/index.d.ts +++ b/@types/index.d.ts @@ -7,3 +7,8 @@ declare module "*.html" { const value: string; export default value; } + +declare module "*.txt" { + const value: string; + export default value; +} diff --git a/rollup.config.js b/rollup.config.js index 89217fdef..cefee1803 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -26,11 +26,11 @@ export default ["generate-examples-index"].map(name => { external, plugins: [ nodeResolve({ - extensions: [".ts", ".js", ".json", ".css", ".html"], + extensions: [".css", ".html", ".js", ".json", ".ts", ".txt"], preferBuiltins: true }), string({ - include: ["**/*.{css,html}"] + include: ["**/*.{css,html,txt}"] }), typescript({ objectHashIgnoreUnknownHack: true, diff --git a/src/generate-examples-index/index.ts b/src/generate-examples-index/index.ts index 9963379cd..1fddedb9b 100644 --- a/src/generate-examples-index/index.ts +++ b/src/generate-examples-index/index.ts @@ -1,6 +1,7 @@ -import Pageres from "pageres"; import $ from "cheerio"; +import Pageres from "pageres"; import childProcess from "child_process"; +import commonScreenshotScript from "./screenshot-script.js.txt"; import crypto from "crypto"; import fs from "fs"; import globby from "globby"; @@ -530,6 +531,9 @@ class ContentBuilder { ); const screenshotPage = $.load(example.html); screenshotPage("head").prepend( + $(" + + + + + +
+ + diff --git a/test/generate-examples-index/examples/example-confirm.html b/test/generate-examples-index/examples/example-confirm.html new file mode 100644 index 000000000..e4639974b --- /dev/null +++ b/test/generate-examples-index/examples/example-confirm.html @@ -0,0 +1,16 @@ + + + + Test | Confirm + + + + + + + +
+ +