Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove p-map and fix jasmine promise chain #3880

Merged
merged 2 commits into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions integration_tests/__tests__/iterator-to-null-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 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';

Array.prototype[Symbol.iterator] = null;
String.prototype[Symbol.iterator] = null;

test('modifying global object does not affect test runner', () => {});
3 changes: 1 addition & 2 deletions packages/jest-jasmine2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"jest-matcher-utils": "^20.0.3",
"jest-matchers": "^20.0.3",
"jest-message-util": "^20.0.3",
"jest-snapshot": "^20.0.3",
"p-map": "^1.1.1"
"jest-snapshot": "^20.0.3"
},
"devDependencies": {
"jest-runtime": "^20.0.4"
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-jasmine2/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import jasmineAsync from './jasmine-async';

const JASMINE = require.resolve('./jasmine/jasmine-light.js');

function jasmine2(
async function jasmine2(
globalConfig: GlobalConfig,
config: ProjectConfig,
environment: Environment,
Expand Down Expand Up @@ -93,7 +93,7 @@ function jasmine2(
}

runtime.requireModule(testPath);
env.execute();
await env.execute();
return reporter
.getResults()
.then(results => addSnapshotData(results, snapshotState));
Expand Down
17 changes: 8 additions & 9 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ module.exports = function(j$) {
return seed;
};

function queueRunnerFactory(options) {
async function queueRunnerFactory(options) {
options.clearTimeout = realClearTimeout;
options.fail = self.fail;
options.setTimeout = realSetTimeout;
Expand All @@ -178,7 +178,7 @@ module.exports = function(j$) {
return topSuite;
};

this.execute = function(runnablesToRun) {
this.execute = async function(runnablesToRun) {
if (!runnablesToRun) {
if (focusedRunnables.length) {
runnablesToRun = focusedRunnables;
Expand All @@ -193,7 +193,7 @@ module.exports = function(j$) {

currentlyExecutingSuites.push(topSuite);

treeProcessor({
await treeProcessor({
nodeComplete(suite) {
if (!suite.disabled) {
clearResourcesForRunnable(suite.id);
Expand All @@ -209,12 +209,11 @@ module.exports = function(j$) {
queueRunnerFactory,
runnableIds: runnablesToRun,
tree: topSuite,
}).then(() => {
clearResourcesForRunnable(topSuite.id);
currentlyExecutingSuites.pop();
reporter.jasmineDone({
failedExpectations: topSuite.result.failedExpectations,
});
});
clearResourcesForRunnable(topSuite.id);
currentlyExecutingSuites.pop();
reporter.jasmineDone({
failedExpectations: topSuite.result.failedExpectations,
});
};

Expand Down
11 changes: 7 additions & 4 deletions packages/jest-jasmine2/src/queueRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @flow
*/

import pMap from 'p-map';
import pTimeout from './p-timeout';

type Options = {
Expand All @@ -25,10 +24,10 @@ type QueueableFn = {
timeout?: () => number,
};

function queueRunner(options: Options) {
async function queueRunner(options: Options) {
const mapper = ({fn, timeout}) => {
const promise = new Promise(resolve => {
const next = () => resolve();
const next = () => resolve();
next.fail = function() {
options.fail.apply(null, arguments);
resolve();
Expand Down Expand Up @@ -57,7 +56,11 @@ function queueRunner(options: Options) {
},
);
};
return pMap(options.queueableFns, mapper, {concurrency: 1});

return options.queueableFns.reduce(
(promise, fn) => promise.then(() => mapper(fn)),
Promise.resolve(),
);
}

module.exports = queueRunner;