diff --git a/src-test/callFunctionInTest.ts b/src-test/callFunctionInTest.ts index b33aaf4..845bbc7 100644 --- a/src-test/callFunctionInTest.ts +++ b/src-test/callFunctionInTest.ts @@ -5,8 +5,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -export function callFunctionInTest(functionName: string, ...params: unknown[]) { +export function callFunctionInTest(functionName: string, testName: string, ...params: unknown[]) { try { + console.log(`calling ${functionName} in test "${testName}"`); + // there is no global object (like window) in apps script, so this is how we get a global function by name const fn = eval(functionName); const result = fn(...params); diff --git a/src/api.ts b/src/api.ts index 01dafca..ab8fa94 100644 --- a/src/api.ts +++ b/src/api.ts @@ -258,7 +258,7 @@ export function fetchAll(requests: MatomoRequestParams[], options: ApiFetchOptio if (errorResponses.length === 1) { const { method, params } = requests[errorResponses[0].index]; - throwUnexpectedError(new Error(`API method ${method} failed with: "${errorResponses[0].message}". (params = ${JSON.stringify(params)})`), 'api client'); + throwUnexpectedError(new Error(`API method ${method} failed (params = ${JSON.stringify(params)}): "${errorResponses[0].message}".`), 'api client'); } else if (errorResponses.length > 1) { throwUnexpectedError(new Error(`${errorResponses.length} API methods failed.`), 'api client'); } diff --git a/src/data.ts b/src/data.ts index ab08776..a693eb8 100644 --- a/src/data.ts +++ b/src/data.ts @@ -408,6 +408,8 @@ function getFieldsFromReportMetadata(reportMetadata: Api.ReportMetadata, goals: allMetrics = { ...allMetrics, ...metricsForEachGoal({ 'conversion_rate': 'Conversion Rate' }, goals) }; } + reportMetadata.metricTypes = reportMetadata.metricTypes || {}; + // pre 5.1.0, the overall conversions and revenue sum metrics were not present in metadata output, // but the data exists in the actual API output if (reportMetadata.module !== 'Actions') { diff --git a/tests/appscript/api.spec.ts b/tests/appscript/api.spec.ts index 6fd77a0..6a95189 100644 --- a/tests/appscript/api.spec.ts +++ b/tests/appscript/api.spec.ts @@ -128,6 +128,8 @@ describe('api', () => { }, }); + await new Promise((resolve) => setTimeout(resolve, 5000)); + // use the mock server's path that forces a random error const result = await Clasp.run('setCredentials', { userToken: { diff --git a/tests/utilities/clasp.ts b/tests/utilities/clasp.ts index 798e49e..7596dad 100644 --- a/tests/utilities/clasp.ts +++ b/tests/utilities/clasp.ts @@ -73,7 +73,8 @@ class Clasp { } async run(functionName: string, ...args: any[]) { - return this.runExecutable(['run', '-p', JSON.stringify([functionName, ...args]), 'callFunctionInTest']); + const testName = expect.getState().currentTestName; + return this.runExecutable(['run', '-p', JSON.stringify([functionName, testName, ...args]), 'callFunctionInTest']); } async setScriptProperties(properties: Record, deleteExisting = false) {