Initial change from Babel/JS to TypeScript (#70)

* will compile as typescript

* migrated test suite to use JestJS

* Migrated to Jest testing framework and typescript source files

* updated deps

* updated prepublish

* resolved 1 failing test

* changed decimal .0 on four tests, it appears that these were the only four tests expecting integer values to have '.0'

* added linter

* added package-lock

* removed tslint in favor of eslint

* changed yarn to npm

* updated version 2.6->3.0

* removing package lock

* updated node version in nvmrc and jest version in package

* removed nvmrc

* removed some unused functions

* replaced data driven with file from master

* commitint yarn.lock

* removing babel as a dependency in favor of typescript compiling to es5

* removing babel deps

* resolved testing issues by migrating helper function

* added partial linting functionality for test suite

* updated imports for decodeLedgerData

* updated test

* updated yarn.lock

* removed a console.log

* added eslint-jest-plugin to package

* reverting to old linting, will add linting in next PR

* removed comments in shamap

* re-adding .nvmrc

* npm -> yarn

* added . to .eslintrc

* added .eslintrc

* removing linting for this PR

* Changed linting to print a message so that linting doesnt fail in CI

* changing back

* added newline so diff wont show

* removed eslint deps, since linting will be dealt with in a later PR

* changed function calls to describe(...)
This commit is contained in:
Nathan Nichols
2020-06-24 09:00:28 -07:00
parent 16b1b91a76
commit a930b9413c
91 changed files with 5058 additions and 5142 deletions

View File

@@ -1,83 +1,24 @@
const intercept = require('intercept-stdout');
const fs = require('fs');
const fsExtra = require('fs-extra');
const assert = require('assert');
const Decimal = require('decimal.js');
const {parseBytes} = require('../src/utils/bytes-utils');
const fs = require('fs')
const { parseBytes } = require('../dist/utils/bytes-utils')
function hexOnly(hex) {
return hex.replace(/[^a-fA-F0-9]/g, '');
function hexOnly (hex) {
return hex.replace(/[^a-fA-F0-9]/g, '')
}
function unused() {}
function unused () {}
function captureLogsAsync() {
let log = '';
const unhook = intercept(txt => {
log += txt;
return '';
});
return function() {
unhook();
return log;
};
function parseHexOnly (hex, to) {
return parseBytes(hexOnly(hex), to)
}
function captureLogs(func) {
const finished = captureLogsAsync();
try {
func();
} catch (e) {
const log = finished();
console.error(log);
throw e;
}
return finished();
function loadFixture (relativePath) {
const fn = __dirname + '/fixtures/' + relativePath
return require(fn)
}
function parseHexOnly(hex, to) {
return parseBytes(hexOnly(hex), to);
}
function loadFixture(relativePath) {
const fn = __dirname + '/fixtures/' + relativePath;
return require(fn);
}
function isBufferOrString(val) {
return Buffer.isBuffer(val) || (typeof val === 'string');
}
function loadFixtureText(relativePath) {
const fn = __dirname + '/fixtures/' + relativePath;
return fs.readFileSync(fn).toString('utf8');
}
function fixturePath(relativePath) {
return __dirname + '/fixtures/' + relativePath;
}
function prettyJSON(val) {
return JSON.stringify(val, null, 2);
}
function writeFixture(relativePath, data) {
const out = isBufferOrString(data) ? data : prettyJSON(data);
return fsExtra.outputFileSync(fixturePath(relativePath), out);
}
function assertEqualAmountJSON(actual, expected) {
const typeA = (typeof actual);
assert(typeA === (typeof expected));
if (typeA === 'string') {
assert.equal(actual, expected);
return;
}
assert.equal(actual.currency, expected.currency);
assert.equal(actual.issuer, expected.issuer);
assert(actual.value === expected.value ||
new Decimal(actual.value).equals(
new Decimal(expected.value)));
function loadFixtureText (relativePath) {
const fn = __dirname + '/fixtures/' + relativePath
return fs.readFileSync(fn).toString('utf8')
}
module.exports = {
@@ -85,9 +26,5 @@ module.exports = {
parseHexOnly,
loadFixture,
loadFixtureText,
assertEqualAmountJSON,
writeFixture,
unused,
captureLogs,
captureLogsAsync
};
unused
}