Skip to content

Commit

Permalink
Merge pull request #3 from ilionic/chore/jest-improve-tests
Browse files Browse the repository at this point in the history
Chore/jest improve tests
  • Loading branch information
Yuripetusko authored Mar 17, 2021
2 parents dc49e37 + 756f3db commit 25ccea2
Show file tree
Hide file tree
Showing 23 changed files with 4,466 additions and 1,140 deletions.
15 changes: 0 additions & 15 deletions .babelrc

This file was deleted.

2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.snap linguist-generated=true
test/mocks/* linguist-generated=true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules
*.log
build
Expand All @@ -12,3 +13,4 @@ dist-cli
/remarks*.json
/dump-*.json
throwaway.js
coverage
21 changes: 21 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = (api) => {
if (api) api.cache(true);
return {
presets: [
"@babel/typescript",
[
"@babel/preset-env",
{
targets: { browsers: "defaults, not ie 11", node: true },
modules: false,
useBuiltIns: false,
loose: true,
},
],
],
plugins: [
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-transform-modules-commonjs",
],
};
};
15 changes: 15 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
transform: {
"^.+\\.(t|j)sx?$": "babel-jest",
},
transformIgnorePatterns: [
"/node_modules/(?!(@polkadot|@babel/runtime/helpers/esm/))",
],
collectCoverage: true,
collectCoverageFrom: [
"src/tools/utils.ts",
"src/tools/validate-remark.ts",
"src/tools/consolidator/consolidator.ts",
"src/rmrk1.0.0/classes/*",
],
};
20 changes: 6 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"cli:getevents": "ts-node --project tsconfig.cli.json cli/index getevents",
"cli:validate": "ts-node --project tsconfig.cli.json src/index validate",
"cli:run-listener": "ts-node --project tsconfig.cli.json cli/run-listener.ts",
"test": "TS_NODE_PROJECT=tsconfig.test.json ava",
"test:watch": "TS_NODE_PROJECT=tsconfig.test.json ava --watch",
"test": "jest --silent",
"test:coverage": "jest --coverage --coverageDirectory='coverage'",
"prepublishOnly": "yarn build"
},
"bin": {
Expand All @@ -60,18 +60,21 @@
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"@types/jest": "^26.0.20",
"@types/node": "^14.11.2",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"ava": "^3.12.1",
"babel-jest": "^26.6.3",
"eslint": "^7.9.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-security": "^1.4.0",
"jest": "^26.6.3",
"prettier": "^2.1.2",
"process": "^0.11.10",
"rollup": "^2.40.0",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^26.5.3",
"ts-loader": "^8.0.17",
"ts-node": "^9.0.0",
"typescript": "^4.0.3",
Expand All @@ -91,16 +94,5 @@
"superstruct": "^0.14.2",
"uint8arrays": "^2.1.3",
"winston": "^3.3.3"
},
"ava": {
"extensions": [
"ts"
],
"require": [
"ts-node/register"
],
"files": [
"test/**/*.test.ts"
]
}
}
32 changes: 12 additions & 20 deletions src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ export const stringIsAValidUrl = (s: string): boolean => {
}
};

export const prefixToArray = function (prefix: string): string[] {
const returnArray = [];
const exploded = prefix.split(",");
for (const p of exploded) {
if (p.indexOf("0x") === 0) {
returnArray.push(p);
} else {
returnArray.push(stringToHex(p));
export const prefixToArray = (prefix: string): string[] =>
prefix.split(",").map((item) => {
if (item.indexOf("0x") === 0) {
return item;
}
}
return returnArray;
};
return stringToHex(item);
});

const getMeta = (call: Call, block: number): RemarkMeta | false => {
const str = hexToString(call.value);
Expand Down Expand Up @@ -141,16 +136,13 @@ export const isBatchInterrupted = async (
return Boolean(events.length);
};

const isSystemRemark = (call: TCall, prefixes: string[]) => {
return (
call.section === "system" &&
call.method === "remark" &&
(prefixes.length < 1 ||
prefixes.some((word) => call.args.toString().startsWith(word)))
);
};
export const isSystemRemark = (call: TCall, prefixes: string[]): Boolean =>
call.section === "system" &&
call.method === "remark" &&
(prefixes.length < 1 ||
prefixes.some((word) => call.args.toString().startsWith(word)));

const isUtilityBatch = (call: TCall) =>
export const isUtilityBatch = (call: TCall) =>
call.section === "utility" &&
(call.method === "batch" || call.method === "batchAll");

Expand Down
Loading

0 comments on commit 25ccea2

Please sign in to comment.