Skip to content

Commit

Permalink
Switch to Playwright for Specs runner
Browse files Browse the repository at this point in the history
Switch to module loading for tests and specs
Update specs to run in docker only
Update docker run test command
Update babel to output cjs
Update rollup input
Split out specs from test
Update readme
Add remaining spec snapshots
  • Loading branch information
fchasen committed May 5, 2022
1 parent 4a62333 commit 73ffb07
Show file tree
Hide file tree
Showing 447 changed files with 6,369 additions and 8,434 deletions.
12 changes: 6 additions & 6 deletions .eslintrc.js → .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module.exports = {
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true,
"jest": true
"jest": true,
"es2022": true
},
"globals": {
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 9
"ecmaVersion": 2020
},
"rules": {
"indent": [
Expand All @@ -34,13 +35,12 @@ module.exports = {
"error",
"always"
],
"no-unused-vars" : ["warn"],
"no-console" : ["error", { allow: ["warn", "error"] }],
"no-console" : ["error", { "allow": ["warn", "error"] }],
"no-unused-vars": [
"error",
{ "vars": "all", "args": "none" }
],
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
"valid-jsdoc": ["warn"]
}
};
}
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ npm-test:
before_script:
- docker build -t pagedmedia/pagedjs .
script:
- docker run --security-opt 'seccomp=seccomp.json' pagedmedia/pagedjs npm test
- docker run --ipc=host pagedmedia/pagedjs npm test
- docker run --ipc=host pagedmedia/pagedjs npm run specs

# This job requires to setup GitLab the following way:
# 1. On https://www.npmjs.com/settings/tokens/create
Expand Down
51 changes: 13 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
FROM node:17
FROM mcr.microsoft.com/playwright:v1.20.0-focal

# Application parameters and variables
ENV NODE_ENV=development
ENV PORT=9090
ENV DIRECTORY /home/node/pagedjs
ENV DIRECTORY /home/pwuser/pagedjs

# Configuration for Chrome
ENV CONNECTION_TIMEOUT=60000
ENV CHROME_PATH=/usr/bin/google-chrome

# Configuration for GS4JS
ENV GS4JS_HOME=/usr/lib/x86_64-linux-gnu
RUN echo "GS4JS_HOME=/usr/lib/$(gcc -dumpmachine)"

# Install ghostscript
RUN apt-get update && \
Expand All @@ -19,33 +18,18 @@ RUN apt-get update && \
apt-get install -y libgs-dev && \
rm -rf /var/lib/apt/lists/*

# See https://github.com/GoogleChrome/puppeteer/blob/master/.ci/node12/Dockerfile.linux
RUN apt-get update && \
apt-get -y install xvfb gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 \
libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 \
libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \
libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 \
libxtst6 ca-certificates fonts-liberation libnss3 lsb-release xdg-utils wget && \
rm -rf /var/lib/apt/lists/*

# Update Freetype
COPY docker-font.conf /etc/fonts/local.conf
ENV FREETYPE_PROPERTIES="truetype:interpreter-version=35"
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
RUN apt-get update \
&& sh -c 'echo "deb http://http.us.debian.org/debian stable main contrib non-free" >> /etc/apt/sources.list' \
&& apt-get update \
&& apt-get install -y ttf-mscorefonts-installer \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
&& apt-get install -y --no-install-recommends fontconfig ttf-mscorefonts-installer

# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.

# Install fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
RUN apt-get update && apt-get install -y wget --no-install-recommends \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome-unstable.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
&& apt-get install -y fonts-liberation fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y curl \
Expand All @@ -64,25 +48,16 @@ RUN npm install -g node-gyp

RUN mkdir -p $DIRECTORY

# Add user so we don't need --no-sandbox.
# RUN groupadd -r node && useradd -r -g node -G audio,video node \
RUN adduser node audio \
&& adduser node video \
&& mkdir -p /home/node/Downloads \
&& chown -R node:node /home/node \
&& chown -R node:node /usr/lib \
&& chown -R node:node $DIRECTORY

# Run everything after as non-privileged user.
USER node
# All running as root and as non-privileged user.
RUN chmod -R 777 $DIRECTORY

WORKDIR $DIRECTORY

COPY --chown=node:node package.json package-lock.json $DIRECTORY/
COPY package.json package-lock.json $DIRECTORY/
RUN npm install
RUN npm install ghostscript4js
RUN GS4JS_HOME="/usr/lib/$(gcc -dumpmachine)" npm install ghostscript4js

COPY --chown=node:node . $DIRECTORY
COPY . $DIRECTORY

EXPOSE $PORT

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ They can also output a pdf and compare pages (one at a time) in that PDF with sa

The PDF comparison tests depend on the `ghostscript` and the `ghostscript4js` package.

To run them you'll need to install a local version of Ghostscript for you system according to https://www.npmjs.com/package/ghostscript4js#prerequisites
It is recomend to run these in the Docker container below via:

```bash
npm run docker-specs
```

However if you'd like to run the specs outside of Docker, you'll need to install a local version of Ghostscript for your system according to https://www.npmjs.com/package/ghostscript4js#prerequisites

For Mac you can install it with

Expand Down Expand Up @@ -247,7 +253,7 @@ docker run -it -p 9090:9090 pagedmedia/pagedjs
The tests and specs can be run within the container by passing a `seccomp` file for Chrome and running `npm test`

```bash
docker run -it --security-opt 'seccomp=seccomp.json' pagedmedia/pagedjs npm test
docker run -it --security-opt 'seccomp=seccomp.json' pagedmedia/pagedjs npm test && npm run specs
```

## Contributors
Expand Down
24 changes: 24 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test

on:
pull_request:
push:
branches:
- "main"

jobs:
test:
name: Run test suite
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build docker image
run: docker build -t pagedmedia/pagedjs .

- name: Run tests
run: docker run --ipc=host pagedmedia/pagedjs npm test

- name: Run specs
run: docker run --ipc=host pagedmedia/pagedjs npm run specs
4 changes: 4 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/env"],
"plugins": ["@babel/plugin-proposal-async-generator-functions", "@babel/plugin-transform-runtime"]
}
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
export default {
testMatch: ['**/?(*.)(test).js'],
}
testEnvironment: "jsdom",
};
Loading

0 comments on commit 73ffb07

Please sign in to comment.