-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(templates): improved test templates, ESLinting
improved test templates and skeletons, improved code, now using ESLint with AirBnB JavaScript style
- Loading branch information
Antonio Pintus
committed
May 8, 2017
1 parent
f81631c
commit 599af10
Showing
21 changed files
with
577 additions
and
561 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "airbnb-base", | ||
"plugins": [ | ||
"import", | ||
"mocha" | ||
], | ||
|
||
"rules": { | ||
"no-console": "off", | ||
"no-restricted-syntax": "off", | ||
"no-shadow": ["error", { "allow": ["done", "resolve", "reject", "done", "cb", "callback", "err", "req", "res"] }], | ||
"mocha/no-exclusive-tests": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,57 @@ | ||
#!/usr/bin/env node | ||
|
||
|
||
//API-PIKI command line tool | ||
// API-PIKI command line tool | ||
const program = require('commander'); | ||
const generator = require('./src/lib/generator'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
let specFile; | ||
|
||
program | ||
.usage('[options] <spec>') | ||
.version(require('./package.json').version) | ||
.arguments('<spec>') | ||
.action( spec => { | ||
specFile = spec; | ||
.action((spec) => { | ||
specFile = spec; | ||
}) | ||
.option('-o, --out [outDir]', 'Output directory for generated test files. Default: ./test/api-swag') | ||
.option('-f, --forceAuth', 'Force generation of authenticated tests using Basic Authentication, even if spec doesn\'t declare it. In this case be sure to set USERNAME and USERPASSWD env variables when running tests') | ||
.option('-o, --out [outDir]', 'Output directory for generated test files. Default: ./test/api-swag') | ||
.option('-f, --forceAuth', 'Force generation of authenticated tests using Basic Authentication, even if spec doesn\'t declare it. In this case be sure to set USERNAME and USERPASSWD env variables when running tests') | ||
.parse(process.argv); | ||
|
||
if(typeof specFile === 'undefined') { | ||
console.log('\n Nothing to do here... API specification file / URL not provided'); | ||
process.exit(1); | ||
} else { | ||
let swaggerPath = ( specFile.startsWith('http:') || specFile.startsWith('https:') ) ? specFile : `file://${path.resolve(specFile)}`; | ||
if( swaggerPath.startsWith('file:') && !fs.existsSync(path.resolve(specFile)) ) { | ||
console.log('\n Specified file doesn\'t exist. Please check it.\n'); | ||
process.exit(1); | ||
} | ||
console.log(`\nGenerating API tests for ${specFile}`); | ||
console.log(`Target directory is ${program.out ? program.out : '(DEFAULTING to) ./api-swag'}`); | ||
if(program.forceAuth) { | ||
console.log('Basic Authorization forcing enabled.'); | ||
} | ||
|
||
generator.run(swaggerPath, program.out, {forcedAuth: program.forceAuth ? true : false}) | ||
.then( files => { | ||
console.log('\nGenerated files:'); | ||
for( f of files ) { | ||
console.log(f); | ||
} | ||
console.log(`${program.out ? program.out : process.cwd()+'/api-swag'}/package.json`); | ||
console.log('\n'); | ||
console.log('HOW TO run tests:'); | ||
console.log('1. (optional) if APIs are authenticated through Basic Authentication (or -f flag is used), set USERNAME and USERPASSWD env variables'); | ||
console.log(`2. cd ${program.out ? program.out : './api-swag'} && npm i && [USERNAME=<username> USERPASSWD=<userpasswd>] npm test\n`); | ||
console.log('Example: USERNAME=james USERPASSWD=my$trongPa$$word npm test\n'); | ||
|
||
} ) | ||
.catch( err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
|
||
} | ||
if (typeof specFile === 'undefined') { | ||
console.log('\n Nothing to do here... API specification file / URL not provided'); | ||
process.exit(1); | ||
} else { | ||
const swaggerPath = (specFile.startsWith('http:') || specFile.startsWith('https:')) ? specFile : `file://${path.resolve(specFile)}`; | ||
if (swaggerPath.startsWith('file:') && !fs.existsSync(path.resolve(specFile))) { | ||
console.log('\n Specified file doesn\'t exist. Please check it.\n'); | ||
process.exit(1); | ||
} | ||
console.log(`\nGenerating API tests for ${specFile}`); | ||
console.log(`Target directory is ${program.out ? program.out : '(DEFAULTING to) ./api-swag'}`); | ||
if (program.forceAuth) { | ||
console.log('Basic Authorization forcing enabled.'); | ||
} | ||
|
||
generator.run(swaggerPath, program.out, { forcedAuth: Boolean(program.forceAuth) }) | ||
.then((files) => { | ||
console.log('\nGenerated files:'); | ||
for (const f of files) { | ||
console.log(f); | ||
} | ||
const altPath = `${process.cwd()}/api-swag`; | ||
console.log(`${program.out ? program.out : altPath}/package.json`); | ||
console.log('\n'); | ||
console.log('HOW TO run tests:'); | ||
console.log('1. (optional) if APIs are authenticated through Basic Authentication (or -f flag is used), set USERNAME and USERPASSWD env variables'); | ||
console.log(`2. cd ${program.out ? program.out : './api-swag'} && npm i && [USERNAME=<username> USERPASSWD=<userpasswd>] npm test\n`); | ||
console.log('Example: USERNAME=james USERPASSWD=my$trongPa$$word npm test\n'); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.