Remove unstable scheduler/tracing API (#20037)

This commit is contained in:
Brian Vaughn
2021-04-26 19:16:18 -04:00
committed by GitHub
parent 7212383945
commit fc33f12bde
94 changed files with 2710 additions and 11153 deletions

View File

@@ -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,
};

View File

@@ -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,
};

View File

@@ -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'),
});

View File

@@ -46,8 +46,6 @@ global.spyOnProd = function(...args) {
};
expect.extend({
...require('../matchers/interactionTracingMatchers'),
...require('../matchers/profilerMatchers'),
...require('../matchers/toWarnDev'),
...require('../matchers/reactTestMatchers'),
});

View File

@@ -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;

View File

@@ -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)

View File

@@ -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 ||

View File

@@ -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',
});