Skip to content

Commit

Permalink
Move Noop Module Test Helpers to top level entry points
Browse files Browse the repository at this point in the history
This module has shared state. It needs to be external from builds.

This lets us test the built versions of the Noop renderer.
  • Loading branch information
sebmarkbage committed Mar 23, 2020
1 parent da758b1 commit b5c62c8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
16 changes: 16 additions & 0 deletions packages/react-noop-renderer/npm/flight-modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

// This file is used as temporary storage for modules generated in Flight tests.
var moduleIdx = 0;
var modules = new Map();

// This simulates what the compiler will do when it replaces render functions with server blocks.
exports.saveModule = function saveModule(render) {
var idx = '' + moduleIdx++;
modules.set(idx, render);
return idx;
};

exports.readModule = function readModule(idx) {
return modules.get(idx);
};
1 change: 1 addition & 0 deletions packages/react-noop-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"persistent.js",
"server.js",
"flight-client.js",
"flight-modules.js",
"flight-server.js",
"cjs/"
]
Expand Down
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/src/ReactNoopFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type {ReactModelRoot} from 'react-client/flight';

import {readModule} from './ReactNoopFlightModuleTestHelper';
import {readModule} from 'react-noop-renderer/flight-modules';

import ReactFlightClient from 'react-client/flight';

Expand Down
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/src/ReactNoopFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type {ReactModel} from 'react-server/src/ReactFlightServer';

import {saveModule} from './ReactNoopFlightModuleTestHelper';
import {saveModule} from 'react-noop-renderer/flight-modules';

import ReactFlightServer from 'react-server/flight';

Expand Down
14 changes: 12 additions & 2 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,12 @@ const bundles = [
moduleType: RENDERER,
entry: 'react-noop-renderer/flight-server',
global: 'ReactNoopFlightServer',
externals: ['react', 'scheduler', 'expect'],
externals: [
'react',
'scheduler',
'expect',
'react-noop-renderer/flight-modules',
],
},

/******* React Noop Flight Client (used for tests) *******/
Expand All @@ -414,7 +419,12 @@ const bundles = [
moduleType: RENDERER,
entry: 'react-noop-renderer/flight-client',
global: 'ReactNoopFlightClient',
externals: ['react', 'scheduler', 'expect'],
externals: [
'react',
'scheduler',
'expect',
'react-noop-renderer/flight-modules',
],
},

/******* React Reconciler *******/
Expand Down

0 comments on commit b5c62c8

Please sign in to comment.