Skip to content
Permalink
Browse files

[JS] Rewrite robustness-tests to TS

  • Loading branch information
Max van gen Hassend Max van gen Hassend
Max van gen Hassend authored and Max van gen Hassend committed Sep 4, 2019
1 parent 427c81e commit 4921f15409b537c964984f7df26d5ad585a7e5f3
@@ -0,0 +1,20 @@
module.exports = {
transform: {
"\\.ts$": "ts-jest"
},
testEnvironment: "node",
testRegex: "src/main/js/.*\\.spec\\.ts$",
testPathIgnorePatterns: ["/node_modules/", "node_integration"],
moduleFileExtensions: ["ts", "js", "json", "node"],
reporters: [
"default",
[
"jest-junit",
{
output: "target/test-results/ts-junit.xml"
}
]
],
modulePathIgnorePatterns: ["target"],
testRunner: "jest-circus/runner"
};
@@ -6,16 +6,15 @@
"main": "src/main/js/consumer.js",
"private": true,
"dependencies": {
"bluebird": "3.3.5",
"joynr": "file:../../javascript/libjoynr-js/src/main/js"
"joynr": "file:../../javascript/libjoynr-js/.output/src/main/js"
},
"config": {
"domain": "joynr-robustness-test-domain",
"testcase": "js_tests",
"cmdPath": "placeholder"
"testcase": "js_tests"
},
"scripts": {
"startprovider": "node src/main/js/provider.js $npm_package_config_domain",
"startjasmine": "jasmine-node --verbose --junitreport --config domain $npm_package_config_domain --config testcase $npm_package_config_testcase --config cmdPath $npm_package_config_cmdPath src/main/js/consumer.spec.js"
"build": "tsc",
"startprovider": "node .output/src/main/js/provider.js $npm_package_config_domain",
"startjest": "export domain=$npm_package_config_domain && export testcase=$npm_package_config_testcase && jest -i"
}
}
@@ -63,7 +63,7 @@
<goal>generate</goal>
</goals>
<configuration>
<model>${basedir}/src/main/model</model>
<model>${basedir}/../robustness-test-base/src/main/model</model>
<generationLanguage>javascript</generationLanguage>
<outputPath>${basedir}/src/main/generated-javascript</outputPath>
</configuration>
@@ -156,7 +156,7 @@ function start_javascript_consumer {
echo '####################################################'
cd $JOYNR_SOURCE_DIR/tests/robustness-test
rm -fr localStorageStorage
npm run-script startjasmine --robustness-test:domain=$DOMAIN --robustness-test:testcase=$TESTCASE --robustness-test:cmdPath=$JOYNR_SOURCE_DIR/tests/robustness-test > $TEST_RESULTS_DIR/consumer_javascript_$1_$(date "+%Y-%m-%d-%H:%M:%S").log 2>&1
npm run-script startjest --robustness-test:domain=$DOMAIN --robustness-test:testcase=$TESTCASE > $TEST_RESULTS_DIR/consumer_javascript_$1_$(date "+%Y-%m-%d-%H:%M:%S").log 2>&1
SUCCESS=$?

if [ "$SUCCESS" != 0 ]

This file was deleted.

@@ -0,0 +1,157 @@
/*
* #%L
* %%
* Copyright (C) 2019 BMW Car IT GmbH
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

import { ProviderReadWriteAttributeImpl } from "joynr/joynr/types/JoynrProvider";
import * as MySubscriptionContainer from "../generated-javascript/joynr/tests/robustness/MySubscriptionContainer";
import { TestInterfaceProviderImplementation } from "../generated-javascript/joynr/tests/robustness/TestInterfaceProvider";
import { prettyLog } from "./logging";
import joynr = require("joynr");

// Attributes
let attributeStringValue = "done";
let intervalTimer: NodeJS.Timer | undefined;

function sendBroadcast(): void {
const stringOut = "boom";
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion,@typescript-eslint/no-use-before-define
const outputParameters = implementation.broadcastWithSingleStringParameter!.createBroadcastOutputParameters();
outputParameters.setStringOut(stringOut);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion,@typescript-eslint/no-use-before-define
implementation.broadcastWithSingleStringParameter!.fire(outputParameters);
}

function createGenericAttributeImpl<T>(): ProviderReadWriteAttributeImpl<T> {
let store: T;
return {
get: () => store,
set: (value: T) => {
store = value;
}
};
}

export const implementation: TestInterfaceProviderImplementation = {
// attribute getter and setter
attributeString: {
get() {
prettyLog("RobustnessProvider.attributeString.get() called");
return Promise.resolve(attributeStringValue);
},
set(value: string) {
prettyLog(`RobustnessProvider.attributeString.set(${value}) called`);
attributeStringValue = value;
return Promise.resolve();
}
},

methodWithStringParameters(opArgs) {
prettyLog(`RobustnessProvider.methodWithStringParameters(${JSON.stringify(opArgs)}) called`);
// eslint-disable-next-line promise/avoid-new
return new Promise((resolve, reject) => {
if (opArgs.stringArg === undefined || opArgs.stringArg === null) {
reject(
new joynr.exceptions.ProviderRuntimeException({
detailMessage: "methodWithStringParameters: invalid argument stringArg"
})
);
} else {
resolve({
stringOut: `received stringArg: ${opArgs.stringArg}`
});
}
});
},

methodWithDelayedResponse(opArgs) {
prettyLog(`RobustnessProvider.methodWithDelayedResponse(${JSON.stringify(opArgs)}) called`);
// eslint-disable-next-line promise/avoid-new
return new Promise((resolve, reject) => {
if (opArgs.delayArg === undefined) {
reject(
new joynr.exceptions.ProviderRuntimeException({
detailMessage: "methodWithDelayedResponse: invalid argument delayArg"
})
);
} else {
// do the delay here
setTimeout(() => {
resolve({
stringOut: "done"
});
}, opArgs.delayArg);
}
});
},

async methodToFireBroadcastWithSingleStringParameter() {
prettyLog("RobustnessProvider.methodToFireBroadcastWithSingleStringParameter() called");
sendBroadcast();
},

startFireBroadcastWithSingleStringParameter() {
prettyLog("RobustnessProvider.startFireBroadcastWithSingleStringParameter() called");
if (intervalTimer) {
clearTimeout(intervalTimer);
intervalTimer = undefined;
}
let numberOfBroadcasts = 0;
const periodMs = 250;
const validityMs = 60000;
intervalTimer = setInterval(() => {
sendBroadcast();
numberOfBroadcasts++;
if (numberOfBroadcasts === validityMs / periodMs) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
clearInterval(intervalTimer!);
}
}, periodMs);
if (intervalTimer) {
// intervalTimer successfully started
return Promise.resolve();
} else {
return Promise.reject(
new joynr.exceptions.ProviderRuntimeException({
detailMessage: "startFireBroadcastWithSingleStringParameter: intervalTimer could not be started"
})
);
}
},

stopFireBroadcastWithSingleStringParameter() {
prettyLog("RobustnessProvider.stopFireBroadcastWithSingleStringParameter() called");
if (intervalTimer) {
clearInterval(intervalTimer);
intervalTimer = undefined;
return Promise.resolve();
} else {
return Promise.reject(
new joynr.exceptions.ProviderRuntimeException({
detailMessage: "stopFireBroadcastWithSingleStringParameter: no intervalTimer running"
})
);
}
},
// dummy implementation below
attributeString1: createGenericAttributeImpl<string>(),
attributeString2: createGenericAttributeImpl<string>(),
methodWithStringParameters1: () => ({ stringOut: "string" }),
methodWithStringParameters2: () => ({ stringOut: "string" }),
ping: () => {},
subContainer: createGenericAttributeImpl<MySubscriptionContainer>()
};

0 comments on commit 4921f15

Please sign in to comment.
You can’t perform that action at this time.