Skip to content

Commit

Permalink
Added another function to Table that will process async callback func… (
Browse files Browse the repository at this point in the history
#571)

* Added another function to Table that will process async callback functions to resolve issue #570.  Also had to bump the ecmaVersion to 8 in eslint to support async await

Signed-off-by: Autumn Calhoun <autumn.calhoun@crowncastle.com>

* #570 updated per code review comments

Signed-off-by: Autumn Calhoun <autumn.calhoun@crowncastle.com>

---------

Signed-off-by: Autumn Calhoun <autumn.calhoun@crowncastle.com>
  • Loading branch information
autumn-calhoun authored Apr 29, 2023
1 parent bb5f1d0 commit 364a73e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
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);

});

});

0 comments on commit 364a73e

Please sign in to comment.