[misc] bump the dev-env to 3.3.2

This commit is contained in:
Jakob Ackermann 2020-08-10 17:23:15 +01:00
parent 5037162f3d
commit c722a79e93
30 changed files with 254 additions and 353 deletions

View file

@ -8,7 +8,7 @@
"prettier/standard"
],
"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2018
},
"plugins": [
"mocha",

View file

@ -0,0 +1,17 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
pull-request-branch-name:
# Separate sections of the branch name with a hyphen
# Docker images use the branch name and do not support slashes in tags
# https://github.com/overleaf/google-ops/issues/822
# https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#pull-request-branch-nameseparator
separator: "-"
# Block informal upgrades -- security upgrades use a separate queue.
# https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#open-pull-requests-limit
open-pull-requests-limit: 0

View file

@ -3,3 +3,6 @@
node_modules/*
cache/spell.cache
**/*.map
# managed by dev-environment$ bin/update_build_scripts
.npmrc

View file

@ -17,8 +17,6 @@ RUN npm ci --quiet
COPY . /app
FROM base
COPY --from=app /app /app

View file

@ -1,131 +0,0 @@
String cron_string = BRANCH_NAME == "master" ? "@daily" : ""
pipeline {
agent any
environment {
GIT_PROJECT = "spelling"
JENKINS_WORKFLOW = "spelling-sharelatex"
TARGET_URL = "${env.JENKINS_URL}blue/organizations/jenkins/${JENKINS_WORKFLOW}/detail/$BRANCH_NAME/$BUILD_NUMBER/pipeline"
GIT_API_URL = "https://api.github.com/repos/overleaf/${GIT_PROJECT}/statuses/$GIT_COMMIT"
}
triggers {
pollSCM('* * * * *')
cron(cron_string)
}
stages {
stage('Install') {
steps {
withCredentials([usernamePassword(credentialsId: 'GITHUB_INTEGRATION', usernameVariable: 'GH_AUTH_USERNAME', passwordVariable: 'GH_AUTH_PASSWORD')]) {
sh "curl $GIT_API_URL \
--data '{ \
\"state\" : \"pending\", \
\"target_url\": \"$TARGET_URL\", \
\"description\": \"Your build is underway\", \
\"context\": \"ci/jenkins\" }' \
-u $GH_AUTH_USERNAME:$GH_AUTH_PASSWORD"
}
}
}
stage('Build') {
steps {
sh 'make build'
}
}
stage('Linting') {
steps {
sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make format'
sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make lint'
}
}
stage('Unit Tests') {
steps {
sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make test_unit'
}
}
stage('Acceptance Tests') {
steps {
sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make test_acceptance'
}
}
stage('Package and docker push') {
steps {
sh 'echo ${BUILD_NUMBER} > build_number.txt'
sh 'touch build.tar.gz' // Avoid tar warning about files changing during read
sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make tar'
withCredentials([file(credentialsId: 'gcr.io_overleaf-ops', variable: 'DOCKER_REPO_KEY_PATH')]) {
sh 'docker login -u _json_key --password-stdin https://gcr.io/overleaf-ops < ${DOCKER_REPO_KEY_PATH}'
}
sh 'DOCKER_REPO=gcr.io/overleaf-ops make publish'
sh 'docker logout https://gcr.io/overleaf-ops'
}
}
stage('Publish to s3') {
steps {
sh 'echo ${BRANCH_NAME}-${BUILD_NUMBER} > build_number.txt'
withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
s3Upload(file:'build.tar.gz', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/${BUILD_NUMBER}.tar.gz")
}
withAWS(credentials:'S3_CI_BUILDS_AWS_KEYS', region:"${S3_REGION_BUILD_ARTEFACTS}") {
// The deployment process uses this file to figure out the latest build
s3Upload(file:'build_number.txt', bucket:"${S3_BUCKET_BUILD_ARTEFACTS}", path:"${JOB_NAME}/latest")
}
}
}
}
post {
always {
sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make test_clean'
sh 'make clean'
}
success {
withCredentials([usernamePassword(credentialsId: 'GITHUB_INTEGRATION', usernameVariable: 'GH_AUTH_USERNAME', passwordVariable: 'GH_AUTH_PASSWORD')]) {
sh "curl $GIT_API_URL \
--data '{ \
\"state\" : \"success\", \
\"target_url\": \"$TARGET_URL\", \
\"description\": \"Your build succeeded!\", \
\"context\": \"ci/jenkins\" }' \
-u $GH_AUTH_USERNAME:$GH_AUTH_PASSWORD"
}
}
failure {
mail(from: "${EMAIL_ALERT_FROM}",
to: "${EMAIL_ALERT_TO}",
subject: "Jenkins build failed: ${JOB_NAME}:${BUILD_NUMBER}",
body: "Build: ${BUILD_URL}")
withCredentials([usernamePassword(credentialsId: 'GITHUB_INTEGRATION', usernameVariable: 'GH_AUTH_USERNAME', passwordVariable: 'GH_AUTH_PASSWORD')]) {
sh "curl $GIT_API_URL \
--data '{ \
\"state\" : \"failure\", \
\"target_url\": \"$TARGET_URL\", \
\"description\": \"Your build failed\", \
\"context\": \"ci/jenkins\" }' \
-u $GH_AUTH_USERNAME:$GH_AUTH_PASSWORD"
}
}
}
// The options directive is for configuration that applies to the whole job.
options {
// we'd like to make sure remove old builds, so we don't fill up our storage!
buildDiscarder(logRotator(numToKeepStr:'50'))
// And we'd really like to be sure that this build doesn't hang forever, so let's time it out after:
timeout(time: 30, unit: 'MINUTES')
}
}

View file

@ -25,13 +25,13 @@ clean:
docker rmi gcr.io/overleaf-ops/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
format:
$(DOCKER_COMPOSE) run --rm test_unit npm run format
$(DOCKER_COMPOSE) run --rm test_unit npm run --silent format
format_fix:
$(DOCKER_COMPOSE) run --rm test_unit npm run format:fix
$(DOCKER_COMPOSE) run --rm test_unit npm run --silent format:fix
lint:
$(DOCKER_COMPOSE) run --rm test_unit npm run lint
$(DOCKER_COMPOSE) run --rm test_unit npm run --silent lint
test: format lint test_unit test_acceptance

View file

@ -44,7 +44,7 @@ const port = settings && settings.port ? settings.port : 3005
if (!module.parent) {
// application entry point, called directly
app.listen(port, host, function(error) {
app.listen(port, host, function (error) {
if (error != null) {
throw error
}

View file

@ -34,14 +34,14 @@ try {
}
// write the cache every 30 minutes
const cacheDump = setInterval(function() {
const cacheDump = setInterval(function () {
const dump = JSON.stringify(cache.dump())
return fs.writeFile(cacheFsPathTmp, dump, function(err) {
return fs.writeFile(cacheFsPathTmp, dump, function (err) {
if (err != null) {
logger.log(OError.tag(err, 'error writing cache file'))
fs.unlink(cacheFsPathTmp, () => {})
} else {
fs.rename(cacheFsPathTmp, cacheFsPath, err => {
fs.rename(cacheFsPathTmp, cacheFsPath, (err) => {
if (err) {
logger.error(OError.tag(err, 'error renaming cache file'))
} else {

View file

@ -65,7 +65,7 @@ class ASpellWorker {
this.callback = null
}
})
this.pipe.on('error', err => {
this.pipe.on('error', (err) => {
const previousWorkerState = this.state
if (this.state !== 'killed') {
this.state = 'error'
@ -87,7 +87,7 @@ class ASpellWorker {
logger.warn(err)
}
})
this.pipe.stdin.on('error', err => {
this.pipe.stdin.on('error', (err) => {
const previousWorkerState = this.state
if (this.state !== 'killed') {
this.state = 'error'
@ -114,7 +114,7 @@ class ASpellWorker {
this.pipe.stdout.setEncoding('utf8') // ensure utf8 output is handled correctly
var output = ''
const endMarkerRegex = new RegExp('^[a-z][a-z]', 'gm')
this.pipe.stdout.on('data', data => {
this.pipe.stdout.on('data', (data) => {
// We receive the language code from Aspell as the end of data marker in
// the data. The input is a utf8 encoded string.
const oldPos = output.length
@ -144,7 +144,7 @@ class ASpellWorker {
})
var error = ''
this.pipe.stderr.on('data', chunk => {
this.pipe.stderr.on('data', (chunk) => {
return (error = error + chunk)
})

View file

@ -56,7 +56,9 @@ class ASpellWorkerPool {
}
cleanup() {
const active = this.PROCESS_POOL.filter(worker => worker.state !== 'killed')
const active = this.PROCESS_POOL.filter(
(worker) => worker.state !== 'killed'
)
this.PROCESS_POOL = active
return metrics.gauge('aspellWorkerPool-size', this.PROCESS_POOL.length)
}
@ -66,7 +68,7 @@ class ASpellWorkerPool {
let worker
const availableWorker = _.find(
this.PROCESS_POOL,
cached => cached.language === language && cached.isReady()
(cached) => cached.language === language && cached.isReady()
)
if (availableWorker == null) {
worker = this.create(language)
@ -103,7 +105,7 @@ class ASpellWorkerPool {
return worker.shutdown(`reached limit of ${this.MAX_REQUESTS} requests`)
} else {
// queue a shutdown if worker is idle
return (worker.idleTimer = setTimeout(function() {
return (worker.idleTimer = setTimeout(function () {
worker.shutdown('idle worker')
return (worker.idleTimer = null)
}, this.MAX_IDLE_TIME))

View file

@ -13,7 +13,7 @@ module.exports = {
},
timeout: 1000 * 20
}
return request.post(opts, function(err, response, body) {
return request.post(opts, function (err, response, body) {
if (err != null) {
return res.sendStatus(500)
}

View file

@ -54,7 +54,7 @@ const LearnedWordsManager = {
metrics.inc('mongoCache', 0.1, { status: 'miss' })
logger.info({ userToken }, 'mongoCache miss')
db.spellingPreferences.findOne({ token: userToken }, function(
db.spellingPreferences.findOne({ token: userToken }, function (
error,
preferences
) {
@ -94,7 +94,7 @@ const promises = {
LearnedWordsManager.promises = promises
module.exports = LearnedWordsManager
;['learnWord', 'unlearnWord', 'getLearnedWords'].map(method =>
;['learnWord', 'unlearnWord', 'getLearnedWords'].map((method) =>
metrics.timeAsyncMethod(
LearnedWordsManager,
method,

View file

@ -21,7 +21,7 @@ module.exports = {
metrics.inc('spelling-check', 0.1)
const { token, wordCount } = extractCheckRequestData(req)
logger.info({ token, wordCount }, 'running check')
SpellingAPIManager.runRequest(token, req.body, function(error, result) {
SpellingAPIManager.runRequest(token, req.body, function (error, result) {
if (error != null) {
logger.error(
OError.tag(error, 'error processing spelling request', {
@ -39,7 +39,7 @@ module.exports = {
metrics.inc('spelling-learn', 0.1)
const { token, word } = extractLearnRequestData(req)
logger.info({ token, word }, 'learning word')
SpellingAPIManager.learnWord(token, req.body, function(error) {
SpellingAPIManager.learnWord(token, req.body, function (error) {
if (error != null) {
return next(OError.tag(error))
}
@ -51,7 +51,7 @@ module.exports = {
metrics.inc('spelling-unlearn', 0.1)
const { token, word } = extractLearnRequestData(req)
logger.info({ token, word }, 'unlearning word')
SpellingAPIManager.unlearnWord(token, req.body, function(error) {
SpellingAPIManager.unlearnWord(token, req.body, function (error) {
if (error != null) {
return next(OError.tag(error))
}
@ -62,7 +62,7 @@ module.exports = {
deleteDic(req, res, next) {
const { token, word } = extractLearnRequestData(req)
logger.log({ token, word }, 'deleting user dictionary')
SpellingAPIManager.deleteDic(token, function(error) {
SpellingAPIManager.deleteDic(token, function (error) {
if (error != null) {
return next(OError.tag(error))
}
@ -78,7 +78,7 @@ module.exports = {
},
'getting user dictionary'
)
SpellingAPIManager.getDic(token, function(error, words) {
SpellingAPIManager.getDic(token, function (error, words) {
if (error != null) {
return next(OError.tag(error))
}

View file

@ -70,7 +70,7 @@ const promises = {
const learnedWords = await LearnedWordsManager.promises.getLearnedWords(
token
)
const notLearntMisspellings = misspellings.filter(m => {
const notLearntMisspellings = misspellings.filter((m) => {
const word = wordSlice[m.index]
return (
learnedWords.indexOf(word) === -1 &&

View file

@ -1,11 +1,9 @@
spelling
--acceptance-creds=None
--data-dirs=cache
--dependencies=mongo
--docker-repos=gcr.io/overleaf-ops
--env-add=
--env-pass-through=
--language=es
--node-version=10.21.0
--public-repo=False
--script-version=2.2.0
--script-version=3.3.2

View file

@ -11,6 +11,7 @@ services:
command: npm run test:unit:_run
environment:
NODE_ENV: test
NODE_OPTIONS: "--unhandled-rejections=strict"
test_acceptance:
@ -23,6 +24,7 @@ services:
POSTGRES_HOST: postgres
MOCHA_GREP: ${MOCHA_GREP}
NODE_ENV: test
NODE_OPTIONS: "--unhandled-rejections=strict"
depends_on:
mongo:
condition: service_healthy
@ -38,4 +40,4 @@ services:
command: tar -czf /tmp/build/build.tar.gz --exclude=build.tar.gz --exclude-vcs .
user: root
mongo:
image: mongo:3.6
image: mongo:4.0

View file

@ -15,7 +15,8 @@ services:
environment:
MOCHA_GREP: ${MOCHA_GREP}
NODE_ENV: test
command: npm run test:unit
NODE_OPTIONS: "--unhandled-rejections=strict"
command: npm run --silent test:unit
user: node
test_acceptance:
@ -33,12 +34,13 @@ services:
MOCHA_GREP: ${MOCHA_GREP}
LOG_LEVEL: ERROR
NODE_ENV: test
NODE_OPTIONS: "--unhandled-rejections=strict"
user: node
depends_on:
mongo:
condition: service_healthy
command: npm run test:acceptance
command: npm run --silent test:acceptance
mongo:
image: mongo:3.6
image: mongo:4.0

View file

@ -8,7 +8,6 @@
"execMap": {
"js": "npm run start"
},
"watch": [
"app/js/",
"app.js",

View file

@ -4992,9 +4992,9 @@
"dev": true
},
"prettier": {
"version": "1.18.2",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz",
"integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==",
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz",
"integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==",
"dev": true
},
"prettier-eslint": {
@ -5125,6 +5125,12 @@
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
},
"prettier": {
"version": "1.19.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
"dev": true
},
"strip-ansi": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",

View file

@ -18,7 +18,7 @@
"compile:all": "npm run compile:app && npm run compile:unit_tests && npm run compile:acceptance_tests && npm run compile:smoke_tests",
"nodemon": "nodemon --config nodemon.json",
"compile:smoke_tests": "[ ! -e test/smoke/coffee ] && echo 'No smoke tests to compile' || coffee -o test/smoke/js -c test/smoke/coffee",
"lint": "node_modules/.bin/eslint .",
"lint": "node_modules/.bin/eslint --max-warnings 0 .",
"format": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --list-different",
"format:fix": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --write"
},
@ -53,6 +53,7 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^7.1.1",
"prettier": "^2.0.0",
"prettier-eslint-cli": "^5.0.0",
"sandboxed-module": "",
"sinon": "^9.0.1"

View file

@ -12,19 +12,19 @@ const checkWord = (words, language) =>
})
})
describe('checking words', function() {
describe('checking words', function () {
let response
describe('on successful response', function() {
beforeEach(async function() {
describe('on successful response', function () {
beforeEach(async function () {
response = await checkWord(['anather'])
})
it('should return status 200', async function() {
it('should return status 200', async function () {
expect(response.statusCode).to.equal(200)
})
it('should return the list of misspellings', async function() {
it('should return the list of misspellings', async function () {
const body = JSON.parse(response.body)
expect(body).to.deep.equal({
misspellings: [{ index: 0, suggestions: ['anther', 'another'] }]
@ -32,23 +32,23 @@ describe('checking words', function() {
})
})
describe('when multiple words are submitted', function() {
beforeEach(async function() {
describe('when multiple words are submitted', function () {
beforeEach(async function () {
response = await checkWord(['anather', 'anather', 'theorie'])
})
it('should return the misspellings for all the words', async function() {
it('should return the misspellings for all the words', async function () {
const body = JSON.parse(response.body)
expect(body.misspellings.length).to.equal(3)
})
it('should have misspelling suggestions with consecutive indexes', async function() {
it('should have misspelling suggestions with consecutive indexes', async function () {
const body = JSON.parse(response.body)
const indexes = body.misspellings.map(mspl => mspl.index)
const indexes = body.misspellings.map((mspl) => mspl.index)
expect(indexes).to.deep.equal([0, 1, 2])
})
it('should return identical suggestions for the same entry', async function() {
it('should return identical suggestions for the same entry', async function () {
const body = JSON.parse(response.body)
expect(body.misspellings[0].suggestions).to.deep.equal(
body.misspellings[1].suggestions
@ -56,8 +56,8 @@ describe('checking words', function() {
})
})
describe('when a very long list of words if submitted', function() {
beforeEach(async function() {
describe('when a very long list of words if submitted', function () {
beforeEach(async function () {
const words = []
for (let i = 0; i <= 20000; i++) {
words.push('anather')
@ -65,14 +65,14 @@ describe('checking words', function() {
response = await checkWord(words)
})
it('should return misspellings for the first 10K results only', async function() {
it('should return misspellings for the first 10K results only', async function () {
const body = JSON.parse(response.body)
expect(body.misspellings.length).to.equal(10000)
})
it('should have misspelling suggestions with consecutive indexes', async function() {
it('should have misspelling suggestions with consecutive indexes', async function () {
const body = JSON.parse(response.body)
const indexList = body.misspellings.map(mspl => mspl.index)
const indexList = body.misspellings.map((mspl) => mspl.index)
expect(indexList.length).to.equal(10000) // avoid testing over an incorrect array
for (let i = 0; i < indexList.length - 1; i++) {
expect(indexList[i] + 1).to.equal(indexList[i + 1])
@ -80,8 +80,8 @@ describe('checking words', function() {
})
})
describe('when a very long list of words with utf8 responses', function() {
beforeEach(async function() {
describe('when a very long list of words with utf8 responses', function () {
beforeEach(async function () {
const words = []
for (let i = 0; i <= 20000; i++) {
words.push('anéther')
@ -89,14 +89,14 @@ describe('checking words', function() {
response = await checkWord(words, 'bg') // use Bulgarian to generate utf8 response
})
it('should return misspellings for the first 10K results only', async function() {
it('should return misspellings for the first 10K results only', async function () {
const body = JSON.parse(response.body)
expect(body.misspellings.length).to.equal(10000)
})
it('should have misspelling suggestions with consecutive indexes', async function() {
it('should have misspelling suggestions with consecutive indexes', async function () {
const body = JSON.parse(response.body)
const indexList = body.misspellings.map(mspl => mspl.index)
const indexList = body.misspellings.map((mspl) => mspl.index)
expect(indexList.length).to.equal(10000) // avoid testing over an incorrect array
for (let i = 0; i < indexList.length - 1; i++) {
expect(indexList[i] + 1).to.equal(indexList[i + 1])
@ -104,23 +104,23 @@ describe('checking words', function() {
})
})
describe('when multiple words with utf8 are submitted', function() {
beforeEach(async function() {
describe('when multiple words with utf8 are submitted', function () {
beforeEach(async function () {
response = await checkWord(['mneá', 'meniésn', 'meônoi', 'mneá'], 'pt_BR')
})
it('should return the misspellings for all the words', async function() {
it('should return the misspellings for all the words', async function () {
const body = JSON.parse(response.body)
expect(body.misspellings.length).to.equal(4)
})
it('should have misspelling suggestions with consecutive indexes', async function() {
it('should have misspelling suggestions with consecutive indexes', async function () {
const body = JSON.parse(response.body)
const indexes = body.misspellings.map(mspl => mspl.index)
const indexes = body.misspellings.map((mspl) => mspl.index)
expect(indexes).to.deep.equal([0, 1, 2, 3])
})
it('should return identical suggestions for the same entry', async function() {
it('should return identical suggestions for the same entry', async function () {
const body = JSON.parse(response.body)
expect(body.misspellings[0].suggestions).to.deep.equal(
body.misspellings[3].suggestions

View file

@ -1,8 +1,8 @@
const { expect } = require('chai')
const request = require('./helpers/request')
describe('/health_check', function() {
it('should return 200', async function() {
describe('/health_check', function () {
it('should return 200', async function () {
const response = await request.get('/health_check')
expect(response.statusCode).to.equal(200)
})

View file

@ -1,6 +1,6 @@
const App = require('../../../app.js')
const { PORT } = require('./helpers/request')
before(function(done) {
before(function (done) {
return App.listen(PORT, 'localhost', done)
})

View file

@ -3,7 +3,7 @@ const request = require('./helpers/request')
const USER_ID = 101
const checkWord = words =>
const checkWord = (words) =>
request.post({
url: `/user/${USER_ID}/check`,
body: JSON.stringify({
@ -11,7 +11,7 @@ const checkWord = words =>
})
})
const learnWord = word =>
const learnWord = (word) =>
request.post({
url: `/user/${USER_ID}/learn`,
body: JSON.stringify({
@ -19,7 +19,7 @@ const learnWord = word =>
})
})
const unlearnWord = word =>
const unlearnWord = (word) =>
request.post({
url: `/user/${USER_ID}/unlearn`,
body: JSON.stringify({
@ -37,17 +37,17 @@ const deleteDict = () =>
url: `/user/${USER_ID}`
})
describe('learning words', function() {
afterEach(async function() {
describe('learning words', function () {
afterEach(async function () {
await deleteDict()
})
it('should return status 204 when posting a word successfully', async function() {
it('should return status 204 when posting a word successfully', async function () {
const response = await learnWord('abcd')
expect(response.statusCode).to.equal(204)
})
it('should not learn the same word twice', async function() {
it('should not learn the same word twice', async function () {
await learnWord('foobar')
const learnResponse = await learnWord('foobar')
expect(learnResponse.statusCode).to.equal(204)
@ -59,7 +59,7 @@ describe('learning words', function() {
expect(responseBody.length).to.equals(1)
})
it('should return no misspellings after a word is learnt', async function() {
it('should return no misspellings after a word is learnt', async function () {
const response = await checkWord(['abv'])
const responseBody = JSON.parse(response.body)
expect(responseBody.misspellings.length).to.equals(1)
@ -71,7 +71,7 @@ describe('learning words', function() {
expect(responseBody2.misspellings.length).to.equals(0)
})
it('should return misspellings again after a personal dictionary is deleted', async function() {
it('should return misspellings again after a personal dictionary is deleted', async function () {
await learnWord('bvc')
await deleteDict()
@ -81,13 +81,13 @@ describe('learning words', function() {
})
})
describe('unlearning words', function() {
it('should return status 204 when posting a word successfully', async function() {
describe('unlearning words', function () {
it('should return status 204 when posting a word successfully', async function () {
const response = await unlearnWord('anything')
expect(response.statusCode).to.equal(204)
})
it('should return misspellings after a word is unlearnt', async function() {
it('should return misspellings after a word is unlearnt', async function () {
await learnWord('abv')
const response = await checkWord(['abv'])

View file

@ -1,8 +1,8 @@
const { expect } = require('chai')
const request = require('./helpers/request')
describe('/status', function() {
it('should return 200', async function() {
describe('/status', function () {
it('should return 200', async function () {
const response = await request.get('/health_check')
expect(response.statusCode).to.equal(200)
})

View file

@ -24,9 +24,9 @@ const wordlist = fs
.readFileSync(WORDS)
.toString()
.split('\n')
.filter(w => w.match(/^[a-z]+$/))
.filter((w) => w.match(/^[a-z]+$/))
const generateCorrectWords = function(n) {
const generateCorrectWords = function (n) {
const words = []
const N = Math.random() > 0.5 ? wordlist.length : 10
for (
@ -40,7 +40,7 @@ const generateCorrectWords = function(n) {
return words
}
const generateIncorrectWords = function(n) {
const generateIncorrectWords = function (n) {
const words = []
const N = wordlist.length
for (
@ -54,7 +54,7 @@ const generateIncorrectWords = function(n) {
return words
}
const make_request = function(correctWords, incorrectWords, callback) {
const make_request = function (correctWords, incorrectWords, callback) {
let i, j, w
let i1
let j1
@ -73,7 +73,7 @@ const make_request = function(correctWords, incorrectWords, callback) {
bad[i + correctSet.length] = true
}
const k = full.length
full.forEach(function(e, i) {
full.forEach(function (e, i) {
let ref
j = Math.floor(k * Math.random())
;[full[i], full[j]] = Array.from([full[j], full[i]])
@ -89,7 +89,7 @@ const make_request = function(correctWords, incorrectWords, callback) {
return request.post(
'http://localhost:3005/user/1/check',
{ json: true, body: { words: full } },
function(err, req, body) {
function (err, req, body) {
let m
const { misspellings } = body
console.log(JSON.stringify({ full, misspellings }))

View file

@ -14,8 +14,8 @@ const should = chai.should()
const SandboxedModule = require('sandboxed-module')
const { assert } = require('chai')
describe('ASpell', function() {
beforeEach(function() {
describe('ASpell', function () {
beforeEach(function () {
return (this.ASpell = SandboxedModule.require('../../../app/js/ASpell', {
requires: {
'logger-sharelatex': {
@ -30,39 +30,39 @@ describe('ASpell', function() {
}
}))
})
afterEach(function() {
afterEach(function () {
clearInterval(this.ASpell.cacheDump)
})
describe('a correctly spelled word', function() {
beforeEach(function(done) {
describe('a correctly spelled word', function () {
beforeEach(function (done) {
return this.ASpell.checkWords('en', ['word'], (error, result) => {
this.result = result
return done()
})
})
return it('should not correct the word', function() {
return it('should not correct the word', function () {
return this.result.length.should.equal(0)
})
})
describe('a misspelled word', function() {
beforeEach(function(done) {
describe('a misspelled word', function () {
beforeEach(function (done) {
return this.ASpell.checkWords('en', ['bussines'], (error, result) => {
this.result = result
return done()
})
})
return it('should correct the word', function() {
return it('should correct the word', function () {
this.result.length.should.equal(1)
return this.result[0].suggestions.indexOf('business').should.not.equal(-1)
})
})
describe('multiple words', function() {
beforeEach(function(done) {
describe('multiple words', function () {
beforeEach(function (done) {
return this.ASpell.checkWords(
'en',
['bussines', 'word', 'neccesary'],
@ -73,7 +73,7 @@ describe('ASpell', function() {
)
})
return it('should correct the incorrect words', function() {
return it('should correct the incorrect words', function () {
this.result[0].index.should.equal(0)
this.result[0].suggestions.indexOf('business').should.not.equal(-1)
this.result[1].index.should.equal(2)
@ -83,8 +83,8 @@ describe('ASpell', function() {
})
})
describe('without a valid language', function() {
beforeEach(function(done) {
describe('without a valid language', function () {
beforeEach(function (done) {
return this.ASpell.checkWords('notALang', ['banana'], (error, result) => {
this.error = error
this.result = result
@ -92,13 +92,13 @@ describe('ASpell', function() {
})
})
return it('should return an error', function() {
return it('should return an error', function () {
return should.exist(this.error)
})
})
describe('when there are no suggestions', function() {
beforeEach(function(done) {
describe('when there are no suggestions', function () {
beforeEach(function (done) {
return this.ASpell.checkWords(
'en',
['asdkfjalkdjfadhfkajsdhfashdfjhadflkjadhflajsd'],
@ -110,15 +110,15 @@ describe('ASpell', function() {
)
})
return it('should return a blank array', function() {
return it('should return a blank array', function () {
this.result.length.should.equal(1)
return assert.deepEqual(this.result[0].suggestions, [])
})
})
return describe('when the request times out', function() {
beforeEach(function(done) {
const words = __range__(0, 1000, true).map(i => 'abcdefg')
return describe('when the request times out', function () {
beforeEach(function (done) {
const words = __range__(0, 1000, true).map((i) => 'abcdefg')
this.ASpell.ASPELL_TIMEOUT = 1
this.start = Date.now()
return this.ASpell.checkWords('en', words, (error, result) => {
@ -130,7 +130,7 @@ describe('ASpell', function() {
// Note that this test fails on OS X, due to differing pipe behaviour
// on killing the child process. It can be tested successfully on Travis
// or the CI server.
return it('should return in reasonable time', function() {
return it('should return in reasonable time', function () {
const delta = Date.now() - this.start
return delta.should.be.below(this.ASpell.ASPELL_TIMEOUT + 1000)
})

View file

@ -8,8 +8,8 @@ const { expect } = chai
const SandboxedModule = require('sandboxed-module')
const EventEmitter = require('events')
describe('ASpellWorker', function() {
beforeEach(function() {
describe('ASpellWorker', function () {
beforeEach(function () {
this.child_process = {}
return (this.ASpellWorker = SandboxedModule.require(
'../../../app/js/ASpellWorker',
@ -30,8 +30,8 @@ describe('ASpellWorker', function() {
))
})
describe('creating a worker', function() {
beforeEach(function() {
describe('creating a worker', function () {
beforeEach(function () {
this.pipe = {
stdout: new EventEmitter(),
stderr: { on: sinon.stub() },
@ -44,8 +44,8 @@ describe('ASpellWorker', function() {
worker = new this.ASpellWorker('en')
})
describe('with normal aspell output', function() {
beforeEach(function() {
describe('with normal aspell output', function () {
beforeEach(function () {
this.callback = worker.callback = sinon.stub()
this.pipe.stdout.emit('data', '& hello\n')
this.pipe.stdout.emit('data', '& world\n')
@ -53,7 +53,7 @@ describe('ASpellWorker', function() {
this.pipe.stdout.emit('data', '& goodbye')
})
it('should call the callback', function() {
it('should call the callback', function () {
expect(this.callback.called).to.equal(true)
expect(
this.callback.calledWith(null, '& hello\n& world\nen\n')
@ -61,8 +61,8 @@ describe('ASpellWorker', function() {
})
})
describe('with the aspell end marker split across chunks', function() {
beforeEach(function() {
describe('with the aspell end marker split across chunks', function () {
beforeEach(function () {
this.callback = worker.callback = sinon.stub()
this.pipe.stdout.emit('data', '& hello\n')
this.pipe.stdout.emit('data', '& world\ne')
@ -70,7 +70,7 @@ describe('ASpellWorker', function() {
this.pipe.stdout.emit('data', '& goodbye')
})
it('should call the callback', function() {
it('should call the callback', function () {
expect(this.callback.called).to.equal(true)
expect(
this.callback.calledWith(null, '& hello\n& world\nen\n')
@ -78,8 +78,8 @@ describe('ASpellWorker', function() {
})
})
describe('with the aspell end marker newline split across chunks', function() {
beforeEach(function() {
describe('with the aspell end marker newline split across chunks', function () {
beforeEach(function () {
this.callback = worker.callback = sinon.stub()
this.pipe.stdout.emit('data', '& hello\n')
this.pipe.stdout.emit('data', '& world\n')
@ -87,7 +87,7 @@ describe('ASpellWorker', function() {
this.pipe.stdout.emit('data', '\n& goodbye')
})
it('should call the callback', function() {
it('should call the callback', function () {
expect(this.callback.called).to.equal(true)
expect(this.callback.calledWith(null, '& hello\n& world\nen')).to.equal(
true
@ -95,15 +95,15 @@ describe('ASpellWorker', function() {
})
})
describe('with everything split across chunks', function() {
beforeEach(function() {
describe('with everything split across chunks', function () {
beforeEach(function () {
this.callback = worker.callback = sinon.stub()
'& hello\n& world\nen\n& goodbye'.split('').forEach(x => {
'& hello\n& world\nen\n& goodbye'.split('').forEach((x) => {
this.pipe.stdout.emit('data', x)
})
})
it('should call the callback', function() {
it('should call the callback', function () {
expect(this.callback.called).to.equal(true)
expect(this.callback.calledWith(null, '& hello\n& world\nen')).to.equal(
true

View file

@ -7,8 +7,8 @@ const modulePath = require('path').join(
'../../../app/js/LearnedWordsManager'
)
const { assert } = require('chai')
describe('LearnedWordsManager', function() {
beforeEach(function() {
describe('LearnedWordsManager', function () {
beforeEach(function () {
this.token = 'a6b3cd919ge'
this.callback = sinon.stub()
this.db = {
@ -41,13 +41,13 @@ describe('LearnedWordsManager', function() {
})
})
describe('learnWord', function() {
beforeEach(function() {
describe('learnWord', function () {
beforeEach(function () {
this.word = 'instanton'
this.LearnedWordsManager.learnWord(this.token, this.word, this.callback)
})
it('should insert the word in the word list in the database', function() {
it('should insert the word in the word list in the database', function () {
expect(
this.db.spellingPreferences.update.calledWith(
{
@ -63,18 +63,18 @@ describe('LearnedWordsManager', function() {
).to.equal(true)
})
it('should call the callback', function() {
it('should call the callback', function () {
expect(this.callback.called).to.equal(true)
})
})
describe('unlearnWord', function() {
beforeEach(function() {
describe('unlearnWord', function () {
beforeEach(function () {
this.word = 'instanton'
this.LearnedWordsManager.unlearnWord(this.token, this.word, this.callback)
})
it('should remove the word from the word list in the database', function() {
it('should remove the word from the word list in the database', function () {
expect(
this.db.spellingPreferences.update.calledWith(
{
@ -87,13 +87,13 @@ describe('LearnedWordsManager', function() {
).to.equal(true)
})
it('should call the callback', function() {
it('should call the callback', function () {
expect(this.callback.called).to.equal(true)
})
})
describe('getLearnedWords', function() {
beforeEach(function() {
describe('getLearnedWords', function () {
beforeEach(function () {
this.wordList = ['apples', 'bananas', 'pears']
this.wordListWithDuplicates = this.wordList.slice()
this.wordListWithDuplicates.push('bananas')
@ -104,19 +104,19 @@ describe('LearnedWordsManager', function() {
this.LearnedWordsManager.getLearnedWords(this.token, this.callback)
})
it('should get the word list for the given user', function() {
it('should get the word list for the given user', function () {
expect(
this.db.spellingPreferences.findOne.calledWith({ token: this.token })
).to.equal(true)
})
it('should return the word list in the callback without duplicates', function() {
it('should return the word list in the callback without duplicates', function () {
expect(this.callback.calledWith(null, this.wordList)).to.equal(true)
})
})
describe('caching the result', function() {
it('should use the cache first if it is primed', function(done) {
describe('caching the result', function () {
it('should use the cache first if it is primed', function (done) {
this.wordList = ['apples', 'bananas', 'pears']
this.cache.get.returns(this.wordList)
this.db.spellingPreferences.findOne = sinon.stub()
@ -128,7 +128,7 @@ describe('LearnedWordsManager', function() {
})
})
it('should set the cache after hitting the db', function(done) {
it('should set the cache after hitting the db', function (done) {
this.wordList = ['apples', 'bananas', 'pears']
this.db.spellingPreferences.findOne = sinon
.stub()
@ -139,7 +139,7 @@ describe('LearnedWordsManager', function() {
})
})
it('should break cache when update is called', function(done) {
it('should break cache when update is called', function (done) {
this.word = 'instanton'
this.LearnedWordsManager.learnWord(this.token, this.word, () => {
this.cache.del.calledWith(this.token).should.equal(true)
@ -148,12 +148,12 @@ describe('LearnedWordsManager', function() {
})
})
describe('deleteUsersLearnedWords', function() {
beforeEach(function() {
describe('deleteUsersLearnedWords', function () {
beforeEach(function () {
this.db.spellingPreferences.remove = sinon.stub().callsArgWith(1)
})
it('should get the word list for the given user', function(done) {
it('should get the word list for the given user', function (done) {
this.LearnedWordsManager.deleteUsersLearnedWords(this.token, () => {
this.db.spellingPreferences.remove
.calledWith({ token: this.token })

View file

@ -11,10 +11,10 @@ const modulePath = require('path').join(
'../../../app/js/SpellingAPIManager'
)
const promiseStub = val => new Promise(resolve => resolve(val))
const promiseStub = (val) => new Promise((resolve) => resolve(val))
describe('SpellingAPIManager', function() {
beforeEach(function() {
describe('SpellingAPIManager', function () {
beforeEach(function () {
this.token = 'user-id-123'
this.ASpell = {}
this.learnedWords = ['lerned']
@ -35,8 +35,8 @@ describe('SpellingAPIManager', function() {
})
})
describe('runRequest', function() {
beforeEach(function() {
describe('runRequest', function () {
beforeEach(function () {
this.nonLearnedWords = [
'some',
'words',
@ -64,8 +64,8 @@ describe('SpellingAPIManager', function() {
sinon.spy(this.ASpell, 'checkWords')
})
describe('with sensible JSON', function() {
beforeEach(function(done) {
describe('with sensible JSON', function () {
beforeEach(function (done) {
this.SpellingAPIManager.runRequest(
this.token,
{ words: this.allWords },
@ -76,15 +76,15 @@ describe('SpellingAPIManager', function() {
)
})
it('should return the words that are spelled incorrectly and not learned', function() {
it('should return the words that are spelled incorrectly and not learned', function () {
expect(this.result.misspellings).to.deep.equal(
this.misspellingsWithoutLearnedWords
)
})
})
describe('with a missing words array', function() {
beforeEach(function(done) {
describe('with a missing words array', function () {
beforeEach(function (done) {
this.SpellingAPIManager.runRequest(this.token, {}, (error, result) => {
this.error = error
this.result = result
@ -92,15 +92,15 @@ describe('SpellingAPIManager', function() {
})
})
it('should return an error', function() {
it('should return an error', function () {
expect(this.error).to.exist
expect(this.error).to.be.instanceof(Error)
expect(this.error.message).to.equal('malformed JSON')
})
})
describe('with a missing token', function() {
beforeEach(function(done) {
describe('with a missing token', function () {
beforeEach(function (done) {
this.SpellingAPIManager.runRequest(
null,
{ words: this.allWords },
@ -112,13 +112,13 @@ describe('SpellingAPIManager', function() {
)
})
it('should spell check without using any learned words', function() {
it('should spell check without using any learned words', function () {
this.LearnedWordsManager.getLearnedWords.called.should.equal(false)
})
})
describe('without a language', function() {
beforeEach(function(done) {
describe('without a language', function () {
beforeEach(function (done) {
this.SpellingAPIManager.runRequest(
this.token,
{ words: this.allWords },
@ -129,13 +129,13 @@ describe('SpellingAPIManager', function() {
)
})
it('should use en as the default', function() {
it('should use en as the default', function () {
this.ASpell.promises.checkWords.calledWith('en').should.equal(true)
})
})
describe('with a language', function() {
beforeEach(function(done) {
describe('with a language', function () {
beforeEach(function (done) {
this.language = 'fr'
this.SpellingAPIManager.runRequest(
this.token,
@ -150,15 +150,15 @@ describe('SpellingAPIManager', function() {
)
})
it('should use the language', function() {
it('should use the language', function () {
this.ASpell.promises.checkWords
.calledWith(this.language)
.should.equal(true)
})
})
describe('with words from the whitelist', function() {
beforeEach(function(done) {
describe('with words from the whitelist', function () {
beforeEach(function (done) {
this.whitelistWord = this.SpellingAPIManager.whitelist[0]
this.words = ['One', 'Two', this.whitelistWord]
this.SpellingAPIManager.runRequest(
@ -171,7 +171,7 @@ describe('SpellingAPIManager', function() {
)
})
it('should ignore the white-listed word', function() {
it('should ignore the white-listed word', function () {
expect(this.result.misspellings.length).to.equal(
this.misspellings.length - 1
)
@ -179,51 +179,51 @@ describe('SpellingAPIManager', function() {
})
})
describe('learnWord', function() {
describe('without a token', function() {
beforeEach(function(done) {
this.SpellingAPIManager.learnWord(null, { word: 'banana' }, error => {
describe('learnWord', function () {
describe('without a token', function () {
beforeEach(function (done) {
this.SpellingAPIManager.learnWord(null, { word: 'banana' }, (error) => {
this.error = error
done()
})
})
it('should return an error', function() {
it('should return an error', function () {
expect(this.error).to.exist
expect(this.error).to.be.instanceof(Error)
expect(this.error.message).to.equal('no token provided')
})
})
describe('without a word', function() {
beforeEach(function(done) {
this.SpellingAPIManager.learnWord(this.token, {}, error => {
describe('without a word', function () {
beforeEach(function (done) {
this.SpellingAPIManager.learnWord(this.token, {}, (error) => {
this.error = error
done()
})
})
it('should return an error', function() {
it('should return an error', function () {
expect(this.error).to.exist
expect(this.error).to.be.instanceof(Error)
expect(this.error.message).to.equal('malformed JSON')
})
})
describe('with a word and a token', function() {
beforeEach(function(done) {
describe('with a word and a token', function () {
beforeEach(function (done) {
this.word = 'banana'
this.SpellingAPIManager.learnWord(
this.token,
{ word: this.word },
error => {
(error) => {
this.error = error
done()
}
)
})
it('should call LearnedWordsManager.learnWord', function() {
it('should call LearnedWordsManager.learnWord', function () {
this.LearnedWordsManager.learnWord
.calledWith(this.token, this.word)
.should.equal(true)
@ -231,51 +231,55 @@ describe('SpellingAPIManager', function() {
})
})
describe('unlearnWord', function() {
describe('without a token', function() {
beforeEach(function(done) {
this.SpellingAPIManager.unlearnWord(null, { word: 'banana' }, error => {
this.error = error
done()
})
})
it('should return an error', function() {
expect(this.error).to.exist
expect(this.error).to.be.instanceof(Error)
expect(this.error.message).to.equal('no token provided')
})
})
describe('without a word', function() {
beforeEach(function(done) {
this.SpellingAPIManager.unlearnWord(this.token, {}, error => {
this.error = error
done()
})
})
it('should return an error', function() {
expect(this.error).to.exist
expect(this.error).to.be.instanceof(Error)
expect(this.error.message).to.equal('malformed JSON')
})
})
describe('with a word and a token', function() {
beforeEach(function(done) {
this.word = 'banana'
describe('unlearnWord', function () {
describe('without a token', function () {
beforeEach(function (done) {
this.SpellingAPIManager.unlearnWord(
this.token,
{ word: this.word },
error => {
null,
{ word: 'banana' },
(error) => {
this.error = error
done()
}
)
})
it('should call LearnedWordsManager.unlearnWord', function() {
it('should return an error', function () {
expect(this.error).to.exist
expect(this.error).to.be.instanceof(Error)
expect(this.error.message).to.equal('no token provided')
})
})
describe('without a word', function () {
beforeEach(function (done) {
this.SpellingAPIManager.unlearnWord(this.token, {}, (error) => {
this.error = error
done()
})
})
it('should return an error', function () {
expect(this.error).to.exist
expect(this.error).to.be.instanceof(Error)
expect(this.error.message).to.equal('malformed JSON')
})
})
describe('with a word and a token', function () {
beforeEach(function (done) {
this.word = 'banana'
this.SpellingAPIManager.unlearnWord(
this.token,
{ word: this.word },
(error) => {
this.error = error
done()
}
)
})
it('should call LearnedWordsManager.unlearnWord', function () {
this.LearnedWordsManager.unlearnWord
.calledWith(this.token, this.word)
.should.equal(true)