mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
* Change demo to server * Expose client in package.json * Reorganize tests We don't want unit tests but instead test how both server and clients work together. So this merges server/client test files. * Fill in the client implementation a bit * Use new client in fixture * Add Promise/Uint8Array to lint rule I'll probably end up deleting these deps later but they're here for now.
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @emails react-core
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
// Polyfills for test environment
|
|
global.ReadableStream = require('@mattiasbuelens/web-streams-polyfill/ponyfill/es6').ReadableStream;
|
|
global.TextEncoder = require('util').TextEncoder;
|
|
|
|
let React;
|
|
let ReactFlightDOMServer;
|
|
|
|
describe('ReactFlightDOM', () => {
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
React = require('react');
|
|
ReactFlightDOMServer = require('react-dom/unstable-flight-server.browser');
|
|
});
|
|
|
|
async function readResult(stream) {
|
|
let reader = stream.getReader();
|
|
let result = '';
|
|
while (true) {
|
|
let {done, value} = await reader.read();
|
|
if (done) {
|
|
return result;
|
|
}
|
|
result += Buffer.from(value).toString('utf8');
|
|
}
|
|
}
|
|
|
|
it('should resolve HTML', async () => {
|
|
function Text({children}) {
|
|
return <span>{children}</span>;
|
|
}
|
|
function HTML() {
|
|
return (
|
|
<div>
|
|
<Text>hello</Text>
|
|
<Text>world</Text>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
let model = {
|
|
html: <HTML />,
|
|
};
|
|
let stream = ReactFlightDOMServer.renderToReadableStream(model);
|
|
jest.runAllTimers();
|
|
let result = JSON.parse(await readResult(stream));
|
|
expect(result).toEqual({
|
|
html: '<div><span>hello</span><span>world</span></div>',
|
|
});
|
|
});
|
|
});
|