Skip to content

Commit 9a28a28

Browse files
bvaughnjetoneza
authored andcommitted
Added Jest test to verify UMD API-forwarding for scheduling package (facebook#13532)
* Added Jest test to verify UMD API-forwarding for scheduling package * Added separate dev/prod UMD bundles for scheduler package
1 parent 591173d commit 9a28a28

File tree

6 files changed

+183
-2
lines changed

6 files changed

+183
-2
lines changed

fixtures/tracking/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ <h3>
6363
</li>
6464
</ol>
6565
<!-- Load the tracking API before react to test that it's lazily evaluated -->
66-
<script src="../../build/node_modules/react-scheduler/umd/react-scheduler.js"></script>
67-
<script src="../../build/node_modules/react-scheduler/umd/react-scheduler-tracking.js"></script>
66+
<script src="../../build/node_modules/react-scheduler/umd/react-scheduler.development.js"></script>
67+
<script src="../../build/node_modules/react-scheduler/umd/react-scheduler-tracking.development.js"></script>
6868
<script src="../../build/node_modules/react/umd/react.development.js"></script>
6969
<script src="../../build/node_modules/react-dom/umd/react-dom.development.js"></script>
7070
<script src="./script.js"></script>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @license React
3+
*
4+
* Copyright (c) 2013-present, Facebook, Inc.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
'use strict';
11+
12+
(function(global, factory) {
13+
typeof exports === 'object' && typeof module !== 'undefined'
14+
? (module.exports = factory(require('react')))
15+
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
16+
? define(['react'], factory) // eslint-disable-line no-undef
17+
: (global.ReactSchedulerTracking = factory(global));
18+
})(this, function(global) {
19+
function __getInteractionsRef() {
20+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.SchedulerTracking.__getInteractionsRef.apply(
21+
this,
22+
arguments
23+
);
24+
}
25+
26+
function __getSubscriberRef() {
27+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.SchedulerTracking.__getSubscriberRef.apply(
28+
this,
29+
arguments
30+
);
31+
}
32+
33+
function unstable_clear() {
34+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.SchedulerTracking.unstable_clear.apply(
35+
this,
36+
arguments
37+
);
38+
}
39+
40+
function unstable_getCurrent() {
41+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.SchedulerTracking.unstable_getCurrent.apply(
42+
this,
43+
arguments
44+
);
45+
}
46+
47+
function unstable_getThreadID() {
48+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.SchedulerTracking.unstable_getThreadID.apply(
49+
this,
50+
arguments
51+
);
52+
}
53+
54+
function unstable_subscribe() {
55+
// eslint-disable-next-line max-len
56+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.SchedulerTracking.unstable_subscribe.apply(
57+
this,
58+
arguments
59+
);
60+
}
61+
62+
function unstable_track() {
63+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.SchedulerTracking.unstable_track.apply(
64+
this,
65+
arguments
66+
);
67+
}
68+
69+
function unstable_unsubscribe() {
70+
// eslint-disable-next-line max-len
71+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.SchedulerTracking.unstable_unsubscribe.apply(
72+
this,
73+
arguments
74+
);
75+
}
76+
77+
function unstable_wrap() {
78+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.SchedulerTracking.unstable_wrap.apply(
79+
this,
80+
arguments
81+
);
82+
}
83+
84+
return Object.freeze({
85+
__getInteractionsRef: __getInteractionsRef,
86+
__getSubscriberRef: __getSubscriberRef,
87+
unstable_clear: unstable_clear,
88+
unstable_getCurrent: unstable_getCurrent,
89+
unstable_getThreadID: unstable_getThreadID,
90+
unstable_subscribe: unstable_subscribe,
91+
unstable_track: unstable_track,
92+
unstable_unsubscribe: unstable_unsubscribe,
93+
unstable_wrap: unstable_wrap,
94+
});
95+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @license React
3+
*
4+
* Copyright (c) 2013-present, Facebook, Inc.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
'use strict';
11+
12+
(function(global, factory) {
13+
typeof exports === 'object' && typeof module !== 'undefined'
14+
? (module.exports = factory(require('react')))
15+
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
16+
? define(['react'], factory) // eslint-disable-line no-undef
17+
: (global.ReactScheduler = factory(global));
18+
})(this, function(global) {
19+
function unstable_now() {
20+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Scheduler.unstable_now.apply(
21+
this,
22+
arguments
23+
);
24+
}
25+
26+
function unstable_scheduleWork() {
27+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Scheduler.unstable_scheduleWork.apply(
28+
this,
29+
arguments
30+
);
31+
}
32+
33+
function unstable_cancelScheduledWork() {
34+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Scheduler.unstable_cancelScheduledWork.apply(
35+
this,
36+
arguments
37+
);
38+
}
39+
40+
return Object.freeze({
41+
unstable_now: unstable_now,
42+
unstable_scheduleWork: unstable_scheduleWork,
43+
unstable_cancelScheduledWork: unstable_cancelScheduledWork,
44+
});
45+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @jest-environment node
8+
*/
9+
'use strict';
10+
11+
describe('Scheduling UMD bundle', () => {
12+
beforeEach(() => {
13+
// Fool SECRET_INTERNALS object into including UMD forwarding methods.
14+
global.__UMD__ = true;
15+
16+
jest.resetModules();
17+
});
18+
19+
function compareAPIS(apis) {
20+
apis = apis.map(api => Object.keys(api).sort());
21+
for (let i = 1; i < apis.length; i++) {
22+
expect(apis[0]).toEqual(apis[i]);
23+
}
24+
}
25+
26+
it('should define the same scheduling API', () => {
27+
const umdAPIDev = require('../../npm/umd/react-scheduler.development');
28+
const umdAPIProd = require('../../npm/umd/react-scheduler.production.min');
29+
const cjsAPI = require('../../index');
30+
const secretAPI = require('react/src/ReactSharedInternals').default;
31+
compareAPIS([umdAPIDev, umdAPIProd, cjsAPI, secretAPI.Scheduler]);
32+
});
33+
34+
it('should define the same tracking API', () => {
35+
const umdAPIDev = require('../../npm/umd/react-scheduler-tracking.development');
36+
const umdAPIProd = require('../../npm/umd/react-scheduler-tracking.production.min');
37+
const cjsAPI = require('../../tracking');
38+
const secretAPI = require('react/src/ReactSharedInternals').default;
39+
compareAPIS([umdAPIDev, umdAPIProd, cjsAPI, secretAPI.SchedulerTracking]);
40+
});
41+
});

0 commit comments

Comments
 (0)