mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Remove unstable scheduler/tracing API (#20037)
This commit is contained in:
@@ -1,101 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const jestDiff = require('jest-diff').default;
|
||||
|
||||
function toContainNoInteractions(actualSet) {
|
||||
return {
|
||||
message: () =>
|
||||
this.isNot
|
||||
? `Expected interactions but there were none.`
|
||||
: `Expected no interactions but there were ${actualSet.size}.`,
|
||||
pass: actualSet.size === 0,
|
||||
};
|
||||
}
|
||||
|
||||
function toHaveBeenLastNotifiedOfInteraction(
|
||||
mockFunction,
|
||||
expectedInteraction
|
||||
) {
|
||||
const calls = mockFunction.mock.calls;
|
||||
if (calls.length === 0) {
|
||||
return {
|
||||
message: () => 'Mock function was not called',
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
|
||||
const [actualInteraction] = calls[calls.length - 1];
|
||||
|
||||
return toMatchInteraction(actualInteraction, expectedInteraction);
|
||||
}
|
||||
|
||||
function toHaveBeenLastNotifiedOfWork(
|
||||
mockFunction,
|
||||
expectedInteractions,
|
||||
expectedThreadID = undefined
|
||||
) {
|
||||
const calls = mockFunction.mock.calls;
|
||||
if (calls.length === 0) {
|
||||
return {
|
||||
message: () => 'Mock function was not called',
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
|
||||
const [actualInteractions, actualThreadID] = calls[calls.length - 1];
|
||||
|
||||
if (expectedThreadID !== undefined) {
|
||||
if (expectedThreadID !== actualThreadID) {
|
||||
return {
|
||||
message: () => jestDiff(expectedThreadID + '', actualThreadID + ''),
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return toMatchInteractions(actualInteractions, expectedInteractions);
|
||||
}
|
||||
|
||||
function toMatchInteraction(actual, expected) {
|
||||
let attribute;
|
||||
for (attribute in expected) {
|
||||
if (actual[attribute] !== expected[attribute]) {
|
||||
return {
|
||||
message: () => jestDiff(expected, actual),
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {pass: true};
|
||||
}
|
||||
|
||||
function toMatchInteractions(actualSetOrArray, expectedSetOrArray) {
|
||||
const actualArray = Array.from(actualSetOrArray);
|
||||
const expectedArray = Array.from(expectedSetOrArray);
|
||||
|
||||
if (actualArray.length !== expectedArray.length) {
|
||||
return {
|
||||
message: () =>
|
||||
`Expected ${expectedArray.length} interactions but there were ${actualArray.length}`,
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
|
||||
for (let i = 0; i < actualArray.length; i++) {
|
||||
const result = toMatchInteraction(actualArray[i], expectedArray[i]);
|
||||
if (result.pass === false) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return {pass: true};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
toContainNoInteractions,
|
||||
toHaveBeenLastNotifiedOfInteraction,
|
||||
toHaveBeenLastNotifiedOfWork,
|
||||
toMatchInteraction,
|
||||
toMatchInteractions,
|
||||
};
|
||||
@@ -1,72 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const jestDiff = require('jest-diff').default;
|
||||
|
||||
function toHaveLastRenderedWithNoInteractions(onRenderMockFn) {
|
||||
const calls = onRenderMockFn.mock.calls;
|
||||
if (calls.length === 0) {
|
||||
return {
|
||||
message: () => 'Mock onRender function was not called',
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function toHaveLastRenderedWithInteractions(
|
||||
onRenderMockFn,
|
||||
expectedInteractions
|
||||
) {
|
||||
const calls = onRenderMockFn.mock.calls;
|
||||
if (calls.length === 0) {
|
||||
return {
|
||||
message: () => 'Mock onRender function was not called',
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
|
||||
const lastCall = calls[calls.length - 1];
|
||||
const actualInteractions = lastCall[6];
|
||||
|
||||
return toMatchInteractions(actualInteractions, expectedInteractions);
|
||||
}
|
||||
|
||||
function toMatchInteraction(actual, expected) {
|
||||
let attribute;
|
||||
for (attribute in expected) {
|
||||
if (actual[attribute] !== expected[attribute]) {
|
||||
return {
|
||||
message: () => jestDiff(expected, actual),
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {pass: true};
|
||||
}
|
||||
|
||||
function toMatchInteractions(actualSetOrArray, expectedSetOrArray) {
|
||||
const actualArray = Array.from(actualSetOrArray);
|
||||
const expectedArray = Array.from(expectedSetOrArray);
|
||||
|
||||
if (actualArray.length !== expectedArray.length) {
|
||||
return {
|
||||
message: () =>
|
||||
`Expected ${expectedArray.length} interactions but there were ${actualArray.length}`,
|
||||
pass: false,
|
||||
};
|
||||
}
|
||||
|
||||
for (let i = 0; i < actualArray.length; i++) {
|
||||
const result = toMatchInteraction(actualArray[i], expectedArray[i]);
|
||||
if (result.pass === false) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return {pass: true};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
toHaveLastRenderedWithInteractions,
|
||||
toHaveLastRenderedWithNoInteractions,
|
||||
};
|
||||
|
||||
@@ -45,8 +45,6 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
|
||||
}
|
||||
|
||||
expect.extend({
|
||||
...require('./matchers/interactionTracingMatchers'),
|
||||
...require('./matchers/profilerMatchers'),
|
||||
...require('./matchers/toWarnDev'),
|
||||
...require('./matchers/reactTestMatchers'),
|
||||
});
|
||||
|
||||
@@ -46,8 +46,6 @@ global.spyOnProd = function(...args) {
|
||||
};
|
||||
|
||||
expect.extend({
|
||||
...require('../matchers/interactionTracingMatchers'),
|
||||
...require('../matchers/profilerMatchers'),
|
||||
...require('../matchers/toWarnDev'),
|
||||
...require('../matchers/reactTestMatchers'),
|
||||
});
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
const {join} = require('path');
|
||||
const puppeteer = require('puppeteer');
|
||||
const theme = require('../theme');
|
||||
const {logPromise} = require('../utils');
|
||||
|
||||
const validate = async ({cwd}) => {
|
||||
const browser = await puppeteer.launch();
|
||||
const page = await browser.newPage();
|
||||
|
||||
await page.goto(
|
||||
'file://' + join(cwd, 'fixtures/tracing/index.html?puppeteer=true')
|
||||
);
|
||||
|
||||
try {
|
||||
return await page.evaluate(() => {
|
||||
const button = document.getElementById('run-test-button');
|
||||
button.click();
|
||||
|
||||
const items = document.querySelectorAll('[data-value]');
|
||||
|
||||
if (items.length === 0) {
|
||||
return 'No results were found.';
|
||||
}
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
if (item.getAttribute('data-value') !== 'All checks pass') {
|
||||
return `Unexpected result, "${item.getAttribute('data-value')}"`;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
};
|
||||
|
||||
const run = async ({cwd}) => {
|
||||
const errorMessage = await logPromise(
|
||||
validate({cwd}),
|
||||
'Verifying "scheduler/tracing" fixture'
|
||||
);
|
||||
if (errorMessage) {
|
||||
console.error(
|
||||
theme.error('✗'),
|
||||
'Verifying "scheduler/tracing" fixture\n ',
|
||||
theme.error(errorMessage)
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = run;
|
||||
@@ -805,24 +805,6 @@ const bundles = [
|
||||
global: 'ReactFreshRuntime',
|
||||
externals: [],
|
||||
},
|
||||
|
||||
{
|
||||
bundleTypes: [
|
||||
FB_WWW_DEV,
|
||||
FB_WWW_PROD,
|
||||
FB_WWW_PROFILING,
|
||||
NODE_DEV,
|
||||
NODE_PROD,
|
||||
NODE_PROFILING,
|
||||
RN_FB_DEV,
|
||||
RN_FB_PROD,
|
||||
RN_FB_PROFILING,
|
||||
],
|
||||
moduleType: ISOMORPHIC,
|
||||
entry: 'scheduler/tracing',
|
||||
global: 'SchedulerTracing',
|
||||
externals: [],
|
||||
},
|
||||
];
|
||||
|
||||
// Based on deep-freeze by substack (public domain)
|
||||
|
||||
@@ -171,25 +171,6 @@ const forks = Object.freeze({
|
||||
}
|
||||
},
|
||||
|
||||
'scheduler/tracing': (bundleType, entry, dependencies) => {
|
||||
switch (bundleType) {
|
||||
case UMD_DEV:
|
||||
case UMD_PROD:
|
||||
case UMD_PROFILING:
|
||||
if (dependencies.indexOf('react') === -1) {
|
||||
// It's only safe to use this fork for modules that depend on React,
|
||||
// because they read the re-exported API from the SECRET_INTERNALS object.
|
||||
return null;
|
||||
}
|
||||
// Optimization: for UMDs, use the API that is already a part of the React
|
||||
// package instead of requiring it to be loaded via a separate <script> tag
|
||||
return 'shared/forks/SchedulerTracing.umd.js';
|
||||
default:
|
||||
// For other bundles, use the shared NPM package.
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
'scheduler/src/SchedulerFeatureFlags': (bundleType, entry, dependencies) => {
|
||||
if (
|
||||
bundleType === FB_WWW_DEV ||
|
||||
|
||||
@@ -15,7 +15,6 @@ const importSideEffects = Object.freeze({
|
||||
'prop-types/checkPropTypes': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
||||
'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
||||
scheduler: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
||||
'scheduler/tracing': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
||||
react: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
||||
'react-dom/server': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
||||
'react/jsx-dev-runtime': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
||||
@@ -31,7 +30,6 @@ const knownGlobals = Object.freeze({
|
||||
'react-dom/server': 'ReactDOMServer',
|
||||
'react-interactions/events/tap': 'ReactEventsTap',
|
||||
scheduler: 'Scheduler',
|
||||
'scheduler/tracing': 'SchedulerTracing',
|
||||
'scheduler/unstable_mock': 'SchedulerMock',
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user