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
2 changes: 2 additions & 0 deletions .changeset/wide-streets-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ jobs:
--outputFile=test-report.junit.xml
--test-timeout=50000
--coverage
--coverage.reporter='json'
--coverage.reporter='text'
--no-cache
--logHeapUsage
--silent
Expand All @@ -85,6 +87,8 @@ jobs:
--reporter=dot
--reporter=junit
--outputFile=test-report.junit.xml
--coverage.reporter='json'
--coverage.reporter='text'
--test-timeout=50000
--no-cache
--logHeapUsage
Expand All @@ -104,6 +108,8 @@ jobs:
--reporter=junit
--outputFile=test-report.junit.xml
--coverage
--coverage.reporter='json'
--coverage.reporter='text'
--no-cache
--logHeapUsage
--silent
Expand All @@ -122,6 +128,8 @@ jobs:
--reporter=junit
--outputFile=test-report.junit.xml
--coverage
--coverage.reporter='json'
--coverage.reporter='text'
--no-cache
--logHeapUsage
--silent
Expand Down
4 changes: 4 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ coverage:
fixes:
- "/home/runner/_work/lynx-stack::"

parsers:
javascript:
enable_partials: yes

comment:
layout: "header, diff, flags, components" # show component info in the PR comment
behavior: default
Expand Down
42 changes: 29 additions & 13 deletions packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import { logger } from '@rsbuild/core'
import { logger, mergeRsbuildConfig } from '@rsbuild/core'
import type { RsbuildPlugin } from '@rsbuild/core'

import type { Tools } from '../config/tools/index.js'
import type {
RsdoctorRspackPluginOptions,
Tools,
} from '../config/tools/index.js'
import { isCI } from '../utils/is-ci.js'

export function pluginRsdoctor(
Expand Down Expand Up @@ -38,18 +41,31 @@
}

config.plugins ??= []
config.plugins.push(
new RsdoctorRspackPlugin({
// We disable client server on CI by default.
// But it can be overridden by `tools.rsdoctor`.
disableClientServer: isCI(),

...options,
supports: {
...options?.supports,
banner: true, // We must enable `supports.banner` since we have runtime wrapper enabled

const defaultOptions: RsdoctorRspackPluginOptions = {
// We disable client server on CI by default.
// But it can be overridden by `tools.rsdoctor`.
disableClientServer: isCI(),

supports: {
banner: true, // We must enable `supports.banner` since we have runtime wrapper enabled
},

Check warning on line 52 in packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts

View check run for this annotation

Codecov / codecov/patch

packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts#L52

Added line #L52 was not covered by tests

linter: {
rules: {
'ecma-version-check':
options?.linter?.rules?.['ecma-version-check'] ?? [
'Warn',
{ ecmaVersion: 2019 },
],

Check warning on line 60 in packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts

View check run for this annotation

Codecov / codecov/patch

packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts#L60

Added line #L60 was not covered by tests
},
}),
},
}

Check warning on line 63 in packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts

View check run for this annotation

Codecov / codecov/patch

packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts#L62-L63

Added lines #L62 - L63 were not covered by tests

config.plugins.push(
new RsdoctorRspackPlugin(
mergeRsbuildConfig(defaultOptions, options),
),
)
}
logger.info(`Rsdoctor is enabled.`)
Expand Down
136 changes: 136 additions & 0 deletions packages/rspeedy/core/test/plugins/rsdoctor.plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import type { Rspack } from '@rsbuild/core'
import type { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin'
import { describe, expect, test, vi } from 'vitest'

describe('Plugins - Rsdoctor', () => {
test('defaults', async () => {
vi.stubEnv('RSDOCTOR', 'true')

const { createStubRspeedy } = await import('../createStubRspeedy.js')

const rsbuild = await createStubRspeedy({})

const compiler = await rsbuild.createCompiler<Rspack.Compiler>()

const { options } = compiler.options.plugins.find(
(plugin) => (typeof plugin === 'object'
&& plugin?.['isRsdoctorPlugin'] === true),
) as RsdoctorRspackPlugin<[]>

expect(options.linter.rules).toEqual({
'ecma-version-check': [
'Warn',
{ ecmaVersion: 2019 },
],
})

expect(options.supports.banner).toBe(true)
})

test('linter.rules.ecma-version-check', async () => {
vi.stubEnv('RSDOCTOR', 'true')

const { createStubRspeedy } = await import('../createStubRspeedy.js')

const rsbuild = await createStubRspeedy({
tools: {
rsdoctor: {
linter: {
rules: {
'ecma-version-check': ['Error', { ecmaVersion: 2019 }],
},
},
},
},
})

const compiler = await rsbuild.createCompiler<Rspack.Compiler>()

const { options } = compiler.options.plugins.find(
(plugin) => (typeof plugin === 'object'
&& plugin?.['isRsdoctorPlugin'] === true),
) as RsdoctorRspackPlugin<[]>

expect(options.linter.rules).toEqual({
'ecma-version-check': [
'Error',
{ ecmaVersion: 2019 },
// We are using `mergeRsbuildConfig` to merge Rsdoctor options.
// So the options of linter.rules will come twice :)
// But it should just work.
'Error',
{ ecmaVersion: 2019 },
],
})
})

test('linter.rules.cross-chunks-package', async () => {
vi.stubEnv('RSDOCTOR', 'true')

const { createStubRspeedy } = await import('../createStubRspeedy.js')

const rsbuild = await createStubRspeedy({
tools: {
rsdoctor: {
linter: {
rules: {
'cross-chunks-package': [
'Error',
{
ignore: ['react'],
},
],
},
},
},
},
})

const compiler = await rsbuild.createCompiler<Rspack.Compiler>()

const { options } = compiler.options.plugins.find(
(plugin) => (typeof plugin === 'object'
&& plugin?.['isRsdoctorPlugin'] === true),
) as RsdoctorRspackPlugin<[]>

expect(options.linter.rules).toEqual({
'cross-chunks-package': [
'Error',
{ ignore: ['react'] },
],
'ecma-version-check': [
'Warn',
{ ecmaVersion: 2019 },
],
})
})

test('supports.banner', async () => {
vi.stubEnv('RSDOCTOR', 'true')

const { createStubRspeedy } = await import('../createStubRspeedy.js')

const rsbuild = await createStubRspeedy({
tools: {
rsdoctor: {
supports: {
banner: false,
},
},
},
})

const compiler = await rsbuild.createCompiler<Rspack.Compiler>()

const { options } = compiler.options.plugins.find(
(plugin) => (typeof plugin === 'object'
&& plugin?.['isRsdoctorPlugin'] === true),
) as RsdoctorRspackPlugin<[]>

expect(options.supports.banner).toBe(false)
})
})