1
0
Fork 0

fix(config): use a URL for config schema path for tests

This commit is contained in:
Sean Sube 2023-01-01 17:37:32 -06:00
parent 49635e6b26
commit c8e2b8dfd5
3 changed files with 207 additions and 10 deletions

View File

@ -0,0 +1,184 @@
## API Report File for "cautious-journey"
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
/// <reference types="node" />
import { BaseOptions } from 'noicejs';
import { Gitlab } from '@gitbeaker/core';
import { Logger } from 'noicejs';
import { Octokit } from '@octokit/rest';
// @public
export interface ChangeSet {
// Warning: (ae-forgotten-export) The symbol "LabelRef" needs to be exported by the entry point index.d.ts
//
// (undocumented)
adds: Array<LabelRef>;
// (undocumented)
removes: Array<LabelRef>;
}
// Warning: (ae-forgotten-export) The symbol "BaseLabel" needs to be exported by the entry point index.d.ts
//
// @public
export type FlagLabel = BaseLabel;
// Warning: (ae-forgotten-export) The symbol "BaseRemote" needs to be exported by the entry point index.d.ts
//
// @public
export class GithubRemote extends BaseRemote<Octokit, RemoteOptions> implements Remote {
constructor(options: RemoteOptions);
// (undocumented)
connect(): Promise<boolean>;
// Warning: (ae-forgotten-export) The symbol "CommentUpdate" needs to be exported by the entry point index.d.ts
//
// (undocumented)
createComment(options: CommentUpdate): Promise<CommentUpdate>;
// Warning: (ae-forgotten-export) The symbol "LabelUpdate" needs to be exported by the entry point index.d.ts
//
// (undocumented)
createLabel(options: LabelUpdate): Promise<LabelUpdate>;
// Warning: (ae-forgotten-export) The symbol "LabelQuery" needs to be exported by the entry point index.d.ts
//
// (undocumented)
deleteLabel(options: LabelQuery): Promise<LabelQuery>;
// (undocumented)
labelName(label: string | {
name?: string;
}): string;
// Warning: (ae-forgotten-export) The symbol "ProjectQuery" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "IssueUpdate" needs to be exported by the entry point index.d.ts
//
// (undocumented)
listIssues(options: ProjectQuery): Promise<Array<IssueUpdate>>;
// (undocumented)
listLabels(options: ProjectQuery): Promise<Array<LabelUpdate>>;
// (undocumented)
resolvePath(project: string): Promise<{
owner: string;
repo: string;
}>;
// (undocumented)
updateIssue(options: IssueUpdate): Promise<IssueUpdate>;
// (undocumented)
updateLabel(options: LabelUpdate): Promise<LabelUpdate>;
}
// @public
export class GitlabRemote extends BaseRemote<Gitlab, RemoteOptions> implements Remote {
constructor(options: RemoteOptions);
// (undocumented)
connect(): Promise<boolean>;
// (undocumented)
createComment(options: CommentUpdate): Promise<CommentUpdate>;
// (undocumented)
createLabel(options: LabelUpdate): Promise<LabelUpdate>;
// (undocumented)
deleteLabel(options: LabelUpdate): Promise<LabelUpdate>;
// (undocumented)
listIssues(options: ProjectQuery): Promise<Array<IssueUpdate>>;
// (undocumented)
listLabels(options: ProjectQuery): Promise<Array<LabelUpdate>>;
// (undocumented)
resolvePath(path: string): Promise<{
groupId: number;
projectId: number;
}>;
// (undocumented)
updateIssue(options: IssueUpdate): Promise<IssueUpdate>;
// (undocumented)
updateLabel(options: LabelUpdate): Promise<LabelUpdate>;
}
// @public
export interface Remote {
// (undocumented)
connect(): Promise<boolean>;
createComment(options: CommentUpdate): Promise<CommentUpdate>;
createLabel(options: LabelUpdate): Promise<LabelUpdate>;
deleteLabel(options: LabelQuery): Promise<LabelQuery>;
listIssues(options: ProjectQuery): Promise<Array<IssueUpdate>>;
listLabels(options: ProjectQuery): Promise<Array<LabelUpdate>>;
updateIssue(options: IssueUpdate): Promise<IssueUpdate>;
updateLabel(options: LabelUpdate): Promise<LabelUpdate>;
}
// @public (undocumented)
export interface RemoteOptions extends BaseOptions {
data: Record<string, string>;
dryrun: boolean;
// (undocumented)
logger: Logger;
type: string;
}
// @public
export interface ResolveInput {
// (undocumented)
flags: Array<FlagLabel>;
// (undocumented)
initial: Array<string>;
// (undocumented)
labels: Array<string>;
// (undocumented)
states: Array<StateLabel>;
}
// @public (undocumented)
export function resolveProject(options: ResolveInput): ResolveResult;
// @public
export interface ResolveResult {
// Warning: (ae-forgotten-export) The symbol "ChangeRecord" needs to be exported by the entry point index.d.ts
//
// (undocumented)
changes: Array<ChangeRecord>;
// Warning: (ae-forgotten-export) The symbol "ErrorRecord" needs to be exported by the entry point index.d.ts
//
// (undocumented)
errors: Array<ErrorRecord>;
// (undocumented)
labels: Array<string>;
}
// @public
export interface StateLabel extends BaseLabel {
// (undocumented)
divider: string;
values: Array<StateValue>;
}
// @public
export interface StateValue extends BaseLabel {
// Warning: (ae-forgotten-export) The symbol "StateChange" needs to be exported by the entry point index.d.ts
becomes: Array<StateChange>;
}
// @public
export function syncIssueLabels(options: SyncOptions): Promise<unknown>;
// @public (undocumented)
export interface SyncOptions {
// (undocumented)
logger: Logger;
// Warning: (ae-forgotten-export) The symbol "ProjectConfig" needs to be exported by the entry point index.d.ts
//
// (undocumented)
project: ProjectConfig;
// Warning: (ae-forgotten-export) The symbol "RandomGenerator" needs to be exported by the entry point index.d.ts
//
// (undocumented)
random: RandomGenerator;
// (undocumented)
remote: Remote;
}
// @public (undocumented)
export function syncProjectLabels(options: SyncOptions): Promise<unknown>;
// (No @packageDocumentation comment for this package)
```

View File

@ -4,6 +4,7 @@ import { promises } from 'fs';
import { load } from 'js-yaml';
import { LogLevel } from 'noicejs';
import { join } from 'path';
import { URL } from 'url';
import { FlagLabel, StateLabel } from '../labels.js';
import { RemoteOptions } from '../remote/index.js';
@ -78,24 +79,29 @@ export interface ConfigData {
export const CONFIG_SCHEMA_KEY = 'cautious-journey#/definitions/config';
export function configSchemaPath(): URL {
return new URL(join('.', 'schema.yml'), import.meta.url);
}
/**
* Load the config from files.
*/
export async function initConfig(path: string): Promise<ConfigData> {
const schemaPath = join(import.meta.url, '..', 'schema.yml');
// eslint-disable-next-line no-console
console.log('init config, schema path', schemaPath);
const schemaPath = configSchemaPath();
const configSchema = await readFile(schemaPath, { encoding: 'utf8' });
const configSchema = await readFile(schemaPath);
const yamlSchema = createSchema({});
const schema = load(configSchema, {
schema: yamlSchema,
}) as object;
const validator = new Ajv(AJV_OPTIONS);
validator.addSchema(configSchema, 'cautious-journey');
validator.addSchema(schema, 'cautious-journey');
const data = await readFile(path, {
encoding: 'utf8',
});
const yamlSchema = createSchema({});
const config = load(data, {
schema: yamlSchema,
});

View File

@ -1,22 +1,29 @@
import { expect } from 'chai';
import { readFile } from 'fs/promises';
import { vol } from 'memfs';
import { Filesystem, initConfig, setFs } from '../../src/config/index.js';
import { configSchemaPath, Filesystem, initConfig, setFs } from '../../src/config/index.js';
describe('config', () => {
describe('init config', () => {
it('should load a valid config', async () => {
const path = 'valid.yml';
const configPath = 'valid.yml';
const schemaPath = configSchemaPath();
// eslint-disable-next-line no-console
console.log('init config, schema path', schemaPath.toString(), schemaPath.pathname);
vol.fromJSON({
[path]: `
[configPath]: `
logger:
level: info
name: test
projects: []`,
[schemaPath.pathname]: await readFile(schemaPath, { encoding: 'utf8' }),
});
const restore = setFs(vol.promises as Filesystem);
const config = await initConfig(path);
const config = await initConfig(configPath);
restore();