From aa6a20f9b322c667f5e61db9fa2eefc624ac4bda Mon Sep 17 00:00:00 2001 From: Dmitrii Abramov Date: Thu, 22 Sep 2016 22:07:06 -0700 Subject: [PATCH] tests with no implementation (#1775) --- .../__snapshots__/globals-test.js.snap | 56 +++++++-- integration_tests/__tests__/globals-test.js | 111 ++++++++++++++++-- .../globals/__tests__/globals-test.js | 40 ------- integration_tests/globals/package.json | 1 - integration_tests/utils.js | 21 +++- packages/jest-jasmine2/src/jasmine-async.js | 4 +- 6 files changed, 171 insertions(+), 62 deletions(-) delete mode 100644 integration_tests/globals/__tests__/globals-test.js delete mode 100644 integration_tests/globals/package.json diff --git a/integration_tests/__tests__/__snapshots__/globals-test.js.snap b/integration_tests/__tests__/__snapshots__/globals-test.js.snap index c1c3887aa745..e16c7b13c5ad 100644 --- a/integration_tests/__tests__/__snapshots__/globals-test.js.snap +++ b/integration_tests/__tests__/__snapshots__/globals-test.js.snap @@ -1,19 +1,57 @@ -exports[`test global jest variables 1`] = ` -" PASS __tests__/globals-test.js - ✓ it.only +exports[`test basic test constructs 1`] = ` +" PASS __tests__/basic-test-constructs-test.js + ✓ it + ✓ test + describe + ✓ it + ✓ test + +Test Summary + › Ran all tests." +`; + +exports[`test only 1`] = ` +" PASS __tests__/only-constructs-test.js ✓ test.only + ✓ it.only + ✓ fit ○ it - ○ test - ○ it.skip - ○ test.skip - ○ xit - ○ xtest fdescribe + ✓ it ✓ test describe.only ✓ test - describe + describe + ✓ test + +Test Summary + › Ran all tests." +`; + +exports[`test skips 1`] = ` +" PASS __tests__/skips-constructs-test.js + ✓ it + ○ xtest + ○ xit + ○ it.skip + ○ test.skip + xdescribe + ○ it + ○ test + describe.skip ○ test + describe + ○ test + +Test Summary + › Ran all tests." +`; + +exports[`test tests with no implementation 1`] = ` +" PASS __tests__/only-constructs-test.js + ✓ it + ○ it, no implementation + ○ test, no implementation Test Summary › Ran all tests." diff --git a/integration_tests/__tests__/globals-test.js b/integration_tests/__tests__/globals-test.js index 9aff730edda1..4950fdecfb3f 100644 --- a/integration_tests/__tests__/globals-test.js +++ b/integration_tests/__tests__/globals-test.js @@ -11,21 +11,114 @@ const path = require('path'); const runJest = require('../runJest'); const skipOnWindows = require('skipOnWindows'); +const os = require('os'); +const {createEmptyPackage, makeTests, cleanup} = require('../utils'); + +const DIR = path.resolve(os.tmpdir(), 'global-variables-test'); +const TEST_DIR = path.resolve(DIR, '__tests__'); skipOnWindows.suite(); -const dir = path.resolve(__dirname, '../globals'); +const escapeOutput = string => string + .split('\n') + .slice(0, -2) + .join('\n') + .replace(/\s*\(.*ms\)/gm, ''); + +beforeEach(() => { + cleanup(DIR); + createEmptyPackage(DIR); +}); + +afterAll(() => cleanup(DIR)); + +test('basic test constructs', () => { + const filename = 'basic-test-constructs-test.js'; + const content = ` + it('it', () => {}); + test('test', () => {}); + + describe('describe', () => { + it('it', () => {}); + test('test', () => {}); + }); + `; -test('global jest variables', () => { - const {stderr, status} = runJest(dir); + makeTests(TEST_DIR, {[filename]: content}); + const {stderr, status} = runJest(DIR); + expect(escapeOutput(stderr)).toMatchSnapshot(); expect(status).toBe(0); +}); + +test('skips', () => { + const filename = 'skips-constructs-test.js'; + const content = ` + it('it', () => {}); + xtest('xtest', () => {}); + xit('xit', () => {}); + it.skip('it.skip', () => {}); + test.skip('test.skip', () => {}); + + xdescribe('xdescribe', () => { + it('it', () => {}); + test('test', () => {}); + }); - const output = stderr - .split('\n') - .slice(0, -2) - .join('\n') - .replace(/\s*\(.*ms\)/gm, ''); + describe.skip('describe.skip', () => { + test('test', () => {}); + describe('describe', () => { + test('test', () => {}); + }); + }); + `; - expect(output).toMatchSnapshot(); + makeTests(TEST_DIR, {[filename]: content}); + const {stderr, status} = runJest(DIR); + + expect(escapeOutput(stderr)).toMatchSnapshot(); + expect(status).toBe(0); +}); + +test('only', () => { + const filename = 'only-constructs-test.js'; + const content = ` + it('it', () => {}); + test.only('test.only', () => {}); + it.only('it.only', () => {}); + fit('fit', () => {}); + + fdescribe('fdescribe', () => { + it('it', () => {}); + test('test', () => {}); + }); + + describe.only('describe.only', () => { + test('test', () => {}); + describe('describe', () => { + test('test', () => {}); + }); + }); + `; + + makeTests(TEST_DIR, {[filename]: content}); + const {stderr, status} = runJest(DIR); + + expect(escapeOutput(stderr)).toMatchSnapshot(); + expect(status).toBe(0); +}); + +test('tests with no implementation', () => { + const filename = 'only-constructs-test.js'; + const content = ` + it('it', () => {}); + it('it, no implementation'); + test('test, no implementation'); + `; + + makeTests(TEST_DIR, {[filename]: content}); + const {stderr, status} = runJest(DIR); + + expect(escapeOutput(stderr)).toMatchSnapshot(); + expect(status).toBe(0); }); diff --git a/integration_tests/globals/__tests__/globals-test.js b/integration_tests/globals/__tests__/globals-test.js deleted file mode 100644 index 0d415217389c..000000000000 --- a/integration_tests/globals/__tests__/globals-test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - - -'use strict'; - -it('it', () => {}); -test('test', () => {}); - -describe('describe', () => { - test('test', () => {}); -}); - -fdescribe('fdescribe', () => { - test('test', () => {}); -}); - -describe.only('describe.only', () => { - test('test', () => {}); -}); - -it.skip('it.skip', () => {}); -test.skip('test.skip', () => {}); - -it.only('it.only', () => {}); -test.only('test.only', () => {}); - -xit('xit', () => {}); -/* eslint-disable no-undef */ -xtest('xtest', () => {}); -/* eslint-enable no-undef */ - -xdescribe('xdescribe', () => { - test('test'); -}); diff --git a/integration_tests/globals/package.json b/integration_tests/globals/package.json deleted file mode 100644 index 0967ef424bce..000000000000 --- a/integration_tests/globals/package.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/integration_tests/utils.js b/integration_tests/utils.js index b8e8541f7f61..66a8802c7aca 100644 --- a/integration_tests/utils.js +++ b/integration_tests/utils.js @@ -65,11 +65,28 @@ const makeTests = (directory: string, tests: {[filename: string]: string}) => { }); }; +const createEmptyPackage = (directory, packageJson) => { + const DEFAULT_PACKAGE_JSON = { + description: 'THIS IS AN AUTOGENERATED FILE AND SHOULD NOT BE ADDED TO GIT', + jest: { + testEnvironment: 'node', + }, + }; + + mkdirp.sync(directory); + packageJson || (packageJson = DEFAULT_PACKAGE_JSON); + fs.writeFileSync( + path.resolve(directory, 'package.json'), + JSON.stringify(packageJson, null, 2) + ); +}; + module.exports = { cleanup, - makeTests, - makeTemplate, + createEmptyPackage, fileExists, linkJestPackage, + makeTemplate, + makeTests, run, }; diff --git a/packages/jest-jasmine2/src/jasmine-async.js b/packages/jest-jasmine2/src/jasmine-async.js index 5d8d55c67e8e..8a9a7a9d6a15 100644 --- a/packages/jest-jasmine2/src/jasmine-async.js +++ b/packages/jest-jasmine2/src/jasmine-async.js @@ -25,7 +25,9 @@ function isPromise(obj) { function promisifyIt(originalFn, env) { return function(specName, fn, timeout) { if (!fn) { - return null; + const spec = originalFn.call(env, specName); + spec.pend('not implemented'); + return spec; } const isAsync = fn.length; // `done` was passed