Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changeset/free-kids-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

---
63 changes: 62 additions & 1 deletion packages/rspeedy/plugin-react/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { describe, expect, test, vi } from 'vitest'

import type { ReactWebpackPlugin } from '@lynx-js/react-webpack-plugin'
import { createRspeedy } from '@lynx-js/rspeedy'
import type { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin'
import type {
LynxEncodePlugin,
LynxTemplatePlugin,
} from '@lynx-js/template-webpack-plugin'

import { pluginStubRspeedyAPI } from './stub-rspeedy-api.plugin.js'

Expand Down Expand Up @@ -538,6 +541,64 @@ describe('Config', () => {
expect(encodePlugin).toHaveProperty('options', { inlineScripts: false })
})

test('output.inlineScripts: function', async () => {
const { pluginReactLynx } = await import('../src/pluginReactLynx.js')

const rsbuild = await createRspeedy({
rspeedyConfig: {
output: {
inlineScripts: ({ name, size }) => {
return name.includes('background') && size > 1000
},
},
source: {
entry: {
foo: {
import: ['./foo/index.jsx', './common.js'],
},
bar: './bar/index.jsx',
},
},
plugins: [
pluginReactLynx(),
pluginStubRspeedyAPI(),
],
},
})

const [config] = await rsbuild.initConfigs()

const LynxEncodePlugin = config?.plugins?.find((
p,
): p is LynxEncodePlugin => p?.constructor.name === 'LynxEncodePlugin')

expect(LynxEncodePlugin).toBeDefined()

// @ts-expect-error private field
const { inlineScripts } = LynxEncodePlugin?.options ?? {}

expect(typeof inlineScripts).toBe('function')
// eslint-disable-next-line @typescript-eslint/no-base-to-string
expect(inlineScripts?.toString()).toMatchInlineSnapshot(`
"({ name, size }) => {
return name.includes("background") && size > 1e3;
}"
`)

const ReactWebpackPlugin = config?.plugins?.find((
p,
): p is ReactWebpackPlugin =>
p?.constructor.name === 'ReactWebpackPlugin'
)

expect(ReactWebpackPlugin).toBeDefined()

// @ts-expect-error private field
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { firstScreenSyncTiming } = ReactWebpackPlugin?.options ?? {}
expect(firstScreenSyncTiming).toBe('jsReady')
})

test('environments.lynx.output.inlineScripts: false', async () => {
const { pluginReactLynx } = await import('../src/pluginReactLynx.js')
const rsbuild = await createRspeedy({
Expand Down
Loading