Skip to content

Commit b3108b6

Browse files
committed
test(e2e): change PDF approach to work with headless browsers
1 parent 88fa3bb commit b3108b6

17 files changed

Lines changed: 231 additions & 90 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env:
1616
NODE_ENV: test
1717
WEBSITE_URL: http://localhost:3000
1818
API_URL: http://localhost:3060
19+
PDF_SERVICE_URL: http://localhost:3002
1920
API_KEY: dvl-1510egmf4a23d80342403fb599qd
2021
CI: true
2122

.github/workflows/e2e.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ env:
88
OC_ENV: ci
99
NODE_ENV: test
1010
WEBSITE_URL: http://localhost:3000
11+
IMAGES_URL: http://localhost:3001
12+
PDF_SERVICE_URL: http://localhost:3002
1113
API_URL: http://localhost:3060
1214
API_KEY: dvl-1510egmf4a23d80342403fb599qd
1315
CI: true
1416

1517
E2E_TEST: 1
1618
PGHOST: localhost
1719
PGUSER: postgres
18-
IMAGES_URL: http://localhost:3001
1920
CYPRESS_RECORD: false
2021
CYPRESS_VIDEO: false
2122
CYPRESS_VIDEO_UPLOAD_ON_PASSES: false
@@ -255,12 +256,26 @@ jobs:
255256
env:
256257
CYPRESS_TEST_FILES: ${{ matrix.files }}
257258

259+
- name: Archive logs
260+
uses: actions/upload-artifact@v3
261+
with:
262+
name: logs
263+
path: logs
264+
if: ${{ failure() }}
265+
258266
- name: Archive test screenshots
259267
uses: actions/upload-artifact@v3
260268
with:
261269
name: screenshots
262270
path: test/cypress/screenshots
263271
if: ${{ failure() }}
264272

273+
- name: Archive download folder
274+
uses: actions/upload-artifact@v3
275+
with:
276+
name: downloads
277+
path: test/cypress/downloads
278+
if: ${{ failure() }}
279+
265280
- name: Report Coverage
266281
run: npm run test:coverage

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_modules
55
npm-debug.log.*
66
./report.*.json
77
*.log
8+
logs
89
yarn.lock
910
.DS_Store
1011
build

components/CreateGiftCardsSuccess.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default class CreateGiftCardsSuccess extends React.Component {
6868
};
6969

