diff --git a/.github/workflows/tests-ci.yml b/.github/workflows/tests-ci.yml index 031ef851b..2b68ff1f2 100644 --- a/.github/workflows/tests-ci.yml +++ b/.github/workflows/tests-ci.yml @@ -49,9 +49,17 @@ jobs: - name: Run linter for all packages run: npm run lint --ws + + - name: start services tests need + run: cd testfiles && docker-compose up -d + + - name: wait for services to be ready + run: until curl -sf http://localhost:3000/health; do echo -n .; sleep .1; done - name: Run tests for all packages run: npm run test:node --ws + env: + DWN_URL: http://localhost:3000 - name: Upload test coverage to Codecov uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 @@ -83,5 +91,16 @@ jobs: - name: Build all workspace packages run: npm run build + - name: install docker + run: brew install docker && brew install docker-compose && colima start + + - name: start local dwn server + run: cd testfiles && docker-compose up -d + + - name: wait for services to be ready + run: until curl -sf http://localhost:3000/health; do echo -n .; sleep .1; done + - name: Run tests for all packages run: npm run test:browser --ws + env: + DWN_URL: http://localhost:3000 diff --git a/packages/common/karma.conf.cjs b/packages/common/karma.conf.cjs index aa89cbca8..908344871 100644 --- a/packages/common/karma.conf.cjs +++ b/packages/common/karma.conf.cjs @@ -34,7 +34,8 @@ module.exports = function (config) { client: { mocha: { timeout: 10000 // 10 seconds - } + }, + dwn_url: process.env.DWN_URL, }, diff --git a/packages/credentials/karma.conf.cjs b/packages/credentials/karma.conf.cjs index aa89cbca8..908344871 100644 --- a/packages/credentials/karma.conf.cjs +++ b/packages/credentials/karma.conf.cjs @@ -34,7 +34,8 @@ module.exports = function (config) { client: { mocha: { timeout: 10000 // 10 seconds - } + }, + dwn_url: process.env.DWN_URL, }, diff --git a/packages/crypto/karma.conf.cjs b/packages/crypto/karma.conf.cjs index 083f0c963..af5313117 100644 --- a/packages/crypto/karma.conf.cjs +++ b/packages/crypto/karma.conf.cjs @@ -34,7 +34,8 @@ module.exports = function (config) { client: { mocha: { timeout: 10000 // 10 seconds - } + }, + dwn_url: process.env.DWN_URL, }, // list of files / patterns to load in the browser diff --git a/packages/dids/karma.conf.cjs b/packages/dids/karma.conf.cjs index 083f0c963..af5313117 100644 --- a/packages/dids/karma.conf.cjs +++ b/packages/dids/karma.conf.cjs @@ -34,7 +34,8 @@ module.exports = function (config) { client: { mocha: { timeout: 10000 // 10 seconds - } + }, + dwn_url: process.env.DWN_URL, }, // list of files / patterns to load in the browser diff --git a/packages/web5-user-agent/karma.conf.cjs b/packages/web5-user-agent/karma.conf.cjs index ba578d742..932d5c7f4 100644 --- a/packages/web5-user-agent/karma.conf.cjs +++ b/packages/web5-user-agent/karma.conf.cjs @@ -34,7 +34,8 @@ module.exports = function (config) { client: { mocha: { timeout: 10000 // 10 seconds - } + }, + dwn_url: process.env.DWN_URL, }, // list of files / patterns to load in the browser diff --git a/packages/web5-user-agent/tests/common/web5-user-agent.spec.ts b/packages/web5-user-agent/tests/common/web5-user-agent.spec.ts index e3916610e..07d57a555 100644 --- a/packages/web5-user-agent/tests/common/web5-user-agent.spec.ts +++ b/packages/web5-user-agent/tests/common/web5-user-agent.spec.ts @@ -1,6 +1,7 @@ import { expect } from 'chai'; import { Encoder, RecordsWriteMessage, RecordsRead } from '@tbd54566975/dwn-sdk-js'; import { TestAgent } from './utils/test-user-agent.js'; +import { dwnNodes } from '../dwn-nodes.js'; // NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage // Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule @@ -11,8 +12,6 @@ import { webcrypto } from 'node:crypto'; if (!globalThis.crypto) globalThis.crypto = webcrypto; let did: string; -let dwnNodes: string[] = ['https://dwn.tbddev.org/dwn0']; -// let dwnNodes: string[] = ['http://localhost:3000']; let testAgent: TestAgent; describe('Web5UserAgent', () => { diff --git a/packages/web5-user-agent/tests/dwn-nodes.ts b/packages/web5-user-agent/tests/dwn-nodes.ts new file mode 100644 index 000000000..8dab9b64a --- /dev/null +++ b/packages/web5-user-agent/tests/dwn-nodes.ts @@ -0,0 +1,8 @@ +function getDWNnodes() { + // @ts-ignore + if(typeof __karma__ == 'object' && __karma__.config && __karma__.config.dwn_url) { return [__karma__.config.dwn_url]; } + if(process && process.env && process.env.DWN_URL) { return [process.env.DWN_URL]; } + return ['https://dwn.tbddev.org/dwn0']; +} + +export const dwnNodes = getDWNnodes(); \ No newline at end of file diff --git a/packages/web5-user-agent/tests/fixtures/test-profiles.ts b/packages/web5-user-agent/tests/fixtures/test-profiles.ts index b407a00fe..eadb1499c 100644 --- a/packages/web5-user-agent/tests/fixtures/test-profiles.ts +++ b/packages/web5-user-agent/tests/fixtures/test-profiles.ts @@ -3,8 +3,7 @@ import type { TestProfileOptions } from '../common/utils/test-user-agent.js'; import { generateKeyPair } from '@decentralized-identity/ion-tools'; -export const dwnNodes = ['https://dwn.tbddev.org/dwn0']; -// const dwnNodes = ['http://localhost:3000']; +import { dwnNodes } from '../../../web5/tests/dwn-nodes.js'; export const keyIds = { did: { diff --git a/packages/web5/karma.conf.cjs b/packages/web5/karma.conf.cjs index e114c588c..afde937c3 100644 --- a/packages/web5/karma.conf.cjs +++ b/packages/web5/karma.conf.cjs @@ -34,7 +34,8 @@ module.exports = function (config) { client: { mocha: { timeout: 10000 // 10 seconds - } + }, + dwn_url: process.env.DWN_URL, }, // list of files / patterns to load in the browser diff --git a/packages/web5/tests/dwn-nodes.ts b/packages/web5/tests/dwn-nodes.ts new file mode 100644 index 000000000..8dab9b64a --- /dev/null +++ b/packages/web5/tests/dwn-nodes.ts @@ -0,0 +1,8 @@ +function getDWNnodes() { + // @ts-ignore + if(typeof __karma__ == 'object' && __karma__.config && __karma__.config.dwn_url) { return [__karma__.config.dwn_url]; } + if(process && process.env && process.env.DWN_URL) { return [process.env.DWN_URL]; } + return ['https://dwn.tbddev.org/dwn0']; +} + +export const dwnNodes = getDWNnodes(); \ No newline at end of file diff --git a/packages/web5/tests/fixtures/test-profiles.ts b/packages/web5/tests/fixtures/test-profiles.ts index f9520fe00..73c43dab3 100644 --- a/packages/web5/tests/fixtures/test-profiles.ts +++ b/packages/web5/tests/fixtures/test-profiles.ts @@ -3,8 +3,7 @@ import type { TestProfileOptions } from '../test-utils/test-user-agent.js'; import { generateKeyPair } from '@decentralized-identity/ion-tools'; -const dwnNodes = ['https://dwn.tbddev.org/dwn0']; -// const dwnNodes = ['http://localhost:3000']; +import { dwnNodes } from '../dwn-nodes.js'; export const keyIds = { did: { diff --git a/packages/web5/tests/tech-preview.spec.ts b/packages/web5/tests/tech-preview.spec.ts index ef9ef9ad8..93146f970 100644 --- a/packages/web5/tests/tech-preview.spec.ts +++ b/packages/web5/tests/tech-preview.spec.ts @@ -92,15 +92,17 @@ describe('Tech Preview', () => { }); }); - it('returns 2 DWN endpoints if at least 2 are healthy', async function() { - const promises = Array(50).fill(0).map(() => Web5.getTechPreviewDwnEndpoints()); + if(!process.env.DWN_URL) { + it('returns 2 DWN endpoints if at least 2 are healthy', async function() { + const promises = Array(50).fill(0).map(() => Web5.getTechPreviewDwnEndpoints()); - const results = await Promise.all(promises); + const results = await Promise.all(promises); - results.forEach(result => { - expect(result).to.be.an('array').that.has.lengthOf(2); + results.forEach(result => { + expect(result).to.be.an('array').that.has.lengthOf(2); + }); }); - }); + } it('returns 1 DWN endpoints if only 1 is healthy', async function() { mockDwnEndpoints = [ diff --git a/testfiles/docker-compose.yaml b/testfiles/docker-compose.yaml new file mode 100644 index 000000000..a19a1b015 --- /dev/null +++ b/testfiles/docker-compose.yaml @@ -0,0 +1,8 @@ +version: "3.98" + +services: + dwn-node: + container_name: dwn-node + image: ghcr.io/tbd54566975/dwn-server:dwn-sdk-0.0.35 + ports: + - "3000:3000"