diff --git a/packages/rstack/tests/config/normalize.test.ts b/packages/rstack/tests/config/normalize.test.ts index 50ab40c6..4251a879 100644 --- a/packages/rstack/tests/config/normalize.test.ts +++ b/packages/rstack/tests/config/normalize.test.ts @@ -1,46 +1,33 @@ 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 = { - extends: [{ fmt: { singleQuote: true } }], + 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 894e12a9..faf0cb4b 100644 --- a/packages/rstack/tests/types/shared-config/index.ts +++ b/packages/rstack/tests/types/shared-config/index.ts @@ -16,45 +16,20 @@ 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'] : []), }; }