From 680a363416199a792cbc21c3ced93afc32f01a0c Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 8 Oct 2026 18:43:14 +0800 Subject: [PATCH 1/2] test(config): simplify shared config normalization and type fixtures --- .../rstack/tests/config/normalize.test.ts | 41 ++++++------------- .../rstack/tests/types/shared-config/index.ts | 38 ++++------------- 2 files changed, 21 insertions(+), 58 deletions(-) diff --git a/packages/rstack/tests/config/normalize.test.ts b/packages/rstack/tests/config/normalize.test.ts index 50ab40c6..f8831a6b 100644 --- a/packages/rstack/tests/config/normalize.test.ts +++ b/packages/rstack/tests/config/normalize.test.ts @@ -1,46 +1,29 @@ import { expect, rs, test } from 'rstack/test'; -import { normalizeRstackConfig, type RstackConfig } from '../../src/config.ts'; +import { normalizeRstackConfig } from '../../src/config.ts'; import { resolveConfigLayers } from '../../src/configLayers.ts'; test('preserves tool definitions without resolving factories or inheritance', () => { const app = rs.fn(() => ({})); - const staged = rs.fn(() => ['rs lint']); - const shared: RstackConfig = { + const config = normalizeRstackConfig({ extends: [{ fmt: { singleQuote: true } }], app, - staged, - }; + lint: [], + }); - expect(normalizeRstackConfig(shared)).toEqual({ app, staged }); - expect(shared.extends).toEqual([{ fmt: { singleQuote: true } }]); + expect(config).toEqual({ app, lint: [] }); expect(app).not.toHaveBeenCalled(); - expect(staged).not.toHaveBeenCalled(); }); -test('resolves sync and async lint factories lazily with tool exports', async () => { - const syncLint = rs.fn((lint: typeof import('@rslint/core')) => [ - lint.js.configs.recommended, - ]); - const asyncLint = rs.fn((lint: typeof import('@rslint/core')) => - Promise.resolve([lint.ts.configs.recommended]), +test('wraps lint factories lazily with tool exports', async () => { + const lint = rs.fn((lint: typeof import('@rslint/core')) => + Promise.resolve([lint.js.configs.recommended]), ); - const shared: RstackConfig[] = [ - { lint: [] }, - { lint: syncLint }, - { lint: asyncLint }, - ]; - const configs = shared.map(normalizeRstackConfig); - - expect(syncLint).not.toHaveBeenCalled(); - expect(asyncLint).not.toHaveBeenCalled(); - expect(shared[1].lint).toBe(syncLint); + const config = normalizeRstackConfig({ lint }); - const resolved = await resolveConfigLayers(configs, 'lint'); - const { js, ts } = await import('@rslint/core'); + expect(lint).not.toHaveBeenCalled(); - expect(resolved).toEqual([ - [], + const { js } = await import('@rslint/core'); + expect(await resolveConfigLayers([config], 'lint')).toEqual([ [js.configs.recommended], - [ts.configs.recommended], ]); }); diff --git a/packages/rstack/tests/types/shared-config/index.ts b/packages/rstack/tests/types/shared-config/index.ts index fa9e5535..425df931 100644 --- a/packages/rstack/tests/types/shared-config/index.ts +++ b/packages/rstack/tests/types/shared-config/index.ts @@ -10,38 +10,18 @@ export const baseConfig: RstackConfig = { staged: { '*.ts': 'rs lint' }, }; -export const syncConfig: RstackConfig = { - extends: [baseConfig] as const, - app: ({ command }) => ({ - source: { define: { COMMAND: JSON.stringify(command) } }, - }), - lib: ({ env }) => ({ - lib: [{ format: 'esm' }], - mode: env === 'production' ? 'production' : 'development', - }), - test: () => ({ retry: 1 }), - lint: ({ js, ts }) => [js.configs.recommended, ts.configs.recommended], - fmt: () => ({ singleQuote: true }), - staged: (files) => (files.length ? ['rs lint'] : []), -}; - -export const asyncConfig: RstackConfig = { - app: ({ env }) => - Promise.resolve({ - source: { define: { ENV: JSON.stringify(env) } }, - }), - lib: () => Promise.resolve({ lib: [{ format: 'esm' }] }), - doc: () => Promise.resolve({ title: 'Docs' }), - test: () => Promise.resolve({ retry: 2 }), - lint: ({ js }) => Promise.resolve([js.configs.recommended]), - fmt: () => Promise.resolve({ singleQuote: true }), - staged: (files) => Promise.resolve(files.length ? ['rs fmt'] : []), -}; - export function sharedConfig(options: { retry?: number } = {}): RstackConfig { return { - extends: [syncConfig, asyncConfig], + extends: [ + baseConfig, + { lint: ({ js }) => Promise.resolve([js.configs.recommended]) }, + ] as const, test: { retry: options.retry ?? 2 }, + app: ({ command }) => ({ + source: { define: { COMMAND: JSON.stringify(command) } }, + }), + lint: ({ js, ts }) => [js.configs.recommended, ts.configs.recommended], + staged: (files) => (files.length ? ['rs lint'] : []), }; } From 5e02a317354665be80dc411db1697417be4225fc Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 8 Oct 2026 20:58:24 +0800 Subject: [PATCH 2/2] test(config): expand nested shared config fixtures --- packages/rstack/tests/config/normalize.test.ts | 6 +++++- packages/rstack/tests/types/shared-config/index.ts | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/rstack/tests/config/normalize.test.ts b/packages/rstack/tests/config/normalize.test.ts index f8831a6b..4251a879 100644 --- a/packages/rstack/tests/config/normalize.test.ts +++ b/packages/rstack/tests/config/normalize.test.ts @@ -5,7 +5,11 @@ import { resolveConfigLayers } from '../../src/configLayers.ts'; test('preserves tool definitions without resolving factories or inheritance', () => { const app = rs.fn(() => ({})); const config = normalizeRstackConfig({ - extends: [{ fmt: { singleQuote: true } }], + extends: [ + { + fmt: { singleQuote: true }, + }, + ], app, lint: [], }); diff --git a/packages/rstack/tests/types/shared-config/index.ts b/packages/rstack/tests/types/shared-config/index.ts index 425df931..45b7fe6c 100644 --- a/packages/rstack/tests/types/shared-config/index.ts +++ b/packages/rstack/tests/types/shared-config/index.ts @@ -1,8 +1,14 @@ import type { RstackConfig } from '../../../src/config.ts'; export const baseConfig: RstackConfig = { - app: { source: { entry: { index: './src/index.ts' } } }, - lib: { lib: [{ format: 'esm' }] }, + app: { + source: { + entry: { index: './src/index.ts' }, + }, + }, + lib: { + lib: [{ format: 'esm' }], + }, doc: { title: 'Docs' }, test: { retry: 2 }, lint: [], @@ -18,7 +24,9 @@ export function sharedConfig(options: { retry?: number } = {}): RstackConfig { ] as const, test: { retry: options.retry ?? 2 }, app: ({ command }) => ({ - source: { define: { COMMAND: JSON.stringify(command) } }, + source: { + define: { COMMAND: JSON.stringify(command) }, + }, }), lint: ({ js, ts }) => [js.configs.recommended, ts.configs.recommended], staged: (files) => (files.length ? ['rs lint'] : []),