Skip to content

Commit ac6194a

Browse files
authored
fix: manually backport Jest testing server fix added in v2.8.0-beta.1
1 parent 2a2694e commit ac6194a

File tree

1 file changed

+5
-67
lines changed

1 file changed

+5
-67
lines changed

packages/servers/testing-server/index.js

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,26 @@
11
const { handleRequest } = require('@bolt/api');
2-
const {
3-
devMiddleware,
4-
webpack,
5-
express,
6-
} = require('@bolt/build-tools/webpack-dev-server');
7-
const { join } = require('path');
8-
const globby = require('globby');
2+
const { express } = require('@bolt/build-tools/webpack-dev-server');
93
const app = express();
104
const path = require('path');
115

126
const port = process.env.PORT || 4444;
13-
const createWebpackConfig = require('@bolt/build-tools/create-webpack-config');
147
const { getConfig } = require('@bolt/build-tools/utils/config-store');
8+
const webpackTasks = require('@bolt/build-tools/tasks/webpack-tasks');
159

1610
let server;
1711

18-
// @todo: re-evaluate if this is worthwhile to re-enable
19-
// const allComponentsWithTests = globby
20-
// .sync(
21-
// path.join(__dirname, '../../../', '/packages/components/**/__tests__'),
22-
// {
23-
// onlyDirectories: true,
24-
// },
25-
// )
26-
// .map(testsDirPath =>
27-
// require(path.join(path.resolve(testsDirPath, '..'), 'package.json')),
28-
// )
29-
// .map(pkg => pkg.name);
30-
3112
getConfig().then(async boltConfig => {
3213
let config = boltConfig;
33-
34-
// don't compile anything in Webpack except for the exported JSON data from Bolt's Design Tokens + all packages with tests
35-
// config.components.global = [
36-
// './packages/core/styles/index.scss',
37-
// '@bolt/global',
38-
// ...allComponentsWithTests,
39-
// ];
40-
41-
config.mode = 'client';
42-
config.components.individual = [];
43-
config.prod = true;
44-
config.sourceMaps = false;
45-
46-
const webpackConfig = await createWebpackConfig(config);
47-
const compiler = webpack(webpackConfig);
48-
49-
// This function makes server rendering of asset references consistent with different webpack chunk/entry configurations
50-
function normalizeAssets(assets) {
51-
return Array.isArray(assets) ? assets : [assets];
52-
}
53-
54-
app.use(
55-
devMiddleware(compiler, {
56-
serverSideRender: true,
57-
stats: webpackConfig[0].devServer.stats,
58-
}),
59-
);
60-
14+
await webpackTasks.compile();
6115
app.use(express.static(path.relative(process.cwd(), config.wwwDir)));
6216

63-
// The following middleware would not be invoked until the latest build is finished.
6417
app.use((req, res) => {
65-
const assetsByChunkName = res.locals.webpackStats.toJson().children[0]
66-
.assetsByChunkName;
67-
const fs = res.locals.fs;
68-
const outputPath = res.locals.webpackStats.toJson().children[0].outputPath;
69-
70-
// then use `assetsByChunkName` for server-sider rendering
71-
// For example, if you have only one main chunk:
7218
res.send(
7319
`<html class="js-fonts-loaded">
7420
<head>
7521
<title>Test</title>
76-
<style>${normalizeAssets(assetsByChunkName['bolt-global'])
77-
.filter(path => path.endsWith('.css'))
78-
.map(path => fs.readFileSync(outputPath + '/' + path))
79-
.join('\n')}</style>
80-
81-
${normalizeAssets(assetsByChunkName['bolt-global'])
82-
.filter(path => path.endsWith('.js'))
83-
.map(path => `<script src="${path}"></script>`)
84-
.join('\n')}
22+
<link rel="stylesheet" href="/build/bolt-global.css" />
23+
<script src="/build/bolt-global.js"></script>
8524
</head>
8625
<body>
8726
<!-- set #root to inline-block so VRT screenshots are only as wide as the component vs are always full width -->
@@ -110,7 +49,6 @@ getConfig().then(async boltConfig => {
11049
});
11150

11251
app.redirect;
113-
11452
// handle cleaning up + shutting down the server instance
11553
process.on('SIGTERM', shutDownSSRServer);
11654
process.on('SIGINT', shutDownSSRServer);

0 commit comments

Comments
 (0)