Skip to content

Commit

Permalink
chore: add integration test for driving promises with fake timers (#7071
Browse files Browse the repository at this point in the history
)
  • Loading branch information
SimenB committed Oct 2, 2018
1 parent 659b048 commit 78e0893
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 61 deletions.
23 changes: 23 additions & 0 deletions e2e/__tests__/fake-promises.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2014-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.
*
* @flow
*/
'use strict';

const runJest = require('../runJest');

describe('Fake promises', () => {
it('should be possible to resolve with fake timers using immediates', () => {
const result = runJest('fake-promises/immediate');
expect(result.status).toBe(0);
});

it('should be possible to resolve with fake timers using asap', () => {
const result = runJest('fake-promises/asap');
expect(result.status).toBe(0);
});
});
19 changes: 19 additions & 0 deletions e2e/fake-promises/asap/__tests__/generator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2014-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';

test('fake promises', () => {
let someValue;
Promise.resolve().then(() => {
someValue = 'foobar';
});

jest.runAllTicks();

expect(someValue).toBe('foobar');
});
10 changes: 10 additions & 0 deletions e2e/fake-promises/asap/fake-promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) 2014-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';

global.Promise = require('promise');
9 changes: 9 additions & 0 deletions e2e/fake-promises/asap/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jest": {
"timers": "fake",
"setupFiles": [
"<rootDir>/fake-promises"
],
"testEnvironment": "node"
}
}
19 changes: 19 additions & 0 deletions e2e/fake-promises/immediate/__tests__/generator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2014-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';

test('fake promises', () => {
let someValue;
Promise.resolve().then(() => {
someValue = 'foobar';
});

jest.runAllImmediates();

expect(someValue).toBe('foobar');
});
10 changes: 10 additions & 0 deletions e2e/fake-promises/immediate/fake-promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) 2014-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';

global.Promise = require('promise/setimmediate');
9 changes: 9 additions & 0 deletions e2e/fake-promises/immediate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jest": {
"timers": "fake",
"setupFiles": [
"<rootDir>/fake-promises"
],
"testEnvironment": "node"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"prettier": "^1.13.3",
"prettylint": "^1.0.0",
"progress": "^2.0.0",
"promise": "^8.0.2",
"readable-stream": "^3.0.3",
"regenerator-runtime": "^0.11.0",
"resolve": "^1.4.0",
Expand Down

0 comments on commit 78e0893

Please sign in to comment.