Repository: codeceptjs/CodeceptJS (JavaScript)

Issue:
Data sets can't be defined with array in version 1.1.2 but can be in version 1.0.1
#### What are you trying to achieve?
I hope data sets can be defined with array...
#### What do you get instead?

> Provide console output if related. Use `--verbose` mode for more details.

```bash
# paste output here
{ ui-regression-test } master » codeceptjs run --steps --profile cm --verbose
CodeceptJS v1.1.2
Using test root "D:\git\Medicare\ui\ui-regression-test"

ehm --
   [1] Starting recording promises
   Emitted | suite.before ([object Object])
   [1] Queued | hook WebDriverIO._beforeSuite()
 test array | undefined
   Emitted | test.before
   [1] Queued | hook WebDriverIO._before()
   Emitted | test.start ([object Object])
   [1] Queued | throw error Error: Object of type current is not defined in container
   [1] Queued | fire test.passed
   [1] Queued | finish test
   [1] Error | Error: Object of type current is not defined in container
   [1] Starting <teardown> session
   Emitted | test.failed ([object Object])
   [1] <teardown> Queued | hook WebDriverIO._failed()
   [1] <teardown> Queued | () => done(err)
   [1] <teardown> Stopping recording promises
 > Screenshot has been saved to D:\git\Medicare\ui\ui-regression-test\output\test_array___undefined.failed.png
 × FAILED in 363ms

   [2] Starting recording promises
   Emitted | test.after
   [2] Queued | hook WebDriverIO._after()
 test array | undefined
   Emitted | test.before
   [2] Queued | hook WebDriverIO._before()
   Emitted | test.start ([object Object])
   [2] Queued | throw error Error: Object of type current is not defined in container
   [2] Queued | fire test.passed
   [2] Queued | finish test
   [2] Error | Error: Object of type current is not defined in container
   [2] Starting <teardown> session
   Emitted | test.failed ([object Object])
   [2] <teardown> Queued | hook WebDriverIO._failed()
   [2] <teardown> Queued | () => done(err)
   [2] <teardown> Stopping recording promises
 > Screenshot has been saved to D:\git\Medicare\ui\ui-regression-test\output\test_array___undefined.failed.png
 × FAILED in 376ms

   [3] Starting recording promises
   Emitted | test.after
   [3] Queued | hook WebDriverIO._after()
 test array | undefined
   Emitted | test.before
   [3] Queued | hook WebDriverIO._before()
   Emitted | test.start ([object Object])
   [3] Queued | throw error Error: Object of type current is not defined in container
   [3] Queued | fire test.passed
   [3] Queued | finish test
   [3] Error | Error: Object of type current is not defined in container
   [3] Starting <teardown> session
   Emitted | test.failed ([object Object])
   [3] <teardown> Queued | hook WebDriverIO._failed()
   [3] <teardown> Queued | () => done(err)
   [3] <teardown> Stopping recording promises
 > Screenshot has been saved to D:\git\Medicare\ui\ui-regression-test\output\test_array___undefined.failed.png
 × FAILED in 349ms

   [4] Starting recording promises
   Emitted | test.after
   [4] Queued | hook WebDriverIO._after()
   Emitted | suite.after ([object Object])
   [4] Queued | hook WebDriverIO._afterSuite()

-- FAILURES:

  1) ehm
       test array | undefined:
     Object of type current is not defined in container
  rror: Object of type current is not defined in container
      at getInjectedArguments (C:\Users\cherrieg\AppData\Roaming\npm\node_modules\codeceptjs\lib\scenario.js:213:13)
      at Context.test.fn (C:\Users\cherrieg\AppData\Roaming\npm\node_modules\codeceptjs\lib\scenario.js:79:38)

  2) ehm
       test array | undefined:
     Object of type current is not defined in container
  rror: Object of type current is not defined in container
      at getInjectedArguments (C:\Users\cherrieg\AppData\Roaming\npm\node_modules\codeceptjs\lib\scenario.js:213:13)
      at Context.test.fn (C:\Users\cherrieg\AppData\Roaming\npm\node_modules\codeceptjs\lib\scenario.js:79:38)

  3) ehm
       test array | undefined:
     Object of type current is not defined in container
  rror: Object of type current is not defined in container
      at getInjectedArguments (C:\Users\cherrieg\AppData\Roaming\npm\node_modules\codeceptjs\lib\scenario.js:213:13)
      at Context.test.fn (C:\Users\cherrieg\AppData\Roaming\npm\node_modules\codeceptjs\lib\scenario.js:79:38)


  FAIL  | 0 passed, 3 failed   // 15s
   Emitted | global.result ([object Object])
   [4] Queued | hook WebDriverIO._finishTest()

```

> Provide test source code if related

```js
// paste test
Feature('ehm');
Data(['1', '2', '3']).Scenario('test array', (I, current)=>{
	console.log(current);
})
```

### Details

* CodeceptJS version: 1.1.2
* NodeJS Version: 8.9.3
* Operating System: Windows 7
* Protractor || WebDriverIO || Nightmare version (if related)
* Configuration file:
exports.config = {
    "tests": "./test/test_test.js",
    "timeout": 100000,
    "output": "./output",
    "include": {
        "censusPage": "./pages/censusPage.js",
        "phonePage": "./pages/phonePage.js",
        "leadPage": "./pages/leadPage.js",
        "quotePage": "./pages/quotePage.js"
    },
    "helpers": {
        "WebDriverIO": {
            "url": "https://",
            "browser": "chrome",
            "windowSize": "maximize",
            "restart": true,
            "desiredCapabilities": {
                "browserName": "chrome",
                "chromeOptions": {
                    "binary": "D:/software/chrome-win32/chrome.exe",
                    "args": ["--window-size=1800,1600"]
                }
            }
        }
    },
    "name": "layer-x",
    "mocha": {
        "reporterOptions": {
            "reportDir": "output"
        }
    }
}
```js
# paste suite config here
```



Discussion:

Patch:
diff --git a/lib/data/context.js b/lib/data/context.js
index 7f042ca0b..c40c79812 100644
--- a/lib/data/context.js
+++ b/lib/data/context.js
@@ -46,6 +46,11 @@ module.exports = function (context) {
   };
 };
 
+function isTableDataRow(row) {
+  const has = Object.prototype.hasOwnProperty;
+  return has.call(row, 'data') && has.call(row, 'skip');
+}
+
 function detectDataType(dataTable) {
   if (dataTable instanceof DataTable) {
     return dataTable.rows;
@@ -64,7 +69,15 @@ function detectDataType(dataTable) {
     return dataTable();
   }
   if (Array.isArray(dataTable)) {
-    return dataTable;
+    return dataTable.map((item) => {
+      if (isTableDataRow(item)) {
+        return item;
+      }
+      return {
+        data: item,
+        skip: false,
+      };
+    });
   }
 
   throw new Error('Invalid data type. Data accepts either: DataTable || generator || Array || function');


Test patch:
diff --git a/test/data/sandbox/ddt_test.ddt.js b/test/data/sandbox/ddt_test.ddt.js
index 6c67ab732..1c8320464 100644
--- a/test/data/sandbox/ddt_test.ddt.js
+++ b/test/data/sandbox/ddt_test.ddt.js
@@ -22,3 +22,7 @@ Data(function* () {
 }).Scenario('Should log accounts3', (I, current) => {
   console.log(`Got changed login ${current[0]}`);
 });
+
+Data(['1', '2', '3']).Scenario('Should log array of strings', (I, current) => {
+  console.log(`Got array item ${current}`);
+});