Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
034c9f3
Create codeql-analysis.yml
testbetter May 10, 2021
d79ec1c
fixed content-length issue
May 11, 2021
1cd9186
updated packages
May 11, 2021
25cad3d
updated version
May 11, 2021
efbf9d6
added .idea to gitignore - ide related
May 11, 2021
2d25296
revered package.json version
May 11, 2021
da88be3
3.2.0
May 11, 2021
8e7c71e
reverted commander version
May 11, 2021
4a91c1a
3.2.1
May 11, 2021
a27c898
reverted js-yaml package
May 11, 2021
ebbeccb
3.2.2
May 11, 2021
d02764e
added option for proxy in openapitest.js
Aug 12, 2021
b758197
implemented superagent-proxy
Aug 12, 2021
158107f
changed version
Aug 12, 2021
7017104
added to readme
Aug 12, 2021
34df1bc
changed package version to 3.3
Aug 12, 2021
a8c8c38
changed package version to 3.3.0
Aug 12, 2021
501cb64
inline mochawesome css in reports
Sep 9, 2021
8603dea
inline mochawesome css in reports via argument
Sep 9, 2021
e0e69d9
updated readme
Sep 9, 2021
5cc318d
PR comment addressed
Oct 8, 2021
4000186
addressed linting issue from travis-ci
Oct 8, 2021
a9249f8
addressed linting issue from travis-ci 2
Oct 8, 2021
daa0196
deleted travis-ci as it's not working
Oct 8, 2021
e3626e1
deleted travis-ci as it's not working - reverted
Oct 8, 2021
49ac328
Revert "addressed linting issue from travis-ci"
Oct 11, 2021
4171587
Revert "addressed linting issue from travis-ci 2"
Oct 11, 2021
50484e4
reverted linting fix
Oct 11, 2021
da5e40e
added tags system for test
Oct 11, 2021
28cf72c
added readme and version change
Oct 11, 2021
ac766e3
Delete .travis.yml
vnysheoran Oct 11, 2021
9657338
removed travis badge from readme
vnysheoran Oct 11, 2021
bb8dd38
Merge branch 'vinay/test-tagging' of https://github.com/testbetter/op…
Oct 12, 2021
ba850d5
added multi-report - junit and mochawesome
Oct 12, 2021
7620d15
changed tags to string
Oct 18, 2021
c31d3bf
changed version
Oct 18, 2021
59e0296
multi-report enabled HTML
Oct 21, 2021
d98106a
user can now provide mochaawesome report
Dec 1, 2021
aa7eb27
changed report dir
Dec 2, 2021
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
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '24 1 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
*~
.DS_Store
npm_debug.log
.idea
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

The purpose of this openapitest framework is to simplify authoring, organizing, executing, and reporting result of API tests using API specification. It runs on node.js and distributed via npm. Add this module to your node.js project as a development dependency and start writing API or Integration tests using YAML language.


