diff --git a/appveyor.yml b/appveyor.yml index 6c905cf67bab..7e1d847a2f78 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,7 +10,7 @@ init: install: - ps: Install-Product node $env:nodejs_version x64 - node --version - - curl -fsSL -o yarn.js https://github.com/yarnpkg/yarn/releases/download/v0.28.4/yarn-0.28.4.js + - curl -fsSL -o yarn.js https://github.com/yarnpkg/yarn/releases/download/v1.1.0/yarn-1.1.0.js - node ./yarn.js --version - node ./yarn.js install - node ./yarn.js run build @@ -20,7 +20,7 @@ cache: - .eslintcache test_script: - - node ./yarn.js run jest -- --color + - node ./yarn.js run jest --color # Don't actually build. build: off diff --git a/integration_tests/__tests__/request_animation_frame.test.js b/integration_tests/__tests__/request_animation_frame.test.js new file mode 100644 index 000000000000..383291d1f604 --- /dev/null +++ b/integration_tests/__tests__/request_animation_frame.test.js @@ -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. + * + * @flow + */ +'use strict'; + +const runJest = require('../runJest'); + +test('requestAnimationFrame', () => { + const result = runJest('request_animation_frame', ['--verbose']); + const stderr = result.stderr.toString(); + + expect(stderr).toMatch('requestAnimationFrame test'); + expect(result.status).toBe(0); +}); diff --git a/integration_tests/request_animation_frame/__tests__/request_animation_frame.test.js b/integration_tests/request_animation_frame/__tests__/request_animation_frame.test.js new file mode 100644 index 000000000000..8f1ff5cbfabf --- /dev/null +++ b/integration_tests/request_animation_frame/__tests__/request_animation_frame.test.js @@ -0,0 +1,21 @@ +/** + * 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. + */ + +/* eslint-env browser */ + +'use strict'; + +test('requestAnimationFrame test', done => { + expect.hasAssertions(); + + requestAnimationFrame(timestamp => { + expect(true).toBe(true); + expect(timestamp).toBeGreaterThan(0); + + done(); + }); +}); diff --git a/integration_tests/request_animation_frame/package.json b/integration_tests/request_animation_frame/package.json new file mode 100644 index 000000000000..0ded940b7cb7 --- /dev/null +++ b/integration_tests/request_animation_frame/package.json @@ -0,0 +1,5 @@ +{ + "jest": { + "testEnvironment": "jsdom" + } +} diff --git a/packages/jest-environment-jsdom/src/index.js b/packages/jest-environment-jsdom/src/index.js index 2f957d2e9ac9..f03b6543c92b 100644 --- a/packages/jest-environment-jsdom/src/index.js +++ b/packages/jest-environment-jsdom/src/index.js @@ -22,6 +22,7 @@ class JSDOMEnvironment { moduleMocker: ?ModuleMocker; constructor(config: ProjectConfig): void { + const jsdomInitialized = process.hrtime(); // lazy require this.document = JSDom.jsdom('', { url: config.testURL, @@ -32,6 +33,16 @@ class JSDOMEnvironment { this.global.Error.stackTraceLimit = 100; installCommonGlobals(global, config.globals); + if (!global.requestAnimationFrame) { + global.requestAnimationFrame = callback => { + const hr = process.hrtime(jsdomInitialized); + const hrInNano = hr[0] * 1e9 + hr[1]; + const hrInMicro = hrInNano / 1e6; + + return global.setTimeout(callback, 0, hrInMicro); + }; + } + this.moduleMocker = new mock.ModuleMocker(global); this.fakeTimers = new FakeTimers(global, this.moduleMocker, config); }