perf: reduce 3D runtime artifacts (#7)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { readFileSync, statSync } from 'node:fs';
|
||||
import { existsSync, readFileSync, statSync } from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
@@ -11,21 +11,25 @@ function sha256(path: string): string {
|
||||
}
|
||||
|
||||
describe('decoder staging', () => {
|
||||
it('copies decoder binaries byte-for-byte without executable permission', () => {
|
||||
const threeRoot = resolve(
|
||||
dirname(fileURLToPath(import.meta.resolve('three'))),
|
||||
'..',
|
||||
);
|
||||
it('stages only the single-thread IFC runtime', () => {
|
||||
expect(
|
||||
existsSync(
|
||||
resolve(projectRoot, 'apps/viewer-3d/public/web-ifc/web-ifc-mt.wasm'),
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('does not stage decoder copies already bundled by Three.js', () => {
|
||||
for (const directory of ['draco', 'basis']) {
|
||||
expect(
|
||||
existsSync(resolve(projectRoot, 'apps/viewer-3d/public', directory)),
|
||||
).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it('copies the IFC binary byte-for-byte without executable permission', () => {
|
||||
const ifcRoot = dirname(fileURLToPath(import.meta.resolve('web-ifc')));
|
||||
const pairs = [
|
||||
[
|
||||
resolve(threeRoot, 'examples/jsm/libs/draco/gltf/draco_decoder.wasm'),
|
||||
resolve(projectRoot, 'apps/viewer-3d/public/draco/draco_decoder.wasm'),
|
||||
],
|
||||
[
|
||||
resolve(threeRoot, 'examples/jsm/libs/basis/basis_transcoder.wasm'),
|
||||
resolve(projectRoot, 'apps/viewer-3d/public/basis/basis_transcoder.wasm'),
|
||||
],
|
||||
[
|
||||
resolve(ifcRoot, 'web-ifc.wasm'),
|
||||
resolve(projectRoot, 'apps/viewer-3d/public/web-ifc/web-ifc.wasm'),
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test('viewer3d resolves Draco and IFC decoders under a production subpath', async ({ page }) => {
|
||||
test('viewer3d resolves hashed Draco and staged IFC decoders under a production subpath', async ({
|
||||
page,
|
||||
}) => {
|
||||
const failedRequests: string[] = [];
|
||||
const responseUrls: string[] = [];
|
||||
page.on('requestfailed', (request) => failedRequests.push(request.url()));
|
||||
@@ -24,7 +26,11 @@ test('viewer3d resolves Draco and IFC decoders under a production subpath', asyn
|
||||
);
|
||||
}
|
||||
|
||||
expect(responseUrls.some((url) => url.includes('/viewer-3d/draco/'))).toBe(true);
|
||||
expect(
|
||||
responseUrls.some((url) =>
|
||||
/\/viewer-3d\/assets\/draco_decoder-.+\.wasm$/.test(new URL(url).pathname),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(responseUrls.some((url) => url.endsWith('/viewer-3d/web-ifc/web-ifc.wasm'))).toBe(true);
|
||||
expect(failedRequests).toEqual([]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user