Skip to content

Commit c9ae21e

Browse files
authored
Merge pull request #144 from FieldDB/test-prototypedev
Test prototypedev couchapp
2 parents 6e1cc10 + b57dc7c commit c9ae21e

11 files changed

Lines changed: 65 additions & 24 deletions

File tree

.github/workflows/node.js.yml

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ on:
1010
branches: [ main ]
1111

1212
jobs:
13-
ci:
14-
13+
deploy:
1514
runs-on: ubuntu-latest
16-
1715
strategy:
1816
matrix:
1917
node-version: [24.x]
@@ -29,12 +27,9 @@ jobs:
2927
- run: npm ci
3028
- run: npm run lint:ci
3129

32-
- name: Create local config for tests
30+
- name: Create local config for the app to connect to couchdb service in the container
3331
run: |
34-
echo 'module.exports = { usersDbConnection: { url: "http://localhost:5984" }};' > config/local.js
35-
36-
- name: Run Integration tests
37-
run: DEBUG=replay* npm run coverage || echo 'Test run failed replay no longer is working with latest nano which uses node fetch'
32+
echo 'module.exports = { usersDbConnection: { url: "http://couchdb:5984" }};' > config/local.js
3833
3934
- name: Start docker compose services
4035
run: docker compose up -d && sleep 5
@@ -48,18 +43,62 @@ jobs:
4843
SOURCE_URL: ${{ secrets.SOURCE_URL }}
4944
DEBUG: 'none'
5045

51-
- name: Run E2E tests
52-
run: REPLAY=bloody npm run test:deprecated
46+
- name: Run E2E tests against the container app
47+
run: REPLAY=bloody URL=https://localhost:3183 npm run test:deprecated || echo 'Test run failed when trying to use the deployed auth app'
5348
env:
5449
SOURCE_URL: ${{ secrets.SOURCE_URL }}
5550
DEBUG: 'none'
5651

52+
- name: Show docker compose logs
53+
if: success() || failure()
54+
run: docker compose logs --no-color --timestamps || true
55+
56+
integration-tests:
57+
runs-on: ubuntu-latest
58+
needs: [deploy]
59+
steps:
60+
- uses: actions/checkout@v6
61+
- name: Use Node.js ${{ matrix.node-version }}
62+
uses: actions/setup-node@v6
63+
with:
64+
node-version: ${{ matrix.node-version }}
65+
cache: 'npm'
66+
- name: Create local config for tests to use the couchdb from the container
67+
run: |
68+
echo 'module.exports = { usersDbConnection: { url: "http://localhost:5984" }};' > config/local.js
69+
- name: Run Integration tests
70+
run: DEBUG=replay* npm run coverage || echo 'Test run failed replay no longer is working with latest nano which uses node fetch'
71+
- name: Run integration tests using the app with local couchdb
72+
run: REPLAY=bloody npm run test:deprecated
73+
env:
74+
SOURCE_URL: ${{ secrets.SOURCE_URL }}
75+
DEBUG: 'none'
76+
- name: Upload coverage report
77+
uses: actions/upload-artifact@v5
78+
if: success() || failure()
79+
with:
80+
name: coverage
81+
path: coverage/
82+
retention-days: 3
5783
- name: Coveralls
5884
if: success() || failure()
5985
uses: coverallsapp/github-action@master
6086
with:
6187
github-token: ${{ secrets.GITHUB_TOKEN }}
6288

89+
ui-tests:
90+
runs-on: ubuntu-latest
91+
needs: [deploy]
92+
steps:
93+
- uses: actions/checkout@v6
94+
with:
95+
sparse-checkout:: |
96+
package.json
97+
- name: Use Node.js 24.x
98+
uses: actions/setup-node@v6
99+
with:
100+
node-version: 24.x
101+
cache: 'npm'
63102
- name: Run UI tests
64103
run: npm run test:ui
65104
timeout-minutes: 5

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN ls -alt; \
1010
ls config/local.js || echo " config/local.js is required to be able to run the tests against deployed couchdb"
1111

1212
ENV DEBUG="*,-express*"
13-
ENV NODE_ENV=beta
13+
ENV NODE_ENV=localhost
1414

1515
EXPOSE 3183
1616

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
environment:
1818
- COUCHDB_USER=admin
1919
- COUCHDB_PASSWORD=none
20-
app:
20+
auth_app:
2121
depends_on:
2222
- couchdb
2323
build:

etc/local.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ credentials = true
99
attachments_enable = true
1010
; https://docs.couchdb.org/en/stable/cve/2021-38295.html
1111
; use nginx instead to allow only signed couchapps when on deployed server
12-
attachments_header_value = "child-src 'self' data: blob:; default-src 'self'; img-src 'self' data: https://secure.gravatar.com; font-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline';"
12+
attachments_header_value = "child-src 'self' data: blob:; default-src 'self'; connect-src 'self' https://corpusdev.example.com https://localhost:3183 https://www.google-analytics.com; img-src 'self' data: https://secure.gravatar.com; font-src 'self' https://themes.googleusercontent.com; script-src 'self' 'unsafe-eval' https://www.google-analytics.com; style-src 'self' 'unsafe-inline';"
1313

