Skip to content

Commit dec6419

Browse files
committed
Restore beta error wording in cli-*.test.ts; restructure mssql validator
Tests - cli-{check,export,generate,migrate,pull,push,studio}.test.ts: assertion text for every `validate config #N` case now matches beta's exact wording byte-for-byte, constructed via the same error() / wrapParam() helpers the runtime uses. The mechanism is res.error.message (not console.log spy + process.exit) because the cli path throws DrizzleCliError; the literal text it asserts is identical to beta. - cli-studio.test.ts #5/#6: prepareStudioConfig is still in the legacy humanLog + process.exit path, so those tests keep beta's spy mechanism unchanged; the only deviation is stripAnsi() on captured calls because withStyle.error wraps the message with chalk codes. Runtime - validations/common.ts: configCommonSchema.dialect is now optional. The early MissingConfigDialectCliError throw in drizzleConfigFromFile is gone so each prepare* helper owns the dialect-missing wording (mirrors beta). - commands/utils.ts: - prepareCheckParams: wrapParam('dialect', config.dialect) was being passed the imported zod schema; pass the actual config value. - prepareGenerateConfig + prepareExportConfig: reorder RequiredParamsCliError builders to dialect-first / schema-second; drop the wrapParam('out',...) line from generate so the message matches beta exactly. - drizzleConfigFromFile: removed the chalk.grey wrap around "Reading config file" so spy assertions can compare against plain text (matches beta). - validations/mssql.ts: rewrote printConfigConnectionIssues to match the postgres.ts shape — url branch, server-form branch, generic fallthrough with "Either connection \"url\" or \"server\", \"user\", \"password\" are required for MsSQL database connection". The previous form duplicated the same "Please provide required params for MsSQL driver:" header on both branches and had no fallthrough. Verified - pnpm tsc --noEmit -p tsconfig.json + tsconfig.typetest.json both clean - TEST_CONFIG_PATH_PREFIX=./tests/cli/ vitest run tests/other/ → 376/376 pass
1 parent fe92e22 commit dec6419

9 files changed

Lines changed: 62 additions & 33 deletions

File tree

drizzle-kit/src/cli/commands/utils.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
ConfigValidationCliError,
1313
MigrationSnapshotNotFoundCliError,
1414
MigrationSqlFilesConflictCliError,
15-
MissingConfigDialectCliError,
1615
MissingDialectCliError,
1716
RequiredParamsCliError,
1817
UnsupportedCommandCliError,
@@ -60,7 +59,9 @@ export const prepareCheckParams = async (
6059
: options;
6160

6261
if (!config.dialect) {
63-
throw new MissingDialectCliError(`${error('Please provide required params:')}\n${wrapParam('dialect', dialect)}`);
62+
throw new MissingDialectCliError(
63+
[error('Please provide required params:'), wrapParam('dialect', config.dialect)].join('\n'),
64+
);
6465
}
6566
return { out: config.out || 'drizzle', dialect: config.dialect };
6667
};
@@ -127,12 +128,11 @@ export const prepareGenerateConfig = async (
127128

128129
if (!schema || !dialect) {
129130
throw new RequiredParamsCliError(
130-
['schema', 'dialect'],
131+
['dialect', 'schema'],
131132
[
132133
error('Please provide required params:'),
133-
wrapParam('schema', schema),
134134
wrapParam('dialect', dialect),
135-
wrapParam('out', out, true),
135+
wrapParam('schema', schema),
136136
].join('\n'),
137137
);
138138
}
@@ -172,11 +172,11 @@ export const prepareExportConfig = async (
172172

173173
if (!schema || !dialect) {
174174
throw new RequiredParamsCliError(
175-
['schema', 'dialect'],
175+
['dialect', 'schema'],
176176
[
177177
error('Please provide required params:'),
178-
wrapParam('schema', schema),
179178
wrapParam('dialect', dialect),
179+
wrapParam('schema', schema),
180180
].join('\n'),
181181
);
182182
}
@@ -943,16 +943,13 @@ export const drizzleConfigFromFile = async (
943943
throw new ConfigFileNotFoundCliError(path);
944944
}
945945

946-
if (!isExport) humanLog(chalk.grey(`Reading config file '${path}'`));
946+
if (!isExport) humanLog(`Reading config file '${path}'`);
947947

948948
const content = await loadModule<any>(path);
949949

950950
// --- get response and then check by each dialect independently
951951
const res = configCommonSchema.safeParse(content);
952952
if (!res.success) {
953-
if (!('dialect' in content)) {
954-
throw new MissingConfigDialectCliError();
955-
}
956953
throw new ConfigValidationCliError(inspect(res.error), res.error.issues as never, { cause: res.error });
957954
}
958955

drizzle-kit/src/cli/validations/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export type EntitiesFilterConfig = {
122122
};
123123

124124
export const configCommonSchema = object({
125-
dialect: dialect,
125+
dialect: dialect.optional(),
126126
out: string().default('drizzle'),
127127
breakpoints: boolean().optional().default(true),
128128
verbose: boolean().optional().default(false),

drizzle-kit/src/cli/validations/mssql.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,27 @@ export const printConfigConnectionIssues = (
2727
options: Record<string, unknown>,
2828
_command?: 'generate' | 'migrate' | 'push' | 'pull' | 'studio',
2929
): never => {
30+
if ('url' in options) {
31+
let text = `Please provide required params for MsSQL driver:\n`;
32+
throw new ConfigConnectionCliError(
33+
'mssql',
34+
['url'],
35+
[
36+
error(text),
37+
wrapParam('url', options.url, false, 'url'),
38+
].join('\n'),
39+
_command,
40+
);
41+
}
42+
3043
if (
31-
'port' in options || 'user' in options || 'password' in options || 'database' in options || 'server' in options
44+
'server' in options || 'database' in options || 'port' in options || 'user' in options || 'password' in options
3245
|| 'options' in options
3346
) {
3447
let text = `Please provide required params for MsSQL driver:\n`;
3548
throw new ConfigConnectionCliError(
3649
'mssql',
37-
['server', 'port', 'user', 'password', 'database'],
50+
['server', 'user', 'password', 'database'],
3851
[
3952
error(text),
4053
wrapParam('server', options.server),
@@ -48,14 +61,10 @@ export const printConfigConnectionIssues = (
4861
);
4962
}
5063

51-
let text = `Please provide required params for MsSQL driver:\n`;
5264
throw new ConfigConnectionCliError(
5365
'mssql',
54-
['url'],
55-
[
56-
error(text),
57-
wrapParam('url', options.url, false, 'url'),
58-
].join('\n'),
66+
['url', 'server', 'database'],
67+
error(`Either connection "url" or "server", "user", "password" are required for MsSQL database connection`),
5968
_command,
6069
);
6170
};

drizzle-kit/tests/other/cli-check.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ test('validate config #4', async (t) => {
7878

7979
expect(res.type).toBe('error');
8080
if (res.type !== 'error') return;
81-
expect((res.error as Error).message).toBe(error("Please specify 'dialect' param in config file"));
81+
expect((res.error as Error).message).toBe(
82+
[error('Please provide required params:'), wrapParam('dialect', undefined)].join('\n'),
83+
);
8284
});
8385

8486
test('validate config #5', async (t) => {

drizzle-kit/tests/other/cli-export.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ test('validate config #3', async (t) => {
149149
expect((res.error as Error).message).toBe(
150150
[
151151
error('Please provide required params:'),
152-
wrapParam('schema', undefined),
153152
wrapParam('dialect', 'postgresql'),
153+
wrapParam('schema', undefined),
154154
].join('\n'),
155155
);
156156
});
@@ -168,5 +168,11 @@ test('validate config #4', async (t) => {
168168

169169
expect(res.type).toBe('error');
170170
if (res.type !== 'error') return;
171-
expect((res.error as Error).message).toBe(error("Please specify 'dialect' param in config file"));
171+
expect((res.error as Error).message).toBe(
172+
[
173+
error('Please provide required params:'),
174+
wrapParam('dialect', undefined),
175+
wrapParam('schema', 'schema.ts'),
176+
].join('\n'),
177+
);
172178
});

drizzle-kit/tests/other/cli-generate.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,8 @@ test('validate config #3', async (t) => {
443443
expect((res.error as Error).message).toBe(
444444
[
445445
error('Please provide required params:'),
446-
wrapParam('schema', undefined),
447446
wrapParam('dialect', 'postgresql'),
448-
wrapParam('out', 'test', true),
447+
wrapParam('schema', undefined),
449448
].join('\n'),
450449
);
451450
});
@@ -461,7 +460,6 @@ test('validate config #4', async (t) => {
461460

462461
unlinkSync(path);
463462

464-
// wrong dialect data type → ConfigValidationCliError
465463
expect(res.type).toBe('error');
466464
if (res.type !== 'error') return;
467465
expect((res.error as Error).name).toBe('ConfigValidationCliError');

drizzle-kit/tests/other/cli-migrate.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,7 @@ test('validate config #3', async (t) => {
235235

236236
expect(res.type).toBe('error');
237237
if (res.type !== 'error') return;
238-
expect((res.error as Error).message).toBe(error("Please specify 'dialect' param in config file"));
238+
expect((res.error as Error).message).toBe(
239+
[error('Please provide required params:'), wrapParam('dialect', undefined)].join('\n'),
240+
);
239241
});

drizzle-kit/tests/other/cli-pull.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ test('validate config #5', async (t) => {
364364

365365
expect(res.type).toBe('error');
366366
if (res.type !== 'error') return;
367-
expect((res.error as Error).message).toBe(error("Please specify 'dialect' param in config file"));
367+
expect((res.error as Error).message).toBe(
368+
[error('Please provide required params:'), wrapParam('dialect', undefined)].join('\n'),
369+
);
368370
});
369371

370372
test('validate config #6', async (t) => {

drizzle-kit/tests/other/cli-studio.test.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { test as brotest } from '@drizzle-team/brocli';
2+
import { stripAnsi } from 'hanji/utils';
23
import { unlinkSync } from 'node:fs';
34
import { afterEach, assert, expect, test, vi } from 'vitest';
45
import { studio } from '../../src/cli/schema';
5-
import { error } from '../../src/cli/views';
66
import { createConfig } from './utils';
77

88
const originalPrefix = process.env.TEST_CONFIG_PATH_PREFIX;
@@ -188,8 +188,17 @@ test('validate config #5', async (t) => {
188188
unlinkSync(path);
189189

190190
expect(res.type).toBe('error');
191-
if (res.type !== 'error') return;
192-
expect((res.error as Error).message).toBe(error("Please specify 'dialect' param in config file"));
191+
192+
const calls = spy.mock.calls.map((c) => stripAnsi(String(c[0])));
193+
expect(calls[0]).toBe(`Reading config file '${path}'`);
194+
expect(calls[1]).toBe(
195+
` Invalid input Please specify 'dialect' param in config, either of 'postgresql', 'mysql', 'sqlite', turso or singlestore`,
196+
);
197+
198+
let error: any = res.type === 'error' ? res.error : undefined;
199+
expect(error).toBeDefined();
200+
expect(error).toBeInstanceOf(Error);
201+
expect(error.message).toBe('process.exit unexpectedly called with "1"');
193202

194203
spy.mockRestore();
195204
});
@@ -210,8 +219,12 @@ test('validate config #6', async (t) => {
210219
unlinkSync(path);
211220

212221
expect(res.type).toBe('error');
213-
const calls = spy.mock.calls.map((c) => String(c[0]));
214-
expect(calls.some((c) => c.includes(`Please specify a 'dbCredentials' param`))).toBe(true);
222+
223+
const calls = spy.mock.calls.map((c) => stripAnsi(String(c[0])));
224+
expect(calls[0]).toBe(`Reading config file '${path}'`);
225+
expect(calls[1]).toBe(
226+
` Invalid input Please specify a 'dbCredentials' param in config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`,
227+
);
215228

216229
let error: any = res.type === 'error' ? res.error : undefined;
217230
expect(error).toBeDefined();

0 commit comments

Comments
 (0)