Skip to content

Commit

Permalink
Update configs.
Browse files Browse the repository at this point in the history
Update configurations and try to get tests working in CI.
  • Loading branch information
jamesbuch committed Sep 14, 2024
1 parent c3bd492 commit a5cd338
Show file tree
Hide file tree
Showing 7 changed files with 1,725 additions and 109 deletions.
15 changes: 15 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
preset: 'ts-jest/presets/default-esm',
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
},
],
},
};
1,706 changes: 1,641 additions & 65 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coinspot-v2-api",
"version": "1.0.3",
"version": "1.0.5",
"description": "CoinSpot v2 API https://www.coinspot.com.au/v2/api",
"homepage": "https://npmjs.com/coinspot-api-v2",
"keywords": [
Expand Down Expand Up @@ -29,17 +29,20 @@
"url": "https://github.com/jamesbuch"
},
"scripts": {
"build": "tsc",
"test": "jest",
"dev": "node --loader ts-node/esm --experimental-specifier-resolution=node examples/demo.ts",
"test:coverage": "jest --coverage",
"lint": "eslint ."
"lint": "eslint .",
"build": "tsc -p tsconfig.build.json",
"test": "node --experimental-vm-modules node_modules/.bin/jest",
"test:coverage": "node --experimental-vm-modules node_modules/.bin/jest --coverage"
},
"dependencies": {
"axios": "^1.7.7",
"winston": "^3.14.2"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.4",
"@babel/preset-typescript": "^7.24.7",
"@types/jest": "^29.5.13",
"@types/node": "^22.5.4",
"@types/winston": "^2.4.4",
Expand All @@ -62,13 +65,14 @@
"html"
],
"collectCoverageFrom": [
"src/**/*.ts",
"!src/types.ts",
"!src/examples/**"
]
"src/**/*.{js,ts}",
"!**/node_modules/**",
"!**/vendor/**"
],
"coverageDirectory": "coverage"
},
"jest-junit": {
"outputDirectory": ".",
"outputName": "junit.xml"
}
}
}
27 changes: 18 additions & 9 deletions tests/authenticatedApi.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import { AuthenticatedCoinspotApi } from '../src/authenticatedApi';

try {
const dotenv = await import('dotenv');
dotenv.config();
} catch (e) {
// console.log('dotenv not found, skipping .env file loading');
}
let API_KEY: string;
let API_SECRET: string;

const API_KEY = process.env.COINSPOT_API_KEY as string;
const API_SECRET = process.env.COINSPOT_API_SECRET as string;
beforeAll(async () => {
try {
const dotenv = await import('dotenv');
dotenv.config();
} catch (e) {
console.log('dotenv not found, skipping .env file loading');
}

API_KEY = process.env.COINSPOT_API_KEY!;
API_SECRET = process.env.COINSPOT_API_SECRET!;

if (!API_KEY || !API_SECRET) {
throw new Error('COINSPOT_API_KEY and COINSPOT_API_SECRET must be set in environment variables or .env file');
}
});

const api = new AuthenticatedCoinspotApi(API_KEY, API_SECRET);

describe('Authenticated API', () => {
const testCoin = 'btc';
const api = new AuthenticatedCoinspotApi(API_KEY, API_SECRET);

test('getCoinWithdrawalDetails', async () => {
const result = await api.getCoinWithdrawalDetails(testCoin);
Expand Down
31 changes: 19 additions & 12 deletions tests/authenticatedReadOnlyApi.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { AuthenticatedCoinspotReadOnlyApi } from '../src/authenticatedReadOnlyApi';

try {
const dotenv = await import('dotenv');
dotenv.config();
} catch (e) {
// console.log('dotenv not found, skipping .env file loading');
}

const API_KEY = process.env.COINSPOT_API_KEY as string;
const API_SECRET = process.env.COINSPOT_API_SECRET as string;

const api = new AuthenticatedCoinspotReadOnlyApi(API_KEY, API_SECRET);
let API_KEY: string;
let API_SECRET: string;

beforeAll(async () => {
try {
const dotenv = await import('dotenv');
dotenv.config();
} catch (e) {
console.log('dotenv not found, skipping .env file loading');
}

API_KEY = process.env.COINSPOT_API_KEY!;
API_SECRET = process.env.COINSPOT_API_SECRET!;

if (!API_KEY || !API_SECRET) {
throw new Error('COINSPOT_API_KEY and COINSPOT_API_SECRET must be set in environment variables or .env file');
}
});

describe('Authenticated Read-Only API', () => {
const testCoin = 'btc';
const api = new AuthenticatedCoinspotReadOnlyApi(API_KEY, API_SECRET);

test('getReadOnlyStatus', async () => {
const result = await api.getReadOnlyStatus();
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"exclude": [
"node_modules",
"dist",
"tests"
]
}
23 changes: 10 additions & 13 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"lib": [
"ES2022"
],
"moduleResolution": "node",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
"strict": true,
"outDir": "./dist",
"rootDir": ".",
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
"src/**/*",
"tests/**/*"
],
"exclude": [
"node_modules",
"**/*.test.ts"
"dist"
],
"ts-node": {
"esm": true,
Expand Down

0 comments on commit a5cd338

Please sign in to comment.