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 1 commit
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
8 changes: 8 additions & 0 deletions src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ var Table = function (protoTable) {
callback(entry);
}
};

this.asyncEntries = async function (callback) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making a new function, can we just check if the callback is an async function and handle it accordingly?

For example

const AsyncFunction = (async () => {}).constructor;

if(callback instanceof AsyncFunction) {
}

Copy link
Contributor Author

@autumn-calhoun autumn-calhoun Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zabil Thank you for the suggestion, I am new to javascript, so that is helpful. I have made the suggested changes.

for (let row of this.rows) {
let entry = {};
row.cells.forEach((cell, index) => entry[this.headers.cells[index]] = cell);
await callback(entry);
}
};
};

module.exports = Table;
31 changes: 31 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,27 @@ describe("ProtoTable parsing", function() {
"Description": "Agile project management"
});
});

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

await table.asyncEntries(async function (entry) {
data.push(await getRowData(entry));
});

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

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

await table.entries(async function (entry) {
data.push(await getRowData(entry));
});

expect(data).to.be.empty;
});

});

});