Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Commit

Permalink
refactor: Added ava lint rules and fixed errors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ethanwu10 committed Mar 19, 2020
1 parent 5b02a24 commit 83becaf
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = {
es6: true
},
extends: [
'standard'
'standard',
'plugin:ava/recommended'
],
globals: {
Atomics: 'readonly',
Expand Down
3 changes: 1 addition & 2 deletions ava.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ module.exports = {
API_ENDPOINT: '/api/v1'
},
files: [
'test/**/*.js',
'!**/util.*'
'test/**/*.js'
],
timeout: '30000'
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"dependencies": {
"ajv": "^6.11.0",
"email-validator": "^2.0.4",
"eslint-plugin-ava": "^10.2.0",
"express": "^4.17.1",
"mustache": "^4.0.0",
"node-pg-migrate": "^4.2.2",
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test/integration/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test.serial('PORT env flag', async t => {
require('../../index')

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

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

t.truthy(resp.body !== undefined)
t.true(resp.body !== undefined)

process.env.TEST_COMPRESSION = old
reloadModule('../../app')
Expand Down
14 changes: 7 additions & 7 deletions test/integration/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ const config = require('../../config/server')
const { responseList } = require('../../server/responses')
const database = require('../../server/database')
const auth = require('../../server/auth')
const util = require('../util')
const util = require('../_util')

const testUser = util.generateTestUser()

test.after.always('cleanup test user', async t => {
await removeUserByEmail({
email: testUser.email
})
})

test('fails with badEmail', async t => {
const resp = await request(app)
.post(process.env.API_ENDPOINT + '/auth/register')
Expand Down Expand Up @@ -129,9 +135,3 @@ test.serial('succeeds with goodUserDelete', async t => {

t.is(resp.body.kind, 'goodUserDelete')
})

test.after.always('cleanup test user', async t => {
await removeUserByEmail({
email: testUser.email
})
})
2 changes: 1 addition & 1 deletion test/integration/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ test.serial('succeeds with goodChallenges', async t => {
.expect(responseList.goodChallenges.status)

t.is(resp.body.kind, 'goodChallenges')
t.truthy(Array.isArray(resp.body.data))
t.true(Array.isArray(resp.body.data))
})
4 changes: 2 additions & 2 deletions test/integration/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('succeeds with goodLeaderboard', async t => {
.expect(responseList.goodLeaderboard.status)

t.is(resp.body.kind, 'goodLeaderboard')
t.truthy(Array.isArray(resp.body.data.leaderboard))
t.true(Array.isArray(resp.body.data.leaderboard))
})

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

t.truthy(Array.isArray(resp.body.standings))
t.true(Array.isArray(resp.body.standings))
})
16 changes: 8 additions & 8 deletions test/integration/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ const db = require('../../server/database')
const challenges = require('../../server/challenges')
const { responseList } = require('../../server/responses')
const auth = require('../../server/auth')
const util = require('../util')
const util = require('../_util')

const chall = challenges.getAllChallenges()[0]

test.after.always('remove solves from test user', async t => {
await db.solves.removeSolvesByUserId({ userid: uuid })
await db.auth.removeUserById({
id: testUser.id
})
})

test('fails with unauthorized', async t => {
const resp = await request(app)
.post(process.env.API_ENDPOINT + '/challs/1/submit')
Expand Down Expand Up @@ -72,10 +79,3 @@ test.serial('fails with badAlreadySolvedChallenge', async t => {

t.is(resp.body.kind, 'badAlreadySolvedChallenge')
})

test.after.always('remove solves from test user', async t => {
await db.solves.removeSolvesByUserId({ userid: uuid })
await db.auth.removeUserById({
id: testUser.id
})
})
2 changes: 1 addition & 1 deletion test/unit/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ const challenges = require('../../server/challenges')
test('get all challenges', t => {
const data = challenges.getAllChallenges()

t.truthy(Array.isArray(data))
t.true(Array.isArray(data))
})
54 changes: 52 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,11 @@ browserslist@^4.8.2:
node-releases "^1.1.52"
pkg-up "^3.1.0"

buf-compare@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/buf-compare/-/buf-compare-1.0.1.tgz#fef28da8b8113a0a0db4430b0b6467b69730b34a"
integrity sha1-/vKNqLgROgoNtEMLC2Rntpcws0o=

buffer-alloc-unsafe@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz#bd7dc26ae2972d0eda253be061dba992349c19f0"
Expand Down Expand Up @@ -2668,6 +2673,14 @@ copy-webpack-plugin@^4.1.0:
p-limit "^1.0.0"
serialize-javascript "^1.4.0"

core-assert@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/core-assert/-/core-assert-0.2.1.tgz#f85e2cf9bfed28f773cc8b3fa5c5b69bdc02fe3f"
integrity sha1-+F4s+b/tKPdzzIs/pcW2m9wC/j8=
dependencies:
buf-compare "^1.0.0"
is-error "^2.2.0"

core-js-pure@^3.0.0:
version "3.6.4"
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.6.4.tgz#4bf1ba866e25814f149d4e9aaa08c36173506e3a"
Expand Down Expand Up @@ -3095,6 +3108,13 @@ deep-is@~0.1.3:
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=

deep-strict-equal@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/deep-strict-equal/-/deep-strict-equal-0.2.0.tgz#4a078147a8ab57f6a0d4f5547243cd22f44eb4e4"
integrity sha1-SgeBR6irV/ag1PVUckPNIvROtOQ=
dependencies:
core-assert "^0.2.0"

default-require-extensions@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-3.0.0.tgz#e03f93aac9b2b6443fc52e5e4a37b3ad9ad8df96"
Expand Down Expand Up @@ -3491,6 +3511,13 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0:
dependencies:
once "^1.4.0"

enhance-visitors@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/enhance-visitors/-/enhance-visitors-1.0.0.tgz#aa945d05da465672a1ebd38fee2ed3da8518e95a"
integrity sha1-qpRdBdpGVnKh69OP7i7T2oUY6Vo=
dependencies:
lodash "^4.13.1"

enhanced-resolve@^3.4.0:
version "3.4.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.4.1.tgz#0421e339fd71419b3da13d129b3979040230476e"
Expand Down Expand Up @@ -3700,6 +3727,19 @@ eslint-module-utils@^2.4.1:
debug "^2.6.9"
pkg-dir "^2.0.0"

eslint-plugin-ava@^10.2.0:
version "10.2.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-ava/-/eslint-plugin-ava-10.2.0.tgz#02c5d91458ddca3b8a116826a803b09fada462f6"
integrity sha512-1EP9Mn/pau+ZxwRPDspiioRD6GHCSz7RywTmqW01JTxXvX0vKEV0odfWe+QL+jXfmqd83SHHvDJfOvYcyzoxYA==
dependencies:
deep-strict-equal "^0.2.0"
enhance-visitors "^1.0.0"
espree "^6.1.2"
espurify "^2.0.1"
import-modules "^2.0.0"
pkg-dir "^4.2.0"
resolve-from "^5.0.0"

eslint-plugin-compat@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-compat/-/eslint-plugin-compat-3.5.1.tgz#09f9c05dcfa9b5cd69345d7ab333749813ed8b14"
Expand Down Expand Up @@ -3887,6 +3927,11 @@ esprima@^4.0.0:
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==

espurify@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/espurify/-/espurify-2.0.1.tgz#c25b3bb613863daa142edcca052370a1a459f41d"
integrity sha512-7w/dUrReI/QbJFHRwfomTlkQOXaB1NuCrBRn5Y26HXn5gvh18/19AgLbayVrNxXQfkckvgrJloWyvZDuJ7dhEA==

esquery@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.1.0.tgz#c5c0b66f383e7656404f86b31334d72524eddb48"
Expand Down Expand Up @@ -5225,6 +5270,11 @@ import-local@^3.0.2:
pkg-dir "^4.2.0"
resolve-cwd "^3.0.0"

import-modules@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/import-modules/-/import-modules-2.0.0.tgz#9c1e13b4e7a15682f70a6e3fa29534e4540cfc5d"
integrity sha512-iczM/v9drffdNnABOKwj0f9G3cFDon99VcG1mxeBsdqnbd+vnQ5c2uAiCHNQITqFTOPaEvwg3VjoWCur0uHLEw==

imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
Expand Down Expand Up @@ -5484,7 +5534,7 @@ is-directory@^0.3.1:
resolved "https://registry.yarnpkg.com/is-directory/-/is-directory-0.3.1.tgz#61339b6f2475fc772fd9c9d83f5c8575dc154ae1"
integrity sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=

is-error@^2.2.2:
is-error@^2.2.0, is-error@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/is-error/-/is-error-2.2.2.tgz#c10ade187b3c93510c5470a5567833ee25649843"
integrity sha512-IOQqts/aHWbiisY5DuPJQ0gcbvaLFCa7fBa9xoLfxBZvQ+ZI/Zh9xoI7Gk+G64N0FdK4AbibytHht2tWgpJWLg==
Expand Down Expand Up @@ -6228,7 +6278,7 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=

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:
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:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
Expand Down

0 comments on commit 83becaf

Please sign in to comment.