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 9, 2020
1 parent b194c82 commit c1f96de
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 53 deletions.
67 changes: 40 additions & 27 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,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 +649,7 @@ gulp.task("default_preferences-pre", function () {
LIB: true,
BUNDLE_VERSION: 0, // Dummy version
BUNDLE_BUILD: 0, // Dummy build
TESTING: process.env.TESTING === "true",
}),
map: {
"pdfjs-lib": "../pdf",
Expand Down Expand Up @@ -1502,6 +1506,31 @@ gulp.task(
})
);

gulp.task(
"dev-sandbox",
gulp.series(
function scripting() {
const defines = builder.merge(DEFINES, { GENERIC: true, TESTING: true });
return createTemporaryScriptingBundle(defines, {
disableVersionInfo: true,
});
},
function () {
console.log();
console.log("### Building development sandbox");

const defines = builder.merge(DEFINES, { GENERIC: true, TESTING: true });
const sandboxDir = BUILD_DIR + "dev-sandbox/";

rimraf.sync(sandboxDir);

return createSandboxBundle(defines, {
disableVersionInfo: true,
}).pipe(gulp.dest(sandboxDir));
}
)
);

gulp.task("testing-pre", function (done) {
process.env.TESTING = "true";
done();
Expand All @@ -1513,7 +1542,8 @@ gulp.task(
return streamqueue(
{ objectMode: true },
createTestSource("unit"),
createTestSource("browser")
createTestSource("browser"),
createTestSource("integration")
);
})
);
Expand All @@ -1525,7 +1555,8 @@ gulp.task(
{ objectMode: true },
createTestSource("unit", true),
createTestSource("font", true),
createTestSource("browser (no reftest)", true)
createTestSource("browser (no reftest)", true),
createTestSource("integration")
);
})
);
Expand All @@ -1545,6 +1576,13 @@ gulp.task(
})
);

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

gulp.task(
"fonttest",
gulp.series("testing-pre", function () {
Expand Down Expand Up @@ -1718,31 +1756,6 @@ gulp.task(
})
);

gulp.task(
"dev-sandbox",
gulp.series(
function scripting() {
const defines = builder.merge(DEFINES, { GENERIC: true, TESTING: true });
return createTemporaryScriptingBundle(defines, {
disableVersionInfo: true,
});
},
function () {
console.log();
console.log("### Building development sandbox");

const defines = builder.merge(DEFINES, { GENERIC: true, TESTING: true });
const sandboxDir = BUILD_DIR + "dev-sandbox/";

rimraf.sync(sandboxDir);

return createSandboxBundle(defines, {
disableVersionInfo: true,
}).pipe(gulp.dest(sandboxDir));
}
)
);

gulp.task("watch-dev-sandbox", function () {
gulp.watch(
[
Expand Down
52 changes: 52 additions & 0 deletions test/integration-boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* 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.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 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 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).toEqual("3,14");
})
);
});

it("must format the field with 2 digits and leave field with a TAB", async () => {
await Promise.all(
pages.map(async 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).toEqual("2,72");
})
);
});
});
});
Loading

0 comments on commit c1f96de

Please sign in to comment.