Skip to content

Commit 47efffe

Browse files
committed
Enforce ES5 and expand linting to test/
1 parent 85a1162 commit 47efffe

File tree

5 files changed

+83
-42
lines changed

5 files changed

+83
-42
lines changed

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@
3333
},
3434
"extends": "eslint:recommended",
3535
"globals": {
36-
"define": true
36+
"define": true,
37+
"describe": true,
38+
"it": true,
39+
"expect": true,
40+
"yea": true,
41+
"__dirname": true,
42+
"process": true
3743
},
3844
"parserOptions": {
39-
"ecmaVersion": 2018
45+
"ecmaVersion": 5
4046
},
4147
"rules": {}
4248
},
@@ -55,7 +61,7 @@
5561
"watch": "mkdir -p build && cp src/index.js build/yea.js && nodemon --exec 'yarn build' --watch src src/index.js",
5662
"build": "mkdir -p build && cp src/index.js build/yea.js && uglifyjs src/index.js --comments > build/yea.min.js",
5763
"bundlesize": "bundlesize",
58-
"lint": "eslint src",
64+
"lint": "eslint src test",
5965
"karma": "karma start test/karma.conf.js --single-run",
6066
"commonjs-test": "node test/commonjs-test.js",
6167
"test": "yarn lint && yarn build && yarn bundlesize && yarn commonjs-test && yarn karma",

test/commonjs-test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
// This test is for ensuring that those using browserify will be able to require the module
22

3-
const assert = require('assert');
4-
const path = require('path');
5-
const rootPath = path.join(__dirname, '..');
3+
var assert = require('assert');
4+
var path = require('path');
5+
var rootPath = path.join(__dirname, '..');
66

7-
const packageJson = require(path.join(rootPath, 'package.json'));
8-
const yea = require(path.join(rootPath, packageJson.main));
7+
var packageJson = require(path.join(rootPath, 'package.json'));
8+
var yea = require(path.join(rootPath, packageJson.main));
99

1010
try {
1111
assert(yea);
1212
assert(yea.constructor);
1313
assert.equal(yea.constructor.name, 'YeaAjaxRequest');
1414
} catch (error) {
15+
/* eslint-disable no-console */
1516
console.error('CommonJS test file errored!');
1617
console.error('');
1718
console.error(error.stack);
19+
process.exit(1);
1820
}

test/karma.conf.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const helperServer = require('./server/helper-server');
1+
var helperServer = require('./server/helper-server');
22

