From 221649453689f2bc8a4475e69764d922daf33573 Mon Sep 17 00:00:00 2001 From: Amadeo Pellicce Date: Thu, 3 Nov 2022 11:47:54 +0100 Subject: [PATCH] adding cache script before running tests --- package.json | 5 +++-- src/cache.ts | 14 ++++++++++++++ src/networks/index.test.ts | 15 +++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/cache.ts diff --git a/package.json b/package.json index bfd7421..f12aa32 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,12 @@ "!dist/**/*.test.js" ], "scripts": { - "index": "yarn ts-node ./src/index.ts", + "index": "ts-node ./src/index.ts", "clean": "rimraf ./dist/ ./exec/", "build": "yarn clean && tsc", "preparePublish": "yarn build && npm version patch", - "test": "yarn build && ava --verbose", + "prepareTest": "yarn ts-node ./src/cache.ts", + "test": "yarn prepareTest && yarn build && ava --verbose", "bundle": "yarn build && pkg . --out-dir ./exec/" }, "devDependencies": { diff --git a/src/cache.ts b/src/cache.ts new file mode 100644 index 0000000..d0b0c5f --- /dev/null +++ b/src/cache.ts @@ -0,0 +1,14 @@ +import { cloneOrPullRepoAndUpdateSubmodules } from "./utils"; +import { REPO_CLONE_URL, DEFAULT_REPO_DISK_LOCATION, DEFAULT_TWA_DISK_LOCATION, TWA_REPO_CLONE_URL } from "./utils/constants"; + +async function main() { + console.log("Cloning map3xyz/assets repo... ahead of tests"); + await Promise.all([ + cloneOrPullRepoAndUpdateSubmodules(REPO_CLONE_URL, DEFAULT_REPO_DISK_LOCATION, true, "master"), + cloneOrPullRepoAndUpdateSubmodules(TWA_REPO_CLONE_URL, DEFAULT_TWA_DISK_LOCATION, true, "master"), + ]); +} + +main().catch(err => console.error(err)); + + diff --git a/src/networks/index.test.ts b/src/networks/index.test.ts index 5d7f797..aaed820 100644 --- a/src/networks/index.test.ts +++ b/src/networks/index.test.ts @@ -1,5 +1,5 @@ import test from "ava"; -import { getAssetMapping, getNetworks, getNetworksWithAssets } from "."; +import { getAssetMapping, getAssetsForNetwork, getNetworks, getNetworksWithAssets } from "."; test("networks includes ethereum", async (t) => { const networks = await getNetworks(); @@ -19,4 +19,15 @@ test("networks with assets includes polygon", async (t) => { test("networks with assets does not include Bitcoin", async (t) => { const networks = await getNetworksWithAssets(); t.falsy(networks.find((n) => n.name === "Bitcoin")); -}); \ No newline at end of file +}); + +test("Get assets limits work", async t => { + const assets = await getAssetsForNetwork("ethereum", undefined, 1); + t.truthy(assets.length === 1); +}) + +test("Get assets identifier limits works", async t => { + const assets = await getAssetsForNetwork("ethereum", undefined, 1, 1, ['coinmarketcap']); + t.truthy(assets.length === 1); + t.truthy(assets[0].identifiers.coinmarketcap); +}) \ No newline at end of file