diff --git a/.changeset/wide-streets-kick.md b/.changeset/wide-streets-kick.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/wide-streets-kick.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3c2057b49d..6ded96747f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,6 +66,8 @@ jobs: --outputFile=test-report.junit.xml --test-timeout=50000 --coverage + --coverage.reporter='json' + --coverage.reporter='text' --no-cache --logHeapUsage --silent @@ -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 @@ -104,6 +108,8 @@ jobs: --reporter=junit --outputFile=test-report.junit.xml --coverage + --coverage.reporter='json' + --coverage.reporter='text' --no-cache --logHeapUsage --silent @@ -122,6 +128,8 @@ jobs: --reporter=junit --outputFile=test-report.junit.xml --coverage + --coverage.reporter='json' + --coverage.reporter='text' --no-cache --logHeapUsage --silent diff --git a/codecov.yml b/codecov.yml index 4791f29515..54de1e2538 100644 --- a/codecov.yml +++ b/codecov.yml @@ -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 diff --git a/packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts b/packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts index 81626b5a49..a3c93a0325 100644 --- a/packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts +++ b/packages/rspeedy/core/src/plugins/rsdoctor.plugin.ts @@ -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( @@ -38,18 +41,31 @@ export function pluginRsdoctor( } 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 + }, + + linter: { + rules: { + 'ecma-version-check': + options?.linter?.rules?.['ecma-version-check'] ?? [ + 'Warn', + { ecmaVersion: 2019 }, + ], }, - }), + }, + } + + config.plugins.push( + new RsdoctorRspackPlugin( + mergeRsbuildConfig(defaultOptions, options), + ), ) } logger.info(`Rsdoctor is enabled.`) diff --git a/packages/rspeedy/core/test/plugins/rsdoctor.plugin.test.ts b/packages/rspeedy/core/test/plugins/rsdoctor.plugin.test.ts new file mode 100644 index 0000000000..5a22a49d51 --- /dev/null +++ b/packages/rspeedy/core/test/plugins/rsdoctor.plugin.test.ts @@ -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() + + 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() + + 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() + + 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() + + const { options } = compiler.options.plugins.find( + (plugin) => (typeof plugin === 'object' + && plugin?.['isRsdoctorPlugin'] === true), + ) as RsdoctorRspackPlugin<[]> + + expect(options.supports.banner).toBe(false) + }) +})