| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  | const { TestRunner } = require('../TestRunner'); | 
					
						
							|  |  |  | const { TestCollector, FocusedFilter, Repeater } = require('../TestCollector'); | 
					
						
							|  |  |  | const { TestExpectation, Environment } = require('../Test'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Runner { | 
					
						
							|  |  |  |   constructor(options = {}) { | 
					
						
							|  |  |  |     this._options = options; | 
					
						
							|  |  |  |     this._filter = new FocusedFilter(); | 
					
						
							|  |  |  |     this._repeater = new Repeater(); | 
					
						
							|  |  |  |     this._collector = new TestCollector(options); | 
					
						
							|  |  |  |     this._collector.addSuiteAttribute('only', s => this._filter.markFocused(s)); | 
					
						
							|  |  |  |     this._collector.addTestAttribute('only', t => this._filter.markFocused(t)); | 
					
						
							|  |  |  |     this._collector.addSuiteAttribute('skip', s => s.setSkipped(true)); | 
					
						
							|  |  |  |     this._collector.addTestAttribute('skip', t => t.setSkipped(true)); | 
					
						
							|  |  |  |     this._collector.addTestAttribute('fail', t => t.setExpectation(t.Expectations.Fail)); | 
					
						
							|  |  |  |     this._collector.addSuiteModifier('repeat', (s, count) => this._repeater.repeat(s, count)); | 
					
						
							|  |  |  |     this._collector.addTestModifier('repeat', (t, count) => this._repeater.repeat(t, count)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const api = this._collector.api(); | 
					
						
							|  |  |  |     for (const [key, value] of Object.entries(api)) | 
					
						
							|  |  |  |       this[key] = value; | 
					
						
							|  |  |  |     this.fdescribe = api.describe.only; | 
					
						
							|  |  |  |     this.xdescribe = api.describe.skip; | 
					
						
							|  |  |  |     this.fit = api.it.only; | 
					
						
							|  |  |  |     this.xit = api.it.skip; | 
					
						
							|  |  |  |     this.Expectations = { ...TestExpectation }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   createTestRuns() { | 
					
						
							|  |  |  |     return this._repeater.createTestRuns(this._filter.filter(this._collector.tests())); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   run() { | 
					
						
							|  |  |  |     this._testRunner = new TestRunner(); | 
					
						
							|  |  |  |     return this._testRunner.run(this.createTestRuns(), this._options); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   tests() { | 
					
						
							|  |  |  |     return this._collector.tests(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   focusedTests() { | 
					
						
							|  |  |  |     return this._filter.focusedTests(this._collector.tests()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   suites() { | 
					
						
							|  |  |  |     return this._collector.suites(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   focusedSuites() { | 
					
						
							|  |  |  |     return this._filter.focusedSuites(this._collector.suites()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   terminate() { | 
					
						
							|  |  |  |     this._testRunner.terminate(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-11 18:30:43 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  | module.exports.addTests = function({describe, fdescribe, xdescribe, it, xit, fit, expect}) { | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |   describe('TestRunner.it', () => { | 
					
						
							|  |  |  |     it('should declare a test', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => {}); | 
					
						
							|  |  |  |       expect(t.tests().length).toBe(1); | 
					
						
							|  |  |  |       const test = t.tests()[0]; | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |       expect(test.name()).toBe('uno'); | 
					
						
							|  |  |  |       expect(test.fullName()).toBe('uno'); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(test.skipped()).toBe(false); | 
					
						
							| 
									
										
										
										
											2020-03-29 21:38:30 -07:00
										 |  |  |       expect(test.location().filePath()).toEqual(__filename); | 
					
						
							|  |  |  |       expect(test.location().fileName()).toEqual('testrunner.spec.js'); | 
					
						
							|  |  |  |       expect(test.location().lineNumber()).toBeTruthy(); | 
					
						
							|  |  |  |       expect(test.location().columnNumber()).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |     it('should run a test', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       t.it('uno', () => {}); | 
					
						
							|  |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs.length).toBe(1); | 
					
						
							|  |  |  |       expect(result.runs[0].test()).toBe(t.tests()[0]); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('ok'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('TestRunner.xit', () => { | 
					
						
							|  |  |  |     it('should declare a skipped test', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.xit('uno', () => {}); | 
					
						
							|  |  |  |       expect(t.tests().length).toBe(1); | 
					
						
							|  |  |  |       const test = t.tests()[0]; | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |       expect(test.name()).toBe('uno'); | 
					
						
							|  |  |  |       expect(test.fullName()).toBe('uno'); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(test.skipped()).toBe(true); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should not run a skipped test', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       t.xit('uno', () => {}); | 
					
						
							|  |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs.length).toBe(1); | 
					
						
							|  |  |  |       expect(result.runs[0].test()).toBe(t.tests()[0]); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('skipped'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('TestRunner.fit', () => { | 
					
						
							|  |  |  |     it('should declare a focused test', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.fit('uno', () => {}); | 
					
						
							|  |  |  |       expect(t.tests().length).toBe(1); | 
					
						
							|  |  |  |       const test = t.tests()[0]; | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |       expect(test.name()).toBe('uno'); | 
					
						
							|  |  |  |       expect(test.fullName()).toBe('uno'); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(test.skipped()).toBe(false); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       expect(t.focusedTests()[0]).toBe(test); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should run a focused test', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       t.fit('uno', () => {}); | 
					
						
							|  |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs.length).toBe(1); | 
					
						
							|  |  |  |       expect(result.runs[0].test()).toBe(t.tests()[0]); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('ok'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-16 19:12:52 -07:00
										 |  |  |     it('should run a failed focused test', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2020-03-16 19:12:52 -07:00
										 |  |  |       let run = false; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       t.it.only.fail('uno', () => { | 
					
						
							| 
									
										
										
										
											2020-03-28 08:49:00 -07:00
										 |  |  |         run = true; throw new Error('failure'); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |       expect(t.focusedTests().length).toBe(1); | 
					
						
							| 
									
										
										
										
											2020-03-29 11:37:45 -07:00
										 |  |  |       expect(t.tests()[0].expectation()).toBe(t.Expectations.Fail); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							| 
									
										
										
										
											2020-03-16 19:12:52 -07:00
										 |  |  |       expect(run).toBe(true); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(result.runs.length).toBe(1); | 
					
						
							|  |  |  |       expect(result.runs[0].test()).toBe(t.tests()[0]); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('failed'); | 
					
						
							| 
									
										
										
										
											2020-03-16 19:12:52 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('TestRunner.describe', () => { | 
					
						
							|  |  |  |     it('should declare a suite', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.describe('suite', () => { | 
					
						
							|  |  |  |         t.it('uno', () => {}); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(t.tests().length).toBe(1); | 
					
						
							|  |  |  |       const test = t.tests()[0]; | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |       expect(test.name()).toBe('uno'); | 
					
						
							|  |  |  |       expect(test.fullName()).toBe('suite uno'); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(test.skipped()).toBe(false); | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |       expect(test.suite().name()).toBe('suite'); | 
					
						
							|  |  |  |       expect(test.suite().fullName()).toBe('suite'); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(test.suite().skipped()).toBe(false); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('TestRunner.xdescribe', () => { | 
					
						
							|  |  |  |     it('should declare a skipped suite', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.xdescribe('suite', () => { | 
					
						
							|  |  |  |         t.it('uno', () => {}); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(t.tests().length).toBe(1); | 
					
						
							|  |  |  |       const test = t.tests()[0]; | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(test.skipped()).toBe(false); | 
					
						
							|  |  |  |       expect(test.suite().skipped()).toBe(true); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-27 15:35:14 -07:00
										 |  |  |     it('focused tests inside a skipped suite are not run', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       let run = false; | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.xdescribe('suite', () => { | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |         t.fit('uno', () => { run = true; }); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(run).toBe(false); | 
					
						
							|  |  |  |       expect(result.runs.length).toBe(1); | 
					
						
							|  |  |  |       expect(result.runs[0].test()).toBe(t.tests()[0]); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('skipped'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('TestRunner.fdescribe', () => { | 
					
						
							|  |  |  |     it('should declare a focused suite', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.fdescribe('suite', () => { | 
					
						
							|  |  |  |         t.it('uno', () => {}); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(t.tests().length).toBe(1); | 
					
						
							|  |  |  |       const test = t.tests()[0]; | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(test.skipped()).toBe(false); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       expect(t.focusedSuites()[0]).toBe(test.suite()); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(test.suite().skipped()).toBe(false); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-27 15:35:14 -07:00
										 |  |  |     it('skipped tests inside a focused suite should not be run', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.fdescribe('suite', () => { | 
					
						
							|  |  |  |         t.xit('uno', () => {}); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs.length).toBe(1); | 
					
						
							|  |  |  |       expect(result.runs[0].test()).toBe(t.tests()[0]); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('skipped'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should run all "run" tests inside a focused suite', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => log.push(1)); | 
					
						
							|  |  |  |       t.fdescribe('suite1', () => { | 
					
						
							|  |  |  |         t.it('dos', () => log.push(2)); | 
					
						
							|  |  |  |         t.it('tres', () => log.push(3)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       t.it('cuatro', () => log.push(4)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('2,3'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should run only "focus" tests inside a focused suite', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => log.push(1)); | 
					
						
							|  |  |  |       t.fdescribe('suite1', () => { | 
					
						
							|  |  |  |         t.fit('dos', () => log.push(2)); | 
					
						
							|  |  |  |         t.it('tres', () => log.push(3)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       t.it('cuatro', () => log.push(4)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('2'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should run both "run" tests in focused suite and non-descendant focus tests', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => log.push(1)); | 
					
						
							|  |  |  |       t.fdescribe('suite1', () => { | 
					
						
							|  |  |  |         t.it('dos', () => log.push(2)); | 
					
						
							|  |  |  |         t.it('tres', () => log.push(3)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       t.fit('cuatro', () => log.push(4)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('2,3,4'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-25 14:40:57 -07:00
										 |  |  |   describe('TestRunner attributes', () => { | 
					
						
							|  |  |  |     it('should work', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 123}); | 
					
						
							| 
									
										
										
										
											2020-03-25 14:40:57 -07:00
										 |  |  |       const log = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       t._collector.addTestModifier('foo', (t, ...args) => { | 
					
						
							| 
									
										
										
										
											2020-03-25 14:40:57 -07:00
										 |  |  |         log.push('foo'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |         expect(t.skipped()).toBe(false); | 
					
						
							| 
									
										
										
										
											2020-03-25 14:40:57 -07:00
										 |  |  |         expect(t.Expectations.Ok).toBeTruthy(); | 
					
						
							|  |  |  |         expect(t.Expectations.Fail).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |         expect(t.expectation()).toBe(t.Expectations.Ok); | 
					
						
							| 
									
										
										
										
											2020-03-25 14:40:57 -07:00
										 |  |  |         expect(t.timeout()).toBe(123); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(args.length).toBe(2); | 
					
						
							|  |  |  |         expect(args[0]).toBe('uno'); | 
					
						
							|  |  |  |         expect(args[1]).toBe('dos'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |         t.setExpectation(t.Expectations.Fail); | 
					
						
							| 
									
										
										
										
											2020-03-25 14:40:57 -07:00
										 |  |  |         t.setTimeout(234); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       t._collector.addTestAttribute('bar', t => { | 
					
						
							| 
									
										
										
										
											2020-03-25 14:40:57 -07:00
										 |  |  |         log.push('bar'); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |         t.setSkipped(true); | 
					
						
							|  |  |  |         expect(t.skipped()).toBe(true); | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |         expect(t.expectation()).toBe(t.Expectations.Fail); | 
					
						
							| 
									
										
										
										
											2020-03-25 14:40:57 -07:00
										 |  |  |         expect(t.timeout()).toBe(234); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       t.it.foo('uno', 'dos').bar('test', () => { }); | 
					
						
							|  |  |  |       expect(log).toEqual(['foo', 'bar']); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |   describe('TestRunner hooks', () => { | 
					
						
							|  |  |  |     it('should run all hooks in proper order', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							|  |  |  |       const e = new Environment('env'); | 
					
						
							|  |  |  |       e.beforeAll(() => log.push('env:beforeAll')); | 
					
						
							|  |  |  |       e.afterAll(() => log.push('env:afterAll')); | 
					
						
							|  |  |  |       e.beforeEach(() => log.push('env:beforeEach')); | 
					
						
							|  |  |  |       e.afterEach(() => log.push('env:afterEach')); | 
					
						
							|  |  |  |       const e2 = new Environment('env2', e); | 
					
						
							|  |  |  |       e2.beforeAll(() => log.push('env2:beforeAll')); | 
					
						
							|  |  |  |       e2.afterAll(() => log.push('env2:afterAll')); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.beforeAll(() => log.push('root:beforeAll')); | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |       t.beforeEach(() => log.push('root:beforeEach1')); | 
					
						
							|  |  |  |       t.beforeEach(() => log.push('root:beforeEach2')); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => log.push('test #1')); | 
					
						
							|  |  |  |       t.describe('suite1', () => { | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         t.beforeAll(() => log.push('suite:beforeAll1')); | 
					
						
							|  |  |  |         t.beforeAll(() => log.push('suite:beforeAll2')); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |         t.beforeEach(() => log.push('suite:beforeEach')); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         t.it('dos', () => log.push('test #2')); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |         t.tests()[t.tests().length - 1].environment().beforeEach(() => log.push('test:before1')); | 
					
						
							|  |  |  |         t.tests()[t.tests().length - 1].environment().beforeEach(() => log.push('test:before2')); | 
					
						
							|  |  |  |         t.tests()[t.tests().length - 1].environment().afterEach(() => log.push('test:after1')); | 
					
						
							|  |  |  |         t.tests()[t.tests().length - 1].environment().afterEach(() => log.push('test:after2')); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         t.it('tres', () => log.push('test #3')); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |         t.tests()[t.tests().length - 1].environment().beforeEach(() => log.push('test:before1')); | 
					
						
							|  |  |  |         t.tests()[t.tests().length - 1].environment().beforeEach(() => log.push('test:before2')); | 
					
						
							|  |  |  |         t.tests()[t.tests().length - 1].environment().afterEach(() => log.push('test:after1')); | 
					
						
							|  |  |  |         t.tests()[t.tests().length - 1].environment().afterEach(() => log.push('test:after2')); | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         t.afterEach(() => log.push('suite:afterEach1')); | 
					
						
							|  |  |  |         t.afterEach(() => log.push('suite:afterEach2')); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         t.afterAll(() => log.push('suite:afterAll')); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       t.it('cuatro', () => log.push('test #4')); | 
					
						
							|  |  |  |       t.tests()[t.tests().length - 1].addEnvironment(e2); | 
					
						
							| 
									
										
										
										
											2020-04-01 10:49:47 -07:00
										 |  |  |       t.describe('no hooks suite', () => { | 
					
						
							|  |  |  |         t.describe('suite2', () => { | 
					
						
							|  |  |  |           t.beforeAll(() => log.push('suite2:beforeAll')); | 
					
						
							|  |  |  |           t.afterAll(() => log.push('suite2:afterAll')); | 
					
						
							|  |  |  |           t.describe('no hooks suite 2', () => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |             t.it('cinco', () => log.push('test #5')); | 
					
						
							| 
									
										
										
										
											2020-04-01 10:49:47 -07:00
										 |  |  |           }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       t.suites()[t.suites().length - 1].addEnvironment(e2); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.afterEach(() => log.push('root:afterEach')); | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |       t.afterAll(() => log.push('root:afterAll1')); | 
					
						
							|  |  |  |       t.afterAll(() => log.push('root:afterAll2')); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log).toEqual([ | 
					
						
							|  |  |  |         'root:beforeAll', | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         'root:beforeEach1', | 
					
						
							|  |  |  |         'root:beforeEach2', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         'test #1', | 
					
						
							|  |  |  |         'root:afterEach', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         'suite:beforeAll1', | 
					
						
							|  |  |  |         'suite:beforeAll2', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         'root:beforeEach1', | 
					
						
							|  |  |  |         'root:beforeEach2', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         'suite:beforeEach', | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         'test:before1', | 
					
						
							|  |  |  |         'test:before2', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         'test #2', | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         'test:after1', | 
					
						
							|  |  |  |         'test:after2', | 
					
						
							|  |  |  |         'suite:afterEach1', | 
					
						
							|  |  |  |         'suite:afterEach2', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         'root:afterEach', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         'root:beforeEach1', | 
					
						
							|  |  |  |         'root:beforeEach2', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         'suite:beforeEach', | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         'test:before1', | 
					
						
							|  |  |  |         'test:before2', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         'test #3', | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         'test:after1', | 
					
						
							|  |  |  |         'test:after2', | 
					
						
							|  |  |  |         'suite:afterEach1', | 
					
						
							|  |  |  |         'suite:afterEach2', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         'root:afterEach', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         'suite:afterAll', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 10:49:47 -07:00
										 |  |  |         'env:beforeAll', | 
					
						
							| 
									
										
										
										
											2020-04-02 13:12:22 -07:00
										 |  |  |         'env2:beforeAll', | 
					
						
							| 
									
										
										
										
											2020-04-01 10:49:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         'root:beforeEach1', | 
					
						
							|  |  |  |         'root:beforeEach2', | 
					
						
							| 
									
										
										
										
											2020-04-01 10:49:47 -07:00
										 |  |  |         'env:beforeEach', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         'test #4', | 
					
						
							| 
									
										
										
										
											2020-04-01 10:49:47 -07:00
										 |  |  |         'env:afterEach', | 
					
						
							|  |  |  |         'root:afterEach', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         'suite2:beforeAll', | 
					
						
							|  |  |  |         'root:beforeEach1', | 
					
						
							|  |  |  |         'root:beforeEach2', | 
					
						
							|  |  |  |         'env:beforeEach', | 
					
						
							|  |  |  |         'test #5', | 
					
						
							|  |  |  |         'env:afterEach', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         'root:afterEach', | 
					
						
							| 
									
										
										
										
											2020-04-01 10:49:47 -07:00
										 |  |  |         'suite2:afterAll', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 13:12:22 -07:00
										 |  |  |         'env2:afterAll', | 
					
						
							| 
									
										
										
										
											2020-04-01 10:49:47 -07:00
										 |  |  |         'env:afterAll', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 22:57:22 -07:00
										 |  |  |         'root:afterAll1', | 
					
						
							|  |  |  |         'root:afterAll2', | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       ]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-03 09:48:01 -07:00
										 |  |  |     it('should remove environment', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							|  |  |  |       const e = new Environment('env'); | 
					
						
							|  |  |  |       e.beforeAll(() => log.push('env:beforeAll')); | 
					
						
							|  |  |  |       e.afterAll(() => log.push('env:afterAll')); | 
					
						
							|  |  |  |       e.beforeEach(() => log.push('env:beforeEach')); | 
					
						
							|  |  |  |       e.afterEach(() => log.push('env:afterEach')); | 
					
						
							|  |  |  |       const e2 = new Environment('env2'); | 
					
						
							|  |  |  |       e2.beforeAll(() => log.push('env2:beforeAll')); | 
					
						
							|  |  |  |       e2.afterAll(() => log.push('env2:afterAll')); | 
					
						
							|  |  |  |       e2.beforeEach(() => log.push('env2:beforeEach')); | 
					
						
							|  |  |  |       e2.afterEach(() => log.push('env2:afterEach')); | 
					
						
							|  |  |  |       t.it('uno', () => log.push('test #1')); | 
					
						
							|  |  |  |       t.tests()[0].addEnvironment(e).addEnvironment(e2).removeEnvironment(e); | 
					
						
							| 
									
										
										
										
											2020-04-03 09:48:01 -07:00
										 |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log).toEqual([ | 
					
						
							|  |  |  |         'env2:beforeAll', | 
					
						
							|  |  |  |         'env2:beforeEach', | 
					
						
							|  |  |  |         'test #1', | 
					
						
							|  |  |  |         'env2:afterEach', | 
					
						
							|  |  |  |         'env2:afterAll', | 
					
						
							|  |  |  |       ]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     it('should have the same state object in hooks and test', async() => { | 
					
						
							|  |  |  |       const states = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.beforeEach(state => states.push(state)); | 
					
						
							|  |  |  |       t.afterEach(state => states.push(state)); | 
					
						
							|  |  |  |       t.beforeAll(state => states.push(state)); | 
					
						
							|  |  |  |       t.afterAll(state => states.push(state)); | 
					
						
							|  |  |  |       t.it('uno', state => states.push(state)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(states.length).toBe(5); | 
					
						
							|  |  |  |       for (let i = 1; i < states.length; ++i) | 
					
						
							|  |  |  |         expect(states[i]).toBe(states[0]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should unwind hooks properly when terminated', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 10000}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.beforeAll(() => log.push('beforeAll')); | 
					
						
							|  |  |  |       t.beforeEach(() => log.push('beforeEach')); | 
					
						
							|  |  |  |       t.afterEach(() => log.push('afterEach')); | 
					
						
							|  |  |  |       t.afterAll(() => log.push('afterAll')); | 
					
						
							|  |  |  |       t.it('uno', () => { | 
					
						
							|  |  |  |         log.push('terminating...'); | 
					
						
							|  |  |  |         t.terminate(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(log).toEqual([ | 
					
						
							|  |  |  |         'beforeAll', | 
					
						
							|  |  |  |         'beforeEach', | 
					
						
							|  |  |  |         'terminating...', | 
					
						
							|  |  |  |         'afterEach', | 
					
						
							|  |  |  |         'afterAll', | 
					
						
							|  |  |  |       ]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-10 11:30:02 -07:00
										 |  |  |     it('should report as terminated even when hook crashes', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 10000}); | 
					
						
							| 
									
										
										
										
											2020-03-10 11:30:02 -07:00
										 |  |  |       t.afterEach(() => { throw new Error('crash!'); }); | 
					
						
							|  |  |  |       t.it('uno', () => { t.terminate(); }); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('terminated'); | 
					
						
							| 
									
										
										
										
											2020-03-10 11:30:02 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should report as terminated when terminated during hook', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 10000}); | 
					
						
							| 
									
										
										
										
											2020-03-10 11:30:02 -07:00
										 |  |  |       t.afterEach(() => { t.terminate(); }); | 
					
						
							|  |  |  |       t.it('uno', () => { }); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('terminated'); | 
					
						
							| 
									
										
										
										
											2020-03-10 11:30:02 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     it('should unwind hooks properly when crashed', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 10000}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.beforeAll(() => log.push('root beforeAll')); | 
					
						
							|  |  |  |       t.beforeEach(() => log.push('root beforeEach')); | 
					
						
							|  |  |  |       t.describe('suite', () => { | 
					
						
							|  |  |  |         t.beforeAll(() => log.push('suite beforeAll')); | 
					
						
							|  |  |  |         t.beforeEach(() => log.push('suite beforeEach')); | 
					
						
							|  |  |  |         t.it('uno', () => log.push('uno')); | 
					
						
							|  |  |  |         t.afterEach(() => { | 
					
						
							|  |  |  |           log.push('CRASH >> suite afterEach'); | 
					
						
							|  |  |  |           throw new Error('crash!'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         t.afterAll(() => log.push('suite afterAll')); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       t.afterEach(() => log.push('root afterEach')); | 
					
						
							|  |  |  |       t.afterAll(() => log.push('root afterAll')); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(log).toEqual([ | 
					
						
							|  |  |  |         'root beforeAll', | 
					
						
							|  |  |  |         'suite beforeAll', | 
					
						
							|  |  |  |         'root beforeEach', | 
					
						
							|  |  |  |         'suite beforeEach', | 
					
						
							|  |  |  |         'uno', | 
					
						
							|  |  |  |         'CRASH >> suite afterEach', | 
					
						
							|  |  |  |         'root afterEach', | 
					
						
							|  |  |  |         'suite afterAll', | 
					
						
							|  |  |  |         'root afterAll' | 
					
						
							|  |  |  |       ]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('TestRunner.run', () => { | 
					
						
							|  |  |  |     it('should run a test', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       let ran = false; | 
					
						
							|  |  |  |       t.it('uno', () => ran = true); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(ran).toBe(true); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |     it('should handle repeat', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |       let suite = 0; | 
					
						
							|  |  |  |       let test = 0; | 
					
						
							|  |  |  |       let beforeAll = 0; | 
					
						
							|  |  |  |       let beforeEach = 0; | 
					
						
							|  |  |  |       t.describe.repeat(2)('suite', () => { | 
					
						
							|  |  |  |         suite++; | 
					
						
							|  |  |  |         t.beforeAll(() => beforeAll++); | 
					
						
							|  |  |  |         t.beforeEach(() => beforeEach++); | 
					
						
							|  |  |  |         t.it.repeat(3)('uno', () => test++); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(suite).toBe(1); | 
					
						
							|  |  |  |       expect(beforeAll).toBe(1); | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |       expect(beforeEach).toBe(6); | 
					
						
							|  |  |  |       expect(test).toBe(6); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-15 18:41:55 -07:00
										 |  |  |     it('should repeat without breaking test order', async() => { | 
					
						
							|  |  |  |       const t = new Runner(); | 
					
						
							|  |  |  |       const log = []; | 
					
						
							|  |  |  |       t.describe.repeat(2)('suite', () => { | 
					
						
							|  |  |  |         t.it('uno', () => log.push(1)); | 
					
						
							|  |  |  |         t.it.repeat(2)('dos', () => log.push(2)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       t.it('tres', () => log.push(3)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('1,2,2,1,2,2,3'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     it('should run tests if some fail', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       const log = []; | 
					
						
							|  |  |  |       t.it('uno', () => log.push(1)); | 
					
						
							|  |  |  |       t.it('dos', () => { throw new Error('bad'); }); | 
					
						
							|  |  |  |       t.it('tres', () => log.push(3)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('1,3'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should run tests if some timeout', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 1}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       const log = []; | 
					
						
							|  |  |  |       t.it('uno', () => log.push(1)); | 
					
						
							|  |  |  |       t.it('dos', async() => new Promise(() => {})); | 
					
						
							|  |  |  |       t.it('tres', () => log.push(3)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('1,3'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should break on first failure if configured so', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({breakOnFailure: true}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('test#1', () => log.push('test#1')); | 
					
						
							|  |  |  |       t.it('test#2', () => log.push('test#2')); | 
					
						
							|  |  |  |       t.it('test#3', () => { throw new Error('crash'); }); | 
					
						
							|  |  |  |       t.it('test#4', () => log.push('test#4')); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log).toEqual([ | 
					
						
							|  |  |  |         'test#1', | 
					
						
							|  |  |  |         'test#2', | 
					
						
							|  |  |  |       ]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should pass a state and a test as a test parameters', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.beforeEach(state => state.FOO = 42); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       t.it('uno', (state, testRun) => { | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |         log.push('state.FOO=' + state.FOO); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |         log.push('test=' + testRun.test().name()); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('state.FOO=42,test=uno'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should run async test', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       let ran = false; | 
					
						
							|  |  |  |       t.it('uno', async() => { | 
					
						
							|  |  |  |         await new Promise(x => setTimeout(x, 10)); | 
					
						
							|  |  |  |         ran = true; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(ran).toBe(true); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should run async tests in order of their declaration', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', async() => { | 
					
						
							|  |  |  |         await new Promise(x => setTimeout(x, 30)); | 
					
						
							|  |  |  |         log.push(1); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       t.it('dos', async() => { | 
					
						
							|  |  |  |         await new Promise(x => setTimeout(x, 20)); | 
					
						
							|  |  |  |         log.push(2); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       t.it('tres', async() => { | 
					
						
							|  |  |  |         await new Promise(x => setTimeout(x, 10)); | 
					
						
							|  |  |  |         log.push(3); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('1,2,3'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should run multiple tests', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => log.push(1)); | 
					
						
							|  |  |  |       t.it('dos', () => log.push(2)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('1,2'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should NOT run a skipped test', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       let ran = false; | 
					
						
							|  |  |  |       t.xit('uno', () => ran = true); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(ran).toBe(false); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should run ONLY non-skipped tests', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => log.push(1)); | 
					
						
							|  |  |  |       t.xit('dos', () => log.push(2)); | 
					
						
							|  |  |  |       t.it('tres', () => log.push(3)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('1,3'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should run ONLY focused tests', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => log.push(1)); | 
					
						
							|  |  |  |       t.xit('dos', () => log.push(2)); | 
					
						
							|  |  |  |       t.fit('tres', () => log.push(3)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('3'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should run tests in order of their declaration', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => log.push(1)); | 
					
						
							|  |  |  |       t.describe('suite1', () => { | 
					
						
							|  |  |  |         t.it('dos', () => log.push(2)); | 
					
						
							|  |  |  |         t.it('tres', () => log.push(3)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       t.it('cuatro', () => log.push(4)); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log.join()).toBe('1,2,3,4'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |     it('should respect total timeout', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 10000, totalTimeout: 1}); | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |       t.it('uno', async () => { await new Promise(() => {}); }); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       expect(result.runs[0].result()).toBe('terminated'); | 
					
						
							| 
									
										
										
										
											2020-03-26 22:47:13 -07:00
										 |  |  |       expect(result.message).toContain('Total timeout'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('TestRunner.run result', () => { | 
					
						
							|  |  |  |     it('should return OK if all tests pass', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => {}); | 
					
						
							|  |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.result).toBe('ok'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should return FAIL if at least one test fails', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => { throw new Error('woof'); }); | 
					
						
							|  |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.result).toBe('failed'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should return FAIL if at least one test times out', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 1}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', async() => new Promise(() => {})); | 
					
						
							|  |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.result).toBe('failed'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should return TERMINATED if it was terminated', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 1000000}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', async() => new Promise(() => {})); | 
					
						
							|  |  |  |       const [result] = await Promise.all([ | 
					
						
							|  |  |  |         t.run(), | 
					
						
							|  |  |  |         t.terminate(), | 
					
						
							|  |  |  |       ]); | 
					
						
							|  |  |  |       expect(result.result).toBe('terminated'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should return CRASHED if it crashed', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 1}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', async() => new Promise(() => {})); | 
					
						
							|  |  |  |       t.afterAll(() => { throw new Error('woof');}); | 
					
						
							|  |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.result).toBe('crashed'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('TestRunner parallel', () => { | 
					
						
							|  |  |  |     it('should run tests in parallel', async() => { | 
					
						
							|  |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({parallel: 2}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', async state => { | 
					
						
							|  |  |  |         log.push(`Worker #${state.parallelIndex} Starting: UNO`); | 
					
						
							|  |  |  |         await Promise.resolve(); | 
					
						
							|  |  |  |         log.push(`Worker #${state.parallelIndex} Ending: UNO`); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       t.it('dos', async state => { | 
					
						
							|  |  |  |         log.push(`Worker #${state.parallelIndex} Starting: DOS`); | 
					
						
							|  |  |  |         await Promise.resolve(); | 
					
						
							|  |  |  |         log.push(`Worker #${state.parallelIndex} Ending: DOS`); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log).toEqual([ | 
					
						
							|  |  |  |         'Worker #0 Starting: UNO', | 
					
						
							|  |  |  |         'Worker #1 Starting: DOS', | 
					
						
							|  |  |  |         'Worker #0 Ending: UNO', | 
					
						
							|  |  |  |         'Worker #1 Ending: DOS', | 
					
						
							|  |  |  |       ]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('TestRunner.hasFocusedTestsOrSuites', () => { | 
					
						
							|  |  |  |     it('should work', () => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => {}); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       expect(t._filter.hasFocusedTestsOrSuites()).toBe(false); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should work #2', () => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.fit('uno', () => {}); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       expect(t._filter.hasFocusedTestsOrSuites()).toBe(true); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should work #3', () => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.describe('suite #1', () => { | 
					
						
							|  |  |  |         t.fdescribe('suite #2', () => { | 
					
						
							|  |  |  |           t.describe('suite #3', () => { | 
					
						
							|  |  |  |             t.it('uno', () => {}); | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       expect(t._filter.hasFocusedTestsOrSuites()).toBe(true); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |   describe('TestRunner result', () => { | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     it('should work for both throwing and timeouting tests', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 1}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => { throw new Error('boo');}); | 
					
						
							|  |  |  |       t.it('dos', () => new Promise(() => {})); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('failed'); | 
					
						
							|  |  |  |       expect(result.runs[1].result()).toBe('timedout'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should report crashed tests', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.beforeEach(() => { throw new Error('woof');}); | 
					
						
							|  |  |  |       t.it('uno', () => {}); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('crashed'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |     it('skipped should work for both throwing and timeouting tests', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 1}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.xit('uno', () => { throw new Error('boo');}); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('skipped'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should return OK', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => {}); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('ok'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should return TIMEDOUT', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({timeout: 1}); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', async() => new Promise(() => {})); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('timedout'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should return SKIPPED', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.xit('uno', () => {}); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('skipped'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should return FAILED', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', async() => Promise.reject('woof')); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('failed'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should return TERMINATED', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', async() => t.terminate()); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('terminated'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     it('should return CRASHED', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner(); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       t.it('uno', () => {}); | 
					
						
							|  |  |  |       t.afterEach(() => {throw new Error('foo');}); | 
					
						
							| 
									
										
										
										
											2020-03-28 14:25:57 -07:00
										 |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.runs[0].result()).toBe('crashed'); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 15:47:25 -07:00
										 |  |  |   describe('TestRunner delegate', () => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |     it('should call delegate methods in proper order', async() => { | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       const log = []; | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       const t = new Runner({ | 
					
						
							| 
									
										
										
										
											2020-04-03 15:47:25 -07:00
										 |  |  |         onStarted: () => log.push('E:started'), | 
					
						
							|  |  |  |         onTestRunStarted: () => log.push('E:teststarted'), | 
					
						
							|  |  |  |         onTestRunFinished: () => log.push('E:testfinished'), | 
					
						
							|  |  |  |         onFinished: () => log.push('E:finished'), | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       t.beforeAll(() => log.push('beforeAll')); | 
					
						
							|  |  |  |       t.beforeEach(() => log.push('beforeEach')); | 
					
						
							|  |  |  |       t.it('test#1', () => log.push('test#1')); | 
					
						
							|  |  |  |       t.afterEach(() => log.push('afterEach')); | 
					
						
							|  |  |  |       t.afterAll(() => log.push('afterAll')); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       await t.run(); | 
					
						
							|  |  |  |       expect(log).toEqual([ | 
					
						
							|  |  |  |         'E:started', | 
					
						
							|  |  |  |         'beforeAll', | 
					
						
							|  |  |  |         'E:teststarted', | 
					
						
							|  |  |  |         'beforeEach', | 
					
						
							|  |  |  |         'test#1', | 
					
						
							|  |  |  |         'afterEach', | 
					
						
							|  |  |  |         'E:testfinished', | 
					
						
							|  |  |  |         'afterAll', | 
					
						
							|  |  |  |         'E:finished', | 
					
						
							|  |  |  |       ]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-03 15:47:25 -07:00
										 |  |  |     it('should call onFinished with result', async() => { | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |       let onFinished; | 
					
						
							|  |  |  |       const finishedPromise = new Promise(f => onFinished = f); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       const [result] = await Promise.all([ | 
					
						
							| 
									
										
										
										
											2020-04-06 17:21:42 -07:00
										 |  |  |         finishedPromise, | 
					
						
							|  |  |  |         new TestRunner().run([], { onFinished }), | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |       ]); | 
					
						
							|  |  |  |       expect(result.result).toBe('ok'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-07 22:56:21 -07:00
										 |  |  |     it('should crash when onStarted throws', async() => { | 
					
						
							|  |  |  |       const t = new Runner({ | 
					
						
							|  |  |  |         onStarted: () => { throw 42; }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.ok()).toBe(false); | 
					
						
							|  |  |  |       expect(result.message).toBe('INTERNAL ERROR: 42'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('should crash when onFinished throws', async() => { | 
					
						
							|  |  |  |       const t = new Runner({ | 
					
						
							|  |  |  |         onFinished: () => { throw new Error('42'); }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       const result = await t.run(); | 
					
						
							|  |  |  |       expect(result.ok()).toBe(false); | 
					
						
							|  |  |  |       expect(result.message).toBe('INTERNAL ERROR'); | 
					
						
							|  |  |  |       expect(result.result).toBe('crashed'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-11-18 18:18:28 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 |