From 9de0d38330c2962bf4f5c2b547227f573c7ebdd1 Mon Sep 17 00:00:00 2001 From: Volodymyr Zakhovaiko Date: Tue, 1 Nov 2022 23:00:14 +0100 Subject: [PATCH 1/2] Added DataTable and DataTableArgument types --- lib/data/table.js | 8 +++++--- .../features/step_definitions/my_other_steps.js | 2 +- typings/index.d.ts | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/data/table.js b/lib/data/table.js index 20981a65a..184b3c66c 100644 --- a/lib/data/table.js +++ b/lib/data/table.js @@ -1,14 +1,16 @@ +const DataTableArgument = require("./dataTableArgument"); + /** * Datatable class to provide data driven testing */ class DataTable { - /** @param {Array<*>} array */ + /** @param {Array} array */ constructor(array) { this.array = array; this.rows = new Array(0); } - /** @param {Array<*>} array */ + /** @param {Array} array */ add(array) { if (array.length !== this.array.length) throw new Error(`There is too many elements in given data array. Please provide data in this format: ${this.array}`); const tempObj = {}; @@ -21,7 +23,7 @@ class DataTable { this.rows.push({ skip: false, data: tempObj }); } - /** @param {Array<*>} array */ + /** @param {Array} array */ xadd(array) { if (array.length !== this.array.length) throw new Error(`There is too many elements in given data array. Please provide data in this format: ${this.array}`); const tempObj = {}; diff --git a/test/data/sandbox/features/step_definitions/my_other_steps.js b/test/data/sandbox/features/step_definitions/my_other_steps.js index a16033f94..225ca4e6f 100644 --- a/test/data/sandbox/features/step_definitions/my_other_steps.js +++ b/test/data/sandbox/features/step_definitions/my_other_steps.js @@ -1,6 +1,6 @@ const I = actor(); -Given('I have products in my cart', (table) => { // eslint-disable-line +Given('I have products in my cart', (table) => { for (const id in table.rows) { if (id < 1) { continue; diff --git a/typings/index.d.ts b/typings/index.d.ts index f8bc4ff33..a6900e1f1 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -356,6 +356,23 @@ declare namespace CodeceptJS { useForSnippets?: boolean preferForRegexpMatch?: boolean } + + interface DataTypeArgument { + [key: T]: { + skip: boolean; + data: T; + } + } + + interface DataTable { + array: DataTypeArgument[]; + rows: { + + }; + add: (array: DataTypeArgument[]) => void; + xadd: (array: DataTypeArgument[]) => void; + filter: (func: (item: DataTypeArgument) => boolean) => DataTypeArgument[]; + } } // Globals From 07bf30bcd055d036f905d11806ffd65dc456fca2 Mon Sep 17 00:00:00 2001 From: Volodymyr Zakhovaiko Date: Sun, 6 Nov 2022 01:35:23 +0100 Subject: [PATCH 2/2] RefactoredDataTable and DataTableArgument types --- lib/data/dataTableArgument.js | 2 +- typings/index.d.ts | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/data/dataTableArgument.js b/lib/data/dataTableArgument.js index b32953483..aceb328af 100644 --- a/lib/data/dataTableArgument.js +++ b/lib/data/dataTableArgument.js @@ -59,7 +59,7 @@ class DataTableArgument { /** Transposed the data */ transpose() { - this.rawData = this.rawData[0].map((x, i) => this.rawData.map((y) => y[i])); + this.rawData = this.rawData[0].map((_, i) => this.rawData.map((y) => y[i])); } } diff --git a/typings/index.d.ts b/typings/index.d.ts index a6900e1f1..0cb2d2a8b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -357,21 +357,26 @@ declare namespace CodeceptJS { preferForRegexpMatch?: boolean } - interface DataTypeArgument { - [key: T]: { - skip: boolean; - data: T; - } + interface DataTableArgument { + rawData: string[][]; + raw(): string[][]; + rows(): string[][]; + hashes(): { [columnHeader: string]: string }[]; + rowsHash(): { [columnHeader: string]: string }; + transpose(): string[][]; } - interface DataTable { - array: DataTypeArgument[]; + interface DataTable { + array: DataTableArgument[]; rows: { - + [key: string]: { + skip: boolean; + data: DataTableArgument; + } }; - add: (array: DataTypeArgument[]) => void; - xadd: (array: DataTypeArgument[]) => void; - filter: (func: (item: DataTypeArgument) => boolean) => DataTypeArgument[]; + add: (array: DataTableArgument[]) => void; + xadd: (array: DataTableArgument[]) => void; + filter: (func: (item: DataTableArgument) => boolean) => DataTableArgument[]; } }