Skip to content

Commit

Permalink
Init tests; give up on tsc for now
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed May 2, 2024
1 parent 4521b2b commit a2a3a6b
Show file tree
Hide file tree
Showing 6 changed files with 3,043 additions and 23 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ extends: [airbnb-base, plugin:prettier/recommended]
env:
es2023: true
node: true
jest: true
parserOptions:
ecmaVersion: latest
sourceType: module
rules:
no-console: off
import/prefer-default-export: off
import/extensions: [error, always]
import/extensions:
- error
- always
- mjs: never
3 changes: 3 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
testRegex: "test.mjs$",
};
18 changes: 18 additions & 0 deletions lib/util.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Parse string to date (or arrays of strings)
*/
export function parseDate(str) {
if (Array.isArray(str)) {
return str.map((s) => parseDate(s));
}

if (str) {
const date = new Date(str);
if (!date.getTime()) {
throw new Error(`Invalid date input: ${str}`);
}
return date;
}

return null;
}
22 changes: 22 additions & 0 deletions lib/util.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { parseDate } from "./util";

Check failure on line 1 in lib/util.test.mjs

View workflow job for this annotation

GitHub Actions / check-javascript / check-javascript

Cannot find module './util' or its corresponding type declarations.

describe("util", () => {
describe("parseDate", () => {
test("parses strings", () => {
expect(parseDate("2022-04-05")).toEqual(new Date("2022-04-05"));
expect(parseDate(["2022-04-05"])).toEqual([new Date("2022-04-05")]);
});

test("returns null for blank values", () => {
expect(parseDate(null)).toBeNull();
expect(parseDate("")).toBeNull();
expect(parseDate([""])).toEqual([null]);
});

test("throws errors for bad dates", () => {
expect(() => parseDate("whatev")).toThrow(/invalid date input/i);
expect(() => parseDate(["whatev"])).toThrow(/invalid date input/i);
expect(() => parseDate("2024-99-99")).toThrow(/invalid date input/i);
});
});
});
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
},
"private": "true",
"scripts": {
"lint": "npm run lint-prettier && npm run lint-es && npm run lint-ts",
"lint": "npm run lint-prettier && npm run lint-es",
"lint-prettier": "npx prettier --check **/*.{json,yml}",
"lint-es": "npx eslint '**/*.{js,mjs}'",
"lint-ts": "npx tsc",
"lint-fix": "npm run lint-fix-prettier && npm run lint-fix-es",
"lint-fix-prettier": "npx prettier --check **/*.{json,yml} --write",
"lint-fix-es": "npx eslint --fix '**/*.{js,mjs}'",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest"
},
"repository": {
"type": "git",
Expand All @@ -34,13 +34,20 @@
},
"homepage": "https://github.com/PRX/dovetail-cdn-usage#readme",
"devDependencies": {
"@aws-sdk/client-athena": "^3.567.0",
"@types/jest": "^29.5.12",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "*",
"eslint-config-prettier": "*",
"eslint-plugin-import": "*",
"eslint-plugin-jest": "*",
"eslint-plugin-prettier": "*",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"typescript": "^5.4.5"
},
"dependencies": {
"@google-cloud/bigquery": "^7.6.1",
"lambda-log": "^3.1.0"
}
}
Loading

0 comments on commit a2a3a6b

Please sign in to comment.