diff --git a/.eslintrc.json b/.eslintrc.json index 918671b..d17d9e4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,7 +9,7 @@ }, "extends": "eslint:recommended", "parserOptions": { - "ecmaVersion": 6 + "ecmaVersion": 8 }, "rules": { "curly": "error", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8112b3b..4b54c65 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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: @@ -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**: diff --git a/js.json b/js.json index 95d014f..eebd5ba 100644 --- a/js.json +++ b/js.json @@ -51,7 +51,7 @@ "--init" ] }, - "version": "2.4.0", + "version": "2.4.1", "gaugeVersionSupport": { "minimum": "1.0.7", "maximum": "" diff --git a/package-lock.json b/package-lock.json index fbce8bd..c71462c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gauge-js", - "version": "2.4.0", + "version": "2.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "gauge-js", - "version": "2.4.0", + "version": "2.4.1", "license": "MIT", "dependencies": { "@grpc/grpc-js": "^1.5.5", @@ -2528,8 +2528,7 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", - "dev": true, - "requires": {} + "dev": true }, "ajv": { "version": "6.12.6", diff --git a/package.json b/package.json index 59f62db..9dfd5b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gauge-js", - "version": "2.4.0", + "version": "2.4.1", "description": "JavaScript runner for Gauge", "main": "index.js", "scripts": { diff --git a/src/table.js b/src/table.js index 3a25cb5..278849f 100644 --- a/src/table.js +++ b/src/table.js @@ -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); + } } }; }; diff --git a/test/table.js b/test/table.js index 096711a..211a637 100644 --- a/test/table.js +++ b/test/table.js @@ -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() { @@ -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); }); @@ -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); + }); });