Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 2x 2x 2x 7x 7x 7x 10x 1x 9x 7x 7x 4x 3x 1x 9x 1x 7x 2x 2x 2x 2x 2x 2x 2x 27x 2x 2x 2x 2x 2x 2x 2x | "use strict"; /** * Contains global framework functions and helpers. * * @module */ var util = require("util"); var chai = require("chai"); var sinon = require("sinon"); chai.use(require("chai-as-promised")); chai.use(require("chai-datetime")); chai.use(require("chai-fs")); chai.use(require("chai-string")); chai.use(require("sinon-chai")); require("../matcher"); var CONF = require("../config"); var plugins = require("../plugins"); var Steps = require("../steps"); var ScopeType = require("../testing").ScopeType; if (CONF.report.deepErrors) { chai.config.truncateThreshold = 0; } /** * `chaijs` `expect` function. * * @global * @function * @arg {*} actualValue - Some actual value which should be checked. * @see {@link http://chaijs.com/|chaijs} to get more details about * `expect` usage. * @example expect(1).to.be.equal(1); expect(2).to.be.gte(0); */ global.expect = chai.expect; /** * `SinonJS` is pretty nice lib for mocking. * * @global */ global.sinon = sinon; var stubObject = (obj, returns, processed) => { processed = processed || []; processed.push(obj); for (var prop in obj) { if (prop.startsWith("__") || ["prototype", "constructor"].includes(prop)) { continue; } if (util.isFunction(obj[prop])) { obj[prop] = sinon.stub(); if (returns) { if (util.isObject(returns)) { if (prop in returns) obj[prop].returns(returns[prop]); } else { obj[prop].returns(returns); } } } if (util.isObject(obj[prop]) && !processed.includes(obj[prop])) { obj[prop] = stubObject(obj[prop], returns, processed); } } return obj; }; /** * Stubs object with its properties recursively. * * @global * @arg {object} obj - Object to stub. * @arg {object|number|string} returns - Returned values. * @return {object} Object with stubbed functions. */ global.stubObject = stubObject; require("rehire").global(); /** * `GlaceJS` config. * * @global * @see {@link module:config|config} to get more details about its options. */ global.CONF = CONF; /** * Allure helper. * * @global */ global.allure = require("../allure"); /** * Steps collection. * * @global * @type {Steps} * @see {@link module:steps/index|steps} to get more details about its methods. */ global.$ = Steps.getInstance(); global.scope = require("./scope"); /** * Creates tests suite. * * @global * @function * @arg {string} name - Suite name. * @arg {function[]} [fixtures] - List of fixtures. * @arg {object} [opts] - Suite options. * @arg {number} [opts.chunkRetry] - Number of chunk retries on failure. * @arg {number} [opts.chunkTimeout] - Time to execute chunk or hook, sec. * @arg {function} func - Callback function with test cases. * @example suite("Some test suite", () => { test("Some test name", () => { before(() => { someFunc(); }); chunk("chunk #1", () => { someFunc(); }); chunk("chunk #2", () => { someFunc(); }); }); }); */ global.suite = (name, fixtures, opts, func) => { scope(new ScopeType(name).setType("suite"), fixtures, opts, func); }; global.session = require("./session"); global.test = require("./test"); global.jaki = global.jaki_chunk = global.chunk = require("./chunk"); global.forEachLanguage = require("./forEachLanguage"); /** * Global function, existing in `glace` tests, which create `before` hook. * * `before` hook executes before all chunks in test or all tests in <a href="#scope">scope</a> / * <a href="#suite">suite</a> / <a href="#session">session</a>. * * @global * @function before * @arg {function} func - Hook function. Can be `async` too. * * @example <caption><b>before chunks</b></caption> * * test("my test", () => { * * before(() => { * doSomeThing(); * }); * * chunk("first chunk", () => { * doSomeThingAgain(); * }); * * chunk("second chunk", () => { * andDoSomeThingAgain(); * }); * }); * * @example <caption><b>before tests</b></caption> * * suite("my suite", () => { * * before(async () => { * await db.connect(); * }); * * test("first", () => { * chunk(async () => { * await db.query("select * from users"); * }); * }); * * test("second", () => { * chunk(async () => { * await db.query("select * from products"); * }); * }); * }); */ /** * Global function, existing in `glace` tests, which create `after` hook. * * `after` hook executes after all chunks in test or all tests in <a href="#scope">scope</a> / * <a href="#suite">suite</a> / <a href="#session">session</a>. * * @global * @function after * @arg {function} func - Hook function. Can be `async` too. * * @example <caption><b>after chunks</b></caption> * * test("my test", () => { * * after(() => { * doSomeThing(); * }); * * chunk("first chunk", () => { * doSomeThingAgain(); * }); * * chunk("second chunk", () => { * andDoSomeThingAgain(); * }); * }); * * @example <caption><b>after tests</b></caption> * * suite("my suite", () => { * * after(async () => { * await db.connect(); * }); * * test("first", () => { * chunk(async () => { * await db.query("select * from users"); * }); * }); * * test("second", () => { * chunk(async () => { * await db.query("select * from products"); * }); * }); * }); */ /** * Global function, existing in `glace` tests, which creates `beforeChunk` hook. * * `beforeChunk` hook executes before each chunk in test. * * @global * @function * @arg {function} func - Hook function. * * @example * * test("Some test", () => { * * beforeChunk(() => { * someFunc(); * }); * * chunk("Chunk #1", () => { * someFunc(); * }); * * chunk("Chunk #2", () => { * someFunc(); * }); * }); */ global.beforeChunk = beforeEach; /** * Global function, existing in `glace` tests, which creates `afterChunk` hook. * * `afterChunk` hook executes after each chunk in test. * * @global * @function * @arg {function} func - Hook function. * * @example * * test("Some test", () => { * * afterChunk(() => { * someFunc(); * }); * * chunk("Chunk #1", () => { * someFunc(); * }); * * chunk("Chunk #2", () => { * someFunc(); * }); * }); */ global.afterChunk = afterEach; /* Load globals from plugins */ plugins.getModules("globals"); |