Skip to content

Commit

Permalink
Set different limits for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Dec 7, 2017
1 parent d4ff183 commit 3fc85fa
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions scripts/babel/transform-prevent-infinite-loops.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* Copyright (c) 2017, Amjad Masad
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// TODO: attribution (this is based on https://repl.it/site/blog/infinite-loops)

'use strict';

// This should be reasonable for all loops that happen in our tests.
// Note that if the number is too large, the tests will take too long to fail
// Based on https://repl.it/site/blog/infinite-loops.

// This should be reasonable for all loops in the source.
// Note that if the numbers are too large, the tests will take too long to fail
// for this to be useful (each individual test case might hit an infinite loop).
const MAX_ITERATIONS = 2000;
const MAX_SOURCE_ITERATIONS = 1000;
// Code in tests themselves is permitted to run longer.
// For example, in the fuzz tester.
const MAX_TEST_ITERATIONS = 5000;

module.exports = ({types: t}) => ({
visitor: {
'WhileStatement|ForStatement|DoWhileStatement': path => {
'WhileStatement|ForStatement|DoWhileStatement': (path, file) => {
const filename = file.file.opts.filename;
const MAX_ITERATIONS =
filename.indexOf('__tests__') === -1
? MAX_SOURCE_ITERATIONS
: MAX_TEST_ITERATIONS;

// An iterator that is incremented with each iteration
const iterator = path.scope.parent.generateUidIdentifier('loopIt');
const iteratorInit = t.numericLiteral(0);
Expand Down

0 comments on commit 3fc85fa

Please sign in to comment.