From 619661e8f7cc583d82551d936d66cf3397f07293 Mon Sep 17 00:00:00 2001 From: Aleck Greenham Date: Sat, 6 May 2017 09:57:18 +0100 Subject: [PATCH] =?UTF-8?q?[Test=20Suite]=20Don=E2=80=99t=20run=20focused?= =?UTF-8?q?=20pending=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/.gitignore | 1 + tests/__tests__/src/tests/pendingTestTests.js | 78 +++++++++++++++++++ tests/lib/TestSuite.js | 20 ++--- 3 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 tests/.gitignore diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 00000000..5afd82db --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +__tests__/build/ diff --git a/tests/__tests__/src/tests/pendingTestTests.js b/tests/__tests__/src/tests/pendingTestTests.js index e7c128a9..1dafed1c 100644 --- a/tests/__tests__/src/tests/pendingTestTests.js +++ b/tests/__tests__/src/tests/pendingTestTests.js @@ -103,6 +103,84 @@ function pendingTestTests({ it: _it, describe: _describe }) { otherTest.should.be.called(); }); }); + + _describe('when an outer context is focused', () => { + _it('a pending test will still not run', async () => { + const pendingTest = sinon.spy(); + const otherTest = sinon.spy(); + const unfocusedTest = sinon.spy(); + + const testSuite = new TestSuite('', '', {}); + + testSuite.addTests(({ fdescribe, it, xit }) => { + fdescribe('', () => { + xit('', pendingTest); + + it('', otherTest); + }); + + it('', unfocusedTest); + }); + + testSuite.setStore({ + getState: () => { return {}; }, + }); + + const testIdsToRun = Object.keys(testSuite.testDefinitions.focusedTestIds).reduce((memo, testId) => { + if (!testSuite.testDefinitions.pendingTestIds[testId]) { + memo.push(testId); + } + + return memo; + }, []); + + await testSuite.run(testIdsToRun); + + pendingTest.should.not.be.called(); + otherTest.should.be.called(); + unfocusedTest.should.not.be.called(); + }); + }); + + _describe('when an outer context is focused', () => { + _it('a pending context will still not run', async () => { + const pendingTest = sinon.spy(); + const otherTest = sinon.spy(); + const unfocusedTest = sinon.spy(); + + const testSuite = new TestSuite('', '', {}); + + testSuite.addTests(({ fdescribe, it, xdescribe }) => { + fdescribe('', () => { + xdescribe('', () => { + it('', pendingTest); + }); + + it('', otherTest); + }); + + it('', unfocusedTest); + }); + + testSuite.setStore({ + getState: () => { return {}; }, + }); + + const testIdsToRun = Object.keys(testSuite.testDefinitions.focusedTestIds).reduce((memo, testId) => { + if (!testSuite.testDefinitions.pendingTestIds[testId]) { + memo.push(testId); + } + + return memo; + }, []); + + await testSuite.run(testIdsToRun); + + pendingTest.should.not.be.called(); + otherTest.should.be.called(); + unfocusedTest.should.not.be.called(); + }); + }); } export default pendingTestTests; diff --git a/tests/lib/TestSuite.js b/tests/lib/TestSuite.js index 3924bb8b..aaa6735c 100644 --- a/tests/lib/TestSuite.js +++ b/tests/lib/TestSuite.js @@ -111,19 +111,19 @@ class TestSuite { */ async run(testIds = undefined) { const testsToRun = (() => { - if (testIds) { - return testIds.map((id) => { - const test = this.testDefinitions.tests[id]; + return (testIds || Object.keys(this.testDefinitions.tests)).reduce((memo, id) => { + const test = this.testDefinitions.tests[id]; - if (!test) { - throw new RangeError(`ReactNativeFirebaseTests.TestRunError: Test with id ${id} not found in test suite ${this.name}`); - } + if (!test) { + throw new RangeError(`ReactNativeFirebaseTests.TestRunError: Test with id ${id} not found in test suite ${this.name}`); + } - return test; - }); - } + if (!this.testDefinitions.pendingTestIds[id]) { + memo.push(test); + } - return Object.values(this.testDefinitions.tests); + return memo; + }, []); })(); const testRun = new TestRun(this, testsToRun.reverse(), this.testDefinitions);