Skip to content

Commit

Permalink
test: fix test typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jan 28, 2024
1 parent f626df7 commit 921621e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
11 changes: 9 additions & 2 deletions @commitlint/config-validator/src/validate.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {validateConfig} from './validate';
import {RuleConfigSeverity, UserConfig} from '@commitlint/types';

import {validateConfig} from './validate.js';

const validSchemas: Record<string, UserConfig> = {
empty: {},
withEmptyExtends: {extends: []},
Expand All @@ -9,7 +10,13 @@ const validSchemas: Record<string, UserConfig> = {
withMultipleExtends: {extends: ['test', 'test2']},
withFormatter: {formatter: ''},
withHelpUrl: {helpUrl: ''},
withRules: {rules: {a: [RuleConfigSeverity.Disabled], b: [RuleConfigSeverity.Warning, 'never'], c: [RuleConfigSeverity.Error, 'never', true]}},
withRules: {
rules: {
a: [RuleConfigSeverity.Disabled],
b: [RuleConfigSeverity.Warning, 'never'],
c: [RuleConfigSeverity.Error, 'never', true],
},
},
withParserPresetString: {parserPreset: 'test'},
withParserPresetObject: {parserPreset: {}},
withParserPresetObject2: {parserPreset: {name: 'string', path: 'string'}},
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/cz-commitlint/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"outDir": "./lib"
},
"include": ["./src"],
"exclude": ["./src/**/*.test.ts", "./lib/**/*"],
"exclude": ["./src/**/*.test.ts", "./src/**/*-test.ts", "./lib/**/*"],
"references": [{"path": "../cli"}]
}
16 changes: 10 additions & 6 deletions @commitlint/rules/src/header-trim.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import parse from '@commitlint/parse';
import {Commit} from '@commitlint/types';
import {headerTrim} from './header-trim';
import type {Commit} from 'conventional-commits-parser';

import {headerTrim} from './header-trim.js';

const messages = {
correct: 'test: subject',
Expand All @@ -18,10 +19,13 @@ const messages = {
mixSurround: '\t \ttest: subject \t \t',
};

const parsed = Object.entries(messages).reduce((_parsed, [key, message]) => {
_parsed[key] = parse(message);
return _parsed;
}, {}) as Record<keyof typeof messages, Promise<Commit>>;
const parsed = Object.entries(messages).reduce(
(_parsed, [key, message]) =>
Object.assign(_parsed, {
[key]: parse(message),
}),
{} as Record<keyof typeof messages, Promise<Commit>>
);

test('should succeed when header is not surrounded by whitespace', async () => {
const result = headerTrim(await parsed.correct);
Expand Down
4 changes: 2 additions & 2 deletions @commitlint/rules/src/header-trim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {SyncRule} from '@commitlint/types';
export const headerTrim: SyncRule = (parsed) => {
const {header} = parsed;

const startsWithWhiteSpace = header !== header.trimStart();
const endsWithWhiteSpace = header !== header.trimEnd();
const startsWithWhiteSpace = header !== header?.trimStart();
const endsWithWhiteSpace = header !== header?.trimEnd();

switch (true) {
case startsWithWhiteSpace && endsWithWhiteSpace:
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "./tsconfig.shared.json",
"files": [],
"include": ["./auto-imports.d.ts", "./**/*.test.ts"],
"exclude": ["./**/lib/*.test.ts"],
"include": ["./auto-imports.d.ts", "./**/*.test.ts", "./**/*-test.ts"],
"exclude": ["./**/lib/*.ts"],
"compilerOptions": {
"noEmit": true
},
Expand Down

0 comments on commit 921621e

Please sign in to comment.