Files
2023-09-25 09:42:15 +08:00

36 lines
1017 B
TypeScript

import { _decorator } from 'cc';
import ps from 'path';
// @ts-expect-error Virtual module
import { runTest as runTest_ } from 'serialization-test-helper/run-test';
import { Port } from './port';
export const runTest: RunTest = runTest_;
export function getCaseName(fileName: string) {
const baseName = ps.basename(fileName, ps.dirname(fileName));
if (baseName.endsWith('.test.ts')) {
return baseName.substr(0, baseName.length - '.test.ts'.length);
} else {
return baseName;
}
}
export const ccclassAutoNamed = (fileName: string): ClassDecorator => {
const caseName = getCaseName(fileName);
return (target) => {
const className = target.name;
const ccName = `${caseName}.${className}`;
return cc._decorator.ccclass(ccName)(target);
};
};
export type RunTest = (
caseModulePath: string,
port: Readonly<Port>,
value: unknown,
verify?: (serialized: any) => void | Promise<void>,
env?: Record<string, any>,
) => Promise<void>;