Removed old desktop tests

This commit is contained in:
Lucas Dower 2023-04-10 00:59:36 +01:00
parent 67828071e4
commit a775fc0403
No known key found for this signature in database
GPG Key ID: B3EE6B8499593605
12 changed files with 6 additions and 599 deletions

View File

@ -1,7 +0,0 @@
{
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/test/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
}

View File

@ -4,5 +4,9 @@
},
"testRegex": "(/test/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"modulePathIgnorePatterns": ["/tests/full/"]
"modulePathIgnorePatterns": ["/tests/full/"],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|vs|fs)$": "<rootDir>/tests/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/tests/__mocks__/styleMock.js"
}
}

View File

@ -0,0 +1 @@
module.exports = {};

View File

@ -1,75 +0,0 @@
import fs from 'fs';
import path from 'path';
import { RGBAColours } from '../src/colour';
import { ObjImporter } from '../src/importers/obj_importer';
import { ASSERT } from '../src/util/error_util';
import { Vector3 } from '../src/vector';
import { NormalCorrectedRayVoxeliser } from '../src/voxelisers/normal-corrected-ray-voxeliser';
import { TEST_PREAMBLE } from './preamble';
test('Voxelise solid 2x2 cube', () => {
TEST_PREAMBLE();
const obj = fs.readFileSync(path.join(__dirname, './data/cube.obj'), 'utf-8');
const importer = new ObjImporter();
importer.parse(obj);
const mesh = importer.toMesh();
mesh.processMesh(0, 0, 0);
const voxeliser = new NormalCorrectedRayVoxeliser();
const voxelMesh = voxeliser.voxelise(mesh, {
constraintAxis: 'y',
size: 2,
useMultisampleColouring: false,
enableAmbientOcclusion: false,
voxelOverlapRule: 'average',
voxeliser: 'ncrb',
});
const expectedVoxels = [
{
position: new Vector3(0, 1, 0),
colour: RGBAColours.BLUE,
},
{
position: new Vector3(1, 1, 0),
colour: RGBAColours.GREEN,
},
{
position: new Vector3(1, 1, 1),
colour: RGBAColours.RED,
},
{
position: new Vector3(0, 1, 1),
colour: RGBAColours.WHITE,
},
{
position: new Vector3(1, 0, 1),
colour: RGBAColours.YELLOW,
},
{
position: new Vector3(1, 0, 0),
colour: RGBAColours.CYAN,
},
{
position: new Vector3(0, 0, 1),
colour: RGBAColours.BLACK,
},
{
position: new Vector3(0, 0, 0),
colour: RGBAColours.MAGENTA,
},
];
for (const expected of expectedVoxels) {
expect(voxelMesh.isVoxelAt(expected.position)).toBe(true);
const voxel = voxelMesh.getVoxelAt(expected.position);
expect(voxel).toBeDefined(); ASSERT(voxel);
expect(voxel.colour.r).toBeCloseTo(expected.colour.r);
expect(voxel.colour.g).toBeCloseTo(expected.colour.g);
expect(voxel.colour.b).toBeCloseTo(expected.colour.b);
expect(voxel.colour.a).toBeCloseTo(expected.colour.a);
}
});

View File

