mirror of
https://github.com/flarum/core.git
synced 2025-08-06 16:36:47 +02:00
test: add frontend tests (#3991)
This commit is contained in:
@@ -11,11 +11,13 @@ class OverrideChunkLoaderFunction {
|
||||
// The function is called by webpack so we can't just override it.
|
||||
compiler.hooks.compilation.tap('OverrideChunkLoaderFunction', (compilation) => {
|
||||
compilation.mainTemplate.hooks.requireEnsure.tap('OverrideChunkLoaderFunction', (source) => {
|
||||
return source + '\nconst originalLoadChunk = __webpack_require__.l;\n__webpack_require__.l = flarum.reg.loadChunk.bind(flarum.reg, originalLoadChunk);';
|
||||
return (
|
||||
source +
|
||||
'\nconst originalLoadChunk = __webpack_require__.l;\n__webpack_require__.l = flarum.reg.loadChunk.bind(flarum.reg, originalLoadChunk);'
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = OverrideChunkLoaderFunction;
|
||||
|
@@ -7,7 +7,7 @@ class RegisterAsyncChunksPlugin {
|
||||
static registry = {};
|
||||
|
||||
processUrlPath(urlPath) {
|
||||
if (path.sep == "\\") {
|
||||
if (path.sep == '\\') {
|
||||
// separator on windows is "\", this will cause escape issues when used in url path.
|
||||
return urlPath.replace(/\\/g, '/');
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
const path = require("path");
|
||||
const {getOptions} = require("loader-utils");
|
||||
const {validate} = require("schema-utils");
|
||||
const fs = require("fs");
|
||||
const path = require('path');
|
||||
const { getOptions } = require('loader-utils');
|
||||
const { validate } = require('schema-utils');
|
||||
const fs = require('fs');
|
||||
|
||||
const optionsSchema = {
|
||||
type: 'object',
|
||||
@@ -66,7 +66,7 @@ module.exports = function autoChunkNameLoader(source) {
|
||||
chunkPath = absolutePathToImport.split(`src${path.sep}`)[1];
|
||||
}
|
||||
|
||||
if (path.sep == "\\") {
|
||||
if (path.sep == '\\') {
|
||||
// separator on windows is '\', the resolver only works with '/'.
|
||||
chunkPath = chunkPath.replace(/\\/g, '/');
|
||||
}
|
||||
@@ -76,7 +76,9 @@ module.exports = function autoChunkNameLoader(source) {
|
||||
webpackMode: 'lazy-once',
|
||||
};
|
||||
|
||||
const comment = Object.entries(webpackCommentOptions).map(([key, value]) => `${key}: '${value}'`).join(', ');
|
||||
const comment = Object.entries(webpackCommentOptions)
|
||||
.map(([key, value]) => `${key}: '${value}'`)
|
||||
.join(', ');
|
||||
|
||||
// Return the new import statement
|
||||
return `${pre}import(/* ${comment} */ '${relativePathToImport}')`;
|
||||
|
@@ -98,7 +98,7 @@ function addAutoExports(source, pathToModule, moduleName) {
|
||||
|
||||
if (matches.length) {
|
||||
const map = matches.reduce((map, match) => {
|
||||
const names = match[1] ? match[1].split(',') : (match[2] ? [match[2]] : null);
|
||||
const names = match[1] ? match[1].split(',') : match[2] ? [match[2]] : null;
|
||||
|
||||
if (!names) {
|
||||
return map;
|
||||
@@ -179,7 +179,8 @@ module.exports = function autoExportLoader(source) {
|
||||
// Get the path of the module to be exported
|
||||
// relative to the src directory.
|
||||
// Example: src/forum/components/UserCard.js => forum/components
|
||||
const pathToModule = path.relative(path.resolve(this.rootContext, 'src'), this.resourcePath)
|
||||
const pathToModule = path
|
||||
.relative(path.resolve(this.rootContext, 'src'), this.resourcePath)
|
||||
.replaceAll(path.sep, '/')
|
||||
.replace(/[A-Za-z_]+\.[A-Za-z_]+$/, '');
|
||||
|
||||
|
@@ -1,3 +1 @@
|
||||
module.exports = (name) => name === 'flarum/core'
|
||||
? 'core'
|
||||
: name.replace('/flarum-ext-', '-').replace('/flarum-', '').replace('/', '-')
|
||||
module.exports = (name) => (name === 'flarum/core' ? 'core' : name.replace('/flarum-ext-', '-').replace('/flarum-', '').replace('/', '-'));
|
||||
|
@@ -1,8 +1,8 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { NormalModuleReplacementPlugin } = require('webpack');
|
||||
const RegisterAsyncChunksPlugin = require("./RegisterAsyncChunksPlugin.cjs");
|
||||
const OverrideChunkLoaderFunction = require("./OverrideChunkLoaderFunction.cjs");
|
||||
const RegisterAsyncChunksPlugin = require('./RegisterAsyncChunksPlugin.cjs');
|
||||
const OverrideChunkLoaderFunction = require('./OverrideChunkLoaderFunction.cjs');
|
||||
|
||||
const entryPointNames = ['forum', 'admin'];
|
||||
const entryPointExts = ['js', 'ts'];
|
||||
@@ -106,8 +106,8 @@ module.exports = function () {
|
||||
cacheGroups: {
|
||||
// Avoid node_modules being split into separate chunks
|
||||
defaultVendors: false,
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
output: {
|
||||
|
Reference in New Issue
Block a user