From 245a878e7aa2c8d5a6500351a55a3e969e726e0b Mon Sep 17 00:00:00 2001 From: Hugo Gomes Date: Fri, 9 Feb 2024 19:24:07 +0000 Subject: [PATCH] feat: add basic smoke tests (#10) * feat: add basic smoke tests * style: prettier * style: pretty * fix: add chrome dependencies * bump: node-version * testing * cleanup --- .github/workflows/main.yml | 8 +++++++ test/puppeteer.js | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/puppeteer.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 903715b..95cc143 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,9 +10,17 @@ jobs: runs-on: ubuntu-latest container: node:${{ matrix.node-version }} steps: + - uses: actions/checkout@v1 + - run: apt-get update && apt-get install -y wget gnupg + - run: >- + wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && + sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' && + apt-get update && apt-get install -y google-chrome-stable --no-install-recommends - uses: actions/checkout@v4 - run: node --version - run: npm install - run: npm install --only=dev - run: npm run lint - run: npm test + env: + PUPPETEER_SKIP_DOWNLOAD: true diff --git a/test/puppeteer.js b/test/puppeteer.js new file mode 100644 index 0000000..6aa43ba --- /dev/null +++ b/test/puppeteer.js @@ -0,0 +1,43 @@ +const assert = require("assert"); +const puppeteer = require("../lib/engines/puppeteer"); + +describe("PUPPETEER", function() { + this.timeout(5000); + + it("should render a pdf", async () => { + const engine = new puppeteer.Puppeteer(); + await engine.init(); + + const req = { + query: { + url: "https://example.com/", + format: "pdf" + }, + body: {} + }; + const res = { + send: function(data) { + this.data = data; + }, + type: function(file) { + this.file = file; + } + }; + await engine.render(req, res); + assert.ok(res.data); + assert.strictEqual(res.file, "pdf"); + + await engine.destroy(); + }); + + it("should open new page", async () => { + const engine = new puppeteer.Puppeteer(); + await engine.init(); + + await engine._newPage(); + const pages = await engine.instance.pages(); + assert.strictEqual(2, pages.length); + + await engine.destroy(); + }); +});