Skip to content

Commit

Permalink
fix: moves the engine testing to beforeEach
Browse files Browse the repository at this point in the history
This way it's possible to properly skip the tests when the engine is not available.
  • Loading branch information
joamag committed Feb 10, 2024
1 parent 6f5f775 commit 4fe3c10
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions test/engines/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,53 @@ const puppeteer = require("../../lib/engines/puppeteer");
describe("Puppeteer", function() {
this.timeout(5000);

it("should render a PDF", async () => {
beforeEach(async function() {
const engine = new puppeteer.Puppeteer();
try {
await engine.init();
} catch (err) {
this.skip();
}
await engine.destroy();
});

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");
it("should render a PDF", async () => {
const engine = new puppeteer.Puppeteer();
await engine.init();

await engine.destroy();
try {
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");
} finally {
await engine.destroy();
}
});

it("should open new page", async () => {
const engine = new puppeteer.Puppeteer();
await engine.init();
try {
await engine.init();
} catch (err) {
this.skip();
await engine._newPage();
const pages = await engine.instance.pages();
assert.strictEqual(2, pages.length);
} finally {
await engine.destroy();
}

await engine._newPage();
const pages = await engine.instance.pages();
assert.strictEqual(2, pages.length);

await engine.destroy();
});
});

0 comments on commit 4fe3c10

Please sign in to comment.