Skip to content

Commit 83becaf

Browse files
committedMar 19, 2020
refactor: Added ava lint rules and fixed errors
Fixed issues: - test/unit/util.js was being ignored - fixed - test/util.js moved to test/_util.js to be implicitly ignored by ava instead of using an explicit ignore rule - use `t.true` instead of `t.truthy` on boolean values - move `test.after` hooks to be declared before tests are declared, ensuring they are actually run
1 parent 5b02a24 commit 83becaf

File tree

11 files changed

+77
-26
lines changed

11 files changed

+77
-26
lines changed
 

‎.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module.exports = {
33
es6: true
44
},
55
extends: [
6-
'standard'
6+
'standard',
7+
'plugin:ava/recommended'
78
],
89
globals: {
910
Atomics: 'readonly',

‎ava.config.cjs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ module.exports = {
55
API_ENDPOINT: '/api/v1'
66
},
77
files: [
8-
'test/**/*.js',
9-
'!**/util.*'
8+
'test/**/*.js'
109
],
1110
timeout: '30000'
1211
}

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"dependencies": {
2525
"ajv": "^6.11.0",
2626
"email-validator": "^2.0.4",
27+
"eslint-plugin-ava": "^10.2.0",
2728
"express": "^4.17.1",
2829
"mustache": "^4.0.0",
2930
"node-pg-migrate": "^4.2.2",
File renamed without changes.

‎test/integration/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test.serial('PORT env flag', async t => {
1313
require('../../index')
1414

1515
const resp = await got(`http://localhost:${PORT}`)
16-
t.truthy(resp.body !== undefined)
16+
t.true(resp.body !== undefined)
1717

1818
process.env.PORT = old
1919
})
@@ -26,7 +26,7 @@ test.serial('TEST_COMPRESSION env flag', async t => {
2626
.get('/favicon.ico')
2727
.expect('Content-Encoding', /gzip/)
2828

29-
t.truthy(resp.body !== undefined)
29+
t.true(resp.body !== undefined)
3030

3131
process.env.TEST_COMPRESSION = old
3232
reloadModule('../../app')

‎test/integration/auth.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ const config = require('../../config/server')
77
const { responseList } = require('../../server/responses')
88
const database = require('../../server/database')
99
const auth = require('../../server/auth')
10-
const util = require('../util')
10+
const util = require('../_util')
1111

1212
const testUser = util.generateTestUser()
1313

14+
test.after.always('cleanup test user', async t => {
15+
await removeUserByEmail({
16+
email: testUser.email
17+
})
18+
})
19+
1420
test('fails with badEmail', async t => {
1521
const resp = await request(app)
1622
.post(process.env.API_ENDPOINT + '/auth/register')
@@ -129,9 +135,3 @@ test.serial('succeeds with goodUserDelete', async t => {
129135

130136
t.is(resp.body.kind, 'goodUserDelete')
131137
})
132-
133-
test.after.always('cleanup test user', async t => {
134-
await removeUserByEmail({
135-
email: testUser.email
136-
})
137-
})

‎test/integration/challenges.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ test.serial('succeeds with goodChallenges', async t => {
4141
.expect(responseList.goodChallenges.status)
4242

4343
t.is(resp.body.kind, 'goodChallenges')
44-
t.truthy(Array.isArray(resp.body.data))
44+
t.true(Array.isArray(resp.body.data))
4545
})

‎test/integration/leaderboard.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('succeeds with goodLeaderboard', async t => {
1212
.expect(responseList.goodLeaderboard.status)
1313

1414
t.is(resp.body.kind, 'goodLeaderboard')
15-
t.truthy(Array.isArray(resp.body.data.leaderboard))
15+
t.true(Array.isArray(resp.body.data.leaderboard))
1616
})
1717

1818
test('ctftime integration succeeds with goodCtftimeLeaderboard', async t => {
@@ -22,5 +22,5 @@ test('ctftime integration succeeds with goodCtftimeLeaderboard', async t => {
2222
.expect('Content-Type', /json/)
2323
.expect(responseList.goodCtftimeLeaderboard.status)
2424

25-
t.truthy(Array.isArray(resp.body.standings))
25+
t.true(Array.isArray(resp.body.standings))
2626
})

‎test/integration/submit.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ const db = require('../../server/database')
77
const challenges = require('../../server/challenges')
88
const { responseList } = require('../../server/responses')
99
const auth = require('../../server/auth')
10-
const util = require('../util')
10+
const util = require('../_util')
1111

1212
const chall = challenges.getAllChallenges()[0]
1313

14+
test.after.always('remove solves from test user', async t => {
15+
await db.solves.removeSolvesByUserId({ userid: uuid })
16+
await db.auth.removeUserById({
17+
id: testUser.id
18+
})
19+
})
20+
1421
test('fails with unauthorized', async t => {
1522
const resp = await request(app)
1623
.post(process.env.API_ENDPOINT + '/challs/1/submit')
@@ -72,10 +79,3 @@ test.serial('fails with badAlreadySolvedChallenge', async t => {
7279

7380
t.is(resp.body.kind, 'badAlreadySolvedChallenge')
7481
})
75-
76-
test.after.always('remove solves from test user', async t => {
77-
await db.solves.removeSolvesByUserId({ userid: uuid })
78-
await db.auth.removeUserById({
79-
id: testUser.id
80-
})
81-
})

‎test/unit/challenges.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ const challenges = require('../../server/challenges')
55
test('get all challenges', t => {
66
const data = challenges.getAllChallenges()
77

8-
t.truthy(Array.isArray(data))
8+
t.true(Array.isArray(data))
99
})

‎yarn.lock

+52-2
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,11 @@ browserslist@^4.8.2:
18081808
node-releases "^1.1.52"
18091809
pkg-up "^3.1.0"
18101810

1811+
buf-compare@^1.0.0:
1812+
version "1.0.1"
1813+
resolved "https://registry.yarnpkg.com/buf-compare/-/buf-compare-1.0.1.tgz#fef28da8b8113a0a0db4430b0b6467b69730b34a"
1814+
integrity sha1-/vKNqLgROgoNtEMLC2Rntpcws0o=
1815+
18111816
buffer-alloc-unsafe@^1.1.0:
18121817
version "1.1.0"
18131818
resolved "https://registry.yarnpkg.com/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz#bd7dc26ae2972d0eda253be061dba992349c19f0"
@@ -2668,6 +2673,14 @@ copy-webpack-plugin@^4.1.0:
26682673
p-limit "^1.0.0"
26692674
serialize-javascript "^1.4.0"
26702675

2676+
core-assert@^0.2.0:
2677+
version "0.2.1"
2678+
resolved "https://registry.yarnpkg.com/core-assert/-/core-assert-0.2.1.tgz#f85e2cf9bfed28f773cc8b3fa5c5b69bdc02fe3f"
2679+
integrity sha1-+F4s+b/tKPdzzIs/pcW2m9wC/j8=
2680+
dependencies:
2681+
buf-compare "^1.0.0"
2682+
is-error "^2.2.0"
2683+
26712684
core-js-pure@^3.0.0:
26722685
version "3.6.4"
26732686
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.6.4.tgz#4bf1ba866e25814f149d4e9aaa08c36173506e3a"
@@ -3095,6 +3108,13 @@ deep-is@~0.1.3:
30953108
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
30963109
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
30973110

3111+
deep-strict-equal@^0.2.0:
3112+
version "0.2.0"
3113+
resolved "https://registry.yarnpkg.com/deep-strict-equal/-/deep-strict-equal-0.2.0.tgz#4a078147a8ab57f6a0d4f5547243cd22f44eb4e4"
3114+
integrity sha1-SgeBR6irV/ag1PVUckPNIvROtOQ=
3115+
dependencies:
3116+
core-assert "^0.2.0"
3117+
30983118
default-require-extensions@^3.0.0:
30993119
version "3.0.0"
31003120
resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-3.0.0.tgz#e03f93aac9b2b6443fc52e5e4a37b3ad9ad8df96"
@@ -3491,6 +3511,13 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0:
34913511
dependencies:
34923512
once "^1.4.0"
34933513

3514+
enhance-visitors@^1.0.0:
3515+
version "1.0.0"
3516+
resolved "https://registry.yarnpkg.com/enhance-visitors/-/enhance-visitors-1.0.0.tgz#aa945d05da465672a1ebd38fee2ed3da8518e95a"
3517+
integrity sha1-qpRdBdpGVnKh69OP7i7T2oUY6Vo=
3518+
dependencies:
3519+
lodash "^4.13.1"
3520+
34943521
enhanced-resolve@^3.4.0:
34953522
version "3.4.1"
34963523
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.4.1.tgz#0421e339fd71419b3da13d129b3979040230476e"
@@ -3700,6 +3727,19 @@ eslint-module-utils@^2.4.1:
37003727
debug "^2.6.9"
37013728
pkg-dir "^2.0.0"
37023729

3730+
eslint-plugin-ava@^10.2.0:
3731+
version "10.2.0"
3732+
resolved "https://registry.yarnpkg.com/eslint-plugin-ava/-/eslint-plugin-ava-10.2.0.tgz#02c5d91458ddca3b8a116826a803b09fada462f6"
3733+
integrity sha512-1EP9Mn/pau+ZxwRPDspiioRD6GHCSz7RywTmqW01JTxXvX0vKEV0odfWe+QL+jXfmqd83SHHvDJfOvYcyzoxYA==
3734+
dependencies:
3735+
deep-strict-equal "^0.2.0"
3736+
enhance-visitors "^1.0.0"
3737+
espree "^6.1.2"
3738+
espurify "^2.0.1"
3739+
import-modules "^2.0.0"
3740+
pkg-dir "^4.2.0"
3741+
resolve-from "^5.0.0"
3742+
37033743
eslint-plugin-compat@^3.5.1:
37043744
version "3.5.1"
37053745
resolved "https://registry.yarnpkg.com/eslint-plugin-compat/-/eslint-plugin-compat-3.5.1.tgz#09f9c05dcfa9b5cd69345d7ab333749813ed8b14"
@@ -3887,6 +3927,11 @@ esprima@^4.0.0:
38873927
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
38883928
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==
38893929

3930+
espurify@^2.0.1:
3931+
version "2.0.1"
3932+
resolved "https://registry.yarnpkg.com/espurify/-/espurify-2.0.1.tgz#c25b3bb613863daa142edcca052370a1a459f41d"
3933+
integrity sha512-7w/dUrReI/QbJFHRwfomTlkQOXaB1NuCrBRn5Y26HXn5gvh18/19AgLbayVrNxXQfkckvgrJloWyvZDuJ7dhEA==
3934+
38903935
esquery@^1.0.1:
38913936
version "1.1.0"
38923937
resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.1.0.tgz#c5c0b66f383e7656404f86b31334d72524eddb48"
@@ -5225,6 +5270,11 @@ import-local@^3.0.2:
52255270
pkg-dir "^4.2.0"
52265271
resolve-cwd "^3.0.0"
52275272

5273+
import-modules@^2.0.0:
5274+
version "2.0.0"
5275+
resolved "https://registry.yarnpkg.com/import-modules/-/import-modules-2.0.0.tgz#9c1e13b4e7a15682f70a6e3fa29534e4540cfc5d"
5276+
integrity sha512-iczM/v9drffdNnABOKwj0f9G3cFDon99VcG1mxeBsdqnbd+vnQ5c2uAiCHNQITqFTOPaEvwg3VjoWCur0uHLEw==
5277+
52285278
imurmurhash@^0.1.4:
52295279
version "0.1.4"
52305280
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
@@ -5484,7 +5534,7 @@ is-directory@^0.3.1:
54845534
resolved "https://registry.yarnpkg.com/is-directory/-/is-directory-0.3.1.tgz#61339b6f2475fc772fd9c9d83f5c8575dc154ae1"
54855535
integrity sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=
54865536

5487-
is-error@^2.2.2:
5537+
is-error@^2.2.0, is-error@^2.2.2:
54885538
version "2.2.2"
54895539
resolved "https://registry.yarnpkg.com/is-error/-/is-error-2.2.2.tgz#c10ade187b3c93510c5470a5567833ee25649843"
54905540
integrity sha512-IOQqts/aHWbiisY5DuPJQ0gcbvaLFCa7fBa9xoLfxBZvQ+ZI/Zh9xoI7Gk+G64N0FdK4AbibytHht2tWgpJWLg==
@@ -6228,7 +6278,7 @@ lodash.uniq@^4.5.0:
62286278
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
62296279
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
62306280

6231-
lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.3.0, lodash@~4.17.0:
6281+
lodash@^4.13.1, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.3.0, lodash@~4.17.0:
62326282
version "4.17.15"
62336283
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
62346284
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==

0 commit comments

Comments
 (0)
Please sign in to comment.