Skip to content

Commit

Permalink
Use jest to facilitate source coverage (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leslie-Wong-H authored Apr 26, 2023
2 parents 5fe6180 + 3cadbdf commit ca7277e
Show file tree
Hide file tree
Showing 7 changed files with 52,820 additions and 26,509 deletions.
11 changes: 10 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ module.exports = {
commonjs: true,
es6: true,
node: true,
"jest/globals": true,
},
plugins: ["@typescript-eslint"],
plugins: ["@typescript-eslint", "jest"],
extends: ["eslint:recommended", "plugin:import/errors", "prettier"],
parserOptions: {
ecmaVersion: 2018,
Expand All @@ -33,4 +34,12 @@ module.exports = {
"no-unused-vars": ["off"],
"no-underscore-dangle": ["off"],
},
settings: {
"import/resolver": {
node: {
extensions: [".ts"],
moduleDirectory: ["src", "test", "node_modules"],
},
},
},
};
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
roots: ["<rootDir>/test"],
testRegex: "test/(.+)\\.spec\\.(js?|ts?)$",
transform: {
"^.+\\.ts?$": ["ts-jest", { useESM: true }],
},
moduleFileExtensions: ["js", "ts"],
extensionsToTreatAsEsm: [".ts"],
};
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"dev": "tsc --watch",
"build": "rm -rf tsc-out && tsc && for f in tsc-out/*.js; do mv -- \"$f\" \"${f%.js}.mjs\"; done && rollup --config rollup.config.js",
"build:win": "rmdir /s/q tsc-out && tsc && for %a in (tsc-out/*.js) do for /f \"tokens=1,* delims=.\" %b in (\"%~nxa\") do ren \"tsc-out\\%a\" \"%b.mjs\" && rollup --config rollup.config.js",
"test": "npm run test:cjs && npm run test:esm && npm run test:browser",
"test:cjs": "nyc --reporter=lcov mocha",
"test": "npm run test:cjs && npm run test:esm && npm run test:browser && npm run test:ts",
"test:cjs": "node test/test.js",
"test:esm": "node --experimental-modules test/test.mjs",
"test:browser": "node test_browser.js",
"test:ts": "jest --coverage",
"lint": "eslint . --ext ts --fix",
"ci": "npm run lint && npm run build && npm run test"
},
Expand All @@ -43,6 +44,7 @@
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-transform-object-assign": "^7.16.0",
"@babel/preset-env": "^7.5.5",
"@types/jest": "^29.5.1",
"@typescript-eslint/eslint-plugin": "4.29.1",
"@typescript-eslint/parser": "4.29.1",
"babel-eslint": "^10.1.0",
Expand All @@ -51,9 +53,9 @@
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^25.7.0",
"husky": "^4.3.8",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"jest": "^28.1.3",
"prettier": "^2.3.2",
"request": "^2.88.2",
"rollup": "^1.19.4",
Expand All @@ -62,6 +64,7 @@
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.0",
"tape": "^4.13.2",
"ts-jest": "^28.0.8",
"typescript": "^4.5.2"
},
"dependencies": {
Expand Down
7 changes: 4 additions & 3 deletions src/jsbi-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ function jsbiCal(tokens: string[]): string {
* @param {Array} inp
* @returns {Array}
*/
function rpnParse(inp: string[]): string[] {
function rpnParse(inp: (string | number)[]): string[] {
let outQueue: Token[] = [];
let opStack: Token[] = [];

Expand Down Expand Up @@ -384,7 +384,7 @@ interface Prec {
"-": 2;
}

function tokenize(expArr: string[]): Token[] {
function tokenize(expArr: (string | number)[]): Token[] {
let result: Token[] = [];

const assoc: Assoc = {
Expand Down Expand Up @@ -418,7 +418,8 @@ function tokenize(expArr: string[]): Token[] {

// array of tokens
if (Array.isArray(expArr)) {
expArr.forEach(function (char, idx) {
expArr.forEach(function (rawChar, idx) {
const char = String(rawChar);
if (isDigit(char)) {
result.push(new (Token as any)("Literal", char));
} else if (isLetter(char)) {
Expand Down
Loading

0 comments on commit ca7277e

Please sign in to comment.