[![Build Status](https://travis-ci.org/testbetter/openapitest.svg?branch=master)](https://travis-ci.org/testbetter/openapitest)

### Installation
----
```npm install --save-dev openapitest```
Expand Down Expand Up @@ -67,6 +64,9 @@ Options:
-g, --globalConfig [path] Global Test data config folder relative/ absolute path. e.g: <path>/global-config
-u, --url [url] Server URL. e.g: http://localhost:9000
-r, --report <n> Will generate the html report or not. Default 0; e.g: 1 or 0
-p, --proxy [proxy] The Proxy URL, e.g: http://127.0.0.1:8080
-a, --tag [tag] Comma seperated tags to run the test, leave empty to run all
-m, --reportName [name] The name of mochawesome report file
-h, --help output usage information
```

Expand Down
42 changes: 34 additions & 8 deletions bin/openapitest.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ program
'Will generate the html report or not. e.g: 1 or 0',
parseInt
)
.option('-a, --tag [tag]', 'Comma seperated tags to run the test, leave empty to run all')
.option('-u, --url [url]', 'Server URL. e.g: http://localhost:9000')
.option('-p, --proxy [proxy]', 'Proxy URL. e.g: http://127.0.0.1:8080')
.option('-m, --reportName [name]', 'The name of mochawesome report file')

program.parse(process.argv)

Expand Down Expand Up @@ -72,18 +75,41 @@ if (program.dataConfig) {
process.env.COMMON_DATA_CONFIG = program.dataConfig
}

if (program.proxy) {
process.env.PROXYURL = program.proxy;
}

process.env.API_SERVER_URL = program.url
if (program.tag) {
process.env.TAGS = program.tag
}

let reportName = "openapitest-report";
if (program.reportName) {
reportName = program.reportName;
}

let options = {}
if(program.report) {
options.reporter = 'mochawesome'
options.reporter = 'mocha-multi-reporters'
options.reporterOptions = {
reportDir: 'reports',
reportFilename: 'test-int-report',
overwrite: true,
charts: true,
code: false,
quiet: true
reporterEnabled: "mocha-junit-reporter, mochawesome",
mochaJunitReporterReporterOptions: {
mochaFile: "reports/junit/results-[hash].xml",
includePending: true,
jenkinsMode: true
},
mochawesomeReporterOptions: {
reportDir: "reports/mochawesome",
reportFilename: reportName,
html: true,
json: true,
overwrite: true,
charts: true,
code: false,
quiet: true,
inline: true
}
}
}

Expand All @@ -106,4 +132,4 @@ function checkExists(file, desc) {
console.log(`${desc}: ${file} does not exist.`.bold.red)
process.exit(-1)
}
}
}
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openapitest",
"version": "3.0.0",
"version": "3.4.5",
"description": "",
"main": "src/index.js",
"scripts": {
Expand All @@ -16,15 +16,14 @@
"openapitest": "./bin/openapitest.js"
},
"repository": {
"type" : "git",
"url" : "git+https://github.com/testbetter/openapitest.git"
"type": "git",
"url": "git+https://github.com/testbetter/openapitest.git"
},
"keywords": [
"operapi",
"swagger",
"integration test"
],
"author": "Test Better",
"author": {
"name": "Test Better",
"email": "testbetter100@gmail.com"
Expand All @@ -34,27 +33,30 @@
},
"license": "MIT",
"dependencies": {
"chai": "^4.2.0",
"chai": "^4.3.4",
"colors": "^1.4.0",
"commander": "^2.20.1",
"expect.js": "^0.3.1",
"faker": "^4.1.0",
"faker": "^5.5.3",
"js-yaml": "^3.13.1",
"jsonpath": "^1.0.0",
"jsonpath": "^1.1.1",
"klaw-sync": "^6.0.0",
"lodash": "^4.17.14",
"mocha": "^5.2.0",
"mochawesome": "^3.1.2",
"object-path": "^0.11.3",
"object-values": "^1.0.0",
"shelljs": "^0.8.3",
"superagent": "^4.1.0",
"lodash": "^4.17.21",
"mocha": "^8.4.0",
"mocha-junit-reporter": "^2.0.2",
"mocha-multi-reporters": "^1.5.1",
"mochawesome": "^6.2.2",
"object-path": "^0.11.5",
"object-values": "^2.0.0",
"shelljs": "^0.8.4",
"superagent": "^6.1.0",
"superagent-proxy": "^2.1.0",
"tryer": "^1.0.1"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-plugin-import": "^2.18.2",
"sinon": "^7.5.0"
"eslint": "^7.26.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"sinon": "^10.0.0"
}
}
33 changes: 33 additions & 0 deletions src/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const { loadYamlFile } = require('./util.js');
const apiPort = new ApiPort();
apiPort.init();

let tagsArray = [];
if (process.env.TAGS) {
tagsArray = process.env.TAGS.split(',');
}

if (apiPort.get('API_TESTS_PATH')) {
const paths = klawSync(apiPort.get('API_TESTS_PATH'), { nodir: true });
if (paths) {
Expand All @@ -18,6 +23,34 @@ if (apiPort.get('API_TESTS_PATH')) {
apiPort.currentFile = filePath;
const config = loadYamlFile(filePath);
describe(filePath, () => {
let tagsInTest = [];
if (tagsInTest) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is always true. Empty arrays are not "falsey". So, this block always executes. Just remove the if.

Unless you meant to check something that might be false - like the config.apiCalls.tag or tagsArray.length (remember tagArray will be truthy even when empty).

if (!Array.isArray(config.apiCalls.tag)) {
tagsInTest = [config.apiCalls.tag];
} else {
tagsInTest = config.apiCalls.tag;
}
}
if (tagsArray.length > 0) {
let tagMatched = false;
for (const tagInArgs of tagsArray) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use lodash and one of its many set operators here - intersection is probably the one you want.

for (const tagInTest of tagsInTest) {
if (`${tagInArgs}` === `${tagInTest}`) {
tagMatched = true;
break;
}
}
if (tagMatched) {
break;
}
}

if (!tagMatched) {
console.error(`The tags ${config.apiCalls.tag || 'empty'} in file: ${filePath} does not match the expected tags: ${tagsArray || 'empty'}`);
return false;
}
}

const describeMethod = config.only ? describe.only : describe;
describeMethod(
(config.apiCalls || {}).name || 'unnamed',
Expand Down
22 changes: 18 additions & 4 deletions src/superClient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable comma-dangle */
const _ = require('lodash');
const request = require('superagent');
require('superagent-proxy')(request);

const proxy = process.env.PROXYURL || null;

module.exports = async function superClient(
apiPort,
Expand All @@ -27,8 +30,19 @@ module.exports = async function superClient(
} else if (basicAuth) {
suObj = suObj.auth(basicAuth.username || '', basicAuth.password || '');
}
return suObj
.set(req.header || '')
.send(data)
.sortQuery();

suObj.set(req.header || '');

if (proxy) {
suObj.proxy(proxy);
}

// Only set data if data has some value, so that content-length is zero
if (data && data !== 'null' && Object.keys(data).length > 0) {
suObj.send(data);
}

suObj.sortQuery();

return suObj;
};