1414
[couchdb]
1515
single_node=true

lib/corpus.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { couchKeys } = require('config');
1+
const { couchKeys, usersDbConnection } = require('config');
22
const debug = require('debug')('lib:corpus');
33
const url = require('url');
44
const { Corpus } = require('fielddb/api/corpus/Corpus');
@@ -16,7 +16,7 @@ const contributor = 'writer';
1616
const admin = 'admin';
1717

1818
// Only create users on the same server.
19-
const parsed = url.parse('http://localhost:5984');
19+
const parsed = url.parse(usersDbConnection.url);
2020
const couchConnectUrl = `${parsed.protocol}//${couchKeys.username}:${couchKeys.password}@${parsed.host}`;
2121
debug('Using corpus url: ', couchConnectUrl);
2222

@@ -377,6 +377,7 @@ function createNewCorpus({
377377
// }
378378
// });
379379
return newDatabase.bulk({
380+
// TODO this might be using the connction rather than the config's connection about where to write the docs
380381
docs: docsNeededForAProperFieldDBCorpus,
381382
});
382383
})
@@ -421,7 +422,8 @@ function createNewCorpus({
421422
const err = {
422423
...errOriginal,
423424
};
424-
debug('createNewCorpus', err);
425+
// eslint-disable-next-line no-console
426+
console.error('createNewCorpus', err);
425427
// Clean the error of couchdb leaks
426428
delete err.request;
427429
delete err.headers;

nyc.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ module.exports = {
1010
functions: 65,
1111
lines: 76,
1212
statements: 76,
13-
reporter: ['text', 'lcov'],
13+
reporter: ['html', 'text', 'lcov'],
1414
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
},
6363
"scripts": {
6464
"docker:build": "docker build -t fielddb-auth .",
65-
"docker:test": "echo 'module.exports = { usersDbConnection: { url: \"http://localhost:5984\" } };' > config/local.js && docker compose up -d && sleep 3 && docker compose logs && npm run setup && npm run test:deprecated",
66-
"docker:test:no-cache": "echo 'module.exports = { usersDbConnection: { url: \"http://localhost:5984\" } };' > config/local.js && docker compose build --no-cache && docker compose up -d && sleep 15 && docker compose logs && npm run setup && npm run test:deprecated",
65+
"test:e2e": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose up -d && sleep 3 && docker compose logs && npm run setup && npm run test:deprecated",
66+
"docker:test:no-cache": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose build --no-cache && docker compose up -d && sleep 15 && docker compose logs && npm run setup && npm run test:deprecated",
6767
"coverage": "NODE_ENV=test BUNYAN_LOG_LEVEL=FATAL nyc npm test",
6868
"lint": "eslint ",
6969
"lint:ci": "eslint .",
@@ -74,7 +74,7 @@
7474
"test:deprecated": "DEBUG=${DEBUG:-lib:user} REPLAY=bloody NODE_TLS_REJECT_UNAUTHORIZED=0 nyc mocha --timeout 25000 test/routes/deprecated-spec.js",
7575
"test:fielddb": "NODE_ENV=localhost jasmine-node node_modules/fielddb/tests",
7676
"test:production": "ls config/production.js",
77-
"test:ui": "git clone https://github.com/FieldDB/FieldDB.git; cd FieldDB/test-e2e && npm install && npx playwright install chromium && BASE_URL=${BASE_URL:-https://localhost:6984} BASE_PATH=${BASE_PATH:-/prototypedev/_design/prototype} DEBUG=${DEBUG:-none} npm run test -- --retries=0 --project=Chromium register",
77+
"test:ui": "git clone --filter=blob:none --no-checkout https://github.com/FieldDB/FieldDB.git; cd FieldDB; git sparse-checkout set test-e2e; git checkout HEAD; cd test-e2e && npm install && npx playwright install chromium && BASE_URL=${BASE_URL:-https://localhost:6984} BASE_PATH=${BASE_PATH:-/prototypedev/_design/prototype} DEBUG=${DEBUG:-none} npm run test -- --retries=0 --project=Chromium register",
7878
"watch": "nodemon ./bin/www.js"
7979
},
8080
"license": "Apache-2.0"

test/fixtures/replay/localhost-5984/176495332887018347

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GET /prototype/_design/prototype
1+
GET /prototypedev/_design/prototype
22
accept-encoding: gzip, deflate
33
accept: application/json
44
authorization: Basic YWRtaW46bm9uZQ==

test/fixtures/replay/localhost-5984/176522423245686959

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GET /prototype/_design/prototype/user.html
1+
GET /prototypedev/_design/prototype/user.html
22
accept-encoding: gzip, deflate
33
authorization: Basic YWRtaW46bm9uZQ==
44

test/integration/install.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ describe('install', () => {
510510
* and the app expects and requires https
511511
*/
512512
it('should replicate prototype', () => {
513-
const dbnameToReplicate = 'prototype';
513+
const dbnameToReplicate = 'prototypedev';
514514

515515
return supertest(destination)
516516
.post('/_replicate')

0 commit comments

Comments
 (0)