7070
renderManualSuccess() {
71-
const filename = `${this.props.collectiveSlug}-giftcards-${Date.now()}.pdf`;
71+
const filename = `${this.props.collectiveSlug}-giftcards.pdf`;
7272
const downloadUrl = giftCardsDownloadUrl(filename);
7373

7474
return (

components/transactions/TransactionDetails.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ const TransactionDetails = ({ displayActions, transaction, onMutationSuccess })
271271
{showDownloadInvoiceButton && (
272272
<StyledButton
273273
buttonSize="small"
274+
data-loading={loadingInvoice}
274275
loading={loadingInvoice}
275276
onClick={downloadInvoiceWith({
276277
transactionUuid: uuid,

cypress.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// eslint-disable-next-line node/no-unpublished-require
22
const { defineConfig } = require('cypress');
3-
const { readPdf } = require('./test/cypress/scripts/read-pdf.ts');
4-
const { listFiles } = require('./test/cypress/scripts/list-files.ts');
3+
const { getTextFromPdfContent } = require('./test/cypress/scripts/get-text-from-pdf-content.ts');
54

65
module.exports = defineConfig({
76
experimentalMemoryManagement: true,
@@ -41,8 +40,7 @@ module.exports = defineConfig({
4140
console.log(...message); // eslint-disable-line no-console
4241
return null;
4342
},
44-
readPdf,
45-
listFiles,
43+
getTextFromPdfContent,
4644
});
4745

4846
config.baseUrl = process.env.WEBSITE_URL || 'http://localhost:3000';

lib/transactions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { formatCurrency } from './currency-utils';
1212
import { toIsoDateStr } from './date-utils';
1313
import { createError, ERROR } from './errors';
1414
import { getFromLocalStorage, LOCAL_STORAGE_KEYS } from './local-storage';
15-
import { collectiveInvoiceURL, invoiceServiceURL, transactionInvoiceURL } from './url-helpers';
15+
import { collectiveInvoiceURL, PDF_SERVICE_URL, transactionInvoiceURL } from './url-helpers';
1616

1717
const messages = defineMessages({
1818
hostFee: {
@@ -210,7 +210,7 @@ export const saveInvoice = async ({
210210
dateTo,
211211
createdAt,
212212
});
213-
const getParams = { format: 'blob', allowExternal: invoiceServiceURL };
213+
const getParams = { format: 'blob', allowExternal: PDF_SERVICE_URL };
214214
const accessToken = getFromLocalStorage(LOCAL_STORAGE_KEYS.ACCESS_TOKEN);
215215
if (accessToken) {
216216
getParams.headers = { Authorization: `Bearer ${accessToken}` };

lib/url-helpers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CollectiveType } from './constants/collectives';
44
import { TransactionTypes } from './constants/transactions';
55
import { getWebsiteUrl } from './utils';
66

7-
export const invoiceServiceURL = process.env.PDF_SERVICE_URL;
7+
export const PDF_SERVICE_URL = process.env.PDF_SERVICE_URL;
88

99
// ---- Utils ----
1010

@@ -37,15 +37,15 @@ export const objectToQueryString = options => {
3737
// ---- Routes to other Open Collective services ----
3838

3939
export const collectiveInvoiceURL = (collectiveSlug, hostSlug, startDate, endDate, format) => {
40-
return `${invoiceServiceURL}/receipts/collectives/${collectiveSlug}/${hostSlug}/${startDate}/${endDate}/receipt.${format}`;
40+
return `${PDF_SERVICE_URL}/receipts/collectives/${collectiveSlug}/${hostSlug}/${startDate}/${endDate}/receipt.${format}`;
4141
};
4242

4343
export const transactionInvoiceURL = transactionUUID => {
44-
return `${invoiceServiceURL}/receipts/transactions/${transactionUUID}/receipt.pdf`;
44+
return `${PDF_SERVICE_URL}/receipts/transactions/${transactionUUID}/receipt.pdf`;
4545
};
4646

4747
export const expenseInvoiceUrl = expenseId => {
48-
return `${invoiceServiceURL}/expense/${expenseId}/invoice.pdf`;
48+
return `${PDF_SERVICE_URL}/expense/${expenseId}/invoice.pdf`;
4949
};
5050

5151
/**
@@ -54,7 +54,7 @@ export const expenseInvoiceUrl = expenseId => {
5454
* @param {string} filename - filename **with** extension
5555
*/
5656
export const giftCardsDownloadUrl = filename => {
57-
return `${invoiceServiceURL}/giftcards/from-data/${filename}`;
57+
return `${PDF_SERVICE_URL}/giftcards/from-data/${filename}`;
5858
};
5959

6060
// ---- Routes to external services ----

package-lock.json

Lines changed: 165 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/run_e2e_tests.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
mkdir -p logs
4+
35
echo "> Starting maildev server"
46
npx maildev@2.0.5 &
57
MAILDEV_PID=$!
@@ -35,7 +37,7 @@ if [ -z "$IMAGES_FOLDER" ]; then
3537
else
3638
cd $IMAGES_FOLDER
3739
fi
38-
npm start &
40+
npm start >../logs/images-service.txt 2>&1 &
3941
IMAGES_PID=$!
4042
cd -
4143

@@ -45,7 +47,7 @@ if [ -z "$PDF_FOLDER" ]; then
4547
else
4648
cd $PDF_FOLDER
4749
fi
48-
PORT=3002 npm start &
50+
PORT=3002 npm start >../logs/pdf-service.txt 2>&1 &
4951
PDF_PID=$!
5052
cd -
5153

0 commit comments

Comments
 (0)