Skip to content

Commit

Permalink
Add E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyNikipelau committed Aug 29, 2024
1 parent e76f3df commit 139b322
Show file tree
Hide file tree
Showing 12 changed files with 804 additions and 111 deletions.
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"root": true,
"extends": "eslint-config-formio",
"plugins": [
"mocha"
],
"env": {
"node": true,
"es6": true
"es6": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2020
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ jobs:
- name: Login to Dockerhub
run: echo ${{secrets.DOCKERHUB_ACCESS_TOKEN}} | docker login -u ${{vars.DOCKERHUB_USERNAME}} --password-stdin

- name: Build intermediate Docker image
run: docker build -f deployment/docker/Dockerfile -t formio/pdf-libs:tmp .

- name: Run tests on the Docker image
run: docker run formio/pdf-libs:tmp npm test

- name: Build the Docker image
run: docker build -f deployment/docker/Dockerfile -t formio/pdf-libs:${{github.ref_name}} .
run: docker build -f deployment/docker/Dockerfile-no-tests -t formio/pdf-libs:${{github.ref_name}} .

- name: Push the Docker image
run: docker push formio/pdf-libs:${{github.ref_name}}
Expand All @@ -27,4 +33,4 @@ jobs:
run: |
docker tag formio/pdf-libs:${{github.ref_name}} formio/pdf-libs:latest
docker push formio/pdf-libs:latest
if: ${{!contains(github.ref_name, 'rc')}}
if: ${{ !contains(github.ref_name, 'rc') && !contains(github.ref_name, 'test') }}
33 changes: 0 additions & 33 deletions .github/workflows/test.yml

This file was deleted.

2 changes: 2 additions & 0 deletions deployment/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ RUN yarn install --production --frozen-lockfile
COPY src ./src
COPY *.js ./

COPY test ./test

# Add docs
COPY docs ./docs

Expand Down
5 changes: 5 additions & 0 deletions deployment/docker/Dockerfile-no-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM formio/pdf-libs:tmp

WORKDIR /usr/src/pdf-libs
# Remove test folder
RUN rm -rf test
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
"author": "",
"license": "ISC",
"dependencies": {
"assert": "^2.1.0",
"cors": "^2.8.5",
"debug": "^4.3.6",
"dotenv": "^16.4.5",
"eslint-plugin-mocha": "^10.5.0",
"express": "^4.19.2",
"formidable": "^3.5.1",
"fs-extra": "^11.2.0",
"lodash": "^4.17.21",
"mocha": "^10.6.0",
"superagent": "^10.1.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"assert": "^2.0.0",
"eslint": "^9.6.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-formio": "^1.1.4",
"eslint-plugin-import": "^2.29.1",
"mocha": "^10.6.0",
"mock-require": "^3.0.3",
"nodemon": "^3.1.4",
"superagent": "^9.0.2"
"nodemon": "^3.1.4"
}
}
29 changes: 29 additions & 0 deletions test/e2e/convertToHtml.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const path = require('path');
const assert = require('assert');
const superagent = require('superagent');
const runServer = require('./runServer');

const PDF_FIXTURE = path.resolve(__dirname, './fixtures/fw4.pdf');

describe('Test convertToHtml', () => {
let server;

before(async () => {
server = await runServer(3000);
});

it('should return html', async () => {
const response = await superagent
.post(`http://localhost:3000/pdf/convertToHtml`)
.set('Content-Type', 'multipart/form-data')
.attach('pdf', PDF_FIXTURE);

const html = response.text;
assert.ok(html.includes('<!DOCTYPE html>'));
assert.ok(html.includes('Base CSS for pdf2htmlEX'));
});

after(() => {
server.kill();
});
});
Loading

0 comments on commit 139b322

Please sign in to comment.