Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 391cc32

Browse files
authored
General fixes (#546)
- Rename `maxAsyncE2EResponseWaitTime` to `maxResponseWaitTime` - `virtualDeviceConfig` over `extraParameters`, merging props having `virtualDeviceConfig` as priority - HTML-report under timestamp output when `traceOutput` is true - Report dir name default to test_file_name if `description` is empty
1 parent 4e312c8 commit 391cc32

15 files changed

Lines changed: 180 additions & 46 deletions

docs/api/TestSuite.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/TestSuite.js.html

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/runner/Configuration.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = class Configuration {
2828
Configuration.singleton = undefined;
2929
}
3030

31-
static instance() {
31+
static instance() {
3232
return Configuration.singleton;
3333
}
3434

@@ -143,12 +143,12 @@ module.exports = class Configuration {
143143
if (cliOverrides && (cliOverrides["context"] || cliOverrides["config"])) {
144144
const contextOverride = cliOverrides["context"] ||
145145
path.dirname(cliOverrides["config"]);
146-
146+
147147
let contextPath = "";
148148
if (contextOverride) {
149149
contextPath = path.isAbsolute(contextOverride) ? contextOverride : path.join(process.cwd(), contextOverride);
150-
}
151-
150+
}
151+
152152
if (contextPath) {
153153
jestConfig.roots = [contextPath];
154154
}
@@ -188,7 +188,7 @@ module.exports = class Configuration {
188188
return path.dirname(this.configurationJSON.configurationPath);
189189
}
190190

191-
htmlReporterConfiguration () {
191+
htmlReporterConfiguration() {
192192
let pathToModule = path.join(__dirname, "../../node_modules/bespoken-jest-stare");
193193
// If we do not find jest-stare in this directory, means this module (skill-testing-ml) is a dependency
194194
// In that case, we keep going up to the node_modules that contains skill-testing-ml - jest-stare will be at that same level
@@ -267,10 +267,17 @@ module.exports = class Configuration {
267267
}
268268

269269
resultsDirectory() {
270-
const testResultsDir = path.join(process.cwd(), "test_output");
270+
let testResultsDir = path.join(process.cwd(), "test_output");
271+
const testTimestamp = this.value("runTimestamp", undefined, undefined);
272+
273+
if (this.value("traceOutput", undefined, false) && testTimestamp) {
274+
testResultsDir = path.resolve(`./test_output/trace_output/${Util.formatTimeStamp(testTimestamp)}`);
275+
}
276+
271277
if (!fs.existsSync(testResultsDir)) {
272-
fs.mkdirSync(testResultsDir);
278+
fs.mkdirSync(testResultsDir, { recursive: true });
273279
}
280+
274281
return testResultsDir;
275282
}
276283

lib/runner/ConfigurationKeys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const ConfigurationKeys = [
8080
text: "don't run the indicated tags",
8181
},
8282
{
83-
key: "maxAsyncE2EResponseWaitTime",
83+
key: "maxResponseWaitTime",
8484
text: "set the max time we wait for a single response in a e2e async interaction in ms, defaults to 15000",
8585
},
8686
{

lib/runner/TraceOutput.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require("fs");
22
const path = require("path");
3+
const Util = require("../util/Util");
34
const { camelCase, padStart, upperFirst } = require("lodash");
45

56
const createDirectoriesForFile = (fileName) => {
@@ -15,14 +16,6 @@ const shortName = longName => longName.split(/[^a-z0-9]/ig)
1516
.map(p => upperFirst(camelCase(p)))
1617
.reduce((p, c) => p.length <= 200 ? p.concat(c) : p, "");
1718

18-
const formatTimeStamp = (milliseconds) => {
19-
const timestamp = new Date(milliseconds);
20-
const date = `${timestamp.getFullYear()}${formatTwoDigits(timestamp.getMonth() + 1)}${formatTwoDigits(timestamp.getDate())}`;
21-
const time = `${formatTwoDigits(timestamp.getHours())}${formatTwoDigits(timestamp.getMinutes())}${formatTwoDigits(timestamp.getSeconds())}`;
22-
23-
return `${date}_${time}`;
24-
};
25-
2619
const formatTwoDigits = number => padStart(number, 2, "0");
2720

2821
class TraceOutputWriter {
@@ -35,9 +28,11 @@ class TraceOutputWriter {
3528
const { description: testSuiteDescription, runTimestamp: timestamp } = testSuite;
3629
const utteranceOrder = allInteractions.findIndex(({ utterance }) => utterance === utteranceText);
3730

31+
const suite = testSuiteDescription || path.parse(testSuite.fileName).name;
32+
3833
const requestPath = testSuite.resolvePath(
39-
`./test_output/trace_output/${formatTimeStamp(timestamp)}`
40-
+ `/${shortName(testSuiteDescription)}`
34+
`./test_output/trace_output/${Util.formatTimeStamp(timestamp)}`
35+
+ `/${shortName(suite)}`
4136
+ `/${shortName(testName)}`
4237
+ `/${formatTwoDigits(utteranceOrder)}-${shortName(utteranceText)}-res.json`
4338
);
@@ -55,9 +50,11 @@ class TraceOutputWriter {
5550
const { description: testSuiteDescription, runTimestamp: timestamp } = testSuite;
5651
const { test: { description: testName } } = interaction;
5752

53+
const suite = testSuiteDescription || path.parse(testSuite.fileName).name;
54+
5855
const responsePath = testSuite.resolvePath(
59-
`./test_output/trace_output/${formatTimeStamp(timestamp)}`
60-
+ `/${shortName(testSuiteDescription)}`
56+
`./test_output/trace_output/${Util.formatTimeStamp(timestamp)}`
57+
+ `/${shortName(suite)}`
6158
+ `/${shortName(testName)}/req.json`
6259
);
6360

@@ -71,7 +68,6 @@ class TraceOutputWriter {
7168
}
7269
}
7370

74-
7571
module.exports = {
7672
traceOutput: new TraceOutputWriter(),
7773
};

lib/runner/VirtualDeviceInvoker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = class VirtualDeviceInvoker extends Invoker {
8080
}
8181
}
8282
}
83-
maxResponseWaitTime = testSuite.maxAsyncE2EResponseWaitTime;
83+
maxResponseWaitTime = testSuite.maxResponseWaitTime;
8484
waitInterval = testSuite.asyncE2EWaitInterval;
8585

8686
if (!virtualDeviceToken) {
@@ -93,7 +93,7 @@ module.exports = class VirtualDeviceInvoker extends Invoker {
9393
}
9494

9595
if (replyTimeout * 1000 > maxResponseWaitTime) {
96-
throw new FrameworkError("The replyTimeout property must be less than or equal to the maxAsyncE2EResponseWaitTime property in the " +
96+
throw new FrameworkError("The replyTimeout property must be less than or equal to the maxResponseWaitTime property in the " +
9797
"testing.json or the YML test file under the config element");
9898
}
9999

@@ -368,7 +368,7 @@ module.exports = class VirtualDeviceInvoker extends Invoker {
368368
} while (!rawVirtualDeviceResponse && !isCurrentInteractionTimeoutExceed && !isCompleted);
369369

370370
if (isCurrentInteractionTimeoutExceed && !rawVirtualDeviceResponse) {
371-
const message = "Timeout exceeded while waiting for the interaction response. Increase the maxAsyncE2EResponseWaitTime value to fix this issue. " +
371+
const message = "Timeout exceeded while waiting for the interaction response. Increase the maxResponseWaitTime value to fix this issue. " +
372372
"More info at: https://read.bespoken.io/end-to-end/guide/.";
373373
errorObject = {
374374
error_category: "system",

lib/test/TestSuite.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,29 @@ class TestSuite {
507507
}
508508

509509
/**
510+
* @alias from {maxResponseWaitTime}
511+
* @deprecated
510512
* Indicates what is the maximum time e2e test can wait for a single utterance response to come back
513+
* @todo These whole maxAsyncE2EResponseWaitTime prop will be removed in next versions
511514
* @return {number} max wait time for a single utterance
512515
*/
513516
get maxAsyncE2EResponseWaitTime() {
517+
return Configuration.instance().value("maxAsyncE2EResponseWaitTime", this.configuration, undefined);
518+
}
519+
520+
/**
521+
* Indicates what is the maximum time e2e test can wait for a single utterance response to come back
522+
* @return {number} max wait time for a single utterance
523+
*/
524+
get maxResponseWaitTime() {
514525
const defaultValue = ["phone", "twilio", "sms", "whatsapp"].includes(this.platform)
515526
? 60000
516527
: 15000;
517-
return Configuration.instance().value("maxAsyncE2EResponseWaitTime", this.configuration, defaultValue);
528+
529+
const newPropValue = Configuration.instance().value("maxResponseWaitTime", this.configuration, undefined);
530+
const oldPropValue = this.maxAsyncE2EResponseWaitTime;
531+
532+
return newPropValue || oldPropValue || defaultValue;
518533
}
519534

520535
/**
@@ -599,13 +614,13 @@ class TestSuite {
599614
}
600615

601616
/**
602-
* extra parameters for virtual device
617+
* Extra parameters for virtual device, `virtualDeviceConfig` has the preference
603618
* @return {string} extraParameters
604619
*/
605620
get extraParameters() {
606621
const extraParameters = Configuration.instance().value("extraParameters", this.configuration);
607622
const virtualDeviceConfig = Configuration.instance().value("virtualDeviceConfig", this.configuration);
608-
return virtualDeviceConfig || extraParameters;
623+
return _.assign(extraParameters, virtualDeviceConfig);
609624
}
610625

611626
/**

lib/util/Util.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const _ = require("lodash");
22
const fs = require("fs");
33
const os = require("os");
44
const path = require("path");
5+
const { padStart } = require("lodash");
56

67
module.exports = class Util {
78
static cleanString(s) {
@@ -253,4 +254,14 @@ module.exports = class Util {
253254

254255
return result;
255256
}
257+
258+
static formatTimeStamp(milliseconds) {
259+
const formatTwoDigits = number => padStart(number, 2, "0");
260+
261+
const timestamp = new Date(milliseconds);
262+
const date = `${timestamp.getFullYear()}${formatTwoDigits(timestamp.getMonth() + 1)}${formatTwoDigits(timestamp.getDate())}`;
263+
const time = `${formatTwoDigits(timestamp.getHours())}${formatTwoDigits(timestamp.getMinutes())}${formatTwoDigits(timestamp.getSeconds())}`;
264+
265+
return `${date}_${time}`;
266+
}
256267
};

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "skill-testing-ml",
3-
"version": "1.4.7",
3+
"version": "1.4.8-alpha.1",
44
"description": "Skill Testing Markup Language",
55
"main": "dist/lib/Index.js",
66
"bin": {
@@ -96,6 +96,7 @@
9696
"ask-sdk-model": "^1.0.0",
9797
"body-parser": "^1.18.3",
9898
"codecov": "^3.0.2",
99+
"debug": "^4.3.4",
99100
"eslint": "^5.16.0",
100101
"eslint-config-google": "^0.12.0",
101102
"eslint-config-standard": "^12.0.0",

0 commit comments

Comments
 (0)