Merge pull request #1368 from balena-io/test-file-ts-adjustments

Refactored @ts-ignore to @ts-expect-error in test file
This commit is contained in:
bulldozer-balena[bot] 2020-06-08 18:12:15 +00:00 committed by GitHub
commit 89055a800b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 21 deletions

View File

@ -23,10 +23,11 @@ const initModels = async (obj: Dictionary<any>, filename: string) => {
await prepare(); await prepare();
config.removeAllListeners(); config.removeAllListeners();
// @ts-ignore // @ts-expect-error setting read-only property
config.configJsonBackend = new ConfigJsonConfigBackend(schema, filename); config.configJsonBackend = new ConfigJsonConfigBackend(schema, filename);
config.generateRequiredFields(); config.generateRequiredFields();
(config.configJsonBackend as any).cache = await (config.configJsonBackend as any).read(); // @ts-expect-error using private properties
config.configJsonBackend.cache = await config.configJsonBackend.read();
await config.generateRequiredFields(); await config.generateRequiredFields();
obj.logger = { obj.logger = {
@ -71,7 +72,7 @@ describe('ApiBinder', () => {
}); });
after(() => { after(() => {
// @ts-ignore // @ts-expect-error setting read-only property
balenaAPI.balenaBackend!.registerHandler.restore(); balenaAPI.balenaBackend!.registerHandler.restore();
try { try {
server.close(); server.close();
@ -88,19 +89,18 @@ describe('ApiBinder', () => {
}); });
after(async () => { after(async () => {
// @ts-ignore // @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend; config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields(); await config.generateRequiredFields();
}); });
it('provisions a device', () => { it('provisions a device', () => {
// @ts-ignore
const promise = components.apiBinder.provisionDevice(); const promise = components.apiBinder.provisionDevice();
return expect(promise).to.be.fulfilled.then(() => { return expect(promise).to.be.fulfilled.then(() => {
expect(balenaAPI.balenaBackend!.registerHandler).to.be.calledOnce; expect(balenaAPI.balenaBackend!.registerHandler).to.be.calledOnce;
// @ts-ignore // @ts-expect-error function does not exist on type
balenaAPI.balenaBackend!.registerHandler.resetHistory(); balenaAPI.balenaBackend!.registerHandler.resetHistory();
expect(eventTracker.track).to.be.calledWith('Device bootstrap success'); expect(eventTracker.track).to.be.calledWith('Device bootstrap success');
}); });
@ -169,7 +169,7 @@ describe('ApiBinder', () => {
return initModels(components, '/config-apibinder.json'); return initModels(components, '/config-apibinder.json');
}); });
after(async () => { after(async () => {
// @ts-ignore // @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend; config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields(); await config.generateRequiredFields();
}); });
@ -200,7 +200,7 @@ describe('ApiBinder', () => {
return initModels(components, '/config-apibinder.json'); return initModels(components, '/config-apibinder.json');
}); });
after(async () => { after(async () => {
// @ts-ignore // @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend; config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields(); await config.generateRequiredFields();
}); });
@ -211,7 +211,6 @@ describe('ApiBinder', () => {
const fetchDeviceStub = stub(components.apiBinder, 'fetchDevice'); const fetchDeviceStub = stub(components.apiBinder, 'fetchDevice');
fetchDeviceStub.onCall(0).resolves({ id: 1 }); fetchDeviceStub.onCall(0).resolves({ id: 1 });
// @ts-ignore
const device = await components.apiBinder.exchangeKeyAndGetDevice( const device = await components.apiBinder.exchangeKeyAndGetDevice(
mockProvisioningOpts, mockProvisioningOpts,
); );
@ -220,9 +219,8 @@ describe('ApiBinder', () => {
expect(device).to.deep.equal({ id: 1 }); expect(device).to.deep.equal({ id: 1 });
expect(components.apiBinder.fetchDevice).to.be.calledOnce; expect(components.apiBinder.fetchDevice).to.be.calledOnce;
// @ts-ignore
components.apiBinder.fetchDevice.restore(); components.apiBinder.fetchDevice.restore();
// @ts-ignore // @ts-expect-error function does not exist on type
balenaAPI.balenaBackend.deviceKeyHandler.restore(); balenaAPI.balenaBackend.deviceKeyHandler.restore();
}); });
@ -230,7 +228,6 @@ describe('ApiBinder', () => {
spy(balenaAPI.balenaBackend!, 'deviceKeyHandler'); spy(balenaAPI.balenaBackend!, 'deviceKeyHandler');
stub(components.apiBinder, 'fetchDevice').returns(Promise.resolve(null)); stub(components.apiBinder, 'fetchDevice').returns(Promise.resolve(null));
// @ts-ignore
const promise = components.apiBinder.exchangeKeyAndGetDevice( const promise = components.apiBinder.exchangeKeyAndGetDevice(
mockProvisioningOpts, mockProvisioningOpts,
); );
@ -241,9 +238,8 @@ describe('ApiBinder', () => {
return expect(promise).to.be.rejected.then(() => { return expect(promise).to.be.rejected.then(() => {
expect(balenaAPI.balenaBackend!.deviceKeyHandler).to.not.be.called; expect(balenaAPI.balenaBackend!.deviceKeyHandler).to.not.be.called;
expect(components.apiBinder.fetchDevice).to.be.calledTwice; expect(components.apiBinder.fetchDevice).to.be.calledTwice;
// @ts-ignore
components.apiBinder.fetchDevice.restore(); components.apiBinder.fetchDevice.restore();
// @ts-ignore // @ts-expect-error function does not exist on type
balenaAPI.balenaBackend.deviceKeyHandler.restore(); balenaAPI.balenaBackend.deviceKeyHandler.restore();
}); });
}); });
@ -254,16 +250,14 @@ describe('ApiBinder', () => {
fetchDeviceStub.onCall(0).returns(Promise.resolve(null)); fetchDeviceStub.onCall(0).returns(Promise.resolve(null));
fetchDeviceStub.onCall(1).returns(Promise.resolve({ id: 1 })); fetchDeviceStub.onCall(1).returns(Promise.resolve({ id: 1 }));
// @ts-ignore
const device = await components.apiBinder.exchangeKeyAndGetDevice( const device = await components.apiBinder.exchangeKeyAndGetDevice(
mockProvisioningOpts as any, mockProvisioningOpts as any,
); );
expect(balenaAPI.balenaBackend!.deviceKeyHandler).to.be.calledOnce; expect(balenaAPI.balenaBackend!.deviceKeyHandler).to.be.calledOnce;
expect(device).to.deep.equal({ id: 1 }); expect(device).to.deep.equal({ id: 1 });
expect(components.apiBinder.fetchDevice).to.be.calledTwice; expect(components.apiBinder.fetchDevice).to.be.calledTwice;
// @ts-ignore
components.apiBinder.fetchDevice.restore(); components.apiBinder.fetchDevice.restore();
// @ts-ignore // @ts-expect-error function does not exist on type
balenaAPI.balenaBackend.deviceKeyHandler.restore(); balenaAPI.balenaBackend.deviceKeyHandler.restore();
}); });
}); });
@ -274,7 +268,7 @@ describe('ApiBinder', () => {
return initModels(components, '/config-apibinder-offline.json'); return initModels(components, '/config-apibinder-offline.json');
}); });
after(async () => { after(async () => {
// @ts-ignore // @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend; config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields(); await config.generateRequiredFields();
}); });
@ -313,7 +307,7 @@ describe('ApiBinder', () => {
}); });
after(async () => { after(async () => {
// @ts-ignore // @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend; config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields(); await config.generateRequiredFields();
}); });
@ -362,7 +356,7 @@ describe('ApiBinder', () => {
}); });
after(async () => { after(async () => {
// @ts-ignore // @ts-expect-error setting read-only property
config.configJsonBackend = defaultConfigBackend; config.configJsonBackend = defaultConfigBackend;
await config.generateRequiredFields(); await config.generateRequiredFields();
}); });

View File

@ -18,7 +18,7 @@ describe('Logger', function () {
this._req.end = sinon.spy(); this._req.end = sinon.spy();
this._req.body = ''; this._req.body = '';
this._req.pipe(zlib.createGunzip()).on('data', (chunk: any) => { this._req.pipe(zlib.createGunzip()).on('data', (chunk: Buffer) => {
this._req.body += chunk; this._req.body += chunk;
}); });