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
47 changes: 17 additions & 30 deletions packages/rstack/tests/config/normalize.test.ts
Original file line number Diff line number Diff line change
@@ -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],
]);
});
47 changes: 11 additions & 36 deletions packages/rstack/tests/types/shared-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : []),
};
}

Expand Down
Loading