Skip to content

Commit

Permalink
chore: fix typescript in test
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Jun 3, 2023
1 parent a484a02 commit 511af5f
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,9 @@ export function _bindExtensionObjectArrayOrMatrix(
const addressSpace = uaVariable.addressSpace;
if (optionalExtensionObjectArray) {
if (optionalExtensionObjectArray.length !== totalLength) {
throw new Error(`optionalExtensionObjectArray must have the expected number of element matching ${arrayDimensions}`)
throw new Error(
`optionalExtensionObjectArray must have the expected number of element matching ${arrayDimensions} but was ${optionalExtensionObjectArray.length}`
);
}
}
if (!optionalExtensionObjectArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const OneDayDuration = 1000 * 60 * 60 * 24;
export const TwoWeeksDuration = OneDayDuration * 2 * 7;

const describe = require("node-opcua-leak-detector").describeWithLeakDetector;
describe("Test Certificate alarm", function () {
describe("Test Certificate alarm", function (this: Mocha.Suite) {
let clock: sinon.SinonFakeTimers | undefined;
beforeEach(() => {
clock = sinon.useFakeTimers({ now: Date.now(), shouldAdvanceTime: true, shouldClearNativeTimers: true } as any);
Expand All @@ -24,7 +24,6 @@ describe("Test Certificate alarm", function () {
});

// eslint-disable-next-line @typescript-eslint/no-this-alias
const test = this;
let addressSpace: AddressSpace;
this.timeout(Math.max(this.timeout(), 100000));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function utest_issue_316(test: any): void {
// instances. If a ConditionSource has only one instance of a ConditionType, and the Server has
// no instance name, the Server shall supply the ConditionType browse name.
condition.conditionName.readValue().value.dataType.should.eql(DataType.String);
condition.conditionName.readValue().value.value.should.eql("MyConditionName");
condition.conditionName.readValue().value.value!.should.eql("MyConditionName");
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function utest_off_normal_alarm(test: any): void {

normalStateNode.setValueFromSource({ dataType: "UInt32", value: green });
normalStateNode.getValue().should.eql(2);
alarm.getNormalStateValue().should.eql(2);
alarm.getNormalStateValue()!.should.eql(2);
alarm.activeState.getValue().should.eql(true);
spyOnEvent.callCount.should.eql(1);

Expand Down Expand Up @@ -129,19 +129,19 @@ export function utest_off_normal_alarm(test: any): void {
// changing the normalStateNode Value shall also automatically update the alarm
normalStateNode.setValue("Orange");
normalStateNode.getValue().should.eql(1);
alarm.getNormalStateValue().should.eql(1);
alarm.getNormalStateValue()!.should.eql(1);

alarm.activeState.getValue().should.eql(true);

normalStateNode.setValue("Green");
normalStateNode.getValue().should.eql(2);
alarm.getNormalStateValue().should.eql(2);
alarm.getNormalStateValue()!.should.eql(2);

alarm.activeState.getValue().should.eql(false);

normalStateNode.setValue("Red");
normalStateNode.getValue().should.eql(0);
alarm.getNormalStateValue().should.eql(0);
alarm.getNormalStateValue()!.should.eql(0);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("Testing Historical Data Node", () => {

const indexRange = null;
const dataEncoding = null;
const continuationPoint: ContinuationPoint | undefined = undefined;
const continuationPoint: ContinuationPoint | null = null;

const historyReadResult = await node.historyRead(context, historyReadDetails, indexRange, dataEncoding, {
continuationPoint
Expand Down Expand Up @@ -130,7 +130,7 @@ describe("Testing Historical Data Node", () => {
});
const indexRange = null;
const dataEncoding = null;
const continuationPoint: ContinuationPoint | undefined = undefined;
const continuationPoint: ContinuationPoint | null = null;

node.setValueFromSource({ dataType: "Double", value: 3.14 });

Expand Down Expand Up @@ -264,7 +264,7 @@ describe("Testing Historical Data Node", () => {
});
const indexRange = null;
const dataEncoding = null;
const continuationPoint: ContinuationPoint | undefined = undefined;
const continuationPoint: ContinuationPoint | null = null;

const historyReadResult = await node.historyRead(context, historyReadDetails, indexRange, dataEncoding, {
continuationPoint
Expand Down Expand Up @@ -363,7 +363,7 @@ describe("Testing Historical Data Node", () => {
});
const indexRange = null;
const dataEncoding = null;
const continuationPoint: ContinuationPoint | undefined = undefined;
const continuationPoint: ContinuationPoint | null = null;

const historyReadResult = await node.historyRead(context, historyReadDetails, indexRange, dataEncoding, {
continuationPoint
Expand All @@ -386,7 +386,7 @@ describe("Testing Historical Data Node", () => {
});
const indexRange = null;
const dataEncoding = null;
const continuationPoint: ContinuationPoint | undefined = undefined;
const continuationPoint: ContinuationPoint | null = null;

const historyReadResult = await node.historyRead(context, historyReadDetails, indexRange, dataEncoding, {
continuationPoint
Expand Down Expand Up @@ -483,7 +483,7 @@ describe("Testing Historical Data Node", () => {
});
const indexRange = null;
const dataEncoding = null;
const continuationPoint: ContinuationPoint | undefined = undefined;
const continuationPoint: ContinuationPoint | null = null;

const historyReadResult1 = await node.historyRead(context, historyReadDetails, indexRange, dataEncoding, {
continuationPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("Testing Historical Data Node", () => {
});
const indexRange = null;
const dataEncoding = null;
const continuationPoint: ContinuationPoint | undefined = undefined;
const continuationPoint: ContinuationPoint | null = null;

node.setValueFromSource(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
v.userAccessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
v.userAccessLevel!.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
});

it("accessLevel: CurrentRead | CurrentWrite\tuserAccessLevel: CurrentRead", () => {
Expand All @@ -45,7 +45,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentRead);
v.userAccessLevel.should.eql(AccessLevelFlag.CurrentRead);
v.userAccessLevel!.should.eql(AccessLevelFlag.CurrentRead);
});

it("accessLevel: CurrentRead | CurrentWrite\tuserAccessLevel: CurrentWrite", () => {
Expand All @@ -59,7 +59,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
v.userAccessLevel.should.eql(AccessLevelFlag.CurrentWrite);
v.userAccessLevel!.should.eql(AccessLevelFlag.CurrentWrite);
});

it("accessLevel: CurrentRead | CurrentWrite\tuserAccessLevel: undefined", () => {
Expand Down Expand Up @@ -87,7 +87,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentRead);
v.userAccessLevel.should.eql(AccessLevelFlag.CurrentRead);
v.userAccessLevel!.should.eql(AccessLevelFlag.CurrentRead);
});

it("accessLevel: CurrentRead \tuserAccessLevel: CurrentRead", () => {
Expand All @@ -101,7 +101,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentRead);
v.userAccessLevel.should.eql(AccessLevelFlag.CurrentRead);
v.userAccessLevel!.should.eql(AccessLevelFlag.CurrentRead);
});

it("accessLevel: CurrentRead \tuserAccessLevel: CurrentWrite", () => {
Expand All @@ -115,7 +115,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentRead);
v.userAccessLevel.should.eql(AccessLevelFlag.NONE);
v.userAccessLevel!.should.eql(AccessLevelFlag.NONE);
});

it("accessLevel: CurrentRead \tuserAccessLevel: undefined", () => {
Expand Down Expand Up @@ -143,7 +143,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentWrite);
v.userAccessLevel.should.eql(AccessLevelFlag.CurrentWrite);
v.userAccessLevel!.should.eql(AccessLevelFlag.CurrentWrite);
});

it("accessLevel: CurrentWrite \tuserAccessLevel: CurrentRead", () => {
Expand All @@ -157,7 +157,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentWrite);
v.userAccessLevel.should.eql(AccessLevelFlag.NONE);
v.userAccessLevel!.should.eql(AccessLevelFlag.NONE);
});

it("accessLevel: CurrentWrite \tuserAccessLevel: CurrentWrite", () => {
Expand All @@ -171,7 +171,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentWrite);
v.userAccessLevel.should.eql(AccessLevelFlag.CurrentWrite);
v.userAccessLevel!.should.eql(AccessLevelFlag.CurrentWrite);
});

it("accessLevel: CurrentWrite \tuserAccessLevel: undefined", () => {
Expand All @@ -198,7 +198,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
v.userAccessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
v.userAccessLevel!.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
});

it("accessLevel: undefined \tuserAccessLevel: CurrentRead", () => {
Expand All @@ -211,7 +211,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
v.userAccessLevel.should.eql(AccessLevelFlag.CurrentRead);
v.userAccessLevel!.should.eql(AccessLevelFlag.CurrentRead);
});

it("accessLevel: undefined \tuserAccessLevel: CurrentWrite", () => {
Expand All @@ -224,7 +224,7 @@ describe("testing Variables ", () => {
});

v.accessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
v.userAccessLevel.should.eql(AccessLevelFlag.CurrentWrite);
v.userAccessLevel!.should.eql(AccessLevelFlag.CurrentWrite);
});

it("accessLevel: undefined \tuserAccessLevel: undefined", () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/node-opcua-address-space/test/test_add_in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ describe("AddIns", () => {
if (nsMachineTool === -1) throw new Error("namespace not found");

const machineToolType = addressSpace.findObjectType("MachineToolType", nsMachineTool);
if (!machineToolType) throw new Error("MachineToolType not found");

const machines = addressSpace.rootFolder.objects.getFolderElementByName("Machines", nsMachinery);
if (!machines) throw new Error("Machines not found");

const machineTool = machineToolType.instantiate({
browseName: "MachineTool",
organizedBy: addressSpace.rootFolder.objects.getFolderElementByName("Machines", nsMachineTool),
organizedBy: machines,
optionals: [
"Identification.DeviceClass",
"Identification.SoftwareIdentification",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("AddressSpace#deleteNode-b", () => {
// normalState: normalStateNode,
optionals: ["ConfirmedState", "Confirm"]
};
const alarmNode = namespace.instantiateAlarmCondition(alarmType, options, null);
const alarmNode = namespace.instantiateAlarmCondition(alarmType, options, undefined);

alarmNode.conditionName.setValueFromSource({
dataType: DataType.String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ describe("Async Callback Straight functors", () => {
async function test(func: MultiformFunc<Output, Stuff>) {
const convertedFunc = convertToCallbackFunction(func);
const result = await new Promise<Output>((resolve, reject) => {
convertedFunc.call(stuff, (err, result) => (err ? reject(err) : resolve(result)));
convertedFunc.call(stuff, (err, result) => (err ? reject(err) : resolve(result!)));
});
return result;
}

async function testFailing(func: MultiformFunc<Output, Stuff>) {
let _err: Error;
let _err: Error | undefined;
try {
const result = await test(func);
} catch (err) {
_err = err as Error;
}
should.exist(_err);
_err.message.should.eql("this is failing");
_err!.message.should.eql("this is failing");
}

it("should work with a straight function", async () => {
Expand Down Expand Up @@ -122,20 +122,20 @@ describe("Async Callback Straight functors with one arguments", () => {
async function test(func: MultiformFunc1<Output, string, Stuff>) {
const convertedFunc = convertToCallbackFunction1(func);
const result = await new Promise<Output>((resolve, reject) => {
convertedFunc.call(stuff, param, (err, result) => (err ? reject(err) : resolve(result)));
convertedFunc.call(stuff, param, (err, result) => (err ? reject(err) : resolve(result!)));
});
return result;
}

async function testFailing(func: MultiformFunc1<Output, string, Stuff>) {
let _err: Error;
let _err: Error | undefined;
try {
const result = await test(func);
} catch (err) {
_err = err as Error;
}
should.exist(_err);
_err.message.should.eql("this is failing");
_err!.message.should.eql("this is failing");
}

it("should work with a straight function", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-address-space/test/test_boiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe("Testing Boiler System", () => {

// when state is "Halted" , the Halt method is not executable
boilerStateMachine.setState(haltedState);
boilerStateMachine.currentStateNode.browseName.toString().should.eql("Halted");
boilerStateMachine.currentStateNode!.browseName.toString().should.eql("Halted");

const haltMethod = boilerStateMachine.getMethodByName("Halt")!;
// halt method should not be executable when current State is Halted
Expand Down

0 comments on commit 511af5f

Please sign in to comment.