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-tbd committed Aug 21, 2023
1 parent 7392aa3 commit dafc064
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 14 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/tests-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ 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
run: npm run test:node --ws -- --color
env:
TEST_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
run: npm run test:browser --ws -- --color
env:
TEST_DWN_URL: http://localhost:3000
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/old/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/old/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
8 changes: 8 additions & 0 deletions packages/old/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/old/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
14 changes: 8 additions & 6 deletions packages/old/web5/tests/tech-preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,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.TEST_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 dafc064

Please sign in to comment.