Commit c78babed authored by Guillaume's avatar Guillaume

Apply linter on specs

parent 2a118035
......@@ -47,7 +47,7 @@
"pretest": "npm run build",
"prepublishOnly": "npm run build && npm run compile && npm run legacy",
"watch": "rollup -w -c",
"lint": "eslint -c .eslintrc.js src",
"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"
},
"repository": {
......
{
"env": {
"jest": true
},
"globals": {
"DEBUG": "readonly",
"PDF_SETTINGS": "readonly",
"loadPage": "readonly"
}
}
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('bleed', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('bleed/bleed.html')
return page.rendered;
}, TIMEOUT)
describe("bleed", () => {
let page;
beforeAll(async () => {
page = await loadPage("bleed/bleed.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
it('should render text', async () => {
let text = await page.evaluate(() => document.body.textContent);
expect(text).toContain('Chapter 1. Loomings.');
})
it("should render text", async () => {
let text = await page.evaluate(() => document.body.textContent);
expect(text).toContain("Chapter 1. Loomings.");
});
it('should render 7 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => r.length);
expect(pages).toBe(7);
})
it("should render 7 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => r.length);
expect(pages).toBe(7);
});
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) {
it("should create a pdf", async () => {
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
describe('break-after-avoid', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('breaks/break-after/break-after-avoid/break-after-avoid.html')
return page.rendered;
}, TIMEOUT)
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');
})
describe("break-after-avoid", () => {
let page;
beforeAll(async () => {
page = await loadPage("breaks/break-after/break-after-avoid/break-after-avoid.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(3);
})
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) {
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
describe('break-after-left', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('breaks/break-after/break-after-left/break-after-left.html')
return page.rendered;
}, TIMEOUT)
describe("break-after-left", () => {
let page;
beforeAll(async () => {
page = await loadPage("breaks/break-after/break-after-left/break-after-left.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it("should render 38 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
it('should render 38 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(38);
});
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 () => {
let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
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 () => {
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
expect(text).toContain("Section 2");
});
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 () => {
let isBlank = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true);
});
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 () => {
let isLeft = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
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 () => {
let text = await page.$eval("[data-page-number='8']", (r) => r.textContent);
expect(text).toContain("Section 3");
});
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 () => {
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
expect(text.trim()).toEqual("A - h2 (inline element)");
});
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 () => {
let isLeft = await page.$eval("[data-page-number='10']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
expect(isLeft).toEqual(true);
})
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(4);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(8);
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(10);
})
}
expect(pdf).toMatchPDFSnapshot(4);
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
describe('break-after-page', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('breaks/break-after/break-after-page/break-after-page.html')
return page.rendered;
}, TIMEOUT)
describe("break-after-page", () => {
let page;
beforeAll(async () => {
page = await loadPage("breaks/break-after/break-after-page/break-after-page.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it("should render 31 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
it('should render 31 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(31);
});
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 () => {
let isLeft = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
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 () => {
let text = await page.$eval("[data-page-number='2']", (r) => r.textContent);
expect(text).toContain("Section 1");
});
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 () => {
let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
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 () => {
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
expect(text).toContain("Section 2");
});
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 () => {
let isRight = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
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 () => {
let text = await page.$eval("[data-page-number='7']", (r) => r.textContent);
expect(text).toContain("Section 3");
});
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 () => {
let text = await page.$eval("[data-page-number='8']", (r) => r.textContent);
expect(text.trim()).toEqual("A - h2 (inline element)");
});
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 () => {
let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(2);
expect(pdf).toMatchPDFSnapshot(4);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(8);
expect(pdf).toMatchPDFSnapshot(9);
})
}
expect(pdf).toMatchPDFSnapshot(2);
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
describe('break-after-recto', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('breaks/break-after/break-after-recto/break-after-recto.html')
return page.rendered;
}, TIMEOUT)
describe("break-after-recto", () => {
let page;
beforeAll(async () => {
page = await loadPage("breaks/break-after/break-after-recto/break-after-recto.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it("should render 39 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
it('should render 39 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(39);
});
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 () => {
let isBlank = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true);
});
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 () => {
let isRight = await page.$eval("[data-page-number='3']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
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 () => {
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
expect(text).toContain("Section 1");
});
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 () => {
let isRight = await page.$eval("[data-page-number='5']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
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 () => {
let text = await page.$eval("[data-page-number='5']", (r) => r.textContent);
expect(text).toContain("Section 2");
});
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 () => {
let isBlank = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true);
});
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 () => {
let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
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 () => {
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
expect(text).toContain("Section 3");
});
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 () => {
let text = await page.$eval("[data-page-number='10']", (r) => r.textContent);
expect(text.trim()).toEqual("A - h2 (inline element)");
});
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");
});