Skip to content

Commit

Permalink
remove p-map and fix jasmine promise chain (#3880)
Browse files Browse the repository at this point in the history
* iterator-to-null test

* move jasmine back to inner scope / don't use iterators
  • Loading branch information
aaronabramov authored Jun 22, 2017
1 parent e9b045f commit e7b0a07
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
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 @@ -97,7 +97,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
9 changes: 6 additions & 3 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,7 +24,7 @@ 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();
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;

0 comments on commit e7b0a07

Please sign in to comment.