Skip to content

Commit

Permalink
test against a local copy of the dwn server
Browse files Browse the repository at this point in the history
* tests check for environment variable DWN_URL and use that as the dwn server if specified
* dwn-server launched in docker container during tests, DWN_URL is set
  • Loading branch information
finn-block committed Aug 4, 2023
1 parent 72facd4 commit 4675325
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 27 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/tests-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion packages/common/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module.exports = function (config) {
client: {
mocha: {
timeout: 10000 // 10 seconds
}
},
dwn_url: process.env.DWN_URL,
},


Expand Down
3 changes: 2 additions & 1 deletion packages/credentials/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module.exports = function (config) {
client: {
mocha: {
timeout: 10000 // 10 seconds
}
},
dwn_url: process.env.DWN_URL,
},


Expand Down
3 changes: 2 additions & 1 deletion packages/crypto/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/dids/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/web5-user-agent/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/web5-user-agent/tests/dwn-nodes.ts
Original file line number Diff line number Diff line change
@@ -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();
3 changes: 1 addition & 2 deletions packages/web5-user-agent/tests/fixtures/test-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion packages/web5/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions packages/web5/tests/dwn-nodes.ts
Original file line number Diff line number Diff line change
@@ -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();
3 changes: 1 addition & 2 deletions packages/web5/tests/fixtures/test-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
36 changes: 21 additions & 15 deletions packages/web5/tests/tech-preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ describe('Tech Preview', () => {
};

beforeEach(() => {
mockDwnEndpoints = [
'https://dwn.tbddev.test/dwn0',
'https://dwn.tbddev.test/dwn1',
'https://dwn.tbddev.test/dwn2',
'https://dwn.tbddev.test/dwn3',
'https://dwn.tbddev.test/dwn4',
'https://dwn.tbddev.test/dwn5',
'https://dwn.tbddev.test/dwn6'
];
if(process.env.DWN_URL) {
mockDwnEndpoints = [process.env.DWN_URL];
} else {
mockDwnEndpoints = [
'https://dwn.tbddev.test/dwn0',
'https://dwn.tbddev.test/dwn1',
'https://dwn.tbddev.test/dwn2',
'https://dwn.tbddev.test/dwn3',
'https://dwn.tbddev.test/dwn4',
'https://dwn.tbddev.test/dwn5',
'https://dwn.tbddev.test/dwn6'
];
}

fetchStub = sinon.stub(globalThis as any, 'fetch');

Expand Down Expand Up @@ -92,15 +96,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 = [
Expand Down
8 changes: 8 additions & 0 deletions testfiles/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 4675325

Please sign in to comment.