Skip to content

Commit 680a363

Browse files
committed
test(config): simplify shared config normalization and type fixtures
1 parent 690c744 commit 680a363

2 files changed

Lines changed: 21 additions & 58 deletions

File tree

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,29 @@
11
import { expect, rs, test } from 'rstack/test';
2-
import { normalizeRstackConfig, type RstackConfig } from '../../src/config.ts';
2+
import { normalizeRstackConfig } from '../../src/config.ts';
33
import { resolveConfigLayers } from '../../src/configLayers.ts';
44

55
test('preserves tool definitions without resolving factories or inheritance', () => {
66
const app = rs.fn(() => ({}));
7-
const staged = rs.fn(() => ['rs lint']);
8-
const shared: RstackConfig = {
7+
const config = normalizeRstackConfig({
98
extends: [{ fmt: { singleQuote: true } }],
109
app,
11-
staged,
12-
};
10+
lint: [],
11+
});
1312

14-
expect(normalizeRstackConfig(shared)).toEqual({ app, staged });
15-
expect(shared.extends).toEqual([{ fmt: { singleQuote: true } }]);
13+
expect(config).toEqual({ app, lint: [] });
1614
expect(app).not.toHaveBeenCalled();
17-
expect(staged).not.toHaveBeenCalled();
1815
});
1916

20-
test('resolves sync and async lint factories lazily with tool exports', async () => {
21-
const syncLint = rs.fn((lint: typeof import('@rslint/core')) => [
22-
lint.js.configs.recommended,
23-
]);
24-
const asyncLint = rs.fn((lint: typeof import('@rslint/core')) =>
25-
Promise.resolve([lint.ts.configs.recommended]),
17+
test('wraps lint factories lazily with tool exports', async () => {
18+
const lint = rs.fn((lint: typeof import('@rslint/core')) =>
19+
Promise.resolve([lint.js.configs.recommended]),
2620
);
27-
const shared: RstackConfig[] = [
28-
{ lint: [] },
29-
{ lint: syncLint },
30-
{ lint: asyncLint },
31-
];
32-
const configs = shared.map(normalizeRstackConfig);
33-
34-
expect(syncLint).not.toHaveBeenCalled();
35-
expect(asyncLint).not.toHaveBeenCalled();
36-
expect(shared[1].lint).toBe(syncLint);
21+
const config = normalizeRstackConfig({ lint });
3722

38-
const resolved = await resolveConfigLayers(configs, 'lint');
39-
const { js, ts } = await import('@rslint/core');
23+
expect(lint).not.toHaveBeenCalled();
4024

41-
expect(resolved).toEqual([
42-
[],
25+
const { js } = await import('@rslint/core');
26+
expect(await resolveConfigLayers([config], 'lint')).toEqual([
4327
[js.configs.recommended],
44-
[ts.configs.recommended],
4528
]);
4629
});

‎packages/rstack/tests/types/shared-config/index.ts‎

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,18 @@ export const baseConfig: RstackConfig = {
1010
staged: { '*.ts': 'rs lint' },
1111
};
1212

13-
export const syncConfig: RstackConfig = {
14-
extends: [baseConfig] as const,
15-
app: ({ command }) => ({
16-
source: { define: { COMMAND: JSON.stringify(command) } },
17-
}),
18-
lib: ({ env }) => ({
19-
lib: [{ format: 'esm' }],
20-
mode: env === 'production' ? 'production' : 'development',
21-
}),
22-
test: () => ({ retry: 1 }),
23-
lint: ({ js, ts }) => [js.configs.recommended, ts.configs.recommended],
24-
fmt: () => ({ singleQuote: true }),
25-
staged: (files) => (files.length ? ['rs lint'] : []),
26-
};
27-
28-
export const asyncConfig: RstackConfig = {
29-
app: ({ env }) =>
30-
Promise.resolve({
31-
source: { define: { ENV: JSON.stringify(env) } },
32-
}),
33-
lib: () => Promise.resolve({ lib: [{ format: 'esm' }] }),
34-
doc: () => Promise.resolve({ title: 'Docs' }),
35-
test: () => Promise.resolve({ retry: 2 }),
36-
lint: ({ js }) => Promise.resolve([js.configs.recommended]),
37-
fmt: () => Promise.resolve({ singleQuote: true }),
38-
staged: (files) => Promise.resolve(files.length ? ['rs fmt'] : []),
39-
};
40-
4113
export function sharedConfig(options: { retry?: number } = {}): RstackConfig {
4214
return {
43-
extends: [syncConfig, asyncConfig],
15+
extends: [
16+
baseConfig,
17+
{ lint: ({ js }) => Promise.resolve([js.configs.recommended]) },
18+
] as const,
4419
test: { retry: options.retry ?? 2 },
20+
app: ({ command }) => ({
21+
source: { define: { COMMAND: JSON.stringify(command) } },
22+
}),
23+
lint: ({ js, ts }) => [js.configs.recommended, ts.configs.recommended],
24+
staged: (files) => (files.length ? ['rs lint'] : []),
4525
};
4626
}
4727

0 commit comments

Comments
 (0)