Skip to content

Commit

Permalink
fix: switch test runner to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
kespinola committed May 6, 2024
1 parent ffc6a39 commit 4418cdf
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 92 deletions.
7 changes: 3 additions & 4 deletions packages/nodes-from-anchor/test/v01/AccountNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
structFieldTypeNode,
structTypeNode,
} from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { accountNodeFromAnchorV01, getAnchorDiscriminatorV01 } from '../../src/index.js';

test('it creates account nodes with anchor discriminators', t => {
test('it creates account nodes with anchor discriminators', () => {
const node = accountNodeFromAnchorV01(
{
discriminator: [246, 28, 6, 87, 251, 45, 50, 42],
Expand All @@ -33,8 +33,7 @@ test('it creates account nodes with anchor discriminators', t => {
],
);

t.deepEqual(
node,
expect(node).toEqual(
accountNode({
data: structTypeNode([
structFieldTypeNode({
Expand Down
7 changes: 3 additions & 4 deletions packages/nodes-from-anchor/test/v01/DefinedTypeNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { definedTypeNode, numberTypeNode, structFieldTypeNode, structTypeNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { definedTypeNodeFromAnchorV01 } from '../../src/index.js';

test('it creates defined type nodes', t => {
test('it creates defined type nodes', () => {
const node = definedTypeNodeFromAnchorV01({
name: 'MyType',
type: {
Expand All @@ -12,8 +12,7 @@ test('it creates defined type nodes', t => {
},
});

t.deepEqual(
node,
expect(node).toEqual(
definedTypeNode({
name: 'myType',
type: structTypeNode([
Expand Down
7 changes: 3 additions & 4 deletions packages/nodes-from-anchor/test/v01/ErrorNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { errorNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { errorNodeFromAnchorV01 } from '../../src/index.js';

test('it creates error nodes', t => {
test('it creates error nodes', () => {
const node = errorNodeFromAnchorV01({
code: 42,
msg: 'my error message',
name: 'myError',
});

t.deepEqual(
node,
expect(node).toEqual(
errorNode({
code: 42,
docs: ['myError: my error message'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { instructionAccountNode, publicKeyValueNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { instructionAccountNodeFromAnchorV01, instructionAccountNodesFromAnchorV01 } from '../../src/index.js';

test('it creates instruction account nodes', t => {
test('it creates instruction account nodes', () => {
const node = instructionAccountNodeFromAnchorV01({
docs: ['my docs'],
name: 'MyInstructionAccount',
Expand All @@ -12,8 +12,7 @@ test('it creates instruction account nodes', t => {
writable: true,
});

t.deepEqual(
node,
expect(node).toEqual(
instructionAccountNode({
docs: ['my docs'],
isOptional: true,
Expand All @@ -24,7 +23,7 @@ test('it creates instruction account nodes', t => {
);
});

test('it flattens nested instruction accounts', t => {
test('it flattens nested instruction accounts', () => {
const nodes = instructionAccountNodesFromAnchorV01([
{ name: 'accountA', signer: false, writable: false },
{
Expand All @@ -49,7 +48,7 @@ test('it flattens nested instruction accounts', t => {
{ name: 'account_d', signer: true, writable: true },
]);

t.deepEqual(nodes, [
expect(nodes).toEqual([
instructionAccountNode({ isSigner: false, isWritable: false, name: 'accountA' }),
instructionAccountNode({ isSigner: false, isWritable: true, name: 'accountB' }),
instructionAccountNode({ isSigner: true, isWritable: false, name: 'accountC' }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { instructionArgumentNode, numberTypeNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { instructionArgumentNodeFromAnchorV01 } from '../../src/index.js';

test('it creates instruction argument nodes', t => {
test('it creates instruction argument nodes', () => {
const node = instructionArgumentNodeFromAnchorV01({
name: 'my_instruction_argument',
type: 'u8',
});

t.deepEqual(
node,
expect(node).toEqual(
instructionArgumentNode({
name: 'myInstructionArgument',
type: numberTypeNode('u8'),
Expand Down
12 changes: 5 additions & 7 deletions packages/nodes-from-anchor/test/v01/InstructionNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ import {
instructionNode,
numberTypeNode,
} from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { instructionNodeFromAnchorV01 } from '../../src/index.js';
import { getAnchorDiscriminatorV01 } from '../../src/index.js';

test('it creates instruction nodes', t => {
test('it creates instruction nodes', () => {
const node = instructionNodeFromAnchorV01({
accounts: [{ name: 'Mint', signer: false, writable: true }],
args: [{ name: 'amount', type: 'u8' }],
discriminator: [246, 28, 6, 87, 251, 45, 50, 42],
name: 'mintTokens',
});

t.deepEqual(
node,
expect(node).toEqual(
instructionNode({
accounts: [instructionAccountNode({ isSigner: false, isWritable: true, name: 'mint' })],
arguments: [
Expand All @@ -38,16 +37,15 @@ test('it creates instruction nodes', t => {
);
});

test('it creates instruction nodes with anchor discriminators', t => {
test('it creates instruction nodes with anchor discriminators', () => {
const node = instructionNodeFromAnchorV01({
accounts: [],
args: [],
discriminator: [246, 28, 6, 87, 251, 45, 50, 42],
name: 'myInstruction',
});

t.deepEqual(
node,
expect(node).toEqual(
instructionNode({
arguments: [
instructionArgumentNode({
Expand Down
7 changes: 3 additions & 4 deletions packages/nodes-from-anchor/test/v01/PdaNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { bytesTypeNode, constantPdaSeedNode, pdaNode, publicKeyTypeNode, variablePdaSeedNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { getAnchorDiscriminatorV01, pdaNodeFromAnchorV01 } from '../../src/index.js';

test('it creates PDA nodes', t => {
test('it creates PDA nodes', () => {
const node = pdaNodeFromAnchorV01({
name: 'myPda',
pda: {
Expand All @@ -14,8 +14,7 @@ test('it creates PDA nodes', t => {
},
});

t.deepEqual(
node,
expect(node).toEqual(
pdaNode({
name: 'myPda',
seeds: [
Expand Down
7 changes: 3 additions & 4 deletions packages/nodes-from-anchor/test/v01/ProgramNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
structTypeNode,
variablePdaSeedNode,
} from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { getAnchorDiscriminatorV01, programNodeFromAnchorV01 } from '../../src/index.js';

test('it creates program nodes', t => {
test('it creates program nodes', () => {
const node = programNodeFromAnchorV01({
accounts: [{ discriminator: [246, 28, 6, 87, 251, 45, 50, 42], name: 'MyAccount' }],
address: '1111',
Expand All @@ -46,8 +46,7 @@ test('it creates program nodes', t => {
types: [{ name: 'MyAccount', type: { fields: [], kind: 'struct' } }],
});

t.deepEqual(
node,
expect(node).toEqual(
programNode({
accounts: [
accountNode({
Expand Down
7 changes: 3 additions & 4 deletions packages/nodes-from-anchor/test/v01/RootNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { programNode, rootNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { rootNodeFromAnchorV01 } from '../../src/index.js';

test('it creates root nodes', t => {
test('it creates root nodes', () => {
const node = rootNodeFromAnchorV01({
address: '1111',
instructions: [],
Expand All @@ -14,8 +14,7 @@ test('it creates root nodes', t => {
},
});

t.deepEqual(
node,
expect(node).toEqual(
rootNode(
programNode({
name: 'myProgram',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { arrayTypeNode, fixedCountNode, numberTypeNode, prefixedCountNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { typeNodeFromAnchorV01 } from '../../../src/index.js';

test('it creates array type nodes', t => {
t.deepEqual(typeNodeFromAnchorV01({ array: ['u8', 2] }), arrayTypeNode(numberTypeNode('u8'), fixedCountNode(2)));
t.deepEqual(
typeNodeFromAnchorV01({ vec: 'u8' }),
test('it creates array type nodes', () => {
expect(typeNodeFromAnchorV01({ array: ['u8', 2] })).toEqual(arrayTypeNode(numberTypeNode('u8'), fixedCountNode(2)));
expect(typeNodeFromAnchorV01({ vec: 'u8' })).toEqual(
arrayTypeNode(numberTypeNode('u8'), prefixedCountNode(numberTypeNode('u32'))),
);
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { booleanTypeNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { typeNodeFromAnchorV01 } from '../../../src/index.js';

test('it creates boolean type nodes', t => {
t.deepEqual(typeNodeFromAnchorV01('bool'), booleanTypeNode());
test('it creates boolean type nodes', () => {
expect(typeNodeFromAnchorV01('bool')).toEqual(booleanTypeNode());
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { bytesTypeNode, numberTypeNode, sizePrefixTypeNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { typeNodeFromAnchorV01 } from '../../../src/index.js';

test('it creates bytes type nodes', t => {
t.deepEqual(typeNodeFromAnchorV01('bytes'), sizePrefixTypeNode(bytesTypeNode(), numberTypeNode('u32')));
test('it creates bytes type nodes', () => {
expect(typeNodeFromAnchorV01('bytes')).toEqual(sizePrefixTypeNode(bytesTypeNode(), numberTypeNode('u32')));
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
structTypeNode,
tupleTypeNode,
} from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { typeNodeFromAnchorV01 } from '../../../src/index.js';

test('it creates enum type nodes', t => {
test('it creates enum type nodes', () => {
const node = typeNodeFromAnchorV01({
kind: 'enum',
variants: [
Expand All @@ -23,8 +23,7 @@ test('it creates enum type nodes', t => {
],
});

t.deepEqual(
node,
expect(node).toEqual(
enumTypeNode([
enumEmptyVariantTypeNode('variantA'),
enumTupleVariantTypeNode('variantB', tupleTypeNode([numberTypeNode('u16'), booleanTypeNode()])),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { numberTypeNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { typeNodeFromAnchorV01 } from '../../../src/index.js';

test('it creates number type nodes', t => {
t.deepEqual(typeNodeFromAnchorV01('f32'), numberTypeNode('f32'));
t.deepEqual(typeNodeFromAnchorV01('f64'), numberTypeNode('f64'));
t.deepEqual(typeNodeFromAnchorV01('i8'), numberTypeNode('i8'));
t.deepEqual(typeNodeFromAnchorV01('i16'), numberTypeNode('i16'));
t.deepEqual(typeNodeFromAnchorV01('i32'), numberTypeNode('i32'));
t.deepEqual(typeNodeFromAnchorV01('i64'), numberTypeNode('i64'));
t.deepEqual(typeNodeFromAnchorV01('i128'), numberTypeNode('i128'));
t.deepEqual(typeNodeFromAnchorV01('shortU16'), numberTypeNode('shortU16'));
t.deepEqual(typeNodeFromAnchorV01('u8'), numberTypeNode('u8'));
t.deepEqual(typeNodeFromAnchorV01('u16'), numberTypeNode('u16'));
t.deepEqual(typeNodeFromAnchorV01('u32'), numberTypeNode('u32'));
t.deepEqual(typeNodeFromAnchorV01('u64'), numberTypeNode('u64'));
t.deepEqual(typeNodeFromAnchorV01('u128'), numberTypeNode('u128'));
test('it creates number type nodes', () => {
expect(typeNodeFromAnchorV01('f32')).toEqual(numberTypeNode('f32'));
expect(typeNodeFromAnchorV01('f64')).toEqual(numberTypeNode('f64'));
expect(typeNodeFromAnchorV01('i8')).toEqual(numberTypeNode('i8'));
expect(typeNodeFromAnchorV01('i16')).toEqual(numberTypeNode('i16'));
expect(typeNodeFromAnchorV01('i32')).toEqual(numberTypeNode('i32'));
expect(typeNodeFromAnchorV01('i64')).toEqual(numberTypeNode('i64'));
expect(typeNodeFromAnchorV01('i128')).toEqual(numberTypeNode('i128'));
expect(typeNodeFromAnchorV01('shortU16')).toEqual(numberTypeNode('shortU16'));
expect(typeNodeFromAnchorV01('u8')).toEqual(numberTypeNode('u8'));
expect(typeNodeFromAnchorV01('u16')).toEqual(numberTypeNode('u16'));
expect(typeNodeFromAnchorV01('u32')).toEqual(numberTypeNode('u32'));
expect(typeNodeFromAnchorV01('u64')).toEqual(numberTypeNode('u64'));
expect(typeNodeFromAnchorV01('u128')).toEqual(numberTypeNode('u128'));
});
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { numberTypeNode, optionTypeNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { typeNodeFromAnchorV01 } from '../../../src/index.js';

test('it creates option type nodes', t => {
t.deepEqual(typeNodeFromAnchorV01({ option: 'u8' }), optionTypeNode(numberTypeNode('u8')));
test('it creates option type nodes', () => {
expect(typeNodeFromAnchorV01({ option: 'u8' })).toEqual(optionTypeNode(numberTypeNode('u8')));
});

test('it creates option type nodes with fixed size', t => {
t.deepEqual(
typeNodeFromAnchorV01({ coption: 'u8' }),
test('it creates option type nodes with fixed size', () => {
expect(typeNodeFromAnchorV01({ coption: 'u8' })).toEqual(
optionTypeNode(numberTypeNode('u8'), { fixed: true, prefix: numberTypeNode('u32') }),
);
t.deepEqual(
typeNodeFromAnchorV01({ coption: 'u8' }),
expect(typeNodeFromAnchorV01({ coption: 'u8' })).toEqual(
optionTypeNode(numberTypeNode('u8'), { fixed: true, prefix: numberTypeNode('u32') }),
);
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { publicKeyTypeNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { typeNodeFromAnchorV01 } from '../../../src/index.js';

test('it creates public key type nodes', t => {
t.deepEqual(typeNodeFromAnchorV01('pubkey'), publicKeyTypeNode());
test('it creates public key type nodes', () => {
expect(typeNodeFromAnchorV01('pubkey')).toEqual(publicKeyTypeNode());
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { numberTypeNode, sizePrefixTypeNode, stringTypeNode } from '@kinobi-so/nodes';
import test from 'ava';
import { expect, test } from 'vitest';

import { typeNodeFromAnchorV01 } from '../../../src/index.js';

test('it creates string type nodes', t => {
t.deepEqual(typeNodeFromAnchorV01('string'), sizePrefixTypeNode(stringTypeNode('utf8'), numberTypeNode('u32')));
test('it creates string type nodes', () => {
expect(typeNodeFromAnchorV01('string')).toEqual(sizePrefixTypeNode(stringTypeNode('utf8'), numberTypeNode('u32')));
});
Loading

0 comments on commit 4418cdf

Please sign in to comment.