Skip to content

Commit

Permalink
Cherry pick test DWN URL from envvar commits from @finn-tbd PR #161
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Hinek <[email protected]>
  • Loading branch information
frankhinek committed Aug 21, 2023
1 parent a9610d7 commit fef91b2
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 33 deletions.
7 changes: 4 additions & 3 deletions packages/agent/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ module.exports = function (config) {
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
frameworks: ['mocha'],

// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
client: {
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
mocha: {
timeout: 10000 // 10 seconds
}
},
// If an environment variable is defined, override the default test DWN URL.
testDwnUrl: process.env.TEST_DWN_URL,
},


// list of files / patterns to load in the browser
files: [
{ pattern: 'tests/**/*.spec.ts', watched: false },
Expand Down
6 changes: 3 additions & 3 deletions packages/agent/tests/dwn-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
RecordsDeleteMessage,
} from '@tbd54566975/dwn-sdk-js';

import { testDwnUrl } from './test-config.js';
import { TestAgent } from './utils/test-agent.js';
import { DwnManager } from '../src/dwn-manager.js';
import { ManagedIdentity } from '../src/identity-manager.js';
Expand All @@ -26,8 +27,7 @@ if (!globalThis.crypto) globalThis.crypto = webcrypto;

chai.use(chaiAsPromised);

// let dwnNodes: string[] = ['https://dwn.tbddev.org/dwn0'];
let dwnNodes: string[] = ['http://localhost:3000'];
let testDwnUrls: string[] = [testDwnUrl];

