mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Convert to ESM
GitOrigin-RevId: 097bc45d500b4d2538ee49d60a597619579419a5
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
const fs = require('fs')
|
||||
const Path = require('path')
|
||||
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { getCsrfTokenForFactory } = require('./support/Csrf')
|
||||
const { SmokeTestFailure } = require('./support/Errors')
|
||||
const {
|
||||
import fs from 'fs'
|
||||
import Path from 'path'
|
||||
import Settings from '@overleaf/settings'
|
||||
import { getCsrfTokenForFactory } from './support/Csrf.mjs'
|
||||
import { SmokeTestFailure } from './support/Errors.mjs'
|
||||
import {
|
||||
requestFactory,
|
||||
assertHasStatusCode,
|
||||
} = require('./support/requestHelper')
|
||||
const { processWithTimeout } = require('./support/timeoutHelper')
|
||||
} from './support/requestHelper.mjs'
|
||||
import { processWithTimeout } from './support/timeoutHelper.mjs'
|
||||
|
||||
const STEP_TIMEOUT = Settings.smokeTest.stepTimeout
|
||||
|
||||
const PATH_STEPS = Path.join(__dirname, './steps')
|
||||
const STEPS = fs
|
||||
.readdirSync(PATH_STEPS)
|
||||
.sort()
|
||||
.map(name => {
|
||||
const step = require(Path.join(PATH_STEPS, name))
|
||||
step.name = Path.basename(name, '.js')
|
||||
return step
|
||||
})
|
||||
const PATH_STEPS = Path.join(import.meta.dirname, './steps')
|
||||
const sortedSteps = fs.readdirSync(PATH_STEPS).sort()
|
||||
|
||||
const STEPS = []
|
||||
|
||||
for (const name of sortedSteps) {
|
||||
const step = (await import(Path.join(PATH_STEPS, name))).default
|
||||
step.name = Path.basename(name, '.mjs')
|
||||
STEPS.push(step)
|
||||
}
|
||||
|
||||
async function runSmokeTests({ isAborted, stats }) {
|
||||
let lastStep = stats.start
|
||||
@@ -92,4 +92,4 @@ async function runSmokeTests({ isAborted, stats }) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { runSmokeTests, SmokeTestFailure }
|
||||
export default { runSmokeTests, SmokeTestFailure }
|
||||
|
||||
@@ -4,4 +4,4 @@ async function run({ getCsrfTokenFor }) {
|
||||
return { loginCsrfToken }
|
||||
}
|
||||
|
||||
module.exports = { run }
|
||||
export default { run }
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
const Settings = require('@overleaf/settings')
|
||||
const {
|
||||
import Settings from '@overleaf/settings'
|
||||
import {
|
||||
overleafLoginRateLimiter,
|
||||
openProjectRateLimiter,
|
||||
} = require('../../../../app/src/infrastructure/RateLimiter')
|
||||
const LoginRateLimiter = require('../../../../app/src/Features/Security/LoginRateLimiter')
|
||||
} from '../../../../app/src/infrastructure/RateLimiter.js'
|
||||
import LoginRateLimiter from '../../../../app/src/Features/Security/LoginRateLimiter.js'
|
||||
|
||||
async function clearLoginRateLimit() {
|
||||
await LoginRateLimiter.promises.recordSuccessfulLogin(Settings.smokeTest.user)
|
||||
@@ -32,4 +32,4 @@ async function run({ processWithTimeout, timeout }) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { run }
|
||||
export default { run }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const Settings = require('@overleaf/settings')
|
||||
import Settings from '@overleaf/settings'
|
||||
|
||||
async function run({ assertHasStatusCode, loginCsrfToken, request }) {
|
||||
const response = await request('/login', {
|
||||
@@ -32,4 +32,4 @@ async function cleanup({ assertHasStatusCode, getCsrfTokenFor, request }) {
|
||||
assertHasStatusCode(response, 302)
|
||||
}
|
||||
|
||||
module.exports = { cleanup, run }
|
||||
export default { cleanup, run }
|
||||
|
||||
@@ -11,4 +11,4 @@ async function run({ request, assertHasStatusCode }) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { run }
|
||||
export default { run }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const Settings = require('@overleaf/settings')
|
||||
import Settings from '@overleaf/settings'
|
||||
|
||||
async function run({ assertHasStatusCode, request }) {
|
||||
const response = await request(`/project/${Settings.smokeTest.projectId}`)
|
||||
@@ -13,4 +13,4 @@ async function run({ assertHasStatusCode, request }) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { run }
|
||||
export default { run }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const OError = require('@overleaf/o-error')
|
||||
const { assertHasStatusCode } = require('./requestHelper')
|
||||
import OError from '@overleaf/o-error'
|
||||
import { assertHasStatusCode } from './requestHelper.mjs'
|
||||
const CSRF_REGEX = /<meta name="ol-csrfToken" content="(.+?)">/
|
||||
|
||||
function _parseCsrf(body) {
|
||||
export function _parseCsrf(body) {
|
||||
const match = CSRF_REGEX.exec(body)
|
||||
if (!match) {
|
||||
throw new Error('Cannot find csrfToken in HTML')
|
||||
@@ -10,7 +10,7 @@ function _parseCsrf(body) {
|
||||
return match[1]
|
||||
}
|
||||
|
||||
function getCsrfTokenForFactory({ request }) {
|
||||
export function getCsrfTokenForFactory({ request }) {
|
||||
return async function getCsrfTokenFor(endpoint) {
|
||||
try {
|
||||
const response = await request(endpoint)
|
||||
@@ -21,7 +21,3 @@ function getCsrfTokenForFactory({ request }) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getCsrfTokenForFactory,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
const OError = require('@overleaf/o-error')
|
||||
import OError from '@overleaf/o-error'
|
||||
|
||||
class SmokeTestFailure extends OError {}
|
||||
|
||||
module.exports = {
|
||||
SmokeTestFailure,
|
||||
}
|
||||
export class SmokeTestFailure extends OError {}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
const { Agent } = require('http')
|
||||
const { createConnection } = require('net')
|
||||
const { promisify } = require('util')
|
||||
|
||||
const OError = require('@overleaf/o-error')
|
||||
const request = require('request')
|
||||
const Settings = require('@overleaf/settings')
|
||||
import { Agent } from 'node:http'
|
||||
import { createConnection } from 'node:net'
|
||||
import { promisify } from 'node:util'
|
||||
import OError from '@overleaf/o-error'
|
||||
import request from 'request'
|
||||
import Settings from '@overleaf/settings'
|
||||
|
||||
// send requests to web router if this is the api process
|
||||
const OWN_PORT = Settings.port || Settings.internal.web.port || 3000
|
||||
@@ -27,7 +26,7 @@ class InsecureCookieJar extends request.jar().constructor {
|
||||
}
|
||||
}
|
||||
|
||||
function requestFactory({ timeout }) {
|
||||
export function requestFactory({ timeout }) {
|
||||
return promisify(
|
||||
request.defaults({
|
||||
agent: new LocalhostAgent(),
|
||||
@@ -43,7 +42,7 @@ function requestFactory({ timeout }) {
|
||||
)
|
||||
}
|
||||
|
||||
function assertHasStatusCode(response, expected) {
|
||||
export function assertHasStatusCode(response, expected) {
|
||||
const { statusCode: actual } = response
|
||||
if (actual !== expected) {
|
||||
throw new OError('unexpected response code', {
|
||||
@@ -53,8 +52,3 @@ function assertHasStatusCode(response, expected) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
assertHasStatusCode,
|
||||
requestFactory,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
async function processWithTimeout({ work, timeout, message }) {
|
||||
export async function processWithTimeout({ work, timeout, message }) {
|
||||
let workDeadLine
|
||||
function checkInResults() {
|
||||
clearTimeout(workDeadLine)
|
||||
@@ -12,7 +12,3 @@ async function processWithTimeout({ work, timeout, message }) {
|
||||
work.finally(checkInResults),
|
||||
])
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
processWithTimeout,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user