@ -1,205 +0,0 @@
import { ObjImporter } from '../src/importers/obj_importer';
import { ASSERT } from '../src/util/error_util';
import { Vector3 } from '../src/vector';
import { TEST_PREAMBLE } from './preamble';
test('Parse vertex #1', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('v 1.0 -2.0 3.0');
const mesh = importer.toMesh();
expect(mesh._vertices.length).toEqual(1);
expect(mesh._vertices[0].equals(new Vector3(1, -2, 3))).toBe(true);
});
test('Parse vertex #2', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('v 4.467e+000 9.243e+000 9.869e+000');
const mesh = importer.toMesh();
expect(mesh._vertices.length).toEqual(1);
expect(mesh._vertices[0].equals(new Vector3(4.467e+000, 9.243e+000, 9.869e+000))).toBe(true);
});
test('Parse normal #1', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('vn -1.0 -0.5 0.0');
const mesh = importer.toMesh();
expect(mesh._normals.length).toEqual(1);
expect(mesh._normals[0].equals(new Vector3(-1, -0.5, 0))).toBe(true);
});
test('Parse texcoord #1', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('vt 0.5 -0.8');
const mesh = importer.toMesh();
expect(mesh._uvs.length).toEqual(1);
expect(mesh._uvs[0].u === 0.5 && mesh._uvs[0].v === -0.8).toBe(true);
});
test('Parse face #1', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('f 12 24 36');
const mesh = importer.toMesh();
expect(mesh._tris.length).toEqual(1);
const tri = mesh._tris[0];
expect(tri.texcoordIndices).toBeDefined(); ASSERT(tri.texcoordIndices);
expect(tri.normalIndices).toBeDefined(); ASSERT(tri.normalIndices);
expect(tri.positionIndices.x === 12 - 1 && tri.positionIndices.y === 24 - 1 && tri.positionIndices.z === 36 - 1).toBe(true);
expect(tri.texcoordIndices.x === 12 - 1 && tri.texcoordIndices.y === 24 - 1 && tri.texcoordIndices.z === 36 - 1).toBe(true);
expect(tri.normalIndices.x === 12 - 1 && tri.normalIndices.y === 24 - 1 && tri.normalIndices.z === 36 - 1).toBe(true);
});
test('Parse face #2', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('f 1/2 3/4 5/6');
const mesh = importer.toMesh();
expect(mesh._tris.length).toEqual(1);
const tri = mesh._tris[0];
expect(tri.texcoordIndices).toBeDefined(); ASSERT(tri.texcoordIndices);
expect(tri.normalIndices).toBeUndefined();
expect(tri.positionIndices.x === 1 - 1 && tri.positionIndices.y === 3 - 1 && tri.positionIndices.z === 5 - 1).toBe(true);
expect(tri.texcoordIndices.x === 2 - 1 && tri.texcoordIndices.y === 4 - 1 && tri.texcoordIndices.z === 6 - 1).toBe(true);
});
test('Parse face #3', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('f 11/2/3 4/55/6 7/8/99');
const mesh = importer.toMesh();
expect(mesh._tris.length).toEqual(1);
const tri = mesh._tris[0];
expect(tri.texcoordIndices).toBeDefined(); ASSERT(tri.texcoordIndices);
expect(tri.normalIndices).toBeDefined(); ASSERT(tri.normalIndices);
expect(tri.positionIndices.x === 11 - 1 && tri.positionIndices.y === 4 - 1 && tri.positionIndices.z === 7 - 1).toBe(true);
expect(tri.texcoordIndices.x === 2 - 1 && tri.texcoordIndices.y === 55 - 1 && tri.texcoordIndices.z === 8 - 1).toBe(true);
expect(tri.normalIndices.x === 3 - 1 && tri.normalIndices.y === 6 - 1 && tri.normalIndices.z === 99 - 1).toBe(true);
});
test('Parse mini #1', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('v -1 2 3');
importer.parseOBJLine('v 4 -5 6');
importer.parseOBJLine('v 7 8 -9');
importer.parseOBJLine('vn 0.0 0.1 0.2');
importer.parseOBJLine('vn 0.3 0.4 0.5');
importer.parseOBJLine('vn 0.6 0.7 0.8');
importer.parseOBJLine('vt 0.0 0.5');
importer.parseOBJLine('vt 0.5 1.0');
importer.parseOBJLine('vt 1.0 0.0');
importer.parseOBJLine('f 1 2 3');
const mesh = importer.toMesh();
expect(mesh._vertices.length).toEqual(3);
expect(mesh._uvs.length).toEqual(3);
expect(mesh._normals.length).toEqual(3);
expect(mesh._tris.length).toEqual(1);
const vertexData = mesh.getVertices(0);
expect(vertexData.v0.equals(new Vector3(-1, 2, 3))).toBe(true);
expect(vertexData.v1.equals(new Vector3(4, -5, 6))).toBe(true);
expect(vertexData.v2.equals(new Vector3(7, 8, -9))).toBe(true);
const texcoordData = mesh.getUVs(0);
expect(texcoordData.uv0.u === 0.0 && texcoordData.uv0.v === 0.5).toBe(true);
expect(texcoordData.uv1.u === 0.5 && texcoordData.uv1.v === 1.0).toBe(true);
expect(texcoordData.uv2.u === 1.0 && texcoordData.uv2.v === 0.0).toBe(true);
const normalData = mesh.getNormals(0);
expect(normalData.v0.equals(new Vector3(0.0, 0.1, 0.2))).toBe(true);
expect(normalData.v1.equals(new Vector3(0.3, 0.4, 0.5))).toBe(true);
expect(normalData.v2.equals(new Vector3(0.6, 0.7, 0.8))).toBe(true);
});
test('Parse mini #2', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('v -1 2 3');
importer.parseOBJLine('v 4 -5 6');
importer.parseOBJLine('v 7 8 -9');
importer.parseOBJLine('vn 0.0 0.1 0.2');
importer.parseOBJLine('vn 0.3 0.4 0.5');
importer.parseOBJLine('vn 0.6 0.7 0.8');
importer.parseOBJLine('vt 0.0 0.5');
importer.parseOBJLine('vt 0.5 1.0');
importer.parseOBJLine('vt 1.0 0.0');
importer.parseOBJLine('f 3/1/2 1/2/3 2/3/1');
const mesh = importer.toMesh();
expect(mesh._vertices.length).toEqual(3);
expect(mesh._uvs.length).toEqual(3);
expect(mesh._normals.length).toEqual(3);
expect(mesh._tris.length).toEqual(1);
const vertexData = mesh.getVertices(0);
expect(vertexData.v0.equals(new Vector3(7, 8, -9))).toBe(true);
expect(vertexData.v1.equals(new Vector3(-1, 2, 3))).toBe(true);
expect(vertexData.v2.equals(new Vector3(4, -5, 6))).toBe(true);
const texcoordData = mesh.getUVs(0);
expect(texcoordData.uv0.u === 0.0 && texcoordData.uv0.v === 0.5).toBe(true);
expect(texcoordData.uv1.u === 0.5 && texcoordData.uv1.v === 1.0).toBe(true);
expect(texcoordData.uv2.u === 1.0 && texcoordData.uv2.v === 0.0).toBe(true);
const normalData = mesh.getNormals(0);
expect(normalData.v0.equals(new Vector3(0.3, 0.4, 0.5))).toBe(true);
expect(normalData.v1.equals(new Vector3(0.6, 0.7, 0.8))).toBe(true);
expect(normalData.v2.equals(new Vector3(0.0, 0.1, 0.2))).toBe(true);
});
test('Parse mini #3', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('v 0 0 0');
importer.parseOBJLine('v 1 0 0');
importer.parseOBJLine('v 0 1 0');
importer.parseOBJLine('f 1 2 3');
const mesh = importer.toMesh();
expect(mesh._vertices.length).toEqual(3);
expect(mesh._uvs.length).toEqual(0);
expect(mesh._normals.length).toEqual(0);
expect(mesh._tris.length).toEqual(1);
const texcoordData = mesh.getUVs(0);
expect(texcoordData.uv0.u === 0.0 && texcoordData.uv0.v === 0.0).toBe(true);
expect(texcoordData.uv1.u === 0.0 && texcoordData.uv1.v === 0.0).toBe(true);
expect(texcoordData.uv2.u === 0.0 && texcoordData.uv2.v === 0.0).toBe(true);
const normalData = mesh.getNormals(0);
expect(normalData.v0.equals(new Vector3(0.0, 0.0, 1.0))).toBe(true);
expect(normalData.v1.equals(new Vector3(0.0, 0.0, 1.0))).toBe(true);
expect(normalData.v2.equals(new Vector3(0.0, 0.0, 1.0))).toBe(true);
});
test('Parse comments', () => {
TEST_PREAMBLE();
const importer = new ObjImporter();
importer.parseOBJLine('# v -1 2 3');
importer.parseOBJLine('# vn 0.0 0.1 0.2');
importer.parseOBJLine('# vt 0.0 0.5');
importer.parseOBJLine('# f 1 1 1');
const mesh = importer.toMesh();
expect(mesh._vertices.length).toEqual(0);
expect(mesh._uvs.length).toEqual(0);
expect(mesh._normals.length).toEqual(0);
expect(mesh._tris.length).toEqual(0);
});

