Skip to content

Commit 611b77b

Browse files
committed
feat(Tests): Add helper for conditional test skipping and node version parsing.
1 parent 4bac5af commit 611b77b

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

jest/setup-tests.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
// need this for async/await in tests
22
import "regenerator-runtime/runtime";
33

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+
442
// pat-fullscreen
543
document.requestFullscreen = jest.fn();
644
document.exitFullscreen = jest.fn();

0 commit comments

Comments
 (0)