diff --git a/README.md b/README.md index 45b9309..5f13db7 100644 --- a/README.md +++ b/README.md @@ -8,19 +8,13 @@ https://github.com/ScottLogic/openapi-forge ### Testing -There are two scripts that can be used for testing, one that uses preset values for file paths to feature files and the `generate.js` file of the forge: - -Using default values: +The standard test script is used to execute the BDD-style tests against this generator. ``` -npm run test:defaultPaths +npm run test ``` -The second script requires values for the featurePath & generatePath: - -``` -npm test {featurePath} {generatorPath} -``` +The script expects that the openapi-forge project (which is where the BDD feature files are located) is checked out at the same folder-level as this project. ### Linting diff --git a/cucumber.js b/cucumber.js index 7fd034a..271d915 100644 --- a/cucumber.js +++ b/cucumber.js @@ -1,17 +1,13 @@ -// cucumber.js - -// Retrieve the path to feature paths from cl arguments of cucumber-js -const cliArgs = process.argv.slice(2); -const featurePath = cliArgs[cliArgs.length - 2]; -if (!featurePath) { - throw new Error(`You must provide a path to the feature files.`); -} - -let common = [ - featurePath, // Specify our feature files - "--require features/support/*.js", // Load step definitions -].join(" "); +const common = { + paths: ["../openapi-forge/features/*.feature"], + require: ["features/support/*.js"], + publishQuiet: true, +}; module.exports = { default: common, + generators: { + ...common, + format: ["message"], + }, }; diff --git a/features/support/util.js b/features/support/util.js index 46c74bb..8cc1fa3 100644 --- a/features/support/util.js +++ b/features/support/util.js @@ -1,3 +1,5 @@ +const generate = require("../../../openapi-forge/src/generate"); + const isJson = (str) => { try { JSON.parse(str); @@ -7,16 +9,6 @@ const isJson = (str) => { return true; }; -// Retrieve the path to generate.js from cl arguments of cucumber-js -const cliArgs = process.argv.slice(2); -const generatePath = cliArgs[cliArgs.length - 1]; - -if (!generatePath) { - throw new Error(`You must provide a path to generate.js.`); -} - -const generate = require(generatePath); - async function generateApi(schema) { await generate(JSON.parse(schema), ".", { output: "./features/api", diff --git a/package-lock.json b/package-lock.json index cc135cc..23fcb9b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "openapi-forge-javascript", "version": "0.1.0", "license": "MIT", + "dependencies": { + "@cucumber/messages": "^20.0.0" + }, "devDependencies": { "@commitlint/cli": "^17.1.2", "@commitlint/config-conventional": "^17.1.0", @@ -15,7 +18,7 @@ "chai": "^4.3.6", "eslint": "^8.24.0", "husky": "^8.0.1", - "openapi-forge": "^1.0.1", + "openapi-forge": "latest", "prettier": "^2.7.1", "semantic-release": "^19.0.5" }, @@ -537,6 +540,18 @@ "regexp-match-indices": "1.0.2" } }, + "node_modules/@cucumber/cucumber/node_modules/@cucumber/messages": { + "version": "19.1.4", + "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-19.1.4.tgz", + "integrity": "sha512-Pksl0pnDz2l1+L5Ug85NlG6LWrrklN9qkMxN5Mv+1XZ3T6u580dnE6mVaxjJRdcOq4tR17Pc0RqIDZMyVY1FlA==", + "dev": true, + "dependencies": { + "@types/uuid": "8.3.4", + "class-transformer": "0.5.1", + "reflect-metadata": "0.1.13", + "uuid": "9.0.0" + } + }, "node_modules/@cucumber/cucumber/node_modules/supports-color": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", @@ -602,6 +617,18 @@ "gherkin-utils": "bin/gherkin-utils" } }, + "node_modules/@cucumber/gherkin-utils/node_modules/@cucumber/messages": { + "version": "19.1.4", + "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-19.1.4.tgz", + "integrity": "sha512-Pksl0pnDz2l1+L5Ug85NlG6LWrrklN9qkMxN5Mv+1XZ3T6u580dnE6mVaxjJRdcOq4tR17Pc0RqIDZMyVY1FlA==", + "dev": true, + "dependencies": { + "@types/uuid": "8.3.4", + "class-transformer": "0.5.1", + "reflect-metadata": "0.1.13", + "uuid": "9.0.0" + } + }, "node_modules/@cucumber/gherkin-utils/node_modules/commander": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/commander/-/commander-9.3.0.tgz", @@ -611,6 +638,18 @@ "node": "^12.20.0 || >=14" } }, + "node_modules/@cucumber/gherkin/node_modules/@cucumber/messages": { + "version": "19.1.4", + "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-19.1.4.tgz", + "integrity": "sha512-Pksl0pnDz2l1+L5Ug85NlG6LWrrklN9qkMxN5Mv+1XZ3T6u580dnE6mVaxjJRdcOq4tR17Pc0RqIDZMyVY1FlA==", + "dev": true, + "dependencies": { + "@types/uuid": "8.3.4", + "class-transformer": "0.5.1", + "reflect-metadata": "0.1.13", + "uuid": "9.0.0" + } + }, "node_modules/@cucumber/html-formatter": { "version": "20.1.0", "resolved": "https://registry.npmjs.org/@cucumber/html-formatter/-/html-formatter-20.1.0.tgz", @@ -630,10 +669,9 @@ } }, "node_modules/@cucumber/messages": { - "version": "19.1.4", - "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-19.1.4.tgz", - "integrity": "sha512-Pksl0pnDz2l1+L5Ug85NlG6LWrrklN9qkMxN5Mv+1XZ3T6u580dnE6mVaxjJRdcOq4tR17Pc0RqIDZMyVY1FlA==", - "dev": true, + "version": "20.0.0", + "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-20.0.0.tgz", + "integrity": "sha512-JFrFwuhxsbig0afaViNhuzoQyC+GQzlI7m+rX+lSiDGV13K3sJzMmHjkbCiNOgoRlKAMwIGR9TRMH0xj9/My0w==", "dependencies": { "@types/uuid": "8.3.4", "class-transformer": "0.5.1", @@ -1148,8 +1186,7 @@ "node_modules/@types/uuid": { "version": "8.3.4", "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", - "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==", - "dev": true + "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==" }, "node_modules/acorn": { "version": "8.8.1", @@ -1527,8 +1564,7 @@ "node_modules/class-transformer": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", - "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", - "dev": true + "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==" }, "node_modules/clean-stack": { "version": "2.2.0", @@ -7131,8 +7167,7 @@ "node_modules/reflect-metadata": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", - "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==", - "dev": true + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" }, "node_modules/reftools": { "version": "1.1.9", @@ -8264,7 +8299,6 @@ "version": "9.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", - "dev": true, "bin": { "uuid": "dist/bin/uuid" } @@ -8891,6 +8925,18 @@ "yup": "^0.32.11" }, "dependencies": { + "@cucumber/messages": { + "version": "19.1.4", + "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-19.1.4.tgz", + "integrity": "sha512-Pksl0pnDz2l1+L5Ug85NlG6LWrrklN9qkMxN5Mv+1XZ3T6u580dnE6mVaxjJRdcOq4tR17Pc0RqIDZMyVY1FlA==", + "dev": true, + "requires": { + "@types/uuid": "8.3.4", + "class-transformer": "0.5.1", + "reflect-metadata": "0.1.13", + "uuid": "9.0.0" + } + }, "supports-color": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", @@ -8918,6 +8964,20 @@ "dev": true, "requires": { "@cucumber/messages": "^19.0.0" + }, + "dependencies": { + "@cucumber/messages": { + "version": "19.1.4", + "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-19.1.4.tgz", + "integrity": "sha512-Pksl0pnDz2l1+L5Ug85NlG6LWrrklN9qkMxN5Mv+1XZ3T6u580dnE6mVaxjJRdcOq4tR17Pc0RqIDZMyVY1FlA==", + "dev": true, + "requires": { + "@types/uuid": "8.3.4", + "class-transformer": "0.5.1", + "reflect-metadata": "0.1.13", + "uuid": "9.0.0" + } + } } }, "@cucumber/gherkin-streams": { @@ -8949,6 +9009,18 @@ "commander": "9.3.0" }, "dependencies": { + "@cucumber/messages": { + "version": "19.1.4", + "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-19.1.4.tgz", + "integrity": "sha512-Pksl0pnDz2l1+L5Ug85NlG6LWrrklN9qkMxN5Mv+1XZ3T6u580dnE6mVaxjJRdcOq4tR17Pc0RqIDZMyVY1FlA==", + "dev": true, + "requires": { + "@types/uuid": "8.3.4", + "class-transformer": "0.5.1", + "reflect-metadata": "0.1.13", + "uuid": "9.0.0" + } + }, "commander": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/commander/-/commander-9.3.0.tgz", @@ -8972,10 +9044,9 @@ "requires": {} }, "@cucumber/messages": { - "version": "19.1.4", - "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-19.1.4.tgz", - "integrity": "sha512-Pksl0pnDz2l1+L5Ug85NlG6LWrrklN9qkMxN5Mv+1XZ3T6u580dnE6mVaxjJRdcOq4tR17Pc0RqIDZMyVY1FlA==", - "dev": true, + "version": "20.0.0", + "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-20.0.0.tgz", + "integrity": "sha512-JFrFwuhxsbig0afaViNhuzoQyC+GQzlI7m+rX+lSiDGV13K3sJzMmHjkbCiNOgoRlKAMwIGR9TRMH0xj9/My0w==", "requires": { "@types/uuid": "8.3.4", "class-transformer": "0.5.1", @@ -9392,8 +9463,7 @@ "@types/uuid": { "version": "8.3.4", "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", - "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==", - "dev": true + "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==" }, "acorn": { "version": "8.8.1", @@ -9682,8 +9752,7 @@ "class-transformer": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", - "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", - "dev": true + "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==" }, "clean-stack": { "version": "2.2.0", @@ -13772,8 +13841,7 @@ "reflect-metadata": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", - "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==", - "dev": true + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" }, "reftools": { "version": "1.1.9", @@ -14645,8 +14713,7 @@ "uuid": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", - "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", - "dev": true + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==" }, "v8-compile-cache-lib": { "version": "3.0.1", diff --git a/package.json b/package.json index c7032e2..b8a6878 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "prepare": "husky install", "test": "\"./node_modules/.bin/cucumber-js\" -p default", - "test:defaultPaths": "\"./node_modules/.bin/cucumber-js\" -p default \"../openapi-forge/features/*.feature\" \"../../../openapi-forge/src/generate\"", + "test:generators": "\"./node_modules/.bin/cucumber-js\" -p generators", "format:check:all": "prettier --check .", "format:write:all": "prettier --write .", "format:write": "prettier --write", @@ -20,6 +20,7 @@ "@commitlint/cli": "^17.1.2", "@commitlint/config-conventional": "^17.1.0", "@cucumber/cucumber": "^8.7.0", + "@cucumber/messages": "^20.0.0", "chai": "^4.3.6", "eslint": "^8.24.0", "husky": "^8.0.1", diff --git a/testResultParser.js b/testResultParser.js deleted file mode 100644 index cabe6eb..0000000 --- a/testResultParser.js +++ /dev/null @@ -1,51 +0,0 @@ -function parseTestResultNumber(number) { - const result = parseInt(number); - return isNaN(result) ? 0 : result; -} - -function parse(results) { - const ll = results.length; - - const failLineRegex = /\d+\)\sScenario:\s(.*)\s#.*/; - let failures = []; - let rr; - for (let xx = 0; xx < ll; xx++) { - if ((rr = results[xx].match(failLineRegex))) failures.push(rr[1]); - } - - let result = {}; - result.failures = failures; - - // Extract the duration of the testing from stdout. - const durationMatch = results[ll - 2].match(/^(\d+)m(\d+)\.\d+s/); - - if (durationMatch) { - // Format the duration - let time = ""; - if (durationMatch[1] !== "0" && durationMatch[1] !== "") - time = `${durationMatch[1]}m`; - time = `${time}${durationMatch[2]}s`; - - // Extract the results of the testing from stdout. In stdout is a count of tests and their outcomes. - const resultMatch = results[ll - 4].match( - /^(\d+)\sscenarios?\s\(((\d+)\sfailed)?(,\s)?((\d+)\sundefined)?(,\s)?((\d+)\spassed)?\)/ - ); - if (resultMatch) { - result.scenarios = parseTestResultNumber(resultMatch[1]); - result.passed = parseTestResultNumber(resultMatch[9]); - result.skipped = 0; - result.undef = parseTestResultNumber(resultMatch[6]); - result.failed = parseTestResultNumber(resultMatch[3]); - result.time = time; - } else { - throw new Error(`Could not parse the results of the TypeScript testing.`); - } - } else { - throw new Error(`Could not parse the duration of the TypeScript testing.`); - } - return result; -} - -module.exports = { - parse, -};