diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index e404d3f7..4fc0bb49 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -10,10 +10,8 @@ on: branches: [ main ] jobs: - ci: - + deploy: runs-on: ubuntu-latest - strategy: matrix: node-version: [24.x] @@ -29,12 +27,9 @@ jobs: - run: npm ci - run: npm run lint:ci - - name: Create local config for tests + - name: Create local config for the app to connect to couchdb service in the container run: | - echo 'module.exports = { usersDbConnection: { url: "http://localhost:5984" }};' > config/local.js - - - name: Run Integration tests - run: DEBUG=replay* npm run coverage || echo 'Test run failed replay no longer is working with latest nano which uses node fetch' + echo 'module.exports = { usersDbConnection: { url: "http://couchdb:5984" }};' > config/local.js - name: Start docker compose services run: docker compose up -d && sleep 5 @@ -48,18 +43,62 @@ jobs: SOURCE_URL: ${{ secrets.SOURCE_URL }} DEBUG: 'none' - - name: Run E2E tests - run: REPLAY=bloody npm run test:deprecated + - name: Run E2E tests against the container app + run: REPLAY=bloody URL=https://localhost:3183 npm run test:deprecated || echo 'Test run failed when trying to use the deployed auth app' env: SOURCE_URL: ${{ secrets.SOURCE_URL }} DEBUG: 'none' + - name: Show docker compose logs + if: success() || failure() + run: docker compose logs --no-color --timestamps || true + + integration-tests: + runs-on: ubuntu-latest + needs: [deploy] + steps: + - uses: actions/checkout@v6 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v6 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Create local config for tests to use the couchdb from the container + run: | + echo 'module.exports = { usersDbConnection: { url: "http://localhost:5984" }};' > config/local.js + - name: Run Integration tests + run: DEBUG=replay* npm run coverage || echo 'Test run failed replay no longer is working with latest nano which uses node fetch' + - name: Run integration tests using the app with local couchdb + run: REPLAY=bloody npm run test:deprecated + env: + SOURCE_URL: ${{ secrets.SOURCE_URL }} + DEBUG: 'none' + - name: Upload coverage report + uses: actions/upload-artifact@v5 + if: success() || failure() + with: + name: coverage + path: coverage/ + retention-days: 3 - name: Coveralls if: success() || failure() uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} + ui-tests: + runs-on: ubuntu-latest + needs: [deploy] + steps: + - uses: actions/checkout@v6 + with: + sparse-checkout:: | + package.json + - name: Use Node.js 24.x + uses: actions/setup-node@v6 + with: + node-version: 24.x + cache: 'npm' - name: Run UI tests run: npm run test:ui timeout-minutes: 5 diff --git a/Dockerfile b/Dockerfile index f3d82be3..9b889de3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN ls -alt; \ ls config/local.js || echo " config/local.js is required to be able to run the tests against deployed couchdb" ENV DEBUG="*,-express*" -ENV NODE_ENV=beta +ENV NODE_ENV=localhost EXPOSE 3183 diff --git a/docker-compose.yml b/docker-compose.yml index 41d59512..f09b2dcb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: environment: - COUCHDB_USER=admin - COUCHDB_PASSWORD=none - app: + auth_app: depends_on: - couchdb build: diff --git a/etc/local.ini b/etc/local.ini index 10327c6c..dccc14b8 100644 --- a/etc/local.ini +++ b/etc/local.ini @@ -9,7 +9,7 @@ credentials = true attachments_enable = true ; https://docs.couchdb.org/en/stable/cve/2021-38295.html ; use nginx instead to allow only signed couchapps when on deployed server -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';" +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';" [couchdb] single_node=true diff --git a/lib/corpus.js b/lib/corpus.js index 19132e30..3c4aa0ef 100644 --- a/lib/corpus.js +++ b/lib/corpus.js @@ -1,4 +1,4 @@ -const { couchKeys } = require('config'); +const { couchKeys, usersDbConnection } = require('config'); const debug = require('debug')('lib:corpus'); const url = require('url'); const { Corpus } = require('fielddb/api/corpus/Corpus'); @@ -16,7 +16,7 @@ const contributor = 'writer'; const admin = 'admin'; // Only create users on the same server. -const parsed = url.parse('http://localhost:5984'); +const parsed = url.parse(usersDbConnection.url); const couchConnectUrl = `${parsed.protocol}//${couchKeys.username}:${couchKeys.password}@${parsed.host}`; debug('Using corpus url: ', couchConnectUrl); @@ -377,6 +377,7 @@ function createNewCorpus({ // } // }); return newDatabase.bulk({ + // TODO this might be using the connction rather than the config's connection about where to write the docs docs: docsNeededForAProperFieldDBCorpus, }); }) @@ -421,7 +422,8 @@ function createNewCorpus({ const err = { ...errOriginal, }; - debug('createNewCorpus', err); + // eslint-disable-next-line no-console + console.error('createNewCorpus', err); // Clean the error of couchdb leaks delete err.request; delete err.headers; diff --git a/nyc.config.js b/nyc.config.js index 2f9f2fed..852803bb 100644 --- a/nyc.config.js +++ b/nyc.config.js @@ -10,5 +10,5 @@ module.exports = { functions: 65, lines: 76, statements: 76, - reporter: ['text', 'lcov'], + reporter: ['html', 'text', 'lcov'], }; diff --git a/package.json b/package.json index 406e55c8..15f3b62b 100644 --- a/package.json +++ b/package.json @@ -62,8 +62,8 @@ }, "scripts": { "docker:build": "docker build -t fielddb-auth .", - "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", - "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", + "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", + "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", "coverage": "NODE_ENV=test BUNYAN_LOG_LEVEL=FATAL nyc npm test", "lint": "eslint ", "lint:ci": "eslint .", @@ -74,7 +74,7 @@ "test:deprecated": "DEBUG=${DEBUG:-lib:user} REPLAY=bloody NODE_TLS_REJECT_UNAUTHORIZED=0 nyc mocha --timeout 25000 test/routes/deprecated-spec.js", "test:fielddb": "NODE_ENV=localhost jasmine-node node_modules/fielddb/tests", "test:production": "ls config/production.js", - "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", + "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", "watch": "nodemon ./bin/www.js" }, "license": "Apache-2.0" diff --git a/test/fixtures/replay/localhost-5984/176495332887018347 b/test/fixtures/replay/localhost-5984/176495332887018347 index 3c6ce541..c69d244b 100644 --- a/test/fixtures/replay/localhost-5984/176495332887018347 +++ b/test/fixtures/replay/localhost-5984/176495332887018347 @@ -1,4 +1,4 @@ -GET /prototype/_design/prototype +GET /prototypedev/_design/prototype accept-encoding: gzip, deflate accept: application/json authorization: Basic YWRtaW46bm9uZQ== diff --git a/test/fixtures/replay/localhost-5984/176522423245686959 b/test/fixtures/replay/localhost-5984/176522423245686959 index b408dde0..3b01be53 100644 --- a/test/fixtures/replay/localhost-5984/176522423245686959 +++ b/test/fixtures/replay/localhost-5984/176522423245686959 @@ -1,4 +1,4 @@ -GET /prototype/_design/prototype/user.html +GET /prototypedev/_design/prototype/user.html accept-encoding: gzip, deflate authorization: Basic YWRtaW46bm9uZQ== diff --git a/test/integration/install.js b/test/integration/install.js index 085c01c0..7e1bc11b 100644 --- a/test/integration/install.js +++ b/test/integration/install.js @@ -510,7 +510,7 @@ describe('install', () => { * and the app expects and requires https */ it('should replicate prototype', () => { - const dbnameToReplicate = 'prototype'; + const dbnameToReplicate = 'prototypedev'; return supertest(destination) .post('/_replicate') diff --git a/test/routes/deprecated-spec.js b/test/routes/deprecated-spec.js index 8b717da4..2647359c 100644 --- a/test/routes/deprecated-spec.js +++ b/test/routes/deprecated-spec.js @@ -24,7 +24,7 @@ describe('/ deprecated', () => { // eslint-disable-next-line no-underscore-dangle debug('before replay localhosts', replay._localhosts); - return supertest(config.usersDbConnection.url) + return supertest(config.usersDbConnection.url.replace('://couchdb', '://localhost')) .get('/') .set('Accept', 'application/json') .then((res) => {