describe('DwnManager', () => {

Expand Down Expand Up @@ -279,7 +279,7 @@ describe('DwnManager', () => {
type : 'DecentralizedWebNode',
serviceEndpoint : {
encryptionKeys : ['#dwn-enc'],
nodes : dwnNodes,
nodes : testDwnUrls,
signingKeys : ['#dwn-sig']
}
}];
Expand Down
24 changes: 24 additions & 0 deletions packages/agent/tests/test-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
declare const __karma__: { config?: { testDwnUrl?: string; } };

const DEFAULT_TEST_DWN_URL = 'https://dwn.tbddev.org/dwn0';

function getTestDwnUrl(): string {
// Check to see if we're running in a Karma browser test environment.
const browserTestEnvironment = typeof __karma__ !== 'undefined' && __karma__?.config?.testDwnUrl !== undefined;

// Check to see if we're running in a Node environment.
const nodeTestEnvironment = process && process?.env !== undefined;

// Attempt to use DWN URL defined in Karma config, if running a browser test.
// Otherwise, attempt to use the Node environment variable.
const envTestDwnUrl = (browserTestEnvironment)
? __karma__.config!.testDwnUrl
: (nodeTestEnvironment)
? process.env.TEST_DWN_URL
: undefined;

// If defined, return the test environment DWN URL. Otherwise, return the default.
return envTestDwnUrl || DEFAULT_TEST_DWN_URL;
}

export const testDwnUrl = getTestDwnUrl();
10 changes: 5 additions & 5 deletions packages/api/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ module.exports = function (config) {
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
frameworks: ['mocha'],

// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
client: {
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
mocha: {
timeout: 10000 // 10 seconds
}
},
// If an environment variable is defined, override the default test DWN URL.
testDwnUrl: process.env.TEST_DWN_URL,
},

// list of files / patterns to load in the browser
files: [
// { pattern: 'tests/test-user-agent.ts', watched: false },
{ pattern: 'tests/**/*.spec.ts', watched: false },
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor
preprocessors: {
// 'tests/test-user-agent.ts' : ['esbuild'],
'tests/**/*.spec.ts': ['esbuild'],
},

Expand All @@ -68,7 +68,7 @@ module.exports = function (config) {
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN ||
// config.LOG_INFO || config.LOG_DEBUG
logLevel: config.INFO,
logLevel: config.LOG_INFO,

concurrency: 1,

Expand Down
3 changes: 3 additions & 0 deletions packages/api/tests/record.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ManagedIdentity, TestManagedAgent } from '@web5/agent';
import { Record } from '../src/record.js';
import { DwnApi } from '../src/dwn-api.js';
import { dataToBlob } from '../src/utils.js';
import { testDwnUrl } from './test-config.js';
import { TestUserAgent } from './utils/test-user-agent.js';
import { TestDataGenerator } from './utils/test-data-generator.js';

Expand All @@ -28,6 +29,8 @@ if (!globalThis.crypto) globalThis.crypto = webcrypto;
// TODO: Come up with a better way of resolving the TS errors.
type RecordsWriteTest = RecordsWrite & RecordsWriteMessage;

let testDwnUrls: string[] = [testDwnUrl];

describe('Record', () => {
let dataText: string;
let dataBlob: Blob;
Expand Down
24 changes: 24 additions & 0 deletions packages/api/tests/test-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
declare const __karma__: { config?: { testDwnUrl?: string; } };

const DEFAULT_TEST_DWN_URL = 'https://dwn.tbddev.org/dwn0';

function getTestDwnUrl(): string {
// Check to see if we're running in a Karma browser test environment.
const browserTestEnvironment = typeof __karma__ !== 'undefined' && __karma__?.config?.testDwnUrl !== undefined;

// Check to see if we're running in a Node environment.
const nodeTestEnvironment = process && process?.env !== undefined;

// Attempt to use DWN URL defined in Karma config, if running a browser test.
// Otherwise, attempt to use the Node environment variable.
const envTestDwnUrl = (browserTestEnvironment)
? __karma__.config!.testDwnUrl
: (nodeTestEnvironment)
? process.env.TEST_DWN_URL
: undefined;

// If defined, return the test environment DWN URL. Otherwise, return the default.
return envTestDwnUrl || DEFAULT_TEST_DWN_URL;
}

export const testDwnUrl = getTestDwnUrl();
6 changes: 3 additions & 3 deletions packages/api/tests/web5-dwn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { expect } from 'chai';
import { TestManagedAgent } from '@web5/agent';

import { DwnApi } from '../src/dwn-api.js';
import { testDwnUrl } from './test-config.js';
import { TestUserAgent } from './utils/test-user-agent.js';
import emailProtocolDefinition from './fixtures/protocol-definitions/email.json' assert { type: 'json' };

// let dwnNodes: string[] = ['https://dwn.tbddev.org/dwn0'];
let dwnNodes: string[] = ['http://localhost:3000'];
let testDwnUrls: string[] = [testDwnUrl];

describe('web5.dwn', () => {
let dwn: DwnApi;
Expand All @@ -30,7 +30,7 @@ describe('web5.dwn', () => {
type : 'DecentralizedWebNode',
serviceEndpoint : {
encryptionKeys : ['#dwn-enc'],
nodes : dwnNodes,
nodes : testDwnUrls,
signingKeys : ['#dwn-sig']
}
}];
Expand Down
7 changes: 4 additions & 3 deletions packages/common/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ module.exports = function (config) {
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
frameworks: ['mocha'],

// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
client: {
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
mocha: {
timeout: 10000 // 10 seconds
}
},
// If an environment variable is defined, override the default test DWN URL.
testDwnUrl: process.env.TEST_DWN_URL,
},


// list of files / patterns to load in the browser
files: [
{ pattern: 'tests/**/*.spec.ts', watched: false },
Expand Down
7 changes: 4 additions & 3 deletions packages/credentials/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ module.exports = function (config) {
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
frameworks: ['mocha'],

// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
client: {
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
mocha: {
timeout: 10000 // 10 seconds
}
},
// If an environment variable is defined, override the default test DWN URL.
testDwnUrl: process.env.TEST_DWN_URL,
},


// list of files / patterns to load in the browser
files: [
{ pattern: 'tests/**/*.spec.ts', watched: false },
Expand Down
6 changes: 4 additions & 2 deletions packages/crypto/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ module.exports = function (config) {
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
frameworks: ['mocha'],

// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
client: {
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
mocha: {
timeout: 10000 // 10 seconds
}
},
// If an environment variable is defined, override the default test DWN URL.
testDwnUrl: process.env.TEST_DWN_URL,
},

// list of files / patterns to load in the browser
Expand Down
6 changes: 4 additions & 2 deletions packages/dids/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ module.exports = function (config) {
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
frameworks: ['mocha'],

// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
client: {
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
mocha: {
timeout: 10000 // 10 seconds
}
},
// If an environment variable is defined, override the default test DWN URL.
testDwnUrl: process.env.TEST_DWN_URL,
},

// list of files / patterns to load in the browser
Expand Down
7 changes: 4 additions & 3 deletions packages/identity-agent/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ module.exports = function (config) {
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
frameworks: ['mocha'],

// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
client: {
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
mocha: {
timeout: 10000 // 10 seconds
}
},
// If an environment variable is defined, override the default test DWN URL.
testDwnUrl: process.env.TEST_DWN_URL,
},


// list of files / patterns to load in the browser
files: [
{ pattern: 'tests/**/*.spec.ts', watched: false },
Expand Down
7 changes: 4 additions & 3 deletions packages/proxy-agent/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ module.exports = function (config) {
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
frameworks: ['mocha'],

// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
client: {
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
mocha: {
timeout: 10000 // 10 seconds
}
},
// If an environment variable is defined, override the default test DWN URL.
testDwnUrl: process.env.TEST_DWN_URL,
},


// list of files / patterns to load in the browser
files: [
{ pattern: 'tests/**/*.spec.ts', watched: false },
Expand Down
7 changes: 4 additions & 3 deletions packages/user-agent/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ module.exports = function (config) {
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
frameworks: ['mocha'],

// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
client: {
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs.
mocha: {
timeout: 10000 // 10 seconds
}
},
// If an environment variable is defined, override the default test DWN URL.
testDwnUrl: process.env.TEST_DWN_URL,
},


// list of files / patterns to load in the browser
files: [
{ pattern: 'tests/**/*.spec.ts', watched: false },
Expand Down

0 comments on commit fef91b2

Please sign in to comment.