Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(build): package updates #22

Merged
merged 2 commits into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ api-debug*
# misc
.env
.docs
.fixtures
15 changes: 6 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
language: node_js

node_js:
- "10"
cache: yarn

jobs:
include:
- stage: test
env:
- NAME=yarn
node_js: "10"
before_script: yarn global add codecov
script: yarn test
after_success: codecov
- stage: Test
before_script: yarn global add codecov
script: yarn test
after_success: codecov
35 changes: 19 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"release": "standard-version",
"start": "./bin/cli.js -w ./data",
"start:dev": "nodemon --watch data --watch src './bin/cli.js -w ./data'",
"test": "CI=true; eslint ./src; jest --collectCoverage",
"test": "run-s -l test:lint test:ci",
"test:ci": "export CI=true; jest --collectCoverage",
"test:clearCache": "jest --clearCache",
"test:dev": "eslint ./src; jest --watch",
"test:clearCache": "jest --clearCache"
"test:lint": "eslint ./src"
},
"jest": {
"roots": [
Expand All @@ -53,25 +55,26 @@
},
"dependencies": {
"apidoc": "^0.17.7",
"express": "^4.16.4",
"node-watch": "^0.6.1",
"express": "^4.17.1",
"node-watch": "^0.6.2",
"winston": "^3.2.1",
"yargs": "^13.2.2"
"yargs": "^13.3.0"
},
"devDependencies": {
"babel-eslint": "^10.0.1",
"eslint": "^5.16.0",
"babel-eslint": "^10.0.2",
"eslint": "^6.1.0",
"eslint-config-esnext": "^4.0.0",
"eslint-config-node": "^4.0.0",
"eslint-config-prettier": "^4.1.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.17.1",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-prettier": "^3.0.1",
"jest": "^24.7.1",
"nodemon": "^1.18.11",
"prettier": "^1.17.0",
"standard-version": "^5.0.2"
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.14.1",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-prettier": "^3.1.0",
"jest": "^24.8.0",
"nodemon": "^1.19.1",
"npm-run-all": "^4.1.5",
"prettier": "^1.18.2",
"standard-version": "^6.0.1"
}
}
9 changes: 9 additions & 0 deletions src/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ApiDocMock should create a predictable docs output: setupDocs 1`] = `
Object {
"error": "{\\"examples\\":[{\\"title\\":\\"Error-Response:\\",\\"content\\":\\"HTTP/1.1 400 OK\\\\n{\\\\n error: test\\\\n}\\",\\"type\\":\\"json\\"}]}",
"success": "{\\"examples\\":[{\\"title\\":\\"Success-Response:\\",\\"content\\":\\"HTTP/1.1 200 OK\\\\n{\\\\n success: test\\\\n}\\",\\"type\\":\\"json\\"}]}",
"type": "get",
"url": "/hello/world/",
}
`;

exports[`ApiDocMock should throw an error during testing: error 1`] = `[Error: Server failed to load]`;
35 changes: 33 additions & 2 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
const { execSync } = require('child_process');
const { apiDocMock, setupDocs, setupResponse } = require('../');

describe('ApiDocMock', () => {
const tempFile = contents => {
const dir = './.fixtures';
const stdout = execSync(`mkdir -p ${dir}; echo "${contents}" > ${dir}/test.js`);
return { dir, stdout };
};

it('should have specific defined properties', () => {
expect(apiDocMock).toBeDefined();
expect(setupDocs).toBeDefined();
expect(setupResponse).toBeDefined();
});

it('should have support functions that fail gracefully for tests', () => {
expect(setupDocs()).toBe(null);
it('should have support functions that fail gracefully', () => {
expect(setupResponse()).toBe(null);
});

it('should create a predictable docs output', () => {
const { dir } = tempFile(`/**
* @api {get} /hello/world/
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "success": "test"
* }
* @apiErrorExample {json} Error-Response:
* HTTP/1.1 400 OK
* {
* "error": "test"
* }
*/`);

const [helloWorld] = setupDocs(dir, './.docs');

expect({
type: helloWorld.type,
url: helloWorld.url,
success: JSON.stringify(helloWorld.success),
error: JSON.stringify(helloWorld.error)
}).toMatchSnapshot('setupDocs');
});

it('should throw an error during testing', () => {
try {
apiDocMock({});
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const setupDocs = (dataPath = '', docsPath = '') => {
dest,
parsers: {
apimock: path.join(__dirname, './docs/configDocs.js')
}
},
silent: process.env.NODE_ENV === 'test'
};

const apiJsonFile = path.join(cwd, docsPath, 'api_data.json');
Expand Down
Loading