From 9adb79179ac411df4bddef41daac78bc8b463c06 Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Wed, 26 Dec 2018 17:42:48 +0100 Subject: [PATCH] add test case for ordering to list-tests e2e test --- .../__snapshots__/list_tests.test.js.snap | 5 +++-- e2e/__tests__/list_tests.test.js | 10 ++++++++++ e2e/list-tests/__tests__/other.test.js | 3 +++ e2e/list-tests/__tests__/with-dep.test.js | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 e2e/list-tests/__tests__/with-dep.test.js diff --git a/e2e/__tests__/__snapshots__/list_tests.test.js.snap b/e2e/__tests__/__snapshots__/list_tests.test.js.snap index b1d8584f771e..73f79aa25de4 100644 --- a/e2e/__tests__/__snapshots__/list_tests.test.js.snap +++ b/e2e/__tests__/__snapshots__/list_tests.test.js.snap @@ -2,7 +2,8 @@ exports[`--listTests flag causes tests to be printed in different lines 1`] = ` "/MOCK_ABOLUTE_PATH/e2e/list-tests/__tests__/dummy.test.js -/MOCK_ABOLUTE_PATH/e2e/list-tests/__tests__/other.test.js" +/MOCK_ABOLUTE_PATH/e2e/list-tests/__tests__/other.test.js +/MOCK_ABOLUTE_PATH/e2e/list-tests/__tests__/with-dep.test.js" `; -exports[`--listTests flag causes tests to be printed out as JSON when using the --json flag 1`] = `"[\\"/MOCK_ABOLUTE_PATH/e2e/list-tests/__tests__/dummy.test.js\\",\\"/MOCK_ABOLUTE_PATH/e2e/list-tests/__tests__/other.test.js\\"]"`; +exports[`--listTests flag causes tests to be printed out as JSON when using the --json flag 1`] = `"[\\"/MOCK_ABOLUTE_PATH/e2e/list-tests/__tests__/dummy.test.js\\",\\"/MOCK_ABOLUTE_PATH/e2e/list-tests/__tests__/other.test.js\\",\\"/MOCK_ABOLUTE_PATH/e2e/list-tests/__tests__/with-dep.test.js\\"]"`; diff --git a/e2e/__tests__/list_tests.test.js b/e2e/__tests__/list_tests.test.js index 34877a8cae68..80757fe40fd9 100644 --- a/e2e/__tests__/list_tests.test.js +++ b/e2e/__tests__/list_tests.test.js @@ -33,6 +33,16 @@ describe('--listTests flag', () => { ).toMatchSnapshot(); }); + it('prints tests in the execution order determined by their dependency sizes', () => { + const {status, stdout} = runJest('list-tests', ['--listTests']); + expect(status).toBe(0); + expect(normalizePaths(stdout).split('\n')).toEqual([ + expect.stringContaining('/with-dep.test.js'), + expect.stringContaining('/other.test.js'), + expect.stringContaining('/dummy.test.js'), + ]); + }); + it('causes tests to be printed out as JSON when using the --json flag', () => { const {status, stdout} = runJest('list-tests', ['--listTests', '--json']); diff --git a/e2e/list-tests/__tests__/other.test.js b/e2e/list-tests/__tests__/other.test.js index b5d611fa8987..3cd81e66bf11 100644 --- a/e2e/list-tests/__tests__/other.test.js +++ b/e2e/list-tests/__tests__/other.test.js @@ -11,3 +11,6 @@ it("isn't actually run", () => { // (because it is only used for --listTests) expect(true).toBe(false); }); + +// Because of this comment, other.test.js is slightly larger than dummy.test.js. +// This matters for the order in which tests are sequenced. diff --git a/e2e/list-tests/__tests__/with-dep.test.js b/e2e/list-tests/__tests__/with-dep.test.js new file mode 100644 index 000000000000..02c379fb152b --- /dev/null +++ b/e2e/list-tests/__tests__/with-dep.test.js @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2018-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +'use strict'; + +require('./dummy.test.js'); + +it("isn't actually run", () => { + // (because it is only used for --listTests) + expect(true).toBe(false); +});