Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Jest, refactor tests #21

Merged
merged 27 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0c18e2e
switch to jest, refactor tests
ilionic Mar 15, 2021
6bcf33a
Update utils.test.ts.snap
ilionic Mar 15, 2021
6f48925
Update .gitattributes
ilionic Mar 15, 2021
aa04f6a
update tests to not throw
ilionic Mar 15, 2021
af66f14
Merge remote-tracking branch 'upstream/updated-for-10' into chore/jes…
ilionic Mar 15, 2021
85c8c7d
Merge remote-tracking branch 'upstream/master' into chore/jest-improv…
ilionic Mar 15, 2021
ce19dff
add tests coverage report
ilionic Mar 15, 2021
35b4b2b
add tests for stringIsAValidUrl util
YuriGii Mar 15, 2021
b64a653
prettier
YuriGii Mar 15, 2021
86a1c12
add consolidator tests
ilionic Mar 15, 2021
a897523
Merge branch 'chore/jest-improve-tests' of https://github.com/ilionic…
ilionic Mar 15, 2021
837f990
prefixToArray test
YuriGii Mar 15, 2021
94cb47d
Delete .DS_Store
ilionic Mar 15, 2021
5154212
Update .gitignore
ilionic Mar 15, 2021
dcd0a17
refactor prefixToArray
YuriGii Mar 16, 2021
1a399cf
consolidator tests: token is minted twice with same ID
ilionic Mar 16, 2021
9cec440
Merge remote-tracking branch 'upstream/master' into chore/jest-improv…
ilionic Mar 16, 2021
07c3598
Merge remote-tracking branch 'upstream/master' into chore/jest-improv…
ilionic Mar 16, 2021
b8ad6b1
Update blocks-dump.ts
ilionic Mar 16, 2021
51b36b1
Update consolidator.test.ts
ilionic Mar 16, 2021
b30c7db
Merge remote-tracking branch 'upstream/master' into chore/jest-improv…
ilionic Mar 16, 2021
8a0a3ee
add isSystemRemark test
YuriGii Mar 16, 2021
1759484
add isUtilityBatch test
YuriGii Mar 16, 2021
5f77fea
add test
YuriGii Mar 16, 2021
c544bae
update utils.test inline inputs
ilionic Mar 16, 2021
c2e8aca
Merge remote-tracking branch 'upstream/master' into chore/jest-improv…
ilionic Mar 16, 2021
756f3db
Add code coverage for rmrk classes
ilionic Mar 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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