Merge pull request #91 from overleaf/jpa-bulk-dependency-upgrades

[misc] bulk dependency upgrades
This commit is contained in:
Jakob Ackermann
2021-07-15 16:51:28 +02:00
committed by GitHub
28 changed files with 1250 additions and 2407 deletions

View File

@@ -3,9 +3,9 @@
// https://github.com/sharelatex/sharelatex-dev-environment
{
"extends": [
"eslint:recommended",
"standard",
"prettier",
"prettier/standard"
"prettier"
],
"parserOptions": {
"ecmaVersion": 2018
@@ -20,6 +20,19 @@
"mocha": true
},
"rules": {
// TODO(das7pad): remove overrides after fixing all the violations manually (https://github.com/overleaf/issues/issues/3882#issuecomment-878999671)
// START of temporary overrides
"array-callback-return": "off",
"no-dupe-else-if": "off",
"no-var": "off",
"no-empty": "off",
"node/handle-callback-err": "off",
"no-loss-of-precision": "off",
"node/no-callback-literal": "off",
"node/no-path-concat": "off",
"prefer-regex-literals": "off",
// END of temporary overrides
// Swap the no-unused-expressions rule with a more chai-friendly one
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": "error",

View File

@@ -20,4 +20,4 @@ updates:
# future if we reorganise teams
labels:
- "dependencies"
- "Team-Magma"
- "type:maintenance"

View File

@@ -1 +1 @@
12.21.0
12.22.3

View File

@@ -2,6 +2,10 @@
# Instead run bin/update_build_scripts from
# https://github.com/sharelatex/sharelatex-dev-environment
{
"arrowParens": "avoid",
"semi": false,
"singleQuote": true
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false
}

View File

@@ -2,7 +2,7 @@
# Instead run bin/update_build_scripts from
# https://github.com/sharelatex/sharelatex-dev-environment
FROM node:12.21.0 as base
FROM node:12.22.3 as base
WORKDIR /app
COPY install_deps.sh /app

View File

@@ -8,7 +8,7 @@
const metrics = require('@overleaf/metrics')
metrics.initialize('spelling')
const Settings = require('settings-sharelatex')
const Settings = require('@overleaf/settings')
const logger = require('logger-sharelatex')
logger.initialize('spelling')
if ((Settings.sentry != null ? Settings.sentry.dsn : undefined) != null) {
@@ -55,7 +55,7 @@ if (!module.parent) {
return logger.info(`spelling starting up, listening on ${host}:${port}`)
})
})
.catch((err) => {
.catch(err => {
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
process.exit(1)
})

View File

@@ -11,7 +11,7 @@ const ASpellWorkerPool = require('./ASpellWorkerPool')
const LRU = require('lru-cache')
const logger = require('logger-sharelatex')
const fs = require('fs')
const settings = require('settings-sharelatex')
const settings = require('@overleaf/settings')
const Path = require('path')
const { promisify } = require('util')
const OError = require('@overleaf/o-error')
@@ -41,7 +41,7 @@ const cacheDump = setInterval(function () {
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 {
@@ -100,7 +100,7 @@ class ASpellRunner {
{
hits,
total: words.length,
hitrate: (hits / words.length).toFixed(2)
hitrate: (hits / words.length).toFixed(2),
},
'cache hit rate'
)
@@ -176,11 +176,11 @@ const ASpell = {
const runner = new ASpellRunner()
return runner.checkWords(language, words, callback)
},
ASPELL_TIMEOUT: 10000
ASPELL_TIMEOUT: 10000,
}
const promises = {
checkWords: promisify(ASpell.checkWords)
checkWords: promisify(ASpell.checkWords),
}
ASpell.promises = promises

View File

@@ -25,7 +25,7 @@ class ASpellWorker {
'-t',
'--encoding=utf-8',
'-d',
language
language,
])
logger.info(
{ process: this.pipe.pid, lang: this.language },
@@ -40,7 +40,7 @@ class ASpellWorker {
)
metrics.inc('aspellWorker', 1, {
status: 'exit',
method: this.language
method: this.language,
})
})
this.pipe.on('close', () => {
@@ -58,14 +58,14 @@ class ASpellWorker {
stderr: error.slice(-1024),
workerState: this.state,
previousWorkerState,
closeReason: this.closeReason
closeReason: this.closeReason,
}
)
this.callback(err, [])
this.callback = null
}
})
this.pipe.on('error', (err) => {
this.pipe.on('error', err => {
const previousWorkerState = this.state
if (this.state !== 'killed') {
this.state = 'error'
@@ -77,7 +77,7 @@ class ASpellWorker {
lang: this.language,
workerState: this.state,
previousWorkerState,
closeReason: this.closeReason
closeReason: this.closeReason,
})
if (this.callback != null) {
@@ -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'
@@ -100,7 +100,7 @@ class ASpellWorker {
lang: this.language,
workerState: this.state,
previousWorkerState,
closeReason: this.closeReason
closeReason: this.closeReason,
})
if (this.callback != null) {
@@ -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
@@ -133,7 +133,7 @@ class ASpellWorker {
{
process: this.pipe.pid,
lang: this.language,
workerState: this.state
workerState: this.state,
}
)
)
@@ -144,7 +144,7 @@ class ASpellWorker {
})
var error = ''
this.pipe.stderr.on('data', (chunk) => {
this.pipe.stderr.on('data', chunk => {
return (error = error + chunk)
})
@@ -168,7 +168,7 @@ class ASpellWorker {
new OError('Aspell callback already in use - SHOULD NOT HAPPEN', {
process: this.pipe.pid,
lang: this.language,
workerState: this.state
workerState: this.state,
})
)
}

View File

@@ -56,9 +56,7 @@ 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)
}
@@ -68,7 +66,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)

View File

@@ -1,6 +1,6 @@
const request = require('request')
const logger = require('logger-sharelatex')
const settings = require('settings-sharelatex')
const settings = require('@overleaf/settings')
const OError = require('@overleaf/o-error')
module.exports = {
@@ -9,9 +9,9 @@ module.exports = {
url: `http://localhost:3005/user/${settings.healthCheckUserId}/check`,
json: {
words: ['helllo'],
language: 'en'
language: 'en',
},
timeout: 1000 * 20
timeout: 1000 * 20,
}
return request.post(opts, function (err, response, body) {
if (err != null) {
@@ -35,5 +35,5 @@ module.exports = {
res.sendStatus(500)
}
})
}
},
}

