overleaf/services/web/cypress/plugins/index.js
Alf Eaton 5e9af2c15c Migrate worker tests to Cypress (#7359)
GitOrigin-RevId: f373f4215e5f25d14256008cf5f6582eb3124431
2022-04-07 08:03:52 +00:00

44 lines
1.3 KiB
JavaScript

module.exports = (on, config) => {
if (config.testingType === 'component') {
const { startDevServer } = require('@cypress/webpack-dev-server')
const { merge } = require('webpack-merge')
const path = require('path')
const webpack = require('webpack')
const devConfig = require('../../webpack.config.dev')
const webpackConfig = merge(devConfig, {
devServer: {
static: path.join(__dirname, '../../public'),
},
stats: 'none',
plugins: [
new webpack.EnvironmentPlugin({
CYPRESS: true,
}),
],
})
delete webpackConfig.devServer.client
webpackConfig.entry = {}
const addWorker = (name, importPath) => {
webpackConfig.entry[name] = require.resolve(importPath)
}
// add entrypoint under '/' for latex-linter worker
addWorker(
'latex-linter-worker',
'../../modules/source-editor/frontend/js/languages/latex/linter/latex-linter.worker.js'
)
// add entrypoints under '/' for pdfjs workers
const pdfjsVersions = ['pdfjs-dist210', 'pdfjs-dist213']
for (const name of pdfjsVersions) {
addWorker(name, `${name}/legacy/build/pdf.worker.js`)
}
on('dev-server:start', options => {
return startDevServer({ options, webpackConfig })
})
}
}