Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add output unit test to pagedown #253

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.Rhistory
.RData
.Ruserdata
node_modules
tests/test-output/*.html
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const config = {
verbose: false,
// transform: {
// "^.+\\.html?$": "html-loader-jest"
// },
preset: "jest-puppeteer"
};

module.exports = config;
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"devDependencies": {
"jest": "^27.3.1",
"jest-puppeteer": "^6.0.0",
"puppeteer": "^11.0.0",
"puppeteer-core": "^11.0.0"
}
}
14 changes: 14 additions & 0 deletions tests/test-output/longtable.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
output:
pagedown::html_paged
---

```{r, echo=FALSE, message=FALSE, results=FALSE}
data(iris)
```

# Table Test

```{r, echo=FALSE}
knitr::kable(iris)
```
44 changes: 44 additions & 0 deletions tests/test-output/longtable.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const exec = require('child_process').execSync;

describe("Long tables", () => {
// TODO encapsulate the file path to make it easier to replicate in other tests
const cwd = process.cwd();
const file = 'longtable'
const rmdFile = cwd + '/tests/test-output/' + file + '.Rmd';
const htmlFile = cwd + '/tests/test-output/' + file + '.html';
const htmlFileUri = 'file://' + cwd + '/tests/test-output/' + file + '.html';

beforeAll(async () => {
exec('Rscript -e "rmarkdown::render(\'' + rmdFile + '\')"');
await page.goto(htmlFileUri, { waitUntil: "networkidle2" });
});

afterAll(() => {
exec('rm \'' + htmlFile + '\'');
});


it("Must page break", async () => {
const pageCount = await page.$$eval(
'div.pagedjs_page',
(el) => el.length);

expect(pageCount).toEqual(8);
});

it("Must break table", async () => {
const tableCount = await page.$$eval(
'table',
(el) => el.length);

expect(tableCount).toEqual(6);
});

it("Must page repeat thead", async () => {
const theadCount = await page.$$eval(
'thead',
(el) => el.length);

expect(theadCount).toEqual(6);
});
});
Loading