MCPcopy Create free account
hub / github.com/abaplint/transpiler / unitTestScriptOpen

Method unitTestScriptOpen

packages/transpiler/src/unit_test.ts:18–76  ·  view source on GitHub ↗
(reg: abaplint.IRegistry, _skip?: TestMethodList)

Source from the content-addressed store, hash-verified

16export class UnitTest {
17
18 public unitTestScriptOpen(reg: abaplint.IRegistry, _skip?: TestMethodList): string {
19 let ret = `/* eslint-disable curly */
20import fs from "fs";
21import path from "path";
22import {fileURLToPath} from "url";
23import "./init.mjs";
24
25const __dirname = path.dirname(fileURLToPath(import.meta.url));
26
27async function run() {
28 let lt_input = new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character(30), testclass_name: new abap.types.Character(30), method_name: new abap.types.Character(30)}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]});
29 let ls_input = new abap.types.Structure({class_name: new abap.types.Character(30), testclass_name: new abap.types.Character(30), method_name: new abap.types.Character(30)});
30 let ls_result = new abap.types.Structure({list: new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character(30), testclass_name: new abap.types.Character(30), method_name: new abap.types.Character(30), expected: new abap.types.String(), actual: new abap.types.String(), status: new abap.types.String(), runtime: new abap.types.Integer(), message: new abap.types.String(), js_location: new abap.types.String(), console: new abap.types.String()}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]}), json: new abap.types.String()});
31`;
32
33 for (const obj of reg.getObjects()) {
34 if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
35 continue;
36 }
37 const hasTestFile = obj.getFiles().some(f => { return f.getFilename().includes(".testclasses."); });
38 if (hasTestFile === true) {
39 ret += ` await import("./${escapeNamespaceFilename(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}.testclasses.mjs");\n`;
40 }
41
42 for (const file of obj.getABAPFiles()) {
43 for (const def of file.getInfo().listClassDefinitions()) {
44 if (def.isForTesting === false || def.isGlobal === true || def.methods.length === 0) {
45 // todo, fix, there might be global test methods
46 continue;
47 }
48
49 for (const m of def.methods) {
50 if (m.isForTesting === false) {
51 continue;
52 }
53 ret += ` ls_input.get().class_name.set("${obj.getName()}");
54 ls_input.get().testclass_name.set("${def.name.toUpperCase()}");
55 ls_input.get().method_name.set("${m.name.toUpperCase()}");
56 abap.statements.append({source: ls_input, target: lt_input});\n`;
57 }
58 }
59 }
60 }
61
62 ret += `
63
64 ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
65 fs.writeFileSync(__dirname + path.sep + "output.json", ls_result.get().json.get());
66}
67
68run().then(() => {
69 process.exit(0);
70}).catch((err) => {
71 console.log(err);
72 process.exit(1);
73});`;
74
75 return ret;

Callers 1

runMethod · 0.80

Calls 3

escapeNamespaceFilenameFunction · 0.90
getFilenameMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected