Skip to content

Commit

Permalink
fix: runtime import error import error (#346)
Browse files Browse the repository at this point in the history
* Fix Error ***ERR_MODULE_NOT_FOUND***: Cannot find module '/app/dst/utils/currency' imported from /app/dst/messages.js

* Let jest use the ts files when importing js files

See: kulshekhar/ts-jest#1057

* Fix more extension-less imports
  • Loading branch information
daniel-hauser authored Sep 8, 2024
1 parent b433fd0 commit 2c13a21
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 24 deletions.
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ export default {
preset: "ts-jest",
testEnvironment: "node",
rootDir: "./src",
moduleNameMapper: {
"^(\\.\\.?\\/.+)\\.jsx?$": "$1",
},
};
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "dotenv/config";
import { subDays, format } from "date-fns";
import { AccountConfig } from "./types";
import { AccountConfig } from "./types.js";
import { createLogger, logToPublicLog } from "./utils/logger.js";

const logger = createLogger("config");
Expand Down
2 changes: 1 addition & 1 deletion src/data/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { performance } from "perf_hooks";
import { getAccountTransactions } from "./scrape.js";
import { AccountConfig, AccountScrapeResult } from "../types";
import { AccountConfig, AccountScrapeResult } from "../types.js";
import { createLogger } from "../utils/logger.js";

const logger = createLogger("data");
Expand Down
10 changes: 5 additions & 5 deletions src/messages.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CompanyTypes } from "israeli-bank-scrapers";
import { getSummaryMessages } from "./messages";
import { AccountScrapeResult, Transaction, TransactionRow } from "./types";
import { getSummaryMessages } from "./messages.js";
import { AccountScrapeResult, Transaction, TransactionRow } from "./types.js";
import {
TransactionStatuses,
TransactionTypes,
} from "israeli-bank-scrapers/lib/transactions";
import { ScraperErrorTypes } from "israeli-bank-scrapers/lib/scrapers/errors";
import { createSaveStats, SaveStats, statsString } from "./saveStats";
} from "israeli-bank-scrapers/lib/transactions.js";
import { ScraperErrorTypes } from "israeli-bank-scrapers/lib/scrapers/errors.js";
import { createSaveStats, SaveStats, statsString } from "./saveStats.js";

describe("messages", () => {
describe("getSummaryMessages", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
TransactionStatuses,
TransactionTypes,
} from "israeli-bank-scrapers/lib/transactions.js";
import { AccountScrapeResult, Transaction } from "./types";
import { normalizeCurrency } from "./utils/currency";
import { AccountScrapeResult, Transaction } from "./types.js";
import { normalizeCurrency } from "./utils/currency.js";

export function getSummaryMessages(results: Array<AccountScrapeResult>) {
const accountsSummary = results.flatMap(({ result, companyId }) => {
Expand Down
5 changes: 0 additions & 5 deletions src/notifier.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Telegraf, TelegramError } from "telegraf";
import { Message } from "telegraf/typings/core/types/typegram";
import { TELEGRAM_API_KEY, TELEGRAM_CHAT_ID } from "./config.js";
import { createLogger, logToPublicLog } from "./utils/logger.js";

Expand Down Expand Up @@ -32,10 +31,6 @@ export async function sendPhoto(photoPath: string, caption: string) {
);
}

export async function deleteMessage(message: Message.TextMessage) {
await bot?.telegram.deleteMessage(TELEGRAM_CHAT_ID, message.message_id);
}

export async function editMessage(
message: number | undefined,
newText: string,
Expand Down
6 changes: 3 additions & 3 deletions src/saveStats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TransactionStatuses } from "israeli-bank-scrapers/lib/transactions";
import { TransactionRow } from "./types";
import { transactionList } from "./messages";
import { TransactionStatuses } from "israeli-bank-scrapers/lib/transactions.js";
import { TransactionRow } from "./types.js";
import { transactionList } from "./messages.js";

export interface SaveStats {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/storage/azure-data-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { sendError } from "../notifier.js";
import { systemName } from "./../config.js";
import { createLogger } from "./../utils/logger.js";
import type KustoIngestClient from "azure-kusto-ingest/types/src/ingestClient.js";
import type { KustoIngestClient } from "azure-kusto-ingest/types/src/ingestClient.js";
import type { TransactionRow, TransactionStorage } from "../types.js";
import { createSaveStats } from "../saveStats.js";

Expand Down
4 changes: 2 additions & 2 deletions src/storage/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
Transaction,
TransactionStatuses,
TransactionTypes,
} from "israeli-bank-scrapers/lib/transactions";
import { transactionUniqueId, transactionHash } from "./utils";
} from "israeli-bank-scrapers/lib/transactions.js";
import { transactionUniqueId, transactionHash } from "./utils.js";
import { CompanyTypes } from "israeli-bank-scrapers";

const transaction1: Transaction = {
Expand Down
2 changes: 1 addition & 1 deletion src/storage/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { formatISO, parseISO, roundToNearestMinutes } from "date-fns";
import type { CompanyTypes } from "israeli-bank-scrapers";
import type { Transaction } from "israeli-bank-scrapers/lib/transactions";
import type { Transaction } from "israeli-bank-scrapers/lib/transactions.js";

/**
* Generates a hash for a transaction that can be used to ~uniquely identify it.
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { CompanyTypes } from "israeli-bank-scrapers";
import type { Transaction } from "israeli-bank-scrapers/lib/transactions";
import type { Transaction } from "israeli-bank-scrapers/lib/transactions.js";
import type {
ScraperScrapingResult,
ScraperCredentials,
} from "israeli-bank-scrapers";
import { SaveStats } from "./saveStats";
import { SaveStats } from "./saveStats.js";
export type { Transaction };

export type AccountConfig = ScraperCredentials & {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/currency.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizeCurrency } from "./currency";
import { normalizeCurrency } from "./currency.js";

describe("normalizeCurrency", () => {
it("should return undefined if currency is undefined", () => {
Expand Down

0 comments on commit 2c13a21

Please sign in to comment.