33
module.exports = function(config) {
44
// Karma config is some of the most horrifying things I've seen... anyway, here goes
55

6-
const configuration = {
6+
var configuration = {
77
basePath: '../',
88
files: [
99
'node_modules/es6-promise/dist/es6-promise.auto.min.js',
@@ -33,7 +33,7 @@ module.exports = function(config) {
3333
'karma-chai',
3434
'karma-chrome-launcher',
3535
'karma-mocha',
36-
{'middleware:helper-server': ['factory', function(config) {
36+
{'middleware:helper-server': ['factory', function() {
3737
return helperServer;
3838
}]}
3939
]

test/server/helper-server.js

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
const bodyParser = require('body-parser');
2-
const express = require('express');
1+
var bodyParser = require('body-parser');
2+
var express = require('express');
33

44
// This server provides useful routes for testing various AJAX requests
55

6-
const app = express();
6+
var app = express();
77

88
// Parse all request bodies into string, no decoding
99
app.use(bodyParser.text({ type: '*/*' }));
1010

11-
app.get('/simple-get', (req, res, next) => res.send('hello'));
12-
app.get('/nested/simple-get', (req, res, next) => res.send('nested hello'));
13-
app.post('/dump-request-body', (req, res, next) => res.send(req.body));
14-
app.get('/dump-headers', (req, res, next) => res.send(
15-
Object.keys(req.headers).sort().map(name => `${name}: ${req.headers[name]}`).join('\n')
16-
));
17-
app.get('/dump-query', (req, res, next) => res.send(
18-
Object.keys(req.query).sort().map(key => `${key}: ${req.query[key]}`).join('\n')
19-
));
20-
app.post('/validate-urlencoded-request', (req, res, next) => {
11+
app.get('/simple-get', function (req, res) {
12+
return res.send('hello');
13+
});
14+
app.get('/nested/simple-get', function (req, res) {
15+
return res.send('nested hello');
16+
});
17+
app.post('/dump-request-body', function (req, res) {
18+
return res.send(req.body);
19+
});
20+
app.get('/dump-headers', function (req, res) {
21+
return res.send(Object.keys(req.headers).sort().map(function (name) {
22+
return "".concat(name, ": ").concat(req.headers[name]);
23+
}).join('\n'));
24+
});
25+
app.get('/dump-query', function (req, res) {
26+
return res.send(Object.keys(req.query).sort().map(function (key) {
27+
return "".concat(key, ": ").concat(req.query[key]);
28+
}).join('\n'));
29+
});
30+
app.post('/validate-urlencoded-request', function (req, res) {
2131
if (req.headers['content-type'] !== 'application/x-www-form-urlencoded') {
2232
res.status(400).send('FAIL (header)');
2333
} else if (req.body !== 'hello=there&whats=up') {
@@ -26,7 +36,7 @@ app.post('/validate-urlencoded-request', (req, res, next) => {
2636
res.set('content-type', 'text/plain').send('PASS');
2737
}
2838
});
29-
app.post('/validate-json-request', (req, res, next) => {
39+
app.post('/validate-json-request', function (req, res) {
3040
if (req.headers['content-type'] !== 'application/json') {
3141
res.status(400).send('FAIL (header)');
3242
} else {
@@ -37,10 +47,24 @@ app.post('/validate-json-request', (req, res, next) => {
3747
}
3848
}
3949
});
40-
app.get('/dummy-headers', (req, res, next) => res.set({ 'x-dummy': 'definitely' }).send(''));
41-
app.get('/json-payload', (req, res, next) => res.set('content-type', 'application/json').send('{"taker":"believer"}'));
42-
app.get('/json-payload-fail', (req, res, next) => res.status(400).set('content-type', 'application/json').send('{"taker":"believer"}'));
43-
app.get('/specific-status', (req, res, next) => res.status(req.query.give).send(''));
44-
app.get('/specific-timeout', (req, res, next) => setTimeout(() => res.send('made it'), req.query.wait));
50+
app.get('/dummy-headers', function (req, res) {
51+
return res.set({
52+
'x-dummy': 'definitely'
53+
}).send('');
54+
});
55+
app.get('/json-payload', function (req, res) {
56+
return res.set('content-type', 'application/json').send('{"taker":"believer"}');
57+
});
58+
app.get('/json-payload-fail', function (req, res) {
59+
return res.status(400).set('content-type', 'application/json').send('{"taker":"believer"}');
60+
});
61+
app.get('/specific-status', function (req, res) {
62+
return res.status(req.query.give).send('');
63+
});
64+
app.get('/specific-timeout', function (req, res) {
65+
return setTimeout(function () {
66+
return res.send('made it');
67+
}, req.query.wait);
68+
});
4569

4670
module.exports = app;

test/server/mocha-server.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
const bodyParser = require('body-parser');
2-
const express = require('express');
3-
const path = require('path');
4-
const helperServer = require('./helper-server');
1+
var express = require('express');
2+
var path = require('path');
3+
var helperServer = require('./helper-server');
54

65
// This file starts a HTTP server which serves the Mocha HTML runner
76
// See also: mocha.html
87

9-
const app = express();
8+
var app = express();
109
app.use(helperServer);
1110

12-
app.get('/', (req, res, next) => res.sendFile(path.join(__dirname, 'mocha.html')));
13-
app.get('/mocha.css', (req, res, next) => res.sendFile(path.join(__dirname, '../../node_modules/mocha/mocha.css')));
14-
app.get('/mocha.js', (req, res, next) => res.sendFile(path.join(__dirname, '../../node_modules/mocha/mocha.js')));
15-
app.get('/chai.js', (req, res, next) => res.sendFile(path.join(__dirname, '../../node_modules/chai/chai.js')));
16-
app.get('/yea.min.js', (req, res, next) => res.sendFile(path.join(__dirname, '../../build/yea.min.js')));
11+
app.get('/', function (req, res) {
12+
return res.sendFile(path.join(__dirname, 'mocha.html'));
13+
});
14+
app.get('/mocha.css', function (req, res) {
15+
return res.sendFile(path.join(__dirname, '../../node_modules/mocha/mocha.css'));
16+
});
17+
app.get('/mocha.js', function (req, res) {
18+
return res.sendFile(path.join(__dirname, '../../node_modules/mocha/mocha.js'));
19+
});
20+
app.get('/chai.js', function (req, res) {
21+
return res.sendFile(path.join(__dirname, '../../node_modules/chai/chai.js'));
22+
});
23+
app.get('/yea.min.js', function (req, res) {
24+
return res.sendFile(path.join(__dirname, '../../build/yea.min.js'));
25+
});
1726
app.use('/specs', express.static(path.join(__dirname, '../specs')));
18-
19-
app.listen(9876, () => {
27+
app.listen(9876, function () {
28+
/* eslint-disable no-console */
2029
console.log('Test server is running!');
2130
console.log('Open http://localhost:9876/ in your browser');
2231
});

0 commit comments

Comments
 (0)