From c3e8c22ea77e44596e45a32b3c4b354055f1c9b3 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Fri, 14 Sep 2018 12:45:20 +0530 Subject: [PATCH] [several] Fixes and features: * non-identifier is disallowed * library not- tests are priority * queue fix for before and after end hooks --- package.json | 2 +- src/lib/buildTestQueue.js | 8 ++++---- src/lib/expect.js | 7 +++++-- src/lib/testrunner.js | 16 ++++++++-------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 364d0cd..d49c0a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@klenty/gunner", - "version": "0.9.1", + "version": "0.9.2", "description": "Zero magic, fast test-runner and assertion framework. No magic globals.", "main": "index.js", "repository": { diff --git a/src/lib/buildTestQueue.js b/src/lib/buildTestQueue.js index acb8a92..881dca0 100644 --- a/src/lib/buildTestQueue.js +++ b/src/lib/buildTestQueue.js @@ -35,12 +35,12 @@ const buildTestTree = instance => { )); - testQueue.push.apply( + Array.prototype.push.apply(testQueue, instance.__suite__.beforeHooks[symbols.End] - .map(wrap('@end'))); - testQueue.push.apply( + .map(wrap('@beforeend'))); + Array.prototype.push.apply(testQueue, instance.__suite__.afterHooks[symbols.End] - .map(wrap(symbols.End))); + .map(wrap('@end'))); return testQueue; diff --git a/src/lib/expect.js b/src/lib/expect.js index 962ab8a..4e4f455 100644 --- a/src/lib/expect.js +++ b/src/lib/expect.js @@ -46,14 +46,17 @@ const expect = (thing, args) => new Proxy({}, { get: function (obj, prop) { const toCheck = args ? thing(...args) : thing; - if (prop.slice(0, 3) === 'not') + if (expects.hasOwnProperty(prop)) + return (...check) => expects[prop](toCheck)(...check); + else if (prop.slice(0, 3) === 'not') return (...check) => negateP( expects[ lowerCaseFirstLetter(prop.slice(3)) ](toCheck)(...check) ); - return (...check) => expects[prop](toCheck)(...check); + else + throw new Error('Unknown assertion method', prop); }, }); diff --git a/src/lib/testrunner.js b/src/lib/testrunner.js index 85c2a86..b3ab3bf 100644 --- a/src/lib/testrunner.js +++ b/src/lib/testrunner.js @@ -52,13 +52,6 @@ const reduceQueue = const { status } = result; - const identifier = (item.unit.label) - || (queue - .filter(i => i.type === item.type) - .filter(i => (i.unit.description - === item.unit.description)) - .length); - if (item.type === '@test') { const resultObject = { @@ -73,13 +66,20 @@ const reduceQueue = } else { + const identifier = (item.unit.label) + || (queue + .filter(i => i.type === item.type) + .filter(i => (i.unit.description + === item.unit.description)) + .length); + const stateAddition = /* eslint-disable-next-line */ status === 'ok' ? result.promise ? result.resolve : result.value : null; - if (stateAddition) + if (identifier && stateAddition) assignToObject( acc.state, item.type )(identifier, stateAddition);