Commit 73ffb071 authored by Fred Chasen's avatar Fred Chasen
Browse files

Switch to Playwright for Specs runner

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
parent 4a623338
Pipeline #33070 passed with stage
in 4 minutes and 27 seconds
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": [
......@@ -34,8 +35,7 @@ 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" }
......@@ -43,4 +43,4 @@ module.exports = {
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
"valid-jsdoc": ["warn"]
}
};
}
......@@ -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
......
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 && \
......@@ -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 \
......@@ -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
......
......@@ -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
......@@ -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
......
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
\ No newline at end of file
{
"presets": ["@babel/env"],
"plugins": ["@babel/plugin-proposal-async-generator-functions", "@babel/plugin-transform-runtime"]
}
module.exports = {
export default {
testMatch: ['**/?(*.)(test).js'],
}
testEnvironment: "jsdom",
};
This diff is collapsed.
......@@ -5,62 +5,63 @@
"author": "Fred Chasen",
"license": "MIT",
"homepage": "https://pagedmedia.org",
"main": "lib/index.js",
"module": "src/index.js",
"main": "src/index.js",
"browser": "dist/paged.js",
"type": "module",
"exports": {
"import": "./src/index.js",
"require": "./lib/index.js",
"require": "./lib/index.cjs",
"browser": "./dist/paged.js",
"default": "./lib/index.js"
"default": "./src/index.js"
},
"dependencies": {
"@babel/polyfill": "^7.10.1",
"@babel/runtime": "^7.14.0",
"@babel/runtime": "^7.17.8",
"clear-cut": "^2.0.2",
"css-tree": "^1.1.3",
"event-emitter": "^0.3.5"
},
"devDependencies": {
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/plugin-proposal-async-generator-functions": "^7.14.2",
"@babel/plugin-transform-runtime": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"@rollup/plugin-commonjs": "^19.0.0",
"@babel/cli": "^7.17.6",
"@babel/core": "^7.17.8",
"@babel/plugin-proposal-async-generator-functions": "^7.16.8",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@rollup/plugin-commonjs": "^21.0.3",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"chalk": "^4.1.1",
"eslint": "^7.27.0",
"express": "^4.17.1",
"ghostscript4js": "^3.2.1",
"jest": "^26.6.3",
"jest-image-snapshot": "^4.5.0",
"puppeteer": "^9.1.1",
"@rollup/plugin-node-resolve": "^13.1.3",
"chalk": "^5.0.1",
"eslint": "^8.12.0",
"express": "^4.17.3",
"jest": "^27.5.1",
"jest-image-snapshot": "^4.5.1",
"rimraf": "^3.0.2",
"rollup": "^2.38.3",
"rollup-plugin-license": "^2.1.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup": "^2.70.1",
"rollup-plugin-license": "^2.6.1",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-serve": "^1.1.0"
"rollup-plugin-serve": "^1.1.0",
"playwright-core": "^1.20.2"
},
"scripts": {
"build": "rollup -c",
"legacy": "rollup -c rollup.legacy.config.js",
"start": "rollup -w -c rollup.server.config.js",
"test": "npm run lint && npm run tests && npm run specs",
"tests": "jest",
"specs": "jest --config=specs/jest.config.js",
"compile": "babel src/ -d lib/",
"pretest": "npm run build",
"test": "npm run lint && jest",
"specs": "npm run pretest && jest --config=specs/jest.config.js",
"compile": "babel src/ -d lib/ --out-file-extension .cjs",
"pretest": "npm run build && npm run compile",
"prepublishOnly": "npm run build && npm run compile && npm run legacy",
"watch": "rollup -w -c",
"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"
"lint": "eslint -c .eslintrc.json src specs",
"docker-build": "docker build -t pagedmedia/pagedjs .",
"docker-test": "docker build -t pagedmedia/pagedjs . && docker run -it --rm --ipc=host --user pwuser --security-opt 'seccomp=seccomp.json' -v $(pwd)/specs:/home/node/pagedjs/specs pagedmedia/pagedjs npm test",
"docker-specs": "docker build -t pagedmedia/pagedjs . && docker run -it --rm --ipc=host -v $(pwd)/specs:/home/node/pagedjs/specs pagedmedia/pagedjs npm run specs",
"docker-update-specs": "docker build -t pagedmedia/pagedjs . && docker run -it --rm --ipc=host -v $(pwd)/specs:/home/node/pagedjs/specs pagedmedia/pagedjs npm specs -- -u"
},
"repository": {
"type": "git",
"url": "https://gitlab.pagedmedia.org/polyfills/pagedjs.git"
"url": "https://gitlab.coko.foundation/pagedjs/pagedjs.git"
},
"files": [
"dist",
......
......@@ -19,7 +19,7 @@ const plugins = [
export default [
// browser-friendly UMD build
{
input: pkg.module,
input: pkg.main,
output: {
name: "Paged",
file: pkg.browser,
......@@ -29,7 +29,7 @@ export default [
},
{
input: pkg.module,
input: pkg.main,
output: {
name: "PagedModule",
file: "./dist/paged.esm.js",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment