| 178 | } |
| 179 | |
| 180 | public unitTestScript(reg: abaplint.IRegistry, skip?: TestMethodList): string { |
| 181 | const callSpecial = (name: string) => { |
| 182 | let ret = ""; |
| 183 | ret += `if (test.${name}) await test.${name}();\n`; |
| 184 | ret += ` if (test.FRIENDS_ACCESS_INSTANCE.${name}) await test.FRIENDS_ACCESS_INSTANCE.${name}();\n`; |
| 185 | ret += ` if (test.FRIENDS_ACCESS_INSTANCE.SUPER && test.FRIENDS_ACCESS_INSTANCE.SUPER.${name}) await test.FRIENDS_ACCESS_INSTANCE.SUPER.${name}();`; |
| 186 | return ret; |
| 187 | }; |
| 188 | |
| 189 | let ret = `/* eslint-disable curly */ |
| 190 | /* eslint-disable max-len */ |
| 191 | import "./init.mjs"; |
| 192 | |
| 193 | function getData() { |
| 194 | const ret = [];\n`; |
| 195 | for (const st of this.getSortedTests(reg)) { |
| 196 | const methods = []; |
| 197 | for (const m of st.methods) { |
| 198 | const skipThis = (skip || []).some(a => a.object.toUpperCase() === st.obj.getName().toUpperCase() |
| 199 | && a.class.toUpperCase() === st.localClass.toUpperCase() |
| 200 | && a.method.toUpperCase() === m.toUpperCase()); |
| 201 | methods.push({ |
| 202 | name: m, |
| 203 | skip: skipThis, |
| 204 | }); |
| 205 | } |
| 206 | |
| 207 | ret += ` ret.push({objectName: "${st.obj.getName()}", |
| 208 | localClass: "${st.localClass}", |
| 209 | methods: ${JSON.stringify(methods)}, |
| 210 | riskLevel: "${st.riskLevel}", |
| 211 | filename: "${st.filename}"});\n`; |
| 212 | } |
| 213 | ret += ` return ret; |
| 214 | } |
| 215 | |
| 216 | async function run() { |
| 217 | const skipCritical = process.argv[2] === "--skip-critical"; |
| 218 | const onlyCritical = process.argv[2] === "--only-critical"; |
| 219 | for (const st of getData()) { |
| 220 | const imported = await import(st.filename); |
| 221 | const localClass = imported[st.localClass]; |
| 222 | if (localClass.class_setup) await localClass.class_setup(); |
| 223 | for (const m of st.methods) { |
| 224 | const prefix = st.objectName + ": running " + st.localClass + "->" + m.name; |
| 225 | if (m.skip) { |
| 226 | console.log(prefix + ", skipped due to configuration"); |
| 227 | } else if (skipCritical && st.riskLevel === "CRITICAL") { |
| 228 | console.log(prefix + ", skipped due to risk level " + st.riskLevel); |
| 229 | } else if (onlyCritical && st.riskLevel !== "CRITICAL") { |
| 230 | console.log(prefix + ", skipped due to risk level " + st.riskLevel); |
| 231 | } else { |
| 232 | const test = await (new localClass()).constructor_(); |
| 233 | ${callSpecial("setup")} |
| 234 | console.log(prefix); |
| 235 | await test.FRIENDS_ACCESS_INSTANCE[m.name](); |
| 236 | ${callSpecial("teardown")} |
| 237 | } |