Commits (198)
root = true
[*]
end_of_line = lf
insert_final_newline = true
[*.{js,html}]
charset = utf-8
indent_style = tab
indent_size = 2
...@@ -3,7 +3,8 @@ module.exports = { ...@@ -3,7 +3,8 @@ module.exports = {
"browser": true, "browser": true,
"commonjs": true, "commonjs": true,
"es6": true, "es6": true,
"node": true "node": true,
"jest": true
}, },
"globals": { "globals": {
}, },
......
before_script: stages:
- docker info - build
- publish
build_image: npm-test:
script: stage: build
before_script:
- docker build -t pagedmedia/pagedjs . - docker build -t pagedmedia/pagedjs .
script:
- docker run --security-opt 'seccomp=seccomp.json' pagedmedia/pagedjs npm test - docker run --security-opt 'seccomp=seccomp.json' pagedmedia/pagedjs npm test
# This job requires to setup GitLab the following way:
# 1. On https://www.npmjs.com/settings/tokens/create
# create a new read/write token (the logged in user must have write access for the `pagedjs` package)
# 2. On https://gitlab.pagedmedia.org/tools/pagedjs/-/settings/ci_cd#js-cicd-variables-settings
# add a new variable named `NPM_TOKEN`, and toggle on _Protected_ and _Masked_
npm-publish:
stage: publish
before_script:
- 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'
- npm install
- npm publish --public --dry-run
script:
- npm publish --public
only:
- tags
FROM node:12-stretch FROM node:15-stretch
# Application parameters and variables # Application parameters and variables
ENV NODE_ENV=development ENV NODE_ENV=development
...@@ -78,7 +78,7 @@ USER node ...@@ -78,7 +78,7 @@ USER node
WORKDIR $DIRECTORY WORKDIR $DIRECTORY
COPY --chown=node:node package.json $DIRECTORY COPY --chown=node:node package.json package-lock.json $DIRECTORY/
RUN npm install RUN npm install
RUN npm install ghostscript4js RUN npm install ghostscript4js
......
...@@ -117,6 +117,7 @@ afterPreview(pages) ...@@ -117,6 +117,7 @@ afterPreview(pages)
// Chunker // Chunker
beforeParsed(content) beforeParsed(content)
filter(content)
afterParsed(parsed) afterParsed(parsed)
beforePageLayout(page) beforePageLayout(page)
afterPageLayout(pageElement, page, breakToken) afterPageLayout(pageElement, page, breakToken)
...@@ -134,9 +135,10 @@ onContent(contentNode, declarationNode, ruleNode) ...@@ -134,9 +135,10 @@ onContent(contentNode, declarationNode, ruleNode)
// Layout // Layout
layoutNode(node) layoutNode(node)
renderNode(node, sourceNode) renderNode(node, sourceNode, layout)
onOverflow(overflow, rendered, bounds) onOverflow(overflow, rendered, bounds)
onBreakToken(breakToken, overflow, rendered) onBreakToken(breakToken, overflow, rendered)
afterOverflowRemoved(removed, rendered)
``` ```
## Setup ## Setup
......
This diff is collapsed.
{ {
"name": "pagedjs", "name": "pagedjs",
"version": "0.1.34", "version": "0.2.0",
"description": "Chunks up a document into paged media flows and applies print styles", "description": "Chunks up a document into paged media flows and applies print styles",
"author": "Fred Chasen", "author": "Fred Chasen",
"license": "MIT", "license": "MIT",
...@@ -9,46 +9,47 @@ ...@@ -9,46 +9,47 @@
"module": "src/index.js", "module": "src/index.js",
"browser": "dist/paged.js", "browser": "dist/paged.js",
"dependencies": { "dependencies": {
"@babel/polyfill": "^7.6.0", "@babel/polyfill": "^7.10.1",
"@babel/runtime": "^7.6.3", "@babel/runtime": "^7.14.0",
"css-tree": "1.0.0-alpha.29", "clear-cut": "^2.0.2",
"css-tree": "^1.1.3",
"event-emitter": "^0.3.5" "event-emitter": "^0.3.5"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.6.4", "@babel/cli": "^7.14.3",
"@babel/core": "^7.6.4", "@babel/core": "^7.14.3",
"@babel/plugin-proposal-async-generator-functions": "^7.2.0", "@babel/plugin-proposal-async-generator-functions": "^7.14.2",
"@babel/plugin-transform-runtime": "^7.6.2", "@babel/plugin-transform-runtime": "^7.14.3",
"@babel/preset-env": "^7.6.3", "@babel/preset-env": "^7.14.2",
"babel-core": "^7.0.0-bridge.0", "@rollup/plugin-commonjs": "^19.0.0",
"babel-jest": "^24.9.0", "@rollup/plugin-json": "^4.1.0",
"chalk": "^2.4.2", "@rollup/plugin-node-resolve": "^13.0.0",
"eslint": "^6.5.1", "chalk": "^4.1.1",
"eslint": "^7.27.0",
"express": "^4.17.1", "express": "^4.17.1",
"jest": "^24.9.0", "ghostscript4js": "^3.2.1",
"jest-image-snapshot": "^2.11.0", "jest": "^26.6.3",
"puppeteer": "^2.0.0", "jest-image-snapshot": "^4.5.0",
"rimraf": "^3.0.0", "puppeteer": "^9.1.1",
"rollup": "^1.25.2", "rimraf": "^3.0.2",
"rollup-plugin-commonjs": "^10.1.0", "rollup": "^2.38.3",
"rollup-plugin-json": "^4.0.0", "rollup-plugin-license": "^2.1.0",
"rollup-plugin-livereload": "^1.0.4", "rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-serve": "^1.1.0"
"rollup-plugin-serve": "^1.0.1"
}, },
"scripts": { "scripts": {
"build": "./node_modules/.bin/rollup -c", "build": "rollup -c",
"legacy": "./node_modules/.bin/rollup -c rollup.legacy.config.js", "legacy": "rollup -c rollup.legacy.config.js",
"start": "./node_modules/.bin/rollup -w -c rollup.server.config.js", "start": "rollup -w -c rollup.server.config.js",
"test": "npm run tests && npm run specs", "test": "npm run lint && npm run tests && npm run specs",
"tests": "./node_modules/.bin/jest", "tests": "jest",
"specs": "./node_modules/.bin/jest --config=specs/jest.config.js", "specs": "jest --config=specs/jest.config.js",
"compile": "./node_modules/.bin/babel src/ -d lib/", "compile": "babel src/ -d lib/",
"pretest": "npm run build", "pretest": "npm run build",
"prepublishOnly": "npm run build && npm run compile && npm run legacy", "prepublishOnly": "npm run build && npm run compile && npm run legacy",
"watch": "./node_modules/.bin/rollup -w -c", "watch": "rollup -w -c",
"lint": "./node_modules/.bin/eslint -c .eslintrc.js src; exit 0", "lint": "eslint -c .eslintrc.js src specs",
"docker": "docker build -t pagedmedia/pagedjs . && docker run -it --security-opt 'seccomp=seccomp.json' -v $(pwd)/specs:/home/node/pagedjs/specs pagedmedia/pagedjs npm test" "docker": "docker build -t pagedmedia/pagedjs . && docker run -it --security-opt 'seccomp=seccomp.json' -v $(pwd)/specs:/home/node/pagedjs/specs pagedmedia/pagedjs npm test"
}, },
"repository": { "repository": {
...@@ -58,8 +59,5 @@ ...@@ -58,8 +59,5 @@
"files": [ "files": [
"dist", "dist",
"lib" "lib"
], ]
"optionalDependencies": {
"ghostscript4js": "^3.1.1"
}
} }
import resolve from 'rollup-plugin-node-resolve'; import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from 'rollup-plugin-commonjs'; import commonjs from "@rollup/plugin-commonjs";
import json from 'rollup-plugin-json'; import json from "@rollup/plugin-json";
import license from "rollup-plugin-license";
import pkg from './package.json'; import pkg from "./package.json";
const plugins = [ const plugins = [
resolve(), nodeResolve(),
commonjs({ commonjs({
include: 'node_modules/**' include: "node_modules/**"
}), }),
json() json(),
license({
banner: "@license Paged.js v<%= pkg.version %> | MIT | https://gitlab.pagedmedia.org/tools/pagedjs",
})
]; ];
export default [ export default [
...@@ -17,9 +21,9 @@ export default [ ...@@ -17,9 +21,9 @@ export default [
{ {
input: pkg.module, input: pkg.module,
output: { output: {
name: 'Paged', name: "Paged",
file: pkg.browser, file: pkg.browser,
format: 'umd' format: "umd"
}, },
plugins: plugins plugins: plugins
}, },
...@@ -27,9 +31,9 @@ export default [ ...@@ -27,9 +31,9 @@ export default [
{ {
input: pkg.module, input: pkg.module,
output: { output: {
name: "PagedModule", name: "PagedModule",
file: "./dist/paged.esm.js", file: "./dist/paged.esm.js",
format: 'es' format: "es"
}, },
plugins: plugins plugins: plugins
}, },
...@@ -37,9 +41,9 @@ export default [ ...@@ -37,9 +41,9 @@ export default [
{ {
input: "./src/polyfill/polyfill.js", input: "./src/polyfill/polyfill.js",
output: { output: {
name: 'PagedPolyfill', name: "PagedPolyfill",
file: "./dist/paged.polyfill.js", file: "./dist/paged.polyfill.js",
format: 'umd' format: "umd"
}, },
plugins: plugins plugins: plugins
} }
......
import resolve from 'rollup-plugin-node-resolve'; import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from 'rollup-plugin-commonjs'; import commonjs from "@rollup/plugin-commonjs";
import json from 'rollup-plugin-json'; import json from "@rollup/plugin-json";
import pkg from './package.json'; import pkg from './package.json';
const plugins = [ const plugins = [
resolve(), nodeResolve(),
commonjs(), commonjs(),
json() json()
]; ];
......
import resolve from 'rollup-plugin-node-resolve'; import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from 'rollup-plugin-commonjs'; import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import json from 'rollup-plugin-json';
// import builtins from 'rollup-plugin-node-builtins'; // import builtins from 'rollup-plugin-node-builtins';
// import globals from 'rollup-plugin-node-globals'; // import globals from 'rollup-plugin-node-globals';
import pkg from './package.json'; // import pkg from './package.json';
import serve from 'rollup-plugin-serve' import serve from 'rollup-plugin-serve'
import livereload from 'rollup-plugin-livereload' import livereload from 'rollup-plugin-livereload'
const plugins = [ const plugins = [
resolve(), nodeResolve(),
commonjs(), commonjs(),
json(), json(),
// globals(), // globals(),
...@@ -30,16 +29,6 @@ const plugins = [ ...@@ -30,16 +29,6 @@ const plugins = [
]; ];
export default [ export default [
{
input: pkg.module,
output: {
name: 'Paged',
file: pkg.browser,
format: 'umd'
},
plugins: plugins
},
{ {
input: "./src/polyfill/polyfill.js", input: "./src/polyfill/polyfill.js",
output: { output: {
......
{
"env": {
"jest": true
},
"globals": {
"DEBUG": "readonly",
"PDF_SETTINGS": "readonly",
"loadPage": "readonly"
}
}
const TIMEOUT = 10000; // Some book might take longer than this to renderer const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('bleed', async () => { describe("bleed", () => {
let page; let page;
let rendered; beforeAll(async () => {
beforeAll(async () => { page = await loadPage("bleed/bleed.html");
page = await loadPage('bleed/bleed.html') return page.rendered;
return page.rendered; }, TIMEOUT);
}, TIMEOUT)
afterAll(async () => { afterAll(async () => {
if (!DEBUG) { if (!DEBUG) {
await page.close(); await page.close();
} }
}) });
it('should render text', async () => { it("should render text", async () => {
let text = await page.evaluate(() => document.body.textContent); let text = await page.evaluate(() => document.body.textContent);
expect(text).toContain('Chapter 1. Loomings.'); expect(text).toContain("Chapter 1. Loomings.");
}) });
it('should render 7 pages', async () => { it("should render 7 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => r.length); let pages = await page.$$eval(".pagedjs_page", (r) => r.length);
expect(pages).toBe(7); expect(pages).toBe(7);
}) });
if (!DEBUG) { if (!DEBUG) {
it('should create a pdf', async () => { it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS); let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(1); expect(pdf).toMatchPDFSnapshot(1);
}) });
}
} }
) }
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-avoid', async () => { describe("break-after-avoid", () => {
let page; let page;
let rendered; beforeAll(async () => {
beforeAll(async () => { page = await loadPage("breaks/break-after/break-after-avoid/break-after-avoid.html");
page = await loadPage('breaks/break-after/break-after-avoid/break-after-avoid.html') return page.rendered;
return page.rendered; }, TIMEOUT);
}, TIMEOUT)
afterAll(async () => {
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it('should render 5 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(5);
})
it('page 3 should be Section 2', async () => {
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
expect(text).toContain('Section 2');
})
if (!DEBUG) { if (!DEBUG) {
it('should create a pdf', async () => { await page.close();
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(3);
})
} }
});
it("should render 5 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(5);
});
it("page 3 should be Section 2", async () => {
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
expect(text).toContain("Section 2");
});
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(3);
});
} }
) }
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-left', async () => { describe("break-after-left", () => {
let page; let page;
let rendered; beforeAll(async () => {
beforeAll(async () => { page = await loadPage("breaks/break-after/break-after-left/break-after-left.html");
page = await loadPage('breaks/break-after/break-after-left/break-after-left.html') return page.rendered;
return page.rendered; }, TIMEOUT);
}, TIMEOUT)
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => { it("should render 38 pages", async () => {
if (!DEBUG) { let pages = await page.$$eval(".pagedjs_page", (r) => {
await page.close(); return r.length;
} });
})
it('should render 38 pages', async () => { expect(pages).toEqual(38);
let pages = await page.$$eval(".pagedjs_page", (r) => { });
return r.length;
});
expect(pages).toEqual(38); it("should render page 4 as left", async () => {
}) let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 4 as left', async () => { expect(isLeft).toEqual(true);
let isLeft = await page.$eval("[data-page-number='4']", (r) => { });
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true); it("page 4 should be Section 2", async () => {
}) let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
it('page 4 should be Section 2', async () => { expect(text).toContain("Section 2");
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent); });
expect(text).toContain('Section 2'); it("should render page 7 as blank", async () => {
}) let isBlank = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 7 as blank', async () => { expect(isBlank).toEqual(true);
let isBlank = await page.$eval("[data-page-number='7']", (r) => { });
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true); it("should render page 8 as left", async () => {
}) let isLeft = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 8 as left', async () => { expect(isLeft).toEqual(true);
let isLeft = await page.$eval("[data-page-number='8']", (r) => { });
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true); it("page 8 should be Section 3", async () => {
}) let text = await page.$eval("[data-page-number='8']", (r) => r.textContent);
it('page 8 should be Section 3', async () => { expect(text).toContain("Section 3");
let text = await page.$eval("[data-page-number='8']", (r) => r.textContent); });
expect(text).toContain('Section 3'); it("page 9 should break after h2", async () => {
}) let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
it('page 9 should break after h2', async () => { expect(text.trim()).toEqual("A - h2 (inline element)");
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent); });
expect(text.trim()).toEqual('A - h2 (inline element)'); it("should render page 10 as left", async () => {
}) let isLeft = await page.$eval("[data-page-number='10']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 10 as left', async () => { expect(isLeft).toEqual(true);
let isLeft = await page.$eval("[data-page-number='10']", (r) => { });
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true); if (!DEBUG) {
}) it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) { expect(pdf).toMatchPDFSnapshot(4);
it('should create a pdf', async () => { expect(pdf).toMatchPDFSnapshot(7);
let pdf = await page.pdf(PDF_SETTINGS); expect(pdf).toMatchPDFSnapshot(8);
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(4); expect(pdf).toMatchPDFSnapshot(10);
expect(pdf).toMatchPDFSnapshot(7); });
expect(pdf).toMatchPDFSnapshot(8);
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(10);
})
}
} }
) }
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-page', async () => { describe("break-after-page", () => {
let page; let page;
let rendered; beforeAll(async () => {
beforeAll(async () => { page = await loadPage("breaks/break-after/break-after-page/break-after-page.html");
page = await loadPage('breaks/break-after/break-after-page/break-after-page.html') return page.rendered;
return page.rendered; }, TIMEOUT);
}, TIMEOUT)
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => { it("should render 31 pages", async () => {
if (!DEBUG) { let pages = await page.$$eval(".pagedjs_page", (r) => {
await page.close(); return r.length;
} });
})
it('should render 31 pages', async () => { expect(pages).toEqual(31);
let pages = await page.$$eval(".pagedjs_page", (r) => { });
return r.length;
});
expect(pages).toEqual(31); it("should render page 2 as left", async () => {
}) let isLeft = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 2 as left', async () => { expect(isLeft).toEqual(true);
let isLeft = await page.$eval("[data-page-number='2']", (r) => { });
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true); it("page 3 should be Section 1", async () => {
}) let text = await page.$eval("[data-page-number='2']", (r) => r.textContent);
it('page 3 should be Section 1', async () => { expect(text).toContain("Section 1");
let text = await page.$eval("[data-page-number='2']", (r) => r.textContent); });
expect(text).toContain('Section 1'); it("should render page 4 as left", async () => {
}) let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 4 as left', async () => { expect(isLeft).toEqual(true);
let isLeft = await page.$eval("[data-page-number='4']", (r) => { });
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true); it("page 4 should be Section 2", async () => {
}) let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
it('page 4 should be Section 2', async () => { expect(text).toContain("Section 2");
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent); });
expect(text).toContain('Section 2'); it("should render page 7 as right", async () => {
}) let isRight = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 7 as right', async () => { expect(isRight).toEqual(true);
let isRight = await page.$eval("[data-page-number='7']", (r) => { });
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true); it("page 7 should be Section 3", async () => {
}) let text = await page.$eval("[data-page-number='7']", (r) => r.textContent);
it('page 7 should be Section 3', async () => { expect(text).toContain("Section 3");
let text = await page.$eval("[data-page-number='7']", (r) => r.textContent); });
expect(text).toContain('Section 3'); it("page 8 should break after h2", async () => {
}) let text = await page.$eval("[data-page-number='8']", (r) => r.textContent);
it('page 8 should break after h2', async () => { expect(text.trim()).toEqual("A - h2 (inline element)");
let text = await page.$eval("[data-page-number='8']", (r) => r.textContent); });
expect(text.trim()).toEqual('A - h2 (inline element)'); it("should render page 9 as right", async () => {
}) let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 9 as right', async () => { expect(isRight).toEqual(true);
let isRight = await page.$eval("[data-page-number='9']", (r) => { });
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true); if (!DEBUG) {
}) it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) { expect(pdf).toMatchPDFSnapshot(2);
it('should create a pdf', async () => { expect(pdf).toMatchPDFSnapshot(4);
let pdf = await page.pdf(PDF_SETTINGS); expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(8);
expect(pdf).toMatchPDFSnapshot(2); expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(4); });
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(8);
expect(pdf).toMatchPDFSnapshot(9);
})
}
} }
) }
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-recto', async () => { describe("break-after-recto", () => {
let page; let page;
let rendered; beforeAll(async () => {
beforeAll(async () => { page = await loadPage("breaks/break-after/break-after-recto/break-after-recto.html");
page = await loadPage('breaks/break-after/break-after-recto/break-after-recto.html') return page.rendered;
return page.rendered; }, TIMEOUT);
}, TIMEOUT)
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => { it("should render 39 pages", async () => {
if (!DEBUG) { let pages = await page.$$eval(".pagedjs_page", (r) => {
await page.close(); return r.length;
} });
})
it('should render 39 pages', async () => { expect(pages).toEqual(39);
let pages = await page.$$eval(".pagedjs_page", (r) => { });
return r.length;
});
expect(pages).toEqual(39); it("should render page 2 as blank", async () => {
}) let isBlank = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 2 as blank', async () => { expect(isBlank).toEqual(true);
let isBlank = await page.$eval("[data-page-number='2']", (r) => { });
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true); it("should render page 3 as recto", async () => {
}) let isRight = await page.$eval("[data-page-number='3']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 3 as recto', async () => { expect(isRight).toEqual(true);
let isRight = await page.$eval("[data-page-number='3']", (r) => { });
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true); it("page 3 should be Section 1", async () => {
}) let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
it('page 3 should be Section 1', async () => { expect(text).toContain("Section 1");
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent); });
expect(text).toContain('Section 1'); it("should render page 5 as recto", async () => {
}) let isRight = await page.$eval("[data-page-number='5']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 5 as recto', async () => { expect(isRight).toEqual(true);
let isRight = await page.$eval("[data-page-number='5']", (r) => { });
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true); it("page 5 should be Section 2", async () => {
}) let text = await page.$eval("[data-page-number='5']", (r) => r.textContent);
it('page 5 should be Section 2', async () => { expect(text).toContain("Section 2");
let text = await page.$eval("[data-page-number='5']", (r) => r.textContent); });
expect(text).toContain('Section 2'); it("should render page 8 as blank", async () => {
}) let isBlank = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 8 as blank', async () => { expect(isBlank).toEqual(true);
let isBlank = await page.$eval("[data-page-number='8']", (r) => { });
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true); it("should render page 9 as recto", async () => {
}) let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 9 as recto', async () => { expect(isRight).toEqual(true);
let isRight = await page.$eval("[data-page-number='9']", (r) => { });
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true); it("page 9 should be Section 3", async () => {
}) let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
it('page 9 should be Section 3', async () => { expect(text).toContain("Section 3");
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent); });
expect(text).toContain('Section 3'); it("page 10 should break after h2", async () => {
}) let text = await page.$eval("[data-page-number='10']", (r) => r.textContent);
it('page 10 should break after h2', async () => { expect(text.trim()).toEqual("A - h2 (inline element)");
let text = await page.$eval("[data-page-number='10']", (r) => r.textContent); });
expect(text.trim()).toEqual('A - h2 (inline element)'); it("should render page 11 as recto", async () => {
}) let isRight = await page.$eval("[data-page-number='11']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 11 as recto', async () => { expect(isRight).toEqual(true);
let isRight = await page.$eval("[data-page-number='11']", (r) => { });
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true); if (!DEBUG) {
}) it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) { expect(pdf).toMatchPDFSnapshot(2);
it('should create a pdf', async () => { expect(pdf).toMatchPDFSnapshot(3);
let pdf = await page.pdf(PDF_SETTINGS); expect(pdf).toMatchPDFSnapshot(5);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(2); expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(3); expect(pdf).toMatchPDFSnapshot(10);
expect(pdf).toMatchPDFSnapshot(5); expect(pdf).toMatchPDFSnapshot(11);
expect(pdf).toMatchPDFSnapshot(7); });
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(10);
expect(pdf).toMatchPDFSnapshot(11);
})
}
} }
) }
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-right', async () => { describe("break-after-right", () => {
let page; let page;
let rendered; beforeAll(async () => {
beforeAll(async () => { page = await loadPage("breaks/break-after/break-after-right/break-after-right.html");
page = await loadPage('breaks/break-after/break-after-right/break-after-right.html') return page.rendered;
return page.rendered; }, TIMEOUT);
}, TIMEOUT)
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => { it("should render 39 pages", async () => {
if (!DEBUG) { let pages = await page.$$eval(".pagedjs_page", (r) => {
await page.close(); return r.length;
} });
})
it('should render 39 pages', async () => { expect(pages).toEqual(39);
let pages = await page.$$eval(".pagedjs_page", (r) => { });
return r.length;
});
expect(pages).toEqual(39); it("should render page 2 as blank", async () => {
}) let isBlank = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 2 as blank', async () => { expect(isBlank).toEqual(true);
let isBlank = await page.$eval("[data-page-number='2']", (r) => { });
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true); it("should render page 3 as right", async () => {
}) let isRight = await page.$eval("[data-page-number='3']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 3 as right', async () => { expect(isRight).toEqual(true);
let isRight = await page.$eval("[data-page-number='3']", (r) => { });
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true); it("page 3 should be Section 1", async () => {
}) let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
it('page 3 should be Section 1', async () => { expect(text).toContain("Section 1");
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent); });
expect(text).toContain('Section 1'); it("should render page 5 as right", async () => {
}) let isRight = await page.$eval("[data-page-number='5']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 5 as right', async () => { expect(isRight).toEqual(true);
let isRight = await page.$eval("[data-page-number='5']", (r) => { });
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true); it("page 5 should be Section 2", async () => {
}) let text = await page.$eval("[data-page-number='5']", (r) => r.textContent);
it('page 5 should be Section 2', async () => { expect(text).toContain("Section 2");
let text = await page.$eval("[data-page-number='5']", (r) => r.textContent); });
expect(text).toContain('Section 2'); it("should render page 8 as blank", async () => {
}) let isBlank = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 8 as blank', async () => { expect(isBlank).toEqual(true);
let isBlank = await page.$eval("[data-page-number='8']", (r) => { });
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true); it("should render page 9 as right", async () => {
}) let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 9 as right', async () => { expect(isRight).toEqual(true);
let isRight = await page.$eval("[data-page-number='9']", (r) => { });
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true); it("page 9 should be Section 3", async () => {
}) let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
it('page 9 should be Section 3', async () => { expect(text).toContain("Section 3");
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent); });
expect(text).toContain('Section 3'); it("page 10 should break after h2", async () => {
}) let text = await page.$eval("[data-page-number='10']", (r) => r.textContent);
it('page 10 should break after h2', async () => { expect(text.trim()).toEqual("A - h2 (inline element)");
let text = await page.$eval("[data-page-number='10']", (r) => r.textContent); });
expect(text.trim()).toEqual('A - h2 (inline element)'); it("should render page 11 as right", async () => {
}) let isRight = await page.$eval("[data-page-number='11']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 11 as right', async () => { expect(isRight).toEqual(true);
let isRight = await page.$eval("[data-page-number='11']", (r) => { });
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true); if (!DEBUG) {
}) it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) { expect(pdf).toMatchPDFSnapshot(2);
it('should create a pdf', async () => { expect(pdf).toMatchPDFSnapshot(3);
let pdf = await page.pdf(PDF_SETTINGS); expect(pdf).toMatchPDFSnapshot(5);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(2); expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(3); expect(pdf).toMatchPDFSnapshot(10);
expect(pdf).toMatchPDFSnapshot(5); expect(pdf).toMatchPDFSnapshot(11);
expect(pdf).toMatchPDFSnapshot(7); });
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(10);
expect(pdf).toMatchPDFSnapshot(11);
})
}
} }
) }
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-verso', async () => { describe("break-after-verso", () => {
let page; let page;
let rendered; beforeAll(async () => {
beforeAll(async () => { page = await loadPage("breaks/break-after/break-after-verso/break-after-verso.html");
page = await loadPage('breaks/break-after/break-after-verso/break-after-verso.html') return page.rendered;
return page.rendered; }, TIMEOUT);
}, TIMEOUT)
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => { it("should render 38 pages", async () => {
if (!DEBUG) { let pages = await page.$$eval(".pagedjs_page", (r) => {
await page.close(); return r.length;
} });
})
it('should render 38 pages', async () => { expect(pages).toEqual(38);
let pages = await page.$$eval(".pagedjs_page", (r) => { });
return r.length;
});
expect(pages).toEqual(38); it("should render page 4 as verso", async () => {
}) let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 4 as verso', async () => { expect(isLeft).toEqual(true);
let isLeft = await page.$eval("[data-page-number='4']", (r) => { });
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true); it("page 4 should be Section 2", async () => {
}) let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
it('page 4 should be Section 2', async () => { expect(text).toContain("Section 2");
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent); });
expect(text).toContain('Section 2'); it("should render page 7 as blank", async () => {
}) let isBlank = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 7 as blank', async () => { expect(isBlank).toEqual(true);
let isBlank = await page.$eval("[data-page-number='7']", (r) => { });
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true); it("should render page 8 as verso", async () => {
}) let isLeft = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 8 as verso', async () => { expect(isLeft).toEqual(true);
let isLeft = await page.$eval("[data-page-number='8']", (r) => { });
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true); it("page 8 should be Section 3", async () => {
}) let text = await page.$eval("[data-page-number='8']", (r) => r.textContent);
it('page 8 should be Section 3', async () => { expect(text).toContain("Section 3");
let text = await page.$eval("[data-page-number='8']", (r) => r.textContent); });
expect(text).toContain('Section 3'); it("page 9 should break after h2", async () => {
}) let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
it('page 9 should break after h2', async () => { expect(text.trim()).toEqual("A - h2 (inline element)");
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent); });
expect(text.trim()).toEqual('A - h2 (inline element)'); it("should render page 10 as verso", async () => {
}) let isLeft = await page.$eval("[data-page-number='10']"