|
1 | 1 | // need this for async/await in tests |
2 | 2 | import "regenerator-runtime/runtime"; |
3 | 3 |
|
| 4 | +/** |
| 5 | + * Return the node version. |
| 6 | + * |
| 7 | + * See: https://stackoverflow.com/a/20798760/1337474 |
| 8 | + * |
| 9 | + * @returns {object} - The node version. { version, major, minor, patch } |
| 10 | + * |
| 11 | + * @example |
| 12 | + * global.node_version().major >= 19 // true if node version is >= 19 |
| 13 | + * global.node_version().version // "v14.17.0" |
| 14 | + */ |
| 15 | +global.node_version = () => { |
| 16 | + const parsed_version = process.version.match(/^v(\d+)\.(\d+)\.(\d+)/); |
| 17 | + console.log(parsed_version); |
| 18 | + return { |
| 19 | + version: parsed_version[0], |
| 20 | + major: parseInt(parsed_version[1]), |
| 21 | + minor: parseInt(parsed_version[2]), |
| 22 | + patch: parseInt(parsed_version[3]), |
| 23 | + }; |
| 24 | +}; |
| 25 | + |
| 26 | +/** |
| 27 | + * Conditional Jest tests |
| 28 | + * |
| 29 | + * See: https://stackoverflow.com/a/60438234/1337474 |
| 30 | + * |
| 31 | + * @param {boolean} condition - The condition to test. |
| 32 | + * @returns {function} - it or it.skip |
| 33 | + * |
| 34 | + * @example |
| 35 | + * |
| 36 | + * global.itif(global.node_version().major >= 19)("should do something", () => { |
| 37 | + * // test code |
| 38 | + * }); |
| 39 | + */ |
| 40 | +global.itif = (condition) => (condition ? it : it.skip); |
| 41 | + |
4 | 42 | // pat-fullscreen |
5 | 43 | document.requestFullscreen = jest.fn(); |
6 | 44 | document.exitFullscreen = jest.fn(); |
|
0 commit comments