mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-28 14:34:48 +00:00
3693ebd90d
Many packages in the monorepo did not specify all of their dependencies; they were effectively relying on resolution in the monorepo's root `node_modules`. In a production release of `embark` and `embark[js]-*` packages this can lead to broken packages. To fix the problem currently and to help prevent it from happening again, make use of the `eslint-plugin-import` package's `import/no-extraneous-dependencies` and `import/no-unresolved` rules. In the root `tslint.json` set `"no-implicit-dependencies": true`, wich is the tslint equivalent of `import/no-extraneous-dependencies`; there is no tslint equivalent for `import/no-unresolved`, but we will eventually replace tslint with an eslint configuration that checks both `.js` and `.ts` files. For `import/no-unresolved` to work in our monorepo setup, in most packages add an `index.js` that has: ```js module.exports = require('./dist'); // or './dist/lib' in some cases ``` And point `"main"` in `package.json` to `"./index.js"`. Despite what's indicated in npm's documentation for `package.json`, it's also necessary to add `"index.js"` to the `"files"` array. Make sure that all `.js` files that can and should be linted are in fact linted. For example, files in `packages/embark/src/cmd/` weren't being linted and many test suites weren't being linted. Bump all relevant packages to `eslint@6.8.0`. Fix all linter errors that arose after these changes. Implement a `check-yarn-lock` script that's run as part of `"ci:full"` and `"qa:full"`, and can manually be invoked via `yarn cylock` in the root of the monorepo. The script exits with error if any specifiers are found in `yarn.lock` for `embark[js][-*]` and/or `@embarklabs/*` (with a few exceptions, cf. `scripts/check-yarn-lock.js`).
76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
const ENS = require("../src/index");
|
|
const { fakeEmbark } = require('embark-testing');
|
|
const {Utils} = require('embarkjs');
|
|
const secureSend = Utils.secureSend;
|
|
|
|
describe('embark-ens', () => {
|
|
let ens;
|
|
|
|
const { embark } = fakeEmbark();
|
|
|
|
|
|
beforeEach(() => {
|
|
embark.events.setCommandHandler('namesystem:node:register', () => {});
|
|
embark.config.blockchainConfig = { enabled: true };
|
|
ens = new ENS(embark);
|
|
ens.config = {
|
|
embarkConfig: {
|
|
generationDir: 'test-dir'
|
|
},
|
|
namesystemConfig: {
|
|
register: {
|
|
rootDomain: 'root.eth'
|
|
},
|
|
dappConnection: []
|
|
},
|
|
contractsConfig: {dappAutoEnable: true}
|
|
};
|
|
});
|
|
|
|
afterEach(() => {
|
|
embark.teardown();
|
|
});
|
|
|
|
it("should register the right artifact", (done) => {
|
|
const pipelineRegisterHandler = jest.fn(async (args, cb) => {
|
|
ens.getEnsConfig((err, config) => {
|
|
expect(args).toEqual({
|
|
path: ['test-dir', 'config'],
|
|
file: 'namesystem.json',
|
|
format: 'json',
|
|
dappAutoEnable: true,
|
|
content: Object.assign({}, embark.config.namesystemConfig, config)
|
|
});
|
|
cb();
|
|
done();
|
|
});
|
|
});
|
|
|
|
embark.events.setCommandHandler('pipeline:register', pipelineRegisterHandler);
|
|
|
|
ens.addArtifactFile({}, () => {});
|
|
});
|
|
|
|
describe('safeRegisterSubDomain', () => {
|
|
it('should register if the name is not registered', (done) => {
|
|
ens.ensResolve = jest.fn((name, cb) => { cb(null, null); });
|
|
ens.registerSubDomain = jest.fn((defaultAccount, subDomainName, reverseNode, address, secureSend, callback) => callback());
|
|
|
|
ens.safeRegisterSubDomain('test.eth', '0x0123', '0x4321', () => {
|
|
expect(ens.registerSubDomain).toHaveBeenCalledWith('0x4321', 'test.eth', '0xd523d7aaff8eefa323a17f2c79662ff1a8d952f6fa9cf53986347e99ada8098c', '0x0123', secureSend, expect.any(Function));
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should not register if the name is already registered', (done) => {
|
|
ens.ensResolve = jest.fn((name, cb) => { cb(null, '0x0123'); });
|
|
ens.registerSubDomain = jest.fn((defaultAccount, subDomainName, reverseNode, address, secureSend, callback) => callback());
|
|
|
|
ens.safeRegisterSubDomain('test.eth', '0x0123', '0x4321', () => {
|
|
expect(ens.registerSubDomain).not.toHaveBeenCalled();
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
});
|