diff --git a/.github/workflows/differential-shellcheck.yml b/.github/workflows/differential-shellcheck.yml index 08b513f..64e85eb 100644 --- a/.github/workflows/differential-shellcheck.yml +++ b/.github/workflows/differential-shellcheck.yml @@ -1,9 +1,9 @@ name: Differential ShellCheck on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] permissions: contents: read diff --git a/.prettierrc.yml b/.prettierrc.yml index ea61491..f18701f 100644 --- a/.prettierrc.yml +++ b/.prettierrc.yml @@ -1,13 +1,12 @@ ---- semi: true overrides: - files: "**/*.{ts,js}" options: - trailingComma: all + trailingComma: "es5" tabWidth: 2 semi: true singleQuote: true - quoteProps: as-needed + quoteProps: "as-needed" bracketSpacing: true bracketSameLine: true - arrowParens: avoid + arrowParens: "avoid" diff --git a/itest/bugzilla-environment.ts b/itest/bugzilla-environment.ts index 3ba3464..2f5685b 100644 --- a/itest/bugzilla-environment.ts +++ b/itest/bugzilla-environment.ts @@ -21,7 +21,7 @@ export default { ['exec', 'integration', '/usr/local/bin/restore-db'], { stdio: 'inherit', - }, + } ); spawnSync(path.join(__dirname, 'stop_container.sh'), { stdio: 'inherit', diff --git a/itest/test/attachments.test.ts b/itest/test/attachments.test.ts index 6d14c48..cb5aa7e 100644 --- a/itest/test/attachments.test.ts +++ b/itest/test/attachments.test.ts @@ -25,7 +25,7 @@ beforeAll(async () => { api = new BugzillaAPI( 'http://localhost:8088/bugzilla/', 'admin@nowhere.com', - 'adminpass', + 'adminpass' ); bugs.push(await api.createBug(bug)); @@ -64,7 +64,7 @@ beforeAll(async () => { file_name: 'image.png', data: Buffer.from('This is not a image.'), content_type: 'image/png', - })), + })) ); expect(attachments).toBeDefined(); @@ -199,7 +199,7 @@ test(`Edit single attachment`, async () => { is_patch: true, // is_private: true, summary: 'new summary', - }), + }) ).resolves.toEqual([ { changes: new Map([ @@ -233,7 +233,7 @@ test('Edit multiple attachments', async () => { is_patch: true, // is_private: true, summary: 'new summary', - }), + }) ).resolves.toEqual([ { changes: expect.anything(), diff --git a/itest/test/basic.test.ts b/itest/test/basic.test.ts index 59943f1..4677c4f 100644 --- a/itest/test/basic.test.ts +++ b/itest/test/basic.test.ts @@ -18,7 +18,7 @@ test('Authenticated access', async () => { let api = new BugzillaAPI( 'http://localhost:8088/bugzilla/', 'admin@nowhere.com', - 'adminpass', + 'adminpass' ); await expect(api.version()).resolves.toBe('5.1.2'); diff --git a/itest/test/bugs.test.ts b/itest/test/bugs.test.ts index cb85889..3c7d337 100644 --- a/itest/test/bugs.test.ts +++ b/itest/test/bugs.test.ts @@ -24,7 +24,7 @@ beforeEach(async () => { api = new BugzillaAPI( 'http://localhost:8088/bugzilla/', 'admin@nowhere.com', - 'adminpass', + 'adminpass' ); bugs.push(await api.createBug(bug)); @@ -40,7 +40,7 @@ beforeEach(async () => { platform: 'Macintosh', priority: 'High', severity: 'normal', - }), + }) ); expect(bugs).toBeDefined(); @@ -149,7 +149,7 @@ test('Fetch bugs', async () => { ]); await expect(api.quicksearch('ALL')).resolves.toEqual( - expect.arrayContaining(result), + expect.arrayContaining(result) ); }); @@ -161,7 +161,7 @@ test('Update bug', async () => { blocks: { set: [bugs[1] as number] }, comment: { comment: 'New comment', is_private: false }, severity: 'normal', - }), + }) ).resolves.toEqual([ { alias: [], @@ -181,7 +181,7 @@ test('Update multiple bugs', async () => { id_or_alias: bugs[0] as number, ids: [bugs[0] as number, bugs[1] as number], severity: 'normal', - }), + }) ).resolves.toEqual([ { alias: [], @@ -208,7 +208,7 @@ test('Get history of bug', async () => { test('Use of advance searching', async () => { const expected = await api.advancedSearch( - 'http://localhost:8088/bugzilla/buglist.cgi?email1=admin%40nowhere.com&severity=normal', + 'http://localhost:8088/bugzilla/buglist.cgi?email1=admin%40nowhere.com&severity=normal' ); expected.forEach(bug => { @@ -216,19 +216,19 @@ test('Use of advance searching', async () => { expect.objectContaining({ severity: 'normal', creator: 'admin@nowhere.com', - }), + }) ); }); await expect( - api.advancedSearch('email1=admin%40nowhere.com&severity=normal'), + api.advancedSearch('email1=admin%40nowhere.com&severity=normal') ).resolves.toEqual(expected); await expect( api.advancedSearch({ email1: 'admin@nowhere.com', severity: 'normal', - }), + }) ).resolves.toEqual(expected); }); diff --git a/itest/test/comments.test.ts b/itest/test/comments.test.ts index 2bd898b..d309602 100644 --- a/itest/test/comments.test.ts +++ b/itest/test/comments.test.ts @@ -24,7 +24,7 @@ beforeEach(async () => { api = new BugzillaAPI( 'http://localhost:8088/bugzilla/', 'admin@nowhere.com', - 'adminpass', + 'adminpass' ); bugs.push(await api.createBug(bug)); @@ -38,7 +38,7 @@ test('Create comment', async () => { await expect( api.createComment(bugs[0] as number, 'First comment!', { is_private: false, - }), + }) ).resolves.not.toThrow(); }); diff --git a/scripts/post-version.js b/scripts/post-version.js index 8a14863..d2c70bd 100644 --- a/scripts/post-version.js +++ b/scripts/post-version.js @@ -22,7 +22,7 @@ async function main() { i, 0, `# [Next](https://github.com/${matches[1]}/compare/v${manifest.version}...main)`, - '', + '' ); break; } diff --git a/src/index.ts b/src/index.ts index 378dfc0..0a21399 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,13 +53,13 @@ export default class BugzillaAPI { instance: URL | string, username: string, password: string, - restrictLogin?: boolean, + restrictLogin?: boolean ); public constructor( instance: URL | string, user?: string, password?: string, - restrictLogin: boolean = false, + restrictLogin: boolean = false ) { let url = instance instanceof URL ? instance : new URL(instance); @@ -84,7 +84,7 @@ export default class BugzillaAPI { public async bugHistory( bugId: number | string, - since?: DateTime, + since?: DateTime ): Promise { let searchParams: URLSearchParams | undefined; @@ -96,7 +96,7 @@ export default class BugzillaAPI { let bugs = await this.link.get( `bug/${bugId}/history`, object(HistoryLookupSpec), - searchParams, + searchParams ); let [bug] = bugs.bugs; @@ -111,7 +111,7 @@ export default class BugzillaAPI { return new FilteredQuery( async ( includes: string[] | undefined, - excludes: string[] | undefined, + excludes: string[] | undefined ): Promise => { let search = params(query); if (includes) { @@ -126,11 +126,11 @@ export default class BugzillaAPI { object({ bugs: array(object(BugSpec, includes, excludes)), }), - search, + search ); return result.bugs; - }, + } ); } @@ -152,7 +152,7 @@ export default class BugzillaAPI { | URL | Record | [string, string][] - | URLSearchParams, + | URLSearchParams ): FilteredQuery { let searchParams: URLSearchParams; @@ -174,7 +174,7 @@ export default class BugzillaAPI { public async getComment(commentId: number): Promise { let comment = await this.link.get( `bug/comment/${commentId}`, - object(CommentsSpec), + object(CommentsSpec) ); if (!comment) { @@ -187,7 +187,7 @@ export default class BugzillaAPI { public async getBugComments(bugId: number): Promise { let comments = await this.link.get( `bug/${bugId}/comment`, - object(CommentsSpec), + object(CommentsSpec) ); if (!comments) { @@ -200,7 +200,7 @@ export default class BugzillaAPI { public async createComment( bugId: number, comment: string, - options: Partial> = {}, + options: Partial> = {} ): Promise { const content = { comment, @@ -210,7 +210,7 @@ export default class BugzillaAPI { let commentStatus = await this.link.post( `bug/${bugId}/comment`, object(CreatedCommentSpec), - content, + content ); if (!commentStatus) { @@ -232,12 +232,12 @@ export default class BugzillaAPI { public async updateBug( bugIdOrAlias: number | string, - data: UpdateBugContent, + data: UpdateBugContent ): Promise { let response = await this.link.put( `bug/${bugIdOrAlias}`, object(UpdatedBugTemplateSpec), - data, + data ); if (!response) { @@ -248,11 +248,11 @@ export default class BugzillaAPI { } public async getAttachment( - attachmentId: number, + attachmentId: number ): Promise { let attachment = await this.link.get( `bug/attachment/${attachmentId}`, - object(AttachmentsSpec), + object(AttachmentsSpec) ); if (!attachment) { @@ -263,11 +263,11 @@ export default class BugzillaAPI { } public async getBugAttachments( - bugId: number, + bugId: number ): Promise { let attachments = await this.link.get( `bug/${bugId}/attachment`, - object(AttachmentsSpec), + object(AttachmentsSpec) ); if (!attachments) { @@ -279,7 +279,7 @@ export default class BugzillaAPI { public async createAttachment( bugId: number, - attachment: CreateAttachmentContent, + attachment: CreateAttachmentContent ): Promise { const dataBase64 = { data: Buffer.from(attachment.data).toString('base64'), @@ -288,7 +288,7 @@ export default class BugzillaAPI { let attachmentStatus = await this.link.post( `bug/${bugId}/attachment`, object(CreatedAttachmentSpec), - { ...attachment, ...dataBase64 }, + { ...attachment, ...dataBase64 } ); if (!attachmentStatus) { @@ -300,12 +300,12 @@ export default class BugzillaAPI { public async updateAttachment( attachmentId: number, - data: UpdateAttachmentContent, + data: UpdateAttachmentContent ): Promise { let response = await this.link.put( `bug/attachment/${attachmentId}`, object(UpdatedAttachmentTemplateSpec), - data, + data ); if (!response) { diff --git a/src/link.ts b/src/link.ts index c9a64d6..460928b 100644 --- a/src/link.ts +++ b/src/link.ts @@ -30,7 +30,7 @@ function isError(payload: unknown): payload is ApiError { async function performRequest( config: AxiosRequestConfig, - validator: Validator, + validator: Validator ): Promise { try { let response = await axios.request({ @@ -69,7 +69,7 @@ export abstract class BugzillaLink { protected abstract request( config: AxiosRequestConfig, - validator: Validator, + validator: Validator ): Promise; protected buildURL(path: string, query?: SearchParams): URL { @@ -83,13 +83,13 @@ export abstract class BugzillaLink { public async get( path: string, validator: Validator, - searchParams?: SearchParams, + searchParams?: SearchParams ): Promise { return this.request( { url: this.buildURL(path, searchParams).toString(), }, - validator, + validator ); } @@ -97,7 +97,7 @@ export abstract class BugzillaLink { path: string, validator: Validator, content: R, - searchParams?: SearchParams, + searchParams?: SearchParams ): Promise { return this.request( { @@ -108,7 +108,7 @@ export abstract class BugzillaLink { 'Content-Type': 'application/json', }, }, - validator, + validator ); } @@ -116,7 +116,7 @@ export abstract class BugzillaLink { path: string, validator: Validator, content: R, - searchParams?: SearchParams, + searchParams?: SearchParams ): Promise { return this.request( { @@ -127,7 +127,7 @@ export abstract class BugzillaLink { 'Content-Type': 'application/json', }, }, - validator, + validator ); } } @@ -135,7 +135,7 @@ export abstract class BugzillaLink { export class PublicLink extends BugzillaLink { protected async request( config: AxiosRequestConfig, - validator: Validator, + validator: Validator ): Promise { return performRequest(config, validator); } @@ -147,14 +147,14 @@ export class PublicLink extends BugzillaLink { export class ApiKeyLink extends BugzillaLink { public constructor( instance: URL, - private readonly apiKey: string, + private readonly apiKey: string ) { super(instance); } protected async request( config: AxiosRequestConfig, - validator: Validator, + validator: Validator ): Promise { return performRequest( { @@ -166,7 +166,7 @@ export class ApiKeyLink extends BugzillaLink { Authorization: `Bearer ${this.apiKey}`, }, }, - validator, + validator ); } } @@ -181,7 +181,7 @@ export class PasswordLink extends BugzillaLink { instance: URL, private readonly username: string, private readonly password: string, - private readonly restrictLogin: boolean, + private readonly restrictLogin: boolean ) { super(instance); } @@ -195,7 +195,7 @@ export class PasswordLink extends BugzillaLink { restrict_login: String(this.restrictLogin), }).toString(), }, - object(LoginResponseSpec), + object(LoginResponseSpec) ); return loginInfo.token; @@ -203,7 +203,7 @@ export class PasswordLink extends BugzillaLink { protected async request( config: AxiosRequestConfig, - validator: Validator, + validator: Validator ): Promise { if (!this.token) { this.token = await this.login(); @@ -217,7 +217,7 @@ export class PasswordLink extends BugzillaLink { 'X-BUGZILLA-TOKEN': this.token, }, }, - validator, + validator ); } } diff --git a/src/query.ts b/src/query.ts index 35d0df5..6747348 100644 --- a/src/query.ts +++ b/src/query.ts @@ -18,7 +18,7 @@ abstract class Executable implements Promisish { onrejected?: | ((reason: unknown) => TResult2 | PromiseLike) | undefined - | null, + | null ): Promise { if (!this.promise) { this.promise = this.execute(); @@ -31,7 +31,7 @@ abstract class Executable implements Promisish { onrejected?: | ((reason: unknown) => TResult | PromiseLike) | undefined - | null, + | null ): Promise { return this.then(undefined, onrejected); } @@ -50,7 +50,7 @@ type Filtered = T extends type FilterExec = ( includes: Keys[] | undefined, - excludes: Keys[] | undefined, + excludes: Keys[] | undefined ) => Promise[]>; export class FilteredQuery< @@ -71,14 +71,14 @@ export class FilteredQuery< } public include>( - includes: NI[] | null, + includes: NI[] | null ): FilteredQuery { this.includes = includes ?? undefined; return this as unknown as FilteredQuery; } public exclude>( - excludes: NE[] | null, + excludes: NE[] | null ): FilteredQuery { this.excludes = excludes ?? undefined; return this as unknown as FilteredQuery; diff --git a/src/validators.ts b/src/validators.ts index 6080b55..d0e71ef 100644 --- a/src/validators.ts +++ b/src/validators.ts @@ -13,7 +13,7 @@ function repr(val: any): string { export function object( validator: ObjectSpec, includes: string[] = Object.keys(validator), - excludes: string[] = [], + excludes: string[] = [] ): Validator { return (val: any): T => { if (!val || typeof val != 'object') { @@ -37,7 +37,7 @@ export function object( result[field] = fieldValidator(val[field]); } catch (e) { throw new Error( - `Error validating field '${field}': ${e instanceof Error ? e.message : e}`, + `Error validating field '${field}': ${e instanceof Error ? e.message : e}` ); } } @@ -56,7 +56,7 @@ export function array(validator: Validator): Validator { return val.map(validator); } catch (e) { throw new Error( - `Error validating array: ${e instanceof Error ? e.message : e}`, + `Error validating array: ${e instanceof Error ? e.message : e}` ); } }; @@ -93,7 +93,7 @@ export const string = typedValidator('string'); export function base64(val: any): Buffer { if (typeof val != 'string') { throw new Error( - `Expected a base64 encoded string but received ${repr(val)}`, + `Expected a base64 encoded string but received ${repr(val)}` ); } @@ -101,7 +101,7 @@ export function base64(val: any): Buffer { return Buffer.from(val, 'base64'); } catch (_) { throw new Error( - `Expected a base64 encoded string but received ${repr(val)}`, + `Expected a base64 encoded string but received ${repr(val)}` ); } } @@ -110,7 +110,7 @@ export function nullable(validator: Validator): Validator; export function nullable(validator: Validator, result: T): Validator; export function nullable( validator: Validator, - result?: T, + result?: T ): Validator { return (val: any): T | null => { if (val === null) { @@ -125,7 +125,7 @@ export function optional(validator: Validator): Validator; export function optional(validator: Validator, result: T): Validator; export function optional( validator: Validator, - result?: T, + result?: T ): Validator { return (val: any): T | undefined => { if (val === undefined) { @@ -143,7 +143,7 @@ export function maybeArray(validator: Validator): Validator { return val.map(validator); } catch (e) { throw new Error( - `Error validating array: ${e instanceof Error ? e.message : e}`, + `Error validating array: ${e instanceof Error ? e.message : e}` ); } } @@ -155,14 +155,14 @@ export function maybeArray(validator: Validator): Validator { export function intString(val: any): number { if (typeof val != 'string') { throw new Error( - `Expected an integer as a string but received ${repr(val)}`, + `Expected an integer as a string but received ${repr(val)}` ); } let value = parseInt(val, 10); if (value.toString() != val) { throw new Error( - `Expected an integer as a string but received ${repr(val)}`, + `Expected an integer as a string but received ${repr(val)}` ); } @@ -171,7 +171,7 @@ export function intString(val: any): number { export function map( keyValidator: Validator, - valueValidator: Validator, + valueValidator: Validator ): Validator> { return (val: any): Map => { if (!val || typeof val != 'object') { @@ -190,7 +190,7 @@ export function map( export function either( first: Validator, - second: Validator, + second: Validator ): Validator { return (val: any): F | S => { let result: F | S; @@ -203,8 +203,8 @@ export function either( } catch (e) { throw new Error( `Expected an ${first.name} or ${second.name} but received ${repr( - val, - )}`, + val + )}` ); } } diff --git a/test/integration.test.ts b/test/integration.test.ts index 110709f..3d91be6 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -11,7 +11,7 @@ test('Mozilla', async () => { let api = new BugzillaAPI('https://bugzilla.mozilla.org/'); await expect(api.getBugs([645699, 1743832, 1749908])).resolves.toHaveLength( - 3, + 3 ); }); @@ -19,6 +19,6 @@ test('Red Hat', async () => { let api = new BugzillaAPI('https://bugzilla.redhat.com/'); await expect( - api.getBugs([1944441, 1749908, 1205830, 1906064, 1730084]), + api.getBugs([1944441, 1749908, 1205830, 1906064, 1730084]) ).resolves.toHaveLength(5); }); diff --git a/test/link.test.ts b/test/link.test.ts index bf27f14..34eed6a 100644 --- a/test/link.test.ts +++ b/test/link.test.ts @@ -22,12 +22,12 @@ test('PublicLink', async () => { JSON.stringify({ foo: 'Bar', length: 38, - }), - ), + }) + ) ); server.use( - http.get('http://bugzilla.test.org/test/rest/foo', responseHandler), + http.get('http://bugzilla.test.org/test/rest/foo', responseHandler) ); let testSpec = object({ @@ -49,14 +49,14 @@ test('PublicLink', async () => { method: 'GET', url: 'http://bugzilla.test.org/test/rest/foo', }), - }), + }) ); }); test('ApiKeyLink', async () => { let link = new ApiKeyLink( new URL('http://bugzilla.test.org/test/'), - 'my-api-key', + 'my-api-key' ); let responseHandler = vi.fn( @@ -65,12 +65,12 @@ test('ApiKeyLink', async () => { JSON.stringify({ foo: 'Bar', length: 38, - }), - ), + }) + ) ); server.use( - http.get('http://bugzilla.test.org/test/rest/foo', responseHandler), + http.get('http://bugzilla.test.org/test/rest/foo', responseHandler) ); let testSpec = object({ @@ -92,7 +92,7 @@ test('ApiKeyLink', async () => { method: 'GET', url: 'http://bugzilla.test.org/test/rest/foo', }), - }), + }) ); }); @@ -101,7 +101,7 @@ test('PasswordLink', async () => { new URL('http://bugzilla.test.org/test/'), 'my-name', 'my-password', - true, + true ); let loginHandler = vi.fn( @@ -110,12 +110,12 @@ test('PasswordLink', async () => { JSON.stringify({ id: 57, token: 'my-token', - }), - ), + }) + ) ); server.use( - http.get('http://bugzilla.test.org/test/rest/login', loginHandler), + http.get('http://bugzilla.test.org/test/rest/login', loginHandler) ); let responseHandler = vi.fn( @@ -124,12 +124,12 @@ test('PasswordLink', async () => { JSON.stringify({ foo: 'Bar', length: 38, - }), - ), + }) + ) ); server.use( - http.get('http://bugzilla.test.org/test/rest/foo', responseHandler), + http.get('http://bugzilla.test.org/test/rest/foo', responseHandler) ); let testSpec = object({ @@ -151,7 +151,7 @@ test('PasswordLink', async () => { method: 'GET', url: 'http://bugzilla.test.org/test/rest/login?login=my-name&password=my-password&restrict_login=true', }), - }), + }) ); expect(responseHandler).toHaveBeenCalledTimes(1); @@ -161,7 +161,7 @@ test('PasswordLink', async () => { method: 'GET', url: 'http://bugzilla.test.org/test/rest/foo', }), - }), + }) ); loginHandler.mockClear(); @@ -177,6 +177,6 @@ test('PasswordLink', async () => { method: 'GET', url: 'http://bugzilla.test.org/test/rest/foo', }), - }), + }) ); }); diff --git a/test/validators.test.ts b/test/validators.test.ts index c2d7ad3..1aeb497 100644 --- a/test/validators.test.ts +++ b/test/validators.test.ts @@ -26,22 +26,22 @@ test('boolean', () => { expect(boolean(true)).toBe(true); expect(() => boolean(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a boolean but received \`null\`]`, + `[Error: Expected a boolean but received \`null\`]` ); expect(() => boolean(undefined)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a boolean but received \`undefined\`]`, + `[Error: Expected a boolean but received \`undefined\`]` ); expect(() => boolean(0)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a boolean but received \`0\`]`, + `[Error: Expected a boolean but received \`0\`]` ); expect(() => boolean('')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a boolean but received \`""\`]`, + `[Error: Expected a boolean but received \`""\`]` ); expect(() => boolean([])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a boolean but received \`[]\`]`, + `[Error: Expected a boolean but received \`[]\`]` ); expect(() => boolean([false])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a boolean but received \`[false]\`]`, + `[Error: Expected a boolean but received \`[false]\`]` ); }); @@ -56,22 +56,22 @@ test('int', () => { expect(int(20.5)).toBe(20.5); expect(() => int(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`null\`]`, + `[Error: Expected a number but received \`null\`]` ); expect(() => int(undefined)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`undefined\`]`, + `[Error: Expected a number but received \`undefined\`]` ); expect(() => int('5')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`"5"\`]`, + `[Error: Expected a number but received \`"5"\`]` ); expect(() => int('0')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`"0"\`]`, + `[Error: Expected a number but received \`"0"\`]` ); expect(() => int([])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`[]\`]`, + `[Error: Expected a number but received \`[]\`]` ); expect(() => int([0])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`[0]\`]`, + `[Error: Expected a number but received \`[0]\`]` ); }); @@ -84,22 +84,22 @@ test('double', () => { expect(double(20.5)).toBe(20.5); expect(() => double(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`null\`]`, + `[Error: Expected a number but received \`null\`]` ); expect(() => double(undefined)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`undefined\`]`, + `[Error: Expected a number but received \`undefined\`]` ); expect(() => double('5')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`"5"\`]`, + `[Error: Expected a number but received \`"5"\`]` ); expect(() => double('0')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`"0"\`]`, + `[Error: Expected a number but received \`"0"\`]` ); expect(() => double([])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`[]\`]`, + `[Error: Expected a number but received \`[]\`]` ); expect(() => double([0])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`[0]\`]`, + `[Error: Expected a number but received \`[0]\`]` ); }); @@ -108,19 +108,19 @@ test('string', () => { expect(string('foo')).toBe('foo'); expect(() => string(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a string but received \`null\`]`, + `[Error: Expected a string but received \`null\`]` ); expect(() => string(undefined)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a string but received \`undefined\`]`, + `[Error: Expected a string but received \`undefined\`]` ); expect(() => string(0)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a string but received \`0\`]`, + `[Error: Expected a string but received \`0\`]` ); expect(() => string([])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a string but received \`[]\`]`, + `[Error: Expected a string but received \`[]\`]` ); expect(() => string([''])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a string but received \`[""]\`]`, + `[Error: Expected a string but received \`[""]\`]` ); }); @@ -130,13 +130,13 @@ test('optional', () => { expect(optional(int, 5)(undefined)).toBe(5); expect(() => optional(int)(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`null\`]`, + `[Error: Expected a number but received \`null\`]` ); expect(() => optional(int, 5)(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`null\`]`, + `[Error: Expected a number but received \`null\`]` ); expect(() => optional(int)('4')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`"4"\`]`, + `[Error: Expected a number but received \`"4"\`]` ); }); @@ -146,37 +146,37 @@ test('nullable', () => { expect(nullable(int, 5)(null)).toBe(5); expect(() => nullable(int)(undefined)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`undefined\`]`, + `[Error: Expected a number but received \`undefined\`]` ); expect(() => nullable(int, 5)(undefined)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`undefined\`]`, + `[Error: Expected a number but received \`undefined\`]` ); expect(() => nullable(int)('4')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a number but received \`"4"\`]`, + `[Error: Expected a number but received \`"4"\`]` ); }); test('datetime', () => { expect(datetime('2022-01-12T05:43:27Z').toISO()).toBe( - '2022-01-12T05:43:27.000Z', + '2022-01-12T05:43:27.000Z' ); expect(() => datetime(5)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an ISO-8601 string but received \`5\`]`, + `[Error: Expected an ISO-8601 string but received \`5\`]` ); expect(() => datetime(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an ISO-8601 string but received \`null\`]`, + `[Error: Expected an ISO-8601 string but received \`null\`]` ); expect(() => datetime(undefined)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an ISO-8601 string but received \`undefined\`]`, + `[Error: Expected an ISO-8601 string but received \`undefined\`]` ); expect(() => datetime('foo')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an ISO-8601 string but received \`"foo"\`]`, + `[Error: Expected an ISO-8601 string but received \`"foo"\`]` ); expect(() => - datetime('2022-15-12T05:43:27Z'), + datetime('2022-15-12T05:43:27Z') ).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an ISO-8601 string but received \`"2022-15-12T05:43:27Z"\`]`, + `[Error: Expected an ISO-8601 string but received \`"2022-15-12T05:43:27Z"\`]` ); }); @@ -192,19 +192,19 @@ test('object', () => { }); expect(() => - object({ str: string, num: int })({ str: 5, num: '5' }), + object({ str: string, num: int })({ str: 5, num: '5' }) ).toThrowErrorMatchingInlineSnapshot( - `[Error: Error validating field 'str': Expected a string but received \`5\`]`, + `[Error: Error validating field 'str': Expected a string but received \`5\`]` ); expect(() => - object({ str: string })(null), + object({ str: string })(null) ).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an object but received \`null\`]`, + `[Error: Expected an object but received \`null\`]` ); expect(() => - object({ str: string })(undefined), + object({ str: string })(undefined) ).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an object but received \`undefined\`]`, + `[Error: Expected an object but received \`undefined\`]` ); }); @@ -215,21 +215,21 @@ test('array', () => { expect(array(int)([5, 3, 7])).toEqual([5, 3, 7]); expect(() => array(string)(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an array but received \`null\`]`, + `[Error: Expected an array but received \`null\`]` ); expect(() => array(string)(undefined)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an array but received \`undefined\`]`, + `[Error: Expected an array but received \`undefined\`]` ); expect(() => array(string)('hello')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an array but received \`"hello"\`]`, + `[Error: Expected an array but received \`"hello"\`]` ); expect(() => array(int)(5)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an array but received \`5\`]`, + `[Error: Expected an array but received \`5\`]` ); expect(() => - array(string)(['foo', 'bar', 6]), + array(string)(['foo', 'bar', 6]) ).toThrowErrorMatchingInlineSnapshot( - `[Error: Error validating array: Expected a string but received \`6\`]`, + `[Error: Error validating array: Expected a string but received \`6\`]` ); }); @@ -239,23 +239,23 @@ test('maybeArray', () => { expect(maybeArray(string)([])).toEqual([]); expect(() => maybeArray(string)(5)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a string but received \`5\`]`, + `[Error: Expected a string but received \`5\`]` ); expect(() => maybeArray(string)(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a string but received \`null\`]`, + `[Error: Expected a string but received \`null\`]` ); expect(() => - maybeArray(string)(undefined), + maybeArray(string)(undefined) ).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a string but received \`undefined\`]`, + `[Error: Expected a string but received \`undefined\`]` ); expect(() => maybeArray(string)([5])).toThrowErrorMatchingInlineSnapshot( - `[Error: Error validating array: Expected a string but received \`5\`]`, + `[Error: Error validating array: Expected a string but received \`5\`]` ); expect(() => - maybeArray(string)(['foo', 5]), + maybeArray(string)(['foo', 5]) ).toThrowErrorMatchingInlineSnapshot( - `[Error: Error validating array: Expected a string but received \`5\`]`, + `[Error: Error validating array: Expected a string but received \`5\`]` ); }); @@ -263,22 +263,22 @@ test('intString', () => { expect(intString('5')).toBe(5); expect(() => intString('')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an integer as a string but received \`""\`]`, + `[Error: Expected an integer as a string but received \`""\`]` ); expect(() => intString(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an integer as a string but received \`null\`]`, + `[Error: Expected an integer as a string but received \`null\`]` ); expect(() => intString(undefined)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an integer as a string but received \`undefined\`]`, + `[Error: Expected an integer as a string but received \`undefined\`]` ); expect(() => intString(0)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an integer as a string but received \`0\`]`, + `[Error: Expected an integer as a string but received \`0\`]` ); expect(() => intString([])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an integer as a string but received \`[]\`]`, + `[Error: Expected an integer as a string but received \`[]\`]` ); expect(() => intString([''])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an integer as a string but received \`[""]\`]`, + `[Error: Expected an integer as a string but received \`[""]\`]` ); }); @@ -289,18 +289,18 @@ test('map', () => { expect(map(intString, string)({ '5': '5' })).toStrictEqual(myMap); expect(() => map(intString, string)('')).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an object but received \`""\`]`, + `[Error: Expected an object but received \`""\`]` ); expect(() => map(intString, string)(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an object but received \`null\`]`, + `[Error: Expected an object but received \`null\`]` ); expect(() => - map(intString, string)(undefined), + map(intString, string)(undefined) ).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an object but received \`undefined\`]`, + `[Error: Expected an object but received \`undefined\`]` ); expect(() => map(intString, string)(0)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an object but received \`0\`]`, + `[Error: Expected an object but received \`0\`]` ); }); @@ -309,39 +309,39 @@ test('either', () => { expect(() => either(string, int)(5)); expect(() => either(string, int)(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an or but received \`null\`]`, + `[Error: Expected an or but received \`null\`]` ); expect(() => - either(string, int)(undefined), + either(string, int)(undefined) ).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an or but received \`undefined\`]`, + `[Error: Expected an or but received \`undefined\`]` ); expect(() => either(string, int)([])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an or but received \`[]\`]`, + `[Error: Expected an or but received \`[]\`]` ); expect(() => either(string, int)({})).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected an or but received \`{}\`]`, + `[Error: Expected an or but received \`{}\`]` ); }); test('base64', () => { expect(base64('base64 string')).toEqual( - Buffer.from([109, 171, 30, 235, 139, 45, 174, 41, 224]), + Buffer.from([109, 171, 30, 235, 139, 45, 174, 41, 224]) ); expect(() => base64(null)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a base64 encoded string but received \`null\`]`, + `[Error: Expected a base64 encoded string but received \`null\`]` ); expect(() => base64(undefined)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a base64 encoded string but received \`undefined\`]`, + `[Error: Expected a base64 encoded string but received \`undefined\`]` ); expect(() => base64(0)).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a base64 encoded string but received \`0\`]`, + `[Error: Expected a base64 encoded string but received \`0\`]` ); expect(() => base64([])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a base64 encoded string but received \`[]\`]`, + `[Error: Expected a base64 encoded string but received \`[]\`]` ); expect(() => base64([''])).toThrowErrorMatchingInlineSnapshot( - `[Error: Expected a base64 encoded string but received \`[""]\`]`, + `[Error: Expected a base64 encoded string but received \`[""]\`]` ); });