Add resolver for jest (#519)

This commit is contained in:
Jaco Greeff
2020-02-06 14:49:55 +01:00
committed by GitHub
parent e4de3a1339
commit bf5ba0f405
5 changed files with 25 additions and 17 deletions
+4
View File
@@ -1,3 +1,7 @@
# 2.2.0-beta.x
- Add resolved for jest requires (tests from src)
# 2.1.1
- Update `detectPackage(<package.json>, __dirname?)` with calling folder
+2 -1
View File
@@ -17,5 +17,6 @@ module.exports = Object.assign({}, config, {
'<rootDir>/packages/util/build',
'<rootDir>/packages/util-crypto/build',
'<rootDir>/packages/util-rlp/build'
]
],
resolver: './jest.resolver.js'
});
+15
View File
@@ -0,0 +1,15 @@
// Copyright 2017-2020 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
module.exports = function resolver (file, config) {
if (file.includes('package.json')) {
console.error(file, config);
return path.join(config.basedir.replace('/src', '/'), file);
}
return config.defaultResolver(file, config);
};
-3
View File
@@ -26,9 +26,6 @@
"url": "https://github.com/polkadot-js/common/issues"
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
"browser": {
"../package.json": "./package.json"
},
"dependencies": {
"@babel/runtime": "^7.8.3",
"@polkadot/util": "^2.1.1",
+4 -13
View File
@@ -7,23 +7,14 @@ import { decodeAddress, encodeAddress, setSS58Format } from '@polkadot/util-cryp
import Keyring from './keyring';
let dirname;
let pkgJson;
// eslint-disable-next-line no-useless-catch
try {
dirname = __dirname;
// eslint-disable-next-line @typescript-eslint/no-var-requires
detectPackage(require('./package.json'), __dirname);
} catch (error) {
// ignore
throw error;
}
try {
pkgJson = require('./package.json');
} catch (error) {
pkgJson = require('../package.json');
}
detectPackage(pkgJson, dirname);
export default Keyring;
export {