View File

@@ -13,13 +13,13 @@ const LearnedWordsManager = {
mongoCache.del(userToken)
return db.spellingPreferences.updateOne(
{
token: userToken
token: userToken,
},
{
$addToSet: { learnedWords: word }
$addToSet: { learnedWords: word },
},
{
upsert: true
upsert: true,
},
callback
)
@@ -32,10 +32,10 @@ const LearnedWordsManager = {
mongoCache.del(userToken)
return db.spellingPreferences.updateOne(
{
token: userToken
token: userToken,
},
{
$pull: { learnedWords: word }
$pull: { learnedWords: word },
},
callback
)
@@ -54,24 +54,24 @@ const LearnedWordsManager = {
metrics.inc('mongoCache', 0.1, { status: 'miss' })
logger.info({ userToken }, 'mongoCache miss')
db.spellingPreferences.findOne({ token: userToken }, function (
error,
preferences
) {
if (error != null) {
return callback(OError.tag(error))
db.spellingPreferences.findOne(
{ token: userToken },
function (error, preferences) {
if (error != null) {
return callback(OError.tag(error))
}
let words =
(preferences != null ? preferences.learnedWords : undefined) || []
if (words) {
// remove duplicates
words = words.filter(
(value, index, self) => self.indexOf(value) === index
)
}
mongoCache.set(userToken, words)
callback(null, words)
}
let words =
(preferences != null ? preferences.learnedWords : undefined) || []
if (words) {
// remove duplicates
words = words.filter(
(value, index, self) => self.indexOf(value) === index
)
}
mongoCache.set(userToken, words)
callback(null, words)
})
)
},
deleteUsersLearnedWords(userToken, callback) {
@@ -79,7 +79,7 @@ const LearnedWordsManager = {
callback = () => {}
}
db.spellingPreferences.deleteOne({ token: userToken }, callback)
}
},
}
const promises = {
@@ -88,13 +88,13 @@ const promises = {
getLearnedWords: promisify(LearnedWordsManager.getLearnedWords),
deleteUsersLearnedWords: promisify(
LearnedWordsManager.deleteUsersLearnedWords
)
),
}
LearnedWordsManager.promises = promises
module.exports = LearnedWordsManager
;['learnWord', 'unlearnWord', 'getLearnedWords'].map((method) =>
;['learnWord', 'unlearnWord', 'getLearnedWords'].map(method =>
metrics.timeAsyncMethod(
LearnedWordsManager,
method,

View File

@@ -3,7 +3,7 @@
const LRU = require('lru-cache')
const cacheOpts = {
max: 15000,
maxAge: 1000 * 60 * 60 * 10
maxAge: 1000 * 60 * 60 * 10,
}
const cache = new LRU(cacheOpts)

View File

@@ -26,7 +26,7 @@ module.exports = {
logger.error(
OError.tag(error, 'error processing spelling request', {
user_id: token,
wordCount
wordCount,
})
)
return res.sendStatus(500)
@@ -74,7 +74,7 @@ module.exports = {
const token = req.params ? req.params.user_id : undefined
logger.info(
{
token
token,
},
'getting user dictionary'
)
@@ -84,5 +84,5 @@ module.exports = {
}
res.send(words)
})
}
},
}

View File

@@ -10,7 +10,7 @@ const ASpell = require('./ASpell')
const LearnedWordsManager = require('./LearnedWordsManager')
const { callbackify } = require('util')
const OError = require('@overleaf/o-error')
const Settings = require('settings-sharelatex')
const Settings = require('@overleaf/settings')
// The max number of words checked in a single request
const REQUEST_LIMIT = 10000
@@ -52,7 +52,7 @@ const SpellingAPIManager = {
getDic(token, callback) {
return LearnedWordsManager.getLearnedWords(token, callback)
}
},
}
const promises = {
@@ -71,7 +71,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 &&
@@ -82,7 +82,7 @@ const promises = {
} else {
return { misspellings }
}
}
},
}
SpellingAPIManager.runRequest = callbackify(promises.runRequest)

