| 1 |
/** @odoo-module */ |
| 2 |
|
| 3 |
import { DEFAULT_EVENT_TYPES } from "../hoot_utils"; |
| 4 |
import { generateSeed } from "../mock/math"; |
| 5 |
|
| 6 |
/** |
| 7 |
* @typedef {keyof typeof FILTER_SCHEMA} SearchFilter |
| 8 |
*/ |
| 9 |
|
| 10 |
//----------------------------------------------------------------------------- |
| 11 |
// Global |
| 12 |
//----------------------------------------------------------------------------- |
| 13 |
|
| 14 |
const { |
| 15 |
Number: { parseFloat: $parseFloat }, |
| 16 |
Object: { entries: $entries, fromEntries: $fromEntries, keys: $keys }, |
| 17 |
} = globalThis; |
| 18 |
|
| 19 |
//----------------------------------------------------------------------------- |
| 20 |
// Internal |
| 21 |
//----------------------------------------------------------------------------- |
| 22 |
|
| 23 |
/** |
| 24 |
* @template {Record<string, any>} T |
| 25 |
* @param {T} schema |
| 26 |
* @returns {{ [key in keyof T]: ReturnType<T[key]["parse"]> }} |
| 27 |
*/ |
| 28 |
function getSchemaDefaults(schema) { |
| 29 |
return $fromEntries($entries(schema).map(([key, value]) => [key, value.default])); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @template {Record<string, any>} T |
| 34 |
* @param {T} schema |
| 35 |
* @returns {(keyof T)[]} |
| 36 |
*/ |
| 37 |
function getSchemaKeys(schema) { |
| 38 |
return $keys(schema); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* @template T |
| 43 |
* @param {(values: string[]) => T} parse |
| 44 |
* @returns {(valueIfEmpty: T) => (values: string[]) => T} |
| 45 |
*/ |
| 46 |
function makeParser(parse) { |
| 47 |
return (valueIfEmpty) => (values) => values.length ? parse(values) : valueIfEmpty; |
| 48 |
} |
| 49 |
|
| 50 |
const parseBoolean = makeParser(([value]) => value === "true"); |
| 51 |
|
| 52 |
const parseNumber = makeParser(([value]) => $parseFloat(value) || 0); |
| 53 |
|
| 54 |
/** @type {ReturnType<typeof makeParser<"first-fail" | "failed" | false>>} */ |
| 55 |
const parseShowDetail = makeParser(([value]) => (value === "false" ? false : value)); |
| 56 |
|
| 57 |
const parseString = makeParser(([value]) => value); |
| 58 |
|
| 59 |
const parseStringArray = makeParser((values) => values); |
| 60 |
|
| 61 |
//----------------------------------------------------------------------------- |
| 62 |
// Exports |
| 63 |
//----------------------------------------------------------------------------- |
| 64 |
|
| 65 |
export const CONFIG_SCHEMA = { |
| 66 |
/** |
| 67 |
* Amount of failed tests after which the test runner will be stopped. |
| 68 |
* A falsy value (including 0) means that the runner should never be aborted. |
| 69 |
* @default false |
| 70 |
*/ |
| 71 |
bail: { |
| 72 |
default: 0, |
| 73 |
parse: parseNumber(1), |
| 74 |
}, |
| 75 |
/** |
| 76 |
* Debug parameter used in Odoo. |
| 77 |
* It has no direct effect on the test runner, but is taken into account since |
| 78 |
* all URL parameters not explicitly defined in the schema are ignored. |
| 79 |
* @default "" |
| 80 |
*/ |
| 81 |
debug: { |
| 82 |
default: "", |
| 83 |
parse: parseString("assets"), |
| 84 |
}, |
| 85 |
/** |
| 86 |
* Same as the {@link FILTER_SCHEMA.test} filter, while also putting the test |
| 87 |
* runner in "debug" mode. See {@link Runner.debug} for more info. |
| 88 |
* @default false |
| 89 |
*/ |
| 90 |
debugTest: { |
| 91 |
default: false, |
| 92 |
parse: parseBoolean(true), |
| 93 |
}, |
| 94 |
/** |
| 95 |
* Determines the event types shown in test results. |
| 96 |
* @default assertion|error |
| 97 |
*/ |
| 98 |
events: { |
| 99 |
default: DEFAULT_EVENT_TYPES, |
| 100 |
parse: parseNumber(0), |
| 101 |
}, |
| 102 |
/** |
| 103 |
* Amount of frames rendered per second, used when mocking animation frames. |
| 104 |
* @default 60 |
| 105 |
*/ |
| 106 |
fps: { |
| 107 |
default: 60, |
| 108 |
parse: parseNumber(60), |
| 109 |
}, |
| 110 |
/** |
| 111 |
* Lights up the mood. |
| 112 |
* @default false |
| 113 |
*/ |
| 114 |
fun: { |
| 115 |
default: false, |
| 116 |
parse: parseBoolean(true), |
| 117 |
}, |
| 118 |
/** |
| 119 |
* Whether to render the test runner user interface. |
| 120 |
* Note: this cannot be changed at runtime: the UI will not be un-rendered or |
| 121 |
* rendered if this parameter changes. |
| 122 |
* @default false |
| 123 |
*/ |
| 124 |
headless: { |
| 125 |
default: false, |
| 126 |
parse: parseBoolean(true), |
| 127 |
}, |
| 128 |
/** |
| 129 |
* Log level used by the test runner. The higher the level, the more logs will |
| 130 |
* be displayed. |
| 131 |
*/ |
| 132 |
loglevel: { |
| 133 |
default: 0, |
| 134 |
parse: parseNumber(0), |
| 135 |
}, |
| 136 |
/** |
| 137 |
* Whether the test runner must be manually started after page load (defaults |
| 138 |
* to starting automatically). |
| 139 |
* @default false |
| 140 |
*/ |
| 141 |
manual: { |
| 142 |
default: false, |
| 143 |
parse: parseBoolean(true), |
| 144 |
}, |
| 145 |
/** |
| 146 |
* Artifical delay introduced for each network call. It can be a fixed integer, |
| 147 |
* or an integer range (in the form "min-max") to generate a random delay between |
| 148 |
* "min" and "max". |
| 149 |
* @default 0 |
| 150 |
*/ |
| 151 |
networkDelay: { |
| 152 |
default: "0", |
| 153 |
parse: parseString("0"), |
| 154 |
}, |
| 155 |
/** |
| 156 |
* Removes the safety of 'try .. catch' statements around each test's run function |
| 157 |
* to let errors bubble to the browser. |
| 158 |
* @default false |
| 159 |
*/ |
| 160 |
notrycatch: { |
| 161 |
default: false, |
| 162 |
parse: parseBoolean(true), |
| 163 |
}, |
| 164 |
/** |
| 165 |
* Determines the order of the tests execution. |
| 166 |
* - `"fifo"`: tests will be run sequentially as declared in the file system. |
| 167 |
* - `"lifo"`: tests will be run sequentially in the reverse order. |
| 168 |
* - `"random"`: shuffles tests and suites within their parent suite. |
| 169 |
* @default "fifo" |
| 170 |
*/ |
| 171 |
order: { |
| 172 |
default: "fifo", |
| 173 |
parse: parseString(""), |
| 174 |
}, |
| 175 |
/** |
| 176 |
* Environment in which the test runner is running. This parameter is used to |
| 177 |
* determine the default value of other parameters, namely: |
| 178 |
* - the user agent; |
| 179 |
* - touch support; |
| 180 |
* - size of the viewport. |
| 181 |
* @default "" no specific parameters are set |
| 182 |
*/ |
| 183 |
preset: { |
| 184 |
default: "", |
| 185 |
parse: parseString(""), |
| 186 |
}, |
| 187 |
/** |
| 188 |
* Determines the seed from which random numbers will be generated. |
| 189 |
* @default 0 |
| 190 |
*/ |
| 191 |
random: { |
| 192 |
default: 0, |
| 193 |
parse: parseString(generateSeed()), |
| 194 |
}, |
| 195 |
/** |
| 196 |
* Determines how the failed tests must be unfolded in the UI: |
| 197 |
* - "first-fail": only the first failed test will be unfolded |
| 198 |
* - "failed": all failed tests will be unfolded |
| 199 |
* - false: all tests will remain folded |
| 200 |
* @default "first-fail" |
| 201 |
*/ |
| 202 |
showdetail: { |
| 203 |
default: "first-fail", |
| 204 |
parse: parseShowDetail("failed"), |
| 205 |
}, |
| 206 |
/** |
| 207 |
* Duration (in milliseconds) at the end of which a test will automatically fail. |
| 208 |
* @default 5_000 |
| 209 |
*/ |
| 210 |
timeout: { |
| 211 |
default: 5_000, |
| 212 |
parse: parseNumber(5_000), |
| 213 |
}, |
| 214 |
}; |
| 215 |
|
| 216 |
export const FILTER_SCHEMA = { |
| 217 |
/** |
| 218 |
* Search string that will filter matching tests/suites, based on: |
| 219 |
* - their full name (including their parent suite(s)) |
| 220 |
* - their tags |
| 221 |
* @default "" |
| 222 |
*/ |
| 223 |
filter: { |
| 224 |
aliases: ["name"], |
| 225 |
default: "", |
| 226 |
parse: parseString(""), |
| 227 |
}, |
| 228 |
/** |
| 229 |
* IDs of the suites OR tests to run exclusively. The ID of a job is generated |
| 230 |
* deterministically based on its full name. |
| 231 |
* @default [] |
| 232 |
*/ |
| 233 |
id: { |
| 234 |
aliases: ["ids"], |
| 235 |
default: [], |
| 236 |
parse: parseStringArray([]), |
| 237 |
}, |
| 238 |
/** |
| 239 |
* Tag names of tests and suites to run exclusively (case insensitive). |
| 240 |
* @default [] |
| 241 |
*/ |
| 242 |
tag: { |
| 243 |
aliases: ["tags"], |
| 244 |
default: [], |
| 245 |
parse: parseStringArray([]), |
| 246 |
}, |
| 247 |
}; |
| 248 |
|
| 249 |
/** @see {@link CONFIG_SCHEMA} */ |
| 250 |
export const DEFAULT_CONFIG = getSchemaDefaults(CONFIG_SCHEMA); |
| 251 |
export const CONFIG_KEYS = getSchemaKeys(CONFIG_SCHEMA); |
| 252 |
|
| 253 |
/** @see {@link FILTER_SCHEMA} */ |
| 254 |
export const DEFAULT_FILTERS = getSchemaDefaults(FILTER_SCHEMA); |
| 255 |
export const FILTER_KEYS = getSchemaKeys(FILTER_SCHEMA); |