Skip to content

Commit 4462983

Browse files
authored
test(config): simplify shared config normalization and type fixtures (#545)
1 parent 437e2da commit 4462983

2 files changed

Lines changed: 28 additions & 66 deletions

File tree

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,33 @@
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 = {
9-
extends: [{ fmt: { singleQuote: true } }],
7+
const config = normalizeRstackConfig({
8+
extends: [
9+
{
10+
fmt: { singleQuote: true },
11+
},
12+
],
1013
app,
11-
staged,
12-
};
14+
lint: [],
15+
});
1316

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

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]),
21+
test('wraps lint factories lazily with tool exports', async () => {
22+
const lint = rs.fn((lint: typeof import('@rslint/core')) =>
23+
Promise.resolve([lint.js.configs.recommended]),
2624
);
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);
25+
const config = normalizeRstackConfig({ lint });
3726

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

41-
expect(resolved).toEqual([
42-
[],
29+
const { js } = await import('@rslint/core');
30+
expect(await resolveConfigLayers([config], 'lint')).toEqual([
4331
[js.configs.recommended],
44-
[ts.configs.recommended],
4532
]);
4633
});

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

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,20 @@ export const baseConfig: RstackConfig = {
1616
staged: { '*.ts': 'rs lint' },
1717
};
1818

19-
export const syncConfig: RstackConfig = {
20-
extends: [baseConfig] as const,
21-
app: ({ command }) => ({
22-
source: {
23-
define: { COMMAND: JSON.stringify(command) },
24-
},
25-
}),
26-
lib: ({ env }) => ({
27-
lib: [{ format: 'esm' }],
28-
mode: env === 'production' ? 'production' : 'development',
29-
}),
30-
test: () => ({ retry: 1 }),
31-
lint: ({ js, ts }) => [js.configs.recommended, ts.configs.recommended],
32-
fmt: () => ({ singleQuote: true }),
33-
staged: (files) => (files.length ? ['rs lint'] : []),
34-
};
35-
36-
export const asyncConfig: RstackConfig = {
37-
app: ({ env }) =>
38-
Promise.resolve({
39-
source: {
40-
define: { ENV: JSON.stringify(env) },
41-
},
42-
}),
43-
lib: () =>
44-
Promise.resolve({
45-
lib: [{ format: 'esm' }],
46-
}),
47-
doc: () => Promise.resolve({ title: 'Docs' }),
48-
test: () => Promise.resolve({ retry: 2 }),
49-
lint: ({ js }) => Promise.resolve([js.configs.recommended]),
50-
fmt: () => Promise.resolve({ singleQuote: true }),
51-
staged: (files) => Promise.resolve(files.length ? ['rs fmt'] : []),
52-
};
53-
5419
export function sharedConfig(options: { retry?: number } = {}): RstackConfig {
5520
return {
56-
extends: [syncConfig, asyncConfig],
21+
extends: [
22+
baseConfig,
23+
{ lint: ({ js }) => Promise.resolve([js.configs.recommended]) },
24+
] as const,
5725
test: { retry: options.retry ?? 2 },
26+
app: ({ command }) => ({
27+
source: {
28+
define: { COMMAND: JSON.stringify(command) },
29+
},
30+
}),
31+
lint: ({ js, ts }) => [js.configs.recommended, ts.configs.recommended],
32+
staged: (files) => (files.length ? ['rs lint'] : []),
5833
};
5934
}
6035

0 commit comments

Comments
 (0)