View File

@@ -1,4 +1,4 @@
const Settings = require('settings-sharelatex')
const Settings = require('@overleaf/settings')
const { MongoClient, ObjectId } = require('mongodb')
const clientPromise = MongoClient.connect(
@@ -24,5 +24,5 @@ async function setupDb() {
module.exports = {
db,
ObjectId,
waitForDb
waitForDb,
}

View File

@@ -4,6 +4,6 @@ spelling
--docker-repos=gcr.io/overleaf-ops
--env-add=
--env-pass-through=
--node-version=12.21.0
--node-version=12.22.3
--public-repo=False
--script-version=3.8.0
--script-version=3.11.0

View File

@@ -4,18 +4,18 @@ module.exports = {
internal: {
spelling: {
port: 3005,
host: process.env.LISTEN_ADDRESS || 'localhost'
}
host: process.env.LISTEN_ADDRESS || 'localhost',
},
},
mongo: {
options: {
useUnifiedTopology:
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true'
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true',
},
url:
process.env.MONGO_CONNECTION_STRING ||
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`,
},
cacheDir: Path.resolve('cache'),
@@ -32,10 +32,10 @@ module.exports = {
'LaTeX',
'http',
'https',
'www'
'www',
],
sentry: {
dsn: process.env.SENTRY_DSN
}
dsn: process.env.SENTRY_DSN,
},
}

File diff suppressed because it is too large Load Diff

View File

@@ -18,42 +18,41 @@
"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 --max-warnings 0 .",
"format": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --list-different",
"format:fix": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --write"
"lint": "eslint --max-warnings 0 --format unix .",
"format": "prettier --list-different $PWD/'**/*.js'",
"format:fix": "prettier --write $PWD/'**/*.js'",
"lint:fix": "eslint --fix ."
},
"version": "0.1.4",
"dependencies": {
"@overleaf/metrics": "^3.5.1",
"@overleaf/o-error": "^3.0.0",
"@overleaf/settings": "^2.1.1",
"async": "^2.6.3",
"body-parser": "^1.19.0",
"coffee-script": "^1.12.7",
"bunyan": "^1.8.15",
"express": "^4.17.1",
"logger-sharelatex": "^2.2.0",
"lru-cache": "^5.1.1",
"mongodb": "^3.6.0",
"request": "^2.88.2",
"settings-sharelatex": "^1.1.0",
"underscore": "1.13.1"
},
"devDependencies": {
"bunyan": "^1.8.12",
"chai": "4.2.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-chai-expect": "^2.1.0",
"eslint-plugin-chai-friendly": "^0.5.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-mocha": "^6.3.0",
"eslint-plugin-node": "^11.0.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eslint": "^7.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-chai-expect": "^2.2.0",
"eslint-plugin-chai-friendly": "^0.6.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.2",
"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",
"mocha": "^8.3.2",
"prettier": "^2.2.1",
"sandboxed-module": "2.0.4",
"sinon": "^9.0.1"
}

View File

@@ -8,8 +8,8 @@ const checkWord = (words, language) =>
url: `/user/${USER_ID}/check`,
body: JSON.stringify({
words,
language
})
language,
}),
})
describe('checking words', function () {
@@ -27,7 +27,7 @@ describe('checking words', 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'] }]
misspellings: [{ index: 0, suggestions: ['anther', 'another'] }],
})
})
})
@@ -44,7 +44,7 @@ describe('checking words', 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])
})
@@ -72,7 +72,7 @@ describe('checking words', 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])
@@ -96,7 +96,7 @@ describe('checking words', 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])
@@ -116,7 +116,7 @@ describe('checking words', 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])
})

View File

@@ -3,38 +3,38 @@ 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({
words
})
words,
}),
})
const learnWord = (word) =>
const learnWord = word =>
request.post({
url: `/user/${USER_ID}/learn`,
body: JSON.stringify({
word
})
word,
}),
})
const unlearnWord = (word) =>
const unlearnWord = word =>
request.post({
url: `/user/${USER_ID}/unlearn`,
body: JSON.stringify({
word
})
word,
}),
})
const getDict = () =>
request.get({
url: `/user/${USER_ID}`
url: `/user/${USER_ID}`,
})
const deleteDict = () =>
request.del({
url: `/user/${USER_ID}`
url: `/user/${USER_ID}`,
})
describe('learning words', function () {

View File

@@ -7,14 +7,14 @@ const BASE_URL = `http://${process.env.HTTP_TEST_HOST || 'localhost'}:${PORT}`
const request = require('request').defaults({
baseUrl: BASE_URL,
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
},
followRedirect: false
followRedirect: false,
})
module.exports = {
PORT,
get: promisify(request.get),
post: promisify(request.post),
del: promisify(request.del)
del: promisify(request.del),
}

View File

@@ -14,8 +14,8 @@ SandboxedModule.configure({
warn() {},
err() {},
error() {},
fatal() {}
}
fatal() {},
},
},
globals: { Buffer, JSON, console, process }
globals: { Buffer, JSON, console, process },
})

