Skip to content

Commit

Permalink
Merge pull request #380 from ar-io/unit-tests
Browse files Browse the repository at this point in the history
chore(test): move unit tests next to implementations
  • Loading branch information
dtfiedler authored Feb 4, 2025
2 parents 0cef900 + 45f03b9 commit 9fbb563
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"test:cjs": "yarn build:cjs && yarn link && cd ./tests/e2e/cjs && yarn && yarn test",
"test:esm": "yarn build:esm && yarn link && cd ./tests/e2e/esm && yarn && yarn test",
"test:web": "yarn build:esm && yarn link && cd ./tests/e2e/web && yarn && yarn test",
"test:unit": "NODE_OPTIONS=\"--import=./register.mjs\" node --test tests/unit/**.test.ts",
"test:unit": "NODE_OPTIONS=\"--import=./register.mjs\" node --test src/**/**.test.ts",
"test:link": "yarn build && yarn link",
"test:e2e": "yarn test:cjs && yarn test:esm && yarn test:web",
"prepare": "husky install",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ant.test.ts → src/types/ant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AntInfoSchema,
AntStateSchema,
isAoANTState,
} from '../../src/types/ant.js';
} from './ant.js';

const stub_address = 'valid-address'.padEnd(43, '1');

Expand Down
1 change: 1 addition & 0 deletions src/types/ant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export interface AoANTWrite extends AoANTRead {
removeController: AoWriteAction<{ controller: WalletAddress }>;
/** @deprecated Use setUndernameRecord instead for undernames, and setBaseNameRecord instead for the top level name (e.g. "@") */
setRecord: AoWriteAction<AoANTSetUndernameRecordParams>;
/** @deprecated Use removeUndernameRecord instead for undernames */
removeRecord: AoWriteAction<{ undername: string }>;
setBaseNameRecord: AoWriteAction<AoANTSetBaseNameRecordParams>;
setUndernameRecord: AoWriteAction<AoANTSetUndernameRecordParams>;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/token.test.ts → src/types/token.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';

import { ARIOToken, mARIOToken } from '../../src/types/token.js';
import { ARIOToken, mARIOToken } from './token.js';

describe('ARIOToken', () => {
it('should throw an error on invalid input', () => {
Expand Down
10 changes: 7 additions & 3 deletions tests/unit/b64.test.ts → src/utils/b64.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';

import { fromB64Url, getRandomText, toB64Url } from '../../src/utils/base64.js';
import { fromB64Url, getRandomText, toB64Url } from './base64.js';

describe('b64utils', () => {
it('should convert various strings to base64url and back', () => {
Expand All @@ -16,8 +16,12 @@ describe('b64utils', () => {
];
for (const str of testStrings) {
const encoded = toB64Url(Buffer.from(str));
const decoded = Buffer.from(fromB64Url(encoded)).toString();
assert.strictEqual(decoded, str, `Failed for string: ${str}`);
const decoded = fromB64Url(encoded);
assert.deepStrictEqual(
decoded,
Buffer.from(str),
`Failed for string: ${str}`,
);
}
});
it('should convert various buffers to base64url and back', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/utils.test.ts → src/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';

import { pruneTags } from '../../src/utils/arweave.js';
import { errorMessageFromOutput } from '../../src/utils/index.js';
import { pruneTags } from './arweave.js';
import { errorMessageFromOutput } from './index.js';

describe('pruneTags', () => {
it('should remove tags with undefined values', () => {
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/esm/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@ describe('e2e esm tests', async () => {
assert(Array.isArray(balances.items));
balances.items.forEach((wallet) => {
assert(typeof wallet.address === 'string');
assert(typeof wallet.balance === 'number');
assert(
typeof wallet.balance === 'number',
`Balance for ${wallet.address} is not a number: ${wallet.balance}`,
);
});
});

Expand Down

0 comments on commit 9fbb563

Please sign in to comment.