wrolpi/app/cypress.config.js
lrnselfreliance 2e0e50c3aa
3D previews load ASCII STLs, stand upright, and fit the preview modal (#952)
* STL files preview with three's own STLLoader

react-stl-viewer inlines a copy of three-stdlib 2.17.2's STLLoader, which reads
ASCII STL text with LoaderUtils.decodeText.  three removed that in r175, so
every ASCII STL preview failed.  The three-stdlib override never reached that
copy, and react-stl-viewer has had no release since January 2024.

The 3MF preview's three.js viewer now previews STL files too, loading each
format with the loader that ships with three, so the loader always matches the
installed three.  react-stl-viewer and the three-stdlib override are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* An e2e spec previews ASCII and binary STL files in a real browser

The STL preview only fails in a browser with WebGL, so the spec opens both
encodings on the live stack and checks the dimensions line appears without a
load error.  fb:reset can now write binary files ({base64: ...}).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* STL previews stand Z-up models upright

STLs are Z-up (the 3D printing convention) and three is Y-up, so the
preview rotates STL geometry to stand the model upright, as react-stl-viewer
did.  Model Z reads as Height again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* 3MF previews stand Z-up models upright too

3MF is Z-up like STL, so the rotation moves from the STL loader into the
shared viewer and applies to every model.  Model Z reads as Height.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* File previews show their buttons without scrolling

.preview-fit reserved a fixed 18.75rem for the rest of the preview modal,
which was short: every framed preview overflowed a little, and a 3D model's
dimensions line pushed the action buttons below the fold.  The preview modal
now fills its height as a flex column, and the .preview-fit takes whatever
height is left.  Previews without a .preview-fit keep their content's height.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* 3D previews frame the model and light it brightly

- The camera fits the model's bounding sphere into the narrower field of view,
  from a raised three-quarter front view, instead of backing off 2.2x along Z.
- A hemisphere light and a headlight that follows the camera (from a little
  above and left) replace lights whose intensities were set before three's
  r155 lighting change and read dim.
- Geometry without normals (3MF) gets creased normals, so flat faces no longer
  shade into their neighbors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 15:33:58 -07:00

129 lines
5.2 KiB
JavaScript

const path = require("path");
const fs = require("fs");
const { defineConfig } = require("cypress");
/*
* Real-file tasks for the FileBrowser e2e tests.
*
* The tests exercise the live stack (delete/rename/move really happen), so every task is
* jailed to one sandbox directory inside the media directory. `test/` also holds shared
* fixtures the whole suite depends on -- a task that could write or delete outside the
* sandbox would let a buggy test destroy them.
*/
const MEDIA_DIR = process.env.WROLPI_MEDIA_DIR || path.resolve(__dirname, "..", "test");
const SANDBOX_NAME = "cypress-fb";
const SANDBOX_DIR = path.join(MEDIA_DIR, SANDBOX_NAME);
function sandboxPath(relativePath) {
const resolved = path.resolve(SANDBOX_DIR, relativePath || ".");
if (resolved !== SANDBOX_DIR && !resolved.startsWith(SANDBOX_DIR + path.sep)) {
throw new Error(`Refusing to touch path outside the sandbox: ${relativePath}`);
}
return resolved;
}
function fileContent(content) {
return content && content.base64 !== undefined ? Buffer.from(content.base64, "base64") : (content ?? "");
}
const fileBrowserTasks = {
// Wipe the sandbox (including leftovers from a crashed run) and create the given files.
// `files` maps sandbox-relative paths to file content; a trailing '/' makes a bare directory.
// Content is text, or `{base64: '...'}` for a binary file.
"fb:reset": ({ files }) => {
fs.rmSync(SANDBOX_DIR, { recursive: true, force: true });
fs.mkdirSync(SANDBOX_DIR, { recursive: true });
for (const [relativePath, content] of Object.entries(files || {})) {
if (relativePath.endsWith("/")) {
fs.mkdirSync(sandboxPath(relativePath), { recursive: true });
} else {
const filePath = sandboxPath(relativePath);
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, fileContent(content));
}
}
return SANDBOX_NAME;
},
// Add files to the existing sandbox without wiping it (e.g. behind the UI's back).
"fb:seed": ({ files }) => {
for (const [relativePath, content] of Object.entries(files || {})) {
const filePath = sandboxPath(relativePath);
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, content ?? "");
}
return true;
},
"fb:exists": (relativePath) => fs.existsSync(sandboxPath(relativePath)),
"fb:readdir": (relativePath) => {
const dir = sandboxPath(relativePath);
return fs.existsSync(dir) ? fs.readdirSync(dir).sort() : null;
},
"fb:cleanup": () => {
fs.rmSync(SANDBOX_DIR, { recursive: true, force: true });
return true;
},
// Tagging creates a hardlink under <media>/tags/<TagName>/, and a force-deleted file
// leaves that link behind (the tags-directory sync refuses to remove it). Only tag
// directories created by these tests may be removed: the name must start with 'CypressFB'.
"fb:cleanup-tag-dir": (tagName) => {
if (!/^CypressFB[A-Za-z0-9]*$/.test(tagName)) {
throw new Error(`Refusing to remove tag directory not owned by the tests: ${tagName}`);
}
fs.rmSync(path.join(MEDIA_DIR, "tags", tagName), { recursive: true, force: true });
return true;
},
};
module.exports = defineConfig({
e2e: {
setupNodeEvents(on) {
on("task", fileBrowserTasks);
},
// Use HTTP for CI, HTTPS for local development
baseUrl: process.env.CI ? 'http://localhost:3000' : 'https://localhost:8443',
specPattern: 'cypress/e2e/**/*.cy.js',
supportFile: 'cypress/support/e2e.js',
video: process.env.CI ? true : false,
screenshotOnRunFailure: true,
env: {
CI: !!process.env.CI,
},
},
component: {
devServer: {
// Cypress removed its create-react-app framework, so hand it the same webpack config
// `npm start` uses, minus the entry, output and HTML plugins Cypress supplies itself.
framework: "react",
bundler: "webpack",
webpackConfig: () => {
// react-scripts reads both of these at require time.
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
process.env.BABEL_ENV = process.env.BABEL_ENV || 'development';
const config = require('react-scripts/config/webpack.config')('development');
delete config.entry;
delete config.output;
delete config.optimization;
const cypressOwnsThese = [
'HtmlWebpackPlugin', 'InterpolateHtmlPlugin', 'MiniCssExtractPlugin',
'WebpackManifestPlugin', 'ManifestPlugin', 'ModuleNotFoundPlugin',
'ForkTsCheckerWebpackPlugin',
];
config.plugins = (config.plugins || [])
.filter(plugin => !cypressOwnsThese.includes(plugin.constructor.name));
// react-scripts only babel-loads `src`; the JSX support file lives in `cypress/`.
const alsoCompile = [path.resolve(__dirname, 'cypress')];
const widenBabel = (rules) => rules.forEach((rule) => {
if (rule.oneOf) return widenBabel(rule.oneOf);
const loader = String(rule.loader || '');
if (loader.includes('babel-loader') && rule.include) {
rule.include = [].concat(rule.include, alsoCompile);
}
});
widenBabel(config.module.rules);
return config;
},
},
},
});