View File

@@ -24,7 +24,7 @@ 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 words = []
@@ -154,7 +154,7 @@ q.drain = () => console.log('all items have been processed')
for (let i = 0; i <= 1000; i++) {
q.push({
correct: Math.floor(30 * Math.random()) + 1,
incorrect: Math.floor(3 * Math.random())
incorrect: Math.floor(3 * Math.random()),
})
}
// if Math.random() < 0.1

View File

@@ -18,9 +18,9 @@ describe('ASpell', function () {
requires: {
'@overleaf/metrics': {
gauge() {},
inc() {}
}
}
inc() {},
},
},
}))
})
afterEach(function () {
@@ -111,7 +111,7 @@ describe('ASpell', function () {
return describe('when the request times out', function () {
beforeEach(function (done) {
const words = __range__(0, 1000, true).map((i) => 'abcdefg')
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) => {

View File

@@ -16,10 +16,10 @@ describe('ASpellWorker', function () {
requires: {
'@overleaf/metrics': {
gauge() {},
inc() {}
inc() {},
},
child_process: this.child_process
}
child_process: this.child_process,
},
}
))
})
@@ -31,7 +31,7 @@ describe('ASpellWorker', function () {
stderr: { on: sinon.stub() },
stdin: { on: sinon.stub() },
on: sinon.stub(),
pid: 12345
pid: 12345,
}
this.child_process.spawn = sinon.stub().returns(this.pipe)
this.pipe.stdout.setEncoding = sinon.stub()
@@ -92,7 +92,7 @@ describe('ASpellWorker', 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)
})
})

View File

@@ -12,13 +12,13 @@ describe('LearnedWordsManager', function () {
this.callback = sinon.stub()
this.db = {
spellingPreferences: {
updateOne: sinon.stub().yields()
}
updateOne: sinon.stub().yields(),
},
}
this.cache = {
get: sinon.stub(),
set: sinon.stub(),
del: sinon.stub()
del: sinon.stub(),
}
this.LearnedWordsManager = SandboxedModule.require(modulePath, {
requires: {
@@ -26,9 +26,9 @@ describe('LearnedWordsManager', function () {
'./MongoCache': this.cache,
'@overleaf/metrics': {
timeAsyncMethod: sinon.stub(),
inc: sinon.stub()
}
}
inc: sinon.stub(),
},
},
})
})
@@ -42,13 +42,13 @@ describe('LearnedWordsManager', function () {
expect(
this.db.spellingPreferences.updateOne.calledWith(
{
token: this.token
token: this.token,
},
{
$addToSet: { learnedWords: this.word }
$addToSet: { learnedWords: this.word },
},
{
upsert: true
upsert: true,
}
)
).to.equal(true)
@@ -69,10 +69,10 @@ describe('LearnedWordsManager', function () {
expect(
this.db.spellingPreferences.updateOne.calledWith(
{
token: this.token
token: this.token,
},
{
$pull: { learnedWords: this.word }
$pull: { learnedWords: this.word },
}
)
).to.equal(true)

View File

@@ -9,7 +9,7 @@ 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 () {
@@ -21,16 +21,16 @@ describe('SpellingAPIManager', function () {
learnWord: sinon.stub().callsArg(2),
unlearnWord: sinon.stub().callsArg(2),
promises: {
getLearnedWords: sinon.stub().returns(promiseStub(this.learnedWords))
}
getLearnedWords: sinon.stub().returns(promiseStub(this.learnedWords)),
},
}
this.SpellingAPIManager = SandboxedModule.require(modulePath, {
requires: {
'./ASpell': this.ASpell,
'settings-sharelatex': { ignoredMisspellings: ['ShareLaTeX'] },
'./LearnedWordsManager': this.LearnedWordsManager
}
'@overleaf/settings': { ignoredMisspellings: ['ShareLaTeX'] },
'./LearnedWordsManager': this.LearnedWordsManager,
},
})
})
@@ -43,14 +43,14 @@ describe('SpellingAPIManager', function () {
'are',
'speled',
'rong',
'lerned'
'lerned',
]
this.allWords = this.nonLearnedWords.concat(this.learnedWords)
this.misspellings = [
{ index: 2, suggestions: ['that'] },
{ index: 4, suggestions: ['spelled'] },
{ index: 5, suggestions: ['wrong', 'ring'] },
{ index: 6, suggestions: ['learned'] }
{ index: 6, suggestions: ['learned'] },
]
this.misspellingsWithoutLearnedWords = this.misspellings.slice(0, 3)
@@ -58,7 +58,7 @@ describe('SpellingAPIManager', function () {
callback(null, this.misspellings)
}
this.ASpell.promises = {
checkWords: sinon.stub().returns(promiseStub(this.misspellings))
checkWords: sinon.stub().returns(promiseStub(this.misspellings)),
}
sinon.spy(this.ASpell, 'checkWords')
})
@@ -140,7 +140,7 @@ describe('SpellingAPIManager', function () {
this.token,
{
words: this.allWords,
language: this.language
language: this.language,
},
(error, result) => {
this.result = result
@@ -181,7 +181,7 @@ describe('SpellingAPIManager', function () {
describe('learnWord', function () {
describe('without a token', function () {
beforeEach(function (done) {
this.SpellingAPIManager.learnWord(null, { word: 'banana' }, (error) => {
this.SpellingAPIManager.learnWord(null, { word: 'banana' }, error => {
this.error = error
done()
})
@@ -196,7 +196,7 @@ describe('SpellingAPIManager', function () {
describe('without a word', function () {
beforeEach(function (done) {
this.SpellingAPIManager.learnWord(this.token, {}, (error) => {
this.SpellingAPIManager.learnWord(this.token, {}, error => {
this.error = error
done()
})
@@ -215,7 +215,7 @@ describe('SpellingAPIManager', function () {
this.SpellingAPIManager.learnWord(
this.token,
{ word: this.word },
(error) => {
error => {
this.error = error
done()
}
@@ -233,14 +233,10 @@ 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()
}
)
this.SpellingAPIManager.unlearnWord(null, { word: 'banana' }, error => {
this.error = error
done()
})
})
it('should return an error', function () {
@@ -252,7 +248,7 @@ describe('SpellingAPIManager', function () {
describe('without a word', function () {
beforeEach(function (done) {
this.SpellingAPIManager.unlearnWord(this.token, {}, (error) => {
this.SpellingAPIManager.unlearnWord(this.token, {}, error => {
this.error = error
done()
})
@@ -271,7 +267,7 @@ describe('SpellingAPIManager', function () {
this.SpellingAPIManager.unlearnWord(
this.token,
{ word: this.word },
(error) => {
error => {
this.error = error
done()
}