Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d73f8a3

Browse files
committedMar 21, 2025··
Test braid-design-system fixture with vite
1 parent 8597212 commit d73f8a3

20 files changed

+1219
-542
lines changed
 

‎.changeset/brown-paws-enter.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sku': patch
3+
---
4+
5+
Add support for root resolutio of `.jsx` and `.cjs` files

‎fixtures/braid-design-system/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@sku-fixtures/braid-design-system",
33
"private": true,
4+
"type": "module",
45
"dependencies": {
56
"braid-design-system": "^33.1.0",
67
"react": "^18.2.0",

‎fixtures/braid-design-system/sku.config.mjs ‎fixtures/braid-design-system/sku.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export default {
88
{ name: 'seekAnz', host: 'dev.seek.com.au' },
99
{ name: 'jobStreet', host: 'dev.jobstreet.com' },
1010
],
11+
clientEntry: 'src/client.jsx',
12+
renderEntry: 'src/render.jsx',
1113
publicPath: '/',
1214
port: 8200,
1315
dangerouslySetWebpackConfig: (config) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import baseConfig from './sku.config.js';
2+
3+
export default {
4+
...baseConfig,
5+
__UNSAFE_EXPERIMENTAL__bundler: 'vite',
6+
renderEntry: 'src/render-vite.jsx',
7+
};

‎fixtures/braid-design-system/src/App.css.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { style } from '@vanilla-extract/css';
2-
import { backgroundColor } from 'src/vars.css';
2+
3+
import { backgroundColor } from 'src/vars.css.ts';
34

45
export const vanillaBox = style({
56
vars: {

‎fixtures/braid-design-system/src/App.js ‎fixtures/braid-design-system/src/App.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'braid-design-system/reset';
2-
import { useState, useEffect } from 'react';
32
import {
43
BraidProvider,
54
Text,
@@ -9,8 +8,9 @@ import {
98
Box,
109
} from 'braid-design-system';
1110
import theme from 'braid-design-system/themes/seekJobs';
11+
import { useState, useEffect } from 'react';
1212

13-
import { vanillaBox } from './App.css';
13+
import { vanillaBox } from './App.css.ts';
1414

1515
const noop = () => {};
1616

@@ -39,7 +39,7 @@ function Stuff({ themeName }) {
3939
);
4040
}
4141

42-
export default function App({ themeName }) {
42+
export function App({ themeName }) {
4343
return (
4444
<BraidProvider theme={theme}>
4545
<Stuff themeName={themeName} />

‎fixtures/braid-design-system/src/client.js

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { hydrateRoot } from 'react-dom/client';
2+
3+
import { App } from './App.jsx';
4+
5+
export default ({ site, rootElementId }) =>
6+
hydrateRoot(document.getElementById(rootElementId), <App themeName={site} />);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { renderToPipeableStream } from 'react-dom/server';
2+
3+
import { App } from './App.jsx';
4+
5+
export default {
6+
render: async ({ options, site }) => {
7+
const appSite = typeof site === 'string' ? site : site?.name;
8+
9+
const result = renderToPipeableStream(<App themeName={appSite} />, options);
10+
11+
return result;
12+
},
13+
14+
provideClientContext: async ({ site }) => ({
15+
site: typeof site === 'string' ? site : site?.name,
16+
rootElementId: 'root',
17+
}),
18+
};

‎fixtures/braid-design-system/src/render.js ‎fixtures/braid-design-system/src/render.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { renderToString } from 'react-dom/server';
22

3-
import App from './App';
3+
import { App } from './App.jsx';
44

55
export default {
66
renderApp: ({ site, SkuProvider }) => {
@@ -13,6 +13,7 @@ export default {
1313

1414
provideClientContext: ({ site }) => ({
1515
site,
16+
rootElementId: 'app',
1617
}),
1718

1819
renderDocument: ({ app, headTags, bodyTags, site }) => `

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"lint:tsc:sku": "pnpm --filter 'sku' lint:tsc",
1414
"build": "pnpm --filter 'sku' build",
1515
"check": "pnpm install --frozen-lockfile && echo 'Ignore paths from lint-staged'",
16-
"test": "SKU_TELEMETRY=false SKU_DISABLE_CACHE=true NODE_OPTIONS='--experimental-vm-modules --disable-warning=ExperimentalWarning' OPEN_TAB=false jest --verbose",
16+
"test": "SKU_TELEMETRY=false SKU_DISABLE_CACHE=true NODE_OPTIONS='--experimental-vm-modules --disable-warning=ExperimentalWarning' OPEN_TAB=false jest --verbose braid-design-system",
1717
"test:sku-init": "SKU_TELEMETRY=false SKU_DISABLE_CACHE=true NODE_OPTIONS='--experimental-vm-modules --disable-warning=ExperimentalWarning' OPEN_TAB=false jest --verbose --config=jest.config.sku-init.js",
1818
"test:update": "pnpm run test -u && pnpm --filter @sku-fixtures/braid-design-system exec sku test -u",
1919
"setup-test-hosts": "node test-utils/setupTestHosts",

‎packages/sku/src/config/babel/babelConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default ({
3232
require.resolve('babel-plugin-module-resolver'),
3333
{
3434
root: rootResolution ? [cwd()] : undefined,
35-
extensions: ['.mjs', '.js', '.json', '.ts', '.tsx'],
35+
extensions: ['.js', '.jsx', '.mjs', '.cjs', '.json', '.ts', '.tsx'],
3636
},
3737
],
3838
require.resolve('babel-plugin-macros'),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const outDir = {
2+
client: 'dist',
3+
ssr: 'dist/server',
4+
ssg: 'dist/render',
5+
};
6+
7+
export const renderEntryChunkName = 'render.js';

‎packages/sku/src/services/vite/helpers/createConfig.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
88
import type { SkuContext } from '@/context/createSkuContext.js';
99
import skuVitePreloadPlugin from '../plugins/skuVitePreloadPlugin.js';
1010
import { fixViteVanillaExtractDepScanPlugin } from '@/services/vite/plugins/esbuild/fixViteVanillaExtractDepScanPlugin.js';
11+
import { outDir, renderEntryChunkName } from './bundleConfig.js';
1112

1213
const require = createRequire(import.meta.url);
1314

@@ -22,12 +23,6 @@ export const createViteConfig = ({
2223
configType?: 'client' | 'ssr' | 'ssg';
2324
plugins?: InlineConfig['plugins'];
2425
}) => {
25-
const outDir = {
26-
client: 'dist',
27-
ssr: 'dist/server',
28-
ssg: 'dist/render',
29-
};
30-
3126
const input = {
3227
client: clientEntry,
3328
ssr: skuContext.paths.serverEntry,
@@ -67,6 +62,8 @@ export const createViteConfig = ({
6762
rollupOptions: {
6863
input: input[configType],
6964
output: {
65+
entryFileNames:
66+
configType === 'ssg' ? renderEntryChunkName : undefined,
7067
experimentalMinChunkSize: undefined,
7168
},
7269
},

‎packages/sku/src/services/vite/helpers/prerenderRoutes.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getBuildRoutes } from '@/services/webpack/config/plugins/createHtmlRend
55
import { createPreRenderedHtml } from './html/createPreRenderedHtml.js';
66
import { createCollector } from '@/services/vite/loadable/collector.js';
77
import { ensureTargetDirectory } from '@/utils/buildFileUtils.js';
8+
import { outDir, renderEntryChunkName } from './bundleConfig.js';
89

910
const resolve = (p: string) => path.resolve(process.cwd(), p);
1011

@@ -14,7 +15,9 @@ export const prerenderRoutes = async (skuContext: SkuContext) => {
1415
await readFile(resolve('./dist/.vite/manifest.json'), 'utf-8'),
1516
);
1617
for (const route of routes) {
17-
const render = (await import(resolve('./dist/render/render.js'))).default;
18+
const render = (
19+
await import(resolve(path.join(outDir.ssg, renderEntryChunkName)))
20+
).default;
1821
const loadableCollector = createCollector({
1922
manifest,
2023
base: skuContext.publicPath.startsWith('/') ? '/' : '',

‎packages/sku/src/utils/contextUtils/hosts.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const setupHosts = async (skuContext: SkuContext) => {
2424
for (const host of appHosts) {
2525
if (host) {
2626
await setSystemHost('127.0.0.1', host);
27+
await setSystemHost('::1', host);
2728
console.log(
2829
`Successfully added '${chalk.bold(host)}' to your hosts file`,
2930
);

‎test-utils/setupTestHosts.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ const setSystemHost = promisify(set);
66

77
const hosts = ['dev.seek.com.au', 'dev.jobstreet.com'];
88

9-
(async () => {
10-
for (const host of hosts) {
11-
await setSystemHost('127.0.0.1', host);
12-
}
13-
})();
9+
for (const host of hosts) {
10+
await setSystemHost('127.0.0.1', host);
11+
}

‎test-utils/waitForUrls.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const waitForUrls = async (...urls) => {
1616
timeout,
1717
// Log output of wait behaviour timing to allow
1818
// increased debugging when service fails to start
19-
log: false,
19+
log: true,
2020
strictSSL: false,
2121
});
2222
} catch (error) {

‎tests/__snapshots__/braid-design-system.test.js.snap

+1,093-467
Large diffs are not rendered by default.

‎tests/braid-design-system.test.js

+59-49
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import {
66
runSkuScriptInDir,
77
} from '@sku-private/test-utils';
88

9-
import skuConfig from '@sku-fixtures/braid-design-system/sku.config.mjs';
9+
import skuConfig from '@sku-fixtures/braid-design-system/sku.config.js';
1010

1111
import { createRequire } from 'node:module';
1212

1313
const require = createRequire(import.meta.url);
1414

1515
const appDir = path.dirname(
16-
require.resolve('@sku-fixtures/braid-design-system/sku.config.mjs'),
16+
require.resolve('@sku-fixtures/braid-design-system/sku.config.js'),
1717
);
1818
const distDir = path.resolve(appDir, 'dist');
1919

@@ -24,55 +24,65 @@ function getLocalUrl(site) {
2424
}
2525

2626
describe('braid-design-system', () => {
27-
describe('start', () => {
28-
let server;
29-
30-
beforeAll(async () => {
31-
server = await runSkuScriptInDir('start', appDir);
32-
await waitForUrls(getLocalUrl('seekAnz'));
33-
}, 230000);
34-
35-
afterAll(async () => {
36-
await server.kill();
37-
});
38-
39-
it('should return development seekAnz site', async () => {
40-
const snapshot = await getAppSnapshot(getLocalUrl('seekAnz'));
41-
expect(snapshot).toMatchSnapshot();
42-
});
43-
44-
it('should return development jobStreet site', async () => {
45-
const snapshot = await getAppSnapshot(getLocalUrl('jobStreet'));
46-
expect(snapshot).toMatchSnapshot();
47-
});
48-
});
49-
50-
describe('build', () => {
51-
let process;
52-
53-
beforeAll(async () => {
54-
await runSkuScriptInDir('build', appDir);
55-
process = await runSkuScriptInDir('serve', appDir);
56-
await waitForUrls(getLocalUrl('seekAnz'));
57-
}, 230000);
58-
59-
afterAll(async () => {
60-
await process.kill();
61-
});
62-
63-
it('should return built jobStreet site', async () => {
64-
const app = await getAppSnapshot(getLocalUrl('jobStreet'));
65-
expect(app).toMatchSnapshot();
66-
});
67-
68-
it('should return built seekAnz site', async () => {
69-
const app = await getAppSnapshot(getLocalUrl('seekAnz'));
70-
expect(app).toMatchSnapshot();
27+
describe.each([
28+
'vite',
29+
// 'webpack'
30+
])('bundler %s', (bundler) => {
31+
const args =
32+
bundler === 'vite'
33+
? ['--config', 'sku.config.vite.js', '--experimental-bundler']
34+
: [];
35+
36+
describe('start', () => {
37+
let server;
38+
39+
beforeAll(async () => {
40+
server = await runSkuScriptInDir('start', appDir, args);
41+
await waitForUrls(getLocalUrl('seekAnz'));
42+
}, 230000);
43+
44+
afterAll(async () => {
45+
await server.kill();
46+
});
47+
48+
it('should return development seekAnz site', async () => {
49+
const snapshot = await getAppSnapshot(getLocalUrl('seekAnz'));
50+
expect(snapshot).toMatchSnapshot();
51+
});
52+
53+
it('should return development jobStreet site', async () => {
54+
const snapshot = await getAppSnapshot(getLocalUrl('jobStreet'));
55+
expect(snapshot).toMatchSnapshot();
56+
});
7157
});
7258

73-
it('should generate the expected files', async () => {
74-
const files = await dirContentsToObject(distDir);
75-
expect(files).toMatchSnapshot();
59+
describe('build', () => {
60+
let process;
61+
62+
beforeAll(async () => {
63+
await runSkuScriptInDir('build', appDir, args);
64+
process = await runSkuScriptInDir('serve', appDir, args);
65+
await waitForUrls(getLocalUrl('seekAnz'));
66+
}, 230000);
67+
68+
afterAll(async () => {
69+
await process.kill();
70+
});
71+
72+
it('should return built jobStreet site', async () => {
73+
const app = await getAppSnapshot(getLocalUrl('jobStreet'));
74+
expect(app).toMatchSnapshot();
75+
});
76+
77+
it('should return built seekAnz site', async () => {
78+
const app = await getAppSnapshot(getLocalUrl('seekAnz'));
79+
expect(app).toMatchSnapshot();
80+
});
81+
82+
it('should generate the expected files', async () => {
83+
const files = await dirContentsToObject(distDir);
84+
expect(files).toMatchSnapshot();
85+
});
7686
});
7787
});
7888

0 commit comments

Comments
 (0)
Please sign in to comment.