Skip to content

Commit

Permalink
Yarn Upgrade (#63)
Browse files Browse the repository at this point in the history
Update all but eslint (some manual some via yarn upgrade)
We also moved to jest for testing instead of mocha.
  • Loading branch information
bh2smith authored Sep 1, 2024
1 parent bf50b19 commit ab2f785
Show file tree
Hide file tree
Showing 16 changed files with 2,053 additions and 669 deletions.
11 changes: 3 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@
"sourceType": "module"
},
"rules": {
// TypeScript specific rules
"@typescript-eslint/explicit-function-return-type": ["warn", { "allowExpressions": true }],
"@typescript-eslint/type-annotation-spacing": "error",

"@typescript-eslint/no-unused-vars": ["error", { "ignoreRestSiblings": true }],
"@typescript-eslint/no-shadow": ["warn"],
"@typescript-eslint/no-shadow": ["warn", {}],
"no-unused-vars": "off",
"no-shadow": "off",

"semi": "error",
// Basic JavaScript/ESLint rules
"eqeqeq": ["error", "always"],
"no-unused-expressions": "warn",
"no-return-await": "error",
"no-console": ["warn", { "allow": ["warn", "error"] }]
"no-console": ["warn", { "allow": ["warn", "error"] }]
}
}
}
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/tests/**/*.spec.ts'], // Adjust the testMatch pattern as needed
moduleFileExtensions: ['ts', 'js'],
testTimeout: 10000
};
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"scripts": {
"build": "tsc",
"test": "ts-mocha 'tests/**/*.spec.ts' -r dotenv/config --timeout 10000",
"test": "jest",
"fmt": "prettier --write \"./**/*.ts\"",
"lint": "eslint ./src"
},
Expand All @@ -21,19 +21,16 @@
"loglevel": "^1.8.0"
},
"devDependencies": {
"@types/chai": "^4.3.3",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.17",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"@types/jest": "^29.5.12",
"@types/node": "^22.5.2",
"@typescript-eslint/eslint-plugin": "^8",
"@typescript-eslint/parser": "^8",
"dotenv": "^16.0.3",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"mocha": "^10.3.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-mocha": "^10.0.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.1",
"typescript": "^5.3.3"
}
Expand Down
8 changes: 1 addition & 7 deletions src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,7 @@ export class DuneClient {
opts?.pingFrequency,
);
if (state === ExecutionState.COMPLETED) {
const result = await this.getLatestResult(args);
if (result.execution_id !== execution_id) {
throw new DuneError(
`invalid execution ID: expected ${execution_id}, got ${result.execution_id}`,
);
}
return result;
return this.exec.getExecutionResults(execution_id, args);
} else {
const message = `refresh (execution ${execution_id}) yields incomplete terminal state ${state}`;
// TODO - log the error in constructor
Expand Down
5 changes: 4 additions & 1 deletion src/api/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export class TableAPI extends Router {
const response = await this.post<SuccessResponse>("table/upload/csv", args);
try {
return Boolean(response.success);
} catch (err) {
} catch (error: unknown) {
console.error(
`Upload CSV Error ${error instanceof Error ? error.message : String(error)}`,
);
throw new DuneError(`UploadCsvResponse ${JSON.stringify(response)}`);
}
}
Expand Down
27 changes: 12 additions & 15 deletions tests/e2e/client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { expect } from "chai";
import { DuneClient, QueryParameter } from "../../src/";
import log from "loglevel";
import { BASIC_KEY, PLUS_KEY } from "./util";
Expand All @@ -11,7 +10,7 @@ describe("DuneClient Extensions", () => {
let parameterizedQuery: number;
let multiRowQuery: number;

before(() => {
beforeAll(() => {
client = new DuneClient(BASIC_KEY);
parameterizedQuery = 1215383;
multiRowQuery = 3463180;
Expand All @@ -23,7 +22,7 @@ describe("DuneClient Extensions", () => {
queryId: parameterizedQuery,
query_parameters: [QueryParameter.text("TextField", "Plain Text")],
});
expect(results.result?.rows).to.be.deep.equal([
expect(results.result?.rows).toEqual([
{
date_field: "2022-05-04 00:00:00",
list_field: "Option 1",
Expand All @@ -36,9 +35,8 @@ describe("DuneClient Extensions", () => {
const multiRowResults = await client.runQuery({
queryId: multiRowQuery,
query_parameters: [QueryParameter.number("StartFrom", 10)],
opts: { batchSize: 4 },
});
expect(multiRowResults.result?.rows).to.be.deep.equal(
expect(multiRowResults.result?.rows).toEqual(
[10, 11, 12, 13, 14, 15].map((t) => ({ number: t })),
);
});
Expand All @@ -48,20 +46,19 @@ describe("DuneClient Extensions", () => {
queryId: multiRowQuery,
query_parameters: [QueryParameter.number("StartFrom", 1)],
filters: "number < 6",
opts: { batchSize: 4 },
});
expect(multiRowResults.result?.rows).to.be.deep.equal(
expect(multiRowResults.result?.rows).toEqual(
[1, 2, 3, 4, 5].map((t) => ({ number: t })),
);
});
}, 10000);

it("executes runQueryCSV", async () => {
// https://dune.com/queries/1215383
const results = await client.runQueryCSV({
queryId: parameterizedQuery,
query_parameters: [QueryParameter.text("TextField", "Plain Text")],
});
expect(results.data).to.be.equal(
expect(results.data).toEqual(
[
"text_field,number_field,date_field,list_field\n",
"Plain Text,3.1415926535,2022-05-04 00:00:00,Option 1\n",
Expand All @@ -74,7 +71,7 @@ describe("DuneClient Extensions", () => {
query_parameters: [QueryParameter.number("StartFrom", 3)],
opts: { batchSize: 4 },
});
expect(multiRowResults.data).to.be.deep.equal("number\n3\n4\n5\n6\n7\n8\n");
expect(multiRowResults.data).toEqual("number\n3\n4\n5\n6\n7\n8\n");
});

it("getsLatestResults", async () => {
Expand All @@ -83,15 +80,15 @@ describe("DuneClient Extensions", () => {
queryId: 1215383,
query_parameters: [QueryParameter.text("TextField", "Plain Text")],
});
expect(results.result?.rows.length).to.be.greaterThan(0);
expect(results.result?.rows.length).toBeGreaterThan(0);

// pagination:
const multiRowResults = await client.getLatestResult({
queryId: multiRowQuery,
query_parameters: [QueryParameter.number("StartFrom", 10)],
opts: { batchSize: 4 },
});
expect(multiRowResults.result?.rows.length).to.be.equal(6);
expect(multiRowResults.result?.rows.length).toEqual(6);
});

it("downloads CSV", async () => {
Expand All @@ -104,7 +101,7 @@ describe("DuneClient Extensions", () => {
);
const fileContents = await fs.readFile("./out.csv", { encoding: "utf8" });
// Compare the contents of the CSV file with the expected string
expect(fileContents).to.deep.equal("number\n3\n4\n5\n6\n7\n8\n");
expect(fileContents).toEqual("number\n3\n4\n5\n6\n7\n8\n");
// Remove the CSV file after the comparison
await fs.unlink("./out.csv");
});
Expand All @@ -117,8 +114,8 @@ describe("DuneClient Extensions", () => {
isPrivate: true,
});
const queryID = results.query_id;
expect(results.result?.rows).to.be.deep.equal([{ _col0: 1 }]);
expect(results.result?.rows).toEqual([{ _col0: 1 }]);
const query = await premiumClient.query.readQuery(queryID);
expect(query.is_archived).to.be.equal(true);
expect(query.is_archived).toEqual(true);
});
});
5 changes: 2 additions & 3 deletions tests/e2e/custom.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { CustomAPI } from "../../src/";
import log from "loglevel";
import { BASIC_KEY } from "./util";
import { expect } from "chai";

log.setLevel("silent", true);

describe("Custom API", () => {
let client: CustomAPI;
const slug = "test-custom-api";

before(() => {
beforeAll(() => {
client = new CustomAPI(BASIC_KEY);
});

Expand All @@ -21,6 +20,6 @@ describe("Custom API", () => {
slug,
limit: 1,
});
expect(results.result!.rows.length).to.equal(1);
expect(results.result!.rows.length).toEqual(1);
});
});
Loading

0 comments on commit ab2f785

Please sign in to comment.