Skip to content

Commit

Permalink
Add some integration tests using puppeteer and Jasmine
Browse files Browse the repository at this point in the history
 * run with `gulp integrationtest`
  • Loading branch information
calixteman committed Dec 10, 2020
1 parent b194c82 commit 1e2cc1f
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 36 deletions.
51 changes: 41 additions & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const DEFINES = Object.freeze({
PRODUCTION: true,
SKIP_BABEL: true,
TESTING: false,
INTEGRATIONTEST: false,
// The main build targets:
GENERIC: false,
MOZCENTRAL: false,
Expand Down Expand Up @@ -303,14 +304,26 @@ function checkChromePreferencesFile(chromePrefsPath, webPrefsPath) {
return false;
}
if (webPrefsKeys.length !== chromePrefsKeys.length) {
console.log("Warning: Prefs objects haven't the same length");
return false;
}
return webPrefsKeys.every(function (value, index) {
return (
chromePrefsKeys[index] === value &&
chromePrefs.properties[value].default === webPrefs[value]
);
});

let ret = true;
for (let i = 0, ii = webPrefsKeys.length; i < ii; i++) {
const value = webPrefsKeys[i];
if (chromePrefsKeys[i] !== value) {
ret = false;
console.log(
`Warning: not the same keys: ${chromePrefsKeys[i]} !== ${value}`
);
} else if (chromePrefs.properties[value].default !== webPrefs[value]) {
ret = false;
console.log(
`Warning: not the same values: ${chromePrefs.properties[value].default} !== ${webPrefs[value]}`
);
}
}
return ret;
}

function replaceWebpackRequire() {
Expand Down Expand Up @@ -515,6 +528,9 @@ function createTestSource(testsName, bot) {
case "font":
args.push("--fontTest");
break;
case "integration":
args.push("--integration");
break;
default:
this.emit("error", new Error("Unknown name: " + testsName));
return null;
Expand Down Expand Up @@ -646,6 +662,7 @@ gulp.task("default_preferences-pre", function () {
LIB: true,
BUNDLE_VERSION: 0, // Dummy version
BUNDLE_BUILD: 0, // Dummy build
INTEGRATIONTEST: process.env.INTEGRATIONTEST === "true",
}),
map: {
"pdfjs-lib": "../pdf",
Expand Down Expand Up @@ -1507,25 +1524,32 @@ gulp.task("testing-pre", function (done) {
done();
});

gulp.task("integration-pre", function (done) {
process.env.INTEGRATIONTEST = "true";
done();
});

gulp.task(
"test",
gulp.series("testing-pre", "generic", "components", function () {
gulp.series("integration-pre", "testing-pre", "generic", "components", function () {
return streamqueue(
{ objectMode: true },
createTestSource("unit"),
createTestSource("browser")
createTestSource("browser"),
createTestSource("integration")
);
})
);

gulp.task(
"bottest",
gulp.series("testing-pre", "generic", "components", function () {
gulp.series("integration-pre", "testing-pre", "generic", "components", function () {
return streamqueue(
{ objectMode: true },
createTestSource("unit", true),
createTestSource("font", true),
createTestSource("browser (no reftest)", true)
createTestSource("browser (no reftest)", true),
createTestSource("integration")
);
})
);
Expand All @@ -1545,6 +1569,13 @@ gulp.task(
})
);

gulp.task(
"integrationtest",
gulp.series("integration-pre", "testing-pre", "generic", function () {
return createTestSource("integration");
})
);

gulp.task(
"fonttest",
gulp.series("testing-pre", function () {
Expand Down
53 changes: 53 additions & 0 deletions test/integration-boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright 2020 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

"use strict";

const Jasmine = require("jasmine");

async function runTests(results) {
const jasmine = new Jasmine();
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;

jasmine.loadConfig({
random: false,
spec_dir: "integration",
spec_files: ["scripting_spec.js", "annotation_spec.js"],
});

jasmine.addReporter({
jasmineDone(suiteInfo) {},
jasmineStarted(suiteInfo) {},
specDone(result) {
++results.runs;
if (result.failedExpectations.length > 0) {
++results.failures;
console.log(`TEST-UNEXPECTED-FAIL | ${result.description}`);
} else {
console.log(`TEST-PASSED | ${result.description}`);
}
},
specStarted(result) {},
suiteDone(result) {},
suiteStarted(result) {},
});

return new Promise(resolve => {
jasmine.onComplete(resolve);
jasmine.execute();
});
}

exports.runTests = runTests;
63 changes: 63 additions & 0 deletions test/integration/annotation_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Copyright 2020 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

describe("Annotation highlight", () => {
describe("annotation-highlight.pdf", () => {
let pages;

beforeAll(async () => {
pages = await Promise.all(
global.integrationSessions.map(async session => {
const page = await session.browser.newPage();
await page.goto(
`${global.integrationBaseUrl}?file=/test/pdfs/annotation-highlight.pdf`
);
await page.bringToFront();
await page.waitForSelector("[data-annotation-id='19R']", {
timeout: 0,
});
return page;
})
);
});

afterAll(async () => {
await Promise.all(
pages.map(async page => {
await page.close();
})
);
});

it("must show a popup on mouseover", async () => {
await Promise.all(
pages.map(async page => {
let hidden = await page.$eval(
"[data-annotation-id='21R']",
el => el.hidden
);
expect(hidden).toEqual(true);
await page.hover("[data-annotation-id='19R']");
await page.waitForTimeout(100);
hidden = await page.$eval(
"[data-annotation-id='21R']",
el => el.hidden
);
expect(hidden).toEqual(false);
})
);
});
});
});
66 changes: 66 additions & 0 deletions test/integration/scripting_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* Copyright 2020 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

describe("Interaction", () => {
describe("in 160F-2019.pdf", () => {
let pages;

beforeAll(async () => {
pages = await Promise.all(
global.integrationSessions.map(async session => {
const page = await session.browser.newPage();
await page.goto(
`${global.integrationBaseUrl}?file=/test/pdfs/160F-2019.pdf`
);
await page.bringToFront();
await page.waitForSelector("#\\34 16R", {
timeout: 0,
});
return [session.name, page];
})
);
});

afterAll(async () => {
await Promise.all(
pages.map(async ([_, page]) => {
await page.close();
})
);
});

it("must format the field with 2 digits and leave field with a click", async () => {
await Promise.all(
pages.map(async ([name, page]) => {
await page.type("#\\34 16R", "3.14159", { delay: 200 });
await page.click("#\\34 19R");
const text = await page.$eval("#\\34 16R", el => el.value);
expect(text).withContext(`In ${name}`).toEqual("3,14");
})
);
});

it("must format the field with 2 digits and leave field with a TAB", async () => {
await Promise.all(
pages.map(async ([name, page]) => {
await page.type("#\\34 22R", "2.7182818", { delay: 200 });
await page.keyboard.press("Tab");
const text = await page.$eval("#\\34 22R", el => el.value);
expect(text).withContext(`In ${name}`).toEqual("2,72");
})
);
});
});
});
Loading

0 comments on commit 1e2cc1f

Please sign in to comment.