Skip to content

Commit

Permalink
Merge pull request #2 from ScottLogic/simplify-tests
Browse files Browse the repository at this point in the history
test: simplify tests
  • Loading branch information
ColinEberhardt authored Dec 13, 2022
2 parents 819f41b + 02eea0f commit d42f555
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 108 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 9 additions & 13 deletions cucumber.js
Original file line number Diff line number Diff line change
@@ -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"],
},
};
12 changes: 2 additions & 10 deletions features/support/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const generate = require("../../../openapi-forge/src/generate");

const isJson = (str) => {
try {
JSON.parse(str);
Expand All @@ -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",
Expand Down
115 changes: 91 additions & 24 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
51 changes: 0 additions & 51 deletions testResultParser.js

This file was deleted.

0 comments on commit d42f555

Please sign in to comment.