Skip to content

Commit

Permalink
feat: add basic smoke tests (#10)
Browse files Browse the repository at this point in the history
* feat: add basic smoke tests

* style: prettier

* style: pretty

* fix: add chrome dependencies

* bump: node-version

* testing

* cleanup
  • Loading branch information
hugo-gomes authored Feb 9, 2024
1 parent 8f7b52c commit 245a878
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 43 additions & 0 deletions test/puppeteer.js
Original file line number Diff line number Diff line change
@@ -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();
});
});

0 comments on commit 245a878

Please sign in to comment.