Skip to content

Commit

Permalink
added linting script to test
Browse files Browse the repository at this point in the history
  • Loading branch information
sdstolworthy committed Jul 15, 2020
1 parent a1e88af commit b80ff52
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
'sourceType': 'module'
},
'rules': {
'object-curly-spacing': ['error', 'always'],
'indent': [
'error',
2
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"url": "https://github.com/sdstolworthy/serves-up"
},
"scripts": {
"lint": "eslint src/**/*.js",
"build": "rollup -c rollup.config.js",
"prepare": "npm run build",
"test": "nyc --reporter=lcov --reporter=text --reporter=html mocha tests/**/*.spec.js --exit"
"test": "npm run lint && nyc --reporter=lcov --reporter=text --reporter=html mocha tests/**/*.spec.js --exit"
},
"homepage": "https://github.com/sdstolworthy/serves-up",
"author": "Spencer Stolworthy",
Expand Down Expand Up @@ -55,4 +56,4 @@
"api",
"testing"
]
}
}
2 changes: 1 addition & 1 deletion src/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Express from 'express';
import chalk from 'chalk';
import { addRouteToApp } from './route';
import {createDefinition, onLoadFixture, getReferenceFilePath} from './server_definition';
import { createDefinition, onLoadFixture, getReferenceFilePath } from './server_definition';
import cors from 'cors';
import morgan from 'morgan';

Expand Down
2 changes: 1 addition & 1 deletion tests/files.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as files from '../src/files';
import fs from 'fs';
import path from 'path';
import {expect} from 'chai';
import { expect } from 'chai';
import process from 'process';

const TEST_FILE_PATH = './__test_file';
Expand Down
2 changes: 1 addition & 1 deletion tests/route.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from 'express';
import {addRouteToApp} from '../src/route';
import { addRouteToApp } from '../src/route';
import { expect } from 'chai';
describe('Route tests:', function() {
it('should throw an error when adding a route to the server that does not have a path', function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/server.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import chai from 'chai';
import {runServer, close} from '../src/server';
import { runServer, close } from '../src/server';
import chaihttp from 'chai-http';
import fs from 'fs';

Expand Down
13 changes: 6 additions & 7 deletions tests/server_definition.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import {
onLoadFixture,
getReferenceFilePath,
} from '../src/server_definition';
import {close as closeServer} from '../src/server';
import { close as closeServer } from '../src/server';
import fs from 'fs';
const { expect } = chai;


describe('Server definition factory', function() {
before(function() {
fs.writeFileSync(
Expand Down Expand Up @@ -228,7 +227,7 @@ describe('Server definition factory', function() {
fs.writeFileSync('./no-port.json', JSON.stringify({
routes: []
}));
expect(createDefinition({inputFile: './no-port.json'}, () => {})).to.deep.equal({
expect(createDefinition({ inputFile: './no-port.json' }, () => {})).to.deep.equal({
'port': 3000,
'routes': []
});
Expand All @@ -237,19 +236,19 @@ describe('Server definition factory', function() {
it('defaults to an empty array of routes when no route is defined', function() {
fs.writeFileSync('./no-routes.json', JSON.stringify({
}));
expect(createDefinition({inputFile: './no-routes.json'}, () => {})).to.deep.equal({
expect(createDefinition({ inputFile: './no-routes.json' }, () => {})).to.deep.equal({
'port': 3000,
'routes': []
});
fs.unlinkSync('./no-routes.json');
});
it('when a route is defined without a return statusCode, it defaults to `200`', function() {
fs.writeFileSync('./no-return-status-code.json', JSON.stringify({
routes: [{path: '/*'}]
routes: [{ path: '/*' }]
}));
expect(createDefinition({inputFile: './no-return-status-code.json'}, () => {})).to.deep.equal({
expect(createDefinition({ inputFile: './no-return-status-code.json' }, () => {})).to.deep.equal({
'port': 3000,
'routes': [{path: '/*', statusCode: 200, fixture: undefined}],
'routes': [{ path: '/*', statusCode: 200, fixture: undefined }],
});
fs.unlinkSync('./no-return-status-code.json');
});
Expand Down

0 comments on commit b80ff52

Please sign in to comment.