View File

@ -1,57 +0,0 @@
import fs from 'fs';
import path from 'path';
import { ColourSpace } from '../src/util';
import { AppPaths, PathUtil } from '../src/util/path_util';
import { Vector3 } from '../src/vector';
import { runHeadless, THeadlessConfig } from '../tools/headless';
import { TEST_PREAMBLE } from './preamble';
const baseConfig: THeadlessConfig = {
import: {
importer: 'obj',
fileSource: '', // Must be an absolute path
rotation: new Vector3(0, 0, 0),
},
voxelise: {
voxeliser: 'bvh-ray',
constraintAxis: 'y',
size: 80,
useMultisampleColouring: false,
voxelOverlapRule: 'average',
enableAmbientOcclusion: false, // Only want true if exporting to .obj
},
assign: {
textureAtlas: 'vanilla', // Must be an atlas name that exists in /resources/atlases
blockPalette: 'all', // Must be a palette name that exists in /resources/palettes
dithering: 'ordered',
colourSpace: ColourSpace.RGB,
fallable: 'replace-falling',
resolution: 32,
calculateLighting: false,
lightThreshold: 0,
contextualAveraging: true,
errorWeight: 0.0,
},
export: {
filepath: '', // Must be an absolute path to the file (can be anywhere)
exporter: 'obj', // 'schematic' / 'litematic',
},
debug: {
showLogs: false,
showWarnings: false,
showTimings: false,
},
};
test('FULL Obj->Obj', () => {
TEST_PREAMBLE();
const config: THeadlessConfig = baseConfig;
config.import.fileSource = fs.readFileSync(PathUtil.join(AppPaths.Get.resources, './samples/skull.obj'), 'utf-8');
config.export.exporter = 'litematic';
config.export.filepath = PathUtil.join(AppPaths.Get.testData, '../out/out.litematic');
runHeadless(config);
});

View File

@ -1,56 +0,0 @@
import fs from 'fs';
import { ColourSpace } from '../src/util';
import { AppPaths, PathUtil } from '../src/util/path_util';
import { Vector3 } from '../src/vector';
import { runHeadless, THeadlessConfig } from '../tools/headless';
import { TEST_PREAMBLE } from './preamble';
const baseConfig: THeadlessConfig = {
import: {
importer: 'obj',
fileSource: '', // Must be an absolute path // Must be an absolute path
rotation: new Vector3(0, 0, 0),
},
voxelise: {
voxeliser: 'bvh-ray',
constraintAxis: 'y',
size: 80,
useMultisampleColouring: false,
voxelOverlapRule: 'average',
enableAmbientOcclusion: false, // Only want true if exporting to .obj
},
assign: {
textureAtlas: 'vanilla', // Must be an atlas name that exists in /resources/atlases
blockPalette: 'all', // Must be a palette name that exists in /resources/palettes
dithering: 'ordered',
colourSpace: ColourSpace.RGB,
fallable: 'replace-falling',
resolution: 32,
calculateLighting: false,
lightThreshold: 0,
contextualAveraging: true,
errorWeight: 0.0,
},
export: {
filepath: '', // Must be an absolute path to the file (can be anywhere)
exporter: 'obj', // 'schematic' / 'litematic',
},
debug: {
showLogs: false,
showWarnings: false,
showTimings: false,
},
};
test('FULL Obj->Obj', () => {
TEST_PREAMBLE();
const config: THeadlessConfig = baseConfig;
config.import.fileSource = PathUtil.join(AppPaths.Get.resources, './samples/skull.obj');
config.export.exporter = 'obj';
config.export.filepath = PathUtil.join(AppPaths.Get.testData, '../out/out.obj');
runHeadless(config);
});

View File

@ -1,56 +0,0 @@
import fs from 'fs';
import { ColourSpace } from '../src/util';
import { AppPaths, PathUtil } from '../src/util/path_util';
import { Vector3 } from '../src/vector';
import { runHeadless, THeadlessConfig } from '../tools/headless';
import { TEST_PREAMBLE } from './preamble';
const baseConfig: THeadlessConfig = {
import: {
importer: 'obj',
fileSource: '', // Must be an absolute path
rotation: new Vector3(0, 0, 0),
},
voxelise: {
voxeliser: 'bvh-ray',
constraintAxis: 'y',
size: 80,
useMultisampleColouring: false,
voxelOverlapRule: 'average',
enableAmbientOcclusion: false, // Only want true if exporting to .obj
},
assign: {
textureAtlas: 'vanilla', // Must be an atlas name that exists in /resources/atlases
blockPalette: 'all', // Must be a palette name that exists in /resources/palettes
dithering: 'ordered',
colourSpace: ColourSpace.RGB,
fallable: 'replace-falling',
resolution: 32,
calculateLighting: false,
lightThreshold: 0,
contextualAveraging: true,
errorWeight: 0.0,
},
export: {
filepath: '', // Must be an absolute path to the file (can be anywhere)
exporter: 'obj', // 'schematic' / 'litematic',
},
debug: {
showLogs: false,
showWarnings: false,
showTimings: false,
},
};
test('FULL Obj->Obj', () => {
TEST_PREAMBLE();
const config: THeadlessConfig = baseConfig;
config.import.fileSource = fs.readFileSync(PathUtil.join(AppPaths.Get.resources, './samples/skull.obj'), 'utf-8');
config.export.exporter = 'schem';
config.export.filepath = PathUtil.join(AppPaths.Get.testData, '../out/out.schem');
runHeadless(config);
});

View File

@ -1,56 +0,0 @@
import fs from 'fs';
import { ColourSpace } from '../src/util';
import { AppPaths, PathUtil } from '../src/util/path_util';
import { Vector3 } from '../src/vector';
import { runHeadless, THeadlessConfig } from '../tools/headless';
import { TEST_PREAMBLE } from './preamble';
const baseConfig: THeadlessConfig = {
import: {
importer: 'obj',
fileSource: '', // Must be an absolute path
rotation: new Vector3(0, 0, 0),
},
voxelise: {
voxeliser: 'bvh-ray',
constraintAxis: 'y',
size: 80,
useMultisampleColouring: false,
voxelOverlapRule: 'average',
enableAmbientOcclusion: false, // Only want true if exporting to .obj
},
assign: {
textureAtlas: 'vanilla', // Must be an atlas name that exists in /resources/atlases
blockPalette: 'all', // Must be a palette name that exists in /resources/palettes
dithering: 'ordered',
colourSpace: ColourSpace.RGB,
fallable: 'replace-falling',
resolution: 32,
calculateLighting: false,
lightThreshold: 0,
contextualAveraging: true,
errorWeight: 0.0,
},
export: {
filepath: '', // Must be an absolute path to the file (can be anywhere)
exporter: 'obj', // 'schematic' / 'litematic',
},
debug: {
showLogs: false,
showWarnings: false,
showTimings: false,
},
};
test('FULL Obj->Schematic', () => {
TEST_PREAMBLE();
const config: THeadlessConfig = baseConfig;
config.import.fileSource = fs.readFileSync(PathUtil.join(AppPaths.Get.resources, './samples/skull.obj'), 'utf-8');
config.export.exporter = 'schematic';
config.export.filepath = PathUtil.join(AppPaths.Get.testData, '../out/out.schematic');
runHeadless(config);
});

View File

@ -1,23 +0,0 @@
import fs from 'fs';
import { StatusHandler, StatusID } from '../src/status';
import { AppPaths, PathUtil } from '../src/util/path_util';
import { WorkerClient } from '../src/worker_client';
import { headlessConfig } from '../tools/headless-config';
import { TEST_PREAMBLE } from './preamble';
test('Random-dither', () => {
TEST_PREAMBLE();
const config = headlessConfig;
config.import.fileSource = fs.readFileSync(PathUtil.join(AppPaths.Get.resources, './samples/skull.obj'), 'utf-8');
config.assign.dithering = 'random';
const worker = WorkerClient.Get;
worker.import(headlessConfig.import);
worker.voxelise(headlessConfig.voxelise);
worker.assign(headlessConfig.assign);
expect(StatusHandler.Get.hasId(StatusID.SchematicUnsupportedBlocks)).toBe(false);
});

View File

@ -1,27 +0,0 @@
import fs from 'fs';
import { StatusHandler, StatusID } from '../src/status';
import { AppPaths, PathUtil } from '../src/util/path_util';
import { WorkerClient } from '../src/worker_client';
import { headlessConfig } from '../tools/headless-config';
import { TEST_PREAMBLE } from './preamble';
test('Schematic-friendly Palette', () => {
TEST_PREAMBLE();
const config = headlessConfig;
config.import.fileSource = fs.readFileSync(PathUtil.join(AppPaths.Get.resources, './samples/skull.obj'), 'utf-8');
config.assign.blockPalette = 'schematic-friendly';
config.export.exporter = 'schematic';
config.export.filepath = PathUtil.join(AppPaths.Get.testData, '../out/friendly.schematic');
const worker = WorkerClient.Get;
worker.import(headlessConfig.import);
worker.voxelise(headlessConfig.voxelise);
worker.assign(headlessConfig.assign);
worker.export(headlessConfig.export);
expect(StatusHandler.Get.hasId(StatusID.SchematicUnsupportedBlocks)).toBe(false);
});

View File

@ -1,36 +0,0 @@
import { StatusHandler } from '../src/status';
import { TEST_PREAMBLE } from './preamble';
test('Status', () => {
TEST_PREAMBLE();
StatusHandler.Get.add(
'warning',
'This is a warning',
);
expect(StatusHandler.Get.getStatusMessages('warning').length).toBe(1);
StatusHandler.Get.clear();
expect(StatusHandler.Get.getStatusMessages('warning').length).toBe(0);
});
test('Status', () => {
TEST_PREAMBLE();
StatusHandler.Get.add(
'warning',
'This is a warning',
);
StatusHandler.Get.add(
'info',
'This is some info',
);
StatusHandler.Get.add(
'info',
'This is some more info',
);
expect(StatusHandler.Get.getStatusMessages('info').length).toBe(2);
expect(StatusHandler.Get.getStatusMessages('warning').length).toBe(1);
StatusHandler.Get.clear();
expect(StatusHandler.Get.getStatusMessages('info').length).toBe(0);
expect(StatusHandler.Get.getStatusMessages('warning').length).toBe(0);
});