Skip to content

Commit

Permalink
style(dotnet): format tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BinToss committed Oct 25, 2024
1 parent 74db7a9 commit 1680575
Show file tree
Hide file tree
Showing 8 changed files with 524 additions and 524 deletions.
126 changes: 63 additions & 63 deletions tests/commitlintConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import { deepStrictEqual, ok } from 'node:assert';
import { describe, it } from 'node:test';
import commitLintConventional from '@commitlint/config-conventional';
import load from '@commitlint/load';
import { RuleConfigSeverity, type QualifiedRuleConfig } from '@commitlint/types';
import rawConfig from '@halospv3/hce.shared-config/commitlintConfig';
import { deepStrictEqual, ok } from 'node:assert'
import { describe, it } from 'node:test'
import commitLintConventional from '@commitlint/config-conventional'
import load from '@commitlint/load'
import { RuleConfigSeverity, type QualifiedRuleConfig } from '@commitlint/types'
import rawConfig from '@halospv3/hce.shared-config/commitlintConfig'
// @ts-expect-error ts(7016) Could not find a declaration file
import createPreset from 'conventional-changelog-conventionalcommits';
import createPreset from 'conventional-changelog-conventionalcommits'

await describe("commitlintConfig", async () => {
await describe("rawConfig", async () => {
await it("has extends", () => {
if (typeof rawConfig.extends === 'string')
deepStrictEqual(rawConfig.extends, '@commitlint/config-conventional');
else if (Array.isArray(rawConfig.extends))
deepStrictEqual(rawConfig.extends, ['@commitlint/config-conventional']);
else ok(false, 'extends is not defined in config file or is an unsupported type!');
});
await describe('commitlintConfig', async () => {
await describe('rawConfig', async () => {
await it('has extends', () => {
if (typeof rawConfig.extends === 'string')
deepStrictEqual(rawConfig.extends, '@commitlint/config-conventional')
else if (Array.isArray(rawConfig.extends))
deepStrictEqual(rawConfig.extends, ['@commitlint/config-conventional'])
else ok(false, 'extends is not defined in config file or is an unsupported type!')
})

await it("has rules", () => {
ok(rawConfig.rules);
const rules = rawConfig.rules;
deepStrictEqual(
rules['body-max-line-length'],
[RuleConfigSeverity.Disabled] as QualifiedRuleConfig<number>
);
deepStrictEqual(
rules['footer-max-line-length'],
[RuleConfigSeverity.Disabled] as QualifiedRuleConfig<number>
);
deepStrictEqual(
rules['header-max-length'],
[RuleConfigSeverity.Disabled] as QualifiedRuleConfig<number>
);
});
});
await it('has rules', () => {
ok(rawConfig.rules)
const rules = rawConfig.rules
deepStrictEqual(
rules['body-max-line-length'],
[RuleConfigSeverity.Disabled] as QualifiedRuleConfig<number>,
)
deepStrictEqual(
rules['footer-max-line-length'],
[RuleConfigSeverity.Disabled] as QualifiedRuleConfig<number>,
)
deepStrictEqual(
rules['header-max-length'],
[RuleConfigSeverity.Disabled] as QualifiedRuleConfig<number>,
)
})
})

await describe('Loaded config tests', async () => {
const config = await load(rawConfig);
await it('has parserPreset', async () => {
const preset = await createPreset();
ok(preset);
ok("parserOpts" in preset || "parser" in preset)
ok(config.parserPreset);
deepStrictEqual(config.parserPreset.name, commitLintConventional.parserPreset);
if ("parser" in preset)
deepStrictEqual(config.parserPreset.parserOpts, preset.parser);
else {
deepStrictEqual(config.parserPreset.parserOpts, preset.parserOpts)
}
});
await it('has rules', async () => {
deepStrictEqual(config.rules['body-leading-blank'], commitLintConventional.rules['body-leading-blank']);
deepStrictEqual(config.rules['body-max-line-length']?.[0], RuleConfigSeverity.Disabled);
deepStrictEqual(config.rules['footer-leading-blank'], commitLintConventional.rules['footer-leading-blank']);
deepStrictEqual(config.rules['footer-max-line-length']?.[0], RuleConfigSeverity.Disabled);
deepStrictEqual(config.rules['header-max-length']?.[0], RuleConfigSeverity.Disabled);
deepStrictEqual(config.rules['header-trim'], commitLintConventional.rules['header-trim']);
deepStrictEqual(config.rules['subject-case'], commitLintConventional.rules['subject-case']);
deepStrictEqual(config.rules['subject-empty'], commitLintConventional.rules['subject-empty']);
deepStrictEqual(config.rules['subject-full-stop'], commitLintConventional.rules['subject-full-stop']);
deepStrictEqual(config.rules['type-case'], commitLintConventional.rules['type-case']);
deepStrictEqual(config.rules['type-empty'], commitLintConventional.rules['type-empty']);
deepStrictEqual(config.rules['type-enum'], commitLintConventional.rules['type-enum']);
});
});
})
await describe('Loaded config tests', async () => {
const config = await load(rawConfig)
await it('has parserPreset', async () => {
const preset = await createPreset()
ok(preset)
ok('parserOpts' in preset || 'parser' in preset)
ok(config.parserPreset)
deepStrictEqual(config.parserPreset.name, commitLintConventional.parserPreset)
if ('parser' in preset)
deepStrictEqual(config.parserPreset.parserOpts, preset.parser)
else {
deepStrictEqual(config.parserPreset.parserOpts, preset.parserOpts)
}
})
await it('has rules', async () => {
deepStrictEqual(config.rules['body-leading-blank'], commitLintConventional.rules['body-leading-blank'])
deepStrictEqual(config.rules['body-max-line-length']?.[0], RuleConfigSeverity.Disabled)
deepStrictEqual(config.rules['footer-leading-blank'], commitLintConventional.rules['footer-leading-blank'])
deepStrictEqual(config.rules['footer-max-line-length']?.[0], RuleConfigSeverity.Disabled)
deepStrictEqual(config.rules['header-max-length']?.[0], RuleConfigSeverity.Disabled)
deepStrictEqual(config.rules['header-trim'], commitLintConventional.rules['header-trim'])
deepStrictEqual(config.rules['subject-case'], commitLintConventional.rules['subject-case'])
deepStrictEqual(config.rules['subject-empty'], commitLintConventional.rules['subject-empty'])
deepStrictEqual(config.rules['subject-full-stop'], commitLintConventional.rules['subject-full-stop'])
deepStrictEqual(config.rules['type-case'], commitLintConventional.rules['type-case'])
deepStrictEqual(config.rules['type-empty'], commitLintConventional.rules['type-empty'])
deepStrictEqual(config.rules['type-enum'], commitLintConventional.rules['type-enum'])
})
})
})
38 changes: 19 additions & 19 deletions tests/dotnet/GithubNugetRegistryInfo.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { GithubNugetRegistryInfo } from '@halospv3/hce.shared-config/dotnet/GithubNugetRegistryInfo';
import { getEnv, getEnvVarValue } from '@halospv3/hce.shared-config/envUtils';
import { type DotenvConfigOptions } from 'dotenv';
import { notDeepStrictEqual, ok, strictEqual } from 'node:assert';
import { existsSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { env } from 'node:process';
import { describe, it } from 'node:test';
import { GithubNugetRegistryInfo } from '@halospv3/hce.shared-config/dotnet/GithubNugetRegistryInfo'
import { getEnv, getEnvVarValue } from '@halospv3/hce.shared-config/envUtils'
import { type DotenvConfigOptions } from 'dotenv'
import { notDeepStrictEqual, ok, strictEqual } from 'node:assert'
import { existsSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { env } from 'node:process'
import { describe, it } from 'node:test'

const dotenvPath = join(dirname(dirname(import.meta.dirname)), '.env');
const dotenvPath = join(dirname(dirname(import.meta.dirname)), '.env')
if (!existsSync(dotenvPath))
writeFileSync(dotenvPath, '')
const dotenvOptions: DotenvConfigOptions = { path: dotenvPath }

Check failure on line 13 in tests/dotnet/GithubNugetRegistryInfo.test.ts

View workflow job for this annotation

GitHub Actions / build

'dotenvOptions' is declared but its value is never read.
Expand All @@ -17,31 +17,31 @@ const dotenvOptions: DotenvConfigOptions = { path: dotenvPath }
* @returns the value of env.GITHUB_REPOSITORY_OWNER
*/
function getOwner(): string {
return env.GITHUB_REPOSITORY_OWNER ??= "HaloSPV3";
return env.GITHUB_REPOSITORY_OWNER ??= 'HaloSPV3'
}

await describe('GithubNugetRegistryInfo', async () => {
await describe('canPushPackagesToUrl', async () => {
await it('returns true when GITHUB_TOKEN is valid and GITHUB_REPOSITORY_OWNER is defined', async (t) => {
if (!getEnvVarValue('GITHUB_TOKEN'))
return t.skip('GITHUB_TOKEN is unavailable for testing');
return t.skip('GITHUB_TOKEN is unavailable for testing')

if (getEnvVarValue('CI') && !(getEnvVarValue('GITHUB_ACTION')?.includes('release')))
return t.skip()

getOwner();
getOwner()
strictEqual(await new GithubNugetRegistryInfo().canPushPackagesToUrl, true)

Check failure on line 33 in tests/dotnet/GithubNugetRegistryInfo.test.ts

View workflow job for this annotation

GitHub Actions / build

Expected 3 arguments, but got 0.
})

await it('throws when GITHUB_TOKEN is invalid', async () => {
getOwner();
const tokenEnvVar = 'TOKEN_CANNOT_WRITE';
getOwner()
const tokenEnvVar = 'TOKEN_CANNOT_WRITE'
getEnv(undefined, { TOKEN_CANNOT_WRITE: tokenEnvVar })
const result = await new GithubNugetRegistryInfo(tokenEnvVar).canPushPackagesToUrl.catch(reason => reason instanceof Error ? reason : new Error(String(reason)));
notDeepStrictEqual(result, true);
ok(result instanceof Error);
});
});
const result = await new GithubNugetRegistryInfo(tokenEnvVar).canPushPackagesToUrl.catch(reason => reason instanceof Error ? reason : new Error(String(reason)))

Check failure on line 40 in tests/dotnet/GithubNugetRegistryInfo.test.ts

View workflow job for this annotation

GitHub Actions / build

Expected 3 arguments, but got 1.
notDeepStrictEqual(result, true)
ok(result instanceof Error)
})
})

// todo: refactor to test new NugetRegistryInfo methods
/* await describe('toRegistryPair', async () => {
Expand Down
Loading

0 comments on commit 1680575

Please sign in to comment.