Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added another function to Table that will process async callback func… #571

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 6
"ecmaVersion": 8
},
"rules": {
"curly": "error",
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Issues

If you find any issues or have any feature requests, please file them in the [issue tracker](https://github.com/getgauge-contrib/gauge-js/issues).
If you find any issues or have any feature requests, please file them in the [issue tracker](https://github.com/getgauge/gauge-js/issues).

If you are filing issues, please provide the version of `gauge` core and `gauge-js` plugin that you have installed. You can find it by doing:

Expand All @@ -13,7 +13,7 @@ $ gauge -v
**Download**

```sh
$ git clone git://github.com/getgauge-contrib/gauge-js --recursive
$ git clone git://github.com/getgauge/gauge-js --recursive
```

**Setup**:
Expand Down
2 changes: 1 addition & 1 deletion js.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"--init"
]
},
"version": "2.4.0",
"version": "2.4.1",
"gaugeVersionSupport": {
"minimum": "1.0.7",
"maximum": ""
Expand Down
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gauge-js",
"version": "2.4.0",
"version": "2.4.1",
"description": "JavaScript runner for Gauge",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 9 additions & 3 deletions src/table.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
var Table = function (protoTable) {
Object.assign(this, protoTable);

this.entries = function (callback) {
for (var row of this.rows) {
this.entries = async function (callback) {
const AsyncFunction = (async () => {}).constructor;

for (const row of this.rows) {
let entry = {};
row.cells.forEach((cell, index) => entry[this.headers.cells[index]] = cell);
callback(entry);
if(callback instanceof AsyncFunction) {
await callback(entry);
} else {
callback(entry);
}
}
};
};
Expand Down
19 changes: 19 additions & 0 deletions test/table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var Table = require("../src/table");
var expect = require("chai").expect;
const util = require("util");
const setTimeoutPromise = util.promisify(setTimeout);

describe("ProtoTable parsing", function() {

Expand All @@ -17,6 +19,14 @@ describe("ProtoTable parsing", function() {

var table = new Table(protoTable);

let getRowData = function(entry) {
const rowData = setTimeoutPromise(500, entry).then((value) => {
return {cells: [value["Product"], value["Description"]]};
});
return rowData;

};

it("Should get headers", function () {
expect(table.headers).to.deep.equal(protoTable.headers);
});
Expand All @@ -41,6 +51,15 @@ describe("ProtoTable parsing", function() {
"Description": "Agile project management"
});
});

it("Should process an asynchronous callback action", async function () {
let data = [];

await table.entries(async (entry) => data.push(await getRowData(entry)));

expect(data).to.deep.equal(protoTable.rows);
}).timeout(10000);

});

});