Skip to content

Commit c4c166b

Browse files
authored
Merge pull request #21 from ilionic/chore/jest-improve-tests
Switch to Jest, refactor tests
2 parents 5f1f58c + 756f3db commit c4c166b

23 files changed

+4466
-1140
lines changed

.babelrc

Lines changed: 0 additions & 15 deletions
This file was deleted.

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.snap linguist-generated=true
2+
test/mocks/* linguist-generated=true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
node_modules
23
*.log
34
build
@@ -12,3 +13,4 @@ dist-cli
1213
/remarks*.json
1314
/dump-*.json
1415
throwaway.js
16+
coverage

babel.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = (api) => {
2+
if (api) api.cache(true);
3+
return {
4+
presets: [
5+
"@babel/typescript",
6+
[
7+
"@babel/preset-env",
8+
{
9+
targets: { browsers: "defaults, not ie 11", node: true },
10+
modules: false,
11+
useBuiltIns: false,
12+
loose: true,
13+
},
14+
],
15+
],
16+
plugins: [
17+
"@babel/plugin-proposal-optional-chaining",
18+
"@babel/plugin-transform-modules-commonjs",
19+
],
20+
};
21+
};

jest.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
transform: {
3+
"^.+\\.(t|j)sx?$": "babel-jest",
4+
},
5+
transformIgnorePatterns: [
6+
"/node_modules/(?!(@polkadot|@babel/runtime/helpers/esm/))",
7+
],
8+
collectCoverage: true,
9+
collectCoverageFrom: [
10+
"src/tools/utils.ts",
11+
"src/tools/validate-remark.ts",
12+
"src/tools/consolidator/consolidator.ts",
13+
"src/rmrk1.0.0/classes/*",
14+
],
15+
};

package.json

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"cli:getevents": "ts-node --project tsconfig.cli.json cli/index getevents",
3838
"cli:validate": "ts-node --project tsconfig.cli.json src/index validate",
3939
"cli:run-listener": "ts-node --project tsconfig.cli.json cli/run-listener.ts",
40-
"test": "TS_NODE_PROJECT=tsconfig.test.json ava",
41-
"test:watch": "TS_NODE_PROJECT=tsconfig.test.json ava --watch",
40+
"test": "jest --silent",
41+
"test:coverage": "jest --coverage --coverageDirectory='coverage'",
4242
"prepublishOnly": "yarn build"
4343
},
4444
"bin": {
@@ -60,18 +60,21 @@
6060
"@rollup/plugin-commonjs": "^17.1.0",
6161
"@rollup/plugin-json": "^4.1.0",
6262
"@rollup/plugin-node-resolve": "^11.2.0",
63+
"@types/jest": "^26.0.20",
6364
"@types/node": "^14.11.2",
6465
"@typescript-eslint/eslint-plugin": "^4.2.0",
6566
"@typescript-eslint/parser": "^4.2.0",
66-
"ava": "^3.12.1",
67+
"babel-jest": "^26.6.3",
6768
"eslint": "^7.9.0",
6869
"eslint-config-prettier": "^6.11.0",
6970
"eslint-plugin-prettier": "^3.1.4",
7071
"eslint-plugin-security": "^1.4.0",
72+
"jest": "^26.6.3",
7173
"prettier": "^2.1.2",
7274
"process": "^0.11.10",
7375
"rollup": "^2.40.0",
7476
"rollup-plugin-terser": "^7.0.2",
77+
"ts-jest": "^26.5.3",
7578
"ts-loader": "^8.0.17",
7679
"ts-node": "^9.0.0",
7780
"typescript": "^4.0.3",
@@ -91,16 +94,5 @@
9194
"superstruct": "^0.14.2",
9295
"uint8arrays": "^2.1.3",
9396
"winston": "^3.3.3"
94-
},
95-
"ava": {
96-
"extensions": [
97-
"ts"
98-
],
99-
"require": [
100-
"ts-node/register"
101-
],
102-
"files": [
103-
"test/**/*.test.ts"
104-
]
10597
}
10698
}

src/tools/utils.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,13 @@ export const stringIsAValidUrl = (s: string): boolean => {
4848
}
4949
};
5050

51-
export const prefixToArray = function (prefix: string): string[] {
52-
const returnArray = [];
53-
const exploded = prefix.split(",");
54-
for (const p of exploded) {
55-
if (p.indexOf("0x") === 0) {
56-
returnArray.push(p);
57-
} else {
58-
returnArray.push(stringToHex(p));
51+
export const prefixToArray = (prefix: string): string[] =>
52+
prefix.split(",").map((item) => {
53+
if (item.indexOf("0x") === 0) {
54+
return item;
5955
}
60-
}
61-
return returnArray;
62-
};
56+
return stringToHex(item);
57+
});
6358

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

144-
const isSystemRemark = (call: TCall, prefixes: string[]) => {
145-
return (
146-
call.section === "system" &&
147-
call.method === "remark" &&
148-
(prefixes.length < 1 ||
149-
prefixes.some((word) => call.args.toString().startsWith(word)))
150-
);
151-
};
139+
export const isSystemRemark = (call: TCall, prefixes: string[]): Boolean =>
140+
call.section === "system" &&
141+
call.method === "remark" &&
142+
(prefixes.length < 1 ||
143+
prefixes.some((word) => call.args.toString().startsWith(word)));
152144

153-
const isUtilityBatch = (call: TCall) =>
145+
export const isUtilityBatch = (call: TCall) =>
154146
call.section === "utility" &&
155147
(call.method === "batch" || call.method === "batchAll");
156148

0 commit comments

Comments
 (0)