Skip to content

Commit

Permalink
convert ava tests to mocha, remove ava dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaineHeffron committed May 28, 2024
1 parent 1b6d7aa commit c3541ab
Show file tree
Hide file tree
Showing 7 changed files with 473 additions and 910 deletions.
17 changes: 4 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"clean": "rm -rf lib/ dist/ coverage/ .nyc_output/ jsdoc/ test/e2e/.soroban",
"docs": "yarn build:docs && jsdoc -c ./config/.jsdoc.json --verbose",
"test": "yarn build:test && yarn test:node && yarn test:integration && yarn test:browser",
"test:e2e": "./test/e2e/initialize.sh && ava",
"test:e2e": "./test/e2e/initialize.sh && yarn _nyc mocha --recursive 'test/e2e/src/test-*.js'",
"test:node": "yarn _nyc mocha --recursive 'test/unit/**/*.js'",
"test:integration": "yarn _nyc mocha --recursive 'test/integration/**/*.js'",
"test:browser": "karma start config/karma.conf.js",
Expand All @@ -75,14 +75,15 @@
"reporter": "spec",
"require": [
"@babel/register",
"test/test-nodejs.js"
"test/test-nodejs.js",
"dotenv/config"
],
"exclude": [
"test/test-browser.js"
],
"sort": true,
"recursive": true,
"timeout": 30000
"timeout": 120000
},
"nyc": {
"instrument": false,
Expand Down Expand Up @@ -112,7 +113,6 @@
"@types/sinon": "^17.0.2",
"@types/urijs": "^1.19.20",
"@typescript-eslint/parser": "^7.7.1",
"ava": "^5.3.1",
"axios-mock-adapter": "^1.22.0",
"babel-loader": "^9.1.3",
"babel-plugin-istanbul": "^6.1.1",
Expand Down Expand Up @@ -169,14 +169,5 @@
"randombytes": "^2.1.0",
"toml": "^3.0.0",
"urijs": "^1.19.1"
},
"ava": {
"files": [
"./test/e2e/src/test-*"
],
"require": [
"dotenv/config"
],
"timeout": "2m"
}
}
71 changes: 35 additions & 36 deletions test/e2e/src/test-contract-client-constructor.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
const test = require("ava");
const assert = require("assert");
const { spawnSync } = require("node:child_process");
const {
contracts,
networkPassphrase,
rpcUrl,
friendbotUrl,
generateFundedKeypair,
} = require("./util");
const { Address, contract, Keypair } = require("../../..");

async function generateFundedKeypair() {
const keypair = Keypair.random();
await fetch(`${friendbotUrl}/friendbot?addr=${keypair.publicKey()}`);
return keypair;
}
const { Address, contract } = require("../../..");

/**
* Generates a Client for the contract with the given name.
Expand Down Expand Up @@ -56,6 +50,7 @@ async function clientFromConstructor(
}

// TODO: do this with js-stellar-sdk, instead of shelling out to the CLI

contractId =
contractId ??
spawnSync(
Expand Down Expand Up @@ -104,33 +99,37 @@ async function clientForFromTest(contractId, publicKey, keypair) {
return contract.Client.from(options);
}

test.before(async (t) => {
const { client, keypair, contractId } =
await clientFromConstructor("customTypes");
const publicKey = keypair.publicKey();
const addr = Address.fromString(publicKey);
t.context = { client, publicKey, addr, contractId, keypair }; // eslint-disable-line no-param-reassign
});
describe('Contract Tests', function() {
let context = {};

test("hello from constructor", async (t) => {
const { result } = await t.context.client.hello({ hello: "tests" });
t.is(result, "tests");
});
before(async function() {
const { client, keypair, contractId } =
await clientFromConstructor("customTypes");
const publicKey = keypair.publicKey();
const addr = Address.fromString(publicKey);
context = { client, publicKey, addr, contractId, keypair };
});

test("from", async (t) => {
// objects with different constructors will not pass deepEqual check
function constructorWorkaround(object) {
return JSON.parse(JSON.stringify(object));
}
it("hello from constructor", async function() {
const { result } = await context.client.hello({ hello: "tests" });
assert.strictEqual(result, "tests");
});

const clientFromFrom = await clientForFromTest(
t.context.contractId,
t.context.publicKey,
t.context.keypair,
);
t.deepEqual(
constructorWorkaround(clientFromFrom),
constructorWorkaround(t.context.client),
);
t.deepEqual(t.context.client.spec.entries, clientFromFrom.spec.entries);
});
it("from", async function() {
// objects with different constructors will not pass deepEqual check
function constructorWorkaround(object) {
return JSON.parse(JSON.stringify(object));
}

const clientFromFrom = await clientForFromTest(
context.contractId,
context.publicKey,
context.keypair,
);
assert.deepStrictEqual(
constructorWorkaround(clientFromFrom),
constructorWorkaround(context.client),
);
assert.deepStrictEqual(context.client.spec.entries, clientFromFrom.spec.entries);
});
});
Loading

0 comments on commit c3541ab